Browse Source

Merge remote-tracking branch 'origin/dev_ic_platform' into dev_ic_platform

master
wangxianzhang 4 years ago
parent
commit
85d44ece28
  1. 3
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/BuildingController.java
  2. 4
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/BuildingService.java
  3. 28
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/BuildingServiceImpl.java
  4. 72
      epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java

3
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/BuildingController.java

@ -188,8 +188,7 @@ public class BuildingController {
}
List<IcBuildingExcel> result =importResult.getList();
buildingService.importExcel(customerId,result);
return new Result().ok("导入成功");
return new Result().ok(buildingService.importExcel(customerId,result,tokenDTO.getUserId()));
}
/**

4
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<BuildingTreeLevelDTO> treeList(String customerId);
void importExcel(String customerId, List<IcBuildingExcel> list);
Result importExcel(String customerId, List<IcBuildingExcel> list, String staffId);
IcNeighborHoodResultDTO listBuilding(ListIcNeighborHoodFormDTO formDTO);

28
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<IcBuildingExcel> list) {
public Result importExcel(String customerId, List<IcBuildingExcel> list, String staffId) {
//2021.11.9 需求变更 当前工作人员只能导致自己所属组织下数据,网格名对应不上的数据舍弃【注:需求就这样】 sun
CustomerStaffInfoCacheResult staffInfoCache = CustomerStaffRedis.getStaffInfo(customerId, staffId);
//组织名称不一样的数据舍弃
Iterator<IcBuildingExcel> 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

72
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<String, FormItem> itemMap1 = otherSheetItems.get(item.getChildGroup().getTableName());
Map<String, Map<String, Object>> 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<String, Object> mapData2 = new HashMap<>();
mapData2.put("list", resiChildMap.values());
@ -308,57 +307,15 @@ public class IcResiUserController {
Map<String, Map<String, Object>> 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<Map<String, Object>>)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<Integer, Map<String, Object>> sheetMap = new HashMap<>();
Map<String, Object> 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<String, Map<String, Object>> resiChildMap = icResiUserService.getDataForExport(itemMap1,resiMainList, pageFormDTO.getCustomerId(), pageFormDTO.getFormCode(), item.getChildGroup().getTableName(), pageFormDTO.getConditions());
resiChildMap.forEach((key, value) -> value.putAll(resiMainList.get(key)));
/*Map<String, Object> 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()) {

Loading…
Cancel
Save