package com.ruoyi.web.controller.visitor;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.visitor.VisitorManage;
import com.ruoyi.system.service.IVisitorManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 来访管理Controller
 *
 * @author boman
 * @date 2025-02-14
 */
@RestController
@RequestMapping("/wuYe/visitorManage")
public class VisitorManageController extends BaseController {
    @Autowired
    private IVisitorManageService visitorManageService;

    /**
     * 查询来访管理列表
     */
    @PreAuthorize("@ss.hasPermi('wuYe:visitorManage:list')")
    @GetMapping("/list")
    public TableDataInfo list(VisitorManage visitorManage) {
        startPage();
        List<VisitorManage> list = visitorManageService.selectVisitorManageList(visitorManage);
        return getDataTable(list);
    }

    /**
     * 导出来访管理列表
     */
    @PreAuthorize("@ss.hasPermi('wuYe:visitorManage:export')")
    @Log(title = "来访管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VisitorManage visitorManage) {
        List<VisitorManage> list = visitorManageService.selectVisitorManageList(visitorManage);
        ExcelUtil<VisitorManage> util = new ExcelUtil<VisitorManage>(VisitorManage.class);
        util.exportExcel(response, list, "来访管理数据");
    }

    /**
     * 获取来访管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('wuYe:visitorManage:query')")
    @GetMapping(value = "/{visitorManageId}")
    public AjaxResult getInfo(@PathVariable("visitorManageId") Long visitorManageId) {
        return success(visitorManageService.selectVisitorManageByVisitorManageId(visitorManageId));
    }

    /**
     * 新增来访管理
     */
    @PreAuthorize("@ss.hasPermi('wuYe:visitorManage:add')")
    @Log(title = "来访管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VisitorManage visitorManage) {
        return toAjax(visitorManageService.insertVisitorManage(visitorManage));
    }

    /**
     * 修改来访管理
     */
    @PreAuthorize("@ss.hasPermi('wuYe:visitorManage:edit')")
    @Log(title = "来访管理", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody VisitorManage visitorManage) {
        return toAjax(visitorManageService.updateVisitorManage(visitorManage));
    }

    /**
     * 删除来访管理
     */
    @PreAuthorize("@ss.hasPermi('wuYe:visitorManage:remove')")
    @Log(title = "来访管理", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{visitorManageIds}")
    public AjaxResult remove(@PathVariable Long[] visitorManageIds) {
        return toAjax(visitorManageService.deleteVisitorManageByVisitorManageIds(visitorManageIds));
    }
}
