# DbManualHandleDbMarketCodeStatisticsService.java

    package cloud.wconnect.workperformance.service.database.marketcode;

    import cloud.wconnect.commonlib.cons.BaseConstant;
    import cloud.wconnect.commonlib.cons.BaseErrorCodeEnum;
    import cloud.wconnect.commonlib.cons.CommonErrorI18nConstant;
    import cloud.wconnect.commonlib.cons.CommonFieldI18nConstant;
    import cloud.wconnect.commonlib.exception.BadRequestException;
    import cloud.wconnect.commonlib.pojo.dto.PropertyDTO;
    import cloud.wconnect.commonlib.util.DateTimeUtils;
    import cloud.wconnect.commonlib.util.I18nMessageUtils;
    import cloud.wconnect.workperformance.cons.database.DbPmsReportTypeEnum;
    import cloud.wconnect.workperformance.entity.database.DbReportImportLog;
    import cloud.wconnect.workperformance.pojo.dto.database.report.DbImportReportDTO;
    import cloud.wconnect.workperformance.service.database.IDbManualHandleReportService;
    import com.baomidou.dynamic.datasource.annotation.DS;
    import jakarta.annotation.Resource;
    import org.springframework.context.ApplicationContext;
    import org.springframework.stereotype.Component;
    import org.springframework.web.multipart.MultipartFile;

    import java.time.LocalDate;
    import java.util.Collection;

    /**
     * 手动解决 Manager Flash/Service 报告
     *
     * @author zc
     * @date 2025/12/02
     */
    @Component
    @DS("database")
    public class DbManualHandleDbMarketCodeStatisticsService implements IDbManualHandleReportService {

        @Resource
        private ApplicationContext applicationContext;
        @Resource
        private I18nMessageUtils i18nMessageUtils;

        /**
         * 根据判断是否支持此报告类型
         *
         * @param reportType 报告分类
         * @return boolean
         * @author zc
         * @date 2025/12/02
         */
        @Override
        public boolean supports(int reportType) {
            return reportType == DbPmsReportTypeEnum.MARKET_CODE_STATISTICS.getType();
        }

        /**
         * 校验文件内容是否合法
         *
         * @param propertyDTO 资产
         * @param file        文件
         * @author zc
         * @date 2025/12/02
         */
        @Override
        public void checkFile(PropertyDTO propertyDTO, String source, MultipartFile file) {
            Collection<IDbPmsMarketCodeStatisticsParseService> parserList =
                    applicationContext.getBeansOfType(IDbPmsMarketCodeStatisticsParseService.class).values();
            for (IDbPmsMarketCodeStatisticsParseService parser : parserList) {
                if (parser.supports(source)) {
                    parser.checkFile(propertyDTO, file);
                    return;
                }
            }
        }

        /**
         * 校验日期参数
         *
         * @param propertyDTO 资产
         * @param reportDTO   报告
         * @author zc
         * @date 2025/12/02
         */
        @Override
        public void checkDate(PropertyDTO propertyDTO, String source, DbImportReportDTO reportDTO) {
            LocalDate startLocalDate = DateTimeUtils.strToLocalDate(reportDTO.getStartDate().toString(),
                    BaseConstant.DATE_FORMAT_YYYYMMDD);
            LocalDate endLocalDate = DateTimeUtils.strToLocalDate(reportDTO.getEndDate().toString(),
                    BaseConstant.DATE_FORMAT_YYYYMMDD);
            LocalDate businessLocalDate = DateTimeUtils.strToLocalDate(reportDTO.getBusinessDate().toString(),
                    BaseConstant.DATE_FORMAT_YYYYMMDD);

            // StartDate 必须等于 EndDate
            if (!startLocalDate.isEqual(endLocalDate)) {
                throw new BadRequestException(CommonErrorI18nConstant.MUST_EQUAL_TO,
                        i18nMessageUtils.getErrorParamMapNeedTranslate(CommonFieldI18nConstant.START_DATE,
                                CommonFieldI18nConstant.BUSINESS_DATE),
                        BaseErrorCodeEnum.DATA_VALIDATION_ERROR.getCode(),
                        "The startDate must be equal to businessDate.");
            }

            // StartDate 必须小于 BusinessDate
            if (!startLocalDate.isBefore(businessLocalDate)) {
                throw new BadRequestException(CommonErrorI18nConstant.MUST_LESS_THAN,
                        i18nMessageUtils.getErrorParamMapNeedTranslate(CommonFieldI18nConstant.START_DATE,
                                CommonFieldI18nConstant.BUSINESS_DATE),
                        BaseErrorCodeEnum.DATA_VALIDATION_ERROR.getCode(),
                        "The startDate must be less than businessDate.");
            }
        }

        /**
         * 处理数据
         *
         * @param propertyDTO 资产
         * @param file        文件
         * @param operatorId  操作人 id
         * @param source      来源
         * @author zc
         * @date 2025/12/02
         */
        @Override
        public void handleData(PropertyDTO propertyDTO, MultipartFile file, DbReportImportLog importLog, int operatorId, String source) {
            Collection<IDbPmsMarketCodeStatisticsParseService> parserList =
                    applicationContext.getBeansOfType(IDbPmsMarketCodeStatisticsParseService.class).values();
            for (IDbPmsMarketCodeStatisticsParseService parser : parserList) {
                if (parser.supports(source)) {
                    parser.handleData(propertyDTO, file, importLog, operatorId);
                    return;
                }
            }
        }
    }