|
|
@ -91,7 +91,9 @@ public class IcResiUserExportServiceImpl implements IcResiUserExportService { |
|
|
|
* @date 2022/4/22 1:35 下午 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public void exportIcResiUser(TokenDto tokenDto, ExportResiUserFormDTO exportResiUserFormDTO, HttpServletResponse response) { |
|
|
|
public Page<Map<String, Object>> exportIcResiUser(TokenDto tokenDto, ExportResiUserFormDTO exportResiUserFormDTO, HttpServletResponse response, boolean onlyGetData) { |
|
|
|
Page<Map<String, Object>> mapListPage = null; |
|
|
|
|
|
|
|
//校验参数
|
|
|
|
this.validateSearchForm(tokenDto, exportResiUserFormDTO); |
|
|
|
IcResiUserPageFormDTO searchForm = exportResiUserFormDTO.getSearchForm(); |
|
|
@ -99,6 +101,7 @@ public class IcResiUserExportServiceImpl implements IcResiUserExportService { |
|
|
|
String templateId = exportResiUserFormDTO.getTemplateId(); |
|
|
|
|
|
|
|
ExcelWriter excelWriter = null; |
|
|
|
WriteSheet writeSheet = null; |
|
|
|
try { |
|
|
|
//获取用户配置的导出条件
|
|
|
|
Result<IcCustomExportResultDTO> exportConfigResult = this.getIcCustomExportConfig(searchForm.getCustomerId(), templateId, exportResiUserFormDTO.getExportConfig()); |
|
|
@ -114,36 +117,40 @@ 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++) { |
|
|
|
IcCustomExportResultDTO.SqlColumn sqlColumn = allShowColumns.get(i); |
|
|
|
if (!sqlColumn.getManyToOne()) { |
|
|
|
mergeColumnIndexList.add(i); |
|
|
|
|
|
|
|
|
|
|
|
if (!onlyGetData){ |
|
|
|
|
|
|
|
//需要合并的列
|
|
|
|
List<Integer> mergeColumnIndexList = new ArrayList<>(); |
|
|
|
for (int i = 0; i < allShowColumns.size(); i++) { |
|
|
|
IcCustomExportResultDTO.SqlColumn sqlColumn = allShowColumns.get(i); |
|
|
|
if (!sqlColumn.getManyToOne()) { |
|
|
|
mergeColumnIndexList.add(i); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
int[] mergeColumnIndex = mergeColumnIndexList.stream().filter(Objects::nonNull).mapToInt(i -> i).toArray(); |
|
|
|
// 从那一列开始合并
|
|
|
|
int mergeRowIndex = exportConfigData.getHeaderRow(); |
|
|
|
|
|
|
|
// 头的策略
|
|
|
|
WriteCellStyle headWriteCellStyle = new WriteCellStyle(); |
|
|
|
// 背景设置为红色
|
|
|
|
headWriteCellStyle.setFillForegroundColor(IndexedColors.PALE_BLUE.getIndex()); |
|
|
|
WriteCellStyle contentWriteCellStyle = new WriteCellStyle(); |
|
|
|
contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER); |
|
|
|
HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle); |
|
|
|
FreezeAndFilter writeHandler = new FreezeAndFilter(); |
|
|
|
//从第几行开始冻结
|
|
|
|
writeHandler.rowSplit = exportConfigData.getHeaderRow(); |
|
|
|
excelWriter = EasyExcel.write(ExcelUtils.getOutputStreamForExcel("居民基本信息.xlsx", response)) |
|
|
|
.registerWriteHandler(new ExcelFillCellMergeStrategy(mergeRowIndex, mergeColumnIndex)) |
|
|
|
.registerWriteHandler(horizontalCellStyleStrategy) |
|
|
|
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) |
|
|
|
.registerWriteHandler(writeHandler).build(); |
|
|
|
|
|
|
|
int[] mergeColumnIndex = mergeColumnIndexList.stream().filter(Objects::nonNull).mapToInt(i -> i).toArray(); |
|
|
|
// 从那一列开始合并
|
|
|
|
int mergeRowIndex = exportConfigData.getHeaderRow(); |
|
|
|
|
|
|
|
// 头的策略
|
|
|
|
WriteCellStyle headWriteCellStyle = new WriteCellStyle(); |
|
|
|
// 背景设置为红色
|
|
|
|
headWriteCellStyle.setFillForegroundColor(IndexedColors.PALE_BLUE.getIndex()); |
|
|
|
WriteCellStyle contentWriteCellStyle = new WriteCellStyle(); |
|
|
|
contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER); |
|
|
|
HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle); |
|
|
|
FreezeAndFilter writeHandler = new FreezeAndFilter(); |
|
|
|
//从第几行开始冻结
|
|
|
|
writeHandler.rowSplit = exportConfigData.getHeaderRow(); |
|
|
|
excelWriter = EasyExcel.write(ExcelUtils.getOutputStreamForExcel("居民基本信息.xlsx", response)) |
|
|
|
.registerWriteHandler(new ExcelFillCellMergeStrategy(mergeRowIndex, mergeColumnIndex)) |
|
|
|
.registerWriteHandler(horizontalCellStyleStrategy) |
|
|
|
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) |
|
|
|
.registerWriteHandler(writeHandler).build(); |
|
|
|
|
|
|
|
WriteSheet writeSheet = EasyExcel.writerSheet("Sheet1").head(exportConfigData.getHeaders()).build(); |
|
|
|
writeSheet = EasyExcel.writerSheet("Sheet1").head(exportConfigData.getHeaders()).build(); |
|
|
|
} |
|
|
|
|
|
|
|
String staffOrgPath = null; |
|
|
|
if (StringUtils.isNotBlank(staffInfoCacheResult.getAgencyPIds()) && !NumConstant.ZERO_STR.equals(staffInfoCacheResult.getAgencyPIds())) { |
|
|
@ -151,7 +158,6 @@ public class IcResiUserExportServiceImpl implements IcResiUserExportService { |
|
|
|
} else { |
|
|
|
staffOrgPath = staffInfoCacheResult.getAgencyId(); |
|
|
|
} |
|
|
|
Page<Map<String, Object>> mapListPage = null; |
|
|
|
|
|
|
|
allShowColumns.addAll(exportConfigData.getHiddenSqlColumns()); |
|
|
|
do { |
|
|
@ -168,45 +174,11 @@ 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> 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); |
|
|
|
//忽略 不需要显示的列的值得设置 要不然数据会写入到excel中
|
|
|
|
if (singleRowData.size() >= showSqlColumns.size()) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
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); |
|
|
|
} |
|
|
|
if (FieldConstant.ID.equals(key)) { |
|
|
|
newValue = Md5Util.md5(vauleStr); |
|
|
|
} |
|
|
|
singleRowData.add(newValue); |
|
|
|
}); |
|
|
|
resultData.add(singleRowData); |
|
|
|
getDataForResi(itemOriginMap, staffInfoCacheResult, resultData, showSqlColumns, hiddenColumnSet, o); |
|
|
|
}); |
|
|
|
excelWriter.write(resultData, writeSheet); |
|
|
|
if (!onlyGetData){ |
|
|
|
excelWriter.write(resultData, writeSheet); |
|
|
|
} |
|
|
|
} while (mapListPage.getResult().size() == searchForm.getPageSize()); |
|
|
|
} catch (IOException e) { |
|
|
|
log.error("exportIcResiUser exception", e); |
|
|
@ -216,6 +188,47 @@ public class IcResiUserExportServiceImpl implements IcResiUserExportService { |
|
|
|
excelWriter.finish(); |
|
|
|
} |
|
|
|
} |
|
|
|
return mapListPage; |
|
|
|
} |
|
|
|
|
|
|
|
private void getDataForResi(Map<String, ExportResiUserItemDTO> itemOriginMap, CustomerStaffInfoCacheResult staffInfoCacheResult, List<List<Object>> resultData, List<IcCustomExportResultDTO.SqlColumn> showSqlColumns, Set<String> hiddenColumnSet, Map<String, Object> o) { |
|
|
|
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); |
|
|
|
//忽略 不需要显示的列的值得设置 要不然数据会写入到excel中
|
|
|
|
if (singleRowData.size() >= showSqlColumns.size()) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
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); |
|
|
|
} |
|
|
|
if (FieldConstant.ID.equals(key)) { |
|
|
|
newValue = Md5Util.md5(vauleStr); |
|
|
|
} |
|
|
|
singleRowData.add(newValue); |
|
|
|
}); |
|
|
|
resultData.add(singleRowData); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|