Browse Source

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

master
jianjun 4 years ago
parent
commit
6dbc87d292
  1. 4
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java
  2. 116
      epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java
  3. 3
      epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcResiUserService.java
  4. 15
      epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserServiceImpl.java
  5. 6
      epmet-user/epmet-user-server/src/main/resources/mapper/IcResiUserDao.xml

4
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java

@ -614,4 +614,8 @@ public class RedisKeys {
public static String getIcFormItemsKey(String customerId, String formCode) {
return rootPrefix.concat("icform:").concat(formCode).concat(":items:").concat(customerId);
}
public static String getExportResiBaseInfoKey(String resiId) {
return rootPrefix.concat("resi:").concat("export").concat(":temp:").concat(resiId);
}
}

116
epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java

@ -64,11 +64,7 @@ import java.net.URLEncoder;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
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.*;
import java.util.concurrent.atomic.AtomicInteger;
@ -108,9 +104,9 @@ public class IcResiUserController {
}
@PostMapping("delete")
public Result delete(@LoginUser TokenDto tokenDto,@RequestBody DelIcResiUserFormDTO formDTO){
public Result delete(@LoginUser TokenDto tokenDto, @RequestBody DelIcResiUserFormDTO formDTO) {
formDTO.setCustomerId(tokenDto.getCustomerId());
ValidatorUtils.validateEntity(formDTO,DelIcResiUserFormDTO.IdGroup.class);
ValidatorUtils.validateEntity(formDTO, DelIcResiUserFormDTO.IdGroup.class);
icResiUserService.delete(formDTO);
return new Result();
}
@ -175,20 +171,21 @@ public class IcResiUserController {
/**
* desc :备用 easypoi
*
* @param customerId
* @param pageFormDTO
* @param response
* @throws Exception
*/
@RequestMapping(value = "/exportExcel2")
public void exportExcel(@RequestHeader String customerId,@LoginUser TokenDto tokenDto, @RequestBody IcResiUserPageFormDTO pageFormDTO, HttpServletResponse response) throws Exception {
public void exportExcel(@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())) {
staffOrgPath = staffInfoCacheResult.getAgencyPIds().concat(":").concat(staffInfoCacheResult.getAgencyId());
}else{
staffOrgPath=staffInfoCacheResult.getAgencyId();
} else {
staffOrgPath = staffInfoCacheResult.getAgencyId();
}
pageFormDTO.setCustomerId(customerId);
pageFormDTO.setPageFlag(false);
@ -196,7 +193,7 @@ public class IcResiUserController {
Map<String, Map<String, FormItemResult>> otherSheetItems = buildItemMap(resiFormItems);
Map<String, Map<String, Object>> resiMainList = icResiUserService.getDataForExport(otherSheetItems.get(BASE_TABLE_NAME),new HashMap<>(),BASE_TABLE_NAME, pageFormDTO,staffInfoCacheResult.getAgencyId(),staffOrgPath);
Map<String, Map<String, Object>> resiMainList = icResiUserService.getDataForExport(otherSheetItems.get(BASE_TABLE_NAME), BASE_TABLE_NAME, pageFormDTO, staffInfoCacheResult.getAgencyId(), staffOrgPath);
//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\"}]");
log.info("resiMainList:{}", JSON.toJSONString(resiMainList));
String templatePath = "excel/ic_resi_info_cid.xls";
@ -205,7 +202,7 @@ public class IcResiUserController {
Map<Integer, Map<String, Object>> sheetMap = new HashMap<>();
Map<String, Object> mapData = new HashMap<>();
mapData.put("list", resiMainList.values());
System.out.println("===resiMainList==="+" "+JSON.toJSONString(resiMainList.values()));
System.out.println("===resiMainList===" + " " + JSON.toJSONString(resiMainList.values()));
sheetMap.put(0, mapData);
AtomicInteger n = new AtomicInteger();
for (FormItemResult item : resiFormItems.getItemList()) {
@ -216,7 +213,7 @@ public class IcResiUserController {
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);
Map<String, Map<String, Object>> resiChildMap = icResiUserService.getDataForExport(itemMap1, tableName, pageFormDTO, staffInfoCacheResult.getAgencyId(), staffOrgPath);
//resiChildMap.forEach((key, value) -> value.putAll(resiMainList.get(key)));
Map<String, Object> mapData2 = new HashMap<>();
@ -229,18 +226,18 @@ public class IcResiUserController {
Workbook workbook = ExcelExportUtil.exportExcel(sheetMap, params);
workbook.setActiveSheet(0);
workbook.write(getOutputStream("居民基本信息.xls",response));
workbook.write(getOutputStream("居民基本信息.xls", response));
}
@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())) {
staffOrgPath = staffInfoCacheResult.getAgencyPIds().concat(":").concat(staffInfoCacheResult.getAgencyId());
}else{
staffOrgPath=staffInfoCacheResult.getAgencyId();
} else {
staffOrgPath = staffInfoCacheResult.getAgencyId();
}
pageFormDTO.setCustomerId(customerId);
pageFormDTO.setPageFlag(false);
@ -254,60 +251,71 @@ public class IcResiUserController {
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();
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();
pageFormDTO.setPageSize(4);
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<>();
//子表是否停止查询
Set<String> stopSearchSet = new HashSet<>();
Map<String, WriteSheet> childTableWriteSheetMap = new HashMap<>();
Map<String, Map<String, Object>> resiMainTableMap = null;
do {
Map<String, Map<String, Object>> resiMainList = icResiUserService.getDataForExport(otherSheetItems.get(BASE_TABLE_NAME),new HashMap<>(), BASE_TABLE_NAME, pageFormDTO,staffInfoCacheResult.getAgencyId(),staffOrgPath);
resiMainTableMap = icResiUserService.getDataForExport(otherSheetItems.get(BASE_TABLE_NAME), BASE_TABLE_NAME, pageFormDTO, staffInfoCacheResult.getAgencyId(), staffOrgPath);
//如果 返回的条数小于每页显示的数 则退出查询
if (resiMainList.keySet().size()<pageFormDTO.getPageSize()){
isGoon.set(false);
if (resiMainTableMap.keySet().size() < pageFormDTO.getPageSize()) {
stopSearchSet.add(BASE_TABLE_NAME);
}
System.out.println("===resiMainList==="+" "+JSON.toJSONString(resiMainList.values()));
System.out.println("===resiMainTableMap===" + " " + JSON.toJSONString(resiMainTableMap.values()));
//写入数据
excelWriter.fill(new FillWrapper("t1", resiMainList.values()),fillConfig, fistSheet);
excelWriter.fill(new FillWrapper("t1", resiMainTableMap.values()), fillConfig, fistSheet);
pageFormDTO.setPageNo(pageFormDTO.getPageNo() + 1);
//重置数据
resiMainTableMap.clear();
} while (!stopSearchSet.contains(BASE_TABLE_NAME));
//子表数据写入
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()){
//子表数据写入
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();
pageFormDTO.setPageNo(NumConstant.ONE);
//循环一次 写入每个sheet
do {
//如果包含则说明子表的数据 已经查询完毕 无需再继续查询了
boolean contains = stopSearchSet.contains(tableName);
if (contains) {
continue;
}
Map<String, FormItemResult> itemMap1 = otherSheetItems.get(tableName);
Map<String, Map<String, Object>> resiChildMap = icResiUserService.getDataForExport(itemMap1, resiMainList, tableName, pageFormDTO, staffInfoCacheResult.getAgencyId(), staffOrgPath);
Map<String, Map<String, Object>> resiChildMap = icResiUserService.getDataForExport(itemMap1, tableName, pageFormDTO, staffInfoCacheResult.getAgencyId(), staffOrgPath);
//如果 返回的条数小于每页显示的数 则退出查询
if (resiChildMap.keySet().size()<pageFormDTO.getPageSize()){
childIsGoon.set(false);
if (resiChildMap.keySet().size() < pageFormDTO.getPageSize()) {
stopSearchSet.add(tableName);
}
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();
WriteSheet childWriteSheet = childTableWriteSheetMap.get(tableName);
if (childWriteSheet == null) {
childWriteSheet = EasyExcel.writerSheet(n.incrementAndGet()).build();
}
childTableWriteSheetMap.put(tableName, childWriteSheet);
//写入数据
excelWriter.fill(new FillWrapper("t" + (n.get() + 1), resiChildMap.values()), childWriteSheet);
}
pageFormDTO.setPageNo(pageFormDTO.getPageNo()+1);
}while (isGoon.get());
excelWriter.fill(new FillWrapper("t" + (n.get() + NumConstant.ONE), resiChildMap.values()), childWriteSheet);
pageFormDTO.setPageNo(pageFormDTO.getPageNo() + NumConstant.ONE);
//重置数据
resiChildMap.clear();
} while (!stopSearchSet.contains(tableName));
}
excelWriter.finish();
}
@NotNull
@ -364,7 +372,7 @@ public class IcResiUserController {
fileName = URLEncoder.encode(fileName, "UTF-8");
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("utf8");
response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
response.addHeader("Access-Control-Expose-Headers", "Content-disposition");
return response.getOutputStream();
@ -409,14 +417,14 @@ public class IcResiUserController {
}
@PostMapping("test")
public Result<List<Map<String, Object>>> test(@LoginUser TokenDto tokenDto,@RequestBody DynamicQueryFormDTO formDTO) {
public Result<List<Map<String, Object>>> test(@LoginUser TokenDto tokenDto, @RequestBody DynamicQueryFormDTO formDTO) {
formDTO.setCustomerId("45687aa479955f9d06204d415238f7cc");
//formDTO.setCustomerId(tokenDto.getCustomerId());
return new Result<List<Map<String, Object>>>().ok(icResiUserService.dynamicQuery(formDTO.getCustomerId(),
formDTO.getFormCode(),
formDTO.getResultTableName(),
formDTO.getConditions(),
tokenDto.getUserId(),null));
tokenDto.getUserId(), null));
}
/**

3
epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcResiUserService.java

@ -106,11 +106,10 @@ public interface IcResiUserService extends BaseService<IcResiUserEntity> {
* desc:条件导出
*
* @param itemList
* @param resiMainList
* @param baseTableName
* @return Map<String,Map<String,Object>> 用户Id用户信息所有的字段名及值
*/
Map<String, Map<String, Object>> getDataForExport(Map<String, FormItemResult> itemList, Map<String, Map<String, Object>> resiMainList, String baseTableName, IcResiUserPageFormDTO pageFormDTO, String currentStaffAgencyId,
Map<String, Map<String, Object>> getDataForExport(Map<String, FormItemResult> itemList, String baseTableName, IcResiUserPageFormDTO pageFormDTO, String currentStaffAgencyId,
String staffOrgPath);
/**

15
epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserServiceImpl.java

@ -31,6 +31,8 @@ import com.epmet.commons.tools.enums.HouseTypeEnum;
import com.epmet.commons.tools.enums.RelationshipEnum;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.redis.RedisKeys;
import com.epmet.commons.tools.redis.RedisUtils;
import com.epmet.commons.tools.redis.common.CustomerOrgRedis;
import com.epmet.commons.tools.redis.common.CustomerStaffRedis;
import com.epmet.commons.tools.redis.common.bean.GridInfoCache;
@ -85,6 +87,8 @@ public class IcResiUserServiceImpl extends BaseServiceImpl<IcResiUserDao, IcResi
@Autowired
private IcResiUserImportServiceImpl icResiUserImportService;
@Autowired
private RedisUtils redisUtils;
private QueryWrapper<IcResiUserEntity> getWrapper(Map<String, Object> params){
String id = (String)params.get(FieldConstant.ID_HUMP);
@ -614,12 +618,11 @@ public class IcResiUserServiceImpl extends BaseServiceImpl<IcResiUserDao, IcResi
*
*
* @param formItemMap key 表名 value formItem
* @param resiMainList
* @param baseTableName
* @return
*/
@Override
public Map<String, Map<String, Object>> getDataForExport(Map<String, FormItemResult> formItemMap, Map<String, Map<String, Object>> resiMainList, String baseTableName,IcResiUserPageFormDTO pageFormDTO,
public Map<String, Map<String, Object>> getDataForExport(Map<String, FormItemResult> formItemMap, String baseTableName,IcResiUserPageFormDTO pageFormDTO,
String currentStaffAgencyId,
String staffOrgPath) {
Page<Map<String, Object>> mapListPage = PageHelper.startPage(pageFormDTO.getPageNo(), pageFormDTO.getPageSize(), pageFormDTO.getPageFlag()).doSelectPage(() -> {
@ -668,7 +671,6 @@ public class IcResiUserServiceImpl extends BaseServiceImpl<IcResiUserDao, IcResi
try {
Map<String, IcResiUserImportServiceImpl.ColumnWrapper> columnWrappers = new HashMap<>();
if (v.getItemId().equals("1078")) {
Map<String, Object> userMap = resiMainList.get(map.get(UserConstant.IC_RESI_USER));
IcResiUserImportServiceImpl.ColumnWrapper value = new IcResiUserImportServiceImpl.ColumnWrapper();
value.setColValue(gridId.toString());
columnWrappers.put("1001", value);
@ -711,7 +713,10 @@ public class IcResiUserServiceImpl extends BaseServiceImpl<IcResiUserDao, IcResi
}
if (!"ic_resi_user".equals(baseTableName)) {
map.putAll(resiMainList.get(resiId));
Map<String,Object> o = (Map<String, Object>) redisUtils.get(RedisKeys.getExportResiBaseInfoKey(resiId));
if (o != null){
map.putAll(o);
}
return;
}
@ -736,6 +741,8 @@ public class IcResiUserServiceImpl extends BaseServiceImpl<IcResiUserDao, IcResi
map.put("UNIT_ID", houseInfoDTO.getUnitName());
}
}
//把人放入缓存
redisUtils.set(RedisKeys.getExportResiBaseInfoKey(resiId),map,RedisUtils.MINUTE_THIRTY_EXPIRE);
});
return result;
}

6
epmet-user/epmet-user-server/src/main/resources/mapper/IcResiUserDao.xml

@ -47,6 +47,10 @@
<!-- 列表查询 -->
<sql id="listWhereForPage">
ic_resi_user.DEL_FLAG = '0'
<!--如果查询的left表则不显示空的数据-->
<if test="resultTableName != null and resultTableName != ''">
AND ${resultTableName}.ID IS NOT NULL
</if>
and ic_resi_user.customer_id=#{customerId}
and (ic_resi_user.AGENCY_ID =#{currentStaffAgencyId} or ic_resi_user.pids like concat(#{staffOrgPath},'%'))
<if test="null != conditions and conditions.size() > 0">
@ -261,4 +265,4 @@
where DEL_FLAG = '0'
AND CUSTOMER_ID = #{customerId}
</select>
</mapper>
</mapper>

Loading…
Cancel
Save