Compare commits

...

5 Commits

Author SHA1 Message Date
lulz1 a7ba57499b 开发数据回推接口 2024-02-20 20:27:00 +08:00
lulz1 54dc2db42b 修复bug 2024-02-20 14:46:47 +08:00
lulz1 19775c580e 修复bug 2024-02-20 09:33:42 +08:00
lulz1 d771a5b068 修复bug 2024-02-20 09:28:07 +08:00
lulz1 7b67196eff 添加行程规划功能接口 2024-02-20 08:19:39 +08:00
56 changed files with 1135 additions and 183 deletions

View File

@ -0,0 +1,29 @@
package com.chint.application.commands;
import com.chint.infrastructure.echo_framework.command.Command;
import lombok.Data;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
@Data
public class OrderStatusChangeCommand extends Command {
private Long orderId;
private String orderNo;
private String outStatus;
private Integer orderEventType;
public OrderStatusChangeCommand eventType(Integer eventType) {
this.orderEventType = eventType;
return this;
}
public OrderStatusChangeCommand orderNo(String orderNo) {
this.orderNo = orderNo;
return this;
}
public OrderStatusChangeCommand outStatus(String outStatus) {
this.outStatus = outStatus;
return this;
}
}

View File

@ -0,0 +1,56 @@
package com.chint.application.dtos.response;
import cn.hutool.core.bean.BeanUtil;
import com.chint.domain.aggregates.order.Leg;
import com.chint.domain.aggregates.order.LegExtensionField;
import com.chint.domain.aggregates.order.OrderDetail;
import com.chint.domain.value_object.enums.CurrencyType;
import lombok.Data;
import org.springframework.data.annotation.Id;
import java.time.format.DateTimeFormatter;
import java.util.List;
@Data
public class LegRes {
@Id
private Long legId;
private String legNo;
private Integer legType;
private String startTime;
private String endTime;
private String estimateAmount;
private String createTime;
private LocationRes originLocation;
private LocationRes destinationLocation;
private String amount;
private String legTypeName;
private String legTypeEnName;
private Integer amountType;
private String amountTypeName;
private String amountTypeEnName;
private Integer legStatus;
private String legStatusName;
private CurrencyType currencyType;
private List<OrderDetail> orderDetails; //这个属性不做持久化保存 根据下单事件进行获取
public static LegRes copyFrom(Leg leg) {
LegRes legRes = BeanUtil.copyProperties(leg, LegRes.class);
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
legRes.startTime = dateTimeFormatter.format(leg.getStartTime());
legRes.endTime = dateTimeFormatter.format(leg.getEndTime());
legRes.createTime = dateTimeFormatter.format(leg.getCreateTime());
LegExtensionField legExtensionField = leg.getLegExtensionField();
if (legExtensionField != null) {
legRes.setAmountType(legExtensionField.getAmountType());
legRes.setAmountTypeName(legExtensionField.getAmountTypeName());
legRes.setAmountTypeEnName(legExtensionField.getAmountTypeEnName());
}
return legRes;
}
}

View File

@ -0,0 +1,17 @@
package com.chint.application.dtos.response;
import cn.hutool.core.bean.BeanUtil;
import com.chint.domain.aggregates.order.Location;
import lombok.Data;
import org.springframework.data.annotation.Id;
@Data
public class LocationRes {
@Id
private Long locationId;
private String locationName;
public static LocationRes copyFrom(Location location) {
return BeanUtil.copyProperties(location, LocationRes.class);
}
}

View File

@ -0,0 +1,30 @@
package com.chint.application.dtos.response;
import cn.hutool.core.bean.BeanUtil;
import com.chint.domain.aggregates.order.OrderDetail;
import com.chint.domain.value_object.enums.CurrencyType;
import lombok.Data;
import java.time.LocalDateTime;
@Data
public class OrderDetailRes {
private Long orderId; // 使用 order_id 作为主键
private String orderNo;
private String supplierName;
private String productName; // 产品名称
private Integer productType; // 商品类型
private Integer quantity; // 数量
private String price; // 价格
private CurrencyType currencyType; //货币类型
private Long destinationId;
private Long originId;
private LocalDateTime startTime;
private LocalDateTime endTime;
private LocalDateTime createTime;
private LocalDateTime updateTime;
private String orderStatus;
public static OrderDetailRes copyFrom(OrderDetail orderDetail){
return BeanUtil.copyProperties(orderDetail, OrderDetailRes.class);
}
}

View File

@ -0,0 +1,39 @@
package com.chint.application.dtos.response;
import com.chint.domain.aggregates.order.ApproveOrderNo;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.relational.core.mapping.Column;
import org.springframework.data.relational.core.mapping.Embedded;
import java.time.LocalDateTime;
@Data
public class RouteOrderPageRes {
@Id
@Column("route_id")
private Long routeId;
//差旅订单单号
private String routeOrderNo;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private LocalDateTime bookingTime;
private Long userId;
//审批订单号
@Embedded.Nullable
private ApproveOrderNo approveOrderNo;
//差旅订单总价值
private String amount;
private String estimateAmount;
private Integer orderStatus;
private String approvalStatus;
private String orderStatusName;
private String startTime;
private String endTime;
private String supplierName;
private String supplierCNName;
}

View File

@ -0,0 +1,48 @@
package com.chint.application.dtos.response;
import cn.hutool.core.bean.BeanUtil;
import com.chint.domain.aggregates.order.ApproveOrderNo;
import com.chint.domain.aggregates.order.RouteOrder;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.relational.core.mapping.Column;
import org.springframework.data.relational.core.mapping.Embedded;
import java.time.LocalDateTime;
import java.util.List;
@Data
public class RouteOrderRes {
@Id
@Column("route_id")
private Long routeId;
//差旅订单单号
private String routeOrderNo;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private LocalDateTime bookingTime;
private Long userId;
//审批订单号
@Embedded.Nullable
private ApproveOrderNo approveOrderNo;
//差旅订单总价值
private String amount;
private String estimateAmount;
private Integer orderStatus;
private String approvalStatus;
private String orderStatusName;
private String startTime;
private String endTime;
private String supplierName;
private String supplierCNName;
private List<LegRes> legResList;
private List<OrderDetailRes> orderDetailRes;
public static RouteOrderRes copyFrom(RouteOrder routeOrder) {
return BeanUtil.copyProperties(routeOrder, RouteOrderRes.class);
}
}

View File

@ -0,0 +1,24 @@
package com.chint.application.dtos.response;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient;
@Data
public class UserRes {
@Id
private Long userId;
private Long employeeNo;
private Integer employeeLevel;
private String name;
private String email;
private String gender;
private String phoneNumber;
private String password;
@Transient
private String rankCode;
@Transient
private String companyCode;
@Transient
private String workStatus;
}

View File

@ -89,9 +89,7 @@ public class OrderController {
@ApiOperation("审批通过行程规划单")
@PostMapping("/success")
public Result<String> approvalOrder(@RequestBody ApprovalLegData approvalLegData) {
orderApplicationService.reject(approvalLegData);
orderApplicationService.approvalSuccess(approvalLegData);
return Result.Success(SUCCESS);
}
}

View File

@ -1,6 +1,8 @@
package com.chint.application.out;
import cn.hutool.core.bean.BeanUtil;
import com.chint.application.dtos.LocationParam;
import com.chint.application.dtos.response.LocationRes;
import com.chint.domain.aggregates.order.Location;
import com.chint.domain.repository.LocationRepository;
import com.chint.domain.service.LocationDomainService;
@ -36,15 +38,21 @@ public class LocationController {
@ApiOperation("根据查询词查询地理信息")
@PostMapping("/query/word")
public Result<List<Location>> queryByFirstLetter(@RequestBody LocationParam locationParam) {
public Result<List<LocationRes>> queryByFirstLetter(@RequestBody LocationParam locationParam) {
String queryWord = locationParam.getQueryWord();
List<Location> locations = null;
List<LocationRes> locationRes = null;
if (StringCheck.isFirstCharacterAlphabetic(queryWord)) {
locations = locationDomainService.queryByFirstLetter(locationParam);
}
if(StringCheck.isFirstCharacterChinese(queryWord)){
if (StringCheck.isFirstCharacterChinese(queryWord)) {
locations = locationDomainService.queryByCityName(locationParam);
}
return Result.Success(SUCCESS, locations);
if (locations != null && !locations.isEmpty()) {
locationRes = locations
.stream()
.map(location -> BeanUtil.copyProperties(location, LocationRes.class)).toList();
}
return Result.Success(SUCCESS, locationRes);
}
}

View File

@ -1,6 +1,11 @@
package com.chint.application.out;
import cn.hutool.core.bean.BeanUtil;
import com.chint.application.dtos.response.LegRes;
import com.chint.application.dtos.response.OrderDetailRes;
import com.chint.application.dtos.response.RouteOrderPageRes;
import com.chint.application.dtos.response.RouteOrderRes;
import com.chint.application.dtos.trip.TripCallback;
import com.chint.application.queryies.OrderQuery;
import com.chint.domain.aggregates.order.RouteOrder;
@ -17,6 +22,8 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import static com.chint.infrastructure.constant.Constant.SUCCESS;
@RestController
@ -28,23 +35,40 @@ public class OrderOutController {
private OrderQuery orderQuery;
@ApiOperation("根据临时单号查询订单")
@ApiOperation("根据临时单号和系统编码查询订单")
@PostMapping("/query/billcode")
public Result<RouteOrder> queryOrderByBillCode(@RequestBody OrderQueryData queryData) {
return Result.Success(SUCCESS, orderQuery.queryByBillCode(queryData.getBillcode()).reloadStatus());
public Result<RouteOrder> queryOrderByBillCodeAndSysCode(@RequestBody OrderQueryData queryData) {
return Result.Success(SUCCESS, orderQuery.queryByBillCodeAndSysCode(queryData.getBillcode(), queryData.getSysCode())
.reloadStatus());
}
@ApiOperation("查询行程规划订单详情")
@PostMapping("/query")
public Result<RouteOrder> queryOrder(@RequestBody OrderQueryData queryData) {
return Result.Success(SUCCESS, orderQuery.queryById(queryData.getRouteId()).reloadStatus());
public Result<RouteOrderRes> queryOrder(@RequestBody OrderQueryData queryData) {
RouteOrder routeOrder = orderQuery.queryById(queryData.getRouteId()).reloadStatus();
RouteOrderRes routeOrderRes = RouteOrderRes.copyFrom(routeOrder);
List<LegRes> list = routeOrder.getLegItems().stream().map(LegRes::copyFrom).toList();
routeOrderRes.setLegResList(list);
List<OrderDetailRes> orderDetailResList = routeOrder
.getOrderDetails()
.stream()
.map(OrderDetailRes::copyFrom)
.toList();
routeOrderRes.setOrderDetailRes(orderDetailResList);
return Result.Success(SUCCESS, routeOrderRes);
}
@ApiOperation("分页查询行程规划订单")
@PostMapping("/pageQuery")
public Result<PageResult<RouteOrder>> pageQuery(@RequestBody OrderQueryData queryData) {
return Result.Success(SUCCESS, orderQuery.pageQuery(queryData));
public Result<PageResult<RouteOrderPageRes>> pageQuery(@RequestBody OrderQueryData queryData) {
PageResult<RouteOrder> routeOrderPageResult = orderQuery.pageQuery(queryData);
List<RouteOrderPageRes> routeOrderPageRes = routeOrderPageResult
.getRecords()
.stream()
.map(routeOrder -> BeanUtil.copyProperties(routeOrder, RouteOrderPageRes.class))
.toList();
return Result.Success(SUCCESS, new PageResult<>(routeOrderPageResult.getTotal(), routeOrderPageRes));
}
@ApiOperation("查询火车估算价格")

View File

@ -1,29 +1,25 @@
package com.chint.application.out;
import com.chint.domain.repository.UserRepository;
import cn.hutool.core.bean.BeanUtil;
import com.chint.application.dtos.response.UserRes;
import com.chint.domain.aggregates.user.User;
import com.chint.infrastructure.util.BaseContext;
import com.chint.infrastructure.util.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import static com.chint.infrastructure.constant.Constant.SUCCESS;
@RestController
@RequestMapping("/users")
public class UserController {
// @Autowired
// private final UserRepository userRepository;
//
//
//
// @ApiOperation("根据Id查询用户信息")
// @PostMapping("/query")
// public Result<UserVO> getUserById(@RequestBody long id) {
// UserVO user = userService.findById(id);
// if (user != null) {
// return new Result<UserVO>(SUCCESS, user);
// } else {
// return Result.error(FAILURE);
// }
// }
@ApiOperation("根据Id查询用户信息")
@PostMapping("/query")
public Result<UserRes> getUserByEmployeeNo() {
User currentUser = BaseContext.getCurrentUser();
return Result.Success(SUCCESS, BeanUtil.copyProperties(currentUser, UserRes.class));
}
}

View File

@ -41,6 +41,7 @@ public class OrderQuery {
@Autowired
private EstimatePrice estimatePrice;
public RouteOrder queryByOrderId(OrderQueryData queryData) {
return routeRepository.queryById(queryData.getRouteId()).reloadStatus();
}
@ -59,8 +60,8 @@ public class OrderQuery {
return routeOrder;
}
public RouteOrder queryByBillCode(String billCode) {
return routeRepository.findByFakeOrderNo(billCode);
public RouteOrder queryByBillCodeAndSysCode(String billCode, String sysCode) {
return routeRepository.findByFakeOrderNoAndSysCode(billCode, sysCode);
}
public TrainPriceData queryTrainPrice(PriceQueryData priceQueryData) {
@ -75,11 +76,14 @@ public class OrderQuery {
User currentUser = BaseContext.getCurrentUser();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
DateTimeFormatter simpleFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
RouteOrder routeOrder = routeRepository.queryById(queryData.getRouteId()).reloadStatus();
// RouteOrder routeOrder = routeRepository.findByFakeOrderNoAndSysCode(queryData.getBillcode(), queryData.getSysCode())
// .reloadStatus();
RouteOrder routeOrder = routeRepository.queryById(queryData.getRouteId())
.reloadStatus();
List<Location> locationList = new ArrayList<>();
List<Leg> legItems = routeOrder.getLegItems();
List<Leg> legItems =
orderDomainService.queryLocation(routeOrder.getLegItems());
legItems.forEach(leg -> {
if (!locationList.contains(leg.getOriginLocation())) {

View File

@ -71,8 +71,12 @@ public class OrderApplicationService {
public RouteOrder deleteLegToOrder(DeleteLegData deleteLegData) {
RouteOrder order = Optional.ofNullable(routeRepository.queryById(deleteLegData.getRouteId()))
.orElseThrow(() -> new NotFoundException(NOT_FOUND));
order.deleteLeg(deleteLegData.getLegNo());
return orderDomainService.saveOrder(order);
if (order.getOrderStatus().equals(ORDER_STATUS_PREPARE)) {
order.deleteLeg(deleteLegData.getLegNo());
return orderDomainService.saveOrder(order);
} else {
throw new OrderException(INVALID_REQUEST);
}
}
@Transactional
@ -114,7 +118,8 @@ public class OrderApplicationService {
}
@Transactional
public void approval(ApprovalLegData data) {
public void approvalSuccess(ApprovalLegData data) {
Command.of(OrderApprovalCommand.class).actualNo(data.getActualOrderNo()).sendToQueue();
}
}

View File

@ -12,7 +12,7 @@ import static com.chint.infrastructure.constant.Constant.*;
@Data
public class ApprovalEvent {
@Id
private Long approveEventId;
private Long approvalEventId;
@Column("route_id")
private Long routeId;

View File

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

View File

@ -6,6 +6,7 @@ import com.chint.domain.service.amount_estimate.EstimateAdapter;
import com.chint.domain.value_object.LegData;
import com.chint.domain.value_object.enums.CurrencyType;
import com.chint.infrastructure.util.BigDecimalCalculator;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
@ -33,12 +34,13 @@ public class Leg {
private Integer legType;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private LocalDateTime startTime;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private LocalDateTime endTime;
private String estimateAmount;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private LocalDateTime createTime;
@Column("origin_id")
@ -56,6 +58,8 @@ public class Leg {
@Transient
private String legTypeName;
@Transient
private String legTypeEnName;
@Transient
private Integer legStatus;
@Transient
private String legStatusName;
@ -67,6 +71,8 @@ public class Leg {
@MappedCollection(idColumn = "leg_id", keyColumn = "leg_key")
private List<LegEvent> eventList;
@MappedCollection(idColumn = "leg_id")
private LegExtensionField legExtensionField;
public Leg(Long legId) {
this.legId = legId;
@ -117,6 +123,7 @@ public class Leg {
this.legStatusName = translateLegStatus(this.legStatus);
if (legType != null) {
this.legTypeName = translateLegType(this.legType);
this.legTypeEnName = translateLegTypeEn(this.legType);
}
return this;
}
@ -159,6 +166,17 @@ public class Leg {
};
}
public String translateLegTypeEn(int type) {
return switch (type) {
case LEG_TYPE_TRAIN -> LEG_TYPE_TRAIN_EN_NAME;
case LEG_TYPE_AIRPLANE -> LEG_TYPE_AIRPLANE_EN_NAME;
case LEG_TYPE_HOTEL -> LEG_TYPE_HOTEL_EN_NAME;
case LEG_TYPE_TAXI -> LEG_TYPE_TAXI_EN_NAME;
case LEG_TYPE_OTHER -> LEG_TYPE_OTHER_EN_NAME;
default -> "未知类型";
};
}
public Leg addEvent(LegEvent event) {
if (eventList == null) {
eventList = new ArrayList<>();
@ -201,4 +219,13 @@ public class Leg {
.map(LegEvent::getEventType)
.max(Integer::compareTo);
}
// private Leg timeFormatter() {
// DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
// String string = this.startTime.toString();
// this.startTime = LocalDateTime.parse(dateTimeFormatter.format(this.startTime), dateTimeFormatter);
// this.endTime = LocalDateTime.parse(this.endTime.toString(), dateTimeFormatter);
// this.createTime = LocalDateTime.parse(this.createTime.toString(), dateTimeFormatter);
// return this;
// }
}

View File

@ -0,0 +1,54 @@
package com.chint.domain.aggregates.order;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient;
import org.springframework.data.relational.core.mapping.Table;
import static com.chint.infrastructure.constant.Constant.*;
@Data
@Table("leg_extension_field")
public class LegExtensionField {
@Id
private Long id;
private Long legId;
private Integer amountType;
@Transient
private String amountTypeName;
@Transient
private String amountTypeEnName;
private String expenseExplanation;
private String originDescription;
private String destinationDescription;
private String estimatedAmount;
public LegExtensionField reloadStatus() {
this.amountTypeName = translateLegOtherAmountTypeToChineseName(this.amountType);
this.amountTypeEnName = translateLegOtherAmountTypeToEnglishName(this.amountType);
return this;
}
public String translateLegOtherAmountTypeToChineseName(int type) {
return switch (type) {
case LEG_OTHER_AMOUNT_TYPE_OTHER -> LEG_OTHER_AMOUNT_OTHER_NAME;
case LEG_OTHER_AMOUNT_TYPE_SHIP -> LEG_OTHER_AMOUNT_SHIP_NAME;
case LEG_OTHER_AMOUNT_TYPE_SELF_TRAFFIC -> LEG_OTHER_AMOUNT_SELF_TRAFFIC_NAME;
case LEG_OTHER_AMOUNT_TYPE_CITY_TRAFFIC -> LEG_OTHER_AMOUNT_CITY_TRAFFIC_NAME;
case LEG_OTHER_AMOUNT_TYPE_BUS -> LEG_OTHER_AMOUNT_BUS_NAME;
default -> "未知类型";
};
}
public String translateLegOtherAmountTypeToEnglishName(int type) {
return switch (type) {
case LEG_OTHER_AMOUNT_TYPE_OTHER -> LEG_OTHER_AMOUNT_OTHER_EN_NAME;
case LEG_OTHER_AMOUNT_TYPE_SHIP -> LEG_OTHER_AMOUNT_SHIP_EN_NAME;
case LEG_OTHER_AMOUNT_TYPE_SELF_TRAFFIC -> LEG_OTHER_AMOUNT_SELF_TRAFFIC_EN_NAME;
case LEG_OTHER_AMOUNT_TYPE_CITY_TRAFFIC -> LEG_OTHER_AMOUNT_CITY_TRAFFIC_EN_NAME;
case LEG_OTHER_AMOUNT_TYPE_BUS -> LEG_OTHER_AMOUNT_BUS_EN_NAME;
default -> "Unknown Type";
};
}
}

View File

@ -15,13 +15,15 @@ import static com.chint.infrastructure.constant.Constant.*;
public class OrderEvent {
@Id
private Long orderEventId;
@Column("route_id")
private Long routeId;
@Column("order_id")
private Long orderId;
private Integer eventType;
@Transient
private String eventName;
private String outStatusName;
private LocalDateTime happenTime;
public String translateOrderEvent(int event) {
@ -41,9 +43,16 @@ public class OrderEvent {
return this;
}
public OrderEvent of(Integer eventType) {
public static OrderEvent of(Integer eventType) {
OrderEvent orderEvent = new OrderEvent();
orderEvent.setEventType(eventType);
return orderEvent;
}
public static OrderEvent of(Integer eventType, String outStatusName) {
OrderEvent orderEvent = new OrderEvent();
orderEvent.setEventType(eventType);
orderEvent.setOutStatusName(outStatusName);
return orderEvent;
}
}

View File

@ -36,10 +36,11 @@ public class RouteOrder extends BaseEntity {
//差旅订单单号
private String routeOrderNo;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private LocalDateTime bookingTime;
private Long userId;
private String supplierName;
//审批订单号
@Embedded.Nullable
private ApproveOrderNo approveOrderNo;
@ -58,8 +59,9 @@ public class RouteOrder extends BaseEntity {
private String startTime;
@Transient
private String endTime;
@Transient
private String supplierCNName;
private String supplierName;
@MappedCollection(idColumn = "route_id", keyColumn = "route_order_key")
private List<Leg> legItems;
@ -119,7 +121,7 @@ public class RouteOrder extends BaseEntity {
}
public RouteOrder addOrderDetail(OrderDetail orderDetail) {
if(this.orderDetails == null){
if (this.orderDetails == null) {
this.orderDetails = new ArrayList<>();
}
this.orderDetails.add(orderDetail);
@ -127,17 +129,17 @@ public class RouteOrder extends BaseEntity {
}
public RouteOrder addApprovalEvent(ApprovalEvent approvalEvent) {
if(this.approveEvents == null){
if (this.approveEvents == null) {
this.approveEvents = new ArrayList<>();
}
this.approveEvents.add(approvalEvent);
return this;
}
private RouteOrder reloadApprovalStatus(){
private RouteOrder reloadApprovalStatus() {
if (this.approveEvents != null && !this.approveEvents.isEmpty()) {
this.approveEvents.stream()
.max(Comparator.comparingLong(ApprovalEvent::getApproveEventId))
.max(Comparator.comparingLong(ApprovalEvent::getApprovalEventId))
.ifPresent(event -> this.setApprovalStatus(event.reloadStatus().getEventName()));
} else {
this.setApprovalStatus(APPROVAL_EVENT_PREPARE_NAME);
@ -161,7 +163,22 @@ public class RouteOrder extends BaseEntity {
.orElse(KEEP_TWO_DECIMAL_ZERO);
this.updateStatus();
this.orderStatusName = translateOrderStatus(this.orderStatus);
//根据节点时间更新订单时间
reloadTime();
//更新供应商中文名称
if (this.supplierName != null) {
this.supplierCNName = translateOrderSupplierName(this.supplierName);
}
if (this.approveEvents != null && !this.approveEvents.isEmpty()) {
this.approvalStatus = this.approveEvents.stream()
.max(Comparator.comparingLong(ApprovalEvent::getApprovalEventId))
.get()
.reloadStatus()
.getEventName();
}
return this;
}
@ -213,33 +230,71 @@ public class RouteOrder extends BaseEntity {
}
public void updateStatus() {
if (allItemsInStatus(4)) {
this.orderStatus = 4;
} else if (allItemsInStatus(3)) {
this.orderStatus = 3;
} else if (allItemsInStatus(2)) {
this.orderStatus = 2;
} else if (allItemsInStatus(1)) {
this.orderStatus = 1;
} else if (allItemsInStatus(-1)) {
this.orderStatus = -1;
} else {
this.orderStatus = 0; // 或其他适当的默认状态
}
this.orderStatus = this.legItems
.stream()
.map(Leg::getLegStatus)
.min(Integer::compareTo)
.orElse(0);
// if (allItemsInStatus(-1)) {
// this.orderStatus = -1;
// } else if (allItemsInStatus(4)) {
// this.orderStatus = 4;
// } else if (allItemsInStatus(3)) {
// this.orderStatus = 3;
// } else if (anyItemInStatus(4) && allOtherItemsInStatus(3)) {
// this.orderStatus = 3;
// } else if (allItemsInStatus(2)) {
// this.orderStatus = 2;
// } else if (anyItemInStatus(3) && allOtherItemsInStatus(2)) {
// this.orderStatus = 2;
// } else if (anyItemInStatus(2) && allOtherItemsInStatus(1)) {
// this.orderStatus = 1;
// } else if (allItemsInStatus(1)) {
// this.orderStatus = 1;
// } else {
// this.orderStatus = 0; // 或其他适当的默认状态
// }
}
private boolean allItemsInStatus(int targetStatus) {
if (this.getLegItems().isEmpty()) {
if (this.legItems.isEmpty()) {
return false;
}
for (Leg item : this.legItems) {
if (item.getLegStatus() < targetStatus) {
if (item.getLegStatus() != targetStatus) {
return false;
}
}
return true;
}
private boolean anyItemInStatus(int targetStatus) {
for (Leg item : this.legItems) {
if (item.getLegStatus() == targetStatus) {
return true;
}
}
return false;
}
private boolean allOtherItemsInStatus(int targetStatus) {
boolean foundHigherStatus = false;
for (Leg item : this.legItems) {
if (item.getLegStatus() > targetStatus) {
if (foundHigherStatus) {
// 如果已经找到一个更高状态而且又遇到另一个则不符合所有其他项目都处于目标状态的条件
return false;
}
foundHigherStatus = true; // 标记已找到一个更高的状态
} else if (item.getLegStatus() < targetStatus) {
return false; // 如果找到状态低于目标状态的项目则直接返回false
}
}
return true;
}
private String translateOrderStatus(int status) {
return switch (status) {
case ORDER_STATUS_PREPARE -> ORDER_STATUS_PREPARE_NAME;
@ -266,4 +321,12 @@ public class RouteOrder extends BaseEntity {
}
return this;
}
private String translateOrderSupplierName(String supplierName) {
return switch (supplierName) {
case SUPPLIER_L_Y -> SUPPLIER_L_Y_CN_NAME;
case SUPPLIER_C_TRIP -> SUPPLIER_C_TRIP_CN_NAME;
default -> "未知供应商";
};
}
}

View File

@ -2,6 +2,7 @@ package com.chint.domain.aggregates.user;
import com.auth0.jwt.interfaces.Claim;
import com.auth0.jwt.interfaces.DecodedJWT;
import com.chint.domain.aggregates.base.BaseEntity;
import com.chint.domain.value_object.UserLoginParam;
import com.google.gson.Gson;
import lombok.AllArgsConstructor;

View File

@ -1,8 +1,11 @@
package com.chint.domain.factoriy.leg;
import cn.hutool.core.bean.BeanUtil;
import com.chint.domain.aggregates.order.Leg;
import com.chint.domain.aggregates.order.LegExtensionField;
import com.chint.domain.factoriy.location.LocationFactory;
import com.chint.domain.value_object.LegData;
import com.chint.domain.value_object.LegExtensionFieldData;
import com.chint.infrastructure.util.OrderNo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@ -13,6 +16,8 @@ import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import static com.chint.infrastructure.constant.Constant.LEG_TYPE_OTHER;
@Component
public class RouteLegFactory implements LegFactory {
@ -35,14 +40,31 @@ public class RouteLegFactory implements LegFactory {
Leg leg = new Leg();
leg.setLegNo(OrderNo.generateLegNo());
leg.setLegType(data.legType);
if (data.legType.equals(LEG_TYPE_OTHER)) {
LegExtensionField legExtensionField = getLegExtensionField(data);
leg.setLegExtensionField(legExtensionField);
}
leg.setStartTime(LocalDateTime.parse(data.getStartTime(), formatter));
leg.setEndTime(LocalDateTime.parse(data.getEndTime(), formatter));
if (data.getEndTime() != null) {
leg.setEndTime(LocalDateTime.parse(data.getEndTime(), formatter));
} else {
leg.setEndTime(LocalDateTime.parse(data.getStartTime(), formatter));
}
leg.setOriginId(data.getOriginId());
leg.setDestinationId(data.getDestinationId());
if (data.getDestinationId() != null) {
leg.setDestinationId(data.getDestinationId());
} else {
leg.setDestinationId(data.getOriginId());
}
leg.setCreateTime(LocalDateTime.now());
if (data.getLegId() != null) {
leg.setLegId(data.getLegId());
}
return leg;
}
private static LegExtensionField getLegExtensionField(LegData data) {
LegExtensionFieldData legExtensionFieldData = data.getLegExtensionFieldData();
return BeanUtil.copyProperties(legExtensionFieldData, LegExtensionField.class);
}
}

View File

@ -50,6 +50,7 @@ public class RouteOrderFactory implements OrderFactory {
//根据项目需求需要保存假审批订单号真审批订单号 创建的时候保存假审批订单号
routeOrder.setUserId(Long.valueOf(loginParam.getSfno()));
ApproveOrderNo approveOrderNo = new ApproveOrderNo();
approveOrderNo.setSysCode(loginParam.getSyscode());
approveOrderNo.setFakeOrderNo(loginParam.getBillcode());
routeOrder.setApproveOrderNo(approveOrderNo);
routeOrder.setBookingTime(LocalDateTime.now());

View File

@ -7,5 +7,5 @@ import com.chint.domain.value_object.OrderLegData;
public interface OrderDetailFactory {
OrderDetail create(OrderLegData orderLegData);
OrderEvent createEvent(Integer eventType);
OrderEvent createEvent(Integer eventType,String outStatus);
}

View File

@ -5,15 +5,19 @@ import com.chint.domain.aggregates.order.OrderEvent;
import com.chint.domain.value_object.OrderLegData;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
@Component
public class OrderDetailFactoryImpl implements OrderDetailFactory {
@Override
public OrderDetail create(OrderLegData orderLegData) {
return OrderDetail.of(orderLegData.getOrderNo(), orderLegData.getSupplierName());
return OrderDetail.of(orderLegData.getOutOrderNo(), orderLegData.getSupplierName());
}
@Override
public OrderEvent createEvent(Integer eventType) {
return null;
public OrderEvent createEvent(Integer eventType, String outStatus) {
OrderEvent orderEvent = OrderEvent.of(eventType, outStatus);
orderEvent.setHappenTime(LocalDateTime.now());
return orderEvent;
}
}

View File

@ -8,4 +8,6 @@ public interface OrderDetailRepository {
OrderDetail findById(Long orderDetailId);
Optional<OrderDetail> findByOrderNo(String orderNo);
OrderDetail save(OrderDetail orderDetail);
}

View File

@ -7,10 +7,15 @@ import com.chint.infrastructure.util.PageResult;
public interface RouteRepository {
RouteOrder queryById(Long orderId);
RouteOrder findByFakeOrderNo(String fakeOrderNo);
void deleteById(Long orderId);
RouteOrder findByFakeOrderNoAndSysCode(String fakeOrderNo, String sysCode);
RouteOrder findByActualOrderNo(String actualOrderNo);
RouteOrder findByOrderNo(String orderNo);
RouteOrder save(RouteOrder routeOrder);
PageResult<RouteOrder> pageQuery(OrderQueryData orderQueryData);

View File

@ -2,12 +2,16 @@ package com.chint.domain.service;
import com.chint.application.commands.OrderApprovalCommand;
import com.chint.application.commands.OrderCreateCommand;
import com.chint.application.commands.OrderStatusChangeCommand;
import com.chint.domain.aggregates.order.ApprovalEvent;
import com.chint.domain.aggregates.order.Leg;
import com.chint.domain.aggregates.order.OrderEvent;
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.factoriy.order_detail.OrderDetailFactory;
import com.chint.domain.repository.LocationRepository;
import com.chint.domain.repository.OrderDetailRepository;
import com.chint.domain.repository.RouteRepository;
import com.chint.domain.repository.UserRepository;
import com.chint.domain.value_object.UserLoginParam;
@ -35,6 +39,12 @@ public class OrderDomainService {
@Autowired
private RouteOrderFactory routeOrderFactory;
@Autowired
private OrderDetailFactory orderDetailFactory;
@Autowired
private OrderDetailRepository orderDetailRepository;
public RouteOrder saveOrder(RouteOrder routeOrder) {
return routeRepository.save(routeOrder);
}
@ -51,14 +61,16 @@ public class OrderDomainService {
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.createRoute(command);
ApprovalEvent approvalEvent = routeOrderFactory.createApprovalEvent(APPROVAL_EVENT_PREPARE);
order.addApprovalEvent(approvalEvent);
this.saveOrder(order);
return order;
});
return Optional.ofNullable(routeRepository
.findByFakeOrderNoAndSysCode(loginParam.getBillcode(), loginParam.getSyscode()))
.orElseGet(() -> {
BaseContext.setCurrentUser(byUserEmployeeNo);
RouteOrder order = routeOrderFactory.createRoute(command);
ApprovalEvent approvalEvent = routeOrderFactory.createApprovalEvent(APPROVAL_EVENT_PREPARE);
order.addApprovalEvent(approvalEvent);
this.saveOrder(order);
return order;
});
}
@ListenTo(command = "OrderApprovalCommand", order = 0)
@ -70,4 +82,13 @@ public class OrderDomainService {
this.saveOrder(route);
});
}
@ListenTo(command = "OrderStatusChangeCommand", order = 0)
public void orderDetailStatusChange(OrderStatusChangeCommand command) {
orderDetailRepository.findByOrderNo(command.getOrderNo()).ifPresent(orderDetail -> {
OrderEvent event = orderDetailFactory.createEvent(command.getOrderEventType(),command.getOutStatus());
orderDetail.addOrderEvent(event);
orderDetailRepository.save(orderDetail);
});
}
}

View File

@ -2,6 +2,7 @@ package com.chint.domain.service.leg_event;
import com.chint.application.commands.*;
import com.chint.domain.aggregates.order.*;
import com.chint.domain.aggregates.user.User;
import com.chint.domain.exceptions.CommandException;
import com.chint.domain.factoriy.leg_event.LegEventFactory;
import com.chint.domain.factoriy.order.RouteOrderFactory;
@ -9,11 +10,13 @@ import com.chint.domain.factoriy.order_detail.OrderDetailFactory;
import com.chint.domain.repository.LegRepository;
import com.chint.domain.repository.OrderDetailRepository;
import com.chint.domain.repository.RouteRepository;
import com.chint.domain.repository.UserRepository;
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.util.BaseContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -46,6 +49,9 @@ public class LegEventHandler implements LegEventService {
@Autowired
private OrderDetailRepository orderDetailRepository;
@Autowired
private UserRepository userRepository;
@Transactional
@Override
public void prepareLeg(LegPrepareCommand command) {
@ -61,7 +67,7 @@ public class LegEventHandler implements LegEventService {
@Override
public void approveLeg(LegApprovalCommand command) {
ApproveLegData data = command.getData();
RouteOrder routeOrder = routeRepository.findByFakeOrderNo(data.getFakeOrderNo()).reloadStatus();
RouteOrder routeOrder = routeRepository.findByFakeOrderNoAndSysCode(data.getFakeOrderNo(), data.getSysCode()).reloadStatus();
if (routeOrder.getOrderStatus().equals(ORDER_STATUS_PREPARE)) {
ApproveOrderNo approveOrderNo = routeOrder.getApproveOrderNo();
@ -88,7 +94,7 @@ public class LegEventHandler implements LegEventService {
if (routeOrder.getOrderStatus().equals(ORDER_STATUS_APPROVAL)) {
String supplierName = data.getSupplierName();
routeOrder.setSupplierName(supplierName);
//这里order所有的leg触发approve事件
//这里order所有的leg触发sync事件
routeOrder.getLegItems().forEach(leg -> leg.getEventList().add(
legEventFactory.creatLegEvent(command.getLegEventType())
));
@ -106,25 +112,31 @@ public class LegEventHandler implements LegEventService {
@Override
public void routeUpdateOrder(RouteUpdateOrderCommand command) {
OrderLegData data = command.getData();
String actualOrderNo = data.getActualOrderNo();
RouteOrder routeOrder = routeRepository.findByActualOrderNo(actualOrderNo);
String orderNo = data.getSelfOrderNo();
RouteOrder routeOrder = routeRepository.findByOrderNo(orderNo);
//获取行程规划单创建者作为该订单
Long employeeNo = routeOrder.getUserId();
User byUserEmployeeNo = userRepository.findByUserEmployeeNo(employeeNo);
BaseContext.setCurrentUser(byUserEmployeeNo);
//首先查询到行程规划订单 从routOrder当中查询是否以及存在该订单
Optional<OrderDetail> byOrderNo = routeOrder.getOrderDetails()
.stream()
.filter(orderDetail -> orderDetail.getOrderNo().equals(data.getOrderNo()))
.filter(orderDetail -> orderDetail.getOrderNo().equals(data.getOutOrderNo()))
.findFirst();
if (byOrderNo.isPresent()) {
//如果订单以及存在了对订单的状态进行更新
OrderEvent event = orderDetailFactory.createEvent(data.getOrderStatus());
OrderDetail orderDetail = byOrderNo.get();
orderDetail.addOrderEvent(event);
} else {
if (byOrderNo.isEmpty())
// {
// //如果订单以及存在了对订单的状态进行更新
// OrderEvent event = orderDetailFactory.createEvent(data.getOrderStatus(), data.getOriginOrderStatus());
// OrderDetail orderDetail = byOrderNo.get();
// orderDetail.addOrderEvent(event);
// } else
{
//否则创建新的订单添加到routeOrder
OrderDetail orderDetail = orderDetailFactory.create(data)
.price(data.getPrice()).productType(data.getProductType());
//为订单添加订单已下单事件
OrderEvent orderEvent = orderDetailFactory.createEvent(ORDER_EVENT_PREPARE);
orderDetail.addOrderEvent(orderEvent);
// OrderEvent orderEvent = orderDetailFactory.createEvent(ORDER_EVENT_PREPARE, data.getOriginOrderStatus());
// orderDetail.addOrderEvent(orderEvent);
routeOrder.addOrderDetail(orderDetail);
//结合外部订单信息筛选最合适的leg节点 触发下单事件
routeOrder.getLegItems()
@ -184,10 +196,19 @@ public class LegEventHandler implements LegEventService {
@Transactional
@Override
public void rejectLeg(LegRejectCommand command) {
RouteOrder routeOrder = routeRepository.findByActualOrderNo(command.getData().getActualOrderNo());
RouteOrder routeOrder = routeRepository.findByActualOrderNo(command.getData().getActualOrderNo()).reloadStatus();
if (routeOrder.getOrderStatus() >= ORDER_STATUS_NOT_ORDERED) {
//这里查看routeOrder的状态 如果是已经同步过的订单 需要取消同步到供应商的订单
if (!syncAdapter.of(routeOrder.getSupplierName()).cancelSyncSupplierOrder(routeOrder)) {
throw new CommandException("订单取消失败");
}
}
LegEvent legEvent = legEventFactory.creatLegEvent(command.getLegEventType());
routeOrder.getLegItems().forEach(leg -> leg.addEvent(legEvent));
//为每一个行程节点添加审批拒绝时间 routeOrder 也添加审批拒绝时间
//为每一个行程节点添加审批拒绝时间 routeOrder 也添加审批拒绝事件
ApprovalEvent approvalEvent = routeOrderFactory.createApprovalEvent(APPROVAL_EVENT_FAIL);
routeOrder.addApprovalEvent(approvalEvent);
routeRepository.save(routeOrder);
}
}

View File

@ -42,15 +42,26 @@ public class CTripOrderSyncAdapter implements SupplierOrderSync {
@Override
public boolean syncSupplierOrder(RouteOrder order) {
System.out.println("开始同步协程订单");
ApprovalRequest approvalRequestParam = getApprovalRequestParam(order);
ApprovalResult approval = approvalRequest.approval(approvalRequestParam);
return approval.getSetApprovalResult().getStatus().getSuccess();
}
@Override
public boolean cancelSyncSupplierOrder(RouteOrder order) {
System.out.println("开始取消协程订单");
ApprovalRequest approvalRequestParam = getApprovalRequestParam(order);
ApprovalResult approval = approvalRequest.cancelApprovalOrder(approvalRequestParam);
return approval.getSetApprovalResult().getStatus().getSuccess();
}
private ApprovalRequest getApprovalRequestParam(RouteOrder order) {
User currentUser = BaseContext.getCurrentUser();
ApproveOrderNo approveOrderNo = order.getApproveOrderNo();
RankInfo rankInfo = RankInfo.of(currentUser.getRankCode());
ApprovalRequest approvalRequestParam = ApprovalRequest
.buildApproval(order.getRouteOrderNo(), String.valueOf(currentUser.getEmployeeNo()), rankInfo);
Map<Integer, List<Leg>> collect = orderDomainService.queryLocation(order.getLegItems())
.stream().collect(Collectors.groupingBy(Leg::getLegType));
ApprovalRequest approvalRequestParam = ApprovalRequest
.buildApproval(approveOrderNo.getActualOrderNo(), String.valueOf(currentUser.getEmployeeNo()), rankInfo);
collect.forEach((k, v) -> {
switch (k) {
case LEG_TYPE_TRAIN -> approvalRequestParam.withTrain(generateTrainList(v));
@ -59,9 +70,7 @@ public class CTripOrderSyncAdapter implements SupplierOrderSync {
case LEG_TYPE_TAXI -> approvalRequestParam.withQuickCar(generateCarList(v));
}
});
ApprovalResult approval = approvalRequest.approval(approvalRequestParam);
return approval.getSetApprovalResult().getStatus().getSuccess();
return approvalRequestParam;
}
private List<HotelEndorsementDetail> generateHotelList(List<Leg> legs) {

View File

@ -80,6 +80,11 @@ public class LYOrderSyncAdapter implements SupplierOrderSync {
return Boolean.parseBoolean(success);
}
@Override
public boolean cancelSyncSupplierOrder(RouteOrder order) {
return false;
}
//同程Leg集合解析
private List<AOSItem> getAosItems(RouteOrder order) {
List<AOSItem> aosItems = new ArrayList<>();

View File

@ -6,4 +6,6 @@ import com.chint.domain.factoriy.order.RouteOrderFactory;
public interface SupplierOrderSync {
boolean syncSupplierOrder(RouteOrder order);
boolean cancelSyncSupplierOrder(RouteOrder order);
}

View File

@ -28,9 +28,9 @@ public class CTripOrderDataAdapter implements OrderDataAdapter {
ItineraryEntity itineraryEntity = itineraryList.get(0);
OrderLegData.Builder builder = OrderLegData.builder()
.actualOrderNo(itineraryEntity.getJourneyNO())
.supplierName(SUPPLIER_C_TRIP);
String journeyNo = itineraryEntity.getHotelOrderInfoList().get(0).getJourneyNo();
System.out.println(journeyNo);
OrderLegData.Builder elementList = findSingleElementList(itineraryEntity, builder);
if (elementList == null) {
return Optional.empty();
@ -46,7 +46,10 @@ public class CTripOrderDataAdapter implements OrderDataAdapter {
if (hotelOrderInfoList != null && hotelOrderInfoList.size() == 1) {
HotelOrderInfoEntity hotelOrderInfoEntity = hotelOrderInfoList.get(0);
return builder.productType(LEG_TYPE_HOTEL)
.orderNo(hotelOrderInfoEntity.getOrderId())
.selfOrderNo(hotelOrderInfoEntity.getJourneyNo())
.outOrderNo(hotelOrderInfoEntity.getOrderID())
.orderStatus(translateHotelOrderStatus(hotelOrderInfoEntity.getOrderDetailStatus()))
.originOrderStatus(hotelOrderInfoEntity.getOrderDetailStatus())
.price(hotelOrderInfoEntity.getAmount());
}
// 处理航班订单
@ -54,7 +57,10 @@ public class CTripOrderDataAdapter implements OrderDataAdapter {
if (flightOrderInfoList != null && flightOrderInfoList.size() == 1) {
FlightOrderInfoEntity flightOrderInfo = flightOrderInfoList.get(0);
return builder.productType(LEG_TYPE_AIRPLANE)
.orderNo(flightOrderInfo.getBasicInfo().getOrderID())
.selfOrderNo(flightOrderInfo.getBasicInfo().getJourneyID())
.outOrderNo(flightOrderInfo.getBasicInfo().getOrderID())
.orderStatus(translateFlightOrderStatus(flightOrderInfo.getBasicInfo().getOrderStatus()))
.originOrderStatus(flightOrderInfo.getBasicInfo().getOrderStatus())
.price(flightOrderInfo.getFlightOrderFeeDetailList().get(0).getPayCurrency());
}
@ -63,7 +69,9 @@ public class CTripOrderDataAdapter implements OrderDataAdapter {
if (trainOrderInfoList != null && trainOrderInfoList.size() == 1) {
TrainOrderInfoEntity trainOrderInfo = trainOrderInfoList.get(0);
return builder.productType(LEG_TYPE_TRAIN)
.orderNo(trainOrderInfo.getBasicInfo().getOrderID())
.outOrderNo(trainOrderInfo.getBasicInfo().getOrderID())
.orderStatus(translateTrainOrderStatus(trainOrderInfo.getBasicInfo().getOrderStatus()))
.originOrderStatus(trainOrderInfo.getBasicInfo().getOrderStatus())
.price(String.valueOf(trainOrderInfo.getOrderPaymentList().get(0).getFeeAmount()));
}
@ -72,7 +80,9 @@ public class CTripOrderDataAdapter implements OrderDataAdapter {
if (carOrderInfoList != null && carOrderInfoList.size() == 1) {
CarOrderInfoEntity carOrderInfo = carOrderInfoList.get(0);
return builder.productType(LEG_TYPE_TAXI)
.orderNo(String.valueOf(carOrderInfo.getBasicInfo().getOrderId()))
.outOrderNo(String.valueOf(carOrderInfo.getBasicInfo().getOrderId()))
.orderStatus(translateCarOrderStatus(carOrderInfo.getBasicInfo().getOrderStatus()))
.originOrderStatus(carOrderInfo.getBasicInfo().getOrderStatus())
.price(String.valueOf(carOrderInfo.getPaymentInfoList().get(0).getAmount()));
}
@ -98,7 +108,7 @@ public class CTripOrderDataAdapter implements OrderDataAdapter {
};
}
private Integer translateHotelOrderStatus(String hotelOrderStatus){
private Integer translateHotelOrderStatus(String hotelOrderStatus) {
return switch (hotelOrderStatus) {
case "Submitted" -> ORDER_EVENT_PREPARE; //已提交
case "Wait" -> ORDER_EVENT_ORDERED; //确认中
@ -111,7 +121,7 @@ public class CTripOrderDataAdapter implements OrderDataAdapter {
};
}
private Integer translateCarOrderStatus(String carOrderStatus){
private Integer translateCarOrderStatus(String carOrderStatus) {
return switch (carOrderStatus) {
case "CreateOrder" -> ORDER_EVENT_PREPARE; //已下单
case "WaitReply" -> ORDER_EVENT_ORDERED; //等待应答
@ -126,7 +136,7 @@ public class CTripOrderDataAdapter implements OrderDataAdapter {
};
}
private Integer translateFlightOrderStatus(String flightOrderStatus){
private Integer translateFlightOrderStatus(String flightOrderStatus) {
return switch (flightOrderStatus) {
case "W" -> ORDER_EVENT_PREPARE; //未处理
case "P" -> ORDER_EVENT_ORDERED; //处理中

View File

@ -17,6 +17,7 @@ public class LYOrderDataAdapter implements OrderDataAdapter {
public Optional<OrderLegData> adapt(SupplierCallbackData supplierData) {
return Optional.empty();
}
@ -25,7 +26,7 @@ public class LYOrderDataAdapter implements OrderDataAdapter {
return Optional.of(
OrderLegData.builder()
.productType(LEG_TYPE_TRAIN)
.orderNo(data.getOrderNo())
.outOrderNo(data.getOrderNo())
.price(String.valueOf( data.getTotalAmount()))
.actualOrderNo(data.getOutOrderNo())
.supplierName(SUPPLIER_L_Y)

View File

@ -17,7 +17,9 @@ public class SupplierServiceImpl implements SupplierService {
orderDataAdapterSelector
.of(callbackData.getSupplierName())
.adapt(callbackData)
.ifPresent(data ->
Command.of(RouteUpdateOrderCommand.class).data(data).sendToQueue());
.ifPresent(data -> {
System.out.println(data);
Command.of(RouteUpdateOrderCommand.class).data(data).sendToQueue();
});
}
}

View File

@ -7,4 +7,5 @@ public class ApproveLegData {
private String actualOrderNo;
private String fakeOrderNo;
private String accountCompany;
private String sysCode;
}

View File

@ -1,5 +1,6 @@
package com.chint.domain.value_object;
import com.chint.domain.aggregates.order.LegExtensionField;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
@ -20,4 +21,6 @@ public class LegData {
public final Long originId;
public final Long destinationId;
private LegExtensionFieldData legExtensionFieldData;
}

View File

@ -0,0 +1,19 @@
package com.chint.domain.value_object;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.data.annotation.Transient;
@Data
public class LegExtensionFieldData {
@ApiModelProperty("其他费用类型")
private Integer amountType;
@ApiModelProperty("费用说明")
private String expenseExplanation;
@ApiModelProperty("出发地详细")
private String originDescription;
@ApiModelProperty("目的地详细")
private String destinationDescription;
@ApiModelProperty("预估金额")
private String estimatedAmount;
}

View File

@ -9,7 +9,8 @@ import lombok.NoArgsConstructor;
@Data
public class OrderLegData {
private String actualOrderNo;
private String orderNo;
private String selfOrderNo;
private String outOrderNo;
private String supplierName;
private Integer productType;
private String price;
@ -18,10 +19,13 @@ public class OrderLegData {
private OrderLegData(Builder builder) {
this.actualOrderNo = builder.actualOrderNo;
this.orderNo = builder.orderNo;
this.outOrderNo = builder.outOrderNo;
this.selfOrderNo = builder.selfOrderNo;
this.supplierName = builder.supplierName;
this.productType = builder.productType;
this.price = builder.price;
this.orderStatus = builder.orderStatus;
this.originOrderStatus = builder.originOrderStatus;
}
public static Builder builder() {
@ -31,7 +35,8 @@ public class OrderLegData {
// Builder class
public static class Builder {
private String actualOrderNo;
private String orderNo;
private String selfOrderNo;
private String outOrderNo;
private String supplierName;
private Integer productType;
private String price;
@ -46,8 +51,13 @@ public class OrderLegData {
return this;
}
public Builder orderNo(String orderNo) {
this.orderNo = orderNo;
public Builder selfOrderNo(String selfOrderNo) {
this.selfOrderNo = selfOrderNo;
return this;
}
public Builder outOrderNo(String outOrderNo) {
this.outOrderNo = outOrderNo;
return this;
}

View File

@ -10,4 +10,6 @@ public class OrderQueryData extends BaseQuery {
private Long routeId;
private String billcode;
private String sysCode;
}

View File

@ -7,6 +7,8 @@ public class SupplierCallbackData {
private String supplierName;
private String employeeNo;
private Integer productType; //用于区分同程搜索数据
private Integer selfOrderStatus;
private String outOrderStatus;
private Object data;
public static SupplierCallbackData of(String supplierName, String employeeNo) {
@ -16,6 +18,12 @@ public class SupplierCallbackData {
return supplierCallbackData;
}
public static SupplierCallbackData of(String supplierName) {
SupplierCallbackData supplierCallbackData = new SupplierCallbackData();
supplierCallbackData.setSupplierName(supplierName);
return supplierCallbackData;
}
public SupplierCallbackData data(Object data) {
this.data = data;
return this;

View File

@ -13,7 +13,7 @@ public class UserLoginParam {
private String sfno;
private String syscpde;
private String syscode;
private String billcode;

View File

@ -1,7 +1,5 @@
package com.chint.infrastructure.constant;
import org.springframework.beans.factory.annotation.Value;
public class Constant {
// 通用消息
// 通用消息
@ -76,14 +74,39 @@ public class Constant {
// 规划节点运输方式
public static final int LEG_TYPE_TRAIN = 0;
public static final String LEG_TYPE_TRAIN_NAME = "火车";
public static final String LEG_TYPE_TRAIN_EN_NAME = "Train";
public static final int LEG_TYPE_AIRPLANE = 1;
public static final String LEG_TYPE_AIRPLANE_NAME = "飞机";
public static final String LEG_TYPE_AIRPLANE_EN_NAME = "Flight";
public static final int LEG_TYPE_HOTEL = 2;
public static final String LEG_TYPE_HOTEL_NAME = "酒店";
public static final String LEG_TYPE_HOTEL_EN_NAME = "Hotel";
public static final int LEG_TYPE_TAXI = 3;
public static final String LEG_TYPE_TAXI_NAME = "出租车";
public static final String LEG_TYPE_TAXI_EN_NAME = "Traffic";
public static final int LEG_TYPE_OTHER = 4;
public static final String LEG_TYPE_OTHER_NAME = "其他";
public static final String LEG_TYPE_OTHER_EN_NAME = "Other";
public static final int LEG_OTHER_AMOUNT_TYPE_OTHER = 0;
public static final String LEG_OTHER_AMOUNT_OTHER_NAME = "其他费用";
public static final String LEG_OTHER_AMOUNT_OTHER_EN_NAME = "Other";
public static final int LEG_OTHER_AMOUNT_TYPE_SHIP = 1;
public static final String LEG_OTHER_AMOUNT_SHIP_NAME = "轮船";
public static final String LEG_OTHER_AMOUNT_SHIP_EN_NAME = "Ship";
public static final int LEG_OTHER_AMOUNT_TYPE_SELF_TRAFFIC = 2;
public static final String LEG_OTHER_AMOUNT_SELF_TRAFFIC_NAME = "自驾车";
public static final String LEG_OTHER_AMOUNT_SELF_TRAFFIC_EN_NAME = "Traffic";
public static final int LEG_OTHER_AMOUNT_TYPE_CITY_TRAFFIC = 3;
public static final String LEG_OTHER_AMOUNT_CITY_TRAFFIC_NAME = "市内交通";
public static final String LEG_OTHER_AMOUNT_CITY_TRAFFIC_EN_NAME = "Traffic";
public static final int LEG_OTHER_AMOUNT_TYPE_BUS = 4;
public static final String LEG_OTHER_AMOUNT_BUS_NAME = "长途汽车";
public static final String LEG_OTHER_AMOUNT_BUS_EN_NAME = "CoachBus";
// 规划节点事件
public static final int LEG_EVENT_PREPARE = 0;
@ -155,7 +178,9 @@ public class Constant {
public static final String TRAVEL_RANK_BASE_URL = "http://10.10.14.178:8080";
public static final String TRAVEL_RANK_PATH = "/fssc/queryBill/queryTravelLevelByRank";
public static final String SUPPLIER_C_TRIP = "CTrip";
public static final String SUPPLIER_C_TRIP_CN_NAME = "携程";
public static final String SUPPLIER_L_Y = "LY";
public static final String SUPPLIER_L_Y_CN_NAME = "同程";
// 携程
public static final String C_TRIP_BASE_URL = "https://ct.ctrip.com";

View File

@ -25,4 +25,9 @@ public class OrderDetailRepositoryImpl implements OrderDetailRepository {
public Optional<OrderDetail> findByOrderNo(String orderNo) {
return Optional.ofNullable(orderDetailRepository.findByOrderNo(orderNo));
}
@Override
public OrderDetail save(OrderDetail orderDetail) {
return orderDetailRepository.save(orderDetail);
}
}

View File

@ -26,10 +26,15 @@ public class RouteRepositoryImpl implements RouteRepository {
return jdbcRouteRepository.findByRouteId(orderId);
}
@Override
public void deleteById(Long orderId) {
jdbcRouteRepository.deleteById(orderId);
}
@Override
public RouteOrder findByFakeOrderNo(String fakeOrderNo) {
return jdbcRouteRepository.findByApproveOrderNo_FakeOrderNo(fakeOrderNo);
public RouteOrder findByFakeOrderNoAndSysCode(String fakeOrderNo, String sysCode) {
return jdbcRouteRepository.findByApproveOrderNo_FakeOrderNoAndApproveOrderNo_SysCode(fakeOrderNo, sysCode);
}
@Override
@ -37,6 +42,11 @@ public class RouteRepositoryImpl implements RouteRepository {
return jdbcRouteRepository.findByApproveOrderNo_ActualOrderNo(actualOrderNo);
}
@Override
public RouteOrder findByOrderNo(String orderNo) {
return jdbcRouteRepository.findByRouteOrderNo(orderNo);
}
@Override
public RouteOrder save(RouteOrder routeOrder) {
return jdbcRouteRepository.save(routeOrder);

View File

@ -12,8 +12,10 @@ public interface JdbcRouteRepository extends CrudRepository<RouteOrder, Long> {
RouteOrder findByRouteId(Long routeId);
RouteOrder findByApproveOrderNo_FakeOrderNo(String approveOrderNo_fakeOrderNo);
RouteOrder findByApproveOrderNo_FakeOrderNoAndApproveOrderNo_SysCode(String approveOrderNo_fakeOrderNo, String sysCode);
RouteOrder findByApproveOrderNo_ActualOrderNo(String approveOrderNo_actualOrderNo);
RouteOrder findByRouteOrderNo(String routeOrderNo);
}

View File

@ -1,16 +1,19 @@
package com.chint.infrastructure.util;
import javax.crypto.*;
import java.io.UnsupportedEncodingException;
import com.chint.interfaces.rest.ctrip.dto.put.CTripNotification;
import org.apache.commons.codec.digest.DigestUtils;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;
import java.util.*;
import static com.chint.infrastructure.constant.Constant.AES_SECRET;
import static com.chint.infrastructure.constant.Constant.C_TRIP_REQUEST_SECRET;
public class Digest {
@ -71,4 +74,58 @@ public class Digest {
throw new RuntimeException(e);
}
}
public static String getPutCTripStatusSign(String corpId,
String productType,
String orderStatus,
String orderId) {
//构造字典
HashMap<String, String> hashMap = new HashMap<String, String>();
hashMap.put("secret", C_TRIP_REQUEST_SECRET);
hashMap.put("corpId", corpId);
hashMap.put("productType", productType);
hashMap.put("orderId", orderId);
hashMap.put("orderStatus", orderStatus);
//排序
Collection<String> collection = hashMap.keySet();
ArrayList<String> list = new ArrayList<String>(collection);
Collections.sort(list);
//拼接
String str = "";
for (int i = 0; i < list.size(); i++) {
str += list.get(i) + "=" + hashMap.get(list.get(i));
if (i != list.size() - 1)
str += "&";
}
//SH1加密
return DigestUtils.sha1Hex(str).toUpperCase();
}
public static String getPutCTripEventSign(CTripNotification postRequest) {
//构造字典
HashMap<String, String> hashMap = new HashMap<>();
hashMap.put("secret", C_TRIP_REQUEST_SECRET);
hashMap.put("corpId", postRequest.getCorpId());
hashMap.put("uid", postRequest.getUId());
hashMap.put("messageCategory", postRequest.getMessageCategory());
hashMap.put("messageType", postRequest.getMessageType());
hashMap.put("businessId", postRequest.getBusinessId());
hashMap.put("businessType", postRequest.getBusinessType());
//排序
Collection<String> collection = hashMap.keySet();
ArrayList<String> list = new ArrayList<>(collection);
Collections.sort(list);
//拼接
StringBuilder sb = new StringBuilder();
for (int i = 0; i < list.size(); i++) {
sb.append(list.get(i));
sb.append("=");
sb.append(hashMap.get(list.get(i)));
if (i != list.size() - 1)
sb.append("&");
}
//SH1加密
return DigestUtils.shaHex(sb.toString()).toUpperCase();
}
}

View File

@ -29,4 +29,13 @@ public class CTripApprovalRequest {
approvalRequest.setAuth(Authentication.of(C_TRIP_APP_KEY, ticket));
return postRequest.post(approvalUrl, approvalRequestOut, ApprovalResult.class);
}
public ApprovalResult cancelApprovalOrder(ApprovalRequest approvalRequest) {
ApprovalRequestOut approvalRequestOut = new ApprovalRequestOut();
approvalRequestOut.setRequest(approvalRequest);
String ticket = ticketRequest.loadTicket();
approvalRequest.setStatus(0);
approvalRequest.setAuth(Authentication.of(C_TRIP_APP_KEY, ticket));
return postRequest.post(approvalUrl, approvalRequestOut, ApprovalResult.class);
}
}

View File

@ -0,0 +1,21 @@
package com.chint.interfaces.rest.ctrip.dto.put;
import lombok.Data;
@Data
public class CTripStatusNotification {
private String productType;
private String orderId;
private String orderStatus;
private String corpId; //公司编号
private String platformID; //平台ID
private String sourceID; //来源ID
private String statusIDs ; //状态流水号
private String refundType; //退款类型 火车票Refunded状态类型RA/退代取票费 RB/退差额 CB/退改签差额 RT/退票退款 TF/出票失败 C/订单退款 CR/改签退款 CD/改签原票张退款
private String approveScenario; //授权场景N - 创建 A - 改签
private String sign; //计算规则将productTypeorderIdorderStatuscorpId和secret具体见1.3按照参数名升序排列,把参数名和值原始值不需要urlencode=号拼接然后再用&拼接最后对字符串进行sha1然后转换为大写即可生成示例见3注意字段为null时要转化成空字符串处理
private String modifyApplyID;
private String modifyType;
private String modifyFormStatus;
private String cancelFormStatus;
}

View File

@ -0,0 +1,12 @@
package com.chint.interfaces.rest.ctrip.dto.put;
import lombok.AllArgsConstructor;
import lombok.Data;
@Data
@AllArgsConstructor
public class CTripStatusResponse {
private String errno;
private String errmsg;
}

View File

@ -12,7 +12,7 @@ import java.util.List;
public class ItineraryEntity {
// 行程单号
private String JourneyNO; // 行程单号
private String JourneyNo; // 行程单号
// 酒店订单信息列表
private List<HotelOrderInfoEntity> HotelOrderInfoList; // 酒店订单信息列表
// 航班订单信息列表

View File

@ -10,5 +10,6 @@ public class BasicInfo {
private String orderStatus;
private String orderStatusCode;
private String UID;
private String JourneyID;
// Other fields and getters/setters
}

View File

@ -6,7 +6,7 @@ import java.util.List;
@Data
public class HotelOrderInfoEntity {
private String OrderId; // 订单ID
private String OrderID; // 订单ID
private String TripId; // 旅行ID
private String Uid; // 用户ID
private String PreEmployeeId; // 预订员工ID

View File

@ -1,10 +1,15 @@
package com.chint.interfaces.rest.ctrip.in;
import com.chint.application.commands.OrderStatusChangeCommand;
import com.chint.domain.service.supplier.SupplierService;
import com.chint.domain.value_object.SupplierCallbackData;
import com.chint.infrastructure.echo_framework.command.Command;
import com.chint.infrastructure.util.Digest;
import com.chint.interfaces.rest.ctrip.CTripOrderSearchRequest;
import com.chint.interfaces.rest.ctrip.dto.put.CTripNoteResponse;
import com.chint.interfaces.rest.ctrip.dto.put.CTripNotification;
import com.chint.interfaces.rest.ctrip.dto.put.CTripStatusNotification;
import com.chint.interfaces.rest.ctrip.dto.put.CTripStatusResponse;
import com.chint.interfaces.rest.ctrip.dto.search.SearchOrderResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
@ -12,7 +17,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import static com.chint.infrastructure.constant.Constant.SUPPLIER_C_TRIP;
import static com.chint.infrastructure.constant.Constant.*;
@RestController
@RequestMapping("/public/CTrip")
@ -25,18 +30,200 @@ public class CTripNoteController {
@Autowired
private CTripOrderSearchRequest cTripOrderSearchRequest;
@PostMapping("/event")
public CTripNoteResponse noteEvent(@RequestBody CTripNotification cTripNotification) {
if (cTripNotification.getContent() != null && cTripNotification.getPreEmployeeID() != null) {
//成功触发消息需要查询对于的订单信息調用订单查询的服务来查询该订单详情
// @PostMapping("/event")
// public CTripNoteResponse noteEvent(@RequestBody CTripNotification cTripNotification) {
// String putCTripEventSign = Digest.getPutCTripEventSign(cTripNotification);
// if (!putCTripEventSign.equals(cTripNotification.getSign())) {
// return new CTripNoteResponse("1", "sign错误");
// }
//
// if (cTripNotification.getContent() != null && cTripNotification.getPreEmployeeID() != null) {
// //成功触发消息需要查询对于的订单信息調用订单查询的服务来查询该订单详情
// SupplierCallbackData supplierCallbackData =
// SupplierCallbackData.of(SUPPLIER_C_TRIP, cTripNotification.getPreEmployeeID());
// SearchOrderResponse response = cTripOrderSearchRequest
// .searchOrderResponseByOrderId(cTripNotification.getBusinessId());
// supplierCallbackData.data(response);
// supplierService.handleSupplierCallback(supplierCallbackData);
// return new CTripNoteResponse("0", "成功收到消息");
// }
// return new CTripNoteResponse("1", "未收到消息");
// }
@PostMapping("/status")
public CTripStatusResponse statusEvent(@RequestBody CTripStatusNotification cTripStatusNotification) {
String productType = cTripStatusNotification.getProductType();
String orderStatus = cTripStatusNotification.getOrderStatus();
String orderId = cTripStatusNotification.getOrderId();
String putCTripSign = Digest.getPutCTripStatusSign(cTripStatusNotification.getCorpId(), productType, orderStatus, orderId);
if (!putCTripSign.equals(cTripStatusNotification.getSign())) {
return new CTripStatusResponse("1", "sign错误");
}
if (orderStatus != null && orderId != null) {
SupplierCallbackData supplierCallbackData =
SupplierCallbackData.of(SUPPLIER_C_TRIP, cTripNotification.getPreEmployeeID());
SupplierCallbackData.of(SUPPLIER_C_TRIP);
SearchOrderResponse response = cTripOrderSearchRequest
.searchOrderResponseByOrderId(cTripNotification.getBusinessId());
.searchOrderResponseByOrderId(orderId);
supplierCallbackData.data(response);
supplierService.handleSupplierCallback(supplierCallbackData);
return new CTripNoteResponse("0", "成功收到消息");
OrderStatusChangeCommand command = Command.of(OrderStatusChangeCommand.class)
.orderNo(orderId)
.outStatus(orderStatus);
switch (productType) {
case "FlightInternational":
case "FlightDomestic":
command.eventType(mapFlightStatus(orderStatus));
break;
case "HotelMember":
case "HotelContract":
command.eventType(mapHotelStatus(orderStatus));
break;
case "Train":
case "OverseaTrain":
command.eventType(mapTrainStatus(orderStatus));
break;
case "CarPickUpInternational":
case "CarRentalDomestic":
case "CarImmediately":
case "CarPickUpDomesticNew":
case "CarCharterDomestic":
case "BusTicket":
command.eventType(mapCarStatus(orderStatus));
break;
}
command.sendToQueue();
return new CTripStatusResponse("0", "成功收到消息");
}
return new CTripNoteResponse("1", "未收到消息");
return new CTripStatusResponse("1", "未收到消息");
}
public Integer mapFlightStatus(String status) {
return switch (status) {
case "Submitted" -> ORDER_EVENT_PREPARE; // "已提交"映射到准备下单
case "Confirmed" -> ORDER_EVENT_ORDERED; // "已客户确认"映射到已下单
case "Ticketed" -> ORDER_EVENT_PAYED; // "已出票"可能意味着已经支付完成
case "Cancelled" -> ORDER_EVENT_CANCEL; // "已取消"映射到取消
case "Refunded" -> ORDER_EVENT_REFUND; // "已经退票"映射到退票
case "RefundCancelled" ->
// 可能需要新的状态常量因为它没有直接映射
ORDER_EVENT_PAYED;
case "Dealt" ->
// "已经成交"可能意味着订单已完成但没有直接映射可能需要新的状态常量
ORDER_EVENT_PAYED;
case "Rebooked" -> ORDER_EVENT_PAYED;
case "rebookSuccess" -> ORDER_EVENT_CHANGE; // "改签成功"映射到改签
case "RebookedFailed" ->
// "改签失败"可能需要新的状态常量因为它没有直接映射
ORDER_EVENT_PAYED;
case "RebookSubmitted" ->
// "改签提交"可能意味着改签过程开始但没有直接映射
ORDER_EVENT_PAYED;
case "RebookConfirmed" ->
// "改签确认"可能需要新的状态常量因为它没有直接映射
ORDER_EVENT_PAYED;
case "RebookToBePaid" ->
// "改签待支付"可能意味着改签了但未支付但没有直接映射
ORDER_EVENT_PAYED;
case "RebookCancelled" ->
// "改签取消"可能需要新的状态常量因为它没有直接映射
ORDER_EVENT_PAYED;
case "Paid" -> ORDER_EVENT_PAYED; // "已支付"映射到已预定
case "RefundSuccess" -> ORDER_EVENT_REFUND; // "退票成功(退款成功)"映射到退票
default ->
// 处理未知或未映射的状态
-1;
};
}
public Integer mapHotelStatus(String status) {
return switch (status) {
case "Submitted" -> ORDER_EVENT_PREPARE; // "已提交"映射到准备状态
case "Confirmed" -> ORDER_EVENT_ORDERED; // "已客户确认"映射到已下单
case "Cancelled" -> ORDER_EVENT_CANCEL; // "已取消"映射到取消
case "Wait" ->
// "确认中"可能表示订单正在处理中但没有直接映射可能需要新的状态常量
ORDER_EVENT_ORDERED;
case "Paid" -> ORDER_EVENT_PAYED; // "已支付"映射到已预定
case "Dealt" ->
// "已经成交"可能表示订单已完成但没有直接映射可能需要新的状态常量
ORDER_EVENT_PAYED;
case "CheckIn" ->
// "入店打卡"可能需要新的状态常量因为它没有直接映射
ORDER_EVENT_PAYED;
case "CheckOut" ->
// "离店打卡"可能需要新的状态常量因为它没有直接映射
ORDER_EVENT_PAYED;
case "CancellationFailed" ->
// "取消失败"可能需要新的状态常量因为它没有直接映射
ORDER_EVENT_PAYED;
case "submitFailed" ->
// "提交失败"可能需要新的状态常量因为它没有直接映射
ORDER_EVENT_PREPARE;
default ->
// 处理未知或未映射的状态
-1;
};
}
public Integer mapTrainStatus(String status) {
return switch (status) {
case "Submitted" -> ORDER_EVENT_PREPARE; // "已提交"映射到准备状态
case "Ticketed" ->
// "已出票"可能表示订单已完成出票但没有直接的映射可能需要新的状态常量或使用现有的常量
ORDER_EVENT_PAYED;
case "Cancelled" -> ORDER_EVENT_CANCEL; // "已取消"映射到取消状态
case "Refunded" -> ORDER_EVENT_REFUND; // "已经退票"映射到退票状态
case "Rebooked" -> ORDER_EVENT_CHANGE; // "已经改签"映射到改签状态
case "IssueTicketFailed" ->
// "出票失败"可能需要新的状态常量因为它没有直接映射
ORDER_EVENT_ORDERED;
case "RebookedFailed" ->
// "改签失败"也可能需要新的状态常量因为它没有直接映射
ORDER_EVENT_PAYED;
case "SubmitRefund" ->
// "退票成功"可能最接近"已经退票"但具体映射取决于业务逻辑
ORDER_EVENT_REFUND; // 使用退票状态作为近似映射
case "Paid" -> ORDER_EVENT_PAYED; // "已支付"映射到已预定状态
default ->
// 处理未知或未映射的状态
-1;
};
}
public Integer mapCarStatus(String status) {
return switch (status) {
case "Cancelled" -> ORDER_EVENT_CANCEL; // "已取消"映射到取消状态
case "Dealt" ->
// "已经成交"可能意味着订单已经确认或完成但没有直接映射可能需要新的状态常量
ORDER_EVENT_PAYED;
case "WaitReply" ->
// "等待应答"可能表示订单正在等待确认但没有直接映射可能需要新的状态常量
ORDER_EVENT_ORDERED;
case "WaitService" ->
// "等待接驾"可能表示服务即将开始但没有直接映射可能需要新的状态常量
ORDER_EVENT_ORDERED;
case "Redispatched" ->
// "改派中"可能需要新的状态常量因为它没有直接映射
ORDER_EVENT_PAYED;
case "DriverArrived" ->
// "司机已到达"可能需要新的状态常量因为它没有直接映射
ORDER_EVENT_PAYED;
case "InService" ->
// "正在服务"表示服务正在进行中但没有直接映射可能需要新的状态常量
ORDER_EVENT_PAYED;
case "EndService" ->
// "行程结束"可能意味着服务已完成但没有直接映射可能需要新的状态常量
ORDER_EVENT_PAYED;
case "Canceling" ->
// "取消中"可能表示订单正在取消过程中但没有直接映射可能需要新的状态常量
ORDER_EVENT_REFUND;
default ->
// 处理未知或未映射的状态
-1;
};
}
}

View File

@ -6,6 +6,9 @@ package com.chint.interfaces.rest.user;
//import com.chint.dc.api.dto.DataCenterOption;
//import com.chint.dc.api.service.DataCenterService;
import com.chint.dc.api.DataCenterResult;
import com.chint.dc.api.dto.DataCenterOption;
import com.chint.dc.api.service.DataCenterService;
import com.chint.domain.aggregates.user.User;
import com.chint.interfaces.rest.base.PostRequest;
import com.chint.interfaces.rest.user.dto.*;
@ -41,14 +44,14 @@ public class UserHttpRequestImpl implements UserHttpRequest {
}
private User loadSFAndRank(User user) {
// List<UserDataDTO> loadSFInfo = loadSFInfo(user);
// String custManaLevel = loadSFInfo.get(0).getCust_manaLevel();
// String level = custManaLevel != null ? custManaLevel : "M0";
// if (level.contains("R")) {
// level = level.substring(0, level.length() - 3) + "M0";
// }
// TravelRankDTO loadTravelRank = loadTravelRank(new TravelRankParam(level));
// user.setRankCode(loadTravelRank.getLEVEL_MAPPING_CODE());
List<UserDataDTO> loadSFInfo = loadSFInfo(user);
String custManaLevel = loadSFInfo.get(0).getCust_manaLevel();
String level = custManaLevel != null ? custManaLevel : "M0";
if (level.contains("R")) {
level = level.substring(0, level.length() - 3) + "M0";
}
TravelRankDTO loadTravelRank = loadTravelRank(new TravelRankParam(level));
user.setRankCode(loadTravelRank.getLEVEL_MAPPING_CODE());
user.setRankCode("测试职级");
return user;
}
@ -68,33 +71,33 @@ public class UserHttpRequestImpl implements UserHttpRequest {
}
private List<UserDataDTO> loadSFInfo(User user) {
// Gson gson = new Gson();
// AccessKeyDTO akSkLoad = akSkLoad();
// DataCenterOption option = new DataCenterOption();
// option.setSk(akSkLoad.sk);
// option.setAk(akSkLoad.ak);
// option.setUrl(OPENAI_BASE_URL);
// DataCenterService dataCenterService = new DataCenterService(option);
// LinkedHashMap map = new LinkedHashMap<String, Object>();
// map.put("LoginUsername", user.getEmployeeNo().toString());
// map.put("start", 0);
// map.put("pageSize", 1);
// DataCenterResult result = dataCenterService.post(USER_DATA_PATH, map);
// Type type = new TypeToken<List<UserDataDTO>>() {
// }.getType();
// if (result.getData() != null) {
// List<UserDataDTO> fromJson = gson.fromJson(result.getData().toString(), type);
// UserDataDTO userDataDTO = fromJson.get(0);
// user.setCompanyCode(userDataDTO.getCompany());
// user.setWorkStatus(userDataDTO.getStatus());
// user.setGender(userDataDTO.getGender());
// user.setName(userDataDTO.getUname());
// user.setPhoneNumber(userDataDTO.getMobilePhone());
// return fromJson;
// } else {
// throw new RuntimeException("用户数据不存在");
// }
return null;
Gson gson = new Gson();
AccessKeyDTO akSkLoad = akSkLoad();
DataCenterOption option = new DataCenterOption();
option.setSk(akSkLoad.sk);
option.setAk(akSkLoad.ak);
option.setUrl(OPENAI_BASE_URL);
DataCenterService dataCenterService = new DataCenterService(option);
LinkedHashMap map = new LinkedHashMap<String, Object>();
map.put("LoginUsername", user.getEmployeeNo().toString());
map.put("start", 0);
map.put("pageSize", 1);
DataCenterResult result = dataCenterService.post(USER_DATA_PATH, map);
Type type = new TypeToken<List<UserDataDTO>>() {
}.getType();
if (result.getData() != null) {
List<UserDataDTO> fromJson = gson.fromJson(result.getData().toString(), type);
UserDataDTO userDataDTO = fromJson.get(0);
user.setCompanyCode(userDataDTO.getCompany());
user.setWorkStatus(userDataDTO.getStatus());
user.setGender(userDataDTO.getGender());
user.setName(userDataDTO.getUname());
user.setPhoneNumber(userDataDTO.getMobilePhone());
return fromJson;
} else {
throw new RuntimeException("用户数据不存在");
}
// return null;
}
private TravelRankDTO loadTravelRank(TravelRankParam travelRankParam) {

View File

@ -135,10 +135,10 @@ public class CTripTest {
System.out.println(gson.toJson(estimate));
}
// @Test
@Test
void search() {
BaseContext.setCurrentUser(user);
SearchOrderResponse response = orderSearchRequest.searchOrder("actual12345622");
SearchOrderResponse response = orderSearchRequest.searchOrderResponseByOrderId("30469349853");
System.out.println(response);
}

View File

@ -4,13 +4,17 @@ import cn.hutool.extra.pinyin.PinyinUtil;
import com.chint.domain.aggregates.order.Location;
import com.chint.domain.aggregates.user.User;
import com.chint.domain.repository.LocationRepository;
import com.chint.domain.repository.RouteRepository;
import com.chint.infrastructure.util.Digest;
import com.chint.interfaces.rest.user.UserHttpRequest;
import org.apache.commons.codec.digest.DigestUtils;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.List;
import java.util.*;
import static com.chint.infrastructure.constant.Constant.C_TRIP_REQUEST_SECRET;
@SpringBootTest
class RouteApplicationTests {
@ -21,6 +25,9 @@ class RouteApplicationTests {
@Autowired
private LocationRepository locationRepository;
@Autowired
private RouteRepository routeRepository;
private User user = new User(1L, 230615020L, 1, "卢麟哲", "1033719135@qq.com", "15857193365");
@ -33,9 +40,9 @@ class RouteApplicationTests {
void loginSign() {
String sfno = "230615020";
String syscode = "abc";
String billcode = "KK12321412323";
String billcode = "KK1033719135";
String sec = "Superdandan";
String timespan = "12312321412312";
String timespan = "12312312312312";
String s = Digest.md5(sfno + syscode + billcode + sec + timespan);
System.out.println(s);
}
@ -55,4 +62,36 @@ class RouteApplicationTests {
locationRepository.saveAll(all);
}
@Test
void deleteRouteOrder(){
routeRepository.deleteById(52L);
}
@Test
void cTripSign(){
HashMap<String, String> hashMap = new HashMap<>();
hashMap.put("secret", C_TRIP_REQUEST_SECRET);
hashMap.put("corpId", "zhengtai2024");
hashMap.put("uid", null);
hashMap.put("messageCategory", "4");
hashMap.put("messageType", "8");
hashMap.put("businessId", "30466168290");
hashMap.put("businessType", "M");
//排序
Collection<String> collection = hashMap.keySet();
ArrayList<String> list = new ArrayList<>(collection);
Collections.sort(list);
//拼接
StringBuilder sb = new StringBuilder();
for (int i = 0; i < list.size(); i++) {
sb.append(list.get(i));
sb.append("=");
sb.append(hashMap.get(list.get(i)));
if (i != list.size() - 1)
sb.append("&");
}
//SH1加密
System.out.println(DigestUtils.shaHex(sb.toString()).toUpperCase());
}
}