diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java index 778740a9a6..76706a51b0 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/IcResiUserController.java @@ -68,6 +68,7 @@ import com.epmet.send.SendMqMsgUtil; import com.epmet.service.IcResiUserExportService; import com.epmet.service.IcResiUserImportService; import com.epmet.service.IcResiUserService; +import com.github.pagehelper.Page; import feign.RequestInterceptor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; @@ -526,7 +527,7 @@ public class IcResiUserController implements ResultDataResolver { log.info("通过原来的模板下载,tokenDto:{}", JSON.toJSONString(tokenDto)); this.exportExcelByEasyExcel(tokenDto, pageFormDTO.getSearchForm(), response); } else { - icResiUserExportService.exportIcResiUser(tokenDto, pageFormDTO, response); + icResiUserExportService.exportIcResiUser(tokenDto, pageFormDTO, response,false); } } catch (EpmetException e) { response.reset(); @@ -539,6 +540,24 @@ public class IcResiUserController implements ResultDataResolver { } } + /** + * desc: 自定义导出居民信息 不下载只有数据 + * + * @param tokenDto + * @param pageFormDTO + * @param response + * @return void + * @author LiuJanJun + * @date 2021/11/19 4:24 下午 + * @remark 用于报表调用的接口 试试 + */ + @NoRepeatSubmit + @RequestMapping(value = "/exportExcelCustomData") + public Result>> exportExcelCustomData(@LoginUser TokenDto tokenDto, @RequestBody ExportResiUserFormDTO pageFormDTO, HttpServletResponse response) throws Exception { + Page> maps = icResiUserExportService.exportIcResiUser(tokenDto, pageFormDTO, null, true); + return new Result>>().ok(maps.getResult()); + } + /** * desc:根据客户id 先从oss下载模版,如果有没有则使用系统默认模板 如果不存在则返回null * diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcResiUserExportService.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcResiUserExportService.java index 53f9bee81f..f67864cf82 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcResiUserExportService.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/IcResiUserExportService.java @@ -2,8 +2,10 @@ package com.epmet.service; import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.dto.form.ExportResiUserFormDTO; +import com.github.pagehelper.Page; import javax.servlet.http.HttpServletResponse; +import java.util.Map; /** *@Description 居民信息导出service @@ -23,5 +25,5 @@ public interface IcResiUserExportService { * @author LiuJanJun * @date 2022/4/22 1:35 下午 */ - void exportIcResiUser(TokenDto tokenDto, ExportResiUserFormDTO exportResiUserFormDTO, HttpServletResponse response); + Page> exportIcResiUser(TokenDto tokenDto, ExportResiUserFormDTO exportResiUserFormDTO, HttpServletResponse response, boolean onlyGetData); } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserExportServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserExportServiceImpl.java index a5ff0484c8..f32f44da1f 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserExportServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/IcResiUserExportServiceImpl.java @@ -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> exportIcResiUser(TokenDto tokenDto, ExportResiUserFormDTO exportResiUserFormDTO, HttpServletResponse response, boolean onlyGetData) { + Page> 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 exportConfigResult = this.getIcCustomExportConfig(searchForm.getCustomerId(), templateId, exportResiUserFormDTO.getExportConfig()); @@ -114,36 +117,40 @@ public class IcResiUserExportServiceImpl implements IcResiUserExportService { List allShowColumns = new ArrayList<>(exportConfigData.getShowSqlColumns()); - //需要合并的列 - List 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 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> mapListPage = null; allShowColumns.addAll(exportConfigData.getHiddenSqlColumns()); do { @@ -168,45 +174,11 @@ public class IcResiUserExportServiceImpl implements IcResiUserExportService { List showSqlColumns = exportConfigData.getShowSqlColumns(); Set hiddenColumnSet = exportConfigData.getHiddenSqlColumns().stream().map(IcCustomExportResultDTO.SqlColumn::getColumnName).collect(Collectors.toSet()); result.forEach(o -> { - List singleRowData = new ArrayList<>(); - Map originalConditionMap = new ConcurrentHashMap<>(); - o.forEach((key, value) -> { - Map 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 itemOriginMap, CustomerStaffInfoCacheResult staffInfoCacheResult, List> resultData, List showSqlColumns, Set hiddenColumnSet, Map o) { + List singleRowData = new ArrayList<>(); + Map originalConditionMap = new ConcurrentHashMap<>(); + o.forEach((key, value) -> { + Map 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); } /**