public List selectGroupByVarietiesName(CsbProductSalesReportVO vo) { List res = new LinkedList<>(); List csbCoalTypeReportPOS = csbCoalTypeReportMapper.selectCsbCoalTypeReport(null); if (CollectionUtils.isEmpty(csbCoalTypeReportPOS)) { fillVarietiesName("", null, Collections.emptyList(), res); return res; }

List<String> varieties = csbCoalTypeReportPOS.stream()
        .map(CsbCoalTypeReportPO::getVarietiesName)
        .collect(Collectors.toList());

Optional<CsbCoalTypeReportPO> first = csbCoalTypeReportPOS.stream()
        .filter(t -> t.getSerialNo().equals(vo.getVarieties()))
        .findFirst();

String queryVarietiesName = first.map(CsbCoalTypeReportPO::getVarietiesName).orElse("");
vo.setStartTime(csbMonRepStatisticsCycleDictMapper.selectJanByYearDate(
        DateUtils.date2Calendar(vo.getStartTime()).get(Calendar.YEAR) + CsbDictTypeConstant.YEAR));

List<CsbProductSalesReportVO> vos = csbProductSalesReportMapper.selectCsbProductSalesReport(vo);
if (CollectionUtils.isEmpty(vos)) {
    fillVarietiesName(queryVarietiesName, null, varieties, res);
    return res;
}

Map<String, List<CsbProductSalesReportVO>> vosMap = vos.stream()
        .collect(Collectors.groupingBy(CsbProductSalesReportVO::getVarietiesName));

ExportCommercialCoalDTO all = new ExportCommercialCoalDTO();
double allSumWaterWeight = 0.0d;
double allSumWaterDeductionWeight = 0.0d;
double allMonthWaterWeight = 0.0d;
double allMonthWaterDeductionWeight = 0.0d;

for (Map.Entry<String, List<CsbProductSalesReportVO>> entry : vosMap.entrySet()) {
    String varietiesName = entry.getKey();
    List<CsbProductSalesReportVO> v = entry.getValue();
    
    ExportCommercialCoalDTO statisticDto = new ExportCommercialCoalDTO();
    double sumWaterWeight = 0.0d;
    double sumWaterDeductionWeight = 0.0d;
    double madSubTotal = 0.0d;
    double adSubTotal = 0.0d;
    double vdSubTotal = 0.0d;
    double gValueTotal = 0.0d;
    double qnetArTotal = 0.0d;
    
    double monthWaterWeight = 0.0d;
    double monthWaterDeductionWeight = 0.0d;
    double monthMadSubTotal = 0.0d;
    double monthAdSubTotal = 0.0d;
    double monthVdSubTotal = 0.0d;
    double monthGValueTotal = 0.0d;
    double monthQnetArTotal = 0.0d;
    
    for (CsbProductSalesReportVO item : v) {
        if (item.getSampleTime() != null) {
            if (DateUtils.after(item.getSampleTime(), vo.getStartTime()) && DateUtils.before(item.getSampleTime(), vo.getEndTime())) {
                if (item.getWaterWeight() != null) {
                    monthWaterWeight += item.getWaterWeight();
                }
                if (item.getWaterDeductionWeight() != null) {
                    monthWaterDeductionWeight += item.getWaterDeductionWeight();
                    if (item.getMt() != null) {
                        monthMadSubTotal += item.getMt() * item.getWaterDeductionWeight();
                    }
                    if (item.getAd() != null) {
                        monthAdSubTotal += item.getAd() * item.getWaterDeductionWeight();
                    }
                    if (item.getVd() != null) {
                        monthVdSubTotal += item.getVd() * item.getWaterDeductionWeight();
                    }
                    if (item.getGvalue() != null) {
                        monthGValueTotal += item.getGvalue() * item.getWaterDeductionWeight();
                    }
                    if (item.getQnetAr() != null) {
                        monthQnetArTotal += item.getQnetAr() * item.getWaterDeductionWeight();
                    }
                }
            }
        }
        
        if (item.getWaterWeight() != null) {
            sumWaterWeight += item.getWaterWeight();
        }
        
        if (item.getWaterDeductionWeight() != null) {
            sumWaterDeductionWeight += item.getWaterDeductionWeight();
            if (item.getMt() != null) {
                madSubTotal += item.getMt() * item.getWaterDeductionWeight();
            }
            if (item.getAd() != null) {
                adSubTotal += item.getAd() * item.getWaterDeductionWeight();
            }
            if (item.getVd() != null) {
                vdSubTotal += item.getVd() * item.getWaterDeductionWeight();
            }
            if (item.getGvalue() != null) {
                gValueTotal += item.getGvalue() * item.getWaterDeductionWeight();
            }
            if (item.getQnetAr() != null) {
                qnetArTotal += item.getQnetAr() * item.getWaterDeductionWeight();
            }
        }
    }
    
    statisticDto.setVarietiesName(varietiesName);
    statisticDto.setWaterWeight(Arith.round(monthWaterWeight, 2));
    statisticDto.setWaterDeductionWeight(Arith.round(monthWaterDeductionWeight, 2));
    statisticDto.setMt(Arith.div(monthMadSubTotal, monthWaterDeductionWeight, 2));
    statisticDto.setAd(Arith.div(monthAdSubTotal, monthWaterDeductionWeight, 2));
    statisticDto.setVd(Arith.div(monthVdSubTotal, monthWaterDeductionWeight, 2));
    statisticDto.setGvalue(Arith.div(monthGValueTotal, monthWaterDeductionWeight, 2));
    statisticDto.setQnetAr(Arith.div(monthQnetArTotal, monthWaterDeductionWeight, 2));
    
    statisticDto.setSumWaterDeductionWeight(Arith.round(sumWaterDeductionWeight, 2));
    statisticDto.setSumWaterWeight(Arith.round(sumWaterWeight, 2));
    statisticDto.setSumAd(Arith.div(adSubTotal, sumWaterDeductionWeight, 2));
    statisticDto.setSumMt(Arith.div(madSubTotal, sumWaterDeductionWeight, 2));
    statisticDto.setSumRd(Arith.div(vdSubTotal, sumWaterDeductionWeight, 2));
    statisticDto.setSumGvalue(Arith.div(gValueTotal, sumWaterDeductionWeight, 2));
    statisticDto.setSumQnetAr(Arith.div(qnetArTotal, sumWaterDeductionWeight, 2));
    
    res.add(statisticDto);
    
    allSumWaterWeight += sumWaterWeight;
    allSumWaterDeductionWeight += sumWaterDeductionWeight;
    allMonthWaterWeight += monthWaterWeight;
    allMonthWaterDeductionWeight += monthWaterDeductionWeight;
}

List<String> resVarieties = res.stream()
        .map(ExportCommercialCoalDTO::getVarietiesName)
        .collect(Collectors.toList());
fillVarietiesName(queryVarietiesName, resVarieties, varieties, res);

all.setVarietiesName("合计");
all.setWaterWeight(Arith.round(allMonthWaterWeight, 2));
all.setWaterDeductionWeight(Arith.round(allMonthWaterDeductionWeight, 2));
all.setSumWaterWeight(Arith.round(allSumWaterWeight, 2));
all.setSumWaterDeductionWeight(Arith.round(allSumWaterDeductionWeight, 2));
res.add(all);

return res;

}

优化下述代码 public ListExportCommercialCoalDTO selectGroupByVarietiesNameCsbProductSalesReportVO vo ListExportCommercialCoalDTO res = new LinkedList; ListCsbCoalTypeReportPO csbCoalTypeRepor

原文地址: https://www.cveoy.top/t/topic/i82N 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录