package com.hotwj.platform.resourceManagement.vehicleCertReissue.controller;

import com.hotwj.platform.resourceManagement.vehicleCertReissue.domain.bo.HotVehicleCertReissueBo;
import com.hotwj.platform.resourceManagement.vehicleCertReissue.domain.vo.HotVehicleCertReissueVo;
import com.hotwj.platform.resourceManagement.vehicleCertReissue.service.IHotVehicleCertReissueService;
import io.swagger.v3.oas.annotations.Operation;
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.service.DictService;
import org.dromara.common.core.utils.StringUtils;
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-15
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/resourceManagement/vehicleCertReissue")
@Tag(name = "证件补领登记", description = "证件补领登记管理")
public class HotVehicleCertReissueController extends BaseController {

    private final IHotVehicleCertReissueService hotVehicleCertReissueService;
    private final DictService dictService;

    /**
     * 查询证件补领登记列表
     */
    //@SaCheckPermission("resourceManagement:vehicleCertReissue:list")
    @GetMapping("/list")
    @Operation(summary = "查询证件补领登记列表")
    public TableDataInfo<HotVehicleCertReissueVo> list(HotVehicleCertReissueBo bo, PageQuery pageQuery) {
        return hotVehicleCertReissueService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出证件补领登记列表
     */
    //@SaCheckPermission("resourceManagement:vehicleCertReissue:export")
    @Log(title = "证件补领登记", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @Operation(summary = "导出证件补领登记列表")
    public void export(HotVehicleCertReissueBo bo, HttpServletResponse response) {
        List<HotVehicleCertReissueVo> list = hotVehicleCertReissueService.queryList(bo);
        for (HotVehicleCertReissueVo vo : list) {
            String dictLabel = dictService.getDictLabel("hot_paper_type", vo.getReissueType());
            if (StringUtils.isNotBlank(dictLabel)) {
                vo.setReissueType(dictLabel);
            }
        }
        ExcelUtil.exportExcel(list, "证件补领登记", HotVehicleCertReissueVo.class, response);
    }

    /**
     * 获取证件补领登记详细信息
     *
     * @param id 主键
     */
    //@SaCheckPermission("resourceManagement:vehicleCertReissue:query")
    @GetMapping("/{id}")
    @Operation(summary = "获取证件补领登记详细信息")
    public R<HotVehicleCertReissueVo> getInfo(@NotNull(message = "主键不能为空")
                                              @PathVariable Long id) {
        return R.ok(hotVehicleCertReissueService.queryById(id));
    }

    /**
     * 新增证件补领登记
     */
    //@SaCheckPermission("resourceManagement:vehicleCertReissue:add")
    @Log(title = "证件补领登记", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    @Operation(summary = "新增证件补领登记")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HotVehicleCertReissueBo bo) {
        return toAjax(hotVehicleCertReissueService.insertByBo(bo));
    }

    /**
     * 修改证件补领登记
     */
    //@SaCheckPermission("resourceManagement:vehicleCertReissue:edit")
    @Log(title = "证件补领登记", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    @Operation(summary = "修改证件补领登记")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HotVehicleCertReissueBo bo) {
        return toAjax(hotVehicleCertReissueService.updateByBo(bo));
    }

    /**
     * 删除证件补领登记
     *
     * @param ids 主键串
     */
    //@SaCheckPermission("resourceManagement:vehicleCertReissue:remove")
    @Log(title = "证件补领登记", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @Operation(summary = "删除证件补领登记")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(hotVehicleCertReissueService.deleteWithValidByIds(List.of(ids), true));
    }
}
