| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.poi.ss.usermodel.*; |
| | | import org.apache.poi.ss.util.CellRangeAddress; |
| | | import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.jeecg.common.constant.CommonConstant; |
| | | import org.jeecg.common.exception.JeecgBootException; |
| | | import org.jeecg.common.system.vo.LoginUser; |
| | | import org.jeecg.modules.mdc.dto.*; |
| | | import org.jeecg.modules.mdc.entity.*; |
| | | import org.jeecg.modules.mdc.mapper.MdcEfficiencyReportMapper; |
| | | import org.jeecg.modules.mdc.service.*; |
| | | import org.jeecg.modules.mdc.util.CustomExcelView; |
| | | import org.jeecg.modules.mdc.util.DateUtils; |
| | | import org.jeecg.modules.mdc.vo.MdcUtilizationRateDto; |
| | | import org.jeecg.modules.mdc.vo.*; |
| | |
| | | import org.jeecg.modules.system.service.ISysDepartService; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.servlet.ModelAndView; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.time.LocalDate; |
| | |
| | | */ |
| | | private void setDepartmentLevels(MdcEfficiencyListDto dto, MdcEquDepDto mdcEquDepDto, List<SysDepart> departList) { |
| | | switch (mdcEquDepDto.getOrgType()) { |
| | | case "1": dto.setLevel1(mdcEquDepDto.getDepartName()); break; |
| | | case "2": dto.setLevel2(mdcEquDepDto.getDepartName()); break; |
| | | case "3": dto.setLevel3(mdcEquDepDto.getDepartName()); break; |
| | | case "1": |
| | | dto.setLevel1(mdcEquDepDto.getDepartName()); |
| | | break; |
| | | case "2": |
| | | dto.setLevel2(mdcEquDepDto.getDepartName()); |
| | | break; |
| | | case "3": |
| | | dto.setLevel3(mdcEquDepDto.getDepartName()); |
| | | break; |
| | | } |
| | | |
| | | Optional<SysDepart> sysDepart = departList.stream().filter(depart -> depart.getId().equals(mdcEquDepDto.getParentId())).findAny(); |
| | | sysDepart.ifPresent(depart -> { |
| | | switch (depart.getOrgType()) { |
| | | case "1": dto.setLevel1(depart.getDepartName()); break; |
| | | case "2": dto.setLevel2(depart.getDepartName()); break; |
| | | case "3": dto.setLevel3(depart.getDepartName()); break; |
| | | case "1": |
| | | dto.setLevel1(depart.getDepartName()); |
| | | break; |
| | | case "2": |
| | | dto.setLevel2(depart.getDepartName()); |
| | | break; |
| | | case "3": |
| | | dto.setLevel3(depart.getDepartName()); |
| | | break; |
| | | } |
| | | if (StringUtils.isNotEmpty(depart.getParentId())) { |
| | | departList.stream().filter(d -> d.getId().equals(depart.getParentId())).findAny().ifPresent(parent -> { |
| | | switch (parent.getOrgType()) { |
| | | case "1": dto.setLevel1(parent.getDepartName()); break; |
| | | case "2": dto.setLevel2(parent.getDepartName()); break; |
| | | case "3": dto.setLevel3(parent.getDepartName()); break; |
| | | case "1": |
| | | dto.setLevel1(parent.getDepartName()); |
| | | break; |
| | | case "2": |
| | | dto.setLevel2(parent.getDepartName()); |
| | | break; |
| | | case "3": |
| | | dto.setLevel3(parent.getDepartName()); |
| | | break; |
| | | } |
| | | }); |
| | | } |
| | |
| | | */ |
| | | private void setProductionLevels(MdcEfficiencyListDto dto, MdcEquProDto mdcEquProDto, List<MdcProduction> productionList) { |
| | | switch (mdcEquProDto.getOrgType()) { |
| | | case "1": dto.setLevel1(mdcEquProDto.getProductionName()); break; |
| | | case "2": dto.setLevel2(mdcEquProDto.getProductionName()); break; |
| | | case "3": dto.setLevel3(mdcEquProDto.getProductionName()); break; |
| | | case "1": |
| | | dto.setLevel1(mdcEquProDto.getProductionName()); |
| | | break; |
| | | case "2": |
| | | dto.setLevel2(mdcEquProDto.getProductionName()); |
| | | break; |
| | | case "3": |
| | | dto.setLevel3(mdcEquProDto.getProductionName()); |
| | | break; |
| | | } |
| | | |
| | | Optional<MdcProduction> mdcProduction = productionList.stream().filter(production -> production.getId().equals(mdcEquProDto.getParentId())).findAny(); |
| | | mdcProduction.ifPresent(production -> { |
| | | switch (production.getOrgType()) { |
| | | case "1": dto.setLevel1(production.getProductionName()); break; |
| | | case "2": dto.setLevel2(production.getProductionName()); break; |
| | | case "3": dto.setLevel3(production.getProductionName()); break; |
| | | case "1": |
| | | dto.setLevel1(production.getProductionName()); |
| | | break; |
| | | case "2": |
| | | dto.setLevel2(production.getProductionName()); |
| | | break; |
| | | case "3": |
| | | dto.setLevel3(production.getProductionName()); |
| | | break; |
| | | } |
| | | if (StringUtils.isNotEmpty(production.getParentId())) { |
| | | productionList.stream().filter(p -> p.getId().equals(production.getParentId())).findAny().ifPresent(parent -> { |
| | | switch (parent.getOrgType()) { |
| | | case "1": dto.setLevel1(parent.getProductionName()); break; |
| | | case "2": dto.setLevel2(parent.getProductionName()); break; |
| | | case "3": dto.setLevel3(parent.getProductionName()); break; |
| | | case "1": |
| | | dto.setLevel1(parent.getProductionName()); |
| | | break; |
| | | case "2": |
| | | dto.setLevel2(parent.getProductionName()); |
| | | break; |
| | | case "3": |
| | | dto.setLevel3(parent.getProductionName()); |
| | | break; |
| | | } |
| | | }); |
| | | } |
| | |
| | | |
| | | List<MdcUtilizationResultDto> list = new ArrayList<>(); |
| | | for (String date : dateList) { |
| | | // Date startTime = DateUtils.toDate(date + " 00:00:00", DateUtils.STR_DATE_TIME_SMALL); |
| | | // Date endTime = DateUtils.toDate(date + " 00:00:00", DateUtils.STR_DATE_TIME_SMALL); |
| | | // endTime = DateUtils.addDays(endTime, 1); |
| | | // list.add(this.utilizationRate(mdcEquDepDto.getEquipmentId(), mdcEquDepDto.getEquipmentName(), mdcEquDepDto.getEquipmentType(), startTime, endTime, date, mdcUtilizationRateList)); |
| | | list.add(this.utilizationRateTrend(mdcEquDepDto.getEquipmentId(), mdcEquDepDto.getEquipmentName(), mdcEquDepDto.getEquipmentType(), date, mdcUtilizationRateList)); |
| | | } |
| | | mdcEfficiencyListDto.setDataList(list); |
| | |
| | | return mdcEfficiencyReportMapper.getEfficiencyRate(equipmentId, date); |
| | | } |
| | | |
| | | /** |
| | | * å©ç¨çåè¡¨å¯¼åº |
| | | * |
| | | * @param vo |
| | | * @return |
| | | */ |
| | | @Override |
| | | public ModelAndView exportEfficiencyXls(MdcEfficiencyReportQueryVo vo){ |
| | | LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | // è·åè®¾å¤ ID å表 |
| | | List<String> equipmentIds = getEquipmentIds(user.getId(), vo); |
| | | if (vo.getEquipmentIdList() == null || vo.getEquipmentIdList().isEmpty()) { |
| | | vo.setEquipmentIdList(equipmentIds); |
| | | } |
| | | |
| | | // å¦æè®¾å¤ ID å表为空ï¼ç´æ¥è¿å |
| | | if (vo.getEquipmentIdList() == null || vo.getEquipmentIdList().isEmpty()) { |
| | | throw new JeecgBootException("æ æ°æ®"); |
| | | } |
| | | // è·åè®¾å¤ ID å表 |
| | | List<String> equipmentIdList = mdcEquipmentService.listEquipmentId(vo); |
| | | if (equipmentIdList == null || equipmentIdList.isEmpty()) { |
| | | throw new JeecgBootException("æ æ°æ®"); |
| | | } |
| | | vo.setEquipmentIdList(equipmentIdList); |
| | | |
| | | // 3. åå¤è®¾å¤æ°æ® |
| | | List<MdcEfficiencyListDto> exportData = new ArrayList<>(); |
| | | |
| | | // è·åæ¥æå表并ææåç» |
| | | List<String> dates = DateUtils.getDatesStringList2(DateUtils.getShortDate2(vo.getStartTime()), DateUtils.getShortDate2(vo.getEndTime())); |
| | | |
| | | Map<String, List<String>> groupedByMonth = dates.stream() |
| | | .collect(Collectors.groupingBy( |
| | | date -> date.substring(0, 6) // æåå¹´æï¼å¦ "202405"ï¼ |
| | | )); |
| | | // 2. æåæ¯æçé¦å°¾æ¥æ |
| | | List<Map<String, Object>> monthRanges = groupedByMonth.entrySet().stream() |
| | | .map(entry -> { |
| | | List<String> monthDates = entry.getValue(); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("startTime", monthDates.get(0)); |
| | | map.put("endTime", monthDates.get(monthDates.size() - 1)); |
| | | map.put("dateList", monthDates); |
| | | return map; |
| | | }) |
| | | .collect(Collectors.toList()); |
| | | |
| | | for (Map<String, Object> monthRange : monthRanges) { |
| | | List<MdcEfficiencyListDto> listDtos = new ArrayList<>(); |
| | | vo.setStartTime((String) monthRange.get("startTime")); |
| | | vo.setEndTime((String) monthRange.get("endTime")); |
| | | List<String> dateList = (List<String>) monthRange.get("dateList"); |
| | | // æ¥è¯¢è®¾å¤æçæ°æ® |
| | | List<MdcEfficiencyDto> efficiencyList = mdcEfficiencyReportMapper.efficiencyList(vo); |
| | | // å¤çæ°æ® |
| | | // æ ¹æ®ç±»åæ å¤çä¸åçå±çº§ |
| | | if ("2".equals(vo.getTypeTree())) { |
| | | // é¨é¨å±çº§ |
| | | listDtos = processDeLevel(vo, efficiencyList, dateList); |
| | | } else { |
| | | // 产线å±çº§ |
| | | listDtos = processProLevel(vo, efficiencyList, dateList); |
| | | } |
| | | if (exportData.isEmpty()) { |
| | | exportData.addAll(listDtos); |
| | | } else { |
| | | Map<String, MdcEfficiencyListDto> map = listDtos.stream().collect(Collectors.toMap(MdcEfficiencyListDto::getEquipmentId, a -> a, (k1, k2) -> k1)); |
| | | exportData.forEach(mdcEfficiencyListDto -> { |
| | | List<MdcEfficiencyResultDto> dataList = mdcEfficiencyListDto.getDataList(); |
| | | if (map.containsKey(mdcEfficiencyListDto.getEquipmentId())) { |
| | | MdcEfficiencyListDto mdcEfficiencyListDto1 = map.get(mdcEfficiencyListDto.getEquipmentId()); |
| | | List<MdcEfficiencyResultDto> dataList1 = mdcEfficiencyListDto1.getDataList(); |
| | | dataList.addAll(dataList1); |
| | | mdcEfficiencyListDto.setDataList(dataList); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | } |
| | | // æ°æ®æåº |
| | | exportData = exportData.stream().sorted(Comparator.comparing(MdcEfficiencyListDto::getLevel2)).sorted(Comparator.comparing(MdcEfficiencyListDto::getLevel3)).collect(Collectors.toList()); |
| | | |
| | | |
| | | // 1. å建工ä½ç°¿åå·¥ä½è¡¨ |
| | | XSSFWorkbook workbook = new XSSFWorkbook(); |
| | | Sheet sheet = workbook.createSheet("å©ç¨çæ°æ®"); |
| | | |
| | | // 3. åå¤è®¾å¤æ°æ® |
| | | |
| | | // åå»ºæ ·å¼ |
| | | CellStyle centerStyle = createCenterStyle(workbook); |
| | | CellStyle fixedHeaderStyle = createFixedHeaderStyle(workbook); |
| | | CellStyle dateHeaderStyle = createDateHeaderStyle(workbook); |
| | | CellStyle metricHeaderStyle = createMetricHeaderStyle(workbook); |
| | | |
| | | // dates.add("å计"); |
| | | // dates.add("å¹³å"); |
| | | |
| | | // åå
¥æ é¢è¡ |
| | | writeHeaderRows(sheet, fixedHeaderStyle, dateHeaderStyle, metricHeaderStyle, dates); |
| | | |
| | | // åå
¥æ°æ®è¡ |
| | | writeDataRows(sheet, centerStyle, exportData, dates); |
| | | |
| | | // æ·»å èªéåºåå®½ï¼ææåï¼ä»0å¼å§å°æåä¸åï¼ |
| | | // autoSizeAllColumns(sheet, 0, sheet.getRow(0).getLastCellNum() - 1); |
| | | |
| | | // 7. å°å·¥ä½ç°¿è½¬æ¢ä¸ºåèæ°ç»è¾åºæµ |
| | | ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
| | | try { |
| | | workbook.write(bos); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | // å
·ä½å®ç°å¯è½éè¦æ ¹æ®ä½ ç项ç®ç»æè¿è¡è°æ´ |
| | | ModelAndView mv = new ModelAndView(new CustomExcelView(bos.toByteArray())); |
| | | return mv; |
| | | } |
| | | |
| | | /** |
| | | * èªéåºææå宽ï¼å¤çåå¹¶åå
æ ¼ï¼ |
| | | * @param sheet å·¥ä½è¡¨ |
| | | * @param startCol èµ·å§åç´¢å¼ |
| | | * @param endCol ç»æåç´¢å¼ |
| | | */ |
| | | private void autoSizeAllColumns(Sheet sheet, int startCol, int endCol) { |
| | | // å
å¤çåå¹¶åå
æ ¼å¯¹å宽çå½±å |
| | | adjustMergedCells(sheet); |
| | | |
| | | // èªå¨è°æ´å宽 |
| | | for (int i = startCol; i <= endCol; i++) { |
| | | sheet.autoSizeColumn(i); |
| | | // è§£å³POIèªå¨å宽è¿çªé®é¢ï¼å¢å é¢å¤å®½åº¦ï¼åä½ï¼1/256å符宽度ï¼è¿éå¢å 200ç¸å½äºçº¦3个åç¬¦ï¼ |
| | | sheet.setColumnWidth(i, sheet.getColumnWidth(i) + 1800); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * å¤çåå¹¶åå
æ ¼ï¼ç¡®ä¿åå®½è®¡ç®æ£ç¡® |
| | | * ï¼POIçautoSizeColumn对åå¹¶åå
æ ¼æ¯æä¸ä½³ï¼éè¦æå¨å±å¼è®¡ç®ï¼ |
| | | */ |
| | | private void adjustMergedCells(Sheet sheet) { |
| | | List<CellRangeAddress> mergedRegions = new ArrayList<>(); |
| | | for (int i = 0; i < sheet.getNumMergedRegions(); i++) { |
| | | mergedRegions.add(sheet.getMergedRegion(i)); |
| | | } |
| | | |
| | | for (CellRangeAddress region : mergedRegions) { |
| | | int firstCol = region.getFirstColumn(); |
| | | int lastCol = region.getLastColumn(); |
| | | if (firstCol == lastCol) continue; // åååå¹¶æ éå¤ç |
| | | |
| | | // 计ç®åå¹¶åºåçæå¤§å®½åº¦ |
| | | int maxWidth = 0; |
| | | for (int row = region.getFirstRow(); row <= region.getLastRow(); row++) { |
| | | Row rowData = sheet.getRow(row); |
| | | if (rowData == null) continue; |
| | | |
| | | Cell cell = rowData.getCell(firstCol); |
| | | if (cell == null) continue; |
| | | |
| | | int width = getCellWidth(cell); |
| | | if (width > maxWidth) { |
| | | maxWidth = width; |
| | | } |
| | | } |
| | | |
| | | // åºç¨å°ææåå¹¶åï¼åªè®¾ç½®é¦å宽度ï¼POIä¼èªå¨åæ¥å°åå¹¶åï¼ |
| | | sheet.setColumnWidth(firstCol, maxWidth); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è·ååå
æ ¼å
容宽度ï¼èèåä½åå
å®¹ï¼ |
| | | */ |
| | | private int getCellWidth(Cell cell) { |
| | | // éè¿Sheetè·åWorkbookï¼å
¼å®¹æ§æ´å¥½ |
| | | Workbook workbook = cell.getSheet().getWorkbook(); |
| | | CellStyle style = cell.getCellStyle(); |
| | | Font font = workbook.getFontAt(style.getFontIndex()); |
| | | String text = cell.getStringCellValue(); |
| | | |
| | | // è®¡ç®ææ¬å®½åº¦ï¼ç²ç¥ä¼°è®¡ï¼å¯æ ¹æ®å®é
åä½è°æ´ï¼ |
| | | int width = text.length() * 256; |
| | | if (font.getBold()) width = (int) (width * 1.2); // å ç²åä½å¢å 20%宽度 |
| | | return width + 512; // å¢å é¢å¤å®½åº¦ |
| | | } |
| | | |
| | | /** |
| | | * å¤çé¨é¨å±çº§ |
| | | */ |
| | | private List<MdcEfficiencyListDto> processDeLevel(MdcEfficiencyReportQueryVo vo, List<MdcEfficiencyDto> efficiencyList, List<String> dates) { |
| | | List<MdcEquDepDto> equipmentList = mdcEquipmentService.findEquDepList(vo.getEquipmentIdList()); |
| | | List<SysDepart> departList = sysDepartService.list(new LambdaQueryWrapper<SysDepart>() |
| | | .ne(SysDepart::getDelFlag, CommonConstant.DEL_FLAG_1.toString()) |
| | | .orderByAsc(SysDepart::getDepartOrder)); |
| | | |
| | | return equipmentList.stream().map(mdcEquDepDto -> { |
| | | MdcEfficiencyListDto mdcEfficiencyListDto = createEfficiencyListDto(mdcEquDepDto); |
| | | setDepartmentLevels(mdcEfficiencyListDto, mdcEquDepDto, departList); |
| | | mdcEfficiencyListDto.setDataList(processEffData(efficiencyList, dates, mdcEquDepDto.getEquipmentId())); |
| | | return mdcEfficiencyListDto; |
| | | }).collect(Collectors.toList()); |
| | | } |
| | | |
| | | private List<MdcEfficiencyListDto> processProLevel(MdcEfficiencyReportQueryVo vo, List<MdcEfficiencyDto> efficiencyList, List<String> dates) { |
| | | List<MdcEquProDto> equipmentList = mdcEquipmentService.findEquProList(vo.getEquipmentIdList()); |
| | | List<MdcProduction> productionList = mdcProductionService.list(new LambdaQueryWrapper<MdcProduction>() |
| | | .ne(MdcProduction::getDelFlag, CommonConstant.DEL_FLAG_1.toString()) |
| | | .orderByAsc(MdcProduction::getProductionOrder)); |
| | | |
| | | return equipmentList.stream().map(mdcEquProDto -> { |
| | | MdcEfficiencyListDto mdcEfficiencyListDto = createEfficiencyListDto(mdcEquProDto); |
| | | setProductionLevels(mdcEfficiencyListDto, mdcEquProDto, productionList); |
| | | mdcEfficiencyListDto.setDataList(processEffData(efficiencyList, dates, mdcEquProDto.getEquipmentId())); |
| | | return mdcEfficiencyListDto; |
| | | }).collect(Collectors.toList()); |
| | | } |
| | | |
| | | private List<MdcEfficiencyResultDto> processEffData(List<MdcEfficiencyDto> efficiencyList, List<String> dates, String equipmentId) { |
| | | List<MdcEfficiencyResultDto> list = new ArrayList<>(); |
| | | // MdcEfficiencyResultDto avgDto = new MdcEfficiencyResultDto(); |
| | | // avgDto.setTheDate("å¹³åå¼"); |
| | | // MdcEfficiencyResultDto sumDto = new MdcEfficiencyResultDto(); |
| | | // sumDto.setTheDate("å计"); |
| | | |
| | | for (String date : dates) { |
| | | MdcEfficiencyResultDto dto = effRate(efficiencyList, date, equipmentId); |
| | | list.add(dto); |
| | | } |
| | | |
| | | // sumDto.setProcessLong(avgDto.getProcessLong()); |
| | | // avgDto.setProcessLong(avgDto.getProcessLong().divide(new BigDecimal(dates.size()), 0, RoundingMode.HALF_UP)); |
| | | // avgDto.setUtilizationRate(avgDto.getUtilizationRate().divide(new BigDecimal(dates.size()), 4, RoundingMode.HALF_UP)); |
| | | // sumDto.setUtilizationRate(avgDto.getUtilizationRate()); |
| | | // avgDto.setStartRate(avgDto.getStartRate().divide(new BigDecimal(dates.size()), 4, RoundingMode.HALF_UP)); |
| | | // sumDto.setStartRate(avgDto.getStartRate()); |
| | | // avgDto.setOpenRate(avgDto.getOpenRate().divide(new BigDecimal(dates.size()), 4, RoundingMode.HALF_UP)); |
| | | // sumDto.setOpenRate(avgDto.getOpenRate()); |
| | | // sumDto.setOpenLong(avgDto.getOpenLong()); |
| | | // avgDto.setOpenLong(avgDto.getOpenLong().divide(new BigDecimal(dates.size()), 0, RoundingMode.HALF_UP)); |
| | | // sumDto.setWaitLong(avgDto.getWaitLong()); |
| | | // avgDto.setWaitLong(avgDto.getWaitLong().divide(new BigDecimal(dates.size()), 0, RoundingMode.HALF_UP)); |
| | | // sumDto.setCloseLong(avgDto.getCloseLong()); |
| | | // avgDto.setCloseLong(avgDto.getCloseLong().divide(new BigDecimal(dates.size()), 0, RoundingMode.HALF_UP)); |
| | | // |
| | | // list.add(sumDto); |
| | | // list.add(avgDto); |
| | | return list; |
| | | } |
| | | |
| | | private MdcEfficiencyResultDto effRate(List<MdcEfficiencyDto> efficiencyList, String date, String equipmentId) { |
| | | MdcEfficiencyResultDto mdcEfficiencyResultDto = new MdcEfficiencyResultDto(); |
| | | if (efficiencyList != null && !efficiencyList.isEmpty()) { |
| | | Map<String, MdcEfficiencyDto> collect = efficiencyList.stream().collect(Collectors.toMap(dto -> dto.getEquipmentId() + "_" + dto.getTheDate(), dto -> dto)); |
| | | if (collect.containsKey(equipmentId + "_" + date)) { |
| | | MdcEfficiencyDto efficiencyDto = collect.get(equipmentId + "_" + date); |
| | | mdcEfficiencyResultDto.setTheDate(efficiencyDto.getTheDate()); |
| | | mdcEfficiencyResultDto.setProcessLong(efficiencyDto.getProcessLong().divide(new BigDecimal("3600"), 2, RoundingMode.HALF_UP)); |
| | | mdcEfficiencyResultDto.setUtilizationRate(efficiencyDto.getUtilizationRate().multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP)); |
| | | mdcEfficiencyResultDto.setStartRate(efficiencyDto.getStartRate().multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP)); |
| | | mdcEfficiencyResultDto.setOpenRate(efficiencyDto.getOpenRate().multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP)); |
| | | mdcEfficiencyResultDto.setOpenLong(efficiencyDto.getOpenLong().divide(new BigDecimal("3600"), 2, RoundingMode.HALF_UP)); |
| | | mdcEfficiencyResultDto.setWaitLong(efficiencyDto.getWaitLong().divide(new BigDecimal("3600"), 2, RoundingMode.HALF_UP)); |
| | | mdcEfficiencyResultDto.setCloseLong(efficiencyDto.getCloseLong().divide(new BigDecimal("3600"), 2, RoundingMode.HALF_UP)); |
| | | } else { |
| | | mdcEfficiencyResultDto.setTheDate(date); |
| | | } |
| | | |
| | | } else { |
| | | mdcEfficiencyResultDto.setTheDate(date); |
| | | mdcEfficiencyResultDto.setProcessLong(new BigDecimal("0")); |
| | | mdcEfficiencyResultDto.setUtilizationRate(new BigDecimal("0")); |
| | | mdcEfficiencyResultDto.setStartRate(new BigDecimal("0")); |
| | | mdcEfficiencyResultDto.setOpenRate(new BigDecimal("0")); |
| | | mdcEfficiencyResultDto.setOpenLong(new BigDecimal("0")); |
| | | mdcEfficiencyResultDto.setWaitLong(new BigDecimal("0")); |
| | | mdcEfficiencyResultDto.setCloseLong(new BigDecimal("0")); |
| | | } |
| | | return mdcEfficiencyResultDto; |
| | | } |
| | | |
| | | private void writeHeaderRows(Sheet sheet, CellStyle fixedHeaderStyle, CellStyle dateHeaderStyle, CellStyle metricHeaderStyle, List<String> dateList) { |
| | | Row titleRow1 = sheet.createRow(0); |
| | | Row titleRow2 = sheet.createRow(1); |
| | | int colIndex = 0; |
| | | |
| | | // åå
¥åºå®åæ é¢ï¼å
¬å¸ã车é´çï¼ |
| | | String[] fixedHeaders = {"å
¬å¸", "车é´", "工段", "设å¤ID", "设å¤åç§°", "设å¤ç±»å"}; |
| | | for (int i = 0; i < fixedHeaders.length; i++) { |
| | | createCellWithStyle(titleRow1, colIndex, fixedHeaders[i], fixedHeaderStyle); |
| | | createCellWithStyle(titleRow2, colIndex, "", fixedHeaderStyle); |
| | | // åå¹¶åå
æ ¼ï¼è·¨è¡ä¸è·¨åï¼ |
| | | CellRangeAddress region = new CellRangeAddress(0, 1, colIndex, colIndex); |
| | | sheet.addMergedRegion(region); |
| | | colIndex++; |
| | | } |
| | | |
| | | // åå
¥æ¥æï¼è·¨6ååå¹¶ |
| | | for (String date : dateList) { |
| | | CellRangeAddress dateRegion = new CellRangeAddress(0, 0, colIndex, colIndex + 5); |
| | | sheet.addMergedRegion(dateRegion); |
| | | createCellWithStyle(titleRow1, colIndex, date, dateHeaderStyle); |
| | | colIndex += 6; |
| | | } |
| | | |
| | | // åå
¥æ¥æææ æ é¢ï¼æ¯ä¸ªæ¥æå¯¹åº6åï¼ |
| | | colIndex = 6; |
| | | for (String date : dateList) { |
| | | createCellWithStyle(titleRow2, colIndex++, "å©ç¨ç(%)", metricHeaderStyle); |
| | | createCellWithStyle(titleRow2, colIndex++, "弿ºç(%)", metricHeaderStyle); |
| | | createCellWithStyle(titleRow2, colIndex++, "弿ºæ¶é¿(å°æ¶)", metricHeaderStyle); |
| | | createCellWithStyle(titleRow2, colIndex++, "å å·¥æ¶é¿(å°æ¶)", metricHeaderStyle); |
| | | createCellWithStyle(titleRow2, colIndex++, "å¾
æºæ¶é¿(å°æ¶)", metricHeaderStyle); |
| | | createCellWithStyle(titleRow2, colIndex++, "å
³æºæ¶é¿(å°æ¶)", metricHeaderStyle); |
| | | } |
| | | |
| | | } |
| | | |
| | | private CellStyle createCenterStyle(Workbook workbook) { |
| | | CellStyle style = workbook.createCellStyle(); |
| | | style.setAlignment(HorizontalAlignment.CENTER); |
| | | style.setVerticalAlignment(VerticalAlignment.CENTER); |
| | | // æ·»å 宿´è¾¹æ¡ |
| | | style.setBorderTop(BorderStyle.THIN); |
| | | style.setBorderBottom(BorderStyle.THIN); |
| | | style.setBorderLeft(BorderStyle.THIN); |
| | | style.setBorderRight(BorderStyle.THIN); |
| | | return style; |
| | | } |
| | | |
| | | private CellStyle createFixedHeaderStyle(Workbook workbook) { |
| | | CellStyle style = createCenterStyle(workbook); |
| | | style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); |
| | | style.setFillPattern(FillPatternType.SOLID_FOREGROUND); |
| | | Font font = workbook.createFont(); |
| | | font.setBold(true); |
| | | style.setFont(font); |
| | | return style; |
| | | } |
| | | |
| | | private CellStyle createDateHeaderStyle(Workbook workbook) { |
| | | CellStyle style = createCenterStyle(workbook); |
| | | style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); |
| | | style.setFillPattern(FillPatternType.SOLID_FOREGROUND); |
| | | Font font = workbook.createFont(); |
| | | font.setBold(true); |
| | | style.setFont(font); |
| | | return style; |
| | | } |
| | | |
| | | private CellStyle createMetricHeaderStyle(Workbook workbook) { |
| | | CellStyle style = createCenterStyle(workbook); |
| | | style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); |
| | | style.setFillPattern(FillPatternType.SOLID_FOREGROUND); |
| | | Font font = workbook.createFont(); |
| | | font.setBold(true); |
| | | style.setFont(font); |
| | | return style; |
| | | } |
| | | |
| | | private void writeDataRows(Sheet sheet, CellStyle style, List<MdcEfficiencyListDto> exportData, List<String> dateList) { |
| | | int rowIndex = 2; |
| | | for (MdcEfficiencyListDto device : exportData) { |
| | | Row dataRow = sheet.createRow(rowIndex++); |
| | | int colIndex = 0; |
| | | |
| | | // åå
¥åºå®åæ°æ®ï¼å
¬å¸ã车é´çï¼ |
| | | createCellWithStyle(dataRow, colIndex++, device.getLevel1(), style); |
| | | createCellWithStyle(dataRow, colIndex++, device.getLevel2(), style); |
| | | createCellWithStyle(dataRow, colIndex++, device.getLevel3(), style); |
| | | createCellWithStyle(dataRow, colIndex++, device.getEquipmentId(), style); |
| | | createCellWithStyle(dataRow, colIndex++, device.getEquipmentName(), style); |
| | | createCellWithStyle(dataRow, colIndex++, device.getEquipmentType(), style); |
| | | |
| | | |
| | | // åå
¥æ¥æææ æ°æ®ï¼æ¯ä¸ªæ¥æå¯¹åº6åï¼ |
| | | for (String date : dateList) { |
| | | // ç¡®ä¿dateStr对åºçMapå·²åå§å |
| | | MdcEfficiencyResultDto dateData = device.getDataList().stream().filter(mdcEfficiencyResultDto -> date.equals(mdcEfficiencyResultDto.getTheDate())).collect(Collectors.toList()).get(0); |
| | | createCellWithStyle(dataRow, colIndex++, dateData.getUtilizationRate().doubleValue(), style); |
| | | createCellWithStyle(dataRow, colIndex++, dateData.getOpenRate().doubleValue(), style); |
| | | createCellWithStyle(dataRow, colIndex++, dateData.getOpenLong().doubleValue(), style); |
| | | createCellWithStyle(dataRow, colIndex++, dateData.getProcessLong().doubleValue(), style); |
| | | createCellWithStyle(dataRow, colIndex++, dateData.getWaitLong().doubleValue(), style); |
| | | createCellWithStyle(dataRow, colIndex++, dateData.getCloseLong().doubleValue(), style); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void createCellWithStyle(Row row, int colIndex, Object value, CellStyle style) { |
| | | Cell cell = row.createCell(colIndex); |
| | | if (value instanceof String) { |
| | | cell.setCellValue((String) value); |
| | | } else if (value instanceof Double) { |
| | | cell.setCellValue((Double) value); |
| | | } |
| | | cell.setCellStyle(style); |
| | | } |
| | | |
| | | private MdcUtilizationResultDto utilizationRate(String equipmentId, String equipmentName, String equipmentType, Date startTime, Date endTime, String date, List<MdcUtilizationRate> mdcUtilizationRateList) { |
| | | MdcUtilizationResultDto dto = new MdcUtilizationResultDto(); |
| | | dto.setEquipmentId(equipmentId); |