| | |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.ZoneId; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.time.temporal.ChronoUnit; |
| | | import java.util.*; |
| | |
| | | import com.aps.common.core.web.domain.AjaxResult; |
| | | import com.aps.core.domain.ApsPartPlan; |
| | | import com.aps.core.domain.ApsResourceDateStat; |
| | | import com.aps.core.domain.ApsResourceGroup; |
| | | import com.aps.core.mapper.ApsAbnormalProcessAnalysisMapper; |
| | | import com.aps.core.mapper.ApsResourceGroupMapper; |
| | | import com.aps.core.service.IApsAbnormalProcessAnalysisService; |
| | | import jakarta.annotation.Resource; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.poi.ss.usermodel.*; |
| | | import org.apache.poi.ss.util.CellRangeAddress; |
| | | import org.apache.poi.util.IOUtils; |
| | | import org.apache.poi.util.Removal; |
| | | import org.apache.poi.xssf.streaming.SXSSFCell; |
| | | import org.apache.poi.xssf.streaming.SXSSFRow; |
| | | import org.apache.poi.xssf.streaming.SXSSFSheet; |
| | |
| | | import com.aps.core.mapper.ApsPartRouteStatMapper; |
| | | import com.aps.core.domain.ApsPartRouteStat; |
| | | import com.aps.core.service.IApsPartRouteStatService; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import static java.util.stream.Collectors.groupingBy; |
| | | |
| | |
| | | private ApsPartRouteStatMapper apsPartRouteStatMapper; |
| | | @Autowired |
| | | private ApsResourceGroupMapper resourceGroupMapper; |
| | | @Autowired |
| | | private ApsResourceGroupMapper apsResourceGroupMapper; |
| | | |
| | | @Resource |
| | | private IApsAbnormalProcessAnalysisService analysisService; |
| | | |
| | | /** |
| | | * 查询零件统计表 |
| | |
| | | /** |
| | | * 查询零件工序并更新计划开工日期 |
| | | * */ |
| | | @Transactional |
| | | @Override |
| | | public void updatePartRoutPlanDate() { |
| | | List<ApsPartRouteStat> tempList = apsPartRouteStatMapper.selectPartRoutStat(); |
| | |
| | | /*判断当前工序 当前工序只有一条*/ |
| | | if (stat.getCurrentProcessNumber().equals(stat.getRoadProcessNumber())) { |
| | | /* 对 stat.getProcessPlanStartDay() 和当前日期 进行对比,只对比到日,不用管十分秒*/ |
| | | if (stat.getProcessPlanStartDay().toLocalDate().isBefore(LocalDateTime.now().toLocalDate())) { |
| | | stat.setProcessPlanStartDay(LocalDateTime.now()); |
| | | LocalDate startLocalDate = LocalDate.ofInstant(stat.getProcessPlanStartDay().toInstant(), ZoneId.systemDefault()); |
| | | LocalDate nowLocalDate = LocalDate.now(); |
| | | if (startLocalDate.isBefore(nowLocalDate)) { |
| | | stat.setProcessPlanStartDay(new Date()); |
| | | } |
| | | } |
| | | /*未开工工序的计划开工日=上一道工序的计划开工日+上一道工序的工序总工时。*/ |
| | | if (stat.getCurrentProcessNumber().compareTo(stat.getRoadProcessNumber()) < 0) { |
| | | if (last != null) { |
| | | stat.setProcessPlanStartDay(last.getProcessPlanStartDay().plusHours(last.getProcessTotalTime())); |
| | | LocalDateTime lastStartDate = LocalDateTime.ofInstant(last.getProcessPlanStartDay().toInstant(), ZoneId.systemDefault()); |
| | | long seconds = last.getProcessTotalTime().multiply(new BigDecimal(60)).multiply(new BigDecimal(60)).longValue(); |
| | | LocalDateTime currentStartDate = lastStartDate.plusSeconds(seconds); |
| | | stat.setProcessPlanStartDay(Date.from(currentStartDate.atZone(ZoneId.systemDefault()).toInstant())); |
| | | } |
| | | } |
| | | /*保存上一步计算的 开工日*/ |
| | | last = stat; |
| | | stat.setId(IdUtils.fastUUID().toString()); |
| | | stat.setBatchNumber(batchNum); |
| | | stat.setDelFlag("0"); |
| | | apsPartRouteStatMapper.insertApsPartRouteStat(stat); |
| | | } |
| | | } |
| | | apsPartRouteStatMapper.deleteLastBatch(batchNum); |
| | | /*计算并保存 工序异常信息*/ |
| | | analysisService.batchSaveAbnormalInfo(); |
| | | } |
| | | /** 查询资源日历表 |
| | | */ |
| | |
| | | /*查出所有统计的数据*/ |
| | | AjaxResult result = new AjaxResult(200, "生成成功"); |
| | | List<ApsResourceDateStat> list = apsPartRouteStatMapper.selectResourceDateStat(); |
| | | List<ApsResourceGroup> resourceGroupList = apsResourceGroupMapper.selectApsResourceGroupList(new ApsResourceGroup()); |
| | | if (!list.isEmpty()) { |
| | | /*求出计划的最大时间,没有 设置为当前时间+15天*/ |
| | | ApsResourceDateStat apsResourceDateStat = list.stream().max(Comparator.comparing(ApsResourceDateStat::getPlanDay)).orElse(null); |
| | |
| | | startDay = startDay.plus(1, ChronoUnit.DAYS); |
| | | } |
| | | /*组织出列头数据*/ |
| | | List<String> resourceNames =list.stream().map(ApsResourceDateStat::getResourceName).distinct().toList(); |
| | | |
| | | /*准备资源组信息*/ |
| | | List<Map<String, List<ApsResourceDateStat>>> targetList = new ArrayList<>(); |
| | | resourceNames.forEach(resourceName -> { |
| | | resourceGroupList.forEach(resourceGroup -> { |
| | | String resourceName=resourceGroup.getResourceGroupName(); |
| | | /*根据日期表头的顺序,组织出每个日期下的统计项目*/ |
| | | Map<String, List<ApsResourceDateStat>> maps = new HashMap<>(Map.of()); |
| | | List<ApsResourceDateStat> currentDaysResouces=new ArrayList<>(); |
| | |
| | | else { |
| | | ApsResourceDateStat empty = new ApsResourceDateStat(); |
| | | empty.setPlanDay(LocalDate.parse(planDay, formatter)); |
| | | empty.setDesignTimes(0); |
| | | empty.setRequireTimes(0); |
| | | // empty.setDesignTimes(resourceGroup.getDevicesQuantity().intValue()*resourceGroup.getTheoryHours().intValue()); |
| | | empty.setDesignTimes(resourceGroup.getTheoryHours().multiply(BigDecimal.valueOf( resourceGroup.getDevicesQuantity()))); |
| | | empty.setRequireTimes(BigDecimal.ZERO); |
| | | empty.setResourceName(resourceName); |
| | | empty.setResourceGroupName(resourceName); |
| | | empty.setCapacityLoad(BigDecimal.ZERO); |
| | |
| | | dataRow.createCell(0).setCellValue(resourceName); |
| | | for (int j = 0; j < resourceDateStats.size(); j++) { |
| | | ApsResourceDateStat apsResourceDateStat = resourceDateStats.get(j); |
| | | dataRow.createCell(j*3+1).setCellValue(apsResourceDateStat.getDesignTimes()); |
| | | dataRow.createCell(j*3+2).setCellValue(apsResourceDateStat.getRequireTimes()); |
| | | dataRow.createCell(j*3+1).setCellValue(apsResourceDateStat.getDesignTimes().doubleValue()); |
| | | dataRow.createCell(j*3+2).setCellValue(apsResourceDateStat.getRequireTimes().doubleValue()); |
| | | dataRow.createCell(j*3+3).setCellValue(apsResourceDateStat.getCapacityLoad().doubleValue()+"%"); |
| | | } |
| | | } |
| | |
| | | style.setVerticalAlignment(VerticalAlignment.CENTER); |
| | | Font titleFont = wb.createFont(); |
| | | titleFont.setFontName("Arial"); |
| | | titleFont.setFontHeightInPoints((short) 16); |
| | | titleFont.setFontHeightInPoints((short) 12); |
| | | titleFont.setBold(true); |
| | | style.setFont(titleFont); |
| | | DataFormat dataFormat = wb.createDataFormat(); |