package com.hotwj.platform.reportStatistics.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.hotwj.platform.reportStatistics.domain.bo.ReportLedgerQueryBo;
import com.hotwj.platform.reportStatistics.domain.vo.GovAccidentLedgerVo;
import com.hotwj.platform.reportStatistics.domain.vo.SafetyProductionMeetingLedgerVo;
import com.hotwj.platform.reportStatistics.service.ILedgerReportService;
import com.hotwj.platform.resourceManagement.company.service.ISysUserLoginPortService;
import com.hotwj.platform.resourceManagement.govEnterpriseUnit.domain.vo.HotGovEnterpriseUnitVo;
import com.hotwj.platform.resourceManagement.govEnterpriseUnit.service.IHotGovEnterpriseUnitService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.model.LoginUser;
import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.common.web.core.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 安全生产管理
 *
 * @author shihongwei
 * @date 2026-02-03
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/reportStatistics/securityManagement")
@Tag(name = "安全生产管理", description = "安全生产管理")
public class SecurityManagementController extends BaseController {

    private final ILedgerReportService ledgerReportService;
    private final IHotGovEnterpriseUnitService hotGovEnterpriseUnitService;

    //@SaCheckPermission("reportStatistics:securityMeeting:list")
    @GetMapping("/meeting/list")
    @Operation(summary = "安全生产会议记录")
    public TableDataInfo<SafetyProductionMeetingLedgerVo> meetingList(ReportLedgerQueryBo bo, PageQuery pageQuery) {
        if (bo.getCompanyId() == null) {
            throw new ServiceException("企业ID不能为空");
        }
        return ledgerReportService.querySafetyProductionMeeting(bo, pageQuery);
    }

    //@SaCheckPermission("reportStatistics:securityAccident:list")
    @GetMapping("/accident/list")
    @Operation(summary = "安全事故台账")
    public TableDataInfo<GovAccidentLedgerVo> accidentList(ReportLedgerQueryBo bo, PageQuery pageQuery) {
        LoginUser loginUser = LoginHelper.getLoginUser();
        if (loginUser == null || !ISysUserLoginPortService.GOVERNMENT_PORT.equals(loginUser.getLoginPort())) {
            return TableDataInfo.build();
        }
        HotGovEnterpriseUnitVo unitVo = hotGovEnterpriseUnitService.queryById(loginUser.getCompanyId());
        if (unitVo == null || unitVo.getDistrictCode() == null) {
            return TableDataInfo.build();
        }
        return ledgerReportService.queryGovAccident(unitVo.getDistrictCode(), bo, pageQuery);
    }
}
