Compare commits

..

No commits in common. "aea8ca7f0ceceda703fccc280829245bc571681b" and "84f4d9d34211f4bf82fb84894cdb6a141ee79cb1" have entirely different histories.

47 changed files with 227 additions and 847 deletions

View File

@ -1,9 +0,0 @@
package com.chint.application.commands;
import com.chint.infrastructure.echo_framework.command.Command;
import static com.chint.infrastructure.constant.Constant.LEG_EVENT_NOT_ORDERED;
public class LegRejectCommand extends Command {
private Integer LegEventType = LEG_EVENT_NOT_ORDERED;
}

View File

@ -9,12 +9,14 @@ import static com.chint.infrastructure.constant.Constant.LEG_EVENT_NOT_ORDERED;
@Data
public class LegSyncCommand extends Command {
private Integer LegEventType = LEG_EVENT_NOT_ORDERED;
private Long LegId;
private Long routOrderId;
private SyncLegData data;
// public LegSyncCommand legId(Long LegId) {
// this.setLegId(LegId);
// return this;
// }
public LegSyncCommand legId(Long LegId) {
this.setLegId(LegId);
return this;
}
public LegSyncCommand data(SyncLegData data) {
this.data = data;

View File

@ -7,7 +7,6 @@ import com.chint.domain.value_object.*;
import com.chint.infrastructure.util.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@ -25,8 +24,6 @@ public class OrderController {
@Autowired
private OrderQuery orderQuery;
@Transactional
@ApiOperation("保存行程规划单")
@PostMapping("/save")
public Result<RouteOrder> creatOrder(@RequestBody OrderSaveData orderCreateData) {
@ -34,8 +31,6 @@ public class OrderController {
return Result.Success(SUCCESS);
}
@Transactional
@ApiOperation("提交审批行程规划单")
@PostMapping("/approve")
public Result<String> approveOrder(@RequestBody ApproveLegData approveLegData) {
@ -43,7 +38,6 @@ public class OrderController {
return Result.Success(SUCCESS);
}
@Transactional
@ApiOperation("同步行程规划单到供应商")
@PostMapping("/sync")
public Result<String> syncOrder(@RequestBody SyncLegData syncLegData) {

View File

@ -2,16 +2,12 @@ package com.chint.application.out;
import com.chint.application.commands.OrderCreateCommand;
import com.chint.domain.aggregates.user.User;
import com.chint.domain.service.auth.AuthenticateService;
import com.chint.domain.value_object.UserLoginParam;
import com.chint.domain.value_object.UserLoginResult;
import com.chint.infrastructure.echo_framework.command.Command;
import com.chint.infrastructure.util.BaseContext;
import com.chint.infrastructure.util.Digest;
import com.chint.infrastructure.util.Result;
import com.chint.interfaces.rest.ctrip.CTripUserSaveRequest;
import com.chint.interfaces.rest.ly.LYUserRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
@ -19,8 +15,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.concurrent.CompletableFuture;
import static com.chint.infrastructure.constant.Constant.*;
@RestController
@ -30,12 +24,6 @@ public class LoginController {
@Autowired
private AuthenticateService authenticateService;
@Autowired
private LYUserRequest lyUserRequest;
@Autowired
private CTripUserSaveRequest cTripUserSaveRequest;
@Transactional
@GetMapping("/login")
public Result<UserLoginResult> login(@RequestParam("sfno") String sfno,
@ -53,21 +41,6 @@ public class LoginController {
.authenticateEmployeeNo(userLoginParam);
//发送创建行程订单命令
Command.of(OrderCreateCommand.class).of(userLoginParam).sendToQueue();
//异步执行更新用户信息到同程
User currentUser = userLoginResult.getUser();
CompletableFuture.runAsync(() -> {
BaseContext.setCurrentUser(currentUser);
lyUserRequest.saveCurrentUser();
BaseContext.removeCurrentUser();
});
//异步执行更新用户信息到携程
CompletableFuture.runAsync(() -> {
BaseContext.setCurrentUser(currentUser);
cTripUserSaveRequest.saveUserToCTrip();
BaseContext.removeCurrentUser();
});
return Result.Success(SUCCESS, userLoginResult);
} else {
return Result.error(SIGN_ERROR);

View File

@ -21,16 +21,11 @@ import static com.chint.infrastructure.constant.Constant.SUCCESS;
public class OrderOutController {
@Autowired
private OrderQuery orderQuery;
@ApiOperation("根据临时单号查询订单")
@PostMapping("/query/billcode")
public Result<RouteOrder> queryOrderByBillCode(@RequestBody OrderQueryData queryData) {
return Result.Success(SUCCESS, orderQuery.queryByBillCode(queryData.getBillcode()).reloadStatus());
}
@ApiOperation("查询行程规划订单详情")
@PostMapping("/query")
public Result<RouteOrder> queryOrder(@RequestBody OrderQueryData queryData) {

View File

@ -3,9 +3,7 @@ package com.chint.application.out;
import com.chint.application.services.SupplierLoginService;
import com.chint.infrastructure.util.Result;
import com.chint.interfaces.rest.ctrip.dto.login.H5Response;
import com.chint.interfaces.rest.ly.dto.login.LYRedirectUrlResponse;
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.RequestMapping;
@ -20,18 +18,16 @@ public class SupplierLoginController {
@Autowired
private SupplierLoginService supplierLoginService;
@ApiOperation("单点登录同程")
@PostMapping("/ly/login")
public Result<LYRedirectUrlResponse> lyLogin() {
//登录
LYRedirectUrlResponse data = supplierLoginService.lyLogin();
return Result.Success(SUCCESS, data);
return Result.Success(SUCCESS,data);
}
@ApiOperation("单点登录携程")
@PostMapping("/CTrip/login")
public Result<H5Response> cTripLogin() {
return Result.Success(SUCCESS, supplierLoginService.cTripLogin());
public Result<String> cTripLogin() {
return Result.Success(SUCCESS);
}
}

View File

@ -1,9 +1,11 @@
package com.chint.application.queryies;
import com.chint.domain.aggregates.order.RouteOrder;
import com.chint.domain.aggregates.user.User;
import com.chint.domain.repository.RouteRepository;
import com.chint.domain.service.OrderDomainService;
import com.chint.domain.value_object.OrderQueryData;
import com.chint.infrastructure.util.BaseContext;
import com.chint.infrastructure.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -34,8 +36,4 @@ public class OrderQuery {
orderDomainService.queryLocation(routeOrder.getLegItems());
return routeOrder;
}
public RouteOrder queryByBillCode(String billCode) {
return routeRepository.findByFakeOrderNo(billCode);
}
}

View File

@ -1,7 +1,5 @@
package com.chint.application.services;
import com.chint.interfaces.rest.ctrip.CTripLoginRequest;
import com.chint.interfaces.rest.ctrip.dto.login.H5Response;
import com.chint.interfaces.rest.ly.LYLoginRequest;
import com.chint.interfaces.rest.ly.dto.login.LYRedirectUrlResponse;
import org.springframework.beans.factory.annotation.Autowired;
@ -15,18 +13,10 @@ public class SupplierLoginService {
@Autowired
private LYLoginRequest lyLoginRequest;
@Autowired
private CTripLoginRequest cTripLoginRequest;
/**
* 登录接口
*/
public LYRedirectUrlResponse lyLogin() {
return lyLoginRequest.login(L_Y_ENTRANCE_HOME);
}
public H5Response cTripLogin() {
return cTripLoginRequest.hSingleLogin();
}
}

View File

@ -13,7 +13,10 @@ import org.springframework.data.relational.core.mapping.MappedCollection;
import org.springframework.data.relational.core.mapping.Table;
import java.time.LocalDateTime;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import static com.chint.infrastructure.constant.Constant.*;
@ -72,23 +75,22 @@ public class Leg {
}
public Leg reloadStatus() {
if (eventList == null || eventList.isEmpty()) {
if (eventList == null) {
this.legStatus = LEG_STATUS_PREPARE;
} else {
// Find the latest event based on the maximum id
LegEvent latestEvent = this.eventList.stream()
.max(Comparator.comparingLong(LegEvent::getLegEventId))
.orElse(null);
// Set the legStatus based on the type of the latest event
this.legStatus = latestEvent.getEventType();
// If the latest event is an order event, update the amount
if (latestEvent.getEventType().equals(LEG_EVENT_ORDERED)) {
this.amount = latestEvent.getOrderDetail().getAmount();
int eventLength = eventList.size() - 1;
this.legStatus = eventLength < 0 ? LEG_STATUS_PREPARE : eventLength;
if (legStatus > 1) {
Optional<LegEvent> legEvent = this.eventList
.stream()
.filter(event -> event.getEventType().equals(LEG_EVENT_ORDERED))
.findFirst();
if (legEvent.isPresent()) {
LegEvent event = legEvent.get();
this.amount = event.getOrderDetail().getAmount();
}
}
}
this.legStatusName = translateLegStatus(this.legStatus);
if (legType != null) {
this.legTypeName = translateLegType(this.legType);
@ -96,7 +98,6 @@ public class Leg {
return this;
}
public Leg reloadStatus(LegData legData) {
this.reloadStatus();
if (Objects.equals(legData.getLegId(), this.getLegId()) && this.legStatus.equals(LEG_STATUS_PREPARE)) {
@ -117,7 +118,6 @@ public class Leg {
case LEG_STATUS_PAYED -> LEG_STATUS_PAYED_NAME;
case LEG_STATUS_FINISH -> LEG_STATUS_FINISH_NAME;
case LEG_STATUS_NOT_ORDERED -> LEG_STATUS_NOT_ORDERED_NAME;
case LEG_STATUS_REJECT -> LEG_STATUS_REJECT_NAME;
default -> "未知状态";
};
}
@ -151,16 +151,11 @@ public class Leg {
throw new LegEventException("The first event must be a prepare event.");
}
// 事件类型为负数代表是可以任何时机都可进行的事件
if(event.getEventType() < 0) {
eventList.add(event);
return this;
}
// 如果列表不为空确保新事件的类型是按顺序的
if (!eventList.isEmpty()) {
LegEvent lastEvent = eventList.get(eventList.size() - 1);
int lastEventType = lastEvent.getEventType();
if (newEventType != lastEventType + 1) {
throw new LegEventException("Events must be added in sequence.");
}

View File

@ -35,8 +35,6 @@ public class LegEvent {
case LEG_EVENT_PAYED -> LEG_EVENT_PAYED_NAME;
case LEG_EVENT_FINISH -> LEG_EVENT_FINISH_NAME;
case LEG_EVENT_NOT_ORDERED -> LEG_EVENT_NOT_ORDERED_NAME;
case LEG_EVENT_APPROVAL -> LEG_EVENT_APPROVAL_NAME;
case LEG_EVENT_REJECT -> LEG_EVENT_REJECT_NAME;
default -> "未知事件";
};
}

View File

@ -95,7 +95,6 @@ public class RouteOrder extends BaseEntity {
this.getLegItems().forEach(Leg::reloadStatus);
this.estimateAmount = this.getLegItems()
.stream()
.filter(leg -> leg.getEstimateAmount() != null)
.map(Leg::getEstimateAmount)
.reduce(BigDecimalCalculator::add)
.orElse(KEEP_TWO_DECIMAL_ZERO);
@ -191,7 +190,6 @@ public class RouteOrder extends BaseEntity {
case ORDER_STATUS_PAYED -> ORDER_STATUS_PAYED_NAME;
case ORDER_STATUS_FINISH -> ORDER_STATUS_FINISH_NAME;
case ORDER_STATUS_NOT_ORDERED -> ORDER_STATUS_NOT_ORDERED_NAME;
case ORDER_STATUS_REJECT -> ORDER_STATUS_REJECT_NAME;
default -> "未知状态";
};
}

View File

@ -2,7 +2,6 @@ package com.chint.domain.service.amount_estimate;
import com.chint.domain.aggregates.order.Leg;
import com.chint.domain.aggregates.order.RouteOrder;
import com.chint.domain.service.OrderDomainService;
import com.chint.infrastructure.constant.Constant;
import com.chint.infrastructure.util.BigDecimalCalculator;
import com.chint.interfaces.rest.ly.LYPostRequest;
@ -66,7 +65,7 @@ public class LYEstimate implements AmountEstimate {
TrainMaxPrice trainMaxPrice = new TrainMaxPrice();
trainMaxPrice.setTicketType(0);
trainMaxPrice.setDepartDate(leg.getStartTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));//开始时间
trainMaxPrice.setDepartCityName(leg.getOriginLocation().getLocationName());//出发城市
trainMaxPrice.setDepartCityName(leg.getOriginLocationId().getLocationName());//出发城市
trainMaxPrice.setArriveCityName(leg.getDestinationLocation().getLocationName());//到达城市
Description<TrainMaxPrice> description = new Description<>();
description.setParam(trainMaxPrice);

View File

@ -1,128 +0,0 @@
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()).reloadStatus();
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);
if (!syncAdapter.of(supplierName).syncSupplierOrder(routeOrder.reloadStatus())) {
throw new CommandException("订单提交失败");
}
} 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

@ -16,5 +16,4 @@ public interface LegEventService {
void payForLeg(LegPayedCommand command);
//结束
void finishLeg(LegFinishedCommand command);
void rejectLeg(LegRejectCommand command);
}

View File

@ -2,7 +2,6 @@ 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;
@ -11,27 +10,38 @@ import com.chint.domain.value_object.ApproveLegData;
import com.chint.domain.value_object.OrderLegData;
import com.chint.domain.value_object.PayLegData;
import com.chint.domain.value_object.SyncLegData;
import com.chint.infrastructure.echo_framework.annotation.ListenTo;
import com.chint.infrastructure.echo_framework.annotation.TransitionTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import static com.chint.infrastructure.constant.Constant.ORDER_STATUS_APPROVAL;
import static com.chint.infrastructure.constant.Constant.ORDER_STATUS_PREPARE;
@Service
public class LegEventServiceImpl implements LegEventService {
@Autowired
private LegEventHandler legEventHandler;
private SyncAdapter syncAdapter;
@Autowired
private RouteRepository routeRepository;
@Autowired
private LegRepository legRepository;
@Autowired
private LegEventFactory legEventFactory;
@TransitionTo(command = "LegPrepareCommand", order = 0)
@Override
public void prepareLeg(LegPrepareCommand command) {
legEventHandler.prepareLeg(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);
}
}
//因为审批是针对整个订单的因此所有订单下属的行程节点触发审批事件
@ -40,42 +50,75 @@ public class LegEventServiceImpl implements LegEventService {
@ListenTo(command = "LegApprovalCommand", order = 0)
@Override
public void approveLeg(LegApprovalCommand command) {
legEventHandler.approveLeg(command);
ApproveLegData data = command.getData();
RouteOrder routeOrder = routeRepository.findByFakeOrderNo(data.getFakeOrderNo());
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);
}
//这里需要获取同步类价格routeOrder同步到供应商
@ListenTo(command = "LegSyncCommand", order = 0)
@Override
public void syncLeg(LegSyncCommand command) {
legEventHandler.syncLeg(command);
SyncLegData data = command.getData();
RouteOrder routeOrder = routeRepository.queryById(command.getRoutOrderId());
String supplierName = data.getSupplierName();
routeOrder.setSupplierName(supplierName);
//这里order所有的leg触发approve事件
routeOrder.getLegItems().forEach(leg -> leg.getEventList().add(
legEventFactory.creatLegEvent(command.getLegEventType())
));
syncAdapter.of(supplierName).syncSupplierOrder(routeOrder.reloadStatus());
//保存routeOrder的状态
routeRepository.save(routeOrder);
}
//下单时间要求回传需要付款的金额以及生成对于的行程订单号如果没有行程订单号根据地点和时间进行匹配
@ListenTo(command = "LegOrderedCommand", order = 0)
@Override
public void orderLeg(LegOrderedCommand command) {
legEventHandler.orderLeg(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);
}
@Override
@ListenTo(command = "LegPayedCommand", order = 0)
public void payForLeg(LegPayedCommand command) {
legEventHandler.payForLeg(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);
}
@Override
@ListenTo(command = "LegFinishedCommand", order = 0)
public void finishLeg(LegFinishedCommand command) {
}
@Override
@ListenTo(command = "LegRejectCommand", order = 0)
public void rejectLeg(LegRejectCommand command) {
// Leg leg = legRepository.findByLegId(Leg.of(command.getLegId()));
// LegEvent legEvent = legEventFactory.creatLegEvent(command.getLegEventType());
// leg.addEvent(legEvent);
// legRepository.save(leg);
Leg leg = legRepository.findByLegId(Leg.of(command.getLegId()));
LegEvent legEvent = legEventFactory.creatLegEvent(command.getLegEventType());
leg.addEvent(legEvent);
legRepository.save(leg);
}
}

View File

@ -1,68 +1,21 @@
package com.chint.domain.service.order_sync;
import com.chint.domain.aggregates.order.ApproveOrderNo;
import com.chint.domain.aggregates.order.RouteOrder;
import com.chint.domain.aggregates.user.User;
import com.chint.domain.repository.CityRepository;
import com.chint.domain.repository.LocationRepository;
import com.chint.domain.service.OrderDomainService;
import com.chint.infrastructure.util.BaseContext;
import com.chint.interfaces.rest.ctrip.CTripApprovalRequest;
import com.chint.interfaces.rest.ctrip.dto.approval.ApprovalRequest;
import com.chint.interfaces.rest.ctrip.dto.approval.PassengerDetail;
import com.chint.interfaces.rest.ctrip.dto.approval.hotel.HotelEndorsementDetail;
import com.chint.interfaces.rest.ctrip.dto.approval.quick.RankInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import static com.chint.infrastructure.constant.Constant.LEG_TYPE_HOTEL;
@Component
public class CTripOrderSyncAdapter implements SupplierOrderSync {
@Autowired
private CityRepository cityRepository;
@Autowired
private CTripApprovalRequest approvalRequest;
@Autowired
private LocationRepository locationRepository;
@Autowired
private OrderDomainService orderDomainService;
@Override
public boolean syncSupplierOrder(RouteOrder order) {
public void syncSupplierOrder(RouteOrder order) {
System.out.println("开始同步协程订单");
User currentUser = BaseContext.getCurrentUser();
ApproveOrderNo approveOrderNo = order.getApproveOrderNo();
RankInfo rankInfo = RankInfo.of(currentUser.getRankCode());
List<String> cityCode = new ArrayList<>();
List<HotelEndorsementDetail> hotelList = new ArrayList<>();
orderDomainService.queryLocation(order.getLegItems())
.forEach(
leg -> {
cityCode.add(
cityRepository.findByCityName(leg.getOriginLocation().getLocationName()).getCity()
);
if (leg.getLegType().equals(LEG_TYPE_HOTEL)) {
hotelList.add(
HotelEndorsementDetail.of(cityCode.stream().distinct().toList())
.passenger(PassengerDetail.of(String.valueOf(currentUser.getEmployeeNo())))
.starTime(leg.getStartTime())
.endTime(leg.getEndTime())
);
}
}
);
ApprovalRequest approvalRequestParam = ApprovalRequest.buildApproval(String.valueOf(currentUser.getEmployeeNo()), approveOrderNo.getActualOrderNo(), rankInfo)
.withHotel(hotelList);
approvalRequest.approval(approvalRequestParam);
return false;
}
}

View File

@ -1,127 +1,19 @@
package com.chint.domain.service.order_sync;
import com.chint.domain.aggregates.order.Leg;
import com.chint.domain.aggregates.order.Location;
import com.chint.domain.aggregates.order.RouteOrder;
import com.chint.domain.aggregates.user.User;
import com.chint.domain.repository.LocationRepository;
import com.chint.domain.service.OrderDomainService;
import com.chint.infrastructure.constant.Constant;
import com.chint.infrastructure.util.BaseContext;
import com.chint.interfaces.rest.ly.LYPostRequest;
import com.chint.interfaces.rest.ly.dto.applyordersync.*;
import com.chint.interfaces.rest.ly.dto.commonresult.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
@Component
public class LYOrderSyncAdapter implements SupplierOrderSync {
@Autowired
private LYPostRequest postRequest;
public class LYOrderSyncAdapter implements SupplierOrderSync {
@Autowired
private LocationRepository locationRepository;
@Autowired
private OrderDomainService orderDomainService;
@Override
public boolean syncSupplierOrder(RouteOrder order) {
String supplierOrderSyncUrl = Constant.L_Y_BASE_URL + Constant.L_Y_ORDER_PATH;//请求地址
//1.设置订单参数
SupplierOrderParam param = new SupplierOrderParam();//参数
param.setOutEmployeeIdType(0);//外部员工ID类型默认为0
param.setOutTravelApplyNo(order.getApproveOrderNo().getActualOrderNo());//审批订单号
param.setTravelApplyType(1); //差旅类型1 普通差旅,2 福利差旅
param.setStatus(1);//状态1通过2作废
//日期格式化
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
String applyTime = order.getCreateTime().format(formatter);
String updateTime = order.getUpdateTime().format(formatter);
param.setTravelApplyTime(applyTime);//开始创建时间
param.setTravelUpdateTime(updateTime);//最后更新时间
param.setOperationType(1);//1新增2更新
//获取用户信息
User user = BaseContext.getCurrentUser();
param.setOutEmployeeId(String.valueOf(user.getEmployeeNo()));//用户id
param.setTravelDescription("同程订单");//描述信息
param.setBookableProducts("1,3,5");//1:国内机票,2:国际机票,3:国内酒店,4:海外酒店,5:火车票,6:用车
//2.同程的行程节点集合
ArrayList<AOSItem> aosItems = getAosItems(order);
//3.差旅人信息
ArrayList<AOSPerson> aosPeople = new ArrayList<>();
AOSPerson aosPerson = new AOSPerson();
aosPerson.setName(user.getName());//用户名
aosPerson.setRelation(0);//0:内部员工1:配偶2:子女3:父母4:面试候选人5:实习生6:外部宾客
aosPerson.setPassengerType(0);//0:成人, 1:儿童, 2:婴儿
aosPerson.setOutEmployeeId(String.valueOf(user.getEmployeeNo()));//SF号(长工号)
aosPeople.add(aosPerson);
//4.前置差旅政策
ArrayList<AOSPreTravelPolicy> aosPreTravelPolicies = new ArrayList<>();
AOSPreTravelPolicy aosPreTravelPolicy = new AOSPreTravelPolicy();
aosPreTravelPolicy.setPolicyCode("");//一般指客户经理提供的差旅政策标题
aosPreTravelPolicy.setProductTypeId(0);//产品ID 1国内机票2国际机票3国内酒店4海外酒店5火车票6用车
aosPreTravelPolicies.add(aosPreTravelPolicy);
param.setItemList(aosItems); // 同程节点内容
param.setPersonList(aosPeople);// 同程信息实际出行人
param.setPreTravelPolicyList(aosPreTravelPolicies);// 同程政策
param.setApproveRuleType(0);//审批规则
SupplierOrderSyncDto supplierOrderSyncDto = new SupplierOrderSyncDto();
supplierOrderSyncDto.setParam(param);
Result result = postRequest.post(supplierOrderSyncUrl, supplierOrderSyncDto, Result.class);
System.out.println("result = " + result);
public void syncSupplierOrder(RouteOrder order) {
System.out.println("开始同步同程订单");
String success = result.getSuccess();
return Boolean.parseBoolean(success);
}
//同程Leg集合解析
private ArrayList<AOSItem> getAosItems(RouteOrder order) {
ArrayList<AOSItem> aosItems = new ArrayList<>();
AOSItem aosItem = new AOSItem();
LocalDateTime startDate = LocalDateTime.MAX;
LocalDateTime endDate = LocalDateTime.MIN;
StringBuilder departCityStr = new StringBuilder();
StringBuilder arriveCityStr = new StringBuilder();
//提取所有行程节点信息
List<Leg> legItems = order.getLegItems();
orderDomainService.queryLocation(legItems);
for (Leg leg : legItems) {
//开始时间
LocalDateTime startTime = leg.getStartTime();
if (startTime.isBefore(startDate)) {
startDate = startTime;
}
//结束时间
LocalDateTime endTime = leg.getEndTime();
if (endTime.isAfter(endDate)) {
endDate = endTime;
}
String departCity = leg.getOriginLocation().getLocationName();//出发城市名
String arriveCity = leg.getDestinationLocation().getLocationName();//到达城市名
departCityStr.append(departCity).append(",");
arriveCityStr.append(arriveCity).append(",");
}
// 移除最后一个逗号
if (!departCityStr.isEmpty()) {
departCityStr.setLength(departCityStr.length() - 1);
}
if (!arriveCityStr.isEmpty()) {
arriveCityStr.setLength(arriveCityStr.length() - 1);
}
aosItem.setStartDate(startDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));//行程最早时间
aosItem.setEndDate(endDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));//行程最晚时间
aosItem.setDepartCity(String.valueOf(departCityStr));//各行程节点出发城市
aosItem.setArriveCity(String.valueOf(arriveCityStr));//各行程节点到达城市
aosItem.setOtherCity("");//其它城市
aosItems.add(aosItem);
return aosItems;
}
}

View File

@ -5,5 +5,5 @@ import com.chint.domain.aggregates.order.RouteOrder;
import com.chint.domain.factoriy.order.RouteOrderFactory;
public interface SupplierOrderSync {
boolean syncSupplierOrder(RouteOrder order);
void syncSupplierOrder(RouteOrder order);
}

View File

@ -6,6 +6,4 @@ import lombok.Data;
@Data
public class OrderQueryData extends BaseQuery {
private Long routeId;
private String billcode;
}

View File

@ -4,6 +4,5 @@ import lombok.Data;
@Data
public class SyncLegData {
private Long routeId;
private String supplierName;
}

View File

@ -52,8 +52,6 @@ public class Constant {
public static final String ORDER_STATUS_PAYED_NAME = "已付款";
public static final int ORDER_STATUS_FINISH = 5;
public static final String ORDER_STATUS_FINISH_NAME = "已结束";
public static final int ORDER_STATUS_REJECT = -1;
public static final String ORDER_STATUS_REJECT_NAME = "审批拒绝";
// 规划节点状态
public static final int LEG_STATUS_PREPARE = 0;
@ -68,8 +66,6 @@ public class Constant {
public static final String LEG_STATUS_PAYED_NAME = "已付款";
public static final int LEG_STATUS_FINISH = 5;
public static final String LEG_STATUS_FINISH_NAME = "已结束";
public static final int LEG_STATUS_REJECT = -1;
public static final String LEG_STATUS_REJECT_NAME = "审批未通过";
// 规划节点运输方式
public static final int LEG_TYPE_TRAIN = 0;
@ -89,15 +85,13 @@ public class Constant {
public static final int LEG_EVENT_APPROVAL = 1;
public static final String LEG_EVENT_APPROVAL_NAME = "审批事件";
public static final int LEG_EVENT_NOT_ORDERED = 2;
public static final String LEG_EVENT_NOT_ORDERED_NAME = "同步事件";
public static final String LEG_EVENT_NOT_ORDERED_NAME = "审批事件";
public static final int LEG_EVENT_ORDERED = 3;
public static final String LEG_EVENT_ORDERED_NAME = "下单事件";
public static final int LEG_EVENT_PAYED = 4;
public static final String LEG_EVENT_PAYED_NAME = "付款事件";
public static final int LEG_EVENT_FINISH = 5;
public static final String LEG_EVENT_FINISH_NAME = "结束事件";
public static final int LEG_EVENT_REJECT = -1;
public static final String LEG_EVENT_REJECT_NAME = "拒绝事件";
// 金额
public static final String KEEP_TWO_DECIMAL_ZERO = "0.00";
@ -137,11 +131,9 @@ public class Constant {
public static final String TICKET_PATH = "/SwitchAPI/Order/Ticket";
public static final String C_TRIP_LOGIN_PATH = "/singlesignon/openapi/saml/login";
public static final String C_TRIP_ENTITY_ID = "/zhengtai";
public static final String C_TRIP_APP_ID = "zhengtai2024";
public static final String C_TRIP_CORP_ID = "zhengtai2024";
public static final String C_TRIP_APP_KEY = "obk_zhengtai2024"; // 测试appkey
public static final String C_TRIP_APP_SECURITY = "fI3}FZX+zUdxPa2W!R6I2gYO"; // 测试app秘钥
public static final String C_TRIP_H5_LOGIN = "/corpservice/authorize/getticket"; // 测试app秘钥
public static final String C_TRIP_CORP_ID = "zhengtai";
public static final String C_TRIP_APP_KEY = "obk_zhengtai"; // 测试appkey
public static final String C_TRIP_APP_SECURITY = "gV417qxpou5bFlh2C93c452T"; // 测试app秘钥
public static final String USER_SAVE_PATH = "/corpservice/CorpCustService/SaveCorpCustInfoList";
public static final String HOTEL_CITY_PATH = "/corpopenapi/HotelCity/GetCountryCityExtend";
public static final String HOTEL_COUNTRY_PATH = "/corpopenapi/HotelCity/GetCountry";
@ -165,21 +157,21 @@ public class Constant {
//同程
public static final String L_Y_BASE_URL = "https://api.qa.dttrip.cn";
public static final String L_Y_TOKEN_PATH = "/openapi/api/OAuth/v2/GetAccessToken";
public static final String L_Y_ORDER_PATH = "/openapi/api/TravelApplyOrder/ApplyOrderSync";
public static final String L_Y_ORDER_PATH = "openapi/api/TravelApplyOrder/ApplyOrderSync";
public static final String L_Y_USER_PATH = "/openapi/api/Employee/SyncEmployeeInfo";
public static final String L_Y_LOGIN_PATH = "/openapi/api/Employee/SSO";
public static final String L_Y_ACCOUNT = "4f9cb1080b564dd0a94aa95f7a19c8b5"; // 测试appkey
public static final String L_Y_PASSWORD = "1fD3SutgzfS48qznYQiq"; // 测试app秘钥
public static final String L_Y_SECRET = "WOHzCMvHd823iHgH"; // 测试app秘钥
public static final Integer L_Y_PLAT_PC = 0; //
public static final Integer L_Y_PLAT_H5 = 1; //
public static final Integer L_Y_ENTRANCE_HOME = 0; //
public static final Integer L_Y_ENTRANCE_AIR_ORDER = 11; //
public static final Integer L_Y_ENTRANCE_AIR_DETAIL = 1; //
public static final Integer L_Y_ENTRANCE_AIR_ORDER_OVERSEA = 22; //
public static final Integer L_Y_ENTRANCE_AIR_DETAIL_OVERSEA = 2; //
public static final Integer L_Y_ENTRANCE_HOTEL_ORDER = 33; //
public static final Integer L_Y_ENTRANCE_HOTEL_DETAIL = 3; //
public static final Integer L_Y_PLAT_PC = 0; // 测试app秘钥
public static final Integer L_Y_PLAT_H5 = 1; // 测试app秘钥
public static final Integer L_Y_ENTRANCE_HOME = 0; // 测试app秘钥
public static final Integer L_Y_ENTRANCE_AIR_ORDER = 11; // 测试app秘钥page
public static final Integer L_Y_ENTRANCE_AIR_DETAIL = 1; // 测试app秘钥
public static final Integer L_Y_ENTRANCE_AIR_ORDER_OVERSEA = 22; // 测试app秘钥
public static final Integer L_Y_ENTRANCE_AIR_DETAIL_OVERSEA = 2; // 测试app秘钥
public static final Integer L_Y_ENTRANCE_HOTEL_ORDER = 33; // 测试app秘钥
public static final Integer L_Y_ENTRANCE_HOTEL_DETAIL = 3; // 测试app秘钥
public static final Integer L_Y_TRAVEL_TYPE_ALL = 0; // 全部(因公因私)
public static final Integer L_Y_TRAVEL_TYPE_PERSON = 1; // (因公)
public static final Integer L_Y_TRAVEL_TYPE_NO_PERSON = 2; // (因私)

View File

@ -3,6 +3,7 @@ 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;
@ -22,7 +23,7 @@ public class CityRepositoryImpl implements CityRepository {
@Override
public CityEntity findByCityName(String name) {
return jdbcCityRepository.findByCityName(name);
return null;
}
}

View File

@ -26,7 +26,6 @@ public class RouteRepositoryImpl implements RouteRepository {
return jdbcRouteRepository.findByRouteId(orderId);
}
@Override
public RouteOrder findByFakeOrderNo(String fakeOrderNo) {
return jdbcRouteRepository.findByApproveOrderNo_FakeOrderNo(fakeOrderNo);

View File

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

View File

@ -1,12 +0,0 @@
package com.chint.infrastructure.util;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class DateTimeUtil {
public static String timeToStr(LocalDateTime input) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
return input.format(formatter);
}
}

View File

@ -16,9 +16,9 @@ public class JwtTokenAdminInterceptor implements HandlerInterceptor {
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
String token = request.getHeader(HEADER_TOKEN);
// if (request.getRequestURI().endsWith("/login")) {
// return true;
// }
if (request.getRequestURI().endsWith("/login")) {
return true;
}
if (request.getRequestURI().contains("/pubilc")) {
return true;
}

View File

@ -55,20 +55,6 @@ public class PostRequest {
return gson.fromJson(responseBody, responseType);
}
public <T> T post(HttpPost post, Class<T> responseType) {
String responseBody = null;
HttpEntity responseEntity = null;
HttpResponse response = null;
try {
response = client.execute(post);
responseEntity = response.getEntity();
responseBody = EntityUtils.toString(responseEntity, "UTF-8");
} catch (IOException e) {
throw new RuntimeException(e);
}
return gson.fromJson(responseBody, responseType);
}
public Gson gson() {
return gson;
}

View File

@ -62,7 +62,7 @@ public class CTripEstimateRequest {
.done()
.valuationProductInfo()
.addFlightProductInfo(flightProductInfo)
.addTrainProductInfo(trainProductInfo)
// .addTrainProductInfo(trainProductInfo)
.done()
.done()
.build();

View File

@ -1,19 +1,22 @@
package com.chint.interfaces.rest.ctrip;
import com.chint.domain.aggregates.user.User;
import com.chint.domain.exceptions.NotFoundException;
import com.chint.infrastructure.util.BaseContext;
import com.chint.infrastructure.util.Digest;
import com.chint.infrastructure.util.Result;
import com.chint.interfaces.rest.base.PostRequest;
import com.chint.interfaces.rest.ctrip.dto.login.*;
import com.chint.interfaces.rest.ctrip.dto.AuthenticationResponseList;
import com.chint.interfaces.rest.ctrip.dto.login.CTripAuthLoginParam;
import com.chint.interfaces.rest.ctrip.dto.login.CTripHSingleLoginParam;
import com.chint.interfaces.rest.ctrip.dto.login.CTripLoginParam;
import com.chint.interfaces.rest.ly.dto.LYBaseRequest;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@ -21,8 +24,6 @@ import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
@ -49,7 +50,6 @@ public class CTripLoginRequest {
//H5单点登录
private String singleLoginUrl = C_TRIP_BASE_URL + C_TRIP_SINGLE_LOGIN;
private String singleTokenUrl = C_TRIP_BASE_URL + C_TRIP_H5_LOGIN;
private String IDPEntityID = C_TRIP_ENTITY_ID;
private String corpId = C_TRIP_CORP_ID;
@ -66,26 +66,26 @@ public class CTripLoginRequest {
authLoginParam.setTicket(ticket);
String appKey = C_TRIP_APP_KEY;
String uid = StringUtils.isNotBlank(authLoginParam.getUID()) ? authLoginParam.getUID() : "";
String uid = StringUtils.isNotBlank(authLoginParam.getUID())?authLoginParam.getUID():"";
String employeeId = StringUtils.isNotBlank(authLoginParam.getEmployeeID()) ? authLoginParam.getEmployeeID() : "";
String email = StringUtils.isNotBlank(authLoginParam.getEmail()) ? authLoginParam.getEmail() : "";
String ta = StringUtils.isNotBlank(authLoginParam.getTA()) ? authLoginParam.getTA() : "";
Integer forCorp = authLoginParam.getForCorp() == null ? authLoginParam.getForCorp() : 0;
String employeeId = StringUtils.isNotBlank(authLoginParam.getEmployeeID())?authLoginParam.getEmployeeID():"";
String email = StringUtils.isNotBlank(authLoginParam.getEmail())?authLoginParam.getEmail():"";
String ta = StringUtils.isNotBlank(authLoginParam.getTA())?authLoginParam.getTA():"";
Integer forCorp = authLoginParam.getForCorp() == null? authLoginParam.getForCorp():0;
String forCopStr = forCorp.toString();
String cost1 = StringUtils.isNotBlank(authLoginParam.getCost1()) ? authLoginParam.getCost1() : "";
if (isContainsChinese(cost1)) {
String cost1 = StringUtils.isNotBlank(authLoginParam.getCost1())?authLoginParam.getCost1():"";
if (isContainsChinese(cost1)){
ByteBuffer byteBuffer = StandardCharsets.UTF_8.encode(cost1);
cost1 = StandardCharsets.UTF_8.decode(byteBuffer).toString();
}
String cost2 = StringUtils.isNotBlank(authLoginParam.getCost2()) ? authLoginParam.getCost2() : "";
if (isContainsChinese(cost2)) {
String cost2 = StringUtils.isNotBlank(authLoginParam.getCost2())?authLoginParam.getCost2():"";
if (isContainsChinese(cost2)){
ByteBuffer byteBuffer = StandardCharsets.UTF_8.encode(cost2);
cost2 = StandardCharsets.UTF_8.decode(byteBuffer).toString();
}
String cost3 = StringUtils.isNotBlank(authLoginParam.getCost3()) ? authLoginParam.getCost3() : "";
if (isContainsChinese(cost3)) {
String cost3 = StringUtils.isNotBlank(authLoginParam.getCost3())?authLoginParam.getCost3():"";
if (isContainsChinese(cost3)){
ByteBuffer byteBuffer = StandardCharsets.UTF_8.encode(cost3);
cost3 = StandardCharsets.UTF_8.decode(byteBuffer).toString();
}
@ -93,7 +93,7 @@ public class CTripLoginRequest {
String finallySign =
Digest.md5(appKey + uid + employeeId + email + ta + forCopStr + cost1 + cost2 + cost3 + mdAppSecurity);
Digest.md5(appKey+uid+employeeId+email+ta+forCopStr+cost1+cost2+cost3+mdAppSecurity);
authLoginParam.setSignature(finallySign);
// Result post = postRequest.post(authLoginUrl, authLoginParam, Result.class);
@ -101,12 +101,13 @@ public class CTripLoginRequest {
// HttpClient client = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(authLoginUrl);
List entitys = new ArrayList<>();
entitys.add(new BasicNameValuePair("AppKey", appKey));
entitys.add(new BasicNameValuePair("Token", token));
entitys.add(new BasicNameValuePair("Ticket", ticket));
entitys.add(new BasicNameValuePair("EmployeeID", employeeId));
entitys.add(new BasicNameValuePair("Signature", finallySign));
entitys.add(new BasicNameValuePair("ForCorp", "0"));
entitys.add(new BasicNameValuePair("AppKey",appKey));
entitys.add(new BasicNameValuePair("Token",token));
entitys.add(new BasicNameValuePair("Ticket",ticket));
entitys.add(new BasicNameValuePair("EmployeeID",authLoginParam.getEmployeeID()));
entitys.add(new BasicNameValuePair("Signature",finallySign));
entitys.add(new BasicNameValuePair("ForCorp","0"));
try {
httpPost.setEntity(new UrlEncodedFormEntity(entitys));
@ -122,64 +123,55 @@ public class CTripLoginRequest {
}
public H5Response hSingleLogin() {
CTripHSingleLoginParam hSingleLoginParam = new CTripHSingleLoginParam();
User currentUser = BaseContext.getCurrentUser();
H5LoginToken h5TokenResponse = postRequest.post(singleTokenUrl, H5TicketModel.build(), H5LoginToken.class);
String token = h5TokenResponse.getToken();
public HttpResponse hSingleLogin(CTripHSingleLoginParam hSingleLoginParam) {
String ticket = ticketRequest.loadTicket();
String token = tokenRequest.getToken();
String accessUserId = C_TRIP_APP_KEY;
String employeeId = String.valueOf(currentUser.getEmployeeNo());
String corpPayType = StringUtils.isNotBlank(hSingleLoginParam.getCorpPayType()) ?
hSingleLoginParam.getCorpPayType() : "public";
String employeeId = StringUtils.isNotBlank(hSingleLoginParam.getEmployeeId())?hSingleLoginParam.getEmployeeId():"";
String corpPayType = StringUtils.isNotBlank(hSingleLoginParam.getCorpPayType())?
hSingleLoginParam.getCorpPayType():"public";
String costCenter1 = StringUtils.isNotBlank(hSingleLoginParam.getCostCenter1()) ?
hSingleLoginParam.getCostCenter1() : "";
if (isContainsChinese(costCenter1)) {
String costCenter1 = StringUtils.isNotBlank(hSingleLoginParam.getCostCenter1())?
hSingleLoginParam.getCostCenter1():"";
if (isContainsChinese(costCenter1)){
ByteBuffer byteBuffer = StandardCharsets.UTF_8.encode(costCenter1);
costCenter1 = StandardCharsets.UTF_8.decode(byteBuffer).toString();
}
String costCenter2 = StringUtils.isNotBlank(hSingleLoginParam.getCostCenter2()) ?
hSingleLoginParam.getCostCenter2() : "";
if (isContainsChinese(costCenter2)) {
String costCenter2 = StringUtils.isNotBlank(hSingleLoginParam.getCostCenter2())?
hSingleLoginParam.getCostCenter2():"";
if (isContainsChinese(costCenter2)){
ByteBuffer byteBuffer = StandardCharsets.UTF_8.encode(costCenter2);
costCenter2 = StandardCharsets.UTF_8.decode(byteBuffer).toString();
}
String costCenter3 = StringUtils.isNotBlank(hSingleLoginParam.getCostCenter3()) ?
hSingleLoginParam.getCostCenter3() : "";
if (isContainsChinese(costCenter3)) {
String costCenter3 = StringUtils.isNotBlank(hSingleLoginParam.getCostCenter3())?
hSingleLoginParam.getCostCenter3():"";
if (isContainsChinese(costCenter3)){
ByteBuffer byteBuffer = StandardCharsets.UTF_8.encode(costCenter3);
costCenter3 = StandardCharsets.UTF_8.decode(byteBuffer).toString();
}
String mdAppSecurity = getMD5Hash(C_TRIP_APP_SECURITY);
String signOrigin = accessUserId + employeeId + corpPayType + costCenter1 + costCenter2 + costCenter3 + mdAppSecurity;
System.out.println(signOrigin);
String mdAppSecurity = Digest.md5(C_TRIP_APP_SECURITY);
String finallySign =
getMD5Hash(signOrigin);
Digest.md5(accessUserId+employeeId+corpPayType+costCenter1+costCenter2+costCenter3+mdAppSecurity);
hSingleLoginParam.setSignature(finallySign);
HttpPost httpPost = new HttpPost(hSinngleLoginUrl);
List entitys = new ArrayList<>();
entitys.add(new BasicNameValuePair("accessUserId", accessUserId));
entitys.add(new BasicNameValuePair("employeeId", employeeId));
entitys.add(new BasicNameValuePair("token", token));
entitys.add(new BasicNameValuePair("appId", C_TRIP_APP_ID));
entitys.add(new BasicNameValuePair("signature", finallySign));
entitys.add(new BasicNameValuePair("corpPayType", corpPayType));
entitys.add(new BasicNameValuePair("accessUserId",accessUserId));
entitys.add(new BasicNameValuePair("employeeId",employeeId));
entitys.add(new BasicNameValuePair("token",token));
entitys.add(new BasicNameValuePair("appId","zhengtai"));
entitys.add(new BasicNameValuePair("signature",finallySign));
entitys.add(new BasicNameValuePair("corpPayType","public"));
try {
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(entitys, "UTF-8");
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(entitys,"UTF-8");
httpPost.setEntity(entity);
HttpClient client = new DefaultHttpClient();
try {
HttpResponse execute = client.execute(httpPost);
String body = EntityUtils.toString(execute.getEntity(), "UTF-8");
String url = getUrlFromHtml(body);
H5Response h5Response = new H5Response();
h5Response.setSuccess(true);
h5Response.setRedirectUrl(url);
return h5Response;
return client.execute(httpPost);
} catch (IOException e) {
throw new RuntimeException(e);
}
@ -194,52 +186,4 @@ public class CTripLoginRequest {
return matcher.find();
}
public H5Response h5Login() {
User currentUser = BaseContext.getCurrentUser();
CTripHSingleLoginParam cTripHSingleLoginParam = new CTripHSingleLoginParam();
cTripHSingleLoginParam.setAppId(C_TRIP_APP_KEY);
cTripHSingleLoginParam.setEmployeeId(String.valueOf(currentUser.getEmployeeNo()));
cTripHSingleLoginParam.setToken(tokenRequest.getToken());
cTripHSingleLoginParam.setAppId("zhengtai");
cTripHSingleLoginParam.setCorpPayType("public");
String finallySign =
Digest.md5(C_TRIP_APP_KEY + currentUser.getEmployeeNo() + "public" + Digest.md5(C_TRIP_APP_SECURITY));
cTripHSingleLoginParam.setSignature(finallySign);
return postRequest.post(hSinngleLoginUrl, cTripHSingleLoginParam, H5Response.class);
}
public String getMD5Hash(String source) {
StringBuilder sb = new StringBuilder();
MessageDigest md5;
try {
md5 = MessageDigest.getInstance("MD5");
md5.update(source.getBytes());
for (byte b : md5.digest()) {
sb.append(String.format("%02x", b));
}
return sb.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return null;
}
private static String getUrlFromHtml(String htmlContent) {
String regexPattern = "var config = \\{\"url\":\"(.*?)\",\"appid\":";
Pattern pattern = Pattern.compile(regexPattern);
Matcher matcher = pattern.matcher(htmlContent);
if (matcher.find()) {
return matcher.group(1);
} else {
throw new NotFoundException(NOT_FOUND);
}
}
}

View File

@ -1,4 +0,0 @@
package com.chint.interfaces.rest.ctrip;
public class CTripSyncRequest {
}

View File

@ -3,14 +3,13 @@ package com.chint.interfaces.rest.ctrip;
import com.chint.domain.aggregates.user.User;
import com.chint.infrastructure.util.BaseContext;
import com.chint.interfaces.rest.base.PostRequest;
import com.chint.interfaces.rest.ctrip.dto.AuthenticationResponseList;
import com.chint.interfaces.rest.ctrip.dto.user.AuthenticationEntity;
import com.chint.interfaces.rest.ctrip.dto.user.AuthenticationInfo;
import com.chint.interfaces.rest.ctrip.dto.user.AuthenticationListRequest;
import com.chint.interfaces.rest.user.UserHttpRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.chint.interfaces.rest.ctrip.dto.AuthenticationResponseList;
import java.util.List;
import static com.chint.infrastructure.constant.Constant.*;
@ -28,7 +27,6 @@ public class CTripUserSaveRequest {
private final String userUrl = C_TRIP_BASE_URL + C_TRIP_USER_SAVE_PATH;
public void saveUserToCTrip() {
User currentUser = BaseContext.getCurrentUser();
User user = userHttpRequest.loadUserInfo(currentUser);
@ -37,12 +35,13 @@ public class CTripUserSaveRequest {
AuthenticationListRequest authenticationListRequest = new AuthenticationListRequest();
authenticationListRequest.setAppkey(C_TRIP_APP_KEY);
authenticationListRequest.setTicket(ticket);
authenticationListRequest.setCorporationID(C_TRIP_CORP_ID);
authenticationListRequest.setCorporationID("zhengtai");
AuthenticationInfo authenticationInfo = new AuthenticationInfo();
authenticationInfo.setSequence("0");
authenticationInfo.setAuthentication(authenticationEntity);
authenticationListRequest.setAuthenticationInfoList(List.of(authenticationInfo));
postRequest.post(userUrl, authenticationListRequest, AuthenticationResponseList.class);
AuthenticationResponseList post = postRequest.post(userUrl, authenticationInfo, AuthenticationResponseList.class);
System.out.println(post);
}
@ -50,7 +49,7 @@ public class CTripUserSaveRequest {
AuthenticationEntity authenticationEntity = new AuthenticationEntity();
authenticationEntity.setName(user.getName());
authenticationEntity.setEmployeeID(user.getEmployeeNo().toString());
// authenticationEntity.setRankName(user.getRankCode());
authenticationEntity.setRankName(user.getRankCode());
authenticationEntity.setValid(user.getWorkStatus());
authenticationEntity.setSubAccountName("zhengtai_提前审批测试");
return authenticationEntity;

View File

@ -1,10 +1,7 @@
package com.chint.interfaces.rest.ctrip.dto.approval;
import lombok.Data;
import java.util.List;
@Data
public class PassengerDetail {
// 姓名 - 必填
@ -65,10 +62,4 @@ public class PassengerDetail {
// Getters and setters for each field would be included below...
public static PassengerDetail of(String employeeNo) {
PassengerDetail passengerDetail = new PassengerDetail();
passengerDetail.setEID(employeeNo);
return passengerDetail;
}
}

View File

@ -1,16 +1,10 @@
package com.chint.interfaces.rest.ctrip.dto.approval.hotel;
import com.chint.infrastructure.util.DateTimeUtil;
import com.chint.interfaces.rest.ctrip.dto.approval.CurrencyType;
import com.chint.interfaces.rest.ctrip.dto.approval.PassengerDetail;
import lombok.Data;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
@Data
public class HotelEndorsementDetail {
// 产品类型
@ -74,30 +68,4 @@ public class HotelEndorsementDetail {
private long preVerifyFields;
// Getters and setters...
public static HotelEndorsementDetail of(List<String> cityCodes) {
HotelEndorsementDetail hotelEndorsementDetail = new HotelEndorsementDetail();
hotelEndorsementDetail.setCheckInCityCodes(cityCodes);
return hotelEndorsementDetail;
}
public HotelEndorsementDetail passenger(PassengerDetail passengerDetail) {
if (this.passengerList == null) {
this.passengerList = new ArrayList<>();
}
this.passengerList.add(passengerDetail);
return this;
}
public HotelEndorsementDetail starTime(LocalDateTime startTime) {
this.checkInDateBegin = DateTimeUtil.timeToStr(startTime);
this.checkOutDateBegin = DateTimeUtil.timeToStr(startTime);
return this;
}
public HotelEndorsementDetail endTime(LocalDateTime endTime) {
this.checkInDateEnd = DateTimeUtil.timeToStr(endTime);
this.checkOutDateEnd = DateTimeUtil.timeToStr(endTime);
return this;
}
}

View File

@ -9,9 +9,4 @@ public class RankInfo {
private String rankName;
// Getters and setters...
public static RankInfo of(String rankName) {
RankInfo rankInfo = new RankInfo();
rankInfo.setRankName(rankName);
return rankInfo;
}
}

View File

@ -1,9 +0,0 @@
package com.chint.interfaces.rest.ctrip.dto.login;
import lombok.Data;
@Data
public class H5LoginToken {
private String Token;
private boolean Success;
}

View File

@ -1,9 +0,0 @@
package com.chint.interfaces.rest.ctrip.dto.login;
import lombok.Data;
@Data
public class H5Response {
private String redirectUrl;
private boolean success;
}

View File

@ -1,19 +0,0 @@
package com.chint.interfaces.rest.ctrip.dto.login;
import lombok.Data;
import static com.chint.infrastructure.constant.Constant.C_TRIP_APP_KEY;
import static com.chint.infrastructure.constant.Constant.C_TRIP_APP_SECURITY;
@Data
public class H5TicketModel {
private String AppKey;
private String AppSecurity;
public static H5TicketModel build(){
H5TicketModel h5TicketModel = new H5TicketModel();
h5TicketModel.setAppKey(C_TRIP_APP_KEY);
h5TicketModel.setAppSecurity(C_TRIP_APP_SECURITY);
return h5TicketModel;
}
}

View File

@ -1,11 +0,0 @@
package com.chint.interfaces.rest.ctrip.dto.login;
import lombok.Data;
@Data
public class PageViewData {
private String serviceStatus;
private boolean success;
private String url;
private String ssoType;
}

View File

@ -29,7 +29,6 @@ public class LYUserRequest {
private String userUrl = L_Y_BASE_URL + L_Y_USER_PATH;
public boolean saveCurrentUser() {
System.out.println("saveCurrentUser");
User currentUser = BaseContext.getCurrentUser();
userHttpRequest.loadUserInfo(currentUser);
EmployeeEntity employeeEntity = user2LYEmployee(currentUser);

View File

@ -1,26 +0,0 @@
package com.chint.interfaces.rest.ly.dto.applyordersync;
import lombok.Data;
import java.util.List;
@Data
public class SupplierOrderParam {
private Integer outEmployeeIdType; //外部人员Id类型
private String outTravelApplyNo;//外部同程单单号
private Integer travelApplyType;//同程类型
private Integer status;//同程单状态
private String travelApplyTime;//同程单申请时间
private String travelUpdateTime;//同程单更新时间
private Integer operationType;//操作类型
private String outEmployeeId;//外部员工ID申请人
private String travelDescription;//同程内容
private String bookableProducts;//可预订产品
private List<AOSItem> itemList;//同程内容
private List<AOSPerson> personList;//同程人信息实际出行人
private List<AOSPreTravelPolicy> preTravelPolicyList;//前置同程政策
private Integer approveRuleType;//审批规则类型
}

View File

@ -1,9 +0,0 @@
package com.chint.interfaces.rest.ly.dto.applyordersync;
import com.chint.interfaces.rest.ly.dto.LYBaseRequest;
import lombok.Data;
@Data
public class SupplierOrderSyncDto extends LYBaseRequest {
private SupplierOrderParam param;
}

View File

@ -1,11 +0,0 @@
package com.chint.interfaces.rest.ly.vo.estimateprice;
import lombok.Data;
import java.util.List;
@Data
public class HotelInfo {
private String hotelId;
private List<PriceInfo> priceList;
}

View File

@ -1,12 +0,0 @@
package com.chint.interfaces.rest.ly.vo.estimateprice;
import lombok.Data;
import java.time.LocalDateTime;
import java.util.List;
@Data
public class HotelListVo {
private List<HotelInfo> hotelList;
}

View File

@ -1,13 +0,0 @@
package com.chint.interfaces.rest.ly.vo.estimateprice;
import lombok.Data;
import java.time.LocalDateTime;
@Data
public class PriceInfo {
private LocalDateTime saleDate;
private int paymentType;
private double price;
}

View File

@ -47,8 +47,8 @@ public class UserHttpRequestImpl implements UserHttpRequest {
level = level.substring(0, level.length() - 3) + "M0";
}
TravelRankDTO loadTravelRank = loadTravelRank(new TravelRankParam(level));
// user.setRankCode(loadTravelRank.getLEVEL_MAPPING_CODE());
user.setRankCode("测试职级");
user.setRankCode(loadTravelRank.getLEVEL_MAPPING_CODE());
// user.setRankCode("M0");
return user;
}

View File

@ -3,6 +3,7 @@ package com.chint;
import com.chint.domain.aggregates.user.User;
import com.chint.domain.repository.CityRepository;
import com.chint.infrastructure.util.BaseContext;
import com.chint.infrastructure.util.Result;
import com.chint.interfaces.rest.ctrip.CTripEstimateRequest;
import com.chint.interfaces.rest.ctrip.CTripLocationHttpRequest;
import com.chint.interfaces.rest.ctrip.CTripLoginRequest;
@ -14,6 +15,7 @@ import com.chint.interfaces.rest.ctrip.dto.estimate.response.BookingRelatedApiRe
import com.chint.interfaces.rest.ctrip.dto.location.CTripCity;
import com.chint.interfaces.rest.ctrip.dto.location.CTripCountry;
import com.chint.interfaces.rest.ctrip.dto.login.CTripAuthLoginParam;
import com.chint.interfaces.rest.ctrip.dto.login.CTripHSingleLoginParam;
import com.chint.interfaces.rest.ctrip.dto.login.CTripLoginParam;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
@ -98,7 +100,7 @@ public class CTripTest {
HttpEntity entity = response.getEntity();
String result = null;
try {
result = EntityUtils.toString(entity, "UTF-8");
result = EntityUtils.toString(entity,"UTF-8");
} catch (IOException e) {
throw new RuntimeException(e);
}
@ -110,16 +112,24 @@ public class CTripTest {
@Test
void hSingleLogin() {
BaseContext.setCurrentUser(user);
System.out.println(loginRequest.hSingleLogin().getRedirectUrl());
}
// BaseContext.setCurrentUser(user);
// CTripLoginParam cTripLoginParam = new CTripLoginParam();
// cTripLoginParam.setEmployeeID(String.valueOf(user.getEmployeeNo()));
@Test
void h5LoginTest() {
BaseContext.setCurrentUser(user);
System.out.println(loginRequest.h5Login());
}
CTripHSingleLoginParam param = new CTripHSingleLoginParam();
param.setEmployeeId("230615020");
param.setCorpPayType("public");
HttpResponse response = loginRequest.hSingleLogin(param);
HttpEntity entity = response.getEntity();
String result = null;
try {
result = EntityUtils.toString(entity,"UTF-8");
} catch (IOException e) {
throw new RuntimeException(e);
}
System.out.println(result);
}
@Test
void estimate() {
BaseContext.setCurrentUser(user);

View File

@ -1,6 +1,6 @@
package com.chint;
import com.chint.domain.aggregates.base.BaseEntity;
import com.alibaba.fastjson2.JSON;
import com.chint.domain.aggregates.user.User;
import com.chint.infrastructure.constant.Constant;
import com.chint.infrastructure.util.BaseContext;
@ -11,18 +11,21 @@ import com.chint.interfaces.rest.ly.LYUserRequest;
import com.chint.interfaces.rest.ly.dto.applyordersync.*;
import com.chint.interfaces.rest.ly.dto.commonresult.Result;
import com.chint.interfaces.rest.ly.dto.estimateprice.*;
import com.chint.interfaces.rest.ly.vo.estimateprice.HotelListVo;
import com.chint.interfaces.rest.ly.vo.estimateprice.TrainPriceVo;
import com.google.gson.Gson;
import com.google.gson.internal.LinkedTreeMap;
import com.google.gson.reflect.TypeToken;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
import static com.chint.infrastructure.constant.Constant.*;
@ -71,8 +74,8 @@ public class LYTest {
void ticketNewPrice() {
String flyPriceUrl = Constant.L_Y_BASE_URL + Constant.L_Y_FLY_PRICE;
TicketNewPrice ticketNewPrice = new TicketNewPrice();
ticketNewPrice.setOrderSerialNo("");//订单号
Description<TicketNewPrice> description = new Description<>();
ticketNewPrice.setOrderSerialNo("");
Description<TicketNewPrice> description = new Description<TicketNewPrice>();
description.setParam(ticketNewPrice);
Result post = postRequest.post(flyPriceUrl, description, Result.class);
System.out.println(post);
@ -100,7 +103,7 @@ public class LYTest {
Description<HotleMinPrice> description = new Description<>();
description.setParam(hotleMinPrice);
Result post = postRequest.post(minPriceUrl, description, Result.class);
System.out.println(post);
}
//火车票最高价查询
@ -206,62 +209,6 @@ public class LYTest {
}
//同步同程订单
@Test
void syncSupplierOrder() {
String supplierOrderSyncUrl = Constant.L_Y_BASE_URL + Constant.L_Y_ORDER_PATH;
SupplierOrderParam param = new SupplierOrderParam();
param.setOutEmployeeIdType(0);
param.setOutTravelApplyNo("string");
param.setTravelApplyType(1); //同程类型
param.setStatus(1);
/*
时间转换
LocalDateTime localDateTime = LocalDateTime.of(2024, 2, 6, 12, 57, 33, 6000000);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
String formattedDateTime = localDateTime.format(formatter);
DateTimeFormatter formatter1 = DateTimeFormatter.ISO_DATE_TIME;
LocalDateTime dateTime = LocalDateTime.parse(formattedDateTime, formatter1);*/
param.setTravelApplyTime("2024-02-05T02:24:49.601Z");
param.setTravelUpdateTime("2024-02-06T02:24:49.601Z");
param.setOperationType(1);
param.setOutEmployeeId("string");
param.setTravelDescription("string");
param.setBookableProducts("string");
//行程节点
ArrayList<AOSItem> aosItems = new ArrayList<>();
AOSItem aosItem = new AOSItem();
aosItem.setStartDate("2024-02-05");//行程最早时间
aosItem.setEndDate("2024-02-06");//行程最晚时间
aosItem.setDepartCity("string");
aosItem.setArriveCity("HGH");
aosItem.setOtherCity("string");
aosItems.add(aosItem);
//差旅人信息
ArrayList<AOSPerson> aosPeople = new ArrayList<>();
AOSPerson aosPerson = new AOSPerson();
aosPerson.setName("测试");
aosPerson.setRelation(0);
aosPerson.setPassengerType(0);
aosPerson.setOutEmployeeId("string");
aosPeople.add(aosPerson);
//同程政策
ArrayList<AOSPreTravelPolicy> aosPreTravelPolicies = new ArrayList<>();
AOSPreTravelPolicy aosPreTravelPolicy = new AOSPreTravelPolicy();
aosPreTravelPolicy.setPolicyCode("string");
aosPreTravelPolicy.setProductTypeId(0);
aosPreTravelPolicies.add(aosPreTravelPolicy);
param.setItemList(aosItems); // 同程节点内容
param.setPersonList(aosPeople);// 同程信息实际出行人
param.setPreTravelPolicyList(aosPreTravelPolicies);// 同程政策
param.setApproveRuleType(0);
SupplierOrderSyncDto supplierOrderSyncDto = new SupplierOrderSyncDto();
supplierOrderSyncDto.setParam(param);
Result post = postRequest.post(supplierOrderSyncUrl, supplierOrderSyncDto, Result.class);
System.out.println(post);
}
@Test
void loadToken() {
System.out.println(lyTokenRequest.loadToken());