|
|
@ -73,6 +73,11 @@ public class IcResiUserExportServiceImpl implements IcResiUserExportService { |
|
|
|
@Autowired |
|
|
|
private IcResiUserImportService icResiUserImportService; |
|
|
|
|
|
|
|
/** |
|
|
|
* key:itemId,value: key:columnName,中文 |
|
|
|
*/ |
|
|
|
private static Map<String, Cache<String, String>> remoteOptionCacheMap = new HashMap<>(); |
|
|
|
|
|
|
|
/** |
|
|
|
* desc: 根据条件查询居民信息并根据配置模板导出 |
|
|
|
* |
|
|
@ -86,7 +91,7 @@ public class IcResiUserExportServiceImpl implements IcResiUserExportService { |
|
|
|
@Override |
|
|
|
public void exportIcResiUser(TokenDto tokenDto, ExportResiUserFormDTO exportResiUserFormDTO, HttpServletResponse response) { |
|
|
|
//校验参数
|
|
|
|
validateSearchForm(tokenDto, exportResiUserFormDTO); |
|
|
|
this.validateSearchForm(tokenDto, exportResiUserFormDTO); |
|
|
|
IcResiUserPageFormDTO searchForm = exportResiUserFormDTO.getSearchForm(); |
|
|
|
|
|
|
|
String templateId = exportResiUserFormDTO.getTemplateId(); |
|
|
@ -94,7 +99,7 @@ public class IcResiUserExportServiceImpl implements IcResiUserExportService { |
|
|
|
ExcelWriter excelWriter = null; |
|
|
|
try { |
|
|
|
//获取用户配置的导出条件
|
|
|
|
Result<IcCustomExportResultDTO> exportConfigResult = getIcCustomExportConfig(searchForm.getCustomerId(), templateId, exportResiUserFormDTO.getExportConfig()); |
|
|
|
Result<IcCustomExportResultDTO> exportConfigResult = this.getIcCustomExportConfig(searchForm.getCustomerId(), templateId, exportResiUserFormDTO.getExportConfig()); |
|
|
|
|
|
|
|
Map<String, ExportResiUserItemDTO> itemOriginMap = getItemMap(searchForm.getCustomerId()); |
|
|
|
IcCustomExportResultDTO exportConfigData = exportConfigResult.getData(); |
|
|
@ -107,7 +112,6 @@ public class IcResiUserExportServiceImpl implements IcResiUserExportService { |
|
|
|
|
|
|
|
List<IcCustomExportResultDTO.SqlColumn> allShowColumns = new ArrayList<>(exportConfigData.getShowSqlColumns()); |
|
|
|
|
|
|
|
|
|
|
|
//需要合并的列
|
|
|
|
List<Integer> mergeColumnIndexList = new ArrayList<>(); |
|
|
|
for (int i = 0; i < allShowColumns.size(); i++) { |
|
|
@ -162,44 +166,46 @@ public class IcResiUserExportServiceImpl implements IcResiUserExportService { |
|
|
|
List<IcCustomExportResultDTO.SqlColumn> showSqlColumns = exportConfigData.getShowSqlColumns(); |
|
|
|
Set<String> hiddenColumnSet = exportConfigData.getHiddenSqlColumns().stream().map(IcCustomExportResultDTO.SqlColumn::getColumnName).collect(Collectors.toSet()); |
|
|
|
result.forEach(o -> { |
|
|
|
List<Object> singleResult = new ArrayList<>(); |
|
|
|
List<Object> singleRowData = new ArrayList<>(); |
|
|
|
Map<String, Object> originalConditionMap = new ConcurrentHashMap<>(); |
|
|
|
o.forEach((key, value) -> { |
|
|
|
|
|
|
|
Map<String, IcCustomExportResultDTO.SqlColumn> itemMap = showSqlColumns.stream().collect(Collectors.toMap(IcCustomExportResultDTO.SqlColumn::getColumnName, item -> item)); |
|
|
|
|
|
|
|
IcCustomExportResultDTO.SqlColumn columnDTO = itemMap.get(key); |
|
|
|
if (singleResult.size() < showSqlColumns.size()) { |
|
|
|
IcCustomExportResultDTO.SqlColumn sqlColumn = itemMap.get(key); |
|
|
|
String tableName = sqlColumn.getTableName(); |
|
|
|
String itemId = sqlColumn.getItemId(); |
|
|
|
String columnName = columnDTO.getColumnName(); |
|
|
|
if (hiddenColumnSet.contains(columnName)) { |
|
|
|
return; |
|
|
|
} |
|
|
|
String vauleStr = value == null ? StrConstant.EPMETY_STR : value.toString(); |
|
|
|
//保留原始值 便于remote条件获取
|
|
|
|
originalConditionMap.putIfAbsent(columnName, vauleStr); |
|
|
|
ExportResiUserItemDTO exportResiUserItemDTO = itemOriginMap.get(tableName); |
|
|
|
FormItemResult formItemResult = exportResiUserItemDTO.getItemMap().get(columnName); |
|
|
|
//忽略 不需要显示的列的值得设置 要不然数据会写入到excel中
|
|
|
|
if (singleRowData.size() >= showSqlColumns.size()) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
String newValue = vauleStr; |
|
|
|
if (Constant.OPITON_SOURCE_REMOTE.equals(sqlColumn.getOptionSourceType()) && StringUtils.isNotBlank(vauleStr)) { |
|
|
|
putRemoteValue(exportResiUserItemDTO.getRemoteItemConditionMap().get(itemId), staffInfoCacheResult.getAgencyId(), o, originalConditionMap, formItemResult, columnName, vauleStr); |
|
|
|
newValue = String.valueOf(o.get(columnName)); |
|
|
|
} else if (Constant.OPITON_SOURCE_LOCAL.equals(sqlColumn.getOptionSourceType())) { |
|
|
|
newValue = putOptionValue(formItemResult, vauleStr); |
|
|
|
} |
|
|
|
singleResult.add(newValue); |
|
|
|
IcCustomExportResultDTO.SqlColumn sqlColumn = itemMap.get(key); |
|
|
|
String tableName = sqlColumn.getTableName(); |
|
|
|
String itemId = sqlColumn.getItemId(); |
|
|
|
String columnName = columnDTO.getColumnName(); |
|
|
|
if (hiddenColumnSet.contains(columnName)) { |
|
|
|
return; |
|
|
|
} |
|
|
|
String vauleStr = value == null ? StrConstant.EPMETY_STR : value.toString(); |
|
|
|
//保留原始值 便于remote条件获取
|
|
|
|
originalConditionMap.putIfAbsent(columnName, vauleStr); |
|
|
|
ExportResiUserItemDTO exportResiUserItemDTO = itemOriginMap.get(tableName); |
|
|
|
FormItemResult formItemResult = exportResiUserItemDTO.getItemMap().get(columnName); |
|
|
|
|
|
|
|
String newValue = vauleStr; |
|
|
|
if (Constant.OPITON_SOURCE_REMOTE.equals(sqlColumn.getOptionSourceType()) && StringUtils.isNotBlank(vauleStr)) { |
|
|
|
putRemoteValue(exportResiUserItemDTO.getRemoteItemConditionMap().get(itemId), staffInfoCacheResult.getAgencyId(), o, originalConditionMap, formItemResult, columnName, vauleStr); |
|
|
|
newValue = String.valueOf(o.get(columnName)); |
|
|
|
} else if (Constant.OPITON_SOURCE_LOCAL.equals(sqlColumn.getOptionSourceType())) { |
|
|
|
newValue = putOptionValue(formItemResult, vauleStr); |
|
|
|
} |
|
|
|
singleRowData.add(newValue); |
|
|
|
}); |
|
|
|
resultData.add(singleResult); |
|
|
|
resultData.add(singleRowData); |
|
|
|
}); |
|
|
|
excelWriter.write(resultData, writeSheet); |
|
|
|
break; |
|
|
|
} while (mapListPage.getResult().size() == searchForm.getPageSize()); |
|
|
|
} catch (IOException e) { |
|
|
|
log.error("exportIcResiUser exception", e); |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), e.getMessage(), "导出失败"); |
|
|
|
} finally { |
|
|
|
if (excelWriter != null) { |
|
|
|
excelWriter.finish(); |
|
|
@ -230,9 +236,9 @@ public class IcResiUserExportServiceImpl implements IcResiUserExportService { |
|
|
|
param.setTempId(templateId); |
|
|
|
param.setExportConfig(exportConfig); |
|
|
|
Result<IcCustomExportResultDTO> exportConfigResult = operCustomizeOpenFeignClient.getExcelHeaderAndSqlColumnForExport(param); |
|
|
|
if (!exportConfigResult.success() || exportConfigResult.getData() == null) { |
|
|
|
log.error("获取模板失败"); |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取模板失败" + exportConfigResult.getInternalMsg()); |
|
|
|
if (!exportConfigResult.success() ) { |
|
|
|
log.error("获取模板失败,internalMsg:{},msg:{}" , exportConfigResult.getInternalMsg(), exportConfigResult.getMsg()); |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "获取模板失败" + exportConfigResult.getInternalMsg(),"获取模板失败" + exportConfigResult.getInternalMsg()); |
|
|
|
} |
|
|
|
IcCustomExportResultDTO data = exportConfigResult.getData(); |
|
|
|
|
|
|
@ -244,12 +250,6 @@ public class IcResiUserExportServiceImpl implements IcResiUserExportService { |
|
|
|
return exportConfigResult; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 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<>(); |
|
|
@ -289,7 +289,6 @@ public class IcResiUserExportServiceImpl implements IcResiUserExportService { |
|
|
|
map.put(columnName, join); |
|
|
|
return; |
|
|
|
} |
|
|
|
//todo 不支持多个itemId
|
|
|
|
Map<String, String> remoteOptions = icResiUserImportService.listRemoteOptions(parts[0], parts[1], columnWrappers, currentStaffAgencyId, "query"); |
|
|
|
if (FormItemTypeEnum.CHECKBOX.getCode().equals(e.getItemType())) { |
|
|
|
remoteOptions.forEach((label, value) -> map.put(value, vauleStr.contains(value) ? StrConstant.YES : StrConstant.NO)); |
|
|
@ -319,13 +318,12 @@ public class IcResiUserExportServiceImpl implements IcResiUserExportService { |
|
|
|
//如果是多选 则返回顿号隔开
|
|
|
|
if (e.getMultiSelect()) { |
|
|
|
List<String> valueList = new ArrayList<>(); |
|
|
|
e.getOptions().forEach(option -> { |
|
|
|
e.getOptions().stream().forEach(option -> { |
|
|
|
if (valueStr.contains(option.getValue())) { |
|
|
|
valueList.add(option.getLabel()); |
|
|
|
} |
|
|
|
}); |
|
|
|
return Joiner.on("、").join(valueList); |
|
|
|
|
|
|
|
} |
|
|
|
for (OptionDTO dto : e.getOptions()) { |
|
|
|
return valueStr.contains(dto.getValue()) ? StrConstant.YES : StrConstant.NO; |
|
|
|