完成部分业务逻辑

This commit is contained in:
lulz1 2024-02-04 10:31:43 +08:00
parent c2a7816da7
commit ca1c093698
25 changed files with 191 additions and 50 deletions

View File

@ -71,6 +71,10 @@
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>3.0.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
<build>

View File

@ -0,0 +1,25 @@
package com.chint.application.commands;
import com.chint.domain.value_object.SyncLegData;
import com.chint.infrastructure.echo_framework.command.Command;
import lombok.Data;
import static com.chint.infrastructure.constant.Constant.LEG_EVENT_NOT_ORDERED;
@Data
public class LegSyncCommand extends Command {
private Integer LegEventType = LEG_EVENT_NOT_ORDERED;
private Long LegId;
private Long routOrderId;
private SyncLegData data;
public LegSyncCommand legId(Long LegId) {
this.setLegId(LegId);
return this;
}
public LegSyncCommand data(SyncLegData data) {
this.data = data;
return this;
}
}

View File

@ -0,0 +1,15 @@
package com.chint.application.commands;
import com.chint.domain.value_object.UserLoginParam;
import com.chint.infrastructure.echo_framework.command.Command;
import lombok.Data;
@Data
public class OrderCreateCommand extends Command {
private UserLoginParam loginParam;
public OrderCreateCommand of(UserLoginParam loginParam) {
this.loginParam = loginParam;
return this;
}
}

View File

@ -1,13 +1,19 @@
package com.chint.application.out;
import com.chint.application.commands.OrderCreateCommand;
import com.chint.domain.service.auth.AuthenticateService;
import com.chint.domain.value_object.UserLoginParam;
import com.chint.domain.value_object.UserLoginResult;
import com.chint.infrastructure.echo_framework.command.Command;
import com.chint.infrastructure.util.Digest;
import com.chint.infrastructure.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import static com.chint.infrastructure.constant.Constant.*;
@ -18,6 +24,7 @@ public class LoginController {
@Autowired
private AuthenticateService authenticateService;
@Transactional
@GetMapping("/login")
public Result<UserLoginResult> login(@RequestParam("sfno") String sfno,
@RequestParam("syscode") String syscode,
@ -32,6 +39,8 @@ public class LoginController {
UserLoginParam userLoginParam = new UserLoginParam(sfno, syscode, billcode, timespan);
UserLoginResult userLoginResult = authenticateService
.authenticateEmployeeNo(userLoginParam);
//发送创建行程订单命令
Command.of(OrderCreateCommand.class).of(userLoginParam).sendToQueue();
return Result.Success(SUCCESS, userLoginResult);
} else {
return Result.error(SIGN_ERROR);

View File

@ -2,6 +2,7 @@ package com.chint.application.services;
import com.chint.application.commands.LegPrepareCommand;
import com.chint.domain.aggregates.order.RouteOrder;
import com.chint.domain.exceptions.NotFoundException;
import com.chint.domain.factoriy.leg.LegFactory;
import com.chint.domain.factoriy.order.OrderFactory;
import com.chint.domain.repository.RouteRepository;
@ -13,6 +14,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import static com.chint.infrastructure.constant.Constant.NOT_FOUND;
@Service
public class OrderApplicationService {
@ -35,10 +38,11 @@ public class OrderApplicationService {
order = routeRepository.queryById(orderSaveData.getRouteId());
order.reloadStatus(orderSaveData, legFactory);
} else {
order = orderFactory.createOrder(orderSaveData);
// order = orderFactory.createOrder(orderSaveData);
throw new NotFoundException(NOT_FOUND);
}
RouteOrder routeOrder = orderDomainService.saveOrder(order);
//这里保存订单之后需要为每个leg执行规划中事件
//这里保存订单之后需要为每个新添加的leg执行规划中事件
routeOrder.getLegItems().forEach(leg ->
Command.of(LegPrepareCommand.class).legId(leg.getLegId()).sendToQueue()
);

View File

@ -6,4 +6,5 @@ import lombok.Data;
public class ApproveOrderNo {
private String fakeOrderNo;
private String actualOrderNo;
private String accountCompany;
}

View File

@ -107,6 +107,7 @@ public class Leg {
case LEG_STATUS_ORDERED -> LEG_STATUS_ORDERED_NAME;
case LEG_STATUS_PAYED -> LEG_STATUS_PAYED_NAME;
case LEG_STATUS_FINISH -> LEG_STATUS_FINISH_NAME;
case LEG_STATUS_NOT_ORDERED -> LEG_STATUS_NOT_ORDERED_NAME;
default -> "未知状态";
};
}

View File

@ -34,6 +34,7 @@ public class LegEvent {
case LEG_EVENT_ORDERED -> LEG_EVENT_ORDERED_NAME;
case LEG_EVENT_PAYED -> LEG_EVENT_PAYED_NAME;
case LEG_EVENT_FINISH -> LEG_EVENT_FINISH_NAME;
case LEG_EVENT_NOT_ORDERED -> LEG_EVENT_NOT_ORDERED_NAME;
default -> "未知事件";
};
}

View File

@ -157,6 +157,7 @@ public class RouteOrder extends BaseEntity {
case ORDER_STATUS_ORDERED -> ORDER_STATUS_ORDERED_NAME;
case ORDER_STATUS_PAYED -> ORDER_STATUS_PAYED_NAME;
case ORDER_STATUS_FINISH -> ORDER_STATUS_FINISH_NAME;
case ORDER_STATUS_NOT_ORDERED -> ORDER_STATUS_NOT_ORDERED_NAME;
default -> "未知状态";
};
}

View File

@ -1,9 +1,11 @@
package com.chint.domain.factoriy.order;
import com.chint.application.commands.OrderCreateCommand;
import com.chint.domain.aggregates.order.RouteOrder;
import com.chint.domain.value_object.OrderSaveData;
public interface OrderFactory {
RouteOrder createOrder(OrderSaveData orderData);
RouteOrder createOrder(OrderCreateCommand command);
}

View File

@ -1,5 +1,6 @@
package com.chint.domain.factoriy.order;
import com.chint.application.commands.OrderCreateCommand;
import com.chint.domain.aggregates.order.ApproveOrderNo;
import com.chint.domain.aggregates.order.Leg;
import com.chint.domain.aggregates.order.RouteOrder;
@ -7,6 +8,7 @@ import com.chint.domain.aggregates.user.User;
import com.chint.domain.factoriy.leg.RouteLegFactory;
import com.chint.domain.value_object.LegData;
import com.chint.domain.value_object.OrderSaveData;
import com.chint.domain.value_object.UserLoginParam;
import com.chint.infrastructure.util.BaseContext;
import com.chint.infrastructure.util.OrderNo;
import org.springframework.beans.factory.annotation.Autowired;
@ -38,4 +40,18 @@ public class RouteOrderFactory implements OrderFactory {
routeOrder.setLegItems(leglist);
return routeOrder;
}
@Override
public RouteOrder createOrder(OrderCreateCommand command) {
UserLoginParam loginParam = command.getLoginParam();
RouteOrder routeOrder = new RouteOrder();
routeOrder.setRouteOrderNo(OrderNo.generate());
//根据项目需求需要保存假审批订单号真审批订单号 创建的时候保存假审批订单号
routeOrder.setUserId(Long.valueOf(loginParam.getSfno()));
ApproveOrderNo approveOrderNo = new ApproveOrderNo();
approveOrderNo.setFakeOrderNo(loginParam.getBillcode());
routeOrder.setApproveOrderNo(approveOrderNo);
routeOrder.setBookingTime(LocalDateTime.now());
return routeOrder;
}
}

View File

@ -1,22 +1,36 @@
package com.chint.domain.service;
import com.chint.application.commands.OrderCreateCommand;
import com.chint.domain.aggregates.order.Leg;
import com.chint.domain.aggregates.order.RouteOrder;
import com.chint.domain.aggregates.user.User;
import com.chint.domain.factoriy.order.RouteOrderFactory;
import com.chint.domain.repository.LocationRepository;
import com.chint.domain.repository.RouteRepository;
import com.chint.domain.repository.UserRepository;
import com.chint.domain.value_object.UserLoginParam;
import com.chint.infrastructure.echo_framework.annotation.ListenTo;
import com.chint.infrastructure.util.BaseContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
@Service
public class OrderDomainService {
@Autowired
private RouteRepository routeRepository;
@Autowired
private UserRepository userRepository;
@Autowired
private LocationRepository locationRepository;
@Autowired
private RouteOrderFactory routeOrderFactory;
public RouteOrder saveOrder(RouteOrder routeOrder) {
return routeRepository.save(routeOrder);
}
@ -28,4 +42,16 @@ public class OrderDomainService {
});
return list;
}
@ListenTo(command = "OrderCreateCommand", order = 0)
public RouteOrder createOrder(OrderCreateCommand command) {
UserLoginParam loginParam = command.getLoginParam();
User byUserEmployeeNo = userRepository.findByUserEmployeeNo(Long.valueOf(loginParam.getSfno()));
return Optional.ofNullable(routeRepository.findByFakeOrderNo(loginParam.getBillcode())).orElseGet(() -> {
BaseContext.setCurrentUser(byUserEmployeeNo);
RouteOrder order = routeOrderFactory.createOrder(command);
this.saveOrder(order);
return order;
});
}
}

View File

@ -9,6 +9,7 @@ public interface LegEventService {
void prepareLeg(LegPrepareCommand command);
//审批事件要从bpm或其他平台接收到一个真实订单
void approveLeg(LegApprovalCommand command);
void syncLeg(LegSyncCommand command);
//下单事件
void orderLeg(LegOrderedCommand command);
//付款

View File

@ -1,10 +1,7 @@
package com.chint.domain.service.leg_event;
import com.chint.application.commands.*;
import com.chint.domain.aggregates.order.Leg;
import com.chint.domain.aggregates.order.LegEvent;
import com.chint.domain.aggregates.order.OrderDetail;
import com.chint.domain.aggregates.order.RouteOrder;
import com.chint.domain.aggregates.order.*;
import com.chint.domain.factoriy.leg_event.LegEventFactory;
import com.chint.domain.repository.LegRepository;
import com.chint.domain.repository.RouteRepository;
@ -12,7 +9,10 @@ import com.chint.domain.service.order_sync.SyncAdapter;
import com.chint.domain.value_object.ApproveLegData;
import com.chint.domain.value_object.OrderLegData;
import com.chint.domain.value_object.PayLegData;
import com.chint.domain.value_object.SyncLegData;
import com.chint.infrastructure.echo_framework.annotation.ListenTo;
import com.chint.infrastructure.echo_framework.annotation.TransitionTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -32,28 +32,29 @@ public class LegEventServiceImpl implements LegEventService {
@Autowired
private LegEventFactory legEventFactory;
@Transactional
@ListenTo(command = "LegPrepareCommand", order = 0)
@TransitionTo(command = "LegPrepareCommand", order = 0)
@Override
public void prepareLeg(LegPrepareCommand command) {
Leg leg = legRepository.findByLegId(Leg.of(command.getLegId()));
LegEvent legEvent = legEventFactory.creatLegEvent(command.getLegEventType());
leg.addEvent(legEvent);
legRepository.save(leg);
if (leg.getEventList().isEmpty()) {
LegEvent legEvent = legEventFactory.creatLegEvent(command.getLegEventType());
leg.addEvent(legEvent);
legRepository.save(leg);
}
}
//因为审批是针对整个订单的因此所有订单下属的行程节点触发审批事件
//出发审批提交事件 需要生成 差旅单 将差旅但提交到供应商
//根据command里面选择的数据来讲差旅但提交到不同的实现类当中
@Transactional
@ListenTo(command = "LegApprovalCommand", order = 0)
@Override
public void approveLeg(LegApprovalCommand command) {
ApproveLegData data = command.getData();
RouteOrder routeOrder = routeRepository.findByFakeOrderNo(data.getFakeOrderNo());
routeOrder.getApproveOrderNo().setActualOrderNo(data.getActualOrderNo());
String supplierName = data.getSupplierName();
syncAdapter.of(supplierName).syncSupplierOrder(routeOrder);
ApproveOrderNo approveOrderNo = routeOrder.getApproveOrderNo();
approveOrderNo.setActualOrderNo(data.getActualOrderNo());
approveOrderNo.setAccountCompany(data.getAccountCompany());
//这里order所有的leg触发approve事件
routeOrder.getLegItems().forEach(leg -> leg.getEventList().add(
@ -64,7 +65,25 @@ public class LegEventServiceImpl implements LegEventService {
routeRepository.save(routeOrder);
}
@Transactional
//这里需要获取同步类价格routeOrder同步到供应商
@ListenTo(command = "LegSyncCommand", order = 0)
@Override
public void syncLeg(LegSyncCommand command) {
SyncLegData data = command.getData();
RouteOrder routeOrder = routeRepository.queryById(command.getRoutOrderId());
String supplierName = data.getSupplierName();
//这里order所有的leg触发approve事件
routeOrder.getLegItems().forEach(leg -> leg.getEventList().add(
legEventFactory.creatLegEvent(command.getLegEventType())
));
syncAdapter.of(supplierName).syncSupplierOrder(routeOrder);
//保存routeOrder的状态
routeRepository.save(routeOrder);
}
@ListenTo(command = "LegOrderedCommand", order = 0)
@Override
public void orderLeg(LegOrderedCommand command) {
@ -79,9 +98,9 @@ public class LegEventServiceImpl implements LegEventService {
legRepository.save(leg);
}
@Transactional
@ListenTo(command = "LegPayedCommand", order = 0)
@Override
@ListenTo(command = "LegPayedCommand", order = 0)
public void payForLeg(LegPayedCommand command) {
PayLegData data = command.getData();
Leg leg = legRepository.findByLegId(Leg.of(command.getLegId()));
@ -94,9 +113,9 @@ public class LegEventServiceImpl implements LegEventService {
legRepository.save(leg);
}
@Transactional
@ListenTo(command = "LegFinishedCommand", order = 0)
@Override
@ListenTo(command = "LegFinishedCommand", order = 0)
public void finishLeg(LegFinishedCommand command) {
Leg leg = legRepository.findByLegId(Leg.of(command.getLegId()));
LegEvent legEvent = legEventFactory.creatLegEvent(command.getLegEventType());

View File

@ -1,10 +1,12 @@
package com.chint.domain.service.order_sync;
import com.chint.domain.aggregates.order.Location;
import com.chint.domain.aggregates.order.RouteOrder;
import org.springframework.stereotype.Component;
@Component
public class LYOrderSyncAdapter implements SupplierOrderSync {
@Override
public void syncSupplierOrder(RouteOrder order) {
System.out.println("开始同步同程订单");

View File

@ -4,7 +4,7 @@ import lombok.Data;
@Data
public class ApproveLegData {
private String supplierName;
private String actualOrderNo;
private String fakeOrderNo;
private String accountCompany;
}

View File

@ -0,0 +1,8 @@
package com.chint.domain.value_object;
import lombok.Data;
@Data
public class SyncLegData {
private String supplierName;
}

View File

@ -43,24 +43,28 @@ public class Constant {
public static final int ORDER_STATUS_PREPARE = 0;
public static final String ORDER_STATUS_PREPARE_NAME = "规划中";
public static final int ORDER_STATUS_APPROVAL = 1;
public static final String ORDER_STATUS_APPROVAL_NAME = "审批中";
public static final int ORDER_STATUS_ORDERED = 2;
public static final String ORDER_STATUS_APPROVAL_NAME = "提交审批";
public static final int ORDER_STATUS_NOT_ORDERED = 2;
public static final String ORDER_STATUS_NOT_ORDERED_NAME = "未下单";
public static final int ORDER_STATUS_ORDERED = 3;
public static final String ORDER_STATUS_ORDERED_NAME = "已下单";
public static final int ORDER_STATUS_PAYED = 3;
public static final int ORDER_STATUS_PAYED = 4;
public static final String ORDER_STATUS_PAYED_NAME = "已付款";
public static final int ORDER_STATUS_FINISH = 4;
public static final int ORDER_STATUS_FINISH = 5;
public static final String ORDER_STATUS_FINISH_NAME = "已结束";
// 规划节点状态
public static final int LEG_STATUS_PREPARE = 0;
public static final String LEG_STATUS_PREPARE_NAME = "规划中";
public static final int LEG_STATUS_APPROVAL = 1;
public static final String LEG_STATUS_APPROVAL_NAME = "审批中";
public static final int LEG_STATUS_ORDERED = 2;
public static final String LEG_STATUS_APPROVAL_NAME = "提交审批";
public static final int LEG_STATUS_NOT_ORDERED = 2;
public static final String LEG_STATUS_NOT_ORDERED_NAME = "未下单";
public static final int LEG_STATUS_ORDERED = 3;
public static final String LEG_STATUS_ORDERED_NAME = "已下单";
public static final int LEG_STATUS_PAYED = 3;
public static final int LEG_STATUS_PAYED = 4;
public static final String LEG_STATUS_PAYED_NAME = "已付款";
public static final int LEG_STATUS_FINISH = 4;
public static final int LEG_STATUS_FINISH = 5;
public static final String LEG_STATUS_FINISH_NAME = "已结束";
// 规划节点运输方式
@ -80,11 +84,13 @@ public class Constant {
public static final String LEG_EVENT_PREPARE_NAME = "初始事件";
public static final int LEG_EVENT_APPROVAL = 1;
public static final String LEG_EVENT_APPROVAL_NAME = "审批事件";
public static final int LEG_EVENT_ORDERED = 2;
public static final int LEG_EVENT_NOT_ORDERED = 2;
public static final String LEG_EVENT_NOT_ORDERED_NAME = "审批事件";
public static final int LEG_EVENT_ORDERED = 3;
public static final String LEG_EVENT_ORDERED_NAME = "下单事件";
public static final int LEG_EVENT_PAYED = 3;
public static final int LEG_EVENT_PAYED = 4;
public static final String LEG_EVENT_PAYED_NAME = "付款事件";
public static final int LEG_EVENT_FINISH = 4;
public static final int LEG_EVENT_FINISH = 5;
public static final String LEG_EVENT_FINISH_NAME = "结束事件";
// 金额

View File

@ -3,13 +3,11 @@ package com.chint.infrastructure.echo_framework.annotation;
import com.chint.infrastructure.echo_framework.command.Command;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.*;
@Target(ElementType.TYPE)
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface BindingCommand {
Class<? extends Command> commandClass();
}

View File

@ -1,13 +1,11 @@
package com.chint.infrastructure.echo_framework.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.*;
// ListenTo Annotation
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.FIELD})
@Documented
public @interface ListenTo {
String command();
long order();

View File

@ -1,13 +1,11 @@
package com.chint.infrastructure.echo_framework.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.*;
// TransitionTo Annotation
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.FIELD})
@Documented
public @interface TransitionTo {
String command();
long order();

View File

@ -1,6 +1,7 @@
package com.chint.infrastructure.echo_framework.manager;
import com.chint.domain.service.leg_event.LegEventService;
import com.chint.infrastructure.echo_framework.annotation.ListenTo;
import com.chint.infrastructure.echo_framework.annotation.TransitionTo;
import com.chint.infrastructure.echo_framework.command.Command;
@ -17,7 +18,9 @@ import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.support.TransactionTemplate;
import com.chint.domain.service.leg_event.LegEventServiceImpl;
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;
@ -85,7 +88,7 @@ public class EventManager implements ApplicationContextAware, BeanNameAware, Ini
List<ResultContainer> resultContainers = new ArrayList<>();
containers.forEach(container -> {
try {
Object result = container.getMethod().invoke(container.getBean(), command, args);
Object result = container.getMethod().invoke(container.getBean(), command);
if (result instanceof ResultContainer) {
resultContainers.add((ResultContainer) result);
}
@ -97,6 +100,7 @@ public class EventManager implements ApplicationContextAware, BeanNameAware, Ini
}
private static List<ResultContainer> processTransitionCommand(Command command) {
System.out.println(transitionMethods);
List<MethodContainer> containers = transitionMethods.getOrDefault(command.getCommandName(), Collections.emptyList());
List<ResultContainer> resultContainers = new ArrayList<>();
transactionTemplate.execute(transactionStatus -> {

View File

@ -13,4 +13,5 @@ public interface JdbcRouteRepository extends CrudRepository<RouteOrder, Long> {
RouteOrder findByRouteId(Long routeId);
RouteOrder findByApproveOrderNo_FakeOrderNo(String approveOrderNo_fakeOrderNo);
}

View File

@ -8,7 +8,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/pubilc/CTrip")
@RequestMapping("/public/CTrip")
public class CTripNoteController {
@PostMapping("/event")

View File

@ -1,6 +1,7 @@
package com.chint.interfaces.rest.user;
import com.chint.dc.api.DataCenterResult;
import com.chint.dc.api.dto.DataCenterOption;
import com.chint.dc.api.service.DataCenterService;