增加 部分接口缺少事务注解

This commit is contained in:
lulz1 2024-02-06 16:16:49 +08:00
parent f82a5d6800
commit 4fe1eb411b
4 changed files with 136 additions and 73 deletions

View File

@ -0,0 +1,126 @@
package com.chint.domain.service.leg_event;
import com.chint.application.commands.*;
import com.chint.domain.aggregates.order.*;
import com.chint.domain.exceptions.CommandException;
import com.chint.domain.factoriy.leg_event.LegEventFactory;
import com.chint.domain.repository.LegRepository;
import com.chint.domain.repository.RouteRepository;
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import static com.chint.infrastructure.constant.Constant.ORDER_STATUS_APPROVAL;
import static com.chint.infrastructure.constant.Constant.ORDER_STATUS_PREPARE;
@Service
public class LegEventHandler implements LegEventService{
@Autowired
private SyncAdapter syncAdapter;
@Autowired
private RouteRepository routeRepository;
@Autowired
private LegRepository legRepository;
@Autowired
private LegEventFactory legEventFactory;
@Transactional
@Override
public void prepareLeg(LegPrepareCommand command) {
Leg leg = legRepository.findByLegId(Leg.of(command.getLegId()));
if (leg.getEventList().isEmpty()) {
LegEvent legEvent = legEventFactory.creatLegEvent(command.getLegEventType());
leg.addEvent(legEvent);
legRepository.save(leg);
}
}
@Transactional
@Override
public void approveLeg(LegApprovalCommand command) {
ApproveLegData data = command.getData();
RouteOrder routeOrder = routeRepository.findByFakeOrderNo(data.getFakeOrderNo());
if (routeOrder.getOrderStatus().equals(ORDER_STATUS_PREPARE)) {
ApproveOrderNo approveOrderNo = routeOrder.getApproveOrderNo();
approveOrderNo.setActualOrderNo(data.getActualOrderNo());
approveOrderNo.setAccountCompany(data.getAccountCompany());
//这里order所有的leg触发approve事件
routeOrder.getLegItems().forEach(leg -> leg.getEventList().add(
legEventFactory.creatLegEvent(command.getLegEventType())
));
//保存routeOrder的状态
routeRepository.save(routeOrder);
} else {
throw new CommandException("订单未初始化");
}
}
@Transactional
@Override
public void syncLeg(LegSyncCommand command) {
SyncLegData data = command.getData();
RouteOrder routeOrder = routeRepository.queryById(data.getRouteId()).reloadStatus();
if (routeOrder.getOrderStatus().equals(ORDER_STATUS_APPROVAL)) {
String supplierName = data.getSupplierName();
routeOrder.setSupplierName(supplierName);
//这里order所有的leg触发approve事件
routeOrder.getLegItems().forEach(leg -> leg.getEventList().add(
legEventFactory.creatLegEvent(command.getLegEventType())
));
//保存routeOrder的状态
routeRepository.save(routeOrder);
syncAdapter.of(supplierName).syncSupplierOrder(routeOrder.reloadStatus());
} else {
throw new CommandException("订单未提交审批");
}
}
@Transactional
@Override
public void orderLeg(LegOrderedCommand command) {
OrderLegData data = command.getData();
Leg leg = legRepository.findByLegId(Leg.of(command.getLegId()));
LegEvent legEvent = legEventFactory.creatLegEvent(command.getLegEventType());
OrderDetail orderDetail = new OrderDetail();
orderDetail.setAmount(data.getOrderNo());
orderDetail.setAmount(data.getAmount());
legEvent.setOrderDetail(orderDetail);
leg.addEvent(legEvent);
legRepository.save(leg);
}
@Transactional
@Override
public void payForLeg(LegPayedCommand command) {
PayLegData data = command.getData();
Leg leg = legRepository.findByLegId(Leg.of(command.getLegId()));
LegEvent legEvent = legEventFactory.creatLegEvent(command.getLegEventType());
OrderDetail orderDetail = new OrderDetail();
orderDetail.setAmount(data.getOrderNo());
orderDetail.setAmount(data.getAmount());
legEvent.setOrderDetail(orderDetail);
leg.addEvent(legEvent);
legRepository.save(leg);
}
@Transactional
@Override
public void finishLeg(LegFinishedCommand command) {
Leg leg = legRepository.findByLegId(Leg.of(command.getLegId()));
LegEvent legEvent = legEventFactory.creatLegEvent(command.getLegEventType());
leg.addEvent(legEvent);
legRepository.save(leg);
}
@Transactional
@Override
public void rejectLeg(LegRejectCommand command) {
}
}

View File

@ -15,6 +15,7 @@ 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;
import static com.chint.infrastructure.constant.Constant.ORDER_STATUS_APPROVAL;
import static com.chint.infrastructure.constant.Constant.ORDER_STATUS_PREPARE;
@ -23,27 +24,14 @@ import static com.chint.infrastructure.constant.Constant.ORDER_STATUS_PREPARE;
public class LegEventServiceImpl implements LegEventService {
@Autowired
private SyncAdapter syncAdapter;
private LegEventHandler legEventHandler;
@Autowired
private RouteRepository routeRepository;
@Autowired
private LegRepository legRepository;
@Autowired
private LegEventFactory legEventFactory;
@TransitionTo(command = "LegPrepareCommand", order = 0)
@Override
public void prepareLeg(LegPrepareCommand command) {
Leg leg = legRepository.findByLegId(Leg.of(command.getLegId()));
if (leg.getEventList().isEmpty()) {
LegEvent legEvent = legEventFactory.creatLegEvent(command.getLegEventType());
leg.addEvent(legEvent);
legRepository.save(leg);
}
legEventHandler.prepareLeg(command);
}
//因为审批是针对整个订单的因此所有订单下属的行程节点触发审批事件
@ -52,85 +40,34 @@ public class LegEventServiceImpl implements LegEventService {
@ListenTo(command = "LegApprovalCommand", order = 0)
@Override
public void approveLeg(LegApprovalCommand command) {
ApproveLegData data = command.getData();
RouteOrder routeOrder = routeRepository.findByFakeOrderNo(data.getFakeOrderNo());
if (routeOrder.getOrderStatus().equals(ORDER_STATUS_PREPARE)){
ApproveOrderNo approveOrderNo = routeOrder.getApproveOrderNo();
approveOrderNo.setActualOrderNo(data.getActualOrderNo());
approveOrderNo.setAccountCompany(data.getAccountCompany());
//这里order所有的leg触发approve事件
routeOrder.getLegItems().forEach(leg -> leg.getEventList().add(
legEventFactory.creatLegEvent(command.getLegEventType())
));
//保存routeOrder的状态
routeRepository.save(routeOrder);
} else {
throw new CommandException("订单未初始化");
}
legEventHandler.approveLeg(command);
}
//这里需要获取同步类价格routeOrder同步到供应商
@ListenTo(command = "LegSyncCommand", order = 0)
@Override
public void syncLeg(LegSyncCommand command) {
SyncLegData data = command.getData();
RouteOrder routeOrder = routeRepository.queryById(data.getRouteId()).reloadStatus();
if (routeOrder.getOrderStatus().equals(ORDER_STATUS_APPROVAL)) {
String supplierName = data.getSupplierName();
routeOrder.setSupplierName(supplierName);
//这里order所有的leg触发approve事件
routeOrder.getLegItems().forEach(leg -> leg.getEventList().add(
legEventFactory.creatLegEvent(command.getLegEventType())
));
//保存routeOrder的状态
routeRepository.save(routeOrder);
syncAdapter.of(supplierName).syncSupplierOrder(routeOrder.reloadStatus());
} else {
throw new CommandException("订单未提交审批");
legEventHandler.syncLeg(command);
}
}
//下单时间要求回传需要付款的金额以及生成对于的行程订单号如果没有行程订单号根据地点和时间进行匹配
@ListenTo(command = "LegOrderedCommand", order = 0)
@Override
public void orderLeg(LegOrderedCommand command) {
OrderLegData data = command.getData();
Leg leg = legRepository.findByLegId(Leg.of(command.getLegId()));
LegEvent legEvent = legEventFactory.creatLegEvent(command.getLegEventType());
OrderDetail orderDetail = new OrderDetail();
orderDetail.setAmount(data.getOrderNo());
orderDetail.setAmount(data.getAmount());
legEvent.setOrderDetail(orderDetail);
leg.addEvent(legEvent);
legRepository.save(leg);
legEventHandler.orderLeg(command);
}
@Override
@ListenTo(command = "LegPayedCommand", order = 0)
public void payForLeg(LegPayedCommand command) {
PayLegData data = command.getData();
Leg leg = legRepository.findByLegId(Leg.of(command.getLegId()));
LegEvent legEvent = legEventFactory.creatLegEvent(command.getLegEventType());
OrderDetail orderDetail = new OrderDetail();
orderDetail.setAmount(data.getOrderNo());
orderDetail.setAmount(data.getAmount());
legEvent.setOrderDetail(orderDetail);
leg.addEvent(legEvent);
legRepository.save(leg);
legEventHandler.payForLeg(command);
}
@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());
leg.addEvent(legEvent);
legRepository.save(leg);
}
@Override

View File

@ -3,7 +3,6 @@ package com.chint.infrastructure.repository;
import com.chint.domain.aggregates.location.CityEntity;
import com.chint.domain.repository.CityRepository;
import com.chint.infrastructure.repository.jdbc.JdbcCityRepository;
import com.chint.interfaces.rest.ctrip.dto.location.CTripCity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
@ -23,7 +22,7 @@ public class CityRepositoryImpl implements CityRepository {
@Override
public CityEntity findByCityName(String name) {
return null;
return jdbcCityRepository.findByCityName(name);
}
}

View File

@ -6,4 +6,5 @@ import org.springframework.stereotype.Repository;
@Repository
public interface JdbcCityRepository extends CrudRepository<CityEntity,Long> {
CityEntity findByCityName(String cityName);
}