|
|
@ -1,17 +1,35 @@ |
|
|
|
package com.epmet.service.impl; |
|
|
|
|
|
|
|
import com.alibaba.excel.EasyExcel; |
|
|
|
import com.alibaba.excel.ExcelWriter; |
|
|
|
import com.alibaba.excel.write.metadata.WriteSheet; |
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.commons.tools.constant.StrConstant; |
|
|
|
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; |
|
|
|
import com.epmet.commons.tools.redis.common.CustomerStaffRedis; |
|
|
|
import com.epmet.commons.tools.security.user.LoginUserUtil; |
|
|
|
import com.epmet.commons.tools.utils.ExcelUtils; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.commons.tools.utils.poi.excel.FreezeAndFilter; |
|
|
|
import com.epmet.constant.IcResiUserConstant; |
|
|
|
import com.epmet.dto.form.IcExportTemplateFormDTO; |
|
|
|
import com.epmet.dto.form.IcResiUserPageFormDTO; |
|
|
|
import com.epmet.dto.result.IcCustomExportResultDTO; |
|
|
|
import com.epmet.feign.OperCustomizeOpenFeignClient; |
|
|
|
import com.epmet.service.IcResiUserExportService; |
|
|
|
import com.epmet.service.IcResiUserService; |
|
|
|
import com.github.pagehelper.Page; |
|
|
|
import com.github.pagehelper.PageHelper; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.io.IOException; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
/** |
|
|
|
* desc: |
|
|
@ -27,6 +45,9 @@ public class IcResiUserExportServiceImpl implements IcResiUserExportService { |
|
|
|
private OperCustomizeOpenFeignClient operCustomizeOpenFeignClient; |
|
|
|
@Autowired |
|
|
|
private LoginUserUtil loginUserUtil; |
|
|
|
@Autowired |
|
|
|
private IcResiUserService icResiUserService; |
|
|
|
|
|
|
|
/** |
|
|
|
* desc: 根据条件查询居民信息并根据配置模板导出 |
|
|
|
* |
|
|
@ -38,11 +59,67 @@ public class IcResiUserExportServiceImpl implements IcResiUserExportService { |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public void exportIcResiUser(IcResiUserPageFormDTO pageFormDTO, HttpServletResponse response) { |
|
|
|
//获取模板条件
|
|
|
|
IcExportTemplateFormDTO param = new IcExportTemplateFormDTO(); |
|
|
|
param.setCustomerId(loginUserUtil.getLoginUserCustomerId()); |
|
|
|
param.setTempId(pageFormDTO.getTemplateId()); |
|
|
|
Result<IcCustomExportResultDTO> exportConfigResult = operCustomizeOpenFeignClient.getExcelHeaderAndSqlColumnForExport(param); |
|
|
|
ExcelWriter excelWriter = null; |
|
|
|
try { |
|
|
|
//获取模板条件
|
|
|
|
IcExportTemplateFormDTO param = new IcExportTemplateFormDTO(); |
|
|
|
param.setCustomerId(loginUserUtil.getLoginUserCustomerId()); |
|
|
|
param.setCustomerId("default"); |
|
|
|
param.setTempId(pageFormDTO.getTemplateId()); |
|
|
|
Result<IcCustomExportResultDTO> exportConfigResult = operCustomizeOpenFeignClient.getExcelHeaderAndSqlColumnForExport(param); |
|
|
|
if (!exportConfigResult.success() || exportConfigResult.getData() == null) { |
|
|
|
log.error("获取模板失败"); |
|
|
|
return; |
|
|
|
} |
|
|
|
IcCustomExportResultDTO resultDTO = exportConfigResult.getData(); |
|
|
|
FreezeAndFilter writeHandler = new FreezeAndFilter(); |
|
|
|
excelWriter = EasyExcel.write(ExcelUtils.getOutputStreamForExcel("居民基本信息.xlsx", response)).registerWriteHandler(writeHandler).build(); |
|
|
|
WriteSheet writeSheet = EasyExcel.writerSheet().head(resultDTO.getHeaders()).build(); |
|
|
|
|
|
|
|
CustomerStaffInfoCacheResult staffInfoCacheResult = CustomerStaffRedis.getStaffInfo(loginUserUtil.getLoginUserCustomerId(), loginUserUtil.getLoginUserId()); |
|
|
|
String staffOrgPath = null; |
|
|
|
if (StringUtils.isNotBlank(staffInfoCacheResult.getAgencyPIds()) && !NumConstant.ZERO_STR.equals(staffInfoCacheResult.getAgencyPIds())) { |
|
|
|
staffOrgPath = staffInfoCacheResult.getAgencyPIds().concat(StrConstant.COLON).concat(staffInfoCacheResult.getAgencyId()); |
|
|
|
} else { |
|
|
|
staffOrgPath = staffInfoCacheResult.getAgencyId(); |
|
|
|
} |
|
|
|
Page<Map<String, Object>> mapListPage = null; |
|
|
|
List<IcCustomExportResultDTO.SqlColumn> allShowColumns = new ArrayList<>(resultDTO.getShowSqlColumns()); |
|
|
|
allShowColumns.addAll(resultDTO.getHiddenSqlColumns()); |
|
|
|
do { |
|
|
|
String finalStaffOrgPath = staffOrgPath; |
|
|
|
mapListPage = PageHelper.startPage(pageFormDTO.getPageNo(), pageFormDTO.getPageSize(), pageFormDTO.getIsPage()).doSelectPage(() -> { |
|
|
|
icResiUserService.dynamicQuery(loginUserUtil.getLoginUserCustomerId(), pageFormDTO.getFormCode(), IcResiUserConstant.IC_RESI_USER, allShowColumns, pageFormDTO.getConditions(), staffInfoCacheResult.getAgencyId(), finalStaffOrgPath); |
|
|
|
}); |
|
|
|
pageFormDTO.setPageNo(pageFormDTO.getPageNo() + NumConstant.ONE); |
|
|
|
|
|
|
|
//todo
|
|
|
|
if (pageFormDTO.getPageNo() == 4) { |
|
|
|
break; |
|
|
|
} |
|
|
|
} while (mapListPage != null && mapListPage.getResult().size() == pageFormDTO.getPageSize()); |
|
|
|
List<Map<String, Object>> result = mapListPage.getResult(); |
|
|
|
|
|
|
|
List<List<Object>> resultData = new ArrayList<>(); |
|
|
|
result.forEach(o -> { |
|
|
|
List<Object> singleResult = new ArrayList<>(); |
|
|
|
o.values().forEach(value -> { |
|
|
|
if (singleResult.size() < resultDTO.getShowSqlColumns().size()) { |
|
|
|
singleResult.add(value); |
|
|
|
} |
|
|
|
}); |
|
|
|
resultData.add(singleResult); |
|
|
|
}); |
|
|
|
log.debug("需要写入的data长度:{}", resultData.size()); |
|
|
|
excelWriter.write(resultData, writeSheet); |
|
|
|
} catch (IOException e) { |
|
|
|
log.error("exportIcResiUser exception", e); |
|
|
|
} finally { |
|
|
|
if (excelWriter != null) { |
|
|
|
excelWriter.finish(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|