fix:修改添加和修改行程的增加审批事件的逻辑

This commit is contained in:
lulz1 2024-07-12 08:44:24 +08:00
parent 845099b282
commit 2c0924372a
13 changed files with 219 additions and 39 deletions

View File

@ -15,9 +15,11 @@ import com.chint.domain.repository.LegRepository;
import com.chint.domain.repository.RouteRepository; import com.chint.domain.repository.RouteRepository;
import com.chint.domain.service.LegDomainService; import com.chint.domain.service.LegDomainService;
import com.chint.domain.service.OrderDomainService; import com.chint.domain.service.OrderDomainService;
import com.chint.domain.service.RouteApprovalDomainService;
import com.chint.domain.service.order_sync.SyncAdapter; import com.chint.domain.service.order_sync.SyncAdapter;
import com.chint.domain.value_object.*; import com.chint.domain.value_object.*;
import com.chint.domain.value_object.enums.CurrencyType; import com.chint.domain.value_object.enums.CurrencyType;
import com.chint.domain.value_object.enums.RoutePermission;
import com.chint.infrastructure.constant.DataMessageConstant; import com.chint.infrastructure.constant.DataMessageConstant;
import com.chint.infrastructure.constant.LegConstant; import com.chint.infrastructure.constant.LegConstant;
import com.chint.infrastructure.echo_framework.command.Command; import com.chint.infrastructure.echo_framework.command.Command;
@ -31,7 +33,10 @@ import java.time.format.DateTimeFormatter;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.Set;
import static com.chint.domain.value_object.enums.RoutePermission.LEG_NEED_APPROVAL;
import static com.chint.domain.value_object.enums.RoutePermission.LEG_NEED_NOTIFY;
import static com.chint.infrastructure.constant.CommonMessageConstant.LEG_TIME_ERROR; import static com.chint.infrastructure.constant.CommonMessageConstant.LEG_TIME_ERROR;
import static com.chint.infrastructure.constant.CommonMessageConstant.NOT_FOUND; import static com.chint.infrastructure.constant.CommonMessageConstant.NOT_FOUND;
import static com.chint.infrastructure.constant.RouteConstant.ORDER_STATUS_APPROVAL; import static com.chint.infrastructure.constant.RouteConstant.ORDER_STATUS_APPROVAL;
@ -55,6 +60,8 @@ public class OrderApplicationService {
@Autowired @Autowired
private LegRepository legRepository; private LegRepository legRepository;
@Autowired
private RouteApprovalDomainService routeApprovalDomainService;
@Autowired @Autowired
private LegDomainService legDomainService; private LegDomainService legDomainService;
@ -143,10 +150,12 @@ public class OrderApplicationService {
// 发送 BPM 保存结果 // 发送 BPM 保存结果
ApproveOrderNo approveOrderNo = routeOrder.getApproveOrderNo(); ApproveOrderNo approveOrderNo = routeOrder.getApproveOrderNo();
if (!routeOrder.getOrderStatus().equals(ORDER_STATUS_PREPARE) && approveOrderNo.getSysCode().equals("ANFSSC")) { if (!routeOrder.getOrderStatus().equals(ORDER_STATUS_PREPARE)) {
//这里加入一个待审批事件, 变更加入旧行程数据 用于回滚还原 //这里加入一个待审批事件, 变更加入旧行程数据 用于回滚还原
if (checkIfNeedApprove(routeOrder)) {
leg.addEvent(LegApprovalEvent.prepare(oldLeg)); leg.addEvent(LegApprovalEvent.prepare(oldLeg));
} }
}
if (!routeOrder.getOrderStatus().equals(ORDER_STATUS_PREPARE) && !approveOrderNo.getSysCode().equals("ANFSSC")) { if (!routeOrder.getOrderStatus().equals(ORDER_STATUS_PREPARE) && !approveOrderNo.getSysCode().equals("ANFSSC")) {
sendLegChangeCommand(oldLeg, leg, sendLegChangeCommand(oldLeg, leg,
routeOrder, routeOrder,
@ -160,6 +169,18 @@ public class OrderApplicationService {
Command.of(RouteAutoSyncCommand.class).route(routeOrder).async().sendToQueue(); Command.of(RouteAutoSyncCommand.class).route(routeOrder).async().sendToQueue();
} }
private boolean checkIfNeedApprove(RouteOrder routeOrder) {
Set<RoutePermission> routePermissionSet = routeOrder.getRoutePermissionSet();
if (routePermissionSet == null) {
routeApprovalDomainService.checkApprovalPermissions(routeOrder);
}
if (routePermissionSet == null) {
return false;
}
return routePermissionSet.contains(LEG_NEED_APPROVAL) || routePermissionSet.contains(LEG_NEED_NOTIFY);
}
private Leg handleLegChangeEvent(Leg leg, LegData legData, RouteOrder routeOrder) { private Leg handleLegChangeEvent(Leg leg, LegData legData, RouteOrder routeOrder) {
// 保存变更事件理由 // 保存变更事件理由
legDomainService.addChangeEvent(leg, legData.getChangeReason()); legDomainService.addChangeEvent(leg, legData.getChangeReason());
@ -182,12 +203,13 @@ public class OrderApplicationService {
leg.setRouteId(routeOrder.getRouteId()); leg.setRouteId(routeOrder.getRouteId());
ApproveOrderNo approveOrderNo = routeOrder.getApproveOrderNo(); ApproveOrderNo approveOrderNo = routeOrder.getApproveOrderNo();
if (!routeOrder.getOrderStatus().equals(ORDER_STATUS_PREPARE) && approveOrderNo.getSysCode().equals("ANFSSC") && if (!routeOrder.getOrderStatus().equals(ORDER_STATUS_PREPARE) && addLegData.getIfApprove() == 1
addLegData.getIfApprove() == 1
) { ) {
//这里加入一个待审批事件 //这里加入一个待审批事件
if (checkIfNeedApprove(routeOrder)) {
leg.addEvent(LegApprovalEvent.prepare()); leg.addEvent(LegApprovalEvent.prepare());
} }
}
if (!routeOrder.getOrderStatus().equals(ORDER_STATUS_PREPARE) && !approveOrderNo.getSysCode().equals("ANFSSC")) { if (!routeOrder.getOrderStatus().equals(ORDER_STATUS_PREPARE) && !approveOrderNo.getSysCode().equals("ANFSSC")) {
leg.reloadStatus(); leg.reloadStatus();
@ -216,7 +238,6 @@ public class OrderApplicationService {
.sendToQueue(); .sendToQueue();
} }
private List<Leg> processLegData(LegData legData, RouteOrder order) { private List<Leg> processLegData(LegData legData, RouteOrder order) {
if (legData.getCurrencyType() == null) { if (legData.getCurrencyType() == null) {
legData.setCurrencyType(CurrencyType.RENMINBI.getCode()); legData.setCurrencyType(CurrencyType.RENMINBI.getCode());

View File

@ -13,6 +13,7 @@ import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.chint.domain.aggregates.approval.ApprovalMethod.NOTIFY;
import static com.chint.domain.aggregates.approval.ApprovalType.LEG_ADD_CHANGE_BATCH; import static com.chint.domain.aggregates.approval.ApprovalType.LEG_ADD_CHANGE_BATCH;
import static com.chint.infrastructure.constant.LegConstant.LEG_APPROVAL_STATUS_PREPARE; import static com.chint.infrastructure.constant.LegConstant.LEG_APPROVAL_STATUS_PREPARE;
import static com.chint.infrastructure.constant.LegConstant.LEG_APPROVAL_STATUS_SUBMIT; import static com.chint.infrastructure.constant.LegConstant.LEG_APPROVAL_STATUS_SUBMIT;
@ -72,7 +73,7 @@ public class ApprovalLegAddAndChangeBatch extends ApprovalProcess {
private boolean isExtensionNotNullOrEmpty(Leg leg) { private boolean isExtensionNotNullOrEmpty(Leg leg) {
Optional<LegApprovalEvent> lastApprovalPrepareEvent = leg.getLastApprovalPrepareEvent(); Optional<LegApprovalEvent> lastApprovalPrepareEvent = leg.getLastApprovalPrepareEvent();
if(lastApprovalPrepareEvent.isEmpty()){ if (lastApprovalPrepareEvent.isEmpty()) {
return false; return false;
} }
String extension = lastApprovalPrepareEvent.get().getExtension(); String extension = lastApprovalPrepareEvent.get().getExtension();
@ -96,8 +97,6 @@ public class ApprovalLegAddAndChangeBatch extends ApprovalProcess {
} }
@Override @Override
public boolean approve() { public boolean approve() {
return false; return false;
@ -110,10 +109,34 @@ public class ApprovalLegAddAndChangeBatch extends ApprovalProcess {
@Override @Override
public ApprovalProcess doSubmitToBpm() { public ApprovalProcess doSubmitToBpm() {
//按照审批类型为行程加入不同的审批事件
if (this.getApprovalMethod().equals(NOTIFY)) {
//所有被提交审批的被加入知会事件
String approvalRecordNo = approvalData.getApprovalRecordNo();
addApprovalEventAndRecord(LegApprovalEvent.notifyEvent(approvalRecordNo));
} else {
//所有被提交审批的被加入审批事件
String approvalRecordNo = approvalData.getApprovalRecordNo();
addApprovalEventAndRecord(LegApprovalEvent.submit(approvalRecordNo));
}
bpmPlatform.submitLegAddOrChangeApproval(approvalData); bpmPlatform.submitLegAddOrChangeApproval(approvalData);
return this; return this;
} }
private void addApprovalEventAndRecord(LegApprovalEvent event) {
ApprovalRecord approvalRecord = this.getApprovalRecord();
approvalData.getAddLegList().forEach(leg -> {
leg.addEvent(event);
approvalRecord.addLeg(leg);
});
approvalData.getChangeLegList().forEach(it -> {
Leg newLeg = it.getFirst();
newLeg.addEvent(event);
approvalRecord.addLeg(newLeg);
});
bpmPlatform.submitLegAddOrChangeApproval(approvalData);
}
@Override @Override
public void handlerApprovalResultBefore(ApprovalResultData data) { public void handlerApprovalResultBefore(ApprovalResultData data) {
String approvalRecordNo = data.getApprovalRecordNo(); String approvalRecordNo = data.getApprovalRecordNo();

View File

@ -2,7 +2,6 @@ package com.chint.domain.aggregates.approval;
import com.chint.domain.aggregates.approval.platform.ApprovalPlatform; import com.chint.domain.aggregates.approval.platform.ApprovalPlatform;
import com.chint.domain.aggregates.order.Leg; import com.chint.domain.aggregates.order.Leg;
import com.chint.domain.aggregates.order.LegApprovalEvent;
import com.chint.domain.aggregates.order.OrderDetail; import com.chint.domain.aggregates.order.OrderDetail;
import com.chint.domain.aggregates.order.RouteOrder; import com.chint.domain.aggregates.order.RouteOrder;
import com.chint.domain.exceptions.CommandException; import com.chint.domain.exceptions.CommandException;
@ -26,6 +25,8 @@ public abstract class ApprovalProcess {
private ApprovalMethod approvalMethod; private ApprovalMethod approvalMethod;
private ApprovalRecord approvalRecord;
public ApprovalProcess(ApprovalPlatform bpmPlatform) { public ApprovalProcess(ApprovalPlatform bpmPlatform) {
this.bpmPlatform = bpmPlatform; this.bpmPlatform = bpmPlatform;
} }
@ -81,6 +82,7 @@ public abstract class ApprovalProcess {
} }
approvalData.setApprovalRecordNo(approvalRecord.getApprovalRecordNo()); approvalData.setApprovalRecordNo(approvalRecord.getApprovalRecordNo());
routeOrder.addApprovalRecord(approvalRecord); routeOrder.addApprovalRecord(approvalRecord);
this.approvalRecord = approvalRecord;
consumer.accept(approvalRecord); consumer.accept(approvalRecord);
return this; return this;
} else { } else {
@ -108,13 +110,6 @@ public abstract class ApprovalProcess {
public abstract ApprovalProcess doSubmitToBpm(); public abstract ApprovalProcess doSubmitToBpm();
public ApprovalProcess beforeSubmitToBpm() { public ApprovalProcess beforeSubmitToBpm() {
//所有被提交审批的被加入审批事件
String approvalRecordNo = approvalData.getApprovalRecordNo();
approvalData.getAddLegList().forEach(leg -> leg.addEvent(LegApprovalEvent.submit(approvalRecordNo)));
approvalData.getChangeLegList().forEach(it -> {
Leg newLeg = it.getFirst();
newLeg.addEvent(LegApprovalEvent.submit(approvalRecordNo));
});
return this; return this;
} }

View File

@ -1,15 +1,20 @@
package com.chint.domain.aggregates.approval; package com.chint.domain.aggregates.approval;
import com.chint.domain.aggregates.order.ApproveOrderNo; import com.chint.domain.aggregates.order.ApproveOrderNo;
import com.chint.domain.aggregates.order.Leg;
import com.chint.domain.aggregates.order.OrderDetail;
import com.chint.domain.aggregates.order.RouteOrder; import com.chint.domain.aggregates.order.RouteOrder;
import com.chint.infrastructure.util.OrderNo; import com.chint.infrastructure.util.OrderNo;
import lombok.Data; import lombok.Data;
import org.springframework.data.annotation.Id; import org.springframework.data.annotation.Id;
import org.springframework.data.relational.core.mapping.MappedCollection;
import org.springframework.data.relational.core.mapping.Table; import org.springframework.data.relational.core.mapping.Table;
import java.io.Serial; import java.io.Serial;
import java.io.Serializable; import java.io.Serializable;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects; import java.util.Objects;
@Data @Data
@ -33,6 +38,11 @@ public class ApprovalRecord implements Serializable {
private String approvalReason; private String approvalReason;
private String extension; private String extension;
private String extensionSub; private String extensionSub;
@MappedCollection(idColumn = "approval_record_id", keyColumn = "approval_record_key")
private List<ApprovalRecordLeg> ApprovalRecordLegList;
@MappedCollection(idColumn = "approval_record_id", keyColumn = "approval_record_key")
private List<ApprovalRecordOrder> ApprovalRecordOrderList;
public static ApprovalRecord of(RouteOrder routeOrder, ApprovalProcess approvalProcess) { public static ApprovalRecord of(RouteOrder routeOrder, ApprovalProcess approvalProcess) {
ApprovalRecord approvalRecord = new ApprovalRecord(); ApprovalRecord approvalRecord = new ApprovalRecord();
@ -50,6 +60,24 @@ public class ApprovalRecord implements Serializable {
return approvalRecord; return approvalRecord;
} }
public ApprovalRecord addLeg(Leg leg) {
if (ApprovalRecordLegList == null) {
ApprovalRecordLegList = new ArrayList<>();
}
ApprovalRecordLegList = new ArrayList<>(ApprovalRecordLegList);
ApprovalRecordLegList.add(ApprovalRecordLeg.of(leg));
return this;
}
public ApprovalRecord addOrderDetail(OrderDetail orderDetail) {
if (ApprovalRecordOrderList == null) {
ApprovalRecordOrderList = new ArrayList<>();
}
ApprovalRecordOrderList = new ArrayList<>(ApprovalRecordOrderList);
ApprovalRecordOrderList.add(ApprovalRecordOrder.of(orderDetail));
return this;
}
public ApprovalRecord reason(String approvalReason) { public ApprovalRecord reason(String approvalReason) {
this.approvalReason = approvalReason; this.approvalReason = approvalReason;
return this; return this;

View File

@ -0,0 +1,35 @@
package com.chint.domain.aggregates.approval;
import com.chint.domain.aggregates.order.Leg;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient;
import org.springframework.data.relational.core.mapping.Table;
import java.io.Serial;
import java.io.Serializable;
@Data
@Table("approval_record_leg")
public class ApprovalRecordLeg implements Serializable {
@Serial
private static final long serialVersionUID = 976619376459713654L;
@Id
private Long id;
private Long ApprovalRecordId;
private Long legId;
@Transient
private Leg leg;
public static ApprovalRecordLeg of(Leg leg) {
ApprovalRecordLeg approvalRecordLeg = of(leg.getLegId());
approvalRecordLeg.setLeg(leg);
return approvalRecordLeg;
}
public static ApprovalRecordLeg of(Long id) {
ApprovalRecordLeg approvalRecordLeg = new ApprovalRecordLeg();
approvalRecordLeg.setLegId(id);
return approvalRecordLeg;
}
}

View File

@ -0,0 +1,37 @@
package com.chint.domain.aggregates.approval;
import com.chint.domain.aggregates.order.Leg;
import com.chint.domain.aggregates.order.OrderDetail;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient;
import org.springframework.data.relational.core.mapping.Table;
import java.io.Serial;
import java.io.Serializable;
@Data
@Table("approval_record_order")
public class ApprovalRecordOrder implements Serializable {
@Serial
private static final long serialVersionUID = 8651937409123544654L;
@Id
private Long id;
private Long ApprovalRecordId;
private Long orderId;
@Transient
private OrderDetail orderDetail;
public static ApprovalRecordOrder of(OrderDetail orderDetail) {
ApprovalRecordOrder approvalRecordOrder = of(orderDetail.getOrderId());
approvalRecordOrder.setOrderDetail(orderDetail);
return approvalRecordOrder;
}
public static ApprovalRecordOrder of(Long orderId) {
ApprovalRecordOrder approvalRecordOrder = new ApprovalRecordOrder();
approvalRecordOrder.setOrderId(orderId);
return approvalRecordOrder;
}
}

View File

@ -30,6 +30,7 @@ public class LegApprovalEvent extends BaseEvent implements Serializable {
LEG_APPROVAL_STATUS_PREPARE, LEG_APPROVAL_STATUS_PREPARE_NAME, LEG_APPROVAL_STATUS_PREPARE, LEG_APPROVAL_STATUS_PREPARE_NAME,
LEG_APPROVAL_STATUS_SUBMIT, LEG_APPROVAL_STATUS_SUBMIT_NAME, LEG_APPROVAL_STATUS_SUBMIT, LEG_APPROVAL_STATUS_SUBMIT_NAME,
LEG_APPROVAL_STATUS_SUCCESS, LEG_APPROVAL_STATUS_SUCCESS_NAME, LEG_APPROVAL_STATUS_SUCCESS, LEG_APPROVAL_STATUS_SUCCESS_NAME,
LEG_APPROVAL_STATUS_NOTIFY, LEG_APPROVAL_STATUS_NOTIFY_NAME,
LEG_APPROVAL_STATUS_REJECT, LEG_APPROVAL_STATUS_REJECT_NAME); LEG_APPROVAL_STATUS_REJECT, LEG_APPROVAL_STATUS_REJECT_NAME);
} }
@ -70,4 +71,17 @@ public class LegApprovalEvent extends BaseEvent implements Serializable {
event.setEventType(LEG_APPROVAL_STATUS_REJECT); event.setEventType(LEG_APPROVAL_STATUS_REJECT);
return event; return event;
} }
public static LegApprovalEvent notifyEvent() {
LegApprovalEvent event = new LegApprovalEvent();
event.setEventType(LEG_APPROVAL_STATUS_NOTIFY);
return event;
}
public static LegApprovalEvent notifyEvent(String extension) {
LegApprovalEvent event = new LegApprovalEvent();
event.setEventType(LEG_APPROVAL_STATUS_NOTIFY);
event.setExtension(extension);
return event;
}
} }

View File

@ -3,6 +3,7 @@ package com.chint.domain.aggregates.order;
import com.chint.application.commands.LegOrderedCommand; import com.chint.application.commands.LegOrderedCommand;
import com.chint.domain.aggregates.approval.ApprovalRecord; import com.chint.domain.aggregates.approval.ApprovalRecord;
import com.chint.domain.aggregates.base.PermissionConfig;
import com.chint.domain.factoriy.leg.LegFactory; import com.chint.domain.factoriy.leg.LegFactory;
import com.chint.domain.service.LegDomainService; import com.chint.domain.service.LegDomainService;
import com.chint.domain.service.amount_estimate.EstimateAdapter; import com.chint.domain.service.amount_estimate.EstimateAdapter;
@ -82,6 +83,8 @@ public class RouteOrder implements Serializable {
private String supplierCNName; private String supplierCNName;
@Transient @Transient
private Set<RoutePermission> routePermissionSet; private Set<RoutePermission> routePermissionSet;
@Transient
private Set<PermissionConfig> permissionConfigSet;
//共有的扩展字段 //共有的扩展字段
@MappedCollection(idColumn = "route_id") @MappedCollection(idColumn = "route_id")

View File

@ -68,6 +68,7 @@ public class RouteApprovalDomainService {
List<Leg> legItems = routeOrder.getLegItems(); List<Leg> legItems = routeOrder.getLegItems();
legDomainService.queryLocation(legItems); legDomainService.queryLocation(legItems);
String approvalPlatformMark = getApprovalPlatformMark(routeOrder); String approvalPlatformMark = getApprovalPlatformMark(routeOrder);
checkApprovalPermissions(List.of(routeOrder));
ApprovalProcess approvalProcess = ApprovalSubmit.of(LEG_ADD_CHANGE_BATCH, approvalPlatformMark) ApprovalProcess approvalProcess = ApprovalSubmit.of(LEG_ADD_CHANGE_BATCH, approvalPlatformMark)
.approveData(routeOrder); .approveData(routeOrder);
checkApprovalData(approvalProcess.getApprovalData()); checkApprovalData(approvalProcess.getApprovalData());
@ -103,6 +104,7 @@ public class RouteApprovalDomainService {
legDomainService.checkLocation(allLegs); legDomainService.checkLocation(allLegs);
} }
public List<RouteOrder> checkApprovalPermissions(List<RouteOrder> routeOrderList) { public List<RouteOrder> checkApprovalPermissions(List<RouteOrder> routeOrderList) {
// 提取所有 approveOrderNo sysCode // 提取所有 approveOrderNo sysCode
Set<String> accountCompanyCodes = routeOrderList.stream() Set<String> accountCompanyCodes = routeOrderList.stream()
@ -129,16 +131,23 @@ public class RouteApprovalDomainService {
// 获取所有审批类型 // 获取所有审批类型
Set<String> approvalTypes = routeOrderList.stream() Set<String> approvalTypes = routeOrderList.stream()
.map(routeOrder -> { .flatMap(routeOrder -> {
ApproveOrderNo approveOrderNo = routeOrder.getApproveOrderNo(); ApproveOrderNo approveOrderNo = routeOrder.getApproveOrderNo();
String accountCompany = approveOrderNo.getAccountCompany(); String accountCompany = approveOrderNo.getAccountCompany();
return accountCompanyToApprovalType.getOrDefault(accountCompany, sysCodeToApprovalType.get(approveOrderNo.getSysCode())); String orDefault = accountCompanyToApprovalType.getOrDefault(accountCompany, sysCodeToApprovalType.get(approveOrderNo.getSysCode()));
if (orDefault != null && !orDefault.isEmpty()) {
return Arrays.stream(orDefault.split("&"));
} else {
return null;
}
}) })
.filter(Objects::nonNull)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
List<PermissionConfig> byPermissionNameIn = permissionConfigRepository
.findByPermissionNameIn(approvalTypes);
// 批量查询 permissionConfigRepository // 批量查询 permissionConfigRepository
Map<String, List<String>> approvalTypeToPermissions = permissionConfigRepository Map<String, List<String>> approvalTypeToPermissions = byPermissionNameIn
.findByPermissionNameIn(approvalTypes)
.stream() .stream()
.collect(Collectors.toMap(PermissionConfig::getPermissionName, PermissionConfig::permissions)); .collect(Collectors.toMap(PermissionConfig::getPermissionName, PermissionConfig::permissions));
@ -157,6 +166,14 @@ public class RouteApprovalDomainService {
Set<RoutePermission> routePermissionSet = approvalTypeToPermissionSet Set<RoutePermission> routePermissionSet = approvalTypeToPermissionSet
.getOrDefault(approvalType, Collections.emptySet()); .getOrDefault(approvalType, Collections.emptySet());
routeOrder.setRoutePermissionSet(routePermissionSet); routeOrder.setRoutePermissionSet(routePermissionSet);
if (approvalType != null && !approvalType.isEmpty()) {
List<String> list = Arrays.stream(approvalType.split("&")).distinct().toList();
routeOrder.setPermissionConfigSet(byPermissionNameIn
.stream()
.filter(it -> list.contains(it.getPermissionName()))
.collect(Collectors.toSet()));
}
} }
return routeOrderList; return routeOrderList;
} }
@ -165,7 +182,8 @@ public class RouteApprovalDomainService {
ApproveOrderNo approveOrderNo = routeOrder.getApproveOrderNo(); ApproveOrderNo approveOrderNo = routeOrder.getApproveOrderNo();
String approvalType = findApprovalType(approveOrderNo); String approvalType = findApprovalType(approveOrderNo);
if (approvalType != null) { if (approvalType != null) {
Set<RoutePermission> permissions = findRoutePermissions(approvalType); Set<String> approvalTypeSet = Arrays.stream(approvalType.split("&")).collect(Collectors.toSet());
Set<RoutePermission> permissions = findRoutePermissions(approvalTypeSet);
routeOrder.setRoutePermissionSet(permissions); routeOrder.setRoutePermissionSet(permissions);
} else { } else {
routeOrder.setRoutePermissionSet(Collections.emptySet()); routeOrder.setRoutePermissionSet(Collections.emptySet());
@ -179,13 +197,13 @@ public class RouteApprovalDomainService {
.orElseGet(() -> systemCodeRepository.findBySysCode(approveOrderNo.getSysCode()).getApprovalType()); .orElseGet(() -> systemCodeRepository.findBySysCode(approveOrderNo.getSysCode()).getApprovalType());
} }
private Set<RoutePermission> findRoutePermissions(String approvalType) { private Set<RoutePermission> findRoutePermissions(Set<String> approvalTypeSet) {
return permissionConfigRepository.findByPermissionName(approvalType) return permissionConfigRepository.findByPermissionNameIn(approvalTypeSet)
.map(permissionConfig -> permissionConfig.permissions().stream() .stream()
.flatMap(permissionConfig -> permissionConfig.permissions().stream()
.distinct() .distinct()
.map(permission -> Enum.valueOf(RoutePermission.class, permission)) .map(permission -> Enum.valueOf(RoutePermission.class, permission)))
.collect(Collectors.toSet())) .collect(Collectors.toSet());
.orElseGet(Collections::emptySet);
} }

View File

@ -1,5 +1,5 @@
package com.chint.domain.value_object.enums; package com.chint.domain.value_object.enums;
public enum RoutePermission { public enum RoutePermission {
APPROVAL_BUTTON APPROVAL_BUTTON, LEG_NEED_APPROVAL, LEG_NEED_NOTIFY
} }

View File

@ -167,18 +167,18 @@ public class SystemOrganizationRepositoryImpl implements SystemOrganizationRepos
@Override @Override
public Optional<SystemOrganization> findByOrgCodeContainingOrOrgNameContaining(String orgCode, String orgName) { public Optional<SystemOrganization> findByOrgCodeContainingOrOrgNameContaining(String orgCode, String orgName) {
return Stream.of( return Optional.ofNullable(cacheSystemOrganizationRepository.cacheOrgCodeById(orgCode, null))
.flatMap(id -> Optional.ofNullable(cacheSystemOrganizationRepository.cacheById(id, null)))
.or(() -> Stream.of(
jdbcSystemOrganizationRepository.findByOrgCode(orgCode).stream().findFirst(), jdbcSystemOrganizationRepository.findByOrgCode(orgCode).stream().findFirst(),
jdbcSystemOrganizationRepository.findByOrgName(orgName).stream().findFirst() jdbcSystemOrganizationRepository.findByOrgName(orgName).stream().findFirst()
) )
.filter(Optional::isPresent) .filter(Optional::isPresent)
.map(Optional::get) .map(Optional::get)
.findFirst(); .findFirst());
} }
@Override @Override
public List<String> queryOrgCodeListByUserId(Long userId) { public List<String> queryOrgCodeListByUserId(Long userId) {
return jdbcSystemOrganizationRepository.queryOrgCodeListByUserId(userId); return jdbcSystemOrganizationRepository.queryOrgCodeListByUserId(userId);

View File

@ -26,11 +26,17 @@ public class CacheSystemOrganizationRepository {
return Objects.requireNonNullElseGet(systemOrganizationList, List::of); return Objects.requireNonNullElseGet(systemOrganizationList, List::of);
} }
@Cacheable(value = "SystemOrganization", key = "#systemOrganization.id") @Cacheable(value = "SystemOrganization", key = "#systemOrganization.id")
public SystemOrganization cache(SystemOrganization systemOrganization) { public SystemOrganization cache(SystemOrganization systemOrganization) {
return systemOrganization; return systemOrganization;
} }
@Cacheable(value = "SystemOrganization", key = "#id")
public SystemOrganization cacheById(Long id, SystemOrganization systemOrganization) {
return systemOrganization;
}
@CacheEvict(value = "SystemOrganization", key = "#systemOrganization.id") @CacheEvict(value = "SystemOrganization", key = "#systemOrganization.id")
public void cacheEvict(SystemOrganization systemOrganization) { public void cacheEvict(SystemOrganization systemOrganization) {
} }

View File

@ -821,7 +821,7 @@ public class LYTest {
@Test @Test
void searchTrain() { void searchTrain() {
TrainDetailResponse trainOrderDetail = lySearchRequest.getTrainOrderDetail("DT24060375930947862"); TrainDetailResponse trainOrderDetail = lySearchRequest.getTrainOrderDetail("DT24062077869838419");
Gson gson = new Gson(); Gson gson = new Gson();
String json = gson.toJson(trainOrderDetail); String json = gson.toJson(trainOrderDetail);
System.out.println(json); System.out.println(json);