fix:审批功能重构-安能添加行程和变更行程-细节问题修复
This commit is contained in:
parent
eaa76fbce3
commit
708226b3c8
|
@ -60,7 +60,6 @@ public class OrderPublicController {
|
|||
|
||||
|
||||
|
||||
|
||||
@ApiOperation("审批拒绝行程规划单")
|
||||
@PostMapping("/reject")
|
||||
public Result<String> rejectOrder(@RequestBody ApproveRouteData approveRouteData) {
|
||||
|
@ -106,7 +105,7 @@ public class OrderPublicController {
|
|||
}
|
||||
|
||||
|
||||
@ApiOperation("提交需要审批的行程节点")
|
||||
@ApiOperation("处理审批结果回复")
|
||||
@PostMapping("/approve/response")
|
||||
public Result<String> approveOrder(@RequestBody ApprovalResultData data) {
|
||||
routeApprovalDomainService.handlerApprovalResponse(data);
|
||||
|
|
|
@ -5,7 +5,6 @@ import com.chint.domain.aggregates.base.BaseEvent;
|
|||
import com.chint.domain.aggregates.order.Leg;
|
||||
import com.chint.domain.aggregates.order.LegApprovalEvent;
|
||||
import com.chint.domain.aggregates.order.RouteOrder;
|
||||
import com.google.gson.Gson;
|
||||
import org.springframework.data.util.Pair;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
@ -36,9 +35,8 @@ public class ApprovalLegAddAndChangeBatch extends ApprovalProcess {
|
|||
approvalData.setAddLegList(legMap.get(true));
|
||||
List<Pair<Leg, Leg>> pairList = legMap.get(false).stream()
|
||||
.map(leg -> {
|
||||
Gson gson = new Gson();
|
||||
String extension = leg.getLastEvent().getExtension();
|
||||
Leg oldLeg = gson.fromJson(extension, Leg.class);
|
||||
Leg oldLeg = leg.deepClone().restoreFromLegString(extension);
|
||||
return Pair.of(leg, oldLeg);
|
||||
}).toList();
|
||||
approvalData.setChangeLegList(pairList);
|
||||
|
@ -67,22 +65,37 @@ public class ApprovalLegAddAndChangeBatch extends ApprovalProcess {
|
|||
public void handlerApprovalResultBefore(ApprovalResultData data) {
|
||||
String approvalRecordNo = data.getApprovalRecordNo();
|
||||
RouteOrder routeOrder = data.getRouteOrder();
|
||||
|
||||
routeOrder.getLegItems().stream()
|
||||
.filter(leg -> {
|
||||
BaseEvent lastEvent = leg.getLastEvent();
|
||||
return lastEvent.getEventType().equals(LEG_APPROVAL_STATUS_SUBMIT) &&
|
||||
lastEvent.getExtension().equals(approvalRecordNo);
|
||||
}).forEach(leg -> {
|
||||
if (data.getApprovalStatus().equals(ApprovalRecord.successApprovalStatus())) {
|
||||
leg.addEvent(LegApprovalEvent.success());
|
||||
.filter(leg -> isLegApprovalPending(leg, approvalRecordNo))
|
||||
.forEach(leg -> handleLegApprovalResult(data, routeOrder, leg));
|
||||
}
|
||||
private boolean isLegApprovalPending(Leg leg, String approvalRecordNo) {
|
||||
BaseEvent lastEvent = leg.getLastEvent();
|
||||
return lastEvent.getEventType().equals(LEG_APPROVAL_STATUS_SUBMIT) &&
|
||||
lastEvent.getExtension().equals(approvalRecordNo);
|
||||
}
|
||||
private void handleLegApprovalResult(ApprovalResultData data, RouteOrder routeOrder, Leg leg) {
|
||||
if (data.getApprovalStatus().equals(ApprovalRecord.successApprovalStatus())) {
|
||||
leg.addEvent(LegApprovalEvent.success());
|
||||
} else {
|
||||
leg.addEvent(LegApprovalEvent.reject());
|
||||
rollbackLegState(routeOrder, leg);
|
||||
}
|
||||
}
|
||||
private void rollbackLegState(RouteOrder routeOrder, Leg leg) {
|
||||
leg.getLegApprovalEventList().stream()
|
||||
.filter(event -> event.getEventType().equals(LEG_APPROVAL_STATUS_PREPARE))
|
||||
.max(Comparator.comparing(LegApprovalEvent::getHappenTime))
|
||||
.ifPresent(lastPrepareEvent -> {
|
||||
if (isRollbackToOriginalLeg(lastPrepareEvent)) {
|
||||
routeOrder.deleteLeg(leg.getLegNo());
|
||||
} else {
|
||||
leg.addEvent(LegApprovalEvent.reject());//如果行程被驳回 ,那么就要回滚到审批前的状态
|
||||
leg.getLegApprovalEventList()
|
||||
.stream()
|
||||
.filter(legApprovalEvent -> legApprovalEvent.getEventType().equals(LEG_APPROVAL_STATUS_PREPARE))
|
||||
.max(Comparator.comparing(LegApprovalEvent::getHappenTime))
|
||||
.ifPresent(it -> leg.restoreFromLegString(it.getExtension()));
|
||||
leg.restoreFromLegString(lastPrepareEvent.getExtension());
|
||||
}
|
||||
});
|
||||
}
|
||||
private boolean isRollbackToOriginalLeg(LegApprovalEvent lastPrepareEvent) {
|
||||
return lastPrepareEvent.getExtension() == null || lastPrepareEvent.getExtension().isEmpty();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,10 +5,14 @@ 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.RouteOrder;
|
||||
import com.chint.domain.exceptions.CommandException;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static com.chint.infrastructure.constant.LegConstant.LEG_APPROVAL_STATUS_PREPARE;
|
||||
|
||||
|
||||
// 定义抽象类 ApprovalProcess
|
||||
@Data
|
||||
|
@ -52,8 +56,16 @@ public abstract class ApprovalProcess {
|
|||
RouteOrder routeOrder = approvalData.getRouteOrder();
|
||||
if (routeOrder != null) {
|
||||
ApprovalRecord approvalRecord = ApprovalRecord.of(routeOrder, this);
|
||||
List<Leg> legs = routeOrder.getLegItems()
|
||||
.stream()
|
||||
.filter(legItem -> legItem.getLastEvent().getEventType().equals(LEG_APPROVAL_STATUS_PREPARE))
|
||||
.toList();
|
||||
if (legs.isEmpty()) {
|
||||
throw new CommandException("不存在需要审批的行程");
|
||||
}
|
||||
approvalData.setApprovalRecordNo(approvalRecord.getApprovalRecordNo());
|
||||
consumer.accept(approvalRecord); // 使用传入的Consumer对象
|
||||
routeOrder.addApprovalRecord(approvalRecord);
|
||||
consumer.accept(approvalRecord);
|
||||
return this;
|
||||
} else {
|
||||
return null;
|
||||
|
@ -82,10 +94,11 @@ public abstract class ApprovalProcess {
|
|||
|
||||
public ApprovalProcess beforeSubmitToBpm() {
|
||||
//所有被提交审批的被加入审批事件
|
||||
approvalData.getAddLegList().forEach(leg -> leg.addEvent(LegApprovalEvent.submit()));
|
||||
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());
|
||||
newLeg.addEvent(LegApprovalEvent.submit(approvalRecordNo));
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.chint.domain.aggregates.approval;
|
||||
|
||||
import com.chint.domain.aggregates.approval.platform.ApprovalPlatform;
|
||||
import com.chint.domain.aggregates.order.RouteOrder;
|
||||
import com.chint.domain.repository.ApprovalRecordRepository;
|
||||
import com.chint.domain.repository.RouteRepository;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -9,8 +10,10 @@ import org.springframework.boot.context.event.ApplicationReadyEvent;
|
|||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
|
@ -57,14 +60,25 @@ public class ApprovalSubmit implements ApplicationListener<ApplicationReadyEvent
|
|||
}
|
||||
|
||||
//用于处理审批结果
|
||||
@Transactional
|
||||
public void handleApprovalResult(ApprovalResultData data) {
|
||||
approvalRecordRepository.findByApprovalRecordNo(data.getApprovalRecordNo())
|
||||
.ifPresent(it -> {
|
||||
data.setRouteOrder(routeRepository.queryById(it.getRouteId()));
|
||||
ApprovalProcess approvalProcess = of(ApprovalType.valueOf(it.getApprovalType()), it.getApprovalPlatformMark());
|
||||
approvalProcess.handlerApprovalResult(data);
|
||||
approvalRecordRepository.save(it);
|
||||
routeRepository.save(data.getRouteOrder());
|
||||
});
|
||||
Optional<ApprovalRecord> optionalApprovalRecord = approvalRecordRepository.findByApprovalRecordNo(data.getApprovalRecordNo());
|
||||
if (optionalApprovalRecord.isPresent()) {
|
||||
ApprovalRecord approvalRecord = optionalApprovalRecord.get();
|
||||
RouteOrder routeOrder = routeRepository.queryById(approvalRecord.getRouteId());
|
||||
data.setRouteOrder(routeOrder);
|
||||
Optional<ApprovalRecord> matchingApprovalRecord = routeOrder.getApprovalRecordList().stream()
|
||||
.filter(record -> record.getApprovalRecordNo().equals(data.getApprovalRecordNo()))
|
||||
.findFirst();
|
||||
matchingApprovalRecord.ifPresent(record -> processHandleApprovalResult(data, routeOrder, record));
|
||||
}
|
||||
}
|
||||
|
||||
private void processHandleApprovalResult(ApprovalResultData data, RouteOrder routeOrder, ApprovalRecord approvalRecord) {
|
||||
ApprovalProcess approvalProcess = of(ApprovalType.valueOf(approvalRecord.getApprovalType()),
|
||||
approvalRecord.getApprovalPlatformMark());
|
||||
approvalProcess.handlerApprovalResult(data);
|
||||
approvalRecord.setApprovalStatus(data.getApprovalStatus());
|
||||
routeRepository.save(routeOrder);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ public class ApprovalPlatformAN implements ApprovalPlatform {
|
|||
@PostConstruct
|
||||
void init() {
|
||||
approvalPlatformInfoRepository.findByPlatformMark(platformMark)
|
||||
.ifPresent(approvalPlatformInfo -> approvalPlatformInfo.setPlatformMark(platformMark));
|
||||
.ifPresent(approvalPlatformInfo -> this.approvalPlatformInfo = approvalPlatformInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -14,7 +14,7 @@ public interface EventManageable {
|
|||
default void addEvent(BaseEvent event) {
|
||||
List<BaseEvent> events = (List<BaseEvent>) getEvents();
|
||||
BaseEvent lastEvent = getLastEvent();
|
||||
if (!Objects.equals(lastEvent.getEventType(), event.getEventType())) {
|
||||
if (lastEvent == null || !Objects.equals(lastEvent.getEventType(), event.getEventType())) {
|
||||
events.add(event);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -421,18 +421,20 @@ public class Leg implements Serializable, EventManageable {
|
|||
public String generateLegString() {
|
||||
return DateTimeUtil.timeToStrCommon(startTime) + "|" +
|
||||
DateTimeUtil.timeToStrCommon(endTime) + "|" +
|
||||
originId + "|" + destinationId;
|
||||
originId + "|" + destinationId + "|" + estimateAmount;
|
||||
}
|
||||
|
||||
public void restoreFromLegString(String legString) {
|
||||
public Leg restoreFromLegString(String legString) {
|
||||
String[] parts = legString.split("\\|");
|
||||
if (parts.length == 4) {
|
||||
if (parts.length == 5) {
|
||||
this.startTime = DateTimeUtil.strToTime(parts[0]);
|
||||
this.endTime = DateTimeUtil.strToTime(parts[1]);
|
||||
this.originId = Long.parseLong(parts[2]);
|
||||
this.destinationId = Long.parseLong(parts[3]);
|
||||
this.estimateAmount = parts[4];
|
||||
} else {
|
||||
throw new IllegalArgumentException("Invalid legString format.");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
package com.chint.domain.aggregates.order;
|
||||
|
||||
import com.chint.domain.aggregates.base.BaseEvent;
|
||||
import com.chint.infrastructure.util.Json;
|
||||
import lombok.Data;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.relational.core.mapping.Column;
|
||||
|
@ -53,6 +52,13 @@ public class LegApprovalEvent extends BaseEvent implements Serializable {
|
|||
return event;
|
||||
}
|
||||
|
||||
public static LegApprovalEvent submit(String extension) {
|
||||
LegApprovalEvent event = new LegApprovalEvent();
|
||||
event.setEventType(LEG_APPROVAL_STATUS_SUBMIT);
|
||||
event.setExtension(extension);
|
||||
return event;
|
||||
}
|
||||
|
||||
public static LegApprovalEvent success() {
|
||||
LegApprovalEvent event = new LegApprovalEvent();
|
||||
event.setEventType(LEG_APPROVAL_STATUS_SUCCESS);
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.chint.domain.aggregates.order;
|
|||
|
||||
|
||||
import com.chint.application.commands.LegOrderedCommand;
|
||||
import com.chint.domain.aggregates.approval.ApprovalRecord;
|
||||
import com.chint.domain.factoriy.leg.LegFactory;
|
||||
import com.chint.domain.service.LegDomainService;
|
||||
import com.chint.domain.service.amount_estimate.EstimateAdapter;
|
||||
|
@ -102,6 +103,9 @@ public class RouteOrder implements Serializable {
|
|||
@MappedCollection(idColumn = "route_id", keyColumn = "route_order_key")
|
||||
private List<RouteRequest> routeRequestList;
|
||||
|
||||
@MappedCollection(idColumn = "route_id", keyColumn = "route_order_key")
|
||||
private List<ApprovalRecord> approvalRecordList;
|
||||
|
||||
@ApiModelProperty("启用状态,1启动,0禁用")
|
||||
public Integer status = 1;
|
||||
|
||||
|
@ -224,6 +228,15 @@ public class RouteOrder implements Serializable {
|
|||
return this;
|
||||
}
|
||||
|
||||
public RouteOrder addApprovalRecord(ApprovalRecord approvalRecord) {
|
||||
if (this.approvalRecordList == null) {
|
||||
this.approvalRecordList = new ArrayList<>();
|
||||
}
|
||||
this.approvalRecordList = new ArrayList<>(this.approvalRecordList);
|
||||
this.approvalRecordList.add(approvalRecord);
|
||||
return this;
|
||||
}
|
||||
|
||||
public RouteOrder addRouteRequest(RouteRequest routeRequest) {
|
||||
if (this.routeRequestList == null) {
|
||||
this.routeRequestList = new ArrayList<>();
|
||||
|
|
|
@ -40,7 +40,7 @@ public class SystemCode implements Serializable {
|
|||
|
||||
private String getExtensionValue(String fieldName) {
|
||||
if (systemCodeExtensionFieldList == null || systemCodeExtensionFieldList.isEmpty()) {
|
||||
return "";
|
||||
return null;
|
||||
}
|
||||
return this.systemCodeExtensionFieldList.stream().filter(it -> it.getFieldName().equals(fieldName))
|
||||
.map(SystemCodeExtensionField::getFieldValue)
|
||||
|
|
|
@ -104,7 +104,7 @@ public class SystemOrganization implements Serializable {
|
|||
|
||||
private String getExtensionValue(String fieldName) {
|
||||
if (systemOrganizationExtensionList == null || systemOrganizationExtensionList.isEmpty()) {
|
||||
return "";
|
||||
return null;
|
||||
}
|
||||
return this.systemOrganizationExtensionList.stream().filter(it -> it.getFieldName().equals(fieldName))
|
||||
.map(SystemOrganizationExtension::getFieldValue)
|
||||
|
|
|
@ -228,7 +228,8 @@ public class LegDomainService {
|
|||
List<Leg> filteredLegItems = legItems.stream()
|
||||
.filter(it -> !it.getLegType().equals(LEG_TYPE_OTHER) && it.legIsInternal())
|
||||
.peek(Leg::reloadStatus)
|
||||
.filter(it -> !it.getLegApprovalStatus().equals(LEG_APPROVAL_STATUS_SUBMIT))
|
||||
.filter(it -> !it.getLegApprovalStatus().equals(LEG_APPROVAL_STATUS_SUBMIT) &&
|
||||
!it.getLegApprovalStatus().equals(LEG_APPROVAL_STATUS_PREPARE))
|
||||
.toList();
|
||||
|
||||
// 根据供应商名称查找供应商并进行处理
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.chint.domain.aggregates.approval.ApprovalResultData;
|
|||
import com.chint.domain.aggregates.approval.ApprovalSubmit;
|
||||
import com.chint.domain.aggregates.base.PermissionConfig;
|
||||
import com.chint.domain.aggregates.order.ApproveOrderNo;
|
||||
import com.chint.domain.aggregates.order.Leg;
|
||||
import com.chint.domain.aggregates.order.RouteOrder;
|
||||
import com.chint.domain.aggregates.system.SystemCode;
|
||||
import com.chint.domain.aggregates.system.SystemOrganization;
|
||||
|
@ -12,6 +13,7 @@ import com.chint.domain.repository.*;
|
|||
import com.chint.domain.value_object.enums.RoutePermission;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
@ -40,6 +42,10 @@ public class RouteApprovalDomainService {
|
|||
@Autowired
|
||||
private ApprovalRecordRepository approvalRecordRepository;
|
||||
|
||||
@Autowired
|
||||
private LegDomainService legDomainService;
|
||||
|
||||
@Autowired
|
||||
private ApprovalSubmit approvalSubmit;
|
||||
|
||||
public void legApprovalResponse() {
|
||||
|
@ -54,15 +60,17 @@ public class RouteApprovalDomainService {
|
|||
approvalSubmit.handleApprovalResult(data);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void approveRouteOfLegChangeAndAdd(LegApprovalParam param) {
|
||||
RouteOrder routeOrder = routeRepository.queryById(param.getRouteId());
|
||||
List<Leg> legItems = routeOrder.getLegItems();
|
||||
if (legItems != null && !legItems.isEmpty() && legItems.get(0).getOriginLocation() == null) {
|
||||
legDomainService.queryLocation(legItems);
|
||||
}
|
||||
String approvalPlatformMark = getApprovalPlatformMark(routeOrder);
|
||||
ApprovalSubmit.of(LEG_ADD_CHANGE_BATCH, approvalPlatformMark)
|
||||
.approveData(routeOrder)
|
||||
.record(record -> {
|
||||
record.setApprovalReason(param.getApprovalReason());
|
||||
approvalRecordRepository.save(record);
|
||||
})
|
||||
.record(it -> it.setApprovalReason(param.getApprovalReason()))
|
||||
.submitToBpm();
|
||||
routeRepository.save(routeOrder);
|
||||
}
|
||||
|
|
|
@ -45,7 +45,8 @@ public interface SupplierOrderSync extends SupplierAdapter {
|
|||
.stream()
|
||||
.map(RouteRequestLeg::getLeg)
|
||||
.peek(Leg::reloadStatus)
|
||||
.filter(it -> !it.getLegApprovalStatus().equals(LEG_APPROVAL_STATUS_SUBMIT))
|
||||
.filter(it -> !it.getLegApprovalStatus().equals(LEG_APPROVAL_STATUS_SUBMIT) &&
|
||||
!it.getLegApprovalStatus().equals(LEG_APPROVAL_STATUS_PREPARE))
|
||||
.toList();
|
||||
|
||||
// Legs can not be empty
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package com.chint.infrastructure.repository;
|
||||
|
||||
import com.chint.domain.aggregates.order.ApproveOrderNo;
|
||||
import com.chint.domain.aggregates.order.Leg;
|
||||
import com.chint.domain.aggregates.order.RouteOrder;
|
||||
import com.chint.domain.repository.RouteRepository;
|
||||
import com.chint.domain.service.LegDomainService;
|
||||
import com.chint.domain.value_object.OrderQueryData;
|
||||
import com.chint.infrastructure.cache.RouteCacheService;
|
||||
import com.chint.infrastructure.repository.jdbc.JdbcRouteRepository;
|
||||
|
@ -32,10 +34,14 @@ public class RouteRepositoryImpl implements RouteRepository {
|
|||
@Autowired
|
||||
private RedisTemplate<String, RouteOrder> redisTemplate;
|
||||
|
||||
|
||||
@Override
|
||||
public RouteOrder queryById(Long orderId) {
|
||||
// jdbcRouteRepository.findByRouteId(orderId);
|
||||
return routeCacheService.getRouteById(orderId);
|
||||
RouteOrder routeOrder = routeCacheService.getRouteById(orderId);
|
||||
if (routeOrder != null && routeOrder.getOrderStatus() == null) {
|
||||
routeOrder.reloadStatus();
|
||||
}
|
||||
return routeOrder;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -11,7 +11,7 @@ public class DelayDispatch {
|
|||
if (attempt >= 5) {
|
||||
return;
|
||||
}
|
||||
boolean success = requestSupplier.get(); // 使用Supplier<Boolean>获取请求成功与否的状态
|
||||
boolean success = requestSupplier != null && requestSupplier.get() != null && requestSupplier.get(); // 使用Supplier<Boolean>获取请求成功与否的状态
|
||||
if (!success) {
|
||||
ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
|
||||
scheduler.schedule(() -> {
|
||||
|
|
Loading…
Reference in New Issue