feat: 结算拉取增加更多拉取方式

This commit is contained in:
lulz1 2024-06-13 13:36:13 +08:00
parent 925e4c5954
commit 88872c2922
22 changed files with 426 additions and 184 deletions

View File

@ -36,4 +36,9 @@ public class OrderRecordGenerateCommand extends Command {
this.setDate(date);
return this;
}
public OrderRecordGenerateCommand oneDate(String oneDate) {
this.setOneDate(oneDate);
return this;
}
}

View File

@ -7,4 +7,5 @@ public class RecordMonthSaveDTO {
private String date;
private String supplierName;
private Integer productType;
private String oneDate;
}

View File

@ -103,6 +103,7 @@ public class AutoWorkController {
.of(param.getSupplierName(), OrderRecordPuller.class);
//将昨天的结算数据生成为财务共享需要的数据
OrderRecordGenerateCommand command = Command.of(OrderRecordGenerateCommand.class)
.oneDate(param.getOneDate())
.supplierName(param.getSupplierName());
if (date != null) {
command.startTime(DateTimeUtil.firstDayOfMonth(date))

View File

@ -5,11 +5,14 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient;
import org.springframework.data.relational.core.mapping.Column;
import org.springframework.data.relational.core.mapping.Table;
import java.io.Serial;
import java.io.Serializable;
import java.util.List;
import java.util.Objects;
@Data
@AllArgsConstructor
@ -33,8 +36,23 @@ public class Location implements Serializable {
private Long cityId;
private Integer isHaveAirport;
private Integer locationType;
@Transient
private List<Location> childLocationList;
public boolean isInternal(){
public boolean isInternal() {
return isInternal == 1;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Location location = (Location) o;
return Objects.equals(locationPath, location.locationPath) && Objects.equals(locationPathName, location.locationPathName) && Objects.equals(locationName, location.locationName) && Objects.equals(locationEnName, location.locationEnName) && Objects.equals(locationShortName, location.locationShortName) && Objects.equals(firstPinYin, location.firstPinYin) && Objects.equals(parentLocationId, location.parentLocationId) && Objects.equals(isInternal, location.isInternal) && Objects.equals(level, location.level) && Objects.equals(cityId, location.cityId) && Objects.equals(isHaveAirport, location.isHaveAirport) && Objects.equals(locationType, location.locationType) && Objects.equals(childLocationList, location.childLocationList);
}
@Override
public int hashCode() {
return Objects.hash(locationPath, locationPathName, locationName, locationEnName, locationShortName, firstPinYin, parentLocationId, isInternal, level, cityId, isHaveAirport, locationType, childLocationList);
}
}

View File

@ -19,6 +19,7 @@ public interface LocationRepository {
List<Location> findAll();
Location findByCityIdAndLevelThree(Long cityId);
Location findByCityIdAndLevelFour(Long cityId);
@ -56,6 +57,8 @@ public interface LocationRepository {
Location findByCityName(String localName);
List<Location> findByParentId(Long parentId);
Location findByDistrictShotName(String name);
List<Location> findChinaCityByLevel(String locationNames, Integer level);

View File

@ -9,7 +9,8 @@ import com.chint.infrastructure.constant.LocationConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
import static com.chint.infrastructure.constant.LocationConstant.*;
@ -53,4 +54,47 @@ public class LocationDomainService {
default -> throw new NotFoundException(CommonMessageConstant.NOT_FOUND);
};
}
public List<Location> queryLocationAndChildren() {
// 1. 加载所有的 Location 到内存中
List<Location> allLocations = locationRepository.findAll().stream().distinct().toList();
// 2. Location 根据 ParentId 分组
Map<Long, List<Location>> locationsByParentId = allLocations.stream()
.filter(location -> location.getParentLocationId() != null)
.collect(Collectors.groupingBy(Location::getParentLocationId));
// 3. 递归设置子 Location
List<Location> rootLocations = new ArrayList<>();
Set<Long> visited = new HashSet<>();
for (Location location : allLocations) {
if (location.getParentLocationId() == null) {
rootLocations.add(location);
}
if (!location.getLocationType().equals(LOCATION_TYPE_COUNTY) &&
!location.getLocationType().equals(LOCATION_TYPE_DISTRICT) &&
!location.getLocationType().equals(LOCATION_TYPE_AIRPORT)) {
if (!visited.contains(location.getLocationId())) {
location.setChildLocationList(getChildren(location.getLocationId(), locationsByParentId, visited));
}
}
}
return rootLocations;
}
private List<Location> getChildren(Long parentId, Map<Long, List<Location>> locationsByParentId, Set<Long> visited) {
List<Location> children = locationsByParentId.getOrDefault(parentId, Collections.emptyList());
for (Location child : children) {
if (!visited.contains(child.getLocationId())) {
visited.add(child.getLocationId());
if (!child.getLocationType().equals(LOCATION_TYPE_COUNTY) &&
!child.getLocationType().equals(LOCATION_TYPE_DISTRICT) &&
!child.getLocationType().equals(LOCATION_TYPE_AIRPORT)) {
child.setChildLocationList(getChildren(child.getLocationId(), locationsByParentId, visited));
}
}
}
return children;
}
}

View File

@ -73,7 +73,10 @@ public class AuthenticateServiceImpl implements AuthenticateService {
private UserLoginResult getUserLoginResult(User user) {
UserLoginParam userLoginParam = user.getUserLoginParam();
user.setCompanyCode(userLoginParam.getCompanyCode());
String companyCode = userLoginParam.getCompanyCode();
if (companyCode != null && !companyCode.isEmpty()) {
user.setCompanyCode(companyCode);
}
user.setUserLoginParam(userLoginParam);
List<FsscSystem> fsscSystemList = user.getFsscSystemList();
Map<String, Object> claims = new HashMap<>();
@ -95,7 +98,7 @@ public class AuthenticateServiceImpl implements AuthenticateService {
}
@Override
public Token authenticateClient(AuthenticationDto authenticationDto) {
public Token authenticateClient(AuthenticationDto authenticationDto) {
//区分测试环境还是正式环境
String clientType;
if (envMark.equals("prod")) {

View File

@ -18,7 +18,7 @@ public class CTripOrderRecordPuller implements OrderRecordPuller {
@Override
public boolean pullTrainOrderRecord(OrderRecordGenerateCommand command) {
try {
cTripOrderRecordAutoSave.cTripCarRecordAutoSave(Optional.ofNullable(command.getDate()));
cTripOrderRecordAutoSave.cTripCarRecordAutoSave(command);
} catch (Exception e) {
e.printStackTrace();
return false;
@ -29,7 +29,7 @@ public class CTripOrderRecordPuller implements OrderRecordPuller {
@Override
public boolean pullFlightOrderRecord(OrderRecordGenerateCommand command) {
try {
cTripOrderRecordAutoSave.cTripFlightRecordAutoSave(Optional.ofNullable(command.getDate()));
cTripOrderRecordAutoSave.cTripFlightRecordAutoSave(command);
} catch (Exception e) {
e.printStackTrace();
return false;
@ -40,7 +40,7 @@ public class CTripOrderRecordPuller implements OrderRecordPuller {
@Override
public boolean pullHotelOrderRecord(OrderRecordGenerateCommand command) {
try {
cTripOrderRecordAutoSave.cTripHotelRecordAutoSave(Optional.ofNullable(command.getDate()));
cTripOrderRecordAutoSave.cTripHotelRecordAutoSave(command);
} catch (Exception e) {
e.printStackTrace();
return false;
@ -51,7 +51,7 @@ public class CTripOrderRecordPuller implements OrderRecordPuller {
@Override
public boolean pullCarOrderRecord(OrderRecordGenerateCommand command) {
try {
cTripOrderRecordAutoSave.cTripCarRecordAutoSave(Optional.ofNullable(command.getDate()));
cTripOrderRecordAutoSave.cTripCarRecordAutoSave(command);
} catch (Exception e) {
e.printStackTrace();
return false;

View File

@ -117,7 +117,16 @@ public class CTripOrderDetailImpl implements CTripOrderDetailRepository {
@Override
public void saveAllCTripFlightRecord(List<CTripFlightRecord> cTripFlightRecordList) {
jdbcCTripFlightRecordRepository.saveAll(cTripFlightRecordList);
if (cTripFlightRecordList.size() > 1000) {
int batchSize = 1000;
for (int i = 0; i < cTripFlightRecordList.size(); i += batchSize) {
int end = Math.min(i + batchSize, cTripFlightRecordList.size());
List<CTripFlightRecord> batch = cTripFlightRecordList.subList(i, end);
jdbcCTripFlightRecordRepository.saveAll(batch);
}
} else {
jdbcCTripFlightRecordRepository.saveAll(cTripFlightRecordList);
}
}
@Override
@ -137,7 +146,16 @@ public class CTripOrderDetailImpl implements CTripOrderDetailRepository {
@Override
public void saveAllCTripHotelRecord(List<CTripHotelRecord> cTripHotelRecordList) {
jdbcCTripHotelRecordRepository.saveAll(cTripHotelRecordList);
if (cTripHotelRecordList.size() > 1000) {
int batchSize = 1000;
for (int i = 0; i < cTripHotelRecordList.size(); i += batchSize) {
int end = Math.min(i + batchSize, cTripHotelRecordList.size());
List<CTripHotelRecord> batch = cTripHotelRecordList.subList(i, end);
jdbcCTripHotelRecordRepository.saveAll(batch);
}
} else {
jdbcCTripHotelRecordRepository.saveAll(cTripHotelRecordList);
}
}
@Override
@ -172,7 +190,16 @@ public class CTripOrderDetailImpl implements CTripOrderDetailRepository {
@Override
public void saveAllCTripCarRecord(List<CTripCarRecord> cTripCarRecordList) {
jdbcCTripCarRecordRepository.saveAll(cTripCarRecordList);
if (cTripCarRecordList.size() > 1000) {
int batchSize = 1000;
for (int i = 0; i < cTripCarRecordList.size(); i += batchSize) {
int end = Math.min(i + batchSize, cTripCarRecordList.size());
List<CTripCarRecord> batch = cTripCarRecordList.subList(i, end);
jdbcCTripCarRecordRepository.saveAll(batch);
}
} else {
jdbcCTripCarRecordRepository.saveAll(cTripCarRecordList);
}
}
@Override

View File

@ -184,6 +184,11 @@ public class LocationRepositoryImpl implements LocationRepository {
return jdbcLocationRepository.findByLocationNameAndLevelOrLocationNameAndLevel(localName, 3, localName, 4);
}
@Override
public List<Location> findByParentId(Long parentId) {
return jdbcLocationRepository.findByParentLocationId(parentId);
}
@Override
public Location findByDistrictShotName(String name) {

View File

@ -11,6 +11,7 @@ import java.util.List;
@Repository
public interface JdbcLocationRepository extends CrudRepository<Location, Long> {
List<Location> findByParentLocationId(Long parentLocationId);
Location findByCityIdAndLocationShortName(Long cityId, String locationShortName);

View File

@ -39,7 +39,7 @@ public class DateTimeUtil {
}
public static LocalDateTime strToTimeYYYYMMDD(String input) {
return LocalDateTime.parse(input, formatterDateYYYYMMDD);
return LocalDate.parse(input, formatterDateYYYYMMDD).atStartOfDay();
}
public static LocalDateTime strToTime(String input) {

View File

@ -0,0 +1,9 @@
package com.chint.interfaces.rest.ctrip.dto.order;
import lombok.Data;
@Data
public class BaseOrderResponse {
private Integer TotalSize;
private Integer TotalRecord;
}

View File

@ -1,13 +1,15 @@
package com.chint.interfaces.rest.ctrip.dto.order;
import com.chint.domain.aggregates.order.CarOrderDetail;
import com.chint.interfaces.rest.amap.BaseResponse;
import io.swagger.models.auth.In;
import lombok.Data;
import java.math.BigDecimal;
import java.util.List;
@Data
public class OrderCarResponse {
public class OrderCarResponse extends BaseOrderResponse {
private List<CarOrderAccountSettlementDetail> CarOrderAccountSettlementList;
private ResponseStatus Status;

View File

@ -1,12 +1,13 @@
package com.chint.interfaces.rest.ctrip.dto.order;
import com.chint.interfaces.rest.amap.BaseResponse;
import lombok.Data;
import java.util.Date;
import java.util.List;
@Data
public class OrderFlightResponse {
public class OrderFlightResponse extends BaseOrderResponse {
private List<FlightOrderAccountSettlementInfo> FlightOrderAccountSettlementList;
private Status Status;

View File

@ -1,12 +1,13 @@
package com.chint.interfaces.rest.ctrip.dto.order;
import com.chint.interfaces.rest.amap.BaseResponse;
import lombok.Data;
import java.math.BigDecimal;
import java.util.List;
@Data
public class OrderHotelResponse {
public class OrderHotelResponse extends BaseOrderResponse {
private List<HotelAccountSettlementInfo> LstHtlSettlement;
private Status Status;
@ -80,6 +81,7 @@ public class OrderHotelResponse {
private BigDecimal averagePrice;
}
@lombok.Data
public static class SettlementOrderDetail {
private long OrderId;
@ -246,7 +248,6 @@ public class OrderHotelResponse {
}
@lombok.Data
public static class SettlementHotelDetail {
private String HotelName;

View File

@ -12,6 +12,11 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.function.BiConsumer;
import static com.chint.infrastructure.constant.CTripConstant.*;
@ -59,17 +64,13 @@ public class CTripOrderDetailRequest {
public OrderFlightResponse getFlightOrder() {
LocalDateTime now = LocalDateTime.now();
LocalDateTime localDateTime = now.minusDays(1L);
return postRequest.post(flightOrderUrl,
getParamByDateFromAndDateTo(DateTimeUtil.timeToStr(localDateTime), DateTimeUtil.timeToStr(now)),
OrderFlightResponse.class);
return pageQueryFlightResponse(getParamByDateFromAndDateTo(DateTimeUtil.timeToStr(localDateTime), DateTimeUtil.timeToStr(now)));
}
public OrderFlightResponse getFlightOrder(String oneDate) {
LocalDateTime oneDateL = DateTimeUtil.strToTimeYYYYMMDD(oneDate);
LocalDateTime localDateTime = oneDateL.minusDays(1L);
return postRequest.post(flightOrderUrl,
getParamByDateFromAndDateTo(DateTimeUtil.timeToStr(localDateTime), DateTimeUtil.timeToStr(oneDateL)),
OrderFlightResponse.class);
return pageQueryFlightResponse(getParamByDateFromAndDateTo(DateTimeUtil.timeToStr(localDateTime), DateTimeUtil.timeToStr(oneDateL)));
}
public OrderFlightResponse getFlightOrderByDate(String date) {
@ -79,8 +80,8 @@ public class CTripOrderDetailRequest {
public OrderFlightResponse getFlightOrder(String dateFrom, String dateTo) {
return postRequest.post(flightOrderUrl, getParamByBatch(dateFrom, dateTo),
OrderFlightResponse.class);
return pageQueryFlightResponse(getParamByBatch(dateFrom, dateTo));
}
public OrderHotelResponse getHotelOrderByDate(String date) {
@ -91,22 +92,17 @@ public class CTripOrderDetailRequest {
public OrderHotelResponse getHotelOrder() {
LocalDateTime now = LocalDateTime.now();
LocalDateTime localDateTime = now.minusDays(1L);
return postRequest.post(hotelOrderUrl,
getParamByDateFromAndDateTo(DateTimeUtil.timeToStr(localDateTime), DateTimeUtil.timeToStr(now)),
OrderHotelResponse.class);
return pageQueryHotelResponse(getParamByDateFromAndDateTo(DateTimeUtil.timeToStr(localDateTime), DateTimeUtil.timeToStr(now)));
}
public OrderHotelResponse getHotelOrder(String oneDate) {
LocalDateTime oneDateL = DateTimeUtil.strToTimeYYYYMMDD(oneDate);
LocalDateTime localDateTime = oneDateL.minusDays(1L);
return postRequest.post(hotelOrderUrl,
getParamByDateFromAndDateTo(DateTimeUtil.timeToStr(localDateTime), DateTimeUtil.timeToStr(oneDateL)),
OrderHotelResponse.class);
return pageQueryHotelResponse(getParamByDateFromAndDateTo(DateTimeUtil.timeToStr(localDateTime), DateTimeUtil.timeToStr(oneDateL)));
}
public OrderHotelResponse getHotelOrder(String dateFrom, String dateTo) {
return postRequest.post(hotelOrderUrl, getParamByBatch(dateFrom, dateTo),
OrderHotelResponse.class);
return pageQueryHotelResponse(getParamByBatch(dateFrom, dateTo));
}
public OrderTrainResponse getTrainOrderByDate(String date) {
@ -145,22 +141,17 @@ public class CTripOrderDetailRequest {
public OrderCarResponse getCarOrder() {
LocalDateTime now = LocalDateTime.now();
LocalDateTime localDateTime = now.minusDays(1L);
return postRequest.post(carOrderUrl,
getParamByDateFromAndDateTo(DateTimeUtil.timeToStr(localDateTime), DateTimeUtil.timeToStr(now)),
OrderCarResponse.class);
return pageQueryCarResponse(getParamByDateFromAndDateTo(DateTimeUtil.timeToStr(localDateTime), DateTimeUtil.timeToStr(now)));
}
public OrderCarResponse getCarOrder(String oneDate) {
LocalDateTime oneDateL = DateTimeUtil.strToTimeYYYYMMDD(oneDate);
LocalDateTime localDateTime = oneDateL.minusDays(1L);
return postRequest.post(carOrderUrl,
getParamByDateFromAndDateTo(DateTimeUtil.timeToStr(localDateTime), DateTimeUtil.timeToStr(oneDateL)),
OrderCarResponse.class);
return pageQueryCarResponse(getParamByDateFromAndDateTo(DateTimeUtil.timeToStr(localDateTime), DateTimeUtil.timeToStr(oneDateL)));
}
public OrderCarResponse getCarOrder(String dateFrom, String dateTo) {
return postRequest.post(carOrderUrl, getParamByBatch(dateFrom, dateTo),
OrderCarResponse.class);
return pageQueryCarResponse(getParamByBatch(dateFrom, dateTo));
}
private OrderRecordParam getParamByDateFromAndDateTo(String dateFrom, String dateTo) {
@ -191,4 +182,77 @@ public class CTripOrderDetailRequest {
orderFlightParam.setTicket(ticketRequest.loadTicket());
return orderFlightParam;
}
private OrderHotelResponse pageQueryHotelResponse(OrderRecordParam param) {
return pageQueryResponse(
param,
hotelOrderUrl,
OrderHotelResponse.class,
(initialResponse, response) -> initialResponse.getLstHtlSettlement()
.addAll(response.getLstHtlSettlement())
);
}
private OrderFlightResponse pageQueryFlightResponse(OrderRecordParam param) {
return pageQueryResponse(
param,
flightOrderUrl,
OrderFlightResponse.class,
(initialResponse, response) -> initialResponse.getFlightOrderAccountSettlementList()
.addAll(response.getFlightOrderAccountSettlementList())
);
}
private OrderCarResponse pageQueryCarResponse(OrderRecordParam param) {
return pageQueryResponse(
param,
carOrderUrl,
OrderCarResponse.class,
(initialResponse, response) -> initialResponse.getCarOrderAccountSettlementList()
.addAll(response.getCarOrderAccountSettlementList())
);
}
private <T extends BaseOrderResponse> T pageQueryResponse(OrderRecordParam param, String url, Class<T> responseType, BiConsumer<T, T> mergeFunction) {
param.setPageIndex(1);
param.setPageSize(100);
// Initial request to get total size
T initialResponse = postRequest.post(url, param, responseType);
int totalSize = initialResponse.getTotalSize();
// List to hold all CompletableFuture instances
List<CompletableFuture<T>> futures = new ArrayList<>();
futures.add(CompletableFuture.completedFuture(initialResponse)); // Add initial response
// Create CompletableFuture for each page
for (int i = 2; i <= totalSize; i++) {
int pageIndex = i;
CompletableFuture<T> future = CompletableFuture.supplyAsync(() -> {
param.setPageIndex(pageIndex);
return postRequest.post(url, param, responseType);
});
futures.add(future);
}
// Combine all responses
CompletableFuture<Void> allOf = CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]));
CompletableFuture<T> combinedFuture = allOf.thenApply(v -> {
futures.forEach(future -> {
try {
T response = future.get();
mergeFunction.accept(initialResponse, response);
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
});
return initialResponse;
});
try {
return combinedFuture.get();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

View File

@ -1,5 +1,6 @@
package com.chint.interfaces.rest.ctrip.order;
import com.chint.application.commands.OrderRecordGenerateCommand;
import com.chint.domain.aggregates.order.order_record.ctrip_order_record.*;
import com.chint.domain.repository.CTripOrderDetailRepository;
import com.chint.infrastructure.util.DateTimeUtil;
@ -42,86 +43,107 @@ public class CTripOrderRecordAutoSave {
this.cTripCarRecordAutoSave(Optional.of(date));
}
public void cTripFlightRecordAutoSave(Optional<String> date) {
OrderFlightResponse flightOrder = date
.flatMap(it -> Optional.ofNullable(cTripOrderDetailRequest.getFlightOrderByDate(it)))
.orElseGet(() -> cTripOrderDetailRequest.getFlightOrder());
List<OrderFlightResponse.FlightOrderAccountSettlementInfo> flightOrderAccountSettlementList = flightOrder
.getFlightOrderAccountSettlementList();
cTripFlightRecordAutoSave(flightOrder);
}
public void cTripFlightRecordAutoSave(OrderRecordGenerateCommand command) {
OrderFlightResponse response = Optional.ofNullable(command.getOneDate())
.map(cTripOrderDetailRequest::getFlightOrder)
.or(() -> Optional.ofNullable(command.getDate())
.flatMap(it -> Optional.ofNullable(cTripOrderDetailRequest.getFlightOrderByDate(it))))
.orElseGet(cTripOrderDetailRequest::getFlightOrder);
cTripFlightRecordAutoSave(response);
}
private void cTripFlightRecordAutoSave(OrderFlightResponse response) {
List<OrderFlightResponse.FlightOrderAccountSettlementInfo> flightOrderAccountSettlementList = response.getFlightOrderAccountSettlementList();
if (flightOrderAccountSettlementList != null && !flightOrderAccountSettlementList.isEmpty()) {
List<OrderFlightResponse.FlightOrderSettlementInfo> flightOrderSettlementInfos = flightOrderAccountSettlementList
.stream()
List<String> recordIds = flightOrderAccountSettlementList.stream()
.flatMap(it -> it.getOrderSettlementList().stream())
.toList();
List<String> recordIds = flightOrderSettlementInfos
.stream()
.map(it -> String.valueOf(it.getOrderSettlementBaseInfo().getRecordID()))
.toList();
Map<String, CTripFlightRecord> cTripFlightRecordMap = cTripOrderDetailRepository.findFlightRecordByRecordIdIn(recordIds)
.stream()
.collect(Collectors.toMap(CTripFlightRecord::getRecordId, Function.identity()));
List<CTripFlightRecord> cTripFlightRecords = flightOrderSettlementInfos.stream()
.map(it -> {
//对数据库进行查找 如果发现已经存在 就使用查找出来的
OrderFlightResponse.FlightOrderSettlementBaseInfo orderSettlementBaseInfo = it.getOrderSettlementBaseInfo();
OrderFlightResponse.FlightTripRecordInfo flightTripRecordInfo = it.getFlightTripRecordInfo();
CTripFlightRecord record = cTripFlightRecordMap.get(String.valueOf(orderSettlementBaseInfo.getRecordID()));
if (record == null) {
record = CTripFlightRecord.of(
CTripFlightRecordBase.changeInfo(orderSettlementBaseInfo),
CTripFlightInfo.of(it.getOrderFlightInfo()),
CTripFlightBaseInfo.of(it.getOrderBaseInfo()),
CTripFlightTripInfo.of(flightTripRecordInfo));
} else {
Long originId = record.getId();
record = CTripFlightRecord.of(
CTripFlightRecordBase.changeInfo(orderSettlementBaseInfo),
CTripFlightInfo.of(it.getOrderFlightInfo()),
CTripFlightBaseInfo.of(it.getOrderBaseInfo()),
CTripFlightTripInfo.of(flightTripRecordInfo));
record.setId(originId);
}
if (it.getOrderPrintDetailInfo() != null) {
record.printInfo(CTripFlightPrintInfo.of(it.getOrderPrintDetailInfo()));
}
//补充额外的字段
OrderFlightResponse.FlightOrderBaseInfo orderBaseInfo = it.getOrderBaseInfo();
record.setRouteOrderNo(orderBaseInfo.getJourneyID());
OrderFlightResponse.FlightOrderPassenger orderPassengerInfo = it.getOrderPassengerInfo();
if (orderPassengerInfo != null) {
record.setTicketNo(orderPassengerInfo.getTicketNo());
record.setUserCode(orderPassengerInfo.getEmployeeID());
record.setUserName(orderPassengerInfo.getPassengerName());
} else {
record.setUserCode(orderBaseInfo.getEmployeeID());
record.setUserName(orderBaseInfo.getName());
}
record.setBookingUserCode(orderBaseInfo.getPreEmployeeID());
record.setBookingUserName(orderBaseInfo.getName());
record.setBookingUserPhone("");
return record;
}).toList();
List<CTripFlightRecord> cTripFlightRecords = flightOrderAccountSettlementList.stream()
.flatMap(it -> it.getOrderSettlementList().stream())
.map(it -> createOrUpdateFlightRecord(it, cTripFlightRecordMap))
.distinct()
.toList();
cTripOrderDetailRepository.saveAllCTripFlightRecord(cTripFlightRecords);
}
}
private CTripFlightRecord createOrUpdateFlightRecord(OrderFlightResponse.FlightOrderSettlementInfo it, Map<String, CTripFlightRecord> cTripFlightRecordMap) {
OrderFlightResponse.FlightOrderSettlementBaseInfo orderSettlementBaseInfo = it.getOrderSettlementBaseInfo();
OrderFlightResponse.FlightTripRecordInfo flightTripRecordInfo = it.getFlightTripRecordInfo();
CTripFlightRecord record = cTripFlightRecordMap.get(String.valueOf(orderSettlementBaseInfo.getRecordID()));
if (record == null) {
record = CTripFlightRecord.of(
CTripFlightRecordBase.changeInfo(orderSettlementBaseInfo),
CTripFlightInfo.of(it.getOrderFlightInfo()),
CTripFlightBaseInfo.of(it.getOrderBaseInfo()),
CTripFlightTripInfo.of(flightTripRecordInfo));
} else {
Long originId = record.getId();
record = CTripFlightRecord.of(
CTripFlightRecordBase.changeInfo(orderSettlementBaseInfo),
CTripFlightInfo.of(it.getOrderFlightInfo()),
CTripFlightBaseInfo.of(it.getOrderBaseInfo()),
CTripFlightTripInfo.of(flightTripRecordInfo));
record.setId(originId);
}
if (it.getOrderPrintDetailInfo() != null) {
record.printInfo(CTripFlightPrintInfo.of(it.getOrderPrintDetailInfo()));
}
// 补充额外的字段
OrderFlightResponse.FlightOrderBaseInfo orderBaseInfo = it.getOrderBaseInfo();
record.setRouteOrderNo(orderBaseInfo.getJourneyID());
OrderFlightResponse.FlightOrderPassenger orderPassengerInfo = it.getOrderPassengerInfo();
if (orderPassengerInfo != null) {
record.setTicketNo(orderPassengerInfo.getTicketNo());
record.setUserCode(orderPassengerInfo.getEmployeeID());
record.setUserName(orderPassengerInfo.getPassengerName());
} else {
record.setUserCode(orderBaseInfo.getEmployeeID());
record.setUserName(orderBaseInfo.getName());
}
record.setBookingUserCode(orderBaseInfo.getPreEmployeeID());
record.setBookingUserName(orderBaseInfo.getName());
record.setBookingUserPhone("");
return record;
}
public void cTripHotelRecordAutoSave(Optional<String> date) {
OrderHotelResponse hotelOrder = date
.flatMap(it -> Optional.ofNullable(cTripOrderDetailRequest.getHotelOrderByDate(it)))
.orElseGet(() -> cTripOrderDetailRequest.getHotelOrder());
cTripHotelRecordAutoSave(hotelOrder);
}
List<OrderHotelResponse.HotelAccountSettlementInfo> lstHtlSettlement = hotelOrder.getLstHtlSettlement();
public void cTripHotelRecordAutoSave(OrderRecordGenerateCommand command){
OrderHotelResponse response = Optional.ofNullable(command.getOneDate())
.map(cTripOrderDetailRequest::getHotelOrder)
.or(() -> Optional.ofNullable(command.getDate())
.flatMap(it -> Optional.ofNullable(cTripOrderDetailRequest.getHotelOrder(it))))
.orElseGet(cTripOrderDetailRequest::getHotelOrder);
cTripHotelRecordAutoSave(response);
}
private void cTripHotelRecordAutoSave(OrderHotelResponse response) {
List<OrderHotelResponse.HotelAccountSettlementInfo> lstHtlSettlement = response.getLstHtlSettlement();
if (lstHtlSettlement != null && !lstHtlSettlement.isEmpty()) {
List<OrderHotelResponse.LstHotelSettlementDetail> hotelSettlementDetailList = lstHtlSettlement.stream()
List<String> recordIds = lstHtlSettlement.stream()
.flatMap(it -> it.getLstHotelSettlementDetail().stream())
.toList();
List<String> recordIds = hotelSettlementDetailList
.stream()
.map(it -> String.valueOf(it.getSettlementDetail().getRecordId()))
.toList();
@ -129,42 +151,48 @@ public class CTripOrderRecordAutoSave {
.stream()
.collect(Collectors.toMap(CTripHotelRecord::getRecordId, Function.identity()));
List<CTripHotelRecord> list = hotelSettlementDetailList.stream()
.map(it -> {
OrderHotelResponse.SettlementDetail settlementDetail = it.getSettlementDetail();
CTripHotelRecord record = cTripHotelRecordMap.get(String.valueOf(settlementDetail.getRecordId()));
OrderHotelResponse.SettlementOrderDetail settlementOrderDetail = it.getOrderDetail();
if (record == null) {
record = CTripHotelRecord.of(CTripHotelRecordBase.changeInfo(settlementDetail),
CTripHotelInfo.of(it.getHotelDetail()),
CTripHotelOrderDetail.of(settlementOrderDetail));
} else {
Long originId = record.getId();
record = CTripHotelRecord.of(CTripHotelRecordBase.changeInfo(settlementDetail),
CTripHotelInfo.of(it.getHotelDetail()),
CTripHotelOrderDetail.of(settlementOrderDetail));
record.setId(originId);
}
//补充额外的字段
record.setRouteOrderNo(settlementOrderDetail.getHotelRelatedJourneyNo());
List<OrderHotelResponse.SettlementClientDetail> clientDetailList = settlementOrderDetail.getClientDetailList();
if (clientDetailList != null && !clientDetailList.isEmpty()) {
OrderHotelResponse.SettlementClientDetail settlementClientDetail = clientDetailList.get(0);
record.setUserCode(settlementClientDetail.getEmployeeID());
record.setUserName(settlementOrderDetail.getClientName());
}
record.setBookingUserCode(settlementOrderDetail.getEmployeeID());
record.setBookingUserName(settlementOrderDetail.getEmployeeName());
record.setBookingUserPhone("");
return record;
}).toList();
Map<Boolean, List<CTripHotelRecord>> collect = list.stream()
.collect(Collectors.groupingBy(record -> record.getId() != null));
collect.values().forEach(it -> cTripOrderDetailRepository.saveAllCTripHotelRecord(it));
List<CTripHotelRecord> list = lstHtlSettlement.stream()
.flatMap(it -> it.getLstHotelSettlementDetail().stream())
.map(it -> createOrUpdateHotelRecord(it, cTripHotelRecordMap))
.distinct()
.toList();
cTripOrderDetailRepository.saveAllCTripHotelRecord(list);
}
}
private CTripHotelRecord createOrUpdateHotelRecord(OrderHotelResponse.LstHotelSettlementDetail it, Map<String, CTripHotelRecord> cTripHotelRecordMap) {
OrderHotelResponse.SettlementDetail settlementDetail = it.getSettlementDetail();
CTripHotelRecord record = cTripHotelRecordMap.get(String.valueOf(settlementDetail.getRecordId()));
OrderHotelResponse.SettlementOrderDetail settlementOrderDetail = it.getOrderDetail();
if (record == null) {
record = CTripHotelRecord.of(
CTripHotelRecordBase.changeInfo(settlementDetail),
CTripHotelInfo.of(it.getHotelDetail()),
CTripHotelOrderDetail.of(settlementOrderDetail));
} else {
Long originId = record.getId();
record = CTripHotelRecord.of(
CTripHotelRecordBase.changeInfo(settlementDetail),
CTripHotelInfo.of(it.getHotelDetail()),
CTripHotelOrderDetail.of(settlementOrderDetail));
record.setId(originId);
}
// 补充额外的字段
record.setRouteOrderNo(settlementOrderDetail.getHotelRelatedJourneyNo());
List<OrderHotelResponse.SettlementClientDetail> clientDetailList = settlementOrderDetail.getClientDetailList();
if (clientDetailList != null && !clientDetailList.isEmpty()) {
OrderHotelResponse.SettlementClientDetail settlementClientDetail = clientDetailList.get(0);
record.setUserCode(settlementClientDetail.getEmployeeID());
record.setUserName(settlementOrderDetail.getClientName());
}
record.setBookingUserCode(settlementOrderDetail.getEmployeeID());
record.setBookingUserName(settlementOrderDetail.getEmployeeName());
record.setBookingUserPhone("");
return record;
}
public void cTripTrainRecordAutoSave(Optional<String> date) {
@ -201,65 +229,76 @@ public class CTripOrderRecordAutoSave {
OrderCarResponse carOrder = date
.flatMap(it -> Optional.ofNullable(cTripOrderDetailRequest.getCarOrderByDate(it)))
.orElseGet(() -> cTripOrderDetailRequest.getCarOrder());
cTripCarRecordAutoSave(carOrder);
}
List<OrderCarResponse.CarOrderAccountSettlementDetail> settlementList = carOrder.getCarOrderAccountSettlementList();
public void cTripCarRecordAutoSave(OrderRecordGenerateCommand command){
OrderCarResponse response = Optional.ofNullable(command.getOneDate())
.map(cTripOrderDetailRequest::getCarOrder)
.or(() -> Optional.ofNullable(command.getDate())
.flatMap(it -> Optional.ofNullable(cTripOrderDetailRequest.getCarOrder(it))))
.orElseGet(cTripOrderDetailRequest::getCarOrder);
cTripCarRecordAutoSave(response);
}
private void cTripCarRecordAutoSave(OrderCarResponse response) {
List<OrderCarResponse.CarOrderAccountSettlementDetail> settlementList = response.getCarOrderAccountSettlementList();
if (settlementList != null && !settlementList.isEmpty()) {
List<OrderCarResponse.CarOrderSettlementDetail> carOrderSettlementDetailList = settlementList.stream()
// 使用流处理减少中间集合
List<String> recordIds = settlementList.stream()
.distinct()
.flatMap(it -> it.getCarSettlementDetailList().stream())
.toList();
List<String> recordIds = carOrderSettlementDetailList
.stream()
.map(it -> String.valueOf(it.getSettlementBaseInfo().getRecordId()))
.toList();
Map<String, CTripCarRecord> cTripCarRecordMap = cTripOrderDetailRepository
.findCarRecordByRecordIdIn(recordIds)
.stream()
.collect(Collectors.toMap(CTripCarRecord::getRecordId, Function.identity()));
.collect(Collectors.toMap(CTripCarRecord::getRecordId, Function.identity(), (existing, replacement) -> existing));
List<CTripCarRecord> list = settlementList.stream()
.flatMap(it -> it.getCarSettlementDetailList().stream())
.map(it -> createOrUpdateRecord(it, cTripCarRecordMap))
.distinct()
.toList();
List<CTripCarRecord> list = carOrderSettlementDetailList.stream()
.map(it -> {
OrderCarResponse.CarOrderDetail orderDetail = it.getOrderDetail();
OrderCarResponse.CarOrderSettlementBaseInfo settlementBaseInfo = it.getSettlementBaseInfo();
CTripCarRecord record = cTripCarRecordMap.get(String.valueOf(settlementBaseInfo.getRecordId()));
List<OrderCarResponse.CarOrderPassengerInfo> passengerInfoList = orderDetail.getPassengerInfoList();
OrderCarResponse.CarOrderPassengerInfo carOrderPassengerInfo = passengerInfoList.get(0);
if (record == null) {
record = CTripCarRecord.of(
CTripCarRecordBase.changeInfo(settlementBaseInfo),
CTripCarQuickInfo.of(orderDetail.getQuickProductInfo()),
CTripCarPassengerInfo.of(carOrderPassengerInfo)
);
} else {
Long originId = record.getId();
record = CTripCarRecord.of(
CTripCarRecordBase.changeInfo(settlementBaseInfo),
CTripCarQuickInfo.of(orderDetail.getQuickProductInfo()),
CTripCarPassengerInfo.of(carOrderPassengerInfo)
);
record.setId(originId);
}
//补充额外的字段
OrderCarResponse.CarOrderCorpInfo corpInfo = orderDetail.getCorpInfo();
record.setRouteOrderNo(corpInfo.getJouneryId());
OrderCarResponse.CarOrderBaseInfo orderBaseInfo = orderDetail.getOrderBaseInfo();
String orderDate = orderBaseInfo.getOrderDate();
record.setOrderDate(DateTimeUtil.timeToStrCommon(DateTimeUtil.strToTime(orderDate)));
record.setUserCode(carOrderPassengerInfo.getEmployeeID());
record.setUserName(carOrderPassengerInfo.getPassengerName());
record.setBookingUserCode(orderBaseInfo.getPreEmployeeID());
record.setBookingUserName(orderBaseInfo.getUserName());
record.setBookingUserPhone(orderBaseInfo.getContactMobile());
return record;
}).toList();
// 批量保存
cTripOrderDetailRepository.saveAllCTripCarRecord(list);
}
}
private CTripCarRecord createOrUpdateRecord(OrderCarResponse.CarOrderSettlementDetail it, Map<String, CTripCarRecord> cTripCarRecordMap) {
OrderCarResponse.CarOrderDetail orderDetail = it.getOrderDetail();
OrderCarResponse.CarOrderSettlementBaseInfo settlementBaseInfo = it.getSettlementBaseInfo();
CTripCarRecord record = cTripCarRecordMap.get(String.valueOf(settlementBaseInfo.getRecordId()));
List<OrderCarResponse.CarOrderPassengerInfo> passengerInfoList = orderDetail.getPassengerInfoList();
OrderCarResponse.CarOrderPassengerInfo carOrderPassengerInfo = passengerInfoList.get(0);
if (record == null) {
record = CTripCarRecord.of(
CTripCarRecordBase.changeInfo(settlementBaseInfo),
CTripCarQuickInfo.of(orderDetail.getQuickProductInfo()),
CTripCarPassengerInfo.of(carOrderPassengerInfo)
);
} else {
Long originId = record.getId();
record = CTripCarRecord.of(
CTripCarRecordBase.changeInfo(settlementBaseInfo),
CTripCarQuickInfo.of(orderDetail.getQuickProductInfo()),
CTripCarPassengerInfo.of(carOrderPassengerInfo)
);
record.setId(originId);
}
// 补充额外的字段
OrderCarResponse.CarOrderCorpInfo corpInfo = orderDetail.getCorpInfo();
record.setRouteOrderNo(corpInfo.getJouneryId());
OrderCarResponse.CarOrderBaseInfo orderBaseInfo = orderDetail.getOrderBaseInfo();
String orderDate = orderBaseInfo.getOrderDate();
record.setOrderDate(DateTimeUtil.timeToStrCommon(DateTimeUtil.strToTime(orderDate)));
record.setUserCode(carOrderPassengerInfo.getEmployeeID());
record.setUserName(carOrderPassengerInfo.getPassengerName());
record.setBookingUserCode(orderBaseInfo.getPreEmployeeID());
record.setBookingUserName(orderBaseInfo.getUserName());
record.setBookingUserPhone(orderBaseInfo.getContactMobile());
return record;
}
}

View File

@ -250,7 +250,7 @@ public class CTripTest {
@Test
void search() {
BaseContext.setCurrentUser(user);
SearchOrderResponse response = orderSearchRequest.searchOrderResponseByOrderId("31592018105");
SearchOrderResponse response = orderSearchRequest.searchOrderResponseByOrderId("31839097186");
System.out.println(response);
}
@ -609,7 +609,6 @@ public class CTripTest {
@Test
void pullCarRecord() {
cTripOrderRecordAutoSave.cTripCarRecordAutoSave(Optional.ofNullable("202405"));
// cTripOrderRecordAutoSave.cTripFlightRecordAutoSave(Optional.ofNullable("202405"));
cTripOrderRecordAutoSave.cTripHotelRecordAutoSave(Optional.ofNullable("202405"));
}
}

View File

@ -828,7 +828,7 @@ public class LYTest {
@Test
void searchHotel() {
HotelDetailResponse hotelOrderDetail = lySearchRequest.getHotelOrderDetail("HO20240417095100616718");
HotelDetailResponse hotelOrderDetail = lySearchRequest.getHotelOrderDetail("HO20240321165300961176");
Gson gson = new Gson();
String json = gson.toJson(hotelOrderDetail);
System.out.println(json);
@ -859,7 +859,7 @@ public class LYTest {
// System.out.println(json);
TrainDetailResponse trainDetailResponse = lySearchRequest.getTrainOrderDetail("DT24041069650132424");
TrainDetailResponse trainDetailResponse = lySearchRequest.getTrainOrderDetail("DT24051073034383248");
Gson gson = new Gson();
String json = gson.toJson(trainDetailResponse);
System.out.println(json);

View File

@ -52,7 +52,7 @@ public class ManageTest {
@Test
void recordAdd(){
OrderPageQuery dto=new OrderPageQuery();
dto.setOderNo("123");
// dto.setOderNo("123");
OrderDownloadRecord downloadRecord=OrderDownloadRecord.builder()
.fileUrl("url")
.status("已完成")

View File

@ -15,6 +15,7 @@ import com.chint.domain.aggregates.order.order_record.ctrip_order_record.CTripHo
import com.chint.domain.aggregates.user.User;
import com.chint.domain.repository.*;
import com.chint.domain.service.JTCompanyDomainService;
import com.chint.domain.service.LocationDomainService;
import com.chint.domain.service.OrderDomainService;
import com.chint.domain.service.SystemDomainService;
import com.chint.domain.service.order_sync.LYOrderSyncAdapter;
@ -53,6 +54,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
@ -110,6 +112,9 @@ class RouteApplicationTests {
@Autowired
private UserRepository userRepository;
@Autowired
private LocationDomainService locationDomainService;
@Value("${FSSC.jt-baseUrl}")
private String jtFSSCUrl;
@ -316,7 +321,7 @@ class RouteApplicationTests {
@Test
void loginSignProd() {
String sfno = "240611055";
String sfno = "230228069";
String syscode = "FSSC";
String billcode = "CLSQ240225000099";
String companycode = "正泰集团股份有限公司";
@ -1472,4 +1477,18 @@ class RouteApplicationTests {
void roleTest() {
}
@Test
void exposedLocation(){
List<Location> locations = locationDomainService.queryLocationAndChildren();
// 将数据转换为JSON格式
Gson gson = new Gson();
String json = gson.toJson(locations);
// 将JSON写入txt文件
try (FileWriter fileWriter = new FileWriter("D:\\data\\locations.txt")) {
fileWriter.write(json);
} catch (IOException e) {
e.printStackTrace();
}
}
}