【update】高德企业订单创建、修改等业务链路完善

This commit is contained in:
nixj 2024-05-06 16:35:24 +08:00
parent 266889852b
commit df11789f6c
4 changed files with 290 additions and 12 deletions

View File

@ -1,20 +1,120 @@
package com.chint.domain.factoriy.order_detail;
import com.chint.domain.aggregates.order.*;
import lombok.Data;
import com.chint.domain.exceptions.NotFoundException;
import com.chint.domain.repository.OrderDetailRepository;
import com.chint.domain.repository.RouteRepository;
import com.chint.interfaces.rest.amap.dto.detail.OrderDetailResponse;
import com.chint.interfaces.rest.amap.request.OrderDetailRequest;
import com.chint.interfaces.rest.ctrip.dto.search.car.Address;
import com.chint.interfaces.rest.ctrip.dto.search.car.CarQuickOrderInfoEntity;
import com.chint.interfaces.rest.ctrip.dto.search.car.OrderFee;
import com.chint.interfaces.rest.ctrip.dto.search.car.Vehicle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
import static com.chint.infrastructure.constant.BelongSystemConstant.TRAVAL_SYS_TYPE_CTRIP;
import static com.chint.infrastructure.constant.CommonMessageConstant.NOT_FOUND;
import static com.chint.infrastructure.constant.FSSCConstant.*;
@Component
public class AmapOrderExtensionFactoryImpl implements OrderExtensionFactory{
@Autowired
private OrderDetailRequest orderDetailRequest;
@Autowired
private OrderDetailRepository orderDetailRepository;
@Autowired
private RouteRepository routeRepository;
@Autowired
private OrderDetailFactory orderDetailFactory;
@Override
public CarOrderDetail createCarOrderDetail(Object carOrderDetailData) {
return null;
OrderDetailResponse.Data data = (OrderDetailResponse.Data) carOrderDetailData;
//订单详情查询
OrderDetailResponse response=orderDetailRequest.queryOrderDetail(data.getAmapOrderId());
if (!response.getCode().equals(1)){
return null;
}
String orderNo=response.getData().getAmapOrderId();
OrderDetail orderDetail = orderDetailRepository.findByOrderNo(orderNo)
.orElseThrow(() -> new NotFoundException(NOT_FOUND));
RouteOrder routeOrder = routeRepository.queryById(orderDetail.getRouteId());
CarOrderDetail carOrderDetail = orderDetailFactory.buildCarWithRouteOrderAndOrderDetail(routeOrder, orderDetail);
//这里要更新用车的状态
OrderEvent lastEvent = orderDetail.getLastEvent();
if (lastEvent != null) {
carOrderDetail.setOrderStatus(lastEvent.mapToCarOrderDetailStatus());
} else {
carOrderDetail.setOrderStatus(FSSC_CAR_STATUS_SUCCESS);
}
//根据状态2来判断该订单已经被取消,和总退款费用判断是否退款
if (data.getShowStatus() == 2) {
carOrderDetail.setOrderStatus(FSSC_ORDER_STATUS_CANCEL);
Integer totalRefundamount=data.getTotalEnterpriseRefundAmount()+data.getTotalPersonRefundAmount();
if (totalRefundamount>0) {
carOrderDetail.setOrderStatus(FSSC_CAR_STATUS_REFUND);
}
}
carOrderDetail.setTrvaleSysType(TRAVAL_SYS_TYPE_CTRIP);
if(carOrderDetail.getOrderNo() == null || carOrderDetail.getDetailId() == null){
carOrderDetail.setOrderNo(orderNo);
carOrderDetail.setDetailId(orderNo);
}
return carOrderDetail;
}
@Override
public CarOrderDetail updateCarOrderDetailData(CarOrderDetail carOrderDetail, Object carOrderDetailData) {
return null;
OrderDetailResponse.Data data = (OrderDetailResponse.Data) carOrderDetailData;
if (data!=null){
carOrderDetail.setUserName(data.getPassengerName());
carOrderDetail.setUserCode(data.getUserId());
carOrderDetail.setPhone(data.getPassengerPhone());
carOrderDetail.setBOOK_ORG_STRUCT_1(data.getDepartmentName());
carOrderDetail.setCreateTime(data.getRequestTime());
carOrderDetail.setOrderAmount(String.valueOf(data.getEnterpriseAmount()+data.getPersonAmount()));
carOrderDetail.setCompanyPaymentAmount(String.valueOf(data.getEnterpriseAmount()));
carOrderDetail.setPersonalPaymentAmount(String.valueOf(data.getPersonAmount()));
if (data.getPersonAmount()==0&&data.getEnterpriseAmount()>0) {
carOrderDetail.setPaymentType("0");
} else if(data.getPersonAmount()>0&&data.getEnterpriseAmount()==0){
carOrderDetail.setPaymentType("1");
}else {
carOrderDetail.setPaymentType("2");
}
//这里判断用车成功的加入服务开始时间和结束时间失败的话使用订单的创建时间
if (carOrderDetail.getOrderStatus().equals(FSSC_CAR_STATUS_SUCCESS)) {
carOrderDetail.setStartTime(data.getGetOnTime());
carOrderDetail.setArriveTime(data.getGetOffTime());
} else {
carOrderDetail.setStartTime(carOrderDetail.getCreateTime());
carOrderDetail.setArriveTime(carOrderDetail.getCreateTime());
}
carOrderDetail.setMileage(data.getMileage());
carOrderDetail.setRunTime(data.getDuration());
carOrderDetail.setFromStationName(data.getStartName());
carOrderDetail.setToStationName(data.getEndName());
carOrderDetail.setFromCity(data.getStartCity());
carOrderDetail.setToCity(data.getEndCity());
carOrderDetail.setCarModel(data.getCarType());
}
return carOrderDetail;
}
@Override

View File

@ -0,0 +1,146 @@
package com.chint.domain.service.supplier;
import com.chint.domain.aggregates.order.Location;
import com.chint.domain.exceptions.NotFoundException;
import com.chint.domain.repository.LocationRepository;
import com.chint.domain.value_object.OrderLegData;
import com.chint.domain.value_object.SupplierCallbackData;
import com.chint.domain.value_object.enums.CurrencyType;
import com.chint.infrastructure.constant.CommonMessageConstant;
import com.chint.infrastructure.constant.LegConstant;
import com.chint.infrastructure.constant.OrderConstant;
import com.chint.infrastructure.constant.SupplierNameConstant;
import com.chint.interfaces.rest.amap.dto.detail.OrderDetailResponse;
import com.chint.interfaces.rest.amap.request.OrderDetailRequest;
import com.chint.interfaces.rest.ctrip.dto.search.ItineraryEntity;
import com.chint.interfaces.rest.ctrip.dto.search.SearchOrderResponse;
import com.chint.interfaces.rest.ctrip.dto.search.car.CarBasicInfo;
import com.chint.interfaces.rest.ctrip.dto.search.car.CarQuickOrderInfoEntity;
import com.chint.interfaces.rest.ctrip.dto.search.car.OrderProduct;
import com.chint.interfaces.rest.ctrip.dto.search.flight.FlightInfo;
import com.chint.interfaces.rest.ctrip.dto.search.flight.FlightOrderInfoEntity;
import com.chint.interfaces.rest.ctrip.dto.search.hotel.HotelOrderInfoEntity;
import com.chint.interfaces.rest.ctrip.dto.search.train.TrainOrderInfoEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Optional;
import static com.chint.infrastructure.constant.LegConstant.LEG_TYPE_TAXI;
import static com.chint.infrastructure.constant.SupplierNameConstant.SUPPLIER_L_Y;
/**
* 高德订单处理
* @Authornxj
* @Date2024/4/30 14:01
*/
@Component
public class AmapOrderDataAdapter implements OrderDataAdapter{
@Autowired
private LocationRepository locationRepository;
@Autowired
private OrderDetailRequest orderDetailRequest;
@Override
public Optional<OrderLegData> adapt(SupplierCallbackData supplierData) {
OrderDetailResponse data=(OrderDetailResponse) supplierData.getData();
OrderDetailResponse response=orderDetailRequest.queryOrderDetail(data.getData().getAmapOrderId());
if (!response.getCode().equals(1)){
return Optional.empty();
}else {
OrderDetailResponse.Data result=response.getData();
return Optional.of(
OrderLegData.builder()
.productType(LEG_TYPE_TAXI)
.outOrderNo(result.getAmapOrderId())
.price(String.valueOf(result.getEnterpriseAmount()+response.getData().getPersonAmount()))
.supplierName(supplierData.getSupplierName())
.currencyCode(CurrencyType.RENMINBI.getCode())
//没有返回差旅申请单号
// .selfOrderNo(response.getTravelApplyNo())
.orderStatus(supplierData.getSelfOrderStatus())
.carOrderDetailData(response)
.orderTime(result.getRequestTime())
.startTime(result.getGetOnTime())
.endTime(result.getGetOffTime())
.orderStatus(supplierData.getSelfOrderStatus())
.originOrderStatus(supplierData.getOutOrderStatus())
.destinationName(result.getEndName())
.supplierName(SUPPLIER_L_Y)
.build()
);
}
}
private OrderLegData.Builder findSingleElementList(ItineraryEntity itineraryEntity,
OrderLegData.Builder builder) {
// 处理租车订单
List<CarQuickOrderInfoEntity> carOrderInfoList = itineraryEntity.getCarQuickOrderInfoList();
if (carOrderInfoList != null && carOrderInfoList.size() == 1) {
CarQuickOrderInfoEntity carOrderInfo = carOrderInfoList.get(0);
OrderProduct orderProduct = carOrderInfo.getOrderProduct();
CarBasicInfo carBasicInfo = carOrderInfo.getBasicInfo();
Long departCityId = Long.valueOf(orderProduct.getDepartAddress().getCityId());
Location departCityName = locationRepository.findByCityIdAndLevelThree(departCityId);
if(departCityName == null){
departCityName = locationRepository.findByCityIdAndLevelFour(departCityId);
}
Long arriveCityId = Long.valueOf(orderProduct.getArriveAddress().getCityId());
Location arriveCityName = locationRepository.findByCityIdAndLevelThree(arriveCityId);
if(arriveCityName == null){
arriveCityName = locationRepository.findByCityIdAndLevelFour(arriveCityId);
}
return builder.productType(LegConstant.LEG_TYPE_TAXI)
.carOrderDetailData(carOrderInfo)
.currencyCode(CurrencyType.RENMINBI.getCode())
.orderTime(carBasicInfo.getCreateTime())
.startTime(orderProduct.getServiceBeginTime())
.endTime(orderProduct.getServiceEndTime())
.originId(departCityName.getLocationId())
.destinationId(arriveCityName.getLocationId())
.price(String.valueOf(carBasicInfo.getOrderAmount()))
.selfOrderNo(carBasicInfo.getJouneryID())
.outOrderNo(String.valueOf(carBasicInfo.getOrderId()))
.orderStatus(translateCarOrderStatus(carBasicInfo.getOrderStatus()))
.originOrderStatus(carBasicInfo.getOrderStatus());
}
// 如果没有找到任何只含一个元素的列表返回null
return null;
}
private Location getLocationId(String cityName, Long cityId) {
Location byName = locationRepository.findByCityIdAndLevelThree(cityId);
if (byName == null) {
List<Location> listByCityName = locationRepository.findListByCityName(cityName);
if (listByCityName != null && !listByCityName.isEmpty()) {
byName = listByCityName.get(0);
}
}
return byName;
}
private Integer translateCarOrderStatus(String carOrderStatus) {
return switch (carOrderStatus) {
case "CreateOrder" -> OrderConstant.ORDER_EVENT_PREPARE; //已下单
case "WaitReply" -> OrderConstant.ORDER_EVENT_ORDERED; //等待应答
case "WaitService" -> OrderConstant.ORDER_EVENT_ORDERED; //等待接驾
case "DriverArrived" -> OrderConstant.ORDER_EVENT_ORDERED; //司机就位
case "InService" -> OrderConstant.ORDER_EVENT_ORDERED; //正在服务
case "EndService" -> OrderConstant.ORDER_EVENT_PAYED; //行程结束
case "Canceling" -> OrderConstant.ORDER_EVENT_CANCEL; //取消中
case "Canceled" -> OrderConstant.ORDER_EVENT_CANCEL; //已取消
case "Successful" -> OrderConstant.ORDER_EVENT_CANCEL; //已成交
default -> throw new NotFoundException(CommonMessageConstant.NOT_FOUND);
};
}
}

View File

@ -15,11 +15,15 @@ public class OrderDataAdapterSelector {
@Autowired
private LYOrderDataAdapter lyOrderDataAdapter;
@Autowired
private AmapOrderDataAdapter amapOrderDataAdapter;
public OrderDataAdapter of(String supplierName) {
// 当找不到匹配的适配器时抛出一个异常
return switch (supplierName) {
case SupplierNameConstant.SUPPLIER_C_TRIP -> cTripOrderDataAdapter;
case SupplierNameConstant.SUPPLIER_L_Y -> lyOrderDataAdapter;
case SupplierNameConstant.SUPPLIER_AMAP -> amapOrderDataAdapter;
default -> throw new NotFoundException(CommonMessageConstant.NOT_FOUND);
};
}

View File

@ -1,6 +1,9 @@
package com.chint;
import com.chint.domain.aggregates.user.User;
import com.chint.domain.service.supplier.SupplierService;
import com.chint.domain.value_object.SupplierCallbackData;
import com.chint.infrastructure.util.BaseContext;
import com.chint.interfaces.rest.amap.AmapLocationRequest;
import com.chint.interfaces.rest.amap.AmapLoginRequest;
import com.chint.interfaces.rest.amap.AmapUserRequest;
@ -15,6 +18,8 @@ import com.chint.interfaces.rest.amap.request.SettleBillRequest;
import com.chint.interfaces.rest.amap.request.TakeCarRequest;
import com.chint.interfaces.rest.amap.request.TokenRequest;
import com.chint.interfaces.rest.base.dto.H5LoginResponse;
import com.chint.interfaces.rest.ctrip.CTripOrderSearchRequest;
import com.chint.interfaces.rest.ctrip.dto.search.SearchOrderResponse;
import com.google.gson.Gson;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
@ -22,6 +27,8 @@ import org.springframework.boot.test.context.SpringBootTest;
import java.util.List;
import static com.chint.infrastructure.constant.SupplierNameConstant.SUPPLIER_AMAP;
@SpringBootTest
public class AmapTest {
@ -53,6 +60,36 @@ public class AmapTest {
System.out.println(gson.toJson(orderDetailResponse));
}
@Autowired
private CTripOrderSearchRequest orderSearchRequest;
@Autowired
private SupplierService supplierService;
/**
* 处理订单
*/
@Test
void searchAndHandlerData() {
BaseContext.setCurrentUser(user);
SupplierCallbackData supplierCallbackData =
SupplierCallbackData.of(SUPPLIER_AMAP);
OrderDetailResponse response = orderDetailRequest.queryOrderDetail("40920084001340019626730137");
supplierCallbackData.data(response);
supplierCallbackData.setSelfOrderStatus(1);
supplierService.handleSupplierCallback(supplierCallbackData);
}
/**
* 订单查询
*/
@Test
public void queryorderDetail() {
OrderDetailResponse orderDetailResponse = orderDetailRequest.queryOrderDetail("40920084001340019626730137");
System.out.println("orderDetailResponse = " + orderDetailResponse);
}
/**
* 完单数据查询
*/
@ -107,15 +144,6 @@ public class AmapTest {
System.out.println("token = " + token);
}
/**
* 订单查询
*/
// @Test
public void queryorderDetail() {
OrderDetailResponse orderDetailResponse = orderDetailRequest.queryOrderDetail("123456");
System.out.println("orderDetailResponse = " + orderDetailResponse);
}
@Autowired
private TakeCarRequest takeCarRequest;