|
|
@ -27,6 +27,7 @@ import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.commons.tools.constant.ServiceConstant; |
|
|
|
import com.epmet.commons.tools.constant.StrConstant; |
|
|
|
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; |
|
|
|
import com.epmet.commons.tools.enums.FormItemTypeEnum; |
|
|
|
import com.epmet.commons.tools.enums.GenderEnum; |
|
|
|
import com.epmet.commons.tools.enums.HouseTypeEnum; |
|
|
|
import com.epmet.commons.tools.enums.RelationshipEnum; |
|
|
@ -44,6 +45,7 @@ import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.commons.tools.utils.DateUtils; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.constant.IcPlatformConstant; |
|
|
|
import com.epmet.constant.IcResiUserConstant; |
|
|
|
import com.epmet.constant.SystemMessageType; |
|
|
|
import com.epmet.constant.UserConstant; |
|
|
|
import com.epmet.dao.IcResiUserDao; |
|
|
@ -55,6 +57,7 @@ import com.epmet.dto.form.*; |
|
|
|
import com.epmet.dto.form.demand.UserDemandNameQueryFormDTO; |
|
|
|
import com.epmet.dto.result.*; |
|
|
|
import com.epmet.entity.IcResiUserEntity; |
|
|
|
import com.epmet.excel.support.ExportResiUserItemDTO; |
|
|
|
import com.epmet.feign.EpmetHeartOpenFeignClient; |
|
|
|
import com.epmet.feign.EpmetMessageOpenFeignClient; |
|
|
|
import com.epmet.feign.GovOrgOpenFeignClient; |
|
|
@ -63,6 +66,8 @@ import com.epmet.service.IcResiUserService; |
|
|
|
import com.github.pagehelper.Page; |
|
|
|
import com.github.pagehelper.PageHelper; |
|
|
|
import com.github.pagehelper.PageInfo; |
|
|
|
import com.google.common.cache.Cache; |
|
|
|
import com.google.common.cache.CacheBuilder; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
@ -639,131 +644,136 @@ public class IcResiUserServiceImpl extends BaseServiceImpl<IcResiUserDao, IcResi |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public Map<String, Map<String, Object>> getDataForExport(Map<String, FormItemResult> formItemMap, String baseTableName,IcResiUserPageFormDTO pageFormDTO, |
|
|
|
String currentStaffAgencyId, |
|
|
|
String staffOrgPath) { |
|
|
|
public List<Map<String, Object>> getDataForExport(ExportResiUserItemDTO formItemMap, String baseTableName, IcResiUserPageFormDTO pageFormDTO, |
|
|
|
String currentStaffAgencyId, |
|
|
|
String staffOrgPath) { |
|
|
|
Page<Map<String, Object>> mapListPage = PageHelper.startPage(pageFormDTO.getPageNo(), pageFormDTO.getPageSize(), pageFormDTO.getPageFlag()).doSelectPage(() -> { |
|
|
|
this.dynamicQuery(pageFormDTO.getCustomerId(), pageFormDTO.getFormCode(), baseTableName, pageFormDTO.getConditions(), currentStaffAgencyId, staffOrgPath); |
|
|
|
}); |
|
|
|
List<Map<String, Object>> mapList = mapListPage.getResult(); |
|
|
|
Map<String, Map<String, Object>> result = new LinkedHashMap<>(); |
|
|
|
mapList.stream().filter(Objects::nonNull).forEach(map -> { |
|
|
|
//遍历所有字段 格式化时间字段
|
|
|
|
map.forEach((k,o) -> { |
|
|
|
if (o instanceof java.sql.Date){ |
|
|
|
o = DateUtils.format(((Date) o),DateUtils.DATE_PATTERN); |
|
|
|
} |
|
|
|
if (o instanceof java.sql.Timestamp){ |
|
|
|
o = DateUtils.format(new Date(((Timestamp) o).getTime()),DateUtils.DATE_TIME_PATTERN); |
|
|
|
} |
|
|
|
map.put(k,o); |
|
|
|
|
|
|
|
//把checkbox radio select的值放入到map里 并添加对应的
|
|
|
|
|
|
|
|
}); |
|
|
|
Object gridId = map.get(UserConstant.GRID_ID); |
|
|
|
mapListPage.getResult().stream().filter(Objects::nonNull).forEach(map -> { |
|
|
|
String resiId = null; |
|
|
|
|
|
|
|
//获取用户Id
|
|
|
|
if ("ic_resi_user".equals(baseTableName)) { |
|
|
|
if (IcResiUserConstant.IC_RESI_USER.equals(baseTableName)) { |
|
|
|
resiId = (String) map.get("ID"); |
|
|
|
}else { |
|
|
|
resiId = (String) map.get(UserConstant.IC_RESI_USER); |
|
|
|
} |
|
|
|
|
|
|
|
if (StringUtils.isBlank(resiId)){ |
|
|
|
log.error("getDataForExport error,resiId is net exist:{}",map); |
|
|
|
return; |
|
|
|
} |
|
|
|
//把人放进去
|
|
|
|
result.put(resiId, map); |
|
|
|
|
|
|
|
for (Map.Entry<String, FormItemResult> e : formItemMap.entrySet()) { |
|
|
|
String k = e.getKey(); |
|
|
|
FormItemResult v = e.getValue(); |
|
|
|
Object temp = map.get(k); |
|
|
|
String vauleStr = temp == null ? "" : temp.toString(); |
|
|
|
|
|
|
|
if (v.getOptionSourceType().equals("remote")) { |
|
|
|
try { |
|
|
|
Map<String, IcResiUserImportServiceImpl.ColumnWrapper> columnWrappers = new HashMap<>(); |
|
|
|
if (v.getItemId().equals("1078")) { |
|
|
|
IcResiUserImportServiceImpl.ColumnWrapper value = new IcResiUserImportServiceImpl.ColumnWrapper(); |
|
|
|
value.setColValue(gridId.toString()); |
|
|
|
columnWrappers.put("1001", value); |
|
|
|
}else if (v.getOptionSourceValue().contains(StrConstant.QUESTION_MARK)){ |
|
|
|
continue; |
|
|
|
} |
|
|
|
//todo 获取 options
|
|
|
|
Map<String, String> stringMap = icResiUserImportService.listRemoteOptions(columnWrappers, v.getOptionSourceValue(), currentStaffAgencyId, "query"); |
|
|
|
if ("checkbox".equals(v.getItemType())) { |
|
|
|
stringMap.forEach((label, value) -> map.put(value, vauleStr.contains(value) ? "是" : "否")); |
|
|
|
} else if ("select".equals(v.getItemType())) { |
|
|
|
stringMap.forEach((label, value) -> { |
|
|
|
if (vauleStr.equals(value)) { |
|
|
|
map.put(k, label); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} catch (Exception ex) { |
|
|
|
log.warn("listRemoteOptions url:{}", v.getOptionSourceValue()); |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
if ("checkbox".equals(v.getItemType())) { |
|
|
|
//遍历所有字段 格式化时间字段
|
|
|
|
map.forEach((k,o) -> { |
|
|
|
if (o instanceof java.sql.Date){ |
|
|
|
o = DateUtils.format(((Date) o),DateUtils.DATE_PATTERN); |
|
|
|
}else if (o instanceof java.sql.Timestamp){ |
|
|
|
o = DateUtils.format(new Date(((Timestamp) o).getTime()),DateUtils.DATE_TIME_PATTERN); |
|
|
|
} |
|
|
|
map.put(k,o); |
|
|
|
FormItemResult itemResult = formItemMap.getItemMap().get(k); |
|
|
|
if (itemResult == null){ |
|
|
|
return; |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
v.getOptions().forEach(optionDTO -> { |
|
|
|
map.put(optionDTO.getValue(), vauleStr.contains(optionDTO.getValue()) ? "是" : "否"); |
|
|
|
}); |
|
|
|
} else if ("select".equals(v.getItemType())) { |
|
|
|
v.getOptions().forEach(optionDTO -> { |
|
|
|
if (optionDTO.getValue().equals(vauleStr)) { |
|
|
|
map.put(k, optionDTO.getLabel()); |
|
|
|
} |
|
|
|
}); |
|
|
|
} else if ("radio".equals(v.getItemType())) { |
|
|
|
v.getOptions().forEach(optionDTO -> { |
|
|
|
if (optionDTO.getValue().equals(vauleStr)) { |
|
|
|
map.put(k, optionDTO.getLabel()); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
//当前条数据原始的id值 map
|
|
|
|
Map<String,Object> originalConditionMap = new HashMap<>(); |
|
|
|
for (FormItemResult e : formItemMap.getItemMap().values()) { |
|
|
|
String columnName = getColumnName(e); |
|
|
|
Object temp = map.get(columnName); |
|
|
|
String vauleStr = temp == null ? StrConstant.EPMETY_STR : temp.toString(); |
|
|
|
originalConditionMap.putIfAbsent(columnName,vauleStr); |
|
|
|
if ("remote".equals(e.getOptionSourceType()) && StringUtils.isNotBlank(vauleStr)) { |
|
|
|
putRemoteValue(formItemMap.getRemoteItemConditionMap().get(e.getItemId()), currentStaffAgencyId, map,originalConditionMap, e, columnName, vauleStr); |
|
|
|
} else { |
|
|
|
putOptionValue(map, e, columnName, vauleStr); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
if (!"ic_resi_user".equals(baseTableName)) { |
|
|
|
if (!IcResiUserConstant.IC_RESI_USER.equals(baseTableName)) { |
|
|
|
Map<String,Object> o = redisUtils.hGetAll(RedisKeys.getExportResiBaseInfoKey(resiId)); |
|
|
|
if (o != null){ |
|
|
|
map.putAll(o); |
|
|
|
} |
|
|
|
return; |
|
|
|
} |
|
|
|
//把人放入redis缓存 便于后面的sheet使用基础信息
|
|
|
|
redisUtils.hMSet(RedisKeys.getExportResiBaseInfoKey(resiId),map,RedisUtils.MINUTE_THIRTY_EXPIRE); |
|
|
|
}); |
|
|
|
remoteOptionCacheMap.clear(); |
|
|
|
return mapListPage.getResult(); |
|
|
|
} |
|
|
|
|
|
|
|
/*if (gridId != null) { |
|
|
|
CustomerGridFormDTO formDTO = new CustomerGridFormDTO(); |
|
|
|
formDTO.setGridId(gridId.toString()); |
|
|
|
Result<CustomerGridDTO> gridInfoRes = govOrgOpenFeignClient.getGridBaseInfoByGridId(formDTO); |
|
|
|
if (gridInfoRes != null && gridInfoRes.success() && gridInfoRes.getData() != null) { |
|
|
|
map.put(UserConstant.GRID_NAME, gridInfoRes.getData().getGridName()); |
|
|
|
/** |
|
|
|
* key:itemId,value: key:columnName,中文 |
|
|
|
*/ |
|
|
|
private static Map<String,Cache<String,String>> remoteOptionCacheMap = new HashMap<>(); |
|
|
|
private void putRemoteValue(Set<FormItemResult> conditionItemSet, String currentStaffAgencyId, Map<String, Object> map, Map<String, Object> originalConditionMap, FormItemResult e, String columnName, String vauleStr) { |
|
|
|
try { |
|
|
|
Map<String, IcResiUserImportServiceImpl.ColumnWrapper> columnWrappers = new HashMap<>(); |
|
|
|
if (e.getOptionSourceValue().contains(StrConstant.QUESTION_MARK)){ |
|
|
|
for (FormItemResult o : conditionItemSet) { |
|
|
|
String column = getColumnName(o); |
|
|
|
Object conditionValue = originalConditionMap.getOrDefault(column, map.get(column)); |
|
|
|
originalConditionMap.putIfAbsent(column,conditionValue.toString()); |
|
|
|
IcResiUserImportServiceImpl.ColumnWrapper value = new IcResiUserImportServiceImpl.ColumnWrapper(); |
|
|
|
value.setColValue(conditionValue.toString()); |
|
|
|
columnWrappers.put(o.getItemId(), value); |
|
|
|
} |
|
|
|
} |
|
|
|
/*if (e.getItemId().equals("1078")) { |
|
|
|
IcResiUserImportServiceImpl.ColumnWrapper value = new IcResiUserImportServiceImpl.ColumnWrapper(); |
|
|
|
value.setColValue(gridId.toString()); |
|
|
|
columnWrappers.put("1001", value); |
|
|
|
}else if (e.getOptionSourceValue().contains(StrConstant.QUESTION_MARK)){ |
|
|
|
continue; |
|
|
|
}*/ |
|
|
|
Object homeId = map.get(UserConstant.HOME_ID); |
|
|
|
if (homeId != null) { |
|
|
|
HashSet<String> houseIds = new HashSet<>(); |
|
|
|
houseIds.add(homeId.toString()); |
|
|
|
Result<List<HouseInfoDTO>> houseInfoRes = govOrgOpenFeignClient.queryListHouseInfo(houseIds); |
|
|
|
if (houseInfoRes != null && houseInfoRes.success() && CollectionUtils.isNotEmpty(houseInfoRes.getData())) { |
|
|
|
HouseInfoDTO houseInfoDTO = houseInfoRes.getData().get(NumConstant.ZERO); |
|
|
|
map.put("VILLAGE_NAME", houseInfoDTO.getNeighborHoodName()); |
|
|
|
map.put("BUILD_NAME", houseInfoDTO.getBuildingName()); |
|
|
|
map.put("HOME_ID", houseInfoDTO.getHouseName()); |
|
|
|
map.put("UNIT_ID", houseInfoDTO.getUnitName()); |
|
|
|
Cache<String, String> cache = remoteOptionCacheMap.getOrDefault(e.getItemId(), CacheBuilder.newBuilder().maximumSize(NumConstant.FIVE_HUNDRED).build()); |
|
|
|
remoteOptionCacheMap.put(e.getItemId(),cache); |
|
|
|
String cacheValue = cache.getIfPresent(vauleStr); |
|
|
|
if (StringUtils.isNotBlank(cacheValue)){ |
|
|
|
map.put(columnName,cacheValue); |
|
|
|
} else { |
|
|
|
Map<String, String> remoteOptions = icResiUserImportService.listRemoteOptions(columnWrappers, e.getOptionSourceValue(), currentStaffAgencyId, "query"); |
|
|
|
if (FormItemTypeEnum.CHECKBOX.getCode().equals(e.getItemType())) { |
|
|
|
remoteOptions.forEach((label, value) -> map.put(value, vauleStr.contains(value) ? "是" : "否")); |
|
|
|
} else if (FormItemTypeEnum.SELECT.getCode().equals(e.getItemType())) { |
|
|
|
remoteOptions.forEach((label, value) -> { |
|
|
|
if (vauleStr.equals(value)) { |
|
|
|
map.put(columnName, label); |
|
|
|
} |
|
|
|
cache.put(value,label); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
//把人放入缓存
|
|
|
|
redisUtils.hMSet(RedisKeys.getExportResiBaseInfoKey(resiId),map,RedisUtils.MINUTE_THIRTY_EXPIRE); |
|
|
|
}); |
|
|
|
return result; |
|
|
|
} catch (Exception ex) { |
|
|
|
log.warn("listRemoteOptions url:{}", e.getOptionSourceValue()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void putOptionValue(Map<String, Object> map, FormItemResult e, String columnName, String vauleStr) { |
|
|
|
FormItemTypeEnum itemTypeEnum = FormItemTypeEnum.getEnum(e.getItemType()); |
|
|
|
switch (itemTypeEnum) { |
|
|
|
case CHECKBOX: |
|
|
|
e.getOptions().forEach(optionDTO -> { |
|
|
|
map.put(optionDTO.getValue(), vauleStr.contains(optionDTO.getValue()) ? "是" : "否"); |
|
|
|
}); |
|
|
|
break; |
|
|
|
case SELECT: |
|
|
|
case RADIO: |
|
|
|
e.getOptions().forEach(optionDTO -> { |
|
|
|
if (optionDTO.getValue().equals(vauleStr)) { |
|
|
|
map.put(columnName, optionDTO.getLabel()); |
|
|
|
} |
|
|
|
}); |
|
|
|
break; |
|
|
|
default: |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private String getColumnName(FormItemResult e) { |
|
|
|
return e.getColumnNum() == NumConstant.ZERO? e.getColumnName():e.getColumnName().concat(e.getColumnNum().toString()); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|