|
@@ -1,11 +1,23 @@
|
|
|
package org.jeecg.modules.billet.rollOutShipp.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import org.jeecg.common.util.oConvertUtils;
|
|
|
+import org.jeecg.modules.billet.rollHeight.entity.DestinationStatistics;
|
|
|
+import org.jeecg.modules.billet.rollHeight.entity.DestinationStatisticsDetails;
|
|
|
import org.jeecg.modules.billet.rollOutShipp.entity.RollOutShipp;
|
|
|
+import org.jeecg.modules.billet.rollOutShipp.entity.RollOutShippDetails;
|
|
|
import org.jeecg.modules.billet.rollOutShipp.mapper.RollOutShippMapper;
|
|
|
+import org.jeecg.modules.billet.rollOutShipp.service.IRollOutShippDetailsService;
|
|
|
import org.jeecg.modules.billet.rollOutShipp.service.IRollOutShippService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
/**
|
|
|
* @Description: 上若
|
|
|
* @Author: jeecg-boot
|
|
@@ -14,4 +26,64 @@ import org.springframework.stereotype.Service;
|
|
|
*/
|
|
|
@Service
|
|
|
public class RollOutShippServiceImpl extends ServiceImpl<RollOutShippMapper, RollOutShipp> implements IRollOutShippService {
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IRollOutShippDetailsService rollOutShippDetailsService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public DestinationStatistics queryByCcmNoHandle(String ccmNo) {
|
|
|
+
|
|
|
+ DestinationStatistics destinationStatistics = new DestinationStatistics();
|
|
|
+// LambdaQueryWrapper<RollOutShipp> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+// if (oConvertUtils.isNotEmpty(ccmNo)){
|
|
|
+// queryWrapper.eq(RollOutShipp::getCcmNo, ccmNo);
|
|
|
+// }
|
|
|
+// List<RollOutShipp> rollOutShippsList = baseMapper.selectList(queryWrapper);
|
|
|
+// if (oConvertUtils.listIsEmpty(rollOutShippsList)){
|
|
|
+// return null;
|
|
|
+// }
|
|
|
+// Integer amountTotal = rollOutShippsList.stream().map(RollOutShipp::getAmountTotal).reduce(0, Integer::sum);
|
|
|
+// // 先将每个RollHeight对象中的heightValue属性值乘以blankOutput,再求和
|
|
|
+// double sumResult = rollOutShippsList.stream().mapToDouble(x -> x.getAmountTotal() * x.getBlankOutput()).sum();
|
|
|
+// BigDecimal bd = BigDecimal.valueOf(sumResult).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+// double finalResult = bd.doubleValue();
|
|
|
+// destinationStatistics.setCounts(amountTotal);
|
|
|
+// destinationStatistics.setBlankOutput(finalResult);
|
|
|
+ LambdaQueryWrapper<RollOutShippDetails> queryWrapperDetails = new LambdaQueryWrapper<>();
|
|
|
+ if (oConvertUtils.isNotEmpty(ccmNo)){
|
|
|
+ queryWrapperDetails.eq(RollOutShippDetails::getCcmNo, ccmNo);
|
|
|
+ }
|
|
|
+ List<RollOutShippDetails> rollOutShippDetailsList = rollOutShippDetailsService.list(queryWrapperDetails);
|
|
|
+ if (oConvertUtils.listIsEmpty(rollOutShippDetailsList)){
|
|
|
+ return destinationStatistics;
|
|
|
+ }
|
|
|
+ // 根据size属性进行分组,并统计每组的总数和总重
|
|
|
+ Map<String, Double> sumBySize = rollOutShippDetailsList.stream().collect(Collectors.groupingBy(RollOutShippDetails::getSize,Collectors.summingDouble(RollOutShippDetails::getBlankOutput)));
|
|
|
+ Map<String, Double> resultMap = sumBySize.entrySet().stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ Map.Entry::getKey,
|
|
|
+ entry -> Double.parseDouble(String.format("%.2f", entry.getValue()))
|
|
|
+ ));
|
|
|
+ Map<String, Long> countBySize = rollOutShippDetailsList.stream().collect(Collectors.groupingBy(RollOutShippDetails::getSize, Collectors.counting()));
|
|
|
+
|
|
|
+ List<DestinationStatisticsDetails> rollOutShippDetailsStatisticsList = new ArrayList<>();
|
|
|
+ sumBySize.forEach((size, totalWeight) -> {
|
|
|
+ long count = countBySize.get(size);
|
|
|
+ rollOutShippDetailsStatisticsList.add(new DestinationStatisticsDetails(size, (int) count, totalWeight));
|
|
|
+ });
|
|
|
+ Integer sums = rollOutShippDetailsStatisticsList.stream()
|
|
|
+ .map(DestinationStatisticsDetails::getNums)
|
|
|
+ .reduce(0, Integer::sum);
|
|
|
+ // 使用String.format方法对求和结果保留两位小数
|
|
|
+ double blankOutputSum = rollOutShippDetailsStatisticsList.stream()
|
|
|
+ .mapToDouble(DestinationStatisticsDetails::getBlankOutput)
|
|
|
+ .sum();
|
|
|
+ String formattedResult = String.format("%.2f", blankOutputSum);
|
|
|
+ double finalBlankOutputSum = Double.parseDouble(formattedResult);
|
|
|
+ destinationStatistics.setCounts(sums);
|
|
|
+ destinationStatistics.setBlankOutput(finalBlankOutputSum);
|
|
|
+ destinationStatistics.setStatisticsDetailsList(rollOutShippDetailsStatisticsList);
|
|
|
+ return destinationStatistics;
|
|
|
+ }
|
|
|
}
|