package com.dcsoft.system.visitor.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.dcsoft.common.core.utils.StringUtils;
import com.dcsoft.system.visitor.domain.VisVisitorRegister;
import com.dcsoft.system.visitor.service.IVisVisitorRegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dcsoft.common.log.annotation.Log;
import com.dcsoft.common.log.enums.BusinessType;
import com.dcsoft.common.security.annotation.RequiresPermissions;
import com.dcsoft.common.core.web.controller.BaseController;
import com.dcsoft.common.core.web.domain.AjaxResult;
import com.dcsoft.common.core.utils.poi.ExcelUtil;
import com.dcsoft.common.core.web.page.TableDataInfo;

/**
 * 访客注册Controller
 *
 * @author dcsoft
 * @date 2024-05-21
 */
@RestController
@RequestMapping("/register")
public class VisVisitorRegisterController extends BaseController {
    @Autowired
    private IVisVisitorRegisterService visVisitorRegisterService;

    /**
     * 查询访客注册列表
     */
//    @RequiresPermissions("system:register:list")
    @GetMapping("/list")
    public TableDataInfo list(VisVisitorRegister visVisitorRegister) {
        startPage();
        List<VisVisitorRegister> list = visVisitorRegisterService.selectVisVisitorRegisterList(visVisitorRegister);
        return getDataTable(list);
    }

    /**
     * 导出访客注册列表
     */
    @RequiresPermissions("system:register:export")
    @Log(title = "访客注册", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VisVisitorRegister visVisitorRegister) {
        List<VisVisitorRegister> list = visVisitorRegisterService.selectVisVisitorRegisterList(visVisitorRegister);
        ExcelUtil<VisVisitorRegister> util = new ExcelUtil<VisVisitorRegister>(VisVisitorRegister.class);
        util.exportExcel(response, list, "访客注册数据");
    }

    /**
     * 获取访客注册详细信息
     */
//    @RequiresPermissions("system:register:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(visVisitorRegisterService.selectVisVisitorRegisterById(id));
    }

    /**
     * 小程序获取访客注册详细信息
     */
//    @RequiresPermissions("system:register:query")
    @PostMapping(value = "/getVisitorInfo")
    public AjaxResult getVisitorInfo() {
        return success(visVisitorRegisterService.getVisitorInfo());
    }

    /**
     * 新增访客注册
     */
//    @RequiresPermissions("system:register:add")
    @Log(title = "访客注册", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult addOrUpdate(@RequestBody VisVisitorRegister visVisitorRegister) {
        if (StringUtils.isBlank(visVisitorRegister.getId())) {
            return toAjax(visVisitorRegisterService.insertVisVisitorRegister(visVisitorRegister));
        } else {
            return toAjax(visVisitorRegisterService.updateVisVisitorRegister(visVisitorRegister));
        }
    }

    /**
     * 修改访客注册
     */
//    @RequiresPermissions("system:register:edit")
    @Log(title = "修改访客注册", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VisVisitorRegister visVisitorRegister) {
        return toAjax(visVisitorRegisterService.updateVisVisitorRegister(visVisitorRegister));
    }

    /**
     * 删除访客注册
     */
    @RequiresPermissions("system:register:remove")
    @Log(title = "访客注册", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(visVisitorRegisterService.deleteVisVisitorRegisterByIds(ids));
    }
}
