package com.pusong.business.controller;

import java.util.List;

import cn.dev33.satoken.annotation.SaIgnore;
import com.pusong.business.domain.bo.PsSalaryConfigAddVo;
import com.pusong.business.domain.vo.PsSalaryConfigInfoVo;
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 com.pusong.common.idempotent.annotation.RepeatSubmit;
import com.pusong.common.log.annotation.Log;
import com.pusong.common.web.core.BaseController;
import com.pusong.common.mybatis.core.page.PageQuery;
import com.pusong.common.core.domain.R;
import com.pusong.common.core.validate.AddGroup;
import com.pusong.common.core.validate.EditGroup;
import com.pusong.common.log.enums.BusinessType;
import com.pusong.common.excel.utils.ExcelUtil;
import com.pusong.business.domain.vo.PsSalaryConfigVo;
import com.pusong.business.domain.bo.PsSalaryConfigBo;
import com.pusong.business.service.IPsSalaryConfigService;
import com.pusong.common.mybatis.core.page.TableDataInfo;

/**
 * 提成配置
 *
 * @author Lion Li
 * @date 2024-08-22
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/business/salaryConfig")
@SaIgnore
public class PsSalaryConfigController extends BaseController {

    private final IPsSalaryConfigService psSalaryConfigService;

    /**
     * 查询提成配置列表
     */
    @SaCheckPermission("business:salaryConfig:list")
    @GetMapping("/list")
    public TableDataInfo<PsSalaryConfigVo> list(PsSalaryConfigBo bo, PageQuery pageQuery) {
        return psSalaryConfigService.queryPageList(bo, pageQuery);
    }

    /**
     * 根据模板编码查询配置详情
     */
    @Log(title = "根据模板编码查询配置详情")
    @SaCheckPermission("business:salaryConfig:info")
    @GetMapping("/info")
    public R<PsSalaryConfigInfoVo> info(String templateCode) {
        return R.ok(psSalaryConfigService.queryByTemplateCode(templateCode));
    }

    /**
     * 新增/修改提成配置
     */
    @RepeatSubmit()
    @Log(title = "新增提成配置")
    @SaCheckPermission("business:salaryConfig:add")
    @PostMapping("/add")
    public R<Void> add(@RequestBody PsSalaryConfigAddVo addVo) {
        psSalaryConfigService.add(addVo);
        return R.ok();
    }

    /**
     * 删除提成配置
     *
     * @param code 主键串
     */
    @SaCheckPermission("business:salaryConfig:remove")
    @Log(title = "提成配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{code}")
    public R<Void> remove(@NotEmpty(message = "编码不能为空")
                          @PathVariable String code) {
        return toAjax(psSalaryConfigService.deleteWithValidByIds(code));
    }

//    /**
//     * 导出提成配置列表
//     */
//    @SaCheckPermission("business:salaryConfig:export")
//    @Log(title = "提成配置", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(PsSalaryConfigBo bo, HttpServletResponse response) {
//        List<PsSalaryConfigVo> list = psSalaryConfigService.queryList(bo);
//        ExcelUtil.exportExcel(list, "提成配置", PsSalaryConfigVo.class, response);
//    }
//
//    /**
//     * 获取提成配置详细信息
//     *
//     * @param id 主键
//     */
//    @SaCheckPermission("business:salaryConfig:query")
//    @GetMapping("/{id}")
//    public R<PsSalaryConfigVo> getInfo(@NotNull(message = "主键不能为空")
//                                     @PathVariable Long id) {
//        return R.ok(psSalaryConfigService.queryById(id));
//    }
//
//    /**
//     * 新增提成配置
//     */
//    @SaCheckPermission("business:salaryConfig:add")
//    @Log(title = "提成配置", businessType = BusinessType.INSERT)
//    @RepeatSubmit()
//    @PostMapping()
//    public R<Void> add(@Validated(AddGroup.class) @RequestBody PsSalaryConfigBo bo) {
//        return toAjax(psSalaryConfigService.insertByBo(bo));
//    }
//
//    /**
//     * 修改提成配置
//     */
//    @SaCheckPermission("business:salaryConfig:edit")
//    @Log(title = "提成配置", businessType = BusinessType.UPDATE)
//    @RepeatSubmit()
//    @PutMapping()
//    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PsSalaryConfigBo bo) {
//        return toAjax(psSalaryConfigService.updateByBo(bo));
//    }
//
//    /**
//     * 删除提成配置
//     *
//     * @param ids 主键串
//     */
//    @SaCheckPermission("business:salaryConfig:remove")
//    @Log(title = "提成配置", businessType = BusinessType.DELETE)
//    @DeleteMapping("/{ids}")
//    public R<Void> remove(@NotEmpty(message = "主键不能为空")
//                          @PathVariable Long[] ids) {
//        return toAjax(psSalaryConfigService.deleteWithValidByIds(List.of(ids), true));
//    }
}
