|
@@ -114,6 +114,8 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
|
|
|
RestTemplate restTemplate;
|
|
|
@Resource
|
|
|
private ProductMapper productMapper;
|
|
|
+ @Resource
|
|
|
+ private ProdProcedureMapper prodProcedureMapper;
|
|
|
|
|
|
@Value(value = "${upload.path}")
|
|
|
private String path;
|
|
@@ -4598,4 +4600,87 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
|
|
|
}
|
|
|
return httpRespMsg;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg productionQuantityList(Integer productId, String startDate, String endDate) {
|
|
|
+ HttpRespMsg msg=new HttpRespMsg();
|
|
|
+ Integer companyId = userMapper.selectById(request.getHeader("token")).getCompanyId();
|
|
|
+ //获取所有产品信息
|
|
|
+ List<Product> products = productMapper.selectList(new LambdaQueryWrapper<Product>().eq(productId != null, Product::getId, productId).eq(Product::getCompanyId,companyId));
|
|
|
+ List<Integer> productIds = products.stream().map(Product::getId).distinct().collect(Collectors.toList());
|
|
|
+ //获取产品下的所有工序数据
|
|
|
+ List<ProdProcedure> prodProcedureList = prodProcedureMapper.selectList(new LambdaQueryWrapper<ProdProcedure>().in(productIds != null, ProdProcedure::getProductId, productIds).eq(ProdProcedure::getCompanyId,companyId));
|
|
|
+ //获取产品下所有已完工的日报数据
|
|
|
+ LambdaQueryWrapper<Report> reportLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ reportLambdaQueryWrapper.eq(Report::getStatus, 2).in(productIds != null, Report::getProductId, productIds).eq(Report::getCompanyId,companyId);
|
|
|
+ if(!StringUtils.isEmpty(startDate)&&!StringUtils.isEmpty(endDate)){
|
|
|
+ reportLambdaQueryWrapper.between(Report::getCreateDate,startDate,endDate);
|
|
|
+ }
|
|
|
+ List<Report> reportList = reportMapper.selectList(reportLambdaQueryWrapper);
|
|
|
+ List<Integer> reportIds = reportList.stream().map(Report::getId).distinct().collect(Collectors.toList());
|
|
|
+ List<ReportSteelNum> reportSteelNums = reportSteelNumMapper.selectList(new LambdaQueryWrapper<ReportSteelNum>().in(reportIds != null, ReportSteelNum::getReportId, reportIds));
|
|
|
+ List<Map<String,Object>> resultMapList=new ArrayList<>();
|
|
|
+ for (Product product : products) {
|
|
|
+ Map<String,Object> resultMap=new HashMap<>();
|
|
|
+ resultMap.put("productName",product.getName());
|
|
|
+ //完整件数
|
|
|
+ Integer integrated=0;
|
|
|
+ //凑整件数
|
|
|
+ Integer rounding=0;
|
|
|
+ //
|
|
|
+ Integer converted=0;
|
|
|
+ //找到产品下的工序
|
|
|
+ List<ProdProcedure> targetProdProcedures = prodProcedureList.stream().filter(p -> p.getProductId().equals(product.getId())).collect(Collectors.toList());
|
|
|
+ //过滤工序id 作为完整件数 需要路过的全部工序
|
|
|
+ List<Integer> targetProdProduceIds = targetProdProcedures.stream().map(ProdProcedure::getId).collect(Collectors.toList());
|
|
|
+ //找到产品下的所日报
|
|
|
+ List<Report> targetReportList = reportList.stream().filter(r ->r.getProductId()!=null&& r.getProductId().equals(product.getId())).collect(Collectors.toList());
|
|
|
+ //找到目标下的所有钢印号数据
|
|
|
+ List<Integer> targetReportIds = targetReportList.stream().map(Report::getId).distinct().collect(Collectors.toList());
|
|
|
+ //过滤已经填报过的所有钢印号去重
|
|
|
+ List<ReportSteelNum> targetReportSteelNums = reportSteelNums.stream().filter(r -> targetReportIds.contains(r.getReportId())).collect(Collectors.toList());
|
|
|
+ List<String> steelNums = targetReportSteelNums.stream().map(ReportSteelNum::getSteelNum).distinct().collect(Collectors.toList());
|
|
|
+ for (String steelNum : steelNums) {
|
|
|
+ //找到该产品下填报了该钢印号的所有日报数据
|
|
|
+ List<Integer> hasReportIds = reportSteelNums.stream().filter(r -> r.getSteelNum().equals(steelNum)).collect(Collectors.toList()).stream().map(ReportSteelNum::getReportId).collect(Collectors.toList());
|
|
|
+ List<Report> hasReportList = targetReportList.stream().filter(r->hasReportIds.contains(r.getId())).collect(Collectors.toList());
|
|
|
+ //过滤日报所填了哪些工序
|
|
|
+ List<Integer> hasReportProdProduceIds = hasReportList.stream().map(Report::getProdProcedureId).collect(Collectors.toList());
|
|
|
+ //如果全包含了所需路过的全部工序内容 就算完整件数
|
|
|
+ if(hasReportProdProduceIds.containsAll(targetProdProduceIds)){
|
|
|
+ integrated+=1;
|
|
|
+ }else {
|
|
|
+ //如果没有包含所需路过的全部工序内容 (有任意工序可以共同完成)-->凑整
|
|
|
+ //根据当前钢印号已经填报的内容 对比出没有填报的工序内容
|
|
|
+ List<Integer> hasNotReportProdProduceIds=new ArrayList<>();
|
|
|
+ targetProdProduceIds.forEach(tp->{
|
|
|
+ if(!hasReportProdProduceIds.contains(tp)){
|
|
|
+ hasNotReportProdProduceIds.add(tp);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //所有已填报的钢印号有任意满足 上面未填报工序集合 就算凑整件数
|
|
|
+ //找到所有填报了未填报工序日报数据
|
|
|
+ List<Report> comparatorReportList = targetReportList.stream().filter(r ->r.getProdProcedureId()!=null && hasNotReportProdProduceIds.contains(r.getProdProcedureId())).collect(Collectors.toList());
|
|
|
+ //过滤这些日报下的工序数据
|
|
|
+ List<Integer> targetComparator = comparatorReportList.stream().map(Report::getProdProcedureId).distinct().collect(Collectors.toList());
|
|
|
+ boolean match = targetComparator.containsAll(hasNotReportProdProduceIds);
|
|
|
+ if(match){
|
|
|
+ rounding+=1;
|
|
|
+ }else {
|
|
|
+ converted+=1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ resultMap.put("integrated",integrated);
|
|
|
+ resultMap.put("rounding",rounding);
|
|
|
+ resultMap.put("converted",converted);
|
|
|
+ BigDecimal bigDecimal=new BigDecimal(integrated);
|
|
|
+ bigDecimal=bigDecimal.add(new BigDecimal(rounding)).add(new BigDecimal(converted));
|
|
|
+ resultMap.put("total",bigDecimal.doubleValue());
|
|
|
+ resultMapList.add(resultMap);
|
|
|
+ }
|
|
|
+ msg.setData(resultMapList);
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
}
|