package org.dromara.controller.visitor;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.domain.visitor.bo.VisitorManageBo;
import org.dromara.domain.visitor.vo.VisitorManageVo;
import org.dromara.service.IVisitorManageService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

;

/**
 * 来访管理
 *
 * @author boman
 * @date 2025-04-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/wuYe/visitorManage")
public class VisitorManageController extends BaseController {

    private final IVisitorManageService visitorManageService;

    /**
     * 查询来访管理列表
     */
    @SaCheckPermission("wuYe:visitorManage:list")
    @GetMapping("/list")
    public TableDataInfo<VisitorManageVo> list(VisitorManageBo bo, PageQuery pageQuery) {
        return visitorManageService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出来访管理列表
     */
    @SaCheckPermission("wuYe:visitorManage:export")
    @Log(title = "来访管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(VisitorManageBo bo, HttpServletResponse response) {
        List<VisitorManageVo> list = visitorManageService.queryList(bo);
        ExcelUtil.exportExcel(list, "来访管理", VisitorManageVo.class, response);
    }

    /**
     * 获取来访管理详细信息
     *
     * @param visitorManageId 主键
     */
    @SaCheckPermission("wuYe:visitorManage:query")
    @GetMapping("/{visitorManageId}")
    public R<VisitorManageVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long visitorManageId) {
        return R.ok(visitorManageService.queryById(visitorManageId));
    }

    /**
     * 新增来访管理
     */
    @SaCheckPermission("wuYe:visitorManage:add")
    @Log(title = "来访管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody VisitorManageBo bo) {
        return toAjax(visitorManageService.insertByBo(bo));
    }

    /**
     * 修改来访管理
     */
    @SaCheckPermission("wuYe:visitorManage:edit")
    @Log(title = "来访管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/put")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody VisitorManageBo bo) {
        return toAjax(visitorManageService.updateByBo(bo));
    }

    /**
     * 删除来访管理
     *
     * @param visitorManageIds 主键串
     */
    @SaCheckPermission("wuYe:visitorManage:remove")
    @Log(title = "来访管理", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{visitorManageIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] visitorManageIds) {
        return toAjax(visitorManageService.deleteWithValidByIds(List.of(visitorManageIds), true));
    }
}
