|
|
@ -10,17 +10,21 @@ import com.alibaba.fastjson.JSON; |
|
|
|
import com.epmet.commons.tools.constant.Constant; |
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.commons.tools.constant.StrConstant; |
|
|
|
import com.epmet.commons.tools.dto.form.IcExportTemplateSaveFormDTO; |
|
|
|
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; |
|
|
|
import com.epmet.commons.tools.enums.FormItemTypeEnum; |
|
|
|
import com.epmet.commons.tools.enums.IcFormCodeEnum; |
|
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
|
import com.epmet.commons.tools.exception.EpmetException; |
|
|
|
import com.epmet.commons.tools.redis.common.CustomerStaffRedis; |
|
|
|
import com.epmet.commons.tools.security.dto.TokenDto; |
|
|
|
import com.epmet.commons.tools.utils.ExcelUtils; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.commons.tools.utils.SpringContextUtils; |
|
|
|
import com.epmet.commons.tools.utils.poi.excel.FreezeAndFilter; |
|
|
|
import com.epmet.commons.tools.validator.ValidatorUtils; |
|
|
|
import com.epmet.constant.IcResiUserConstant; |
|
|
|
import com.epmet.dto.form.ExportResiUserFormDTO; |
|
|
|
import com.epmet.dto.form.IcExportTemplateQueryFormDTO; |
|
|
|
import com.epmet.dto.form.IcResiUserPageFormDTO; |
|
|
|
import com.epmet.dto.result.FormItemResult; |
|
|
@ -69,14 +73,23 @@ public class IcResiUserExportServiceImpl implements IcResiUserExportService { |
|
|
|
/** |
|
|
|
* desc: 根据条件查询居民信息并根据配置模板导出 |
|
|
|
* |
|
|
|
* @param pageFormDTO |
|
|
|
* |
|
|
|
* @param tokenDto |
|
|
|
* @param exportResiUserFormDTO |
|
|
|
* @param response |
|
|
|
* @return void |
|
|
|
* @author LiuJanJun |
|
|
|
* @date 2022/4/22 1:35 下午 |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public void exportIcResiUser(IcResiUserPageFormDTO pageFormDTO, HttpServletResponse response) { |
|
|
|
public void exportIcResiUser(TokenDto tokenDto, ExportResiUserFormDTO exportResiUserFormDTO, HttpServletResponse response) { |
|
|
|
//校验参数
|
|
|
|
validateSearchForm(tokenDto, exportResiUserFormDTO); |
|
|
|
IcResiUserPageFormDTO searchForm = exportResiUserFormDTO.getSearchForm(); |
|
|
|
|
|
|
|
String templateId = exportResiUserFormDTO.getTemplateId(); |
|
|
|
|
|
|
|
|
|
|
|
// 头的策略
|
|
|
|
WriteCellStyle headWriteCellStyle = new WriteCellStyle(); |
|
|
|
// 背景设置为红色
|
|
|
@ -88,9 +101,9 @@ public class IcResiUserExportServiceImpl implements IcResiUserExportService { |
|
|
|
ExcelWriter excelWriter = null; |
|
|
|
try { |
|
|
|
//获取用户配置的导出条件
|
|
|
|
Result<IcCustomExportResultDTO> exportConfigResult = getIcCustomExportConfig(pageFormDTO); |
|
|
|
Result<IcCustomExportResultDTO> exportConfigResult = getIcCustomExportConfig(searchForm.getCustomerId(),templateId,exportResiUserFormDTO.getExportConfig()); |
|
|
|
|
|
|
|
Map<String, ExportResiUserItemDTO> itemOriginMap = getItemMap(pageFormDTO.getCustomerId()); |
|
|
|
Map<String, ExportResiUserItemDTO> itemOriginMap = getItemMap(searchForm.getCustomerId()); |
|
|
|
IcCustomExportResultDTO exportConfigData = exportConfigResult.getData(); |
|
|
|
log.info("查询到的模板配置信息:{}", JSON.toJSONString(exportConfigData)); |
|
|
|
FreezeAndFilter writeHandler = new FreezeAndFilter(); |
|
|
@ -100,7 +113,7 @@ public class IcResiUserExportServiceImpl implements IcResiUserExportService { |
|
|
|
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) |
|
|
|
.head(exportConfigData.getHeaders()).build(); |
|
|
|
|
|
|
|
CustomerStaffInfoCacheResult staffInfoCacheResult = CustomerStaffRedis.getStaffInfo(pageFormDTO.getCustomerId(), pageFormDTO.getStaffId()); |
|
|
|
CustomerStaffInfoCacheResult staffInfoCacheResult = CustomerStaffRedis.getStaffInfo(searchForm.getCustomerId(), searchForm.getStaffId()); |
|
|
|
if (staffInfoCacheResult == null){ |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"获取工作人员信息失败"); |
|
|
|
} |
|
|
@ -115,10 +128,10 @@ public class IcResiUserExportServiceImpl implements IcResiUserExportService { |
|
|
|
allShowColumns.addAll(exportConfigData.getHiddenSqlColumns()); |
|
|
|
do { |
|
|
|
String finalStaffOrgPath = staffOrgPath; |
|
|
|
mapListPage = PageHelper.startPage(pageFormDTO.getPageNo(), pageFormDTO.getPageSize(), pageFormDTO.getIsPage()).doSelectPage(() -> { |
|
|
|
icResiUserService.dynamicQuery(pageFormDTO.getCustomerId(), pageFormDTO.getFormCode(), IcResiUserConstant.IC_RESI_USER, allShowColumns, pageFormDTO.getConditions(), staffInfoCacheResult.getAgencyId(), finalStaffOrgPath); |
|
|
|
mapListPage = PageHelper.startPage(searchForm.getPageNo(), searchForm.getPageSize(), searchForm.getIsPage()).doSelectPage(() -> { |
|
|
|
icResiUserService.dynamicQuery(searchForm.getCustomerId(), searchForm.getFormCode(), IcResiUserConstant.IC_RESI_USER, allShowColumns, searchForm.getConditions(), staffInfoCacheResult.getAgencyId(), finalStaffOrgPath); |
|
|
|
}); |
|
|
|
pageFormDTO.setPageNo(pageFormDTO.getPageNo() + NumConstant.ONE); |
|
|
|
searchForm.setPageNo(searchForm.getPageNo() + NumConstant.ONE); |
|
|
|
|
|
|
|
List<Map<String, Object>> result = mapListPage.getResult(); |
|
|
|
|
|
|
@ -163,7 +176,7 @@ public class IcResiUserExportServiceImpl implements IcResiUserExportService { |
|
|
|
excelWriter.write(resultData, writeSheet); |
|
|
|
//todo
|
|
|
|
break; |
|
|
|
} while (mapListPage.getResult().size() == pageFormDTO.getPageSize()); |
|
|
|
} while (mapListPage.getResult().size() == searchForm.getPageSize()); |
|
|
|
} catch (IOException e) { |
|
|
|
log.error("exportIcResiUser exception", e); |
|
|
|
} finally { |
|
|
@ -173,11 +186,21 @@ public class IcResiUserExportServiceImpl implements IcResiUserExportService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void validateSearchForm(TokenDto tokenDto, ExportResiUserFormDTO exportResiUserFormDTO) { |
|
|
|
IcResiUserPageFormDTO searchForm = exportResiUserFormDTO.getSearchForm(); |
|
|
|
searchForm.setCustomerId(tokenDto.getCustomerId()); |
|
|
|
searchForm.setStaffId(tokenDto.getUserId()); |
|
|
|
ValidatorUtils.validateEntity(searchForm, IcResiUserPageFormDTO.AddUserInternalGroup.class); |
|
|
|
searchForm.setIsPage(false); |
|
|
|
} |
|
|
|
|
|
|
|
@Nullable |
|
|
|
public Result<IcCustomExportResultDTO> getIcCustomExportConfig(IcResiUserPageFormDTO pageFormDTO) { |
|
|
|
public Result<IcCustomExportResultDTO> getIcCustomExportConfig(String customerId, String templateId, IcExportTemplateSaveFormDTO exportConfig) { |
|
|
|
//通过配置导出
|
|
|
|
IcExportTemplateQueryFormDTO param = new IcExportTemplateQueryFormDTO(); |
|
|
|
param.setCustomerId(pageFormDTO.getCustomerId()); |
|
|
|
param.setTempId(pageFormDTO.getTemplateId()); |
|
|
|
param.setCustomerId(customerId); |
|
|
|
param.setTempId(templateId); |
|
|
|
param.setExportConfig(exportConfig); |
|
|
|
Result<IcCustomExportResultDTO> exportConfigResult = operCustomizeOpenFeignClient.getExcelHeaderAndSqlColumnForExport(param); |
|
|
|
if (!exportConfigResult.success() || exportConfigResult.getData() == null) { |
|
|
|
log.error("获取模板失败"); |
|
|
|