package org.dromara.personnel.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
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.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.personnel.domain.vo.OpsWorkWageVo;
import org.dromara.personnel.domain.bo.OpsWorkWageBo;
import org.dromara.personnel.service.IOpsWorkWageService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 工种薪水
 * 前端访问路由地址为:/personnel/workWage
 *
 * @author LionLi
 * @date 2025-09-17
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/workWage")
public class OpsWorkWageController extends BaseController {

    private final IOpsWorkWageService opsWorkWageService;

    /**
     * 查询工种薪水列表
     */
    @SaCheckPermission("personnel:workWage:list")
    @GetMapping("/list")
    public TableDataInfo<OpsWorkWageVo> list(OpsWorkWageBo bo, PageQuery pageQuery) {
        return opsWorkWageService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出工种薪水列表
     */
    @SaCheckPermission("personnel:workWage:export")
    @Log(title = "工种薪水", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(OpsWorkWageBo bo, HttpServletResponse response) {
        List<OpsWorkWageVo> list = opsWorkWageService.queryList(bo);
        ExcelUtil.exportExcel(list, "工种薪水", OpsWorkWageVo.class, response);
    }

    /**
     * 获取工种薪水详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("personnel:workWage:query")
    @GetMapping("/{id}")
    public R<OpsWorkWageVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable("id") Long id) {
        return R.ok(opsWorkWageService.queryById(id));
    }

    /**
     * 新增工种薪水
     */
    @SaCheckPermission("personnel:workWage:add")
    @Log(title = "工种薪水", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody OpsWorkWageBo bo) {
        return toAjax(opsWorkWageService.insertByBo(bo));
    }

    /**
     * 修改工种薪水
     */
    @SaCheckPermission("personnel:workWage:edit")
    @Log(title = "工种薪水", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody OpsWorkWageBo bo) {
        return toAjax(opsWorkWageService.updateByBo(bo));
    }

    /**
     * 删除工种薪水
     *
     * @param ids 主键串
     */
    @SaCheckPermission("personnel:workWage:remove")
    @Log(title = "工种薪水", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable("ids") Long[] ids) {
        return toAjax(opsWorkWageService.deleteWithValidByIds(List.of(ids), true));
    }
}
