|
|
@ -3,6 +3,7 @@ package com.epmet.service.impl; |
|
|
|
import com.alibaba.excel.EasyExcel; |
|
|
|
import com.alibaba.excel.ExcelWriter; |
|
|
|
import com.alibaba.excel.write.metadata.WriteSheet; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.commons.tools.constant.StrConstant; |
|
|
|
import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; |
|
|
@ -20,6 +21,7 @@ import com.epmet.service.IcResiUserExportService; |
|
|
|
import com.epmet.service.IcResiUserService; |
|
|
|
import com.github.pagehelper.Page; |
|
|
|
import com.github.pagehelper.PageHelper; |
|
|
|
import com.google.common.cache.Cache; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
@ -28,8 +30,10 @@ import org.springframework.stereotype.Service; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.io.IOException; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
|
* desc: |
|
|
@ -64,17 +68,17 @@ public class IcResiUserExportServiceImpl implements IcResiUserExportService { |
|
|
|
//获取模板条件
|
|
|
|
IcExportTemplateQueryFormDTO param = new IcExportTemplateQueryFormDTO(); |
|
|
|
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(); |
|
|
|
IcCustomExportResultDTO exportConfigData = exportConfigResult.getData(); |
|
|
|
log.info("查询到的模板配置信息:{}", JSON.toJSONString(exportConfigData)); |
|
|
|
FreezeAndFilter writeHandler = new FreezeAndFilter(); |
|
|
|
excelWriter = EasyExcel.write(ExcelUtils.getOutputStreamForExcel("居民基本信息.xlsx", response)).registerWriteHandler(writeHandler).build(); |
|
|
|
WriteSheet writeSheet = EasyExcel.writerSheet().head(resultDTO.getHeaders()).build(); |
|
|
|
WriteSheet writeSheet = EasyExcel.writerSheet().head(exportConfigData.getHeaders()).build(); |
|
|
|
|
|
|
|
CustomerStaffInfoCacheResult staffInfoCacheResult = CustomerStaffRedis.getStaffInfo(loginUserUtil.getLoginUserCustomerId(), loginUserUtil.getLoginUserId()); |
|
|
|
String staffOrgPath = null; |
|
|
@ -84,8 +88,8 @@ public class IcResiUserExportServiceImpl implements IcResiUserExportService { |
|
|
|
staffOrgPath = staffInfoCacheResult.getAgencyId(); |
|
|
|
} |
|
|
|
Page<Map<String, Object>> mapListPage = null; |
|
|
|
List<IcCustomExportResultDTO.SqlColumn> allShowColumns = new ArrayList<>(resultDTO.getShowSqlColumns()); |
|
|
|
allShowColumns.addAll(resultDTO.getHiddenSqlColumns()); |
|
|
|
List<IcCustomExportResultDTO.SqlColumn> allShowColumns = new ArrayList<>(exportConfigData.getShowSqlColumns()); |
|
|
|
allShowColumns.addAll(exportConfigData.getHiddenSqlColumns()); |
|
|
|
do { |
|
|
|
String finalStaffOrgPath = staffOrgPath; |
|
|
|
mapListPage = PageHelper.startPage(pageFormDTO.getPageNo(), pageFormDTO.getPageSize(), pageFormDTO.getIsPage()).doSelectPage(() -> { |
|
|
@ -93,25 +97,31 @@ public class IcResiUserExportServiceImpl implements IcResiUserExportService { |
|
|
|
}); |
|
|
|
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()) { |
|
|
|
o.forEach((key,value) -> { |
|
|
|
List<IcCustomExportResultDTO.SqlColumn> showSqlColumns = exportConfigData.getShowSqlColumns(); |
|
|
|
Map<String, IcCustomExportResultDTO.SqlColumn> itemMap = showSqlColumns.stream().collect(Collectors.toMap(IcCustomExportResultDTO.SqlColumn::getColumnName, item -> item)); |
|
|
|
if (singleResult.size() < showSqlColumns.size()) { |
|
|
|
singleResult.add(value); |
|
|
|
|
|
|
|
IcCustomExportResultDTO.SqlColumn sqlColumn = itemMap.get(key); |
|
|
|
String vauleStr = value == null ? StrConstant.EPMETY_STR : value.toString(); |
|
|
|
/* if (Constant.OPITON_SOURCE_REMOTE.equals(sqlColumn.getOptionSourceType()) && StringUtils.isNotBlank(vauleStr)) { |
|
|
|
putRemoteValue(formItemMap.getRemoteItemConditionMap().get(e.getItemId()), currentStaffAgencyId, resiUser,originalConditionMap, e, columnName, vauleStr); |
|
|
|
} else { |
|
|
|
putOptionValue(resiUser, e, columnName, vauleStr); |
|
|
|
}*/ |
|
|
|
} |
|
|
|
}); |
|
|
|
resultData.add(singleResult); |
|
|
|
}); |
|
|
|
log.debug("需要写入的data长度:{}", resultData.size()); |
|
|
|
log.info("需要写入的data长度:{}", resultData.size()); |
|
|
|
excelWriter.write(resultData, writeSheet); |
|
|
|
} while (mapListPage.getResult().size() == pageFormDTO.getPageSize()); |
|
|
|
} catch (IOException e) { |
|
|
|
log.error("exportIcResiUser exception", e); |
|
|
|
} finally { |
|
|
@ -119,7 +129,70 @@ public class IcResiUserExportServiceImpl implements IcResiUserExportService { |
|
|
|
excelWriter.finish(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 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<>(); |
|
|
|
if (e.getOptionSourceValue().contains(StrConstant.QUESTION_MARK)){ |
|
|
|
for (FormItemResult o : conditionItemSet) { |
|
|
|
String column = getColumnName(o); |
|
|
|
Object conditionValue = originalConditionMap.getOrDefault(column, map.get(column)); |
|
|
|
originalConditionMap.putIfAbsent(column,conditionValue.toString()); |
|
|
|
IcResiUserImportServiceImpl.ColumnWrapper value = new IcResiUserImportServiceImpl.ColumnWrapper(); |
|
|
|
value.setColValue(conditionValue.toString()); |
|
|
|
columnWrappers.put(o.getItemId(), value); |
|
|
|
} |
|
|
|
} |
|
|
|
Cache<String, String> cache = remoteOptionCacheMap.getOrDefault(e.getItemId(), CacheBuilder.newBuilder().maximumSize(NumConstant.FIVE_HUNDRED).build()); |
|
|
|
remoteOptionCacheMap.putIfAbsent(e.getItemId(),cache); |
|
|
|
String cacheValue = cache.getIfPresent(vauleStr); |
|
|
|
if (StringUtils.isNotBlank(cacheValue)){ |
|
|
|
map.put(columnName,cacheValue); |
|
|
|
} else { |
|
|
|
String[] parts = icResiUserImportService.splitOptionSourceUrl(e.getOptionSourceValue()); |
|
|
|
|
|
|
|
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)); |
|
|
|
} else if (FormItemTypeEnum.SELECT.getCode().equals(e.getItemType())) { |
|
|
|
remoteOptions.forEach((label, value) -> { |
|
|
|
if (vauleStr.equals(value)) { |
|
|
|
map.put(columnName, label); |
|
|
|
} |
|
|
|
cache.put(value,label); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (Exception ex) { |
|
|
|
log.error("listRemoteOptions url:{}", e.getOptionSourceValue()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void putOptionValue(Map<String, Object> map, FormItemResult e, String columnName, String vauleStr) { |
|
|
|
FormItemTypeEnum itemTypeEnum = FormItemTypeEnum.getEnum(e.getItemType()); |
|
|
|
switch (itemTypeEnum) { |
|
|
|
case CHECKBOX: |
|
|
|
e.getOptions().forEach(optionDTO -> { |
|
|
|
map.put(optionDTO.getValue(), vauleStr.contains(optionDTO.getValue()) ? StrConstant.YES : StrConstant.NO); |
|
|
|
}); |
|
|
|
break; |
|
|
|
case SELECT: |
|
|
|
case RADIO: |
|
|
|
e.getOptions().forEach(optionDTO -> { |
|
|
|
if (optionDTO.getValue().equals(vauleStr)) { |
|
|
|
map.put(columnName, optionDTO.getLabel()); |
|
|
|
} |
|
|
|
}); |
|
|
|
break; |
|
|
|
default: |
|
|
|
} |
|
|
|
}*/ |
|
|
|
|
|
|
|
} |
|
|
|