package com.hotwj.platform.reportStatistics.controller;

import com.hotwj.platform.reportStatistics.domain.bo.ReportLedgerQueryBo;
import com.hotwj.platform.reportStatistics.domain.vo.GovGpsViolationLedgerVo;
import com.hotwj.platform.reportStatistics.domain.vo.GovVehicleInfoLedgerVo;
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.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/vehicleManagement")
@Tag(name = "车辆信息管理台账（政府端）", description = "车辆信息管理台账（政府端）")
public class VehicleManagementController extends BaseController {

    private final ILedgerReportService ledgerReportService;
    private final IHotGovEnterpriseUnitService hotGovEnterpriseUnitService;

    //@SaCheckPermission("vehicleManagement:vehicleInfo:list")
    @GetMapping("/vehicleInfo/list")
    @Operation(summary = "车辆信息管理台账-分页（政府端）")
    public TableDataInfo<GovVehicleInfoLedgerVo> vehicleInfoList(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();
        }
        bo.setVehicleStatus(1);
        bo.setOperationStatus(1);
        return ledgerReportService.queryGovVehicleInfo(unitVo.getDistrictCode(), bo, pageQuery);
    }

    //@SaCheckPermission("vehicleManagement:gpsViolation:list")
    @GetMapping("/gpsViolation/list")
    @Operation(summary = "车辆GPS违章-分页（政府端）")
    public TableDataInfo<GovGpsViolationLedgerVo> gpsViolationList(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();
        }
        bo.setNeedInterview(1);
        bo.setProcessStatus(2);
        return ledgerReportService.queryGovGpsViolation(unitVo.getDistrictCode(), bo, pageQuery);
    }
}
