¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.aps.core.service.impl; |
| | | |
| | | import com.alibaba.fastjson2.JSONArray; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.aps.common.core.utils.DateUtils; |
| | | import com.aps.common.core.utils.uuid.IdUtils; |
| | | import com.aps.common.security.utils.SecurityUtils; |
| | | import com.aps.core.domain.*; |
| | | import com.aps.core.mapper.ApsGasPipelineCapacityPlanMapper; |
| | | import com.aps.core.mapper.ApsGasPipingPlanMapper; |
| | | import com.aps.core.mapper.ApsGasPipingRouteStatMapper; |
| | | import com.aps.core.service.IApsGasMaterialUsageService; |
| | | import com.aps.core.service.IApsGasPipingRouteStatService; |
| | | 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.xssf.streaming.SXSSFCell; |
| | | import org.apache.poi.xssf.streaming.SXSSFRow; |
| | | import org.apache.poi.xssf.streaming.SXSSFSheet; |
| | | import org.apache.poi.xssf.streaming.SXSSFWorkbook; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.sql.Timestamp; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.YearMonth; |
| | | import java.time.ZoneId; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * æ°ä½ç®¡è·¯äº§è½è´è½½ç»è®¡Serviceä¸å¡å±å¤ç |
| | | * |
| | | * @author hjy |
| | | * @date 2025-04-24 |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class ApsGasPipingRouteStatServiceImpl implements IApsGasPipingRouteStatService |
| | | { |
| | | @Autowired |
| | | private ApsGasPipingRouteStatMapper apsGasPipingRouteStatMapper; |
| | | |
| | | @Autowired |
| | | private ApsGasPipingPlanMapper apsGasPipingPlanMapper; |
| | | |
| | | @Autowired |
| | | private ApsGasPipelineCapacityPlanMapper apsGasPipelineCapacityPlanMapper; |
| | | |
| | | @Autowired |
| | | private IApsGasMaterialUsageService apsGasMaterialUsageService; |
| | | |
| | | /** |
| | | * æ¥è¯¢æ°ä½ç®¡è·¯äº§è½è´è½½ç»è®¡ |
| | | * |
| | | * @param id æ°ä½ç®¡è·¯äº§è½è´è½½ç»è®¡ä¸»é® |
| | | * @return æ°ä½ç®¡è·¯äº§è½è´è½½ç»è®¡ |
| | | */ |
| | | @Override |
| | | public ApsGasPipingRouteStat selectApsGasPipingRouteStatById(String id) |
| | | { |
| | | return apsGasPipingRouteStatMapper.selectApsGasPipingRouteStatById(id); |
| | | } |
| | | |
| | | /** |
| | | * æ¥è¯¢æ°ä½ç®¡è·¯äº§è½è´è½½ç»è®¡å表 |
| | | * |
| | | * @param apsGasPipingRouteStat æ°ä½ç®¡è·¯äº§è½è´è½½ç»è®¡ |
| | | * @return æ°ä½ç®¡è·¯äº§è½è´è½½ç»è®¡ |
| | | */ |
| | | @Override |
| | | public List<ApsGasPipingRouteStat> selectApsGasPipingRouteStatList(ApsGasPipingRouteStat apsGasPipingRouteStat) |
| | | { |
| | | return apsGasPipingRouteStatMapper.selectApsGasPipingRouteStatList(apsGasPipingRouteStat); |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢æ°ä½ç®¡è·¯äº§è½è´è½½ç»è®¡ |
| | | * |
| | | * @param apsGasPipingRouteStat æ°ä½ç®¡è·¯äº§è½è´è½½ç»è®¡ |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int insertApsGasPipingRouteStat(ApsGasPipingRouteStat apsGasPipingRouteStat) |
| | | { |
| | | apsGasPipingRouteStat.setCreateTime(DateUtils.getNowDate()); |
| | | apsGasPipingRouteStat.setCreateBy(SecurityUtils.getUsername()); |
| | | return apsGasPipingRouteStatMapper.insertApsGasPipingRouteStat(apsGasPipingRouteStat); |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹æ°ä½ç®¡è·¯äº§è½è´è½½ç»è®¡ |
| | | * |
| | | * @param apsGasPipingRouteStat æ°ä½ç®¡è·¯äº§è½è´è½½ç»è®¡ |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int updateApsGasPipingRouteStat(ApsGasPipingRouteStat apsGasPipingRouteStat) |
| | | { |
| | | apsGasPipingRouteStat.setUpdateBy(SecurityUtils.getUsername()); |
| | | apsGasPipingRouteStat.setUpdateTime(DateUtils.getNowDate()); |
| | | return apsGasPipingRouteStatMapper.updateApsGasPipingRouteStat(apsGasPipingRouteStat); |
| | | } |
| | | |
| | | /** |
| | | * æ¹éå 餿°ä½ç®¡è·¯äº§è½è´è½½ç»è®¡ |
| | | * |
| | | * @param ids éè¦å é¤çæ°ä½ç®¡è·¯äº§è½è´è½½ç»è®¡ä¸»é® |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int deleteApsGasPipingRouteStatByIds(String[] ids) |
| | | { |
| | | return apsGasPipingRouteStatMapper.deleteApsGasPipingRouteStatByIds(ids); |
| | | } |
| | | |
| | | /** |
| | | * å 餿°ä½ç®¡è·¯äº§è½è´è½½ç»è®¡ä¿¡æ¯ |
| | | * |
| | | * @param id æ°ä½ç®¡è·¯äº§è½è´è½½ç»è®¡ä¸»é® |
| | | * @return ç»æ |
| | | */ |
| | | @Override |
| | | public int deleteApsGasPipingRouteStatById(String id) |
| | | { |
| | | return apsGasPipingRouteStatMapper.deleteApsGasPipingRouteStatById(id); |
| | | } |
| | | |
| | | @Override |
| | | public boolean computeCapacity() { |
| | | // PageHelper.startPage(1, 500); |
| | | List<ApsGasPipingPlan> apsGasPipingPlans = apsGasPipingPlanMapper.selectApsGasPipingPlanWithProcess(new ApsGasPipingPlan()); |
| | | List<ApsGasPipingRouteStat> apsGasPipingRouteStatList = new ArrayList<>(); |
| | | /*æ¬æ¬¡è®¡ç®æ¹æ¬¡å·*/ |
| | | String batchNum = IdUtils.fastSimpleUUID(); |
| | | try { |
| | | apsGasPipingPlans.forEach(apsGasPipingPlan -> { |
| | | List<ApsProcessRoute> apsProcessRoutes = apsGasPipingPlan.getApsProcessRoutes(); |
| | | //æç
§å·¥åºåºå·ååºæåº |
| | | apsProcessRoutes.sort((a, b)->a.getProcessNumber().compareTo(b.getProcessNumber())); |
| | | //æ¯å¦æ¾å°å½åå·¥åº |
| | | boolean isFind = false; |
| | | for (int i=0;i<apsProcessRoutes.size();i++){ |
| | | ApsProcessRoute apsProcessRoute = apsProcessRoutes.get(i); |
| | | ApsGasPipingRouteStat apsGasPipingRouteStat = new ApsGasPipingRouteStat(); |
| | | //å·¥åå· |
| | | apsGasPipingRouteStat.setWorkOrderNo(apsGasPipingPlan.getDocumentNumber()); |
| | | //æå· |
| | | apsGasPipingRouteStat.setItemNumber(apsGasPipingPlan.getItemNumber()); |
| | | //å½åå·¥åºå· |
| | | apsGasPipingRouteStat.setCurrentProcessNumber(apsGasPipingPlan.getProcessNumber()); |
| | | //ç产æ°é |
| | | apsGasPipingRouteStat.setProductionQuantity(apsGasPipingPlan.getProductionQuantity()); |
| | | //å·¥åºåç§° |
| | | apsGasPipingRouteStat.setProcessName(apsProcessRoute.getProcessName()); |
| | | //å·¥åºå· |
| | | apsGasPipingRouteStat.setRoadProcessNumber(apsProcessRoute.getProcessNumber()); |
| | | //æ åå·¥æ¶ |
| | | apsGasPipingRouteStat.setStandardTime(apsProcessRoute.getStandardTime()); |
| | | //ä¸ä¸ |
| | | apsGasPipingRouteStat.setMajor(apsGasPipingPlan.getPlanType()); |
| | | //å·¥åºæ»å·¥æ¶ çäº æ åå·¥æ¶*ç产æ°é |
| | | apsGasPipingRouteStat.setProcessTotalTime(apsProcessRoute.getStandardTime().multiply(apsGasPipingPlan.getProductionQuantity())); |
| | | //计åå¼å·¥æ¥ |
| | | if(apsGasPipingRouteStat.getCurrentProcessNumber().equals(apsGasPipingRouteStat.getRoadProcessNumber())) { |
| | | /* 对 stat.getProcessPlanStartDay() åå½åæ¥æ è¿è¡å¯¹æ¯ï¼åªå¯¹æ¯å°æ¥ï¼ä¸ç¨ç®¡ååç§*/ |
| | | LocalDate startLocalDate = LocalDate.ofInstant(apsProcessRoute.getProcessPlanStartDay().toInstant(), ZoneId.systemDefault()); |
| | | LocalDate nowLocalDate = LocalDate.now(); |
| | | if (startLocalDate.isBefore(nowLocalDate)) { |
| | | apsGasPipingRouteStat.setProcessPlanStartDay(new Date()); |
| | | }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 previousProcessTotalTime = apsGasPipingRouteStatList.get(i - 1).getProcessTotalTime().longValue(); |
| | | LocalDateTime currentProcessPlanStartDay = previousProcessPlanStartDay.plusHours(previousProcessTotalTime); |
| | | apsGasPipingRouteStat.setProcessPlanStartDay(Date.from(Timestamp.valueOf(currentProcessPlanStartDay.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))).toInstant())); |
| | | } |
| | | //æå
¥ å¹´ æ æ¥ |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | String formattedDate = sdf.format(apsGasPipingRouteStat.getProcessPlanStartDay()); |
| | | String[] dateParts = formattedDate.split("-"); |
| | | apsGasPipingRouteStat.setPlanStartYear(String.valueOf(Integer.parseInt(dateParts[0]))); |
| | | apsGasPipingRouteStat.setPlanStartMonth(String.valueOf(Integer.parseInt(dateParts[1]))); |
| | | apsGasPipingRouteStat.setPlanStartDay(String.valueOf(Integer.parseInt(dateParts[2]))); |
| | | //æ åç¨é æ¥è¯¢ç©æç¨é表 |
| | | // ApsGasMaterialUsage apsGasMaterialUsage = new ApsGasMaterialUsage(); |
| | | // apsGasMaterialUsage.setItemNumber(apsGasPipingPlan.getItemNumber()); |
| | | // apsGasMaterialUsage.setProcessName(apsProcessRoute.getProcessName()); |
| | | // List<ApsGasMaterialUsage> apsGasMaterialUsageList = apsGasMaterialUsageService.selectApsGasMaterialUsageList(apsGasMaterialUsage); |
| | | apsGasPipingRouteStat.setStandardDosage(apsProcessRoute.getStandardTime().multiply(apsGasPipingPlan.getProductionQuantity())); |
| | | //å·¥åºæ»ç¨é = æ åç¨é*ç产æ°é |
| | | apsGasPipingRouteStat.setProcessTotalDosage(apsGasPipingRouteStat.getStandardDosage().multiply(apsGasPipingPlan.getProductionQuantity())); |
| | | apsGasPipingRouteStat.setCreateTime(DateUtils.getNowDate()); |
| | | apsGasPipingRouteStat.setCreateBy("auto"); |
| | | apsGasPipingRouteStat.setBatchNumber(batchNum); |
| | | apsGasPipingRouteStat.setId(IdUtils.fastSimpleUUID()); |
| | | apsGasPipingRouteStatList.add(apsGasPipingRouteStat); |
| | | } |
| | | }); |
| | | List<ApsGasPipingRouteStat> tempInsertList = new ArrayList<>(); |
| | | for (int i = 0; i < apsGasPipingRouteStatList.size(); i++) { |
| | | tempInsertList.add(apsGasPipingRouteStatList.get(i)); |
| | | if(tempInsertList.size()==500){ |
| | | apsGasPipingRouteStatMapper.insertApsGasPipingRouteStatBatch(tempInsertList); |
| | | tempInsertList = new ArrayList<>(); |
| | | }else if(i==apsGasPipingRouteStatList.size()-1){ |
| | | apsGasPipingRouteStatMapper.insertApsGasPipingRouteStatBatch(tempInsertList); |
| | | } |
| | | } |
| | | apsGasPipingRouteStatMapper.deleteApsGasPipingRouteStatByBatchNum(batchNum); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | public JSONObject getCapacityPlanData(ApsGasPipingRouteStat apsGasPipingRouteStat) { |
| | | JSONObject result = new JSONObject(); |
| | | HashSet<String> startPlanTimeSet = new HashSet<>(); |
| | | JSONArray processData = new JSONArray(); |
| | | try { |
| | | //è·åå·¥åºè®¡åäº§è½æ°æ® |
| | | HashMap<String, ApsGasPipelineCapacityPlan> apsGasPipingPlanMap = new HashMap<>(); |
| | | List<ApsGasPipelineCapacityPlan> apsGasPipelineCapacityPlanList = apsGasPipelineCapacityPlanMapper.selectApsGasPipelineCapacityPlanList(new ApsGasPipelineCapacityPlan()); |
| | | apsGasPipelineCapacityPlanList.forEach(apsGasPipelineCapacityPlan -> { |
| | | apsGasPipingPlanMap.put(apsGasPipelineCapacityPlan.getProcessName(),apsGasPipelineCapacityPlan); |
| | | }); |
| | | //è®¡ç®æ¥äº§è½æ°æ® |
| | | DateTimeFormatter formatter = null; |
| | | List<ApsGasPipingRouteStat> apsGasPipingRouteStats; |
| | | SimpleDateFormat simpleDateFormat = null; |
| | | YearMonth yearMonth = YearMonth.parse(apsGasPipingRouteStat.getSearchEndDate()); |
| | | int daysInMonth = yearMonth.lengthOfMonth(); |
| | | apsGasPipingRouteStat.setSearchStartDate(apsGasPipingRouteStat.getSearchStartDate()+"-01 00:00:00"); |
| | | apsGasPipingRouteStat.setSearchEndDate(apsGasPipingRouteStat.getSearchEndDate()+"-"+ daysInMonth +" 23:59:59"); |
| | | if("day".equals(apsGasPipingRouteStat.getSearchType())){ |
| | | formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
| | | simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); |
| | | }else if("month".equals(apsGasPipingRouteStat.getSearchType())){ |
| | | formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
| | | simpleDateFormat = new SimpleDateFormat("yyyy-MM"); |
| | | } |
| | | apsGasPipingRouteStats = apsGasPipingRouteStatMapper.selectApsGasPipingRouteStatList(apsGasPipingRouteStat); |
| | | //æ ¹æ®å¼å·¥æ¥è¿è¡ååºæåº |
| | | apsGasPipingRouteStats.sort((a, b)->a.getProcessPlanStartDay().compareTo(b.getProcessPlanStartDay())); |
| | | //å·¥åºåç»ç»è®¡ |
| | | HashMap<String, List<ApsResourceDateStat>> processMap = new HashMap<>(); |
| | | List<HashMap<String, List<ApsResourceDateStat>>> processList = new ArrayList<>(); |
| | | //å·¥åºå¼å·¥æ¥æ |
| | | String planStartDate = ""; |
| | | //ç»è®¡ææå·¥åºå¯¹åºçå¼å·¥æ¶é´ |
| | | for (ApsGasPipingRouteStat apsGasPipingRouteStatTemp : apsGasPipingRouteStats) { |
| | | planStartDate = simpleDateFormat.format(apsGasPipingRouteStatTemp.getProcessPlanStartDay()); |
| | | if("month".equals(apsGasPipingRouteStat.getSearchType())){ |
| | | planStartDate = planStartDate+"-01"; |
| | | } |
| | | ApsResourceDateStat apsResourceDateStat = new ApsResourceDateStat(); |
| | | apsResourceDateStat.setPlanDay(LocalDate.parse(planStartDate, formatter)); |
| | | apsResourceDateStat.setResourceName(apsGasPipingRouteStatTemp.getProcessName()); |
| | | //æ¥è¯¢æ°æç®¡è·¯äº§è½è§å表 |
| | | apsResourceDateStat.setDesignTimes(apsGasPipingPlanMap.get(apsGasPipingRouteStatTemp.getProcessName())!=null?apsGasPipingPlanMap.get(apsGasPipingRouteStatTemp.getProcessName()).getDayProduceAllNum().intValue():0); |
| | | //æ¥è¯¢æå·å·¥åºäº§è½è¡¨ |
| | | apsResourceDateStat.setRequireTimes(apsGasPipingRouteStatTemp.getProcessTotalTime().intValue()); |
| | | if(apsResourceDateStat.getDesignTimes()!=0){ |
| | | apsResourceDateStat.setCapacityLoad(BigDecimal.valueOf(apsResourceDateStat.getRequireTimes()/apsResourceDateStat.getDesignTimes()* 100L)); |
| | | }else{ |
| | | apsResourceDateStat.setCapacityLoad(BigDecimal.valueOf(0)); |
| | | } |
| | | List<ApsResourceDateStat> apsResourceDateStatList = new ArrayList<>(); |
| | | if(processMap.containsKey(apsGasPipingRouteStatTemp.getProcessName())){ |
| | | apsResourceDateStatList = processMap.get(apsGasPipingRouteStatTemp.getProcessName()); |
| | | } |
| | | apsResourceDateStatList.add(apsResourceDateStat); |
| | | processMap.put(apsGasPipingRouteStatTemp.getProcessName(), apsResourceDateStatList); |
| | | } |
| | | //è忝éå·¥åºçå¼å·¥æ¶é´åäº§è½ |
| | | processMap.forEach((processName, apsResourceDateStatList) -> { |
| | | LinkedHashMap<String, ApsResourceDateStat> dayMap = new LinkedHashMap<>(); |
| | | apsResourceDateStatList.forEach(apsResourceDateStat -> { |
| | | startPlanTimeSet.add(apsResourceDateStat.getPlanDay().toString()); |
| | | if(dayMap.containsKey(apsResourceDateStat.getPlanDay().toString())){ |
| | | ApsResourceDateStat apsResourceDateStatTemp = dayMap.get(apsResourceDateStat.getPlanDay().toString()); |
| | | apsResourceDateStatTemp.setDesignTimes(apsGasPipingPlanMap.get(processName)!=null?apsGasPipingPlanMap.get(processName).getMonthProduceAllNum().intValue():0); |
| | | apsResourceDateStatTemp.setRequireTimes(apsResourceDateStatTemp.getRequireTimes()+apsResourceDateStat.getRequireTimes()); |
| | | if(apsResourceDateStatTemp.getDesignTimes()!=0){ |
| | | apsResourceDateStatTemp.setCapacityLoad(BigDecimal.valueOf(apsResourceDateStatTemp.getRequireTimes()/apsResourceDateStatTemp.getDesignTimes()* 100L)); |
| | | }else{ |
| | | apsResourceDateStatTemp.setCapacityLoad(BigDecimal.valueOf(0)); |
| | | } |
| | | apsResourceDateStatTemp.setResourceGroupName(processName); |
| | | apsResourceDateStatTemp.setPlanDay(apsResourceDateStat.getPlanDay()); |
| | | dayMap.put(apsResourceDateStat.getPlanDay().toString(), apsResourceDateStatTemp); |
| | | }else{ |
| | | dayMap.put(apsResourceDateStat.getPlanDay().toString(), apsResourceDateStat); |
| | | } |
| | | }); |
| | | List<ApsResourceDateStat> tempList = new ArrayList<>(); |
| | | dayMap.forEach((key, value) -> { |
| | | tempList.add(value); |
| | | }); |
| | | // processMap.put(processName, tempList); |
| | | HashMap<String, List<ApsResourceDateStat>> temp = new HashMap<>(); |
| | | temp.put(processName, tempList); |
| | | processList.add(temp); |
| | | }); |
| | | // for (String key : processMap.keySet()) { |
| | | // HashMap<String, List<ApsResourceDateStat>> temp = new HashMap<>(); |
| | | // temp.put(key, processMap.get(key)); |
| | | // processList.add(temp); |
| | | // } |
| | | //æåºæ¶é´æ é¢ |
| | | List<String> sortedStartPlanTimeList = new ArrayList<>(startPlanTimeSet); |
| | | Collections.sort(sortedStartPlanTimeList); |
| | | result.put("planTable", processList); |
| | | result.put("planTitle", sortedStartPlanTimeList); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public void exportExcel(HttpServletResponse response, ApsGasPipingRouteStat apsGasPipingRouteStat) { |
| | | SXSSFWorkbook wb = new SXSSFWorkbook(500); |
| | | wb.createSheet(); |
| | | wb.setSheetName(0, "æ°æç®¡è·¯äº§è½è´è½½ç»è®¡è¡¨"); |
| | | response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | |
| | | Map<String, CellStyle> styles = createStyles(wb); |
| | | CellStyle title = styles.get("title"); |
| | | try |
| | | { |
| | | JSONObject stat = getCapacityPlanData(apsGasPipingRouteStat); |
| | | List<String> days = (List<String>) stat.get("planTitle"); |
| | | List<HashMap<String, List<ApsResourceDateStat>>> table= (List<HashMap<String, List<ApsResourceDateStat>>>) stat.get("planTable"); |
| | | SXSSFSheet sheet = wb.getSheetAt(0); |
| | | /*填忥æå å å·¥æ¶å*/ |
| | | SXSSFRow rowDay = sheet.createRow(0); |
| | | SXSSFRow rowTitle = sheet.createRow(1); |
| | | |
| | | SXSSFCell daytitle = rowDay.createCell(0); |
| | | daytitle.setCellValue("æ¥æ"); |
| | | daytitle.setCellStyle(title); |
| | | SXSSFCell titleCell = rowTitle.createCell(0); |
| | | titleCell.setCellValue("å·¥åº"); |
| | | titleCell.setCellStyle(title); |
| | | |
| | | for (int i = 0; i < days.size(); i++) { |
| | | SXSSFCell dateCell = rowDay.createCell(i * 3 + 1); |
| | | SXSSFCell designHoursCell = rowTitle.createCell(i * 3 + 1); |
| | | SXSSFCell requireHoursCell = rowTitle.createCell(i * 3 + 2); |
| | | SXSSFCell loadCell = rowTitle.createCell(i * 3 + 3); |
| | | dateCell.setCellValue(days.get(i)); |
| | | designHoursCell.setCellValue("设计工æ¶"); |
| | | requireHoursCell.setCellValue("鿱工æ¶"); |
| | | loadCell.setCellValue("产è½è´è·"); |
| | | /*set cell style*/ |
| | | dateCell.setCellStyle(title); |
| | | designHoursCell.setCellStyle(title); |
| | | requireHoursCell.setCellStyle(title); |
| | | loadCell.setCellStyle(title); |
| | | |
| | | /*åå¹¶æ¥æåå
æ ¼*/ |
| | | sheet.addMergedRegion( new CellRangeAddress(0, 0, i*3+1, i*3+3)); |
| | | } |
| | | for (int i = 0; i < table.size(); i++) { |
| | | Map<String, List<ApsResourceDateStat>> resourceList = table.get(i); |
| | | /*åå»ºæ°æ®è¡*/ |
| | | SXSSFRow dataRow = sheet.createRow(i+2); |
| | | for( Map.Entry<String, List<ApsResourceDateStat>> entry : resourceList.entrySet()){ |
| | | String resourceName = entry.getKey(); |
| | | List<ApsResourceDateStat> resourceDateStats = entry.getValue(); |
| | | 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()); |
| | | if(apsResourceDateStat.getCapacityLoad()!=null){ |
| | | dataRow.createCell(j*3+3).setCellValue(apsResourceDateStat.getCapacityLoad().doubleValue()+"%"); |
| | | }else{ |
| | | dataRow.createCell(j*3+3).setCellValue("%"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | wb.write(response.getOutputStream()); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | log.error("导åºExcelå¼å¸¸{}", e.getMessage()); |
| | | } |
| | | finally |
| | | { |
| | | IOUtils.closeQuietly(wb); |
| | | } |
| | | } |
| | | private Map<String,CellStyle> createStyles(SXSSFWorkbook wb) |
| | | { |
| | | Map<String,CellStyle> styles=new HashMap<>(); |
| | | CellStyle style = wb.createCellStyle(); |
| | | style.setAlignment(HorizontalAlignment.CENTER); |
| | | style.setVerticalAlignment(VerticalAlignment.CENTER); |
| | | Font titleFont = wb.createFont(); |
| | | titleFont.setFontName("Arial"); |
| | | titleFont.setFontHeightInPoints((short) 12); |
| | | titleFont.setBold(true); |
| | | style.setFont(titleFont); |
| | | DataFormat dataFormat = wb.createDataFormat(); |
| | | style.setDataFormat(dataFormat.getFormat("@")); |
| | | styles.put("title", style); |
| | | return styles; |
| | | } |
| | | } |