From fcd921fcb5a279ca702735e0de41d714820a2fa9 Mon Sep 17 00:00:00 2001 From: jianjun Date: Tue, 9 Nov 2021 18:05:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9A=82=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/IcResiUserController.java | 72 +++---------------- 1 file changed, 10 insertions(+), 62 deletions(-) diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java index 6d3a4db52c..3fe32e2409 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java @@ -21,12 +21,12 @@ import cn.afterturn.easypoi.excel.ExcelExportUtil; import cn.afterturn.easypoi.excel.entity.TemplateExportParams; import com.alibaba.excel.EasyExcel; import com.alibaba.excel.ExcelWriter; -import com.alibaba.excel.converters.date.DateDateConverter; -import com.alibaba.excel.converters.date.DateStringConverter; import com.alibaba.excel.write.metadata.WriteSheet; import com.alibaba.excel.write.metadata.fill.FillWrapper; import com.alibaba.fastjson.JSON; import com.epmet.commons.tools.annotation.LoginUser; +import com.epmet.commons.tools.aop.NoRepeatSubmit; +import com.epmet.commons.tools.constant.NumConstant; import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.ExceptionUtils; import com.epmet.commons.tools.exception.RenException; @@ -41,7 +41,6 @@ import com.epmet.dto.result.*; import com.epmet.feign.OperCustomizeOpenFeignClient; import com.epmet.service.IcResiUserImportService; import com.epmet.service.IcResiUserService; -import com.epmet.util.TestFileUtil; import lombok.extern.slf4j.Slf4j; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; @@ -238,7 +237,7 @@ public class IcResiUserController { if (!item.getChildGroup().getTableName().equals(BASE_TABLE_NAME)) { Map itemMap1 = otherSheetItems.get(item.getChildGroup().getTableName()); Map> resiChildMap = icResiUserService.getDataForExport(itemMap1,resiMainList, pageFormDTO.getCustomerId(), pageFormDTO.getFormCode(), item.getChildGroup().getTableName(), pageFormDTO.getConditions()); - resiChildMap.forEach((key, value) -> value.putAll(resiMainList.get(key))); + //resiChildMap.forEach((key, value) -> value.putAll(resiMainList.get(key))); Map mapData2 = new HashMap<>(); mapData2.put("list", resiChildMap.values()); @@ -308,57 +307,15 @@ public class IcResiUserController { Map> resiMainList = icResiUserService.getDataForExport(otherSheetItems.get(BASE_TABLE_NAME),new HashMap<>(), pageFormDTO.getCustomerId(), pageFormDTO.getFormCode(), BASE_TABLE_NAME, pageFormDTO.getConditions()); //========================================= - - - // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替 - // {} 代表普通变量 {.} 代表是list的变量 {前缀.} 前缀可以区分不同的list - -// String templatePath = "/excel/ic_resi_info_cid_for_easy_excel.xls"; -// String s1 = this.getClass().getResource(templatePath).getPath(); -// System.out.println("模版路径:"+s1); -// -// String templateFileName = s1; -// System.out.println("=templateFileName=="+templateFileName); -// String fileName = TestFileUtil.getPath() + "/excel/ic_resi_info_cid_for_easy_excel0000.xls"; -// System.out.println(fileName); -// ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build(); -// WriteSheet writeSheet = EasyExcel.writerSheet(0).build(); -// WriteSheet build = EasyExcel.writerSheet(1).build(); -// // 如果有多个list 模板上必须有{前缀.} 这里的前缀就是 data1,然后多个list必须用 FillWrapper包裹 -// excelWriter.fill(new FillWrapper("t1", resiMainList.values()), writeSheet); -// excelWriter.fill(new FillWrapper("t2", resiMainList.values()), build); - - // 别忘记关闭流 - //excelWriter.finish(); - //EasyExcel.write(new File(fileName)); - //========================================= //resiMainList = (List>)JSON.parse("[{\"IS_BDHJ\":\"1\",\"IS_SPECIAL\":\"1\",\"IS_XFRY\":\"0\",\"REMARKS\":\"beizhu\",\"IS_PARTY\":\"1\",\"icResiUserId\":\"yzmtest2\",\"HOME_ID\":\"中海国际社区一里城1号楼1单元101\",\"HOUSE_TYPE\":\"平房\",\"UNIT_NAME\":\"1单元\",\"GRID_ID\":\"市北区-市北区第三网格3\",\"IS_DB\":\"0\",\"GENDER\":\"男\",\"BIRTHDAY\":\"2021-10-04\",\"IS_VETERANS\":\"0\",\"IS_MB\":\"0\",\"IS_UNEMPLOYED\":\"0\",\"DEMAND_NAME\":null,\"IS_KC\":\"0\",\"IS_ENSURE_HOUSE\":\"0\",\"IS_SD\":\"0\",\"NAME\":\"尹作梅\",\"RDSJ\":null,\"IS_VOLUNTEER\":\"1\",\"GRID_ID_VALUE\":\"e74829ffc43d5470eba6b5e060c11e63\",\"IS_SZ\":\"0\",\"IS_CJ\":\"0\",\"HOME_ID_VALUE\":\"200\",\"DEMAND_CATEGORY_IDS\":null,\"VILLAGE_NAME\":\"中海国际社区一里城\",\"IS_DBH\":\"0\",\"IS_SN\":\"0\",\"BUILD_NAME\":\"1号楼\",\"IS_YLFN\":\"0\",\"IS_UNITED_FRONT\":\"0\",\"ID_CARD\":\"371325199310260529\",\"MOBILE\":\"15764229697\",\"IS_OLD_PEOPLE\":\"0\",\"DOOR_NAME\":\"101\"},{\"IS_SPECIAL\":\"1\",\"IS_XFRY\":\"0\",\"REMARKS\":\"beizhu\",\"IS_PARTY\":\"1\",\"icResiUserId\":\"yzmtest\",\"HOME_ID\":\"中海国际社区一里城1号楼1单元101\",\"HOUSE_TYPE\":\"平房\",\"UNIT_NAME\":\"1单元\",\"GRID_ID\":\"市北区-市北区第三网格3\",\"IS_DB\":\"0\",\"GENDER\":\"男\",\"BIRTHDAY\":\"2021-10-04\",\"IS_VETERANS\":\"0\",\"IS_MB\":\"0\",\"IS_UNEMPLOYED\":\"0\",\"DEMAND_NAME\":\"心理咨询\",\"IS_KC\":\"0\",\"IS_ENSURE_HOUSE\":\"0\",\"IS_SD\":\"0\",\"NAME\":\"尹作梅\",\"RDSJ\":\"2021-10-28 00:00:00\",\"IS_VOLUNTEER\":\"1\",\"GRID_ID_VALUE\":\"e74829ffc43d5470eba6b5e060c11e63\",\"IS_SZ\":\"0\",\"IS_CJ\":\"0\",\"HOME_ID_VALUE\":\"200\",\"DEMAND_CATEGORY_IDS\":\"10180002\",\"VILLAGE_NAME\":\"中海国际社区一里城\",\"IS_DBH\":\"0\",\"IS_SN\":\"0\",\"BUILD_NAME\":\"1号楼\",\"IS_YLFN\":\"0\",\"IS_UNITED_FRONT\":\"0\",\"ID_CARD\":\"371325199310260529\",\"MOBILE\":\"15764229697\",\"IS_OLD_PEOPLE\":\"0\",\"DOOR_NAME\":\"101\"}]"); - String originValue = JSON.toJSONString(resiMainList.values()); - System.out.println("========="+ originValue); - String templatePath = "/excel/ic_resi_info_cid_for_easy_excel.xls"; - String s1 = this.getClass().getResource(templatePath).getPath(); - System.out.println("模版路径:"+s1); - //TemplateExportParams params = new TemplateExportParams(templatePath, true); - String fileName = TestFileUtil.getPath() + "compositeFill" + "ic_resi_info_cid_for_easy_excel.xls"; - fileName = "/Users/liujianjun/Downloads/ic_resi_info_cid_for_easy_excel2.xls"; - System.out.println("fileName======="+fileName); - //String fileName = "居民基本信息.xls"; - ExcelWriter excelWriter = EasyExcel.write(getOutputStream(fileName,response)).registerConverter(new DateStringConverter()).registerConverter(new DateDateConverter()).withTemplate(s1).build(); - //ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(s1).build(); - WriteSheet fistSheet = EasyExcel.writerSheet(0).build(); - try { - excelWriter.fill(new FillWrapper("t1", resiMainList.values()), fistSheet); - } catch (Exception e) { - e.printStackTrace(); - } + String templatePath = this.getClass().getResource("/excel/ic_resi_info_cid_for_easy_excel.xls").getPath(); - //======================================= + String fileName = "居民基本信息.xls"; + ExcelWriter excelWriter = EasyExcel.write(getOutputStream(fileName,response)).withTemplate(templatePath).build(); + WriteSheet fistSheet = EasyExcel.writerSheet(NumConstant.ZERO).build(); + excelWriter.fill(new FillWrapper("t1", resiMainList.values()), fistSheet); - /* Map> sheetMap = new HashMap<>(); - Map mapData = new HashMap<>(); - mapData.put("list", resiMainList.values()); - System.out.println("========="+JSON.toJSONString(resiMainList.values())); - sheetMap.put(0, mapData);*/ + //======================================= AtomicInteger n = new AtomicInteger(); for (FormItem item : resiFormItems.getItemList()) { @@ -368,10 +325,6 @@ public class IcResiUserController { Map> resiChildMap = icResiUserService.getDataForExport(itemMap1,resiMainList, pageFormDTO.getCustomerId(), pageFormDTO.getFormCode(), item.getChildGroup().getTableName(), pageFormDTO.getConditions()); resiChildMap.forEach((key, value) -> value.putAll(resiMainList.get(key))); - /*Map mapData2 = new HashMap<>(); - mapData2.put("list", resiChildMap.values()); - System.out.println("========="+JSON.toJSONString(mapData2)); - sheetMap.put(n.incrementAndGet(), mapData2);*/ int sheetNo = n.incrementAndGet(); WriteSheet writeSheet = EasyExcel.writerSheet(sheetNo).build(); System.out.println("======"+JSON.toJSONString(resiChildMap.values())); @@ -380,14 +333,8 @@ public class IcResiUserController { } } - /* Workbook workbook = ExcelExportUtil.exportExcel(sheetMap, params); - workbook.setActiveSheet(0);*/ excelWriter.finish(); - - /* response.setHeader("content-Type", "application/vnd.ms-excel"); - response.addHeader("Content-Disposition", "attachment;fileName=" + URLEncoder.encode(fileName, "UTF-8")); - workbook.write(response.getOutputStream());*/ } private static OutputStream getOutputStream(String fileName, HttpServletResponse response) throws Exception { fileName = URLEncoder.encode(fileName, "UTF-8"); @@ -404,6 +351,7 @@ public class IcResiUserController { * * @return */ + @NoRepeatSubmit @PostMapping("importExcel") public void importExcelByEasyExcel(@RequestPart("file") MultipartFile file, HttpServletResponse response) { if (file.isEmpty()) {