Commit a849f6a1 by “zcwang”

modify:导出完善,查询循环外置

parent a017b715
Pipeline #44159 passed with stages
in 2 minutes 23 seconds
......@@ -11,7 +11,6 @@ import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.commons.collections4.CollectionUtils;
......@@ -122,33 +121,60 @@ public class ChangeFlowExportCallback implements DesCallbackService {
if (CollectionUtils.isEmpty(changeRecords)) {
return Lists.newArrayList();
}
// 提前查询所有行动项用户名
List<String> allExecUserEmailList = new ArrayList<>();
for (ChangeRecord changeRecord : changeRecords) {
List<ChangeExecRecord> changeExecRecords = changeExecRecordMapper.selectByChangeRecordId(changeRecord.getId());
List<String> collect = changeExecRecords.stream()
.map(ChangeExecRecord::getChangeExecUserEmail)
.filter(StringUtils::isNotBlank).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(collect)) {
allExecUserEmailList.addAll(collect);
}
}
List<IusUserInfoRsp> userListInfo = new ArrayList<>();
try {
if (CollectionUtils.isNotEmpty(allExecUserEmailList)) {
List<String> userEmailList = allExecUserEmailList.stream().distinct().collect(Collectors.toList());
userListInfo = iusService.queryUserListInfo(UserQueryDTO.builder().uids(userEmailList).build());
}
} catch (Exception e) {
log.info("query user info has ex", e);
}
// 提前查询所有商品
List<Long> allItemList = new ArrayList<>();
List<String> allChangeProduct = changeRecords.stream()
.filter(changeRecord -> changeRecord.getChangeSubject().equals(ChangeSubjectEnum.PRODUCT.getType()))
.map(ChangeRecord::getChangeItem).filter(StringUtils::isNotBlank).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(allChangeProduct)) {
for (String changeItemJsonStr : allChangeProduct) {
List<ItemVO> itemVOS = JSON.parseArray(changeItemJsonStr, ItemVO.class);
List<Long> itemIds = itemVOS.stream().map(ItemVO::getItemId).collect(Collectors.toList());
allItemList.addAll(itemIds);
}
}
if (CollectionUtils.isNotEmpty(allItemList)) {
allItemList = allItemList.stream().distinct().collect(Collectors.toList());
}
// 批量查询spu信息
List<SpuTO> spuTOS = itemService.batchQuerySpuInfo(BatchQuerySpuInfoParam.builder().ids(allItemList)
.commonProps(new ArrayList<>()).spuProps(Arrays.asList("itemSetupType", "businessForm")).build());
// 批量查询物理类目
Map<Long, List<SimplePhyCateGoryResultCo>> categoryChain = itemService
.queryBySpuIds(CommonIdsParamQuery.builder().ids(allItemList).build());
// 查询商品对应负责人信息
Map<Long, ChangeGoodsPrincipalPO> longChangeGoodsPrincipalPOMap = interiorChangeConfigService
.queryGoodsPrincipalInfo(allItemList);
log.debug("[getExportList] spuTOS:{}", spuTOS.size());
List<ChangeFlowExcelDTO> changeFlowExcelDTOList = new ArrayList<>();
// 导出excel,按照商品/供应商和行动项,n*n重复拆分,例2个商品3个行动项,拆分成2*3=6行,其他属性一致
for (ChangeRecord record : changeRecords) {
List<ChangeExecRecord> changeExecRecords = changeExecRecordMapper.selectByChangeRecordId(record.getId());
List<IusUserInfoRsp> userListInfo = new ArrayList<>();
try {
Set<String> userEmail = changeExecRecords.stream().map(ChangeExecRecord::getChangeExecUserEmail).collect(Collectors.toSet());
userListInfo = iusService.queryUserListInfo(UserQueryDTO.builder().uids(new ArrayList<>(userEmail)).build());
} catch (Exception ex) {
log.info("query user info has ex", ex);
}
ChangeSubjectEnum changeSubjectEnum = ChangeSubjectEnum.getChangeSubjectEnum(record.getChangeSubject());
switch (changeSubjectEnum) {
case PRODUCT:
String changeItemJsonStr = record.getChangeItem();
List<ItemVO> itemVOS = JSON.parseArray(changeItemJsonStr, ItemVO.class);
List<Long> itemIds = itemVOS.stream().map(ItemVO::getItemId).collect(Collectors.toList());
// 批量查询spu信息
List<SpuTO> spuTOS = itemService.batchQuerySpuInfo(BatchQuerySpuInfoParam.builder().ids(itemIds)
.commonProps(new ArrayList<>()).spuProps(Arrays.asList("itemSetupType", "businessForm")).build());
// 批量查询物理类目
Map<Long, List<SimplePhyCateGoryResultCo>> categoryChain = itemService
.queryBySpuIds(CommonIdsParamQuery.builder().ids(itemIds).build());
// 查询商品对应负责人信息
Map<Long, ChangeGoodsPrincipalPO> longChangeGoodsPrincipalPOMap = interiorChangeConfigService
.queryGoodsPrincipalInfo(itemIds);
log.debug("[detail] spuTOS:{}", JSON.toJSONString(spuTOS));
for (ItemVO itemVO : itemVOS) {
for (ChangeExecRecord changeExecRecord : changeExecRecords) {
Long itemId = itemVO.getItemId();
......@@ -210,40 +236,13 @@ public class ChangeFlowExportCallback implements DesCallbackService {
}
break;
case SUPPLIER:
// 供应商变更,以行动项循环
for (ChangeExecRecord changeExecRecord : changeExecRecords) {
// 组装通用信息,除商品信息,行动项以外其他字段一致
ChangeFlowExcelDTO changeFlowExcelDTO = this.obtainCommon(record, changeSubjectEnum);
changeFlowExcelDTO.setSupplier(record.getChangeSupplier());
changeFlowExcelDTO.setChangeItem(null);
changeFlowExcelDTO.setSPUId(null);
changeFlowExcelDTO.setQcCategory(null);
changeFlowExcelDTO.setPhyCategory(null);
changeFlowExcelDTO.setItemSetupType(null);
changeFlowExcelDTO.setBusinessForm(null);
changeFlowExcelDTO.setStatus(null);
changeFlowExcelDTO.setFunctionary(null);
changeFlowExcelDTO.setPurchase(null);
changeFlowExcelDTO.setGoodsSqe(null);
changeFlowExcelDTO.setGoodsProjectName(null);
// 组装行动项相关信息
this.obtainChangeExec(changeExecRecord, changeFlowExcelDTO, userListInfo);
ChangeResultEnum resultEnum = ChangeResultEnum.getByStatus(record.getChangeResult());
changeFlowExcelDTO.setChangeResult(resultEnum == null ? "": resultEnum.getDesc());
changeFlowExcelDTO
.setChangeEndTime(record.getState().equals(ChangeStatusEnum.END.getStatus())
? DateUtils.parseLongToString(record.getUpdateTime(), DateUtils.DATE_TIME_FORMAT)
: "");
changeFlowExcelDTOList.add(changeFlowExcelDTO);
}
break;
case OTHER:
default:
// 供应商变更,以行动项循环
for (ChangeExecRecord changeExecRecord : changeExecRecords) {
// 组装通用信息,除商品信息,行动项以外其他字段一致
ChangeFlowExcelDTO changeFlowExcelDTO = this.obtainCommon(record, changeSubjectEnum);
changeFlowExcelDTO.setSupplier(null);
changeFlowExcelDTO.setSupplier(record.getChangeSupplier());
changeFlowExcelDTO.setChangeItem(null);
changeFlowExcelDTO.setSPUId(null);
changeFlowExcelDTO.setQcCategory(null);
......@@ -265,6 +264,7 @@ public class ChangeFlowExportCallback implements DesCallbackService {
: "");
changeFlowExcelDTOList.add(changeFlowExcelDTO);
}
break;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment