package com.ruoyi.system.controller;

import java.util.List;
import java.util.Arrays;

import cn.dev33.satoken.annotation.SaIgnore;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.vo.ZsWorkInfoVo;
import com.ruoyi.system.domain.bo.ZsWorkInfoBo;
import com.ruoyi.system.service.IZsWorkInfoService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 职位管理
 *
 * @author wq
 * @date 2025-06-24
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/workInfo")
@Slf4j
public class ZsWorkInfoController extends BaseController {

    private final IZsWorkInfoService iZsWorkInfoService;

    /**
     * 查询职位管理列表
     */
    @SaCheckPermission("system:workInfo:list")
    @GetMapping("/list")
    public TableDataInfo<ZsWorkInfoVo> list(ZsWorkInfoBo bo, PageQuery pageQuery) {
        return iZsWorkInfoService.queryPageList(bo, pageQuery);
    }


    /**
     * 查询职位管理列表 无鉴权
     */
    @SaIgnore
    @GetMapping("/noVerifyList")
    public TableDataInfo<ZsWorkInfoVo> noVerifyList(ZsWorkInfoBo bo, PageQuery pageQuery) {
        return iZsWorkInfoService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出职位管理列表
     */
    @SaCheckPermission("system:workInfo:export")
    @Log(title = "职位管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ZsWorkInfoBo bo, HttpServletResponse response) {
        List<ZsWorkInfoVo> list = iZsWorkInfoService.queryList(bo);
        ExcelUtil.exportExcel(list, "职位管理", ZsWorkInfoVo.class, response);
    }

    /**
     * 获取职位管理详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("system:workInfo:query")
    @GetMapping("/{id}")
    public R<ZsWorkInfoVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iZsWorkInfoService.queryById(id));
    }

    /**
     * 获取职位管理详细信息 无鉴权
     *
     * @param id 主键
     */
    @GetMapping("/noVerify/{id}")
    @SaIgnore
    public R<ZsWorkInfoVo> getInfonoVerify(@NotNull(message = "主键不能为空")
                                   @PathVariable Long id) {
        return R.ok(iZsWorkInfoService.queryById(id));
    }

    /**
     * 新增职位管理
     */
    @SaCheckPermission("system:workInfo:add")
    @Log(title = "职位管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ZsWorkInfoBo bo) {
        return toAjax(iZsWorkInfoService.insertByBo(bo));
    }

    /**
     * 修改职位管理
     */
    @SaCheckPermission("system:workInfo:edit")
    @Log(title = "职位管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ZsWorkInfoBo bo) {
        return toAjax(iZsWorkInfoService.updateByBo(bo));
    }

    /**
     * 删除职位管理
     *
     * @param ids 主键串
     */
    @SaCheckPermission("system:workInfo:remove")
    @Log(title = "职位管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iZsWorkInfoService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
