Commit ebd408b3 by 王志超

feat: 抽取方法,简化主工单代码

parent 59f6e1a9
......@@ -997,57 +997,24 @@ public class ChangeFlowBiz {
log.debug("[detail] detail:{}", JSON.toJSONString(changeRecord));
ChangeFlowVO changeFlowVO = new ChangeFlowVO();
BeanUtils.copyProperties(changeRecord, changeFlowVO);
ChangeType parentChangeType = changeTypeService.getChangeTypeById(changeRecord.getParentChangeClassId());
if (parentChangeType == null) {
throw ExceptionFactory.createBiz(ResponseCode.CHANGE_TYPE_NOT_EXIST, "变更类型不存在");
}
ChangeType sonChangeType = changeTypeService.getChangeTypeById(changeRecord.getSonChangeClassId());
if (sonChangeType == null) {
throw ExceptionFactory.createBiz(ResponseCode.CHANGE_TYPE_NOT_EXIST, "变更类型配置不存在");
}
changeFlowVO.setChangeType(parentChangeType.getTypeName() + ">" + sonChangeType.getTypeName());
// 供应商名称需要查询
String changeSupplier = changeRecord.getChangeSupplier();
String changeSupplierName = "";
if (StringUtils.isNotBlank(changeSupplier)) {
List<SupplierSimpleRsp> supplierSimple = supplierService.getSupplierName(changeSupplier);
if (CollectionUtils.isNotEmpty(supplierSimple)) {
SupplierSimpleRsp supplier = supplierSimple.get(0);
changeSupplierName = supplier.getSupplierName();
}
}
// 设置变更类型,一级变更类型>二级变更类型
String changeType = this.buildChangeType(changeRecord.getParentChangeClassId(), changeRecord.getSonChangeClassId());
changeFlowVO.setChangeType(changeType);
// 设置供应商名称
String changeSupplierName = this.buildChangeSupplierName(changeRecord.getChangeSupplier());
changeFlowVO.setChangeSupplierName(changeSupplierName);
// 获取附件
List<ChangeFlowFile> changeFileList = changeFileService.getChangeFileList(changeRecord.getId());
changeFlowVO.setFiles(changeFileList);
// 组装商品信息
this.buildItemBasicInfoList(changeRecord, changeFlowVO);
changeFlowVO.setChangeState(changeRecord.getState());
changeFlowVO.setChangeStateDesc(ChangeStatusEnum.getDescByStatus(changeRecord.getState()));
changeFlowVO.setChangeCreator(changeRecord.getCreator());
List<ChangeFlowExecVO> changeFlowExecRecord = changeFlowExecService.getChangeFlowExecRecord(changeRecord.getId());
try {
Set<String> userEmail = changeFlowExecRecord.stream().map(ChangeFlowExecVO::getChangeExecUserEmail).collect(Collectors.toSet());
AjaxResponse<List<IusUserInfoRsp>> userListInfo = iusRpcService.queryUserListInfo(UserQueryDTO.builder().uids(new ArrayList<>(userEmail)).build());
List<IusUserInfoRsp> data = userListInfo.getData();
changeFlowExecRecord.forEach(i -> {
Optional<IusUserInfoRsp> anyExeUser = data.stream().filter(u -> u.getUid().equals(i.getChangeExecUserEmail())).findAny();
if (anyExeUser.isPresent()) {
i.setChangeExecUserName(anyExeUser.get().getName());
} else {
// 批量查询没查到的人名,通过全量查询单独再查一次
IusUserInfoRsp user = iusService.queryUserInfo(i.getChangeExecUserEmail());
if (user != null && StringUtils.isNotBlank(user.getName())) {
i.setChangeExecUserName(user.getName());
}
}
});
} catch (Exception ex) {
log.error("query user info has ex", ex);
}
// 填充行动人姓名
this.fillChangeExecUserName(changeFlowExecRecord);
changeFlowVO.setChangeExecProjectList(changeFlowExecRecord);
changeFlowVO.setTopoId(ChangeFlowEnum.NEW_CHANGE_FLOW.getTopoId());
try {
......@@ -1175,6 +1142,83 @@ public class ChangeFlowBiz {
changeFlowVO.setItemBasicInfoList(itemBasicInfoVOS);
}
/**
* 构建变更类型字符串
*
* @param parentChangeClassId 一级变更类型ID
* @param sonChangeClassId 二级变更类型ID
* @return 变更类型字符串,格式:一级类型>二级类型
*/
private String buildChangeType(Long parentChangeClassId, Long sonChangeClassId) {
ChangeType parentChangeType = changeTypeService.getChangeTypeById(parentChangeClassId);
if (parentChangeType == null) {
throw ExceptionFactory.createBiz(ResponseCode.CHANGE_TYPE_NOT_EXIST, "变更类型不存在");
}
ChangeType sonChangeType = changeTypeService.getChangeTypeById(sonChangeClassId);
if (sonChangeType == null) {
throw ExceptionFactory.createBiz(ResponseCode.CHANGE_TYPE_NOT_EXIST, "变更类型配置不存在");
}
return parentChangeType.getTypeName() + ">" + sonChangeType.getTypeName();
}
/**
* 构建供应商名称
*
* @param changeSupplier 供应商ID
* @return 供应商名称,如果查询不到则返回空字符串
*/
private String buildChangeSupplierName(String changeSupplier) {
if (StringUtils.isBlank(changeSupplier)) {
return "";
}
List<SupplierSimpleRsp> supplierSimple = supplierService.getSupplierName(changeSupplier);
if (CollectionUtils.isEmpty(supplierSimple)) {
return "";
}
return supplierSimple.get(0).getSupplierName();
}
/**
* 填充变更行动人姓名
*
* @param changeFlowExecRecord 变更行动方案列表
*/
private void fillChangeExecUserName(List<ChangeFlowExecVO> changeFlowExecRecord) {
if (CollectionUtils.isEmpty(changeFlowExecRecord)) {
return;
}
try {
Set<String> userEmail = changeFlowExecRecord.stream()
.map(ChangeFlowExecVO::getChangeExecUserEmail)
.collect(Collectors.toSet());
// 批量查询用户信息
AjaxResponse<List<IusUserInfoRsp>> userListInfo = iusRpcService.queryUserListInfo(
UserQueryDTO.builder().uids(new ArrayList<>(userEmail)).build());
List<IusUserInfoRsp> data = userListInfo.getData();
// 填充用户姓名
changeFlowExecRecord.forEach(i -> {
Optional<IusUserInfoRsp> anyExeUser = data.stream()
.filter(u -> u.getUid().equals(i.getChangeExecUserEmail()))
.findAny();
if (anyExeUser.isPresent()) {
i.setChangeExecUserName(anyExeUser.get().getName());
} else {
// 批量查询没查到的人名,通过全量查询单独再查一次
IusUserInfoRsp user = iusService.queryUserInfo(i.getChangeExecUserEmail());
if (user != null && StringUtils.isNotBlank(user.getName())) {
i.setChangeExecUserName(user.getName());
}
}
});
} catch (Exception ex) {
log.error("query user info has ex", ex);
}
}
public ChangeFlowListVO query(Integer page, Integer pageSize, ChangeFlowListQueryReq changeFlowListQueryReq) {
log.info("[query] page:{}, pageSize:{}, changeFlowListQueryReq:{}", page, pageSize,
JSON.toJSONString(changeFlowListQueryReq));
......
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