# GmwrManagerFlashParseServiceByShiji.java

    package cloud.wconnect.workperformance.service.gmwr.managerflash;

    import cloud.wconnect.commonlib.cons.BaseConstant;
    import cloud.wconnect.commonlib.cons.BaseErrorCodeEnum;
    import cloud.wconnect.commonlib.cons.SystemPlatformEnum;
    import cloud.wconnect.commonlib.exception.InternalServerErrorException;
    import cloud.wconnect.commonlib.exception.ParseReportException;
    import cloud.wconnect.commonlib.pojo.dto.PropertyDTO;
    import cloud.wconnect.commonlib.pojo.dto.internationalization.InternationalizationNumberDTO;
    import cloud.wconnect.commonlib.util.InternationalizationUtils;
    import cloud.wconnect.commonlib.util.ShijiFileCheckUtils;
    import cloud.wconnect.workperformance.pojo.bo.gmwr.GmwrManagerFlashBO;
    import com.baomidou.dynamic.datasource.annotation.DS;
    import org.apache.commons.csv.CSVFormat;
    import org.apache.commons.csv.CSVRecord;
    import org.apache.commons.lang3.StringUtils;
    import org.springframework.stereotype.Component;

    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.math.BigDecimal;
    import java.math.RoundingMode;
    import java.util.Iterator;

    /**
     * 解析 Opera 系统的 Manager Flash/Service 报告
     *
     * @author zc
     * @date 2025/7/24
     */
    @Component
    @DS("work_performance")
    public class GmwrManagerFlashParseServiceByShiji implements IGmwrManagerFlashParseService {

        /**
         * 支持的报告来源
         *
         * @param source 报告来源
         * @return boolean
         * @author zc
         * @date 2025/7/24
         */
        @Override
        public boolean supports(String source) {
            return SystemPlatformEnum.SHI_JI.getDesc().equals(source);
        }

        /**
         * 解析报告
         *
         * @param propertyDTO 资产
         * @param in          报告文件流
         * @return GmwrManagerFlashBO
         * @author zc
         * @date 2025/7/24
         */
        @Override
        public GmwrManagerFlashBO parse(PropertyDTO propertyDTO, InputStream in) throws ParseReportException {
            InternationalizationNumberDTO number = propertyDTO.getInternationalization().getNumber();
            RoundingMode roundingMode = InternationalizationUtils.getRoundingMode(number.getCalculationRule());
            try (InputStreamReader inputStreamReader = new InputStreamReader(in)) {
                GmwrManagerFlashBO managerFlashBO = new GmwrManagerFlashBO();
                // 获取CSV数据迭代器
                Iterable<CSVRecord> iterable = CSVFormat.EXCEL.parse(inputStreamReader);
                Iterator<CSVRecord> iterator = iterable.iterator();
                // 跳过标题行
                iterator.next();
                while (iterator.hasNext()) {
                    CSVRecord csvRecord = iterator.next();
                    String description = ShijiFileCheckUtils.get(csvRecord, "A");
                    if ("Revenue - F&B Revenue".equalsIgnoreCase(description)) {
                        // Month CY
                        String fbRevenueStr = ShijiFileCheckUtils.getAndFormatNumber(csvRecord, "C");
                        BigDecimal fbRevenue = StringUtils.isEmpty(fbRevenueStr) ? null : new BigDecimal(fbRevenueStr)
                                .setScale(BaseConstant.DATA_PRECISION, roundingMode);
                        managerFlashBO.setFbRevenue(fbRevenue);
                    } else if ("Revenue - Other Revenue".equalsIgnoreCase(description)) {
                        // Month CY
                        String otherRevenueStr = ShijiFileCheckUtils.getAndFormatNumber(csvRecord, "C");
                        BigDecimal otherRevenue = StringUtils.isEmpty(otherRevenueStr) ? null : new BigDecimal(otherRevenueStr)
                                .setScale(BaseConstant.DATA_PRECISION, roundingMode);
                        managerFlashBO.setOthersRevenue(otherRevenue);
                    }
                }
                return managerFlashBO;
            } catch (IOException e) {
                throw new InternalServerErrorException(BaseErrorCodeEnum.SYSTEM_ERROR.getI18nCode(),
                        BaseErrorCodeEnum.SYSTEM_ERROR.getCode(),
                        "GM Weekly Report parse Manager Flash Shiji report error", e);
            }
        }
    }