package com.hotwj.platform.securityManagement.hiddenDangerInspection.controller;

import com.hotwj.platform.securityManagement.hiddenDangerInspection.domain.bo.HotHiddenDangerInspectionBo;
import com.hotwj.platform.securityManagement.hiddenDangerInspection.domain.vo.HotHiddenDangerInspectionVo;
import com.hotwj.platform.securityManagement.hiddenDangerInspection.service.IHotHiddenDangerInspectionService;
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-31
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/securityManagement/hiddenDangerInspection")
@Tag(name = "隐患排查-排查项目", description = "隐患排查-排查项目管理")
public class HotHiddenDangerInspectionController extends BaseController {

    private final IHotHiddenDangerInspectionService hotHiddenDangerInspectionService;

    /**
     * 查询隐患排查-排查项目列表
     */
    //@SaCheckPermission("securityManagement:hiddenDangerInspection:list")
    @GetMapping("/list")
    @Operation(summary = "分页查询隐患排查-排查项目列表")
    public TableDataInfo<HotHiddenDangerInspectionVo> list(HotHiddenDangerInspectionBo bo, PageQuery pageQuery) {
        return hotHiddenDangerInspectionService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出隐患排查-排查项目列表
     */
    //@SaCheckPermission("securityManagement:hiddenDangerInspection:export")
    @Log(title = "隐患排查-排查项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @Operation(summary = "导出隐患排查-排查项目列表")
    public void export(HotHiddenDangerInspectionBo bo, HttpServletResponse response) {
        List<HotHiddenDangerInspectionVo> list = hotHiddenDangerInspectionService.queryList(bo);
        ExcelUtil.exportExcel(list, "隐患排查-排查项目", HotHiddenDangerInspectionVo.class, response);
    }

    /**
     * 获取隐患排查-排查项目详细信息
     *
     * @param id 主键
     */
    //@SaCheckPermission("securityManagement:hiddenDangerInspection:query")
    @GetMapping("/{id}")
    @Operation(summary = "获取隐患排查-排查项目详细信息")
    public R<HotHiddenDangerInspectionVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @Parameter(name = "id", description = "主键", required = true, example = "1")
                                                  @PathVariable Long id) {
        return R.ok(hotHiddenDangerInspectionService.queryById(id));
    }

    /**
     * 新增隐患排查-排查项目
     */
    //@SaCheckPermission("securityManagement:hiddenDangerInspection:add")
    @Log(title = "隐患排查-排查项目", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    @Operation(summary = "新增隐患排查-排查项目")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HotHiddenDangerInspectionBo bo) {
        return toAjax(hotHiddenDangerInspectionService.insertByBo(bo));
    }

    /**
     * 修改隐患排查-排查项目
     */
    //@SaCheckPermission("securityManagement:hiddenDangerInspection:edit")
    @Log(title = "隐患排查-排查项目", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    @Operation(summary = "修改隐患排查-排查项目")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HotHiddenDangerInspectionBo bo) {
        return toAjax(hotHiddenDangerInspectionService.updateByBo(bo));
    }

    /**
     * 审核隐患排查-排查项目
     */
    //@SaCheckPermission("securityManagement:hiddenDangerInspection:edit")
    @Log(title = "隐患排查-排查项目", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/audit")
    @Operation(summary = "审核隐患排查-排查项目")
    public R<Void> audit(@RequestBody HotHiddenDangerInspectionBo bo) {
        hotHiddenDangerInspectionService.audit(bo);
        return R.ok();
    }

    /**
     * 删除隐患排查-排查项目
     *
     * @param ids 主键串
     */
    //@SaCheckPermission("securityManagement:hiddenDangerInspection: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(hotHiddenDangerInspectionService.deleteWithValidByIds(List.of(ids), true));
    }

    @GetMapping("/hidden-danger-plans/page")
    @Operation(
            summary = "移动端分页查询隐患排查计划列表",
            description = "权限说明：驾驶员仅可查看本人及所属车辆当月全部计划和历史未做计划；管理员可查看企业当月全部计划和历史未做计划。"
    )
    public TableDataInfo<HotHiddenDangerInspectionVo> hiddenDangerPlanPage(
            @RequestParam(value = "keyword", required = false) String keyword,
            PageQuery pageQuery) {
        return hotHiddenDangerInspectionService.queryMobilePlanPage(keyword, pageQuery);
    }
}
