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

import com.hotwj.platform.config.vehicleThreeInspectConfig.domain.bo.HotVehicleThreeInspectConfigBo;
import com.hotwj.platform.config.vehicleThreeInspectConfig.domain.vo.HotVehicleThreeInspectConfigVo;
import com.hotwj.platform.config.vehicleThreeInspectConfig.service.IHotVehicleThreeInspectConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
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-29
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/config/vehicleThreeInspectConfig")
@Tag(name = "车辆三检配置", description = "车辆三检配置管理")
public class HotVehicleThreeInspectConfigController extends BaseController {

    private final IHotVehicleThreeInspectConfigService hotVehicleThreeInspectConfigService;

    /**
     * 查询车辆三检配置列表
     */
    //@SaCheckPermission("config:vehicleThreeInspectConfig:list")
    @GetMapping("/list")
    @Operation(summary = "分页查询车辆三检配置列表")
    public TableDataInfo<HotVehicleThreeInspectConfigVo> list(HotVehicleThreeInspectConfigBo bo, PageQuery pageQuery) {
        return hotVehicleThreeInspectConfigService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出车辆三检配置列表
     */
    //@SaCheckPermission("config:vehicleThreeInspectConfig:export")
    @Log(title = "车辆三检配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @Operation(summary = "导出车辆三检配置列表")
    public void export(HotVehicleThreeInspectConfigBo bo, HttpServletResponse response) {
        List<HotVehicleThreeInspectConfigVo> list = hotVehicleThreeInspectConfigService.queryList(bo);
        ExcelUtil.exportExcel(list, "车辆三检配置", HotVehicleThreeInspectConfigVo.class, response);
    }

    /**
     * 获取车辆三检配置详细信息
     *
     * @param id 主键
     */
    //@SaCheckPermission("config:vehicleThreeInspectConfig:query")
    @GetMapping("/{id}")
    @Operation(summary = "获取车辆三检配置详细信息")
    public R<HotVehicleThreeInspectConfigVo> getInfo(@NotNull(message = "主键不能为空")
                                                     @Parameter(name = "id", description = "主键", required = true, example = "1")
                                                     @PathVariable Long id) {
        return R.ok(hotVehicleThreeInspectConfigService.queryById(id));
    }

    /**
     * 新增车辆三检配置
     */
    //@SaCheckPermission("config:vehicleThreeInspectConfig:add")
    @Log(title = "车辆三检配置", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    @Operation(summary = "新增车辆三检配置")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HotVehicleThreeInspectConfigBo bo) {
        return toAjax(hotVehicleThreeInspectConfigService.insertByBo(bo));
    }

    /**
     * 修改车辆三检配置
     */
    //@SaCheckPermission("config:vehicleThreeInspectConfig:edit")
    @Log(title = "车辆三检配置", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    @Operation(summary = "修改车辆三检配置")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HotVehicleThreeInspectConfigBo bo) {
        return toAjax(hotVehicleThreeInspectConfigService.updateByBo(bo));
    }

    /**
     * 删除车辆三检配置
     *
     * @param ids 主键串
     */
    //@SaCheckPermission("config:vehicleThreeInspectConfig:remove")
    @Log(title = "车辆三检配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @Operation(summary = "删除车辆三检配置")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @Parameter(name = "ids", description = "主键串", required = true, example = "1,2,3")
                          @PathVariable Long[] ids) {
        return toAjax(hotVehicleThreeInspectConfigService.deleteWithValidByIds(List.of(ids), true));
    }

    /**
     * 采用默认配置
     */
    //@SaCheckPermission("config:vehicleThreeInspectConfig:add")
    @Log(title = "车辆三检配置", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/useDefault")
    @Operation(summary = "采用默认配置")
    public R<Void> useDefault() {
        return toAjax(hotVehicleThreeInspectConfigService.useDefault());
    }

    /**
     * 一键清空
     */
    //@SaCheckPermission("config:vehicleThreeInspectConfig:remove")
    @Log(title = "车辆三检配置", businessType = BusinessType.DELETE)
    @RepeatSubmit()
    @PostMapping("/clearAll")
    @Operation(summary = "一键清空")
    public R<Void> clearAll() {
        return toAjax(hotVehicleThreeInspectConfigService.clearAll());
    }

    /**
     * 根据公司ID与ID串查询车辆三检配置（包含已删除数据）
     */
    //@SaCheckPermission("config:vehicleThreeInspectConfig:list")
    @GetMapping("/listByIds")
    @Operation(summary = "根据公司ID与ID串查询车辆三检配置列表")
    public R<java.util.List<HotVehicleThreeInspectConfigVo>> listByIds(
            @RequestParam Long companyId,
            @RequestParam String ids
    ) {
        if (companyId == null) {
            return R.ok(java.util.List.of());
        }
        java.util.List<Long> idList = java.util.Arrays.stream(ids.split(","))
                .map(String::trim)
                .filter(s -> !s.isEmpty())
                .map(Long::valueOf)
                .distinct()
                .toList();
        return R.ok(hotVehicleThreeInspectConfigService.queryByCompanyIdAndIds(companyId, idList));
    }
}
