From 436504300e59093766323b45eed5ed424514f615 Mon Sep 17 00:00:00 2001 From: sunyuchao Date: Tue, 9 Nov 2021 17:46:25 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=A5=BC=E6=A0=8B=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E5=AF=BC=E5=85=A5=20=E6=8C=89=E9=9C=80=E6=B1=82=E5=8F=98?= =?UTF-8?q?=E6=9B=B4=E4=BF=AE=E6=94=B9=E3=80=90=E9=9C=80=E6=B1=82=EF=BC=9A?= =?UTF-8?q?=E5=8F=AA=E8=83=BD=E5=AF=BC=E5=85=A5=E5=BD=93=E5=89=8D=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E4=BA=BA=E6=89=80=E5=B1=9E=E7=BB=84=E7=BB=87=E4=B8=8B?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=EF=BC=8C=E5=8C=B9=E9=85=8D=E4=B8=8D=E4=B8=8A?= =?UTF-8?q?=E7=9A=84=E6=95=B0=E6=8D=AE=E8=88=8D=E5=BC=83=EF=BC=8C=E5=B0=86?= =?UTF-8?q?=E5=8C=B9=E9=85=8D=E4=B8=8D=E4=B8=8A=E7=9A=84=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=BB=99=E5=88=B0=E5=89=8D=E7=AB=AF=E6=8F=90=E7=A4=BA=20?= =?UTF-8?q?=E5=A6=82=E5=8D=97=E5=AE=81=E7=A4=BE=E5=8C=BA=E4=B8=8D=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../epmet/controller/BuildingController.java | 3 +- .../com/epmet/service/BuildingService.java | 4 +-- .../service/impl/BuildingServiceImpl.java | 28 +++++++++++++++++-- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/BuildingController.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/BuildingController.java index 5f7533dfaa..5b408d1367 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/BuildingController.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/BuildingController.java @@ -188,8 +188,7 @@ public class BuildingController { } List result =importResult.getList(); - buildingService.importExcel(customerId,result); - return new Result().ok("导入成功"); + return new Result().ok(buildingService.importExcel(customerId,result,tokenDTO.getUserId())); } /** diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/BuildingService.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/BuildingService.java index 728c472116..1a8c8c04e9 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/BuildingService.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/BuildingService.java @@ -17,13 +17,13 @@ package com.epmet.service; +import com.epmet.commons.tools.utils.Result; import com.epmet.dto.BuildingTreeLevelDTO; import com.epmet.dto.form.IcBulidingFormDTO; import com.epmet.dto.form.ListIcNeighborHoodFormDTO; import com.epmet.dto.result.BuildingResultDTO; import com.epmet.dto.result.IcNeighborHoodResultDTO; import com.epmet.excel.IcBuildingExcel; -import com.epmet.excel.IcNeighborHoodExcel; import javax.servlet.http.HttpServletResponse; import java.util.List; @@ -53,7 +53,7 @@ public interface BuildingService { List treeList(String customerId); - void importExcel(String customerId, List list); + Result importExcel(String customerId, List list, String staffId); IcNeighborHoodResultDTO listBuilding(ListIcNeighborHoodFormDTO formDTO); diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/BuildingServiceImpl.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/BuildingServiceImpl.java index 61ad0ba641..40659b958f 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/BuildingServiceImpl.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/BuildingServiceImpl.java @@ -4,9 +4,12 @@ import cn.afterturn.easypoi.excel.entity.TemplateExportParams; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.RenException; +import com.epmet.commons.tools.redis.common.CustomerStaffRedis; import com.epmet.commons.tools.utils.ConvertUtils; +import com.epmet.commons.tools.utils.Result; import com.epmet.dao.*; import com.epmet.dto.BuildingTreeLevelDTO; import com.epmet.dto.CustomerStaffAgencyDTO; @@ -207,10 +210,23 @@ public class BuildingServiceImpl implements BuildingService { @Override @Transactional(rollbackFor = Exception.class) - public void importExcel(String customerId, List list) { + public Result importExcel(String customerId, List list, String staffId) { + //2021.11.9 需求变更 当前工作人员只能导致自己所属组织下数据,网格名对应不上的数据舍弃【注:需求就这样】 sun + CustomerStaffInfoCacheResult staffInfoCache = CustomerStaffRedis.getStaffInfo(customerId, staffId); + //组织名称不一样的数据舍弃 + Iterator iterator = list.iterator(); + while (iterator.hasNext()) { + IcBuildingExcel obj = iterator.next(); + if (!obj.getAgencyName().trim().equals(staffInfoCache.getAgencyName())) { + iterator.remove(); + } + } + //用于存储匹配不上的数据给前端的提示 如南宁社区不存在 + StringBuffer str = new StringBuffer(""); + //end sun //导入 if(CollectionUtils.isEmpty(list)){ - return ; + return new Result(); } //查询所有组织和网格根据名字 @@ -235,6 +251,10 @@ public class BuildingServiceImpl implements BuildingService { entity.setId(uuid); entity.setCustomerId(customerId); entity.setNeighborHoodId(Optional.ofNullable(neighborHoodMap.get(icBuildingExcel.getNeighborHoodName())).map(u->u.getId()).orElse(""));//neighborHoodMap.get(icBuildingExcel.getNeighborHoodName()).getId() + if ("".equals(entity.getNeighborHoodId())) { + str.append("".equals(str) ? icBuildingExcel.getNeighborHoodName() : str.append("、").append(icBuildingExcel.getNeighborHoodName())); + continue; + } entity.setBuildingName(icBuildingExcel.getBuildingName()); entity.setType(BuildingTypeEnums.getKeyByValue(icBuildingExcel.getType())); entity.setSort(0); @@ -266,6 +286,10 @@ public class BuildingServiceImpl implements BuildingService { icBuildingService.insertBatch(buildingEntityList); icBuildingUnitService.insertBatch(icBuildingUnitEntityList); + if(!"".equals(str)){ + return new Result().error(9999, str.append("不存在").toString()); + } + return new Result(); } @Override From fcd921fcb5a279ca702735e0de41d714820a2fa9 Mon Sep 17 00:00:00 2001 From: jianjun Date: Tue, 9 Nov 2021 18:05:51 +0800 Subject: [PATCH 2/2] =?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()) {