package com.ruoyi.business.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.ruoyi.basic.entity.CoalInfo; import com.ruoyi.basic.entity.CoalPlan; import com.ruoyi.basic.entity.CoalValue; import com.ruoyi.basic.entity.Customer; import com.ruoyi.basic.mapper.CoalInfoMapper; import com.ruoyi.basic.mapper.CoalPlanMapper; import com.ruoyi.basic.mapper.CoalValueMapper; import com.ruoyi.basic.mapper.CustomerMapper; import com.ruoyi.business.dto.*; import com.ruoyi.business.entity.*; import com.ruoyi.business.mapper.*; import com.ruoyi.business.service.ProductHomeService; import com.ruoyi.common.core.domain.R; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import java.math.BigDecimal; import java.math.RoundingMode; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.time.format.DateTimeFormatter; import java.util.*; import java.util.stream.Collectors; /** * @author :yys * @date : 2025/10/13 9:11 */ @Service @Slf4j public class ProductHomeServiceImpl implements ProductHomeService { @Autowired private ProductionMapper productionMapper; @Autowired private ProductionSchedulingMapper productionSchedulingMapper; @Autowired private OfficialInventoryMapper officialInventoryMapper; @Autowired private SalesRecordMapper salesRecordMapper; @Autowired private CoalInfoMapper coalInfoMapper; @Autowired private CustomerMapper customerMapper; @Autowired private PurchaseRegistrationMapper purchaseRegistrationMapper; @Autowired private CoalValueMapper coalValueMapper; @Autowired private CoalPlanMapper coalPlanMapper; @Override public R productionSchedulingStatistics(DateQueryDto dto) { String start = dto.getEntryDateStart(); String end = dto.getEntryDateEnd(); // 使用 LambdaQueryWrapper 构建查询条件 LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); if (start != null && !start.isEmpty() && end != null && !end.isEmpty()) { wrapper.between(ProductionScheduling::getSchedulingDate, LocalDate.parse(start, DateTimeFormatter.ISO_LOCAL_DATE), LocalDate.parse(end, DateTimeFormatter.ISO_LOCAL_DATE)); } List schedulingList = productionSchedulingMapper.selectList(wrapper); ProductionSchedulingStatisticsDto result = new ProductionSchedulingStatisticsDto(); BigDecimal totalScheduling = BigDecimal.ZERO; BigDecimal completedScheduling = BigDecimal.ZERO; BigDecimal pendingScheduling = BigDecimal.ZERO; for (ProductionScheduling scheduling : schedulingList) { BigDecimal num = scheduling.getSchedulingNum(); if (num != null) { totalScheduling = totalScheduling.add(num); if (scheduling.getStatus() == 3) { // 已报工 completedScheduling = completedScheduling.add(num); } else if (scheduling.getStatus() == 1) { // 待生产 pendingScheduling = pendingScheduling.add(num); } } } result.setTotalOutput(totalScheduling); result.setCompletedScheduling(completedScheduling); result.setPendingScheduling(pendingScheduling); return R.ok(result); } @Override public R> productionSchedulingStatisticsList(DateQueryDto dto) { String start = dto.getEntryDateStart(); String end = dto.getEntryDateEnd(); // 使用 LambdaQueryWrapper 构建查询条件 LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); if (start != null && !start.isEmpty() && end != null && !end.isEmpty()) { wrapper.between(ProductionScheduling::getSchedulingDate, LocalDate.parse(start, DateTimeFormatter.ISO_LOCAL_DATE), LocalDate.parse(end, DateTimeFormatter.ISO_LOCAL_DATE)); } List schedulingList = productionSchedulingMapper.selectList(wrapper); // 通过煤种id获取煤种名称 schedulingList.forEach(scheduling -> { CoalInfo coalInfo = coalInfoMapper.selectById(scheduling.getCoalId()); scheduling.setCoalName(coalInfo.getCoal()); }); return R.ok(schedulingList); } @Override public R> productionSchedulingInventoryList(DateQueryDto dto) { String start = dto.getEntryDateStart(); String end = dto.getEntryDateEnd(); // 使用 LambdaQueryWrapper 构建查询条件 LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); if (start != null && !start.isEmpty() && end != null && !end.isEmpty()) { wrapper.between(OfficialInventory::getRegistrationDate, LocalDate.parse(start, DateTimeFormatter.ISO_LOCAL_DATE), LocalDate.parse(end, DateTimeFormatter.ISO_LOCAL_DATE)); } List schedulingList = officialInventoryMapper.selectList(wrapper); schedulingList.forEach(scheduling -> { CoalInfo coalInfo = coalInfoMapper.selectById(scheduling.getCoalId()); scheduling.setCoalName(coalInfo.getCoal()); }); return R.ok(schedulingList); } @Override public R materialStatistics(DateQueryDto dto) { MaterialStatisticsDto result = new MaterialStatisticsDto(); // 获取今日开始时间,结束时间 LocalDateTime todayStart = LocalDateTime.of( LocalDateTime.now().toLocalDate(), LocalTime.MIN ); LocalDateTime todayEnd = LocalDateTime.of( LocalDateTime.now().toLocalDate(), LocalTime.MAX ); // 使用 LambdaQueryWrapper 构建查询条件 LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.between(OfficialInventory::getRegistrationDate, todayStart, todayEnd); // 获取今日入库总量 List officialInventories = officialInventoryMapper.selectList(wrapper); if (!CollectionUtils.isEmpty(officialInventories)) { BigDecimal todayInboundTotal = officialInventories.stream() .map(OfficialInventory::getInventoryQuantity) .reduce(BigDecimal.ZERO, BigDecimal::add); result.setTodayInboundTotal(todayInboundTotal); } // 获取当前库存总量 R> listR = productionSchedulingInventoryList(dto); if (R.isSuccess(listR)) { List officialInventoriesList = listR.getData(); if (!CollectionUtils.isEmpty(officialInventoriesList)) { BigDecimal todayOutboundTotal = officialInventoriesList.stream() .map(OfficialInventory::getInventoryQuantity) .reduce(BigDecimal.ZERO, BigDecimal::add); result.setTodayOutboundTotal(todayOutboundTotal); } } // 获取今日出库总量 // 使用 LambdaQueryWrapper 构建查询条件 LambdaQueryWrapper wrapperSalesRecord = new LambdaQueryWrapper<>(); wrapperSalesRecord.between(SalesRecord::getSaleDate, todayStart, todayEnd); // 获取今日入库总量 List salesRecords = salesRecordMapper.selectList(wrapperSalesRecord); if (!CollectionUtils.isEmpty(salesRecords)) { BigDecimal todayInboundTotal = salesRecords.stream() .map(SalesRecord::getInventoryQuantity) .reduce(BigDecimal.ZERO, BigDecimal::add); result.setTodayOutboundTotal(todayInboundTotal); } return R.ok(result); } @Override public R> coalTypeDistribution(DateQueryDto dto) { String start = dto.getEntryDateStart(); String end = dto.getEntryDateEnd(); // 获取煤种列表 List coalInfoList = coalInfoMapper.selectList(null); // 使用 LambdaQueryWrapper 构建查询条件 LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); if (start != null && !start.isEmpty() && end != null && !end.isEmpty()) { wrapper.between(SalesRecord::getRegistrationDate, LocalDate.parse(start, DateTimeFormatter.ISO_LOCAL_DATE), LocalDate.parse(end, DateTimeFormatter.ISO_LOCAL_DATE)); } List salesRecords = salesRecordMapper.selectList(wrapper); // 根据煤种进行分组,并计算占比 Map> coalTypeMap = salesRecords.stream() .collect(Collectors.groupingBy(SalesRecord::getCoalId)); List itemListDtos = coalInfoList.stream().map(coalInfo -> { ItemListDto itemListDto = new ItemListDto(); itemListDto.setName(coalInfo.getCoal()); // 计算该煤种的销售记录总数量 List records = coalTypeMap.getOrDefault(coalInfo.getId(), Collections.emptyList()); BigDecimal totalQuantity = records.stream() .map(SalesRecord::getInventoryQuantity) .reduce(BigDecimal.ZERO, BigDecimal::add); itemListDto.setValue(totalQuantity); return itemListDto; }).collect(Collectors.toList()); // 计算所有煤种的销售总量 BigDecimal totalAll = itemListDtos.stream() .map(ItemListDto::getValue) .reduce(BigDecimal.ZERO, BigDecimal::add); // 设置占比 for (ItemListDto item : itemListDtos) { if (totalAll.compareTo(BigDecimal.ZERO) > 0) { BigDecimal percentage = item.getValue().multiply(BigDecimal.valueOf(100)) .divide(totalAll, 2, RoundingMode.HALF_UP); item.setPercent(percentage); } else { item.setPercent(BigDecimal.ZERO); } } return R.ok(itemListDtos); } @Override public R> originDistribution(DateQueryDto dto) { String start = dto.getEntryDateStart(); String end = dto.getEntryDateEnd(); // 获取客户列表 List coalInfoList = customerMapper.selectList(null); // 使用 LambdaQueryWrapper 构建查询条件 LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); if (start != null && !start.isEmpty() && end != null && !end.isEmpty()) { wrapper.between(SalesRecord::getRegistrationDate, LocalDate.parse(start, DateTimeFormatter.ISO_LOCAL_DATE), LocalDate.parse(end, DateTimeFormatter.ISO_LOCAL_DATE)); } List salesRecords = salesRecordMapper.selectList(wrapper); // 根据煤种进行分组,并计算占比 Map> coalTypeMap = salesRecords.stream() .collect(Collectors.groupingBy(SalesRecord::getCustomerId)); List itemListDtos = coalInfoList.stream().map(coalInfo -> { ItemListDto itemListDto = new ItemListDto(); itemListDto.setName(coalInfo.getCustomerName()); // 计算该煤种的销售记录总数量 List records = coalTypeMap.getOrDefault(coalInfo.getId(), Collections.emptyList()); BigDecimal totalQuantity = records.stream() .map(SalesRecord::getInventoryQuantity) .reduce(BigDecimal.ZERO, BigDecimal::add); itemListDto.setValue(totalQuantity); return itemListDto; }).collect(Collectors.toList()); // 计算所有煤种的销售总量 BigDecimal totalAll = itemListDtos.stream() .map(ItemListDto::getValue) .reduce(BigDecimal.ZERO, BigDecimal::add); // 设置占比 for (ItemListDto item : itemListDtos) { if (totalAll.compareTo(BigDecimal.ZERO) > 0) { BigDecimal percentage = item.getValue().multiply(BigDecimal.valueOf(100)) .divide(totalAll, 2, RoundingMode.HALF_UP); item.setPercent(percentage); } else { item.setPercent(BigDecimal.ZERO); } } return R.ok(itemListDtos); } @Override public R> carCodeDistribution(DateQueryDto dto) { String start = dto.getEntryDateStart(); String end = dto.getEntryDateEnd(); // 使用 LambdaQueryWrapper 构建查询条件 LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); if (start != null && !start.isEmpty() && end != null && !end.isEmpty()) { wrapper.between(PurchaseRegistration::getRegistrationDate, LocalDate.parse(start, DateTimeFormatter.ISO_LOCAL_DATE), LocalDate.parse(end, DateTimeFormatter.ISO_LOCAL_DATE)); } List purchaseRegistrations = purchaseRegistrationMapper.selectList(wrapper); // 通过车牌号分组获取次数,计算总量 Map> carMap = purchaseRegistrations.stream() .collect(Collectors.groupingBy(PurchaseRegistration::getLicensePlate)); List carDtos = carMap.entrySet().stream().map(entry -> { CarDto carDto = new CarDto(); carDto.setCode(entry.getKey()); carDto.setCount(entry.getValue().size()); carDto.setTotal(entry.getValue().stream() .map(PurchaseRegistration::getPurchaseQuantity) .reduce(BigDecimal.ZERO, BigDecimal::add)); return carDto; }).collect(Collectors.toList()); return R.ok(carDtos); } @Override public R> recentTransaction(DateQueryDto dto) { String start = dto.getEntryDateStart(); String end = dto.getEntryDateEnd(); // 使用 LambdaQueryWrapper 构建查询条件 LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); if (start != null && !start.isEmpty() && end != null && !end.isEmpty()) { wrapper.between(PurchaseRegistration::getRegistrationDate, LocalDate.parse(start, DateTimeFormatter.ISO_LOCAL_DATE), LocalDate.parse(end, DateTimeFormatter.ISO_LOCAL_DATE)); } List purchaseRegistrations = purchaseRegistrationMapper.selectList(wrapper); purchaseRegistrations.forEach(purchaseRegistration -> { purchaseRegistration.setCoalName(coalInfoMapper.selectById(purchaseRegistration.getCoalId()).getCoal()); }); return R.ok(purchaseRegistrations); } @Override public R> heatValueDistribution(DateQueryDto dto) { String start = dto.getEntryDateStart(); String end = dto.getEntryDateEnd(); LambdaQueryWrapper officialInventoryLambdaQueryWrapper = new LambdaQueryWrapper<>(); if (start != null && !start.isEmpty() && end != null && !end.isEmpty()) { officialInventoryLambdaQueryWrapper.between(OfficialInventory::getRegistrationDate, LocalDate.parse(start, DateTimeFormatter.ISO_LOCAL_DATE), LocalDate.parse(end, DateTimeFormatter.ISO_LOCAL_DATE)); } List officialInventories = officialInventoryMapper.selectList(officialInventoryLambdaQueryWrapper); Map heatValueMap = new HashMap<>(); BigDecimal totalQuantity = BigDecimal.ZERO; for (OfficialInventory officialInventory : officialInventories) { List coalValues = coalValueMapper.selectList(new LambdaQueryWrapper() .eq(CoalValue::getPlanId, officialInventory.getId()) .eq(CoalValue::getFieldName, "发热量")); if (coalValues != null && !coalValues.isEmpty()) { // 根据发热量值进行分类统计 heatValueMap.put("4000以下", BigDecimal.ZERO); heatValueMap.put("4000-4500", BigDecimal.ZERO); heatValueMap.put("4500-5000", BigDecimal.ZERO); heatValueMap.put("5000-5500", BigDecimal.ZERO); heatValueMap.put("5500-6000", BigDecimal.ZERO); heatValueMap.put("6000+", BigDecimal.ZERO); for (CoalValue coalValue : coalValues) { BigDecimal heatValue = BigDecimal.valueOf(Long.parseLong(coalValue.getCoalValue())); if (heatValue == null) continue; if (heatValue.compareTo(BigDecimal.valueOf(4000)) < 0) { heatValueMap.put("4000以下", heatValueMap.get("4000以下").add(officialInventory.getInventoryQuantity())); } else if (heatValue.compareTo(BigDecimal.valueOf(4000)) >= 0 && heatValue.compareTo(BigDecimal.valueOf(4500)) < 0) { heatValueMap.put("4000-4500", heatValueMap.get("4000-4500").add(officialInventory.getInventoryQuantity())); } else if (heatValue.compareTo(BigDecimal.valueOf(4500)) >= 0 && heatValue.compareTo(BigDecimal.valueOf(5000)) < 0) { heatValueMap.put("4500-5000", heatValueMap.get("4500-5000").add(officialInventory.getInventoryQuantity())); } else if (heatValue.compareTo(BigDecimal.valueOf(5000)) >= 0 && heatValue.compareTo(BigDecimal.valueOf(5500)) < 0) { heatValueMap.put("5000-5500", heatValueMap.get("5000-5500").add(officialInventory.getInventoryQuantity())); } else if (heatValue.compareTo(BigDecimal.valueOf(5500)) >= 0 && heatValue.compareTo(BigDecimal.valueOf(6000)) < 0) { heatValueMap.put("5500-6000", heatValueMap.get("5500-6000").add(officialInventory.getInventoryQuantity())); } else { heatValueMap.put("6000+", heatValueMap.get("6000+").add(officialInventory.getInventoryQuantity())); } } } } // 计算总量 totalQuantity = heatValueMap.values().stream().reduce(BigDecimal.ZERO, BigDecimal::add); // 将结果转换为 ItemListDto 列表 BigDecimal finalTotalQuantity = totalQuantity; List itemListDtos = heatValueMap.entrySet().stream() .map(entry -> { ItemListDto itemListDto = new ItemListDto(); itemListDto.setName(entry.getKey()); itemListDto.setValue(entry.getValue()); if (finalTotalQuantity.compareTo(BigDecimal.ZERO) > 0) { BigDecimal percentage = entry.getValue().multiply(BigDecimal.valueOf(100)) .divide(finalTotalQuantity, 2, RoundingMode.HALF_UP); itemListDto.setPercent(percentage); } return itemListDto; }) .collect(Collectors.toList()); return R.ok(itemListDtos); } @Override public R reportStatistics(DateQueryDto dto) { ReportStatisticsDto reportStatisticsDto = new ReportStatisticsDto(); String start = dto.getEntryDateStart(); String end = dto.getEntryDateEnd(); LambdaQueryWrapper officialInventoryLambdaQueryWrapper = new LambdaQueryWrapper<>(); if (start != null && !start.isEmpty() && end != null && !end.isEmpty()) { officialInventoryLambdaQueryWrapper.between(OfficialInventory::getRegistrationDate, LocalDate.parse(start, DateTimeFormatter.ISO_LOCAL_DATE), LocalDate.parse(end, DateTimeFormatter.ISO_LOCAL_DATE)); } List officialInventories = officialInventoryMapper.selectList(officialInventoryLambdaQueryWrapper); if(!CollectionUtils.isEmpty(officialInventories)){ BigDecimal reduce = officialInventories.stream() .map(OfficialInventory::getInventoryQuantity) .reduce(BigDecimal.ZERO, BigDecimal::add); List coalValues = coalValueMapper.selectList(new LambdaQueryWrapper() .in(CoalValue::getPlanId, officialInventories.stream().map(OfficialInventory::getId).collect(Collectors.toList())) .eq(CoalValue::getFieldName, "发热量")); BigDecimal totalQuantity = coalValues.stream() .map(coalValue -> BigDecimal.valueOf(Long.parseLong(coalValue.getCoalValue()))) .reduce(BigDecimal.ZERO, BigDecimal::add); long count = coalValues.stream() .filter(coalValue -> BigDecimal.valueOf(Long.parseLong(coalValue.getCoalValue())).compareTo(BigDecimal.valueOf(5000)) >= 0) .count(); if (!coalValues.isEmpty()){ // 单位热值耗煤量 = reduce * 1000 / totalQuantity BigDecimal heatValue = reduce.multiply(BigDecimal.valueOf(1000)).divide(totalQuantity, 2, RoundingMode.HALF_UP); reportStatisticsDto.setUnitHeatValue(heatValue); // 平均发热量 reportStatisticsDto.setAverageFuel(totalQuantity.divide(BigDecimal.valueOf(coalValues.size()), 2, RoundingMode.HALF_UP)); // 整体达标率(发热量≥5000大卡) BigDecimal wholeStandardRate = BigDecimal.valueOf(count).divide(BigDecimal.valueOf(coalValues.size()), 2, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)); reportStatisticsDto.setWholeStandardRate(wholeStandardRate); }else{ reportStatisticsDto.setAverageFuel(BigDecimal.ZERO); reportStatisticsDto.setWholeStandardRate(BigDecimal.ZERO); reportStatisticsDto.setUnitHeatValue(BigDecimal.ZERO); } } return R.ok(reportStatisticsDto); } @Override public R> reportTrend(DateQueryDto dto) { List lastFiveDaysQuery = getLastFiveDaysQuery(); List itemListDtos = new ArrayList<>(); for (LocalDate s : lastFiveDaysQuery) { ItemListDto itemListDto = new ItemListDto(); itemListDto.setName(s.toString()); LambdaQueryWrapper officialInventoryLambdaQueryWrapper = new LambdaQueryWrapper<>(); // 在s后面拼上00:00:00 officialInventoryLambdaQueryWrapper.eq(OfficialInventory::getRegistrationDate, s); List officialInventories = officialInventoryMapper.selectList(officialInventoryLambdaQueryWrapper); if(!CollectionUtils.isEmpty(officialInventories)){ List coalValues = coalValueMapper.selectList(new LambdaQueryWrapper() .in(CoalValue::getPlanId, officialInventories.stream().map(OfficialInventory::getId).collect(Collectors.toList())) .eq(CoalValue::getFieldName, "发热量")); // 整体达标率(发热量≥5000大卡) long count = coalValues.stream() .filter(coalValue -> BigDecimal.valueOf(Long.parseLong(coalValue.getCoalValue())).compareTo(BigDecimal.valueOf(5000)) >= 0) .count(); // 判断除数不能为零的情况 if (!coalValues.isEmpty()) { BigDecimal wholeStandardRate = BigDecimal.valueOf(count).divide(BigDecimal.valueOf(coalValues.size()), 2, RoundingMode.HALF_UP); itemListDto.setValue(wholeStandardRate); }else{ itemListDto.setValue(BigDecimal.ZERO); } } itemListDtos.add(itemListDto); } return R.ok(itemListDtos); } @Override public R> coalTypeHeatValueComparison(DateQueryDto dto) { List lastFiveDaysQuery = getLastFiveDaysQuery(); List itemListDtos = new ArrayList<>(); for (LocalDate s : lastFiveDaysQuery) { ItemListDto itemListDto = new ItemListDto(); itemListDto.setName(s.toString()); LambdaQueryWrapper officialInventoryLambdaQueryWrapper = new LambdaQueryWrapper<>(); // 在s后面拼上00:00:00 officialInventoryLambdaQueryWrapper.eq(OfficialInventory::getRegistrationDate, s); List officialInventories = officialInventoryMapper.selectList(officialInventoryLambdaQueryWrapper); if(!CollectionUtils.isEmpty(officialInventories)){ List coalValues = coalValueMapper.selectList(new LambdaQueryWrapper() .in(CoalValue::getPlanId, officialInventories.stream().map(OfficialInventory::getId).collect(Collectors.toList())) .eq(CoalValue::getFieldName, "发热量")); // 发热量(求和) long count = coalValues.stream() .mapToLong(coalValue -> Long.parseLong(coalValue.getCoalValue())) .sum(); itemListDto.setValue(BigDecimal.valueOf(count)); } itemListDtos.add(itemListDto); } return R.ok(itemListDtos); } @Override public R> processingRateAnalysis(DateQueryDto dto) { List lastFiveDaysQuery = getLastFiveDaysQuery(); List itemListDtos = new ArrayList<>(); for (LocalDate s : lastFiveDaysQuery) { ItemListDto itemListDto = new ItemListDto(); itemListDto.setName(s.toString()); // 获取采购数量 LambdaQueryWrapper purchaseRegistrationLambdaQueryWrapper = new LambdaQueryWrapper<>(); // 在s后面拼上00:00:00 purchaseRegistrationLambdaQueryWrapper.eq(PurchaseRegistration::getRegistrationDate, s); List purchaseRegistrations = purchaseRegistrationMapper.selectList(purchaseRegistrationLambdaQueryWrapper); if(!CollectionUtils.isEmpty(purchaseRegistrations)){ BigDecimal totalQuantity = purchaseRegistrations.stream() .map(PurchaseRegistration::getPurchaseQuantity) .reduce(BigDecimal.ZERO, BigDecimal::add); // 获取正式库存数量 LambdaQueryWrapper officialInventoryLambdaQueryWrapper = new LambdaQueryWrapper<>(); // 在s后面拼上00:00:00 officialInventoryLambdaQueryWrapper.eq(OfficialInventory::getRegistrationDate, s); List officialInventories = officialInventoryMapper.selectList(officialInventoryLambdaQueryWrapper); if(!CollectionUtils.isEmpty(officialInventories)){ BigDecimal officialInventoryQuantity = officialInventories.stream() .map(OfficialInventory::getInventoryQuantity) .reduce(BigDecimal.ZERO, BigDecimal::add); // 加工得率 = 正式库存数量/采购数量 if(!totalQuantity.equals(BigDecimal.ZERO)){ itemListDto.setValue(officialInventoryQuantity.divide(totalQuantity, 2, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100))); }else{ itemListDto.setValue(BigDecimal.ZERO); } } } itemListDtos.add(itemListDto); } return R.ok(itemListDtos); } @Override public R> costStructure(DateQueryDto dto) { List itemListDtos = new ArrayList<>(); LocalDate now = LocalDate.now(); LocalDate startDate = now.minusDays(4); LambdaQueryWrapper productionLambdaQueryWrapper = new LambdaQueryWrapper<>(); productionLambdaQueryWrapper.between(Production::getCreateTime, startDate, now); List productions = productionMapper.selectList(productionLambdaQueryWrapper); ItemListDto itemListDto = new ItemListDto(); itemListDto.setName("人工成本"); itemListDto.setValue(productions.stream() .map(Production::getLaborCost) .reduce(BigDecimal.ZERO, BigDecimal::add)); itemListDtos.add(itemListDto); ItemListDto itemListDtoOne = new ItemListDto(); itemListDtoOne.setName("能耗成本"); itemListDtoOne.setValue(productions.stream() .map(Production::getEnergyConsumptionCost) .reduce(BigDecimal.ZERO, BigDecimal::add)); itemListDtos.add(itemListDtoOne); return R.ok(itemListDtos); } /** * 获取最近五天的时间集合 */ private List getLastFiveDaysQuery() { LocalDate now = LocalDate.now(); LocalDate startDate = now.minusDays(4); List dates = new ArrayList<>(); for (int i = 0; i < 5; i++) { LocalDate date = startDate.plusDays(i); dates.add(date); } return dates; } }