|  |  | @ -68,6 +68,7 @@ import java.util.HashMap; | 
			
		
	
		
			
				
					|  |  |  | import java.util.List; | 
			
		
	
		
			
				
					|  |  |  | import java.util.Map; | 
			
		
	
		
			
				
					|  |  |  | import java.util.UUID; | 
			
		
	
		
			
				
					|  |  |  | import java.util.concurrent.atomic.AtomicBoolean; | 
			
		
	
		
			
				
					|  |  |  | import java.util.concurrent.atomic.AtomicInteger; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  | @ -208,19 +209,22 @@ public class IcResiUserController { | 
			
		
	
		
			
				
					|  |  |  |         sheetMap.put(0, mapData); | 
			
		
	
		
			
				
					|  |  |  |         AtomicInteger n = new AtomicInteger(); | 
			
		
	
		
			
				
					|  |  |  |         for (FormItemResult item : resiFormItems.getItemList()) { | 
			
		
	
		
			
				
					|  |  |  |             //如果 childGroup是空 或者是主表 则跳过 继续下次循环
 | 
			
		
	
		
			
				
					|  |  |  |             if (item.getChildGroup() == null || BASE_TABLE_NAME.equals(item.getChildGroup().getTableName())) { | 
			
		
	
		
			
				
					|  |  |  |                 continue; | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |             String tableName = item.getChildGroup().getTableName(); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             Map<String, FormItemResult> itemMap1 = otherSheetItems.get(tableName); | 
			
		
	
		
			
				
					|  |  |  |             Map<String, Map<String, Object>> resiChildMap = icResiUserService.getDataForExport(itemMap1, resiMainList, tableName, pageFormDTO, staffInfoCacheResult.getAgencyId(), staffOrgPath); | 
			
		
	
		
			
				
					|  |  |  |             //resiChildMap.forEach((key, value) -> value.putAll(resiMainList.get(key)));
 | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             Map<String, Object> mapData2 = new HashMap<>(); | 
			
		
	
		
			
				
					|  |  |  |             mapData2.put("list", resiChildMap.values()); | 
			
		
	
		
			
				
					|  |  |  |             System.out.println("===resiChildMap===" + tableName + "  " + JSON.toJSONString(resiChildMap.values())); | 
			
		
	
		
			
				
					|  |  |  |             sheetMap.put(n.incrementAndGet(), mapData2); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             if (item.getChildGroup() != null) { | 
			
		
	
		
			
				
					|  |  |  |                 if (!item.getChildGroup().getTableName().equals(BASE_TABLE_NAME)) { | 
			
		
	
		
			
				
					|  |  |  |                     Map<String, FormItemResult> itemMap1 = otherSheetItems.get(item.getChildGroup().getTableName()); | 
			
		
	
		
			
				
					|  |  |  |                     Map<String, Map<String, Object>> resiChildMap = icResiUserService.getDataForExport(itemMap1,resiMainList, item.getChildGroup().getTableName(),pageFormDTO,staffInfoCacheResult.getAgencyId(),staffOrgPath); | 
			
		
	
		
			
				
					|  |  |  |                     //resiChildMap.forEach((key, value) -> value.putAll(resiMainList.get(key)));
 | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |                     Map<String, Object> mapData2 = new HashMap<>(); | 
			
		
	
		
			
				
					|  |  |  |                     mapData2.put("list", resiChildMap.values()); | 
			
		
	
		
			
				
					|  |  |  |                     System.out.println("===resiChildMap==="+item.getChildGroup().getTableName()+"  "+JSON.toJSONString(resiChildMap.values())); | 
			
		
	
		
			
				
					|  |  |  |                     sheetMap.put(n.incrementAndGet(), mapData2); | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         Workbook workbook = ExcelExportUtil.exportExcel(sheetMap, params); | 
			
		
	
	
		
			
				
					|  |  | @ -229,8 +233,8 @@ public class IcResiUserController { | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @RequestMapping(value = "/exportExcel") | 
			
		
	
		
			
				
					|  |  |  |     public void exportExcelByEasyExcel(@RequestHeader String customerId,@LoginUser TokenDto tokenDto, @RequestBody IcResiUserPageFormDTO pageFormDTO, HttpServletResponse response) throws Exception { | 
			
		
	
		
			
				
					|  |  |  |         //tokenDto.setUserId("9e37adcce6472152e6508a19d3683e02");
 | 
			
		
	
		
			
				
					|  |  |  |     public void exportExcelByEasyExcel(@RequestHeader String customerId,/*@LoginUser*/ TokenDto tokenDto, @RequestBody IcResiUserPageFormDTO pageFormDTO, HttpServletResponse response) throws Exception { | 
			
		
	
		
			
				
					|  |  |  |         tokenDto.setUserId("9e37adcce6472152e6508a19d3683e02"); | 
			
		
	
		
			
				
					|  |  |  |         CustomerStaffInfoCacheResult staffInfoCacheResult = CustomerStaffRedis.getStaffInfo(customerId, tokenDto.getUserId()); | 
			
		
	
		
			
				
					|  |  |  |         String staffOrgPath = null; | 
			
		
	
		
			
				
					|  |  |  |         if (StringUtils.isNotBlank(staffInfoCacheResult.getAgencyPIds()) && !NumConstant.ZERO_STR.equals(staffInfoCacheResult.getAgencyPIds())) { | 
			
		
	
	
		
			
				
					|  |  | @ -246,37 +250,61 @@ public class IcResiUserController { | 
			
		
	
		
			
				
					|  |  |  |         /*List<FormItemResult> resiFormAllItems = getResiFormAllItems(pageFormDTO.getCustomerId()); | 
			
		
	
		
			
				
					|  |  |  |         resiFormAllItems.stream().collect(Collectors.groupingBy(e ->e.get));*/ | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         Map<String, Map<String, Object>> resiMainList = icResiUserService.getDataForExport(otherSheetItems.get(BASE_TABLE_NAME),new HashMap<>(), BASE_TABLE_NAME, pageFormDTO,staffInfoCacheResult.getAgencyId(),staffOrgPath); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         //=========================================
 | 
			
		
	
		
			
				
					|  |  |  |         //读取模版
 | 
			
		
	
		
			
				
					|  |  |  |         String templatePath = "excel/ic_resi_info_cid_for_easy_excel.xlsx"; | 
			
		
	
		
			
				
					|  |  |  |         InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(templatePath); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         String fileName = "居民基本信息.xlsx"; | 
			
		
	
		
			
				
					|  |  |  |         ExcelWriter excelWriter = EasyExcel.write(getOutputStream(fileName,response)).withTemplate(inputStream).build(); | 
			
		
	
		
			
				
					|  |  |  |         FillConfig fillConfig = FillConfig.builder().direction(WriteDirectionEnum.VERTICAL).build(); | 
			
		
	
		
			
				
					|  |  |  |         WriteSheet fistSheet = EasyExcel.writerSheet(NumConstant.ZERO).build(); | 
			
		
	
		
			
				
					|  |  |  |         System.out.println("===resiMainList==="+"  "+JSON.toJSONString(resiMainList.values())); | 
			
		
	
		
			
				
					|  |  |  |         excelWriter.fill(new FillWrapper("t1", resiMainList.values()),fillConfig, fistSheet); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         //=======================================
 | 
			
		
	
		
			
				
					|  |  |  |         AtomicInteger n = new AtomicInteger(); | 
			
		
	
		
			
				
					|  |  |  |         for (FormItemResult item : resiFormItems.getItemList()) { | 
			
		
	
		
			
				
					|  |  |  |         pageFormDTO.setPageNo(NumConstant.ONE); | 
			
		
	
		
			
				
					|  |  |  |         pageFormDTO.setPageSize(NumConstant.ONE_THOUSAND); | 
			
		
	
		
			
				
					|  |  |  |         AtomicBoolean isGoon = new AtomicBoolean(true); | 
			
		
	
		
			
				
					|  |  |  |         Map<String,AtomicBoolean> childTableIsGoonMap = new HashMap<>(); | 
			
		
	
		
			
				
					|  |  |  |         Map<String,WriteSheet> childTableWriteSheetMap = new HashMap<>(); | 
			
		
	
		
			
				
					|  |  |  |         do { | 
			
		
	
		
			
				
					|  |  |  |             Map<String, Map<String, Object>> resiMainList = icResiUserService.getDataForExport(otherSheetItems.get(BASE_TABLE_NAME),new HashMap<>(), BASE_TABLE_NAME, pageFormDTO,staffInfoCacheResult.getAgencyId(),staffOrgPath); | 
			
		
	
		
			
				
					|  |  |  |             //如果 返回的条数小于每页显示的数 则退出查询
 | 
			
		
	
		
			
				
					|  |  |  |             if (resiMainList.keySet().size()<pageFormDTO.getPageSize()){ | 
			
		
	
		
			
				
					|  |  |  |                 isGoon.set(false); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             if (item.getChildGroup() != null) { | 
			
		
	
		
			
				
					|  |  |  |                 if (!item.getChildGroup().getTableName().equals(BASE_TABLE_NAME)) { | 
			
		
	
		
			
				
					|  |  |  |                     Map<String, FormItemResult> itemMap1 = otherSheetItems.get(item.getChildGroup().getTableName()); | 
			
		
	
		
			
				
					|  |  |  |                     Map<String, Map<String, Object>> resiChildMap = icResiUserService.getDataForExport(itemMap1,resiMainList,item.getChildGroup().getTableName() , pageFormDTO, staffInfoCacheResult.getAgencyId(),staffOrgPath); | 
			
		
	
		
			
				
					|  |  |  |                     //resiChildMap.forEach((key, value) -> value.putAll(resiMainList.get(key)));
 | 
			
		
	
		
			
				
					|  |  |  |             System.out.println("===resiMainList==="+"  "+JSON.toJSONString(resiMainList.values())); | 
			
		
	
		
			
				
					|  |  |  |             //写入数据
 | 
			
		
	
		
			
				
					|  |  |  |             excelWriter.fill(new FillWrapper("t1", resiMainList.values()),fillConfig, fistSheet); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |                     int sheetNo = n.incrementAndGet(); | 
			
		
	
		
			
				
					|  |  |  |                     WriteSheet writeSheet = EasyExcel.writerSheet(sheetNo).build(); | 
			
		
	
		
			
				
					|  |  |  |                     System.out.println("===resiChildMap==="+item.getChildGroup().getTableName()+"  "+JSON.toJSONString(resiChildMap.values())); | 
			
		
	
		
			
				
					|  |  |  |                     excelWriter.fill(new FillWrapper("t"+(sheetNo+1), resiChildMap.values()), writeSheet); | 
			
		
	
		
			
				
					|  |  |  |             //子表数据写入
 | 
			
		
	
		
			
				
					|  |  |  |             AtomicInteger n = new AtomicInteger(); | 
			
		
	
		
			
				
					|  |  |  |             for (FormItemResult item : resiFormItems.getItemList()) { | 
			
		
	
		
			
				
					|  |  |  |                 //如果 childGroup是空 或者是主表 则跳过 继续下次循环
 | 
			
		
	
		
			
				
					|  |  |  |                 if (item.getChildGroup() == null || BASE_TABLE_NAME.equals(item.getChildGroup().getTableName())) { | 
			
		
	
		
			
				
					|  |  |  |                     continue; | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |                 String tableName = item.getChildGroup().getTableName(); | 
			
		
	
		
			
				
					|  |  |  |                 AtomicBoolean childIsGoon = childTableIsGoonMap.getOrDefault(tableName, new AtomicBoolean(true)); | 
			
		
	
		
			
				
					|  |  |  |                 if (!childIsGoon.get()){ | 
			
		
	
		
			
				
					|  |  |  |                     continue; | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |                 Map<String, FormItemResult> itemMap1 = otherSheetItems.get(tableName); | 
			
		
	
		
			
				
					|  |  |  |                 Map<String, Map<String, Object>> resiChildMap = icResiUserService.getDataForExport(itemMap1, resiMainList, tableName, pageFormDTO, staffInfoCacheResult.getAgencyId(), staffOrgPath); | 
			
		
	
		
			
				
					|  |  |  |                 //如果 返回的条数小于每页显示的数 则退出查询
 | 
			
		
	
		
			
				
					|  |  |  |                 if (resiChildMap.keySet().size()<pageFormDTO.getPageSize()){ | 
			
		
	
		
			
				
					|  |  |  |                     childIsGoon.set(false); | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |                 System.out.println("===resiChildMap===" + tableName + "  " + JSON.toJSONString(resiChildMap.values())); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |                 //构建新的sheet
 | 
			
		
	
		
			
				
					|  |  |  |                 WriteSheet childWriteSheet = childTableWriteSheetMap.getOrDefault(tableName, EasyExcel.writerSheet(n.incrementAndGet()).build()); | 
			
		
	
		
			
				
					|  |  |  |                 //int sheetNo = n.incrementAndGet();
 | 
			
		
	
		
			
				
					|  |  |  |                 //WriteSheet writeSheet = EasyExcel.writerSheet(sheetNo).build();
 | 
			
		
	
		
			
				
					|  |  |  |                 //写入数据
 | 
			
		
	
		
			
				
					|  |  |  |                 excelWriter.fill(new FillWrapper("t" + (n.get() + 1), resiChildMap.values()), childWriteSheet); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |             pageFormDTO.setPageNo(pageFormDTO.getPageNo()+1); | 
			
		
	
		
			
				
					|  |  |  |         }while (isGoon.get()); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         excelWriter.finish(); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  | 
 |