package com.hotwj.platform.config.driverAnnualAssessmentConfig.controller;

import com.hotwj.platform.config.driverAnnualAssessmentConfig.domain.bo.HotDriverAnnualAssessmentConfigBo;
import com.hotwj.platform.config.driverAnnualAssessmentConfig.domain.vo.HotDriverAnnualAssessmentConfigVo;
import com.hotwj.platform.config.driverAnnualAssessmentConfig.service.IHotDriverAnnualAssessmentConfigService;
import io.swagger.v3.oas.annotations.tags.Tag;
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.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 驾驶员年度考核配置
 *
 * @author shihongwei
 * @date 2025-12-16
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/config/driverAnnualAssessmentConfig")
@Tag(name = "驾驶员年度考核配置", description = "年度考核配置管理")
public class HotDriverAnnualAssessmentConfigController extends BaseController {

    private final IHotDriverAnnualAssessmentConfigService hotDriverAnnualAssessmentConfigService;

    /**
     * 查询驾驶员年度考核配置列表
     */
    //@SaCheckPermission("config:driverAnnualAssessmentConfig:list")
    @GetMapping("/list")
    public TableDataInfo<HotDriverAnnualAssessmentConfigVo> list(HotDriverAnnualAssessmentConfigBo bo, PageQuery pageQuery) {
        return hotDriverAnnualAssessmentConfigService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出驾驶员年度考核配置列表
     */
    //@SaCheckPermission("config:driverAnnualAssessmentConfig:export")
    @Log(title = "驾驶员年度考核配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HotDriverAnnualAssessmentConfigBo bo, HttpServletResponse response) {
        List<HotDriverAnnualAssessmentConfigVo> list = hotDriverAnnualAssessmentConfigService.queryList(bo);
        ExcelUtil.exportExcel(list, "驾驶员年度考核配置", HotDriverAnnualAssessmentConfigVo.class, response);
    }

    /**
     * 获取驾驶员年度考核配置详细信息
     *
     * @param id 主键
     */
    //@SaCheckPermission("config:driverAnnualAssessmentConfig:query")
    @GetMapping("/{id}")
    public R<HotDriverAnnualAssessmentConfigVo> getInfo(@NotNull(message = "主键不能为空")
                                                        @PathVariable Long id) {
        return R.ok(hotDriverAnnualAssessmentConfigService.queryById(id));
    }

    /**
     * 新增驾驶员年度考核配置
     */
    //@SaCheckPermission("config:driverAnnualAssessmentConfig:add")
    @Log(title = "驾驶员年度考核配置", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HotDriverAnnualAssessmentConfigBo bo) {
        return toAjax(hotDriverAnnualAssessmentConfigService.insertByBo(bo));
    }

    /**
     * 修改驾驶员年度考核配置
     */
    //@SaCheckPermission("config:driverAnnualAssessmentConfig:edit")
    @Log(title = "驾驶员年度考核配置", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HotDriverAnnualAssessmentConfigBo bo) {
        return toAjax(hotDriverAnnualAssessmentConfigService.updateByBo(bo));
    }

    /**
     * 删除驾驶员年度考核配置
     *
     * @param ids 主键串
     */
    //@SaCheckPermission("config:driverAnnualAssessmentConfig:remove")
    @Log(title = "驾驶员年度考核配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(hotDriverAnnualAssessmentConfigService.deleteWithValidByIds(List.of(ids), true));
    }

    /**
     * 采用默认配置
     */
    //@SaCheckPermission("config:driverAnnualAssessmentConfig:add")
    @Log(title = "驾驶员年度考核配置", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/useDefault")
    public R<Void> useDefault() {
        return toAjax(hotDriverAnnualAssessmentConfigService.useDefault());
    }

    /**
     * 一键清空
     */
    //@SaCheckPermission("config:driverAnnualAssessmentConfig:remove")
    @Log(title = "驾驶员年度考核配置", businessType = BusinessType.DELETE)
    @RepeatSubmit()
    @PostMapping("/clearAll")
    public R<Void> clearAll() {
        return toAjax(hotDriverAnnualAssessmentConfigService.clearAll());
    }
}
