优化代码

This commit is contained in:
lulz1 2024-03-16 22:46:14 +08:00
parent e10e0632c3
commit da61de44f2
4 changed files with 175 additions and 104 deletions

View File

@ -20,6 +20,7 @@ import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.stream.Stream;
import static com.chint.infrastructure.constant.CommonMessageConstant.SUCCESS;
@ -35,74 +36,168 @@ public class OrderDetailQuery {
private RouteRepository routeRepository;
// public Result<PageResult<Object>> orderDetailInfoPageQuery(AuthenticationSignDto authenticationDto) {
// Integer productType = authenticationDto.getProductType();
// String systemType = authenticationDto.getSystemType();
// Integer pageSize = authenticationDto.getPageSize();
// Integer pageNum = authenticationDto.getPageNum();
//
// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
// LocalDateTime targetTimeBegin = LocalDateTime.parse(authenticationDto.getStartTime(), formatter);
// LocalDateTime targetTimeEnd = LocalDateTime.parse(authenticationDto.getEndTime(), formatter);
// List<OrderDetail> orderDetailList = orderDetailRepository.findByUpdateTimeBetween(targetTimeBegin, targetTimeEnd);
// List<Object> orderDetailResList = new ArrayList<>();
// for (OrderDetail orderDetail : orderDetailList) {
// if (productType == 1) {
// FlightOrderDetail flightOrderDetail = orderDetail.getFlightOrderDetail();
//
// if (flightOrderDetail != null) {
// String receiptsNum = flightOrderDetail.getReceiptsNum();
// if (receiptsNum != null) {
// flightOrderDetail.setReceiptsNum(regetReceiptsNum(receiptsNum));
// }
// if (flightOrderDetail.getOrderStatus() != null && flightOrderDetail.getBelongSysType() != null && flightOrderDetail.getBelongSysType().equals(systemType)) {
// orderDetailResList.add(flightOrderDetail);
// }
// }
// }
// if (productType == 2) {
// HotelOrderDetail hotelOrderDetail = orderDetail.getHotelOrderDetail();
// if (hotelOrderDetail != null) {
// String receiptsNum = hotelOrderDetail.getReceiptsNum();
// if (receiptsNum != null) {
// hotelOrderDetail.setReceiptsNum(regetReceiptsNum(receiptsNum));
// }
// if (hotelOrderDetail.getBelongSysType() != null && hotelOrderDetail.getBelongSysType().equals(systemType)) {
// //这里添加过滤逻辑 如果该订单为同程酒店订单 并且金额为0 判断为 临时订单数据
// if (orderDetail.getSupplierName().equals(SUPPLIER_L_Y) && Double.parseDouble(hotelOrderDetail.getOrderAmount()) == 0)
// continue;
// orderDetailResList.add(hotelOrderDetail);
// }
// }
// }
// if (productType == 3) {
// TrainOrderDetail trainOrderDetail = orderDetail.getTrainOrderDetail();
// if (trainOrderDetail != null) {
// String receiptsNum = trainOrderDetail.getReceiptsNum();
// if (receiptsNum != null) {
// trainOrderDetail.setReceiptsNum(regetReceiptsNum(receiptsNum));
// }
// if (trainOrderDetail.getOrderStatus() != null && trainOrderDetail.getBelongSysType() != null && trainOrderDetail.getBelongSysType().equals(systemType)) {
// orderDetailResList.add(trainOrderDetail);
// }
// }
// }
// if (productType == 4) {
// CarOrderDetail carOrderDetail = orderDetail.getCarOrderDetail();
// if (carOrderDetail != null) {
// String receiptsNum = carOrderDetail.getReceiptsNum();
// if (receiptsNum != null) {
// carOrderDetail.setReceiptsNum(regetReceiptsNum(receiptsNum));
// }
// if (carOrderDetail.getOrderStatus() != null && carOrderDetail.getBelongSysType() != null && carOrderDetail.getBelongSysType().equals(systemType)) {
// orderDetailResList.add(carOrderDetail);
// }
// }
// }
// }
// List<Object> newres2 = orderDetailResList.stream().skip((long) (pageNum - 1) * pageSize).limit(pageSize).toList();
//
// return Result.Success(SUCCESS, PageResult.totalPageNum(Long.parseLong(String.valueOf(orderDetailResList.size())), newres2));
// }
public Result<PageResult<Object>> orderDetailInfoPageQuery(AuthenticationSignDto authenticationDto) {
Integer productType = authenticationDto.getProductType();
String systemType = authenticationDto.getSystemType();
Integer pageSize = authenticationDto.getPageSize();
Integer pageNum = authenticationDto.getPageNum();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime targetTimeBegin = LocalDateTime.parse(authenticationDto.getStartTime(), formatter);
LocalDateTime targetTimeEnd = LocalDateTime.parse(authenticationDto.getEndTime(), formatter);
List<OrderDetail> orderDetailList = orderDetailRepository.findByUpdateTimeBetween(targetTimeBegin, targetTimeEnd);
List<Object> orderDetailResList = new ArrayList<>();
for (OrderDetail orderDetail : orderDetailList) {
if (productType == 1) {
FlightOrderDetail flightOrderDetail = orderDetail.getFlightOrderDetail();
if (flightOrderDetail != null) {
String receiptsNum = flightOrderDetail.getReceiptsNum();
if (receiptsNum != null) {
flightOrderDetail.setReceiptsNum(regetReceiptsNum(receiptsNum));
}
if (flightOrderDetail.getBelongSysType() != null && flightOrderDetail.getBelongSysType().equals(systemType)) {
orderDetailResList.add(flightOrderDetail);
}
}
List<OrderDetail> orderDetailList = orderDetailRepository.findByUpdateTimeBetween(targetTimeBegin, targetTimeEnd);
Stream<Object> orderDetailStream = orderDetailList.stream().map(orderDetail -> {
switch (productType) {
case 1:
return processFlightOrderDetail(orderDetail, systemType);
case 2:
return processHotelOrderDetail(orderDetail, systemType);
case 3:
return processTrainOrderDetail(orderDetail, systemType);
case 4:
return processCarOrderDetail(orderDetail, systemType);
default:
return null;
}
if (productType == 2) {
HotelOrderDetail hotelOrderDetail = orderDetail.getHotelOrderDetail();
if (hotelOrderDetail != null) {
String receiptsNum = hotelOrderDetail.getReceiptsNum();
if (receiptsNum != null) {
hotelOrderDetail.setReceiptsNum(regetReceiptsNum(receiptsNum));
}
if (hotelOrderDetail.getBelongSysType() != null && hotelOrderDetail.getBelongSysType().equals(systemType)) {
//这里添加过滤逻辑 如果该订单为同程酒店订单 并且金额为0 判断为 临时订单数据
if (orderDetail.getSupplierName().equals(SUPPLIER_L_Y) && Double.parseDouble(hotelOrderDetail.getOrderAmount()) == 0)
continue;
orderDetailResList.add(hotelOrderDetail);
}
}
}).filter(Objects::nonNull);
List<Object> paginatedResults = orderDetailStream
.skip((long) (pageNum - 1) * pageSize)
.limit(pageSize)
.toList();
return Result.Success(SUCCESS, PageResult.totalPageNum((long) orderDetailList.size(), paginatedResults));
}
private Object processHotelOrderDetail(OrderDetail orderDetail, String systemType) {
HotelOrderDetail hotelOrderDetail = orderDetail.getHotelOrderDetail();
if (hotelOrderDetail != null &&
systemType.equals(hotelOrderDetail.getBelongSysType())) {
String receiptsNum = hotelOrderDetail.getReceiptsNum();
if (receiptsNum != null) {
hotelOrderDetail.setReceiptsNum(regetReceiptsNum(receiptsNum));
}
if (productType == 3) {
TrainOrderDetail trainOrderDetail = orderDetail.getTrainOrderDetail();
if (trainOrderDetail != null) {
String receiptsNum = trainOrderDetail.getReceiptsNum();
if (receiptsNum != null) {
trainOrderDetail.setReceiptsNum(regetReceiptsNum(receiptsNum));
}
if (trainOrderDetail.getBelongSysType() != null && trainOrderDetail.getBelongSysType().equals(systemType)) {
orderDetailResList.add(trainOrderDetail);
}
}
}
if (productType == 4) {
CarOrderDetail carOrderDetail = orderDetail.getCarOrderDetail();
if (carOrderDetail != null) {
String receiptsNum = carOrderDetail.getReceiptsNum();
if (receiptsNum != null) {
carOrderDetail.setReceiptsNum(regetReceiptsNum(receiptsNum));
}
if (carOrderDetail.getBelongSysType() != null && carOrderDetail.getBelongSysType().equals(systemType)) {
orderDetailResList.add(carOrderDetail);
}
}
// 仅当订单不是临时订单数据才加入结果列表
if (orderDetail.getOrderStatus() != null &&
!orderDetail.getSupplierName().equals(SUPPLIER_L_Y) &&
Double.parseDouble(hotelOrderDetail.getOrderAmount()) != 0) {
return hotelOrderDetail;
}
}
List<Object> newres2 = orderDetailResList.stream().skip((long) (pageNum - 1) * pageSize).limit(pageSize).toList();
return null;
}
return Result.Success(SUCCESS, PageResult.totalPageNum(Long.parseLong(String.valueOf(orderDetailResList.size())), newres2));
private Object processTrainOrderDetail(OrderDetail orderDetail, String systemType) {
TrainOrderDetail trainOrderDetail = orderDetail.getTrainOrderDetail();
if (trainOrderDetail != null &&
trainOrderDetail.getOrderStatus() != null &&
systemType.equals(trainOrderDetail.getBelongSysType())) {
String receiptsNum = trainOrderDetail.getReceiptsNum();
if (receiptsNum != null) {
trainOrderDetail.setReceiptsNum(regetReceiptsNum(receiptsNum));
}
return trainOrderDetail;
}
return null;
}
private Object processCarOrderDetail(OrderDetail orderDetail, String systemType) {
CarOrderDetail carOrderDetail = orderDetail.getCarOrderDetail();
if (carOrderDetail != null &&
carOrderDetail.getOrderStatus() != null &&
systemType.equals(carOrderDetail.getBelongSysType())) {
String receiptsNum = carOrderDetail.getReceiptsNum();
if (receiptsNum != null) {
carOrderDetail.setReceiptsNum(regetReceiptsNum(receiptsNum));
}
return carOrderDetail;
}
return null;
}
private Object processFlightOrderDetail(OrderDetail orderDetail, String systemType) {
FlightOrderDetail flightOrderDetail = orderDetail.getFlightOrderDetail();
if (flightOrderDetail != null &&
flightOrderDetail.getOrderStatus() != null &&
systemType.equals(flightOrderDetail.getBelongSysType())) {
String receiptsNum = flightOrderDetail.getReceiptsNum();
if (receiptsNum != null) {
flightOrderDetail.setReceiptsNum(regetReceiptsNum(receiptsNum));
}
return flightOrderDetail;
}
return null;
}

View File

@ -7,6 +7,7 @@ import com.chint.application.queryies.estimate.EstimatePrice;
import com.chint.domain.aggregates.location.CityEntity;
import com.chint.domain.aggregates.order.*;
import com.chint.domain.aggregates.user.User;
import com.chint.domain.exceptions.NotFoundException;
import com.chint.domain.repository.CityRepository;
import com.chint.domain.repository.RouteRepository;
import com.chint.domain.repository.UserRepository;
@ -34,6 +35,7 @@ import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static com.chint.infrastructure.constant.CommonMessageConstant.NOT_FOUND;
import static com.chint.infrastructure.constant.FSSCConstant.*;
import static com.chint.infrastructure.constant.LegConstant.LEG_TYPE_HOTEL;
import static com.chint.infrastructure.constant.LegConstant.LEG_TYPE_OTHER;
@ -381,7 +383,7 @@ public class OrderQuery {
originCity = cityEntities.stream().filter(cityEntity -> cityEntity
.getCityName()
.equals(leg.getOriginLocation().getLocationName()))
.findFirst().get();
.findFirst().orElseThrow(() -> new NotFoundException(NOT_FOUND));
scheduleDetailBuilder
.startCity(originCity.getCityName())
.startCityName(originCity.getCityName())
@ -392,7 +394,7 @@ public class OrderQuery {
destinationCity = cityEntities.stream().filter(cityEntity -> cityEntity
.getCityName()
.equals(leg.getDestinationLocation().getLocationName()))
.findFirst().get();
.findFirst().orElseThrow(() -> new NotFoundException(NOT_FOUND));
scheduleDetailBuilder
.endCityName(destinationCity.getCityName())
.endCity(destinationCity.getCityName())

View File

@ -15,7 +15,6 @@ import com.chint.interfaces.rest.ly.dto.strokepush.Param;
import com.chint.interfaces.rest.ly.dto.strokepush.StrokeController;
import com.chint.interfaces.rest.ly.dto.strokepush.StrokePushDTO;
import com.chint.interfaces.rest.ly.dto.strokepush.StrokePushResult;
import com.chint.interfaces.rest.ly.dto.strokepush.TrainChange.TrainChangeDto;
import com.chint.interfaces.rest.ly.dto.strokepush.TrainChange.TrainChangeParam;
import com.chint.interfaces.rest.ly.dto.strokepush.TrainChange.TrainChangeRequest;
import com.chint.interfaces.rest.ly.tools.GetObjectNature;
@ -70,10 +69,12 @@ public class CommonController {
int notifyType = notification.getNotifyType();
return switch (notifyType) {
//进行订单数据回推
case 1 -> getOrderFlight(notification);
case 3 -> getOrderHotel(notification);
case 5 -> getOrderTrain(notification);
case 6 -> getOrderCar(notification);
//50进行行程数据回推
case 50 -> getOrderType(notification);
default -> new LYNoteResponse("100", "OK");
};
@ -93,13 +94,12 @@ public class CommonController {
ResultBackCar.DataObject orderCar = jsonObj.toJavaObject(ResultBackCar.DataObject.class);
String orderSerialNo = orderCar.getOrder().getOrderSerialNo();
String travelApplyNo = orderCar.getTravelData().getTravelApplyNo();
OrderTravel orderTravel = new OrderTravel();
orderTravel.setOrderNo(orderSerialNo);
orderTravel.setTravelNo(travelApplyNo);
saveOrderTravel(orderTravel);
lyCallBackDataHandler.carCallBackData(orderSerialNo, 0);/*
lyCallBackDataHandler.carCallBackData(orderSerialNo, 0);
/*
if (subNotifyType == 2 || subNotifyType == 3 || subNotifyType == 1){
sendMsg(travelApplyNo);
}*/
@ -118,22 +118,16 @@ public class CommonController {
Object notifyData = notification.notifyData;
int subNotifyType = notification.getSubNotifyType();
if (Objects.nonNull(notifyData)) {
JSONObject jsonObj = JSON.parseObject(notifyData.toString());
ResultBackTrain orderTrain = jsonObj.toJavaObject(ResultBackTrain.class);
// OrderTravel orderTravel = new OrderTravel();
// orderTravel.setOrderNo(orderTrain.getOrderNo());
// orderTravel.setTravelNo( orderTrain.getTravelData().getTravelApplyNo());
// saveOrderTravel(orderTravel);
int ruleViolate = orderTrain.getRuleViolate() ? 1 : 0;
if (subNotifyType == 16) {
isOkTrain(ruleViolate, subNotifyType, orderTrain.getOrderNo());
changeTrain(ruleViolate, subNotifyType, orderTrain.getOrderNo());
}
lyCallBackDataHandler.trainCallBackData(orderTrain.getOrderNo(), Integer.valueOf(ruleViolate));
if (subNotifyType == 2 || subNotifyType == 3 || subNotifyType == 1) {
sendMsg(orderTrain.getTravelData().getTravelApplyNo());
@ -196,7 +190,7 @@ public class CommonController {
//改签
if (subNotifyType == 9) {
isOk(ruleViolate, subNotifyType, orderSerialNo);
changeFlight(ruleViolate, subNotifyType, orderSerialNo);
}
//正常流程
@ -224,18 +218,13 @@ public class CommonController {
boolean emptyFly = Objects.nonNull(common.getTravelBizOrderList().getFlightOrderList());
boolean emptyCar = Objects.nonNull(common.getTravelBizOrderList().getCarOrderList());
boolean emptyTrain = Objects.nonNull(common.getTravelBizOrderList().getTrainOrderList());
if (emptyHotel) {//酒店
NotifyData.HotelOrder hotelOrder = common.getTravelBizOrderList().getHotelOrderList().get(0);
OrderTravel orderTravel = new OrderTravel();
orderTravel.setOrderNo(hotelOrder.getOrderInfo().getOrderSerialNo());
orderTravel.setTravelNo(common.getTravelBizOrder().getTravelOrderNo());
saveOrderTravel(orderTravel);
return lyCallBackDataHandler.hotelCallBackData(hotelOrder.getOrderInfo().getOrderSerialNo(), hotelOrder.getOrderInfo().getRuleViolate() ? 1 : 0);
} else if (emptyFly) {//机票originalOrderNo
NotifyData.OrderDetails flyOrder = common.getTravelBizOrderList().getFlightOrderList().get(0).getOrderDetails();
OrderTravel orderTravel = new OrderTravel();
@ -246,13 +235,11 @@ public class CommonController {
} else if (emptyTrain) {//火车票
NotifyData.TrainOrderList.OrderTrain orderTrain = common.getTravelBizOrderList().getTrainOrderList().get(0);
OrderTravel orderTravel = new OrderTravel();
orderTravel.setOrderNo(orderTrain.getOrderNo());
orderTravel.setTravelNo(common.getTravelBizOrder().getTravelOrderNo());
saveOrderTravel(orderTravel);
return lyCallBackDataHandler.trainCallBackData(orderTrain.getOrderNo(), orderTrain.getRuleViolate() ? 1 : 0);
} else if (emptyCar) {
NotifyData.CarOrderList.Order orderCar = common.getTravelBizOrderList().getCarOrderList().get(0).getOrder();
OrderTravel orderTravel = new OrderTravel();
@ -285,27 +272,20 @@ public class CommonController {
/**
* 机票确认改签接口
*/
public void strokePush(FlyOkDTO flyOkDTO) {
StrokePushResult postData = postRequest.post(lyBaseUrl + lyConfirmPath, flyOkDTO, StrokePushResult.class);
public void changeFlightPush(FlyOkDTO flyOkDTO) {
postRequest.post(lyBaseUrl + lyConfirmPath, flyOkDTO, StrokePushResult.class);
log.info("调用了机票改签确认接口");
}
public LYNoteResponse isOk(Integer ruleViolate, Integer subNotifyType, String orderSerialNo) {
if (ruleViolate == 0 && subNotifyType == 9) {
FlyOkDTO freightDTO = new FlyOkDTO();
ParamFly param = new ParamFly();
param.setOrderSerialNo(orderSerialNo);
freightDTO.setParam(param);
strokePush(freightDTO);
return new LYNoteResponse("100", "OK");
} else if (ruleViolate == 1 && subNotifyType == 9) {
FlyOkDTO freightDTO = new FlyOkDTO();
ParamFly param = new ParamFly();
param.setOrderSerialNo(orderSerialNo);
strokePush(freightDTO);
freightDTO.setParam(param);
public LYNoteResponse changeFlight(Integer ruleViolate, Integer subNotifyType, String orderSerialNo) {
FlyOkDTO freightDTO = new FlyOkDTO();
ParamFly param = new ParamFly();
param.setOrderSerialNo(orderSerialNo);
changeFlightPush(freightDTO);
freightDTO.setParam(param);
//ruleViolate
if (ruleViolate == 1 && subNotifyType == 9) {
sendMsg(orderSerialNo);
return new LYNoteResponse("100", "OK");
}
return new LYNoteResponse("100", "OK");
}
@ -313,21 +293,17 @@ public class CommonController {
/**
* 火车确认改签接口
*/
public void getTrainOk(TrainChangeParam trainChangeParam) {
TrainChangeDto trainChangeDto = trainChangeRequest.trainChangeRequest(trainChangeParam);
public void changeTrainPush(TrainChangeParam trainChangeParam) {
trainChangeRequest.trainChangeRequest(trainChangeParam);
}
public LYNoteResponse isOkTrain(Integer ruleViolate, Integer subNotifyType, String orderSerialNo) {
public LYNoteResponse changeTrain(Integer ruleViolate, Integer subNotifyType, String orderSerialNo) {
TrainChangeParam trainChangeParam = new TrainChangeParam();
trainChangeParam.setOrderNo(orderSerialNo);
trainChangeParam.setApprovalStatus(1);
if (ruleViolate == 0 && subNotifyType == 16) {
getTrainOk(trainChangeParam);
return new LYNoteResponse("100", "OK");
} else if (ruleViolate == 1 && subNotifyType == 16) {
getTrainOk(trainChangeParam);
changeTrainPush(trainChangeParam);
if (ruleViolate == 1 && subNotifyType == 16) {
sendMsg(orderSerialNo);
return new LYNoteResponse("100", "OK");
}
return new LYNoteResponse("100", "OK");
}

View File

@ -25,8 +25,6 @@ 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.dto.search.response.car.CarDetailResponse;
import com.chint.interfaces.rest.ly.dto.search.response.filght.FlightOrderResponse;
import com.chint.interfaces.rest.ly.dto.search.response.hotel.HotelDetailResponse;
import com.chint.interfaces.rest.ly.dto.search.response.train.TrainDetailResponse;
import com.chint.interfaces.rest.ly.in.CommonController;
import com.chint.interfaces.rest.ly.vo.estimateprice.TrainPriceVo;
@ -825,7 +823,7 @@ public class LYTest {
@Test
void conform() {
commonController.isOk(0, 9, "T24031566810476306");
commonController.changeFlight(0, 9, "T24031566810476306");
}
@Test