package org.dromara.project.controller;

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.project.domain.dto.workwage.BusWorkWageCreateReq;
import org.dromara.project.domain.dto.workwage.BusWorkWageQueryReq;
import org.dromara.project.domain.dto.workwage.BusWorkWageUpdateReq;
import org.dromara.project.domain.vo.workwage.BusWorkWageVo;
import org.dromara.project.service.IBusWorkWageService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 工种薪水
 *
 * @author lcj
 * @date 2025-03-26
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/project/workWage")
public class BusWorkWageController extends BaseController {

    private final IBusWorkWageService busWorkWageService;

    /**
     * 查询工种薪水列表
     */
    @SaCheckPermission("project:workWage:list")
    @GetMapping("/list")
    public TableDataInfo<BusWorkWageVo> list(BusWorkWageQueryReq req, PageQuery pageQuery) {
        return busWorkWageService.queryPageList(req, pageQuery);
    }

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

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

    /**
     * 新增工种薪水
     */
    @SaCheckPermission("project:workWage:add")
    @Log(title = "工种薪水", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Long> add(@Validated(AddGroup.class) @RequestBody BusWorkWageCreateReq req) {
        return R.ok(busWorkWageService.insertByBo(req));
    }

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

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