| | |
| | | apsGasPipingPlans.forEach(apsGasPipingPlan -> { |
| | | List<ApsProcessRoute> apsProcessRoutes = apsGasPipingPlan.getApsProcessRoutes(); |
| | | //按照工序序号升序排序 |
| | | apsProcessRoutes.sort((a, b)->a.getProcessNumber().compareTo(b.getProcessNumber())); |
| | | apsProcessRoutes.sort((a, b)->b.getProcessNumber().compareTo(a.getProcessNumber())); |
| | | //是否找到当前工序 |
| | | boolean isFind = false; |
| | | boolean isCurrentProcess = false; |
| | | ApsGasPipingRouteStat preApsProcessRoute = null; |
| | | for (int i=0;i<apsProcessRoutes.size();i++){ |
| | | ApsProcessRoute apsProcessRoute = apsProcessRoutes.get(i); |
| | | ApsGasPipingRouteStat apsGasPipingRouteStat = new ApsGasPipingRouteStat(); |
| | |
| | | //料号 |
| | | apsGasPipingRouteStat.setItemNumber(apsGasPipingPlan.getItemNumber()); |
| | | //当前工序号 |
| | | apsGasPipingRouteStat.setCurrentProcessNumber(apsGasPipingPlan.getProcessNumber()); |
| | | apsGasPipingRouteStat.setCurrentProcessNumber(new BigDecimal(apsGasPipingPlan.getProcessNumber())); |
| | | //生产数量 |
| | | apsGasPipingRouteStat.setProductionQuantity(apsGasPipingPlan.getProductionQuantity()); |
| | | //工序名称 |
| | |
| | | apsGasPipingRouteStat.setMajor(apsGasPipingPlan.getPlanType()); |
| | | //工序总工时 等于 标准工时*生产数量 |
| | | apsGasPipingRouteStat.setProcessTotalTime(apsProcessRoute.getStandardTime().multiply(apsGasPipingPlan.getProductionQuantity())); |
| | | //计划开工日 |
| | | if(apsGasPipingRouteStat.getCurrentProcessNumber().equals(apsGasPipingRouteStat.getRoadProcessNumber())) { |
| | | //计划开工日 如果是当前序 |
| | | if(apsGasPipingRouteStat.getCurrentProcessNumber().toString().equals(apsGasPipingRouteStat.getRoadProcessNumber())) { |
| | | /* 对 stat.getProcessPlanStartDay() 和当前日期 进行对比,只对比到日,不用管十分秒*/ |
| | | LocalDate startLocalDate = LocalDate.ofInstant(apsProcessRoute.getProcessPlanStartDay().toInstant(), ZoneId.systemDefault()); |
| | | LocalDate nowLocalDate = LocalDate.now(); |
| | |
| | | }else{ |
| | | apsGasPipingRouteStat.setProcessPlanStartDay(apsProcessRoute.getProcessPlanStartDay()); |
| | | } |
| | | isFind = true; |
| | | } |
| | | if(!isFind){ |
| | | continue; |
| | | } |
| | | // 上一道工序的结束时间 = 上一道工序的开始时间 + 上一道工序的总工时 |
| | | if(apsGasPipingRouteStat.getProcessPlanStartDay()==null){ |
| | | LocalDateTime previousProcessPlanStartDay = apsProcessRoutes.get(i - 1).getProcessPlanStartDay().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); |
| | | long seconds = apsGasPipingRouteStatList.get(i - 1).getProcessTotalTime().multiply(new BigDecimal(60)).multiply(new BigDecimal(60)).longValue(); |
| | | LocalDateTime currentProcessPlanStartDay = previousProcessPlanStartDay.plusSeconds(seconds); |
| | | apsGasPipingRouteStat.setProcessPlanStartDay(Date.from(currentProcessPlanStartDay.atZone(ZoneId.systemDefault()).toInstant())); |
| | | LocalDateTime planStartDay = apsGasPipingRouteStat.getProcessPlanStartDay().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); |
| | | long seconds = apsProcessRoute.getStandardTime().multiply(apsGasPipingPlan.getProductionQuantity()).multiply(new BigDecimal(60)).multiply(new BigDecimal(60)).longValue(); |
| | | apsGasPipingRouteStat.setProcessPlanEndDay(Date.from(planStartDay.plusSeconds(seconds).atZone(ZoneId.systemDefault()).toInstant())); |
| | | isCurrentProcess = true; |
| | | }else{ |
| | | // 上一道工序的结束时间 = 上一道工序的开始时间 + 上一道工序的总工时 |
| | | if(i==0){ |
| | | apsGasPipingRouteStat.setProcessPlanEndDay(apsGasPipingPlan.getPlanEndDay()); |
| | | LocalDate endLocalDate = LocalDate.ofInstant(apsGasPipingPlan.getPlanEndDay().toInstant(), ZoneId.systemDefault()); |
| | | LocalDate nowLocalDate = LocalDate.now(); |
| | | LocalDateTime planEndDay; |
| | | if(endLocalDate.isBefore(nowLocalDate)){ |
| | | planEndDay = LocalDateTime.now(); |
| | | }else{ |
| | | planEndDay = apsGasPipingPlan.getPlanEndDay().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); |
| | | } |
| | | long seconds = apsProcessRoute.getStandardTime().multiply(apsGasPipingPlan.getProductionQuantity()).multiply(new BigDecimal(60)).multiply(new BigDecimal(60)).longValue(); |
| | | LocalDateTime planStartDay = planEndDay.plusSeconds(-seconds); |
| | | apsGasPipingRouteStat.setProcessPlanStartDay(Date.from(planStartDay.atZone(ZoneId.systemDefault()).toInstant())); |
| | | }else{ |
| | | apsGasPipingRouteStat.setProcessPlanEndDay(preApsProcessRoute.getProcessPlanEndDay()); |
| | | LocalDateTime planEndDay = apsGasPipingPlan.getPlanEndDay().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); |
| | | long seconds = apsProcessRoute.getStandardTime().multiply(apsGasPipingPlan.getProductionQuantity()).multiply(new BigDecimal(60)).multiply(new BigDecimal(60)).longValue(); |
| | | LocalDateTime planStartDay = planEndDay.plusSeconds(-seconds); |
| | | apsGasPipingRouteStat.setProcessPlanStartDay(Date.from(planStartDay.atZone(ZoneId.systemDefault()).toInstant())); |
| | | } |
| | | } |
| | | //插入 年 月 日 |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | |
| | | apsGasPipingRouteStat.setBatchNumber(batchNum); |
| | | apsGasPipingRouteStat.setId(IdUtils.fastSimpleUUID()); |
| | | apsGasPipingRouteStatList.add(apsGasPipingRouteStat); |
| | | preApsProcessRoute = apsGasPipingRouteStat; |
| | | if(isCurrentProcess){ |
| | | break; |
| | | } |
| | | } |
| | | }); |
| | | List<ApsGasPipingRouteStat> tempInsertList = new ArrayList<>(); |
| | |
| | | JSONObject result = new JSONObject(); |
| | | YearMonth yearMonth = YearMonth.parse(apsGasPipingRouteStat.getSearchEndDate()); |
| | | int daysInMonth = yearMonth.lengthOfMonth(); |
| | | HashSet<String> startPlanTimeSet = new HashSet<>(); |
| | | LinkedHashSet<String> startPlanTimeSet = new LinkedHashSet<>(); |
| | | //工序分组统计 |
| | | LinkedHashMap<String, List<ApsResourceDateStat>> processMap = new LinkedHashMap<>(); |
| | | List<HashMap<String, List<ApsResourceDateStat>>> processList = new ArrayList<>(); |
| | |
| | | } |
| | | }else if("month".equals(apsGasPipingRouteStat.getSearchType())){ |
| | | searchCapacityPlan.setYear(yearMonth.getYear()+""); |
| | | for(int i=1;i<=12;i++){ |
| | | startPlanTimeSet.add(yearMonth.getYear()+"-"+(i<10?"0"+i:i)); |
| | | } |
| | | YearMonth start = YearMonth.of(Integer.parseInt(apsGasPipingRouteStat.getSearchStartDate().split("-")[0]), Integer.parseInt(apsGasPipingRouteStat.getSearchStartDate().split("-")[1])); |
| | | YearMonth end = YearMonth.of(Integer.parseInt(apsGasPipingRouteStat.getSearchEndDate().split("-")[0]), Integer.parseInt(apsGasPipingRouteStat.getSearchEndDate().split("-")[1])); |
| | | List<String> yearMonths = getYearMonthsInRange(start, end); |
| | | startPlanTimeSet.addAll(yearMonths); |
| | | } |
| | | List<ApsGasPipelineCapacityPlan> apsGasPipelineCapacityPlanList = apsGasPipelineCapacityPlanMapper.selectApsGasPipelineCapacityPlanList(searchCapacityPlan); |
| | | apsGasPipelineCapacityPlanList.forEach(apsGasPipelineCapacityPlan -> { |
| | | apsGasPipingPlanMap.put(apsGasPipelineCapacityPlan.getProcessName(),apsGasPipelineCapacityPlan); |
| | | apsGasPipingPlanMap.put(apsGasPipelineCapacityPlan.getProcessName()+"-"+apsGasPipelineCapacityPlan.getYear()+"-"+(Integer.parseInt(apsGasPipelineCapacityPlan.getMonth())<10?"0"+apsGasPipelineCapacityPlan.getMonth():apsGasPipelineCapacityPlan.getMonth()),apsGasPipelineCapacityPlan); |
| | | }); |
| | | //计算日产能数据 |
| | | DateTimeFormatter formatter = null; |
| | |
| | | apsResourceDateStat.setPlanDay(LocalDate.parse(planStartDate, formatter)); |
| | | apsResourceDateStat.setResourceName(apsGasPipingRouteStatTemp.getProcessName()); |
| | | //查询气柜管路产能规划表 |
| | | apsResourceDateStat.setDesignTimes(apsGasPipingPlanMap.get(apsGasPipingRouteStatTemp.getProcessName())!=null?apsGasPipingPlanMap.get(apsGasPipingRouteStatTemp.getProcessName()).getDayProduceAllNum():new BigDecimal(0)); |
| | | apsResourceDateStat.setDesignTimes(apsGasPipingPlanMap.get(apsGasPipingRouteStatTemp.getProcessName()+"-"+planStartDate.substring(0, 7))!=null?apsGasPipingPlanMap.get(apsGasPipingRouteStatTemp.getProcessName()+"-"+planStartDate.substring(0, 7)).getDayProduceAllNum():new BigDecimal(0)); |
| | | //查询料号工序产能表 |
| | | apsResourceDateStat.setRequireTimes(apsGasPipingRouteStatTemp.getProcessTotalTime()); |
| | | if(apsResourceDateStat.getDesignTimes().compareTo(BigDecimal.ZERO)>0){ |
| | |
| | | if(dayMap.containsKey(apsResourceDateStat.getPlanDay().toString())){ |
| | | ApsResourceDateStat apsResourceDateStatTemp = dayMap.get(apsResourceDateStat.getPlanDay().toString()); |
| | | if("month".equals(apsGasPipingRouteStat.getSearchType())){ |
| | | apsResourceDateStatTemp.setDesignTimes(apsGasPipingPlanMap.get(processName)!=null?apsGasPipingPlanMap.get(processName).getMonthProduceAllNum():new BigDecimal(0)); |
| | | apsResourceDateStatTemp.setDesignTimes(apsGasPipingPlanMap.get(processName+"-"+apsResourceDateStat.getPlanDay().toString().substring(0,7))!=null?apsGasPipingPlanMap.get(processName+"-"+apsResourceDateStat.getPlanDay().toString().substring(0,7)).getMonthProduceAllNum():new BigDecimal(0)); |
| | | }else{ |
| | | apsResourceDateStatTemp.setDesignTimes(apsGasPipingPlanMap.get(processName)!=null?apsGasPipingPlanMap.get(processName).getDayProduceAllNum():new BigDecimal(0)); |
| | | apsResourceDateStatTemp.setDesignTimes(apsGasPipingPlanMap.get(processName+"-"+apsResourceDateStat.getPlanDay().toString().substring(0,7))!=null?apsGasPipingPlanMap.get(processName+"-"+apsResourceDateStat.getPlanDay().toString().substring(0,7)).getDayProduceAllNum():new BigDecimal(0)); |
| | | } |
| | | apsResourceDateStatTemp.setRequireTimes(apsResourceDateStatTemp.getRequireTimes().add(apsResourceDateStat.getRequireTimes())); |
| | | if(apsResourceDateStatTemp.getDesignTimes().compareTo(BigDecimal.ZERO) > 0){ |
| | |
| | | String key = entry.getKey(); |
| | | List<ApsResourceDateStat> crtList = new ArrayList<>(); |
| | | for(String tempTime:sortedStartPlanTimeList) { |
| | | if("month".equals(apsGasPipingRouteStat.getSearchType())){ |
| | | tempTime += "-01"; |
| | | } |
| | | LocalDate crtDate = LocalDate.parse(tempTime, formatter); |
| | | Optional<ApsResourceDateStat> first = apsResourceDateStatList.stream().filter(x -> x.getPlanDay().equals(crtDate)).findFirst(); |
| | | if (first.isPresent()) { |
| | |
| | | ApsResourceDateStat apsResourceDateStat = new ApsResourceDateStat(); |
| | | apsResourceDateStat.setPlanDay(LocalDate.parse(tempTime, formatter)); |
| | | if ("month".equals(apsGasPipingRouteStat.getSearchType())) { |
| | | apsResourceDateStat.setDesignTimes(apsGasPipingPlanMap.get(entry.getKey()) != null ? apsGasPipingPlanMap.get(entry.getKey()).getMonthProduceAllNum() : new BigDecimal(0)); |
| | | apsResourceDateStat.setDesignTimes(apsGasPipingPlanMap.get(entry.getKey()+"-"+tempTime.substring(0,7)) != null ? apsGasPipingPlanMap.get(entry.getKey()+"-"+tempTime.substring(0,7)).getMonthProduceAllNum() : new BigDecimal(0)); |
| | | } else { |
| | | apsResourceDateStat.setDesignTimes(apsGasPipingPlanMap.get(entry.getKey()) != null ? apsGasPipingPlanMap.get(entry.getKey()).getDayProduceAllNum() : new BigDecimal(0)); |
| | | apsResourceDateStat.setDesignTimes(apsGasPipingPlanMap.get(entry.getKey()+"-"+tempTime.substring(0,7)) != null ? apsGasPipingPlanMap.get(entry.getKey()+"-"+tempTime.substring(0,7)).getDayProduceAllNum() : new BigDecimal(0)); |
| | | } |
| | | apsResourceDateStat.setRequireTimes(new BigDecimal(0)); |
| | | apsResourceDateStat.setCapacityLoad(new BigDecimal(0)); |
| | |
| | | styles.put("title", style); |
| | | return styles; |
| | | } |
| | | |
| | | public static List<String> getYearMonthsInRange(YearMonth start, YearMonth end) { |
| | | List<String> yearMonths = new ArrayList<>(); |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM"); |
| | | |
| | | while (!start.isAfter(end)) { |
| | | yearMonths.add(start.format(formatter)); |
| | | start = start.plusMonths(1); |
| | | } |
| | | |
| | | return yearMonths; |
| | | } |
| | | } |