| | |
| | | package com.aps.core.service.mainPlan.impl; |
| | | |
| | | import com.aps.common.core.annotation.Excel; |
| | | import com.aps.common.core.utils.DateUtils; |
| | | import com.aps.common.core.utils.poi.ExcelUtil; |
| | | import com.aps.common.core.utils.uuid.IdUtils; |
| | | import com.aps.common.core.web.page.TableDataInfo; |
| | | import com.aps.common.security.utils.DictUtils; |
| | | import com.aps.common.security.utils.SecurityUtils; |
| | | import com.aps.core.controller.basicData.ApsGasPipelineCapacityPlanController; |
| | | import com.aps.core.domain.ApsGasPipelineCapacityPlan; |
| | | import com.aps.core.domain.mainPlan.ApsWeldSeamStatisticsV2; |
| | | import com.aps.core.mapper.mainPlan.ApsWeldSeamStatisticsV2Mapper; |
| | | import com.aps.core.service.IApsGasPipelineCapacityPlanService; |
| | | import com.aps.core.service.mainPlan.IApsWeldSeamStatisticsV2Service; |
| | | import com.aps.system.api.domain.SysDictData; |
| | | import com.fasterxml.jackson.databind.JsonNode; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.fasterxml.jackson.databind.node.ObjectNode; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import org.apache.poi.ss.usermodel.CellStyle; |
| | | import org.apache.poi.ss.util.CellRangeAddress; |
| | | 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 org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | |
| | | /** |
| | | * 焊缝统计表V2Service业务层处理 |
| | |
| | | |
| | | return count; |
| | | } |
| | | @Override |
| | | public void exportWeldSeamStatistics(HttpServletResponse response) throws IOException { |
| | | //1. 获取数据源 |
| | | List<ApsWeldSeamStatisticsV2> list = apsWeldSeamStatisticsV2Mapper.selectApsWeldSeamStatisticsV2List(new ApsWeldSeamStatisticsV2()); |
| | | |
| | | |
| | | List<SysDictData> isRequireDic = DictUtils.getDictCache("aps_task_is_require"); |
| | | List<SysDictData> factoryDic = DictUtils.getDictCache("aps_factory"); |
| | | |
| | | |
| | | //2. 创建Excel工作簿 |
| | | SXSSFWorkbook wb = new SXSSFWorkbook(500); |
| | | ExcelUtil<ApsWeldSeamStatisticsV2> excelUtil = new ExcelUtil<>(ApsWeldSeamStatisticsV2.class); |
| | | excelUtil.init(list, "焊缝统计表", "焊缝统计表", Excel.Type.EXPORT); |
| | | excelUtil.createWorkbook(); |
| | | excelUtil.createExcelField(); |
| | | |
| | | Map<String, CellStyle> cellStyleMap = excelUtil.createStyles(wb); |
| | | CellStyle titleStyle = cellStyleMap.get("header_WHITE_GREY_50_PERCENT"); |
| | | CellStyle dataStyle = cellStyleMap.get("data_CENTER_BLACK_WHITE_STRING_false"); |
| | | |
| | | SXSSFSheet sheet = wb.createSheet("焊缝统计表"); |
| | | List<LinkedHashMap<String,String>> titleList= initRowTitle(); |
| | | //3. 构建表头 |
| | | for (int i = 0; i < titleList.size(); i++) { |
| | | SXSSFRow titleRow = sheet.createRow(i); |
| | | LinkedHashMap<String, String> map = titleList.get(i); |
| | | AtomicInteger index = new AtomicInteger(); |
| | | titleList.get(i).forEach((key,value)->{ |
| | | SXSSFCell cell = titleRow.createCell(index.get()); |
| | | cell.setCellValue(value); |
| | | cell.setCellStyle(titleStyle); |
| | | index.getAndIncrement(); |
| | | }); |
| | | } |
| | | //5. 构建数据行 |
| | | LinkedHashMap<String, String> first = titleList.get(0); |
| | | ArrayList<Map.Entry<String, String>> titles = new ArrayList<>(first.entrySet()); |
| | | List<String> stringFiledKeys=Arrays.asList("productionBase","isSatisfy"); |
| | | for (int rowInx = 0; rowInx < list.size(); rowInx++) { |
| | | SXSSFRow dataRow = sheet.createRow(rowInx + 2); |
| | | ApsWeldSeamStatisticsV2 statistics = list.get(rowInx); |
| | | ObjectMapper mapper = new ObjectMapper(); |
| | | ObjectNode node = mapper.valueToTree(statistics); |
| | | for (int colInx = 0; colInx < titles.size(); colInx++) { |
| | | Map.Entry<String, String> entry = titles.get(colInx); |
| | | String filedKey = entry.getKey(); |
| | | SXSSFCell cell = dataRow.createCell(colInx); |
| | | JsonNode jsonNode = node.get(filedKey); |
| | | if(filedKey.equals("productionBase")){ |
| | | factoryDic.stream().filter(x->x.getDictValue().equals(jsonNode.textValue())).findFirst().ifPresent( |
| | | sysDictData -> cell.setCellValue(sysDictData.getDictLabel()) |
| | | ); |
| | | }else if(filedKey.equals("isSatisfy")){ |
| | | isRequireDic.stream().filter(x->x.getDictValue().equals(jsonNode.textValue())).findFirst().ifPresent( |
| | | sysDictData -> cell.setCellValue(sysDictData.getDictLabel()) |
| | | ); |
| | | }else{ |
| | | cell.setCellValue(jsonNode.longValue()); |
| | | } |
| | | cell.setCellStyle(dataStyle); |
| | | } |
| | | } |
| | | for (int i = 0; i < sheet.getRow(0).getLastCellNum(); i++) { |
| | | sheet.setColumnWidth(i, 20 * 256); |
| | | } |
| | | |
| | | //4.合并表头 |
| | | sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 0)); |
| | | sheet.addMergedRegion(new CellRangeAddress(0, 1, 1, 1)); |
| | | sheet.addMergedRegion(new CellRangeAddress(0, 1, 2, 2)); |
| | | sheet.addMergedRegion(new CellRangeAddress(0, 0, 3, 4)); |
| | | sheet.addMergedRegion(new CellRangeAddress(0, 0, 5, 6)); |
| | | sheet.addMergedRegion(new CellRangeAddress(0, 1, 7, 7)); |
| | | sheet.addMergedRegion(new CellRangeAddress(0, 1, 8, 8)); |
| | | sheet.addMergedRegion(new CellRangeAddress(0, 1, 9, 9)); |
| | | sheet.addMergedRegion(new CellRangeAddress(0, 1, 10, 10)); |
| | | sheet.addMergedRegion(new CellRangeAddress(0, 1, 11, 11)); |
| | | sheet.addMergedRegion(new CellRangeAddress(0, 1, 12, 12)); |
| | | //3. 设置响应头 |
| | | response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | wb.write(response.getOutputStream()); |
| | | |
| | | } |
| | | private List<LinkedHashMap<String,String>> initRowTitle(){ |
| | | List<LinkedHashMap<String,String>> list = new ArrayList<>(); |
| | | LinkedHashMap<String,String> level1 = new LinkedHashMap<>(); |
| | | level1.put("year","年份"); |
| | | level1.put("month","月份"); |
| | | level1.put("productionBase","生产基地"); |
| | | level1.put("pipingOrderRequirement","订单需求"); |
| | | level1.put("gasOrderRequirement","订单需求"); |
| | | level1.put("pipingPredictionRequirement","预测需求"); |
| | | level1.put("gasPredictionRequirement","预测需求"); |
| | | level1.put("reserveEmergencyOrderOutput","预留紧急订单产出"); |
| | | level1.put("total","合计"); |
| | | level1.put("days","天数"); |
| | | level1.put("requirementDayWeldSeam","需求日焊缝"); |
| | | level1.put("productionDayWeldSeam","生产日焊缝"); |
| | | level1.put("isSatisfy","是否满足"); |
| | | list.add(level1); |
| | | |
| | | LinkedHashMap<String,String> level2 = new LinkedHashMap<>(); |
| | | level2.put("year","年份"); |
| | | level2.put("month","月份"); |
| | | level2.put("productionBase","生产基地"); |
| | | level2.put("pipingOrderRequirement","管路"); |
| | | level2.put("gasOrderRequirement","气柜"); |
| | | level2.put("pipingPredictionRequirement","管路"); |
| | | level2.put("gasPredictionRequirement","气柜"); |
| | | level2.put("reserveEmergencyOrderOutput","预留紧急订单产出"); |
| | | level2.put("total","合计"); |
| | | level2.put("days","天数"); |
| | | level2.put("requirementDayWeldSeam","需求日焊缝"); |
| | | level2.put("productionDayWeldSeam","生产日焊缝"); |
| | | level2.put("isSatisfy","是否满足"); |
| | | list.add(level2); |
| | | |
| | | return list; |
| | | } |
| | | } |