diff --git a/src/main/java/com/chint/application/commands/RouteAutoSyncCommand.java b/src/main/java/com/chint/application/commands/RouteAutoSyncCommand.java new file mode 100644 index 00000000..75d7d7b3 --- /dev/null +++ b/src/main/java/com/chint/application/commands/RouteAutoSyncCommand.java @@ -0,0 +1,16 @@ +package com.chint.application.commands; + +import com.chint.domain.aggregates.order.RouteOrder; +import com.chint.infrastructure.echo_framework.command.Command; +import lombok.Data; + + +@Data +public class RouteAutoSyncCommand extends Command { + private RouteOrder routeOrder; + + public RouteAutoSyncCommand route(RouteOrder routeOrder) { + this.routeOrder = routeOrder; + return this; + } +} diff --git a/src/main/java/com/chint/application/in/AutoWorkController.java b/src/main/java/com/chint/application/in/AutoWorkController.java index 5e64d524..3f13388f 100644 --- a/src/main/java/com/chint/application/in/AutoWorkController.java +++ b/src/main/java/com/chint/application/in/AutoWorkController.java @@ -4,7 +4,9 @@ import com.chint.application.commands.LYOrderRecordGenerateCommand; import com.chint.application.commands.OrderRecordGenerateCommand; import com.chint.application.dtos.RecordMonthSaveDTO; import com.chint.domain.aggregates.order.RouteOrder; +import com.chint.domain.aggregates.system.SystemAnnouncement; import com.chint.domain.factoriy.order_record.LyStatementOrder; +import com.chint.domain.repository.SystemAnnouncementRepository; import com.chint.domain.service.OrderRecordDomainService; import com.chint.domain.service.order_record.OrderRecordGenerator; import com.chint.domain.service.order_record.OrderRecordPuller; @@ -27,6 +29,9 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.time.LocalDateTime; +import java.util.List; + import static com.chint.infrastructure.constant.CommonMessageConstant.SUCCESS; import static com.chint.infrastructure.constant.LegConstant.*; import static com.chint.infrastructure.constant.SupplierNameConstant.SUPPLIER_AMAP; @@ -56,6 +61,9 @@ public class AutoWorkController { @Autowired private SupplierAdapterSelector supplierAdapterSelector; + @Autowired + private SystemAnnouncementRepository systemAnnouncementRepository; + @ApiOperation("用户状态检查,离职用户将关闭开卡") @PostMapping("/user/status/check") @@ -198,4 +206,17 @@ public class AutoWorkController { PageResult routeOrderPageResult = PageResult.totalPageNum(res.getTotalElements(), res.toList()); return Result.Success(SUCCESS, routeOrderPageResult); } + + + @ApiOperation("更新公告是否过期") + @PostMapping("/system/announcement/check/status") + public Result updateSystemAnnouncementStatus() { + List systemAnnouncements = systemAnnouncementRepository.findEffective() + .stream() + .filter(it -> it.getExpiryDate().isBefore(LocalDateTime.now())) + .peek(SystemAnnouncement::updateStatusByExpiryDate) + .toList(); + systemAnnouncementRepository.saveAll(systemAnnouncements); + return Result.Success(SUCCESS); + } } diff --git a/src/main/java/com/chint/application/out/FSSCController.java b/src/main/java/com/chint/application/out/FSSCController.java index f6949fff..70832423 100644 --- a/src/main/java/com/chint/application/out/FSSCController.java +++ b/src/main/java/com/chint/application/out/FSSCController.java @@ -114,6 +114,12 @@ public class FSSCController { if (extensionOptional.isPresent()) { reDirectUrl = dataBaseUrl + extensionOptional.get().getFieldValue(); } + //特殊处理 + if(sysCode.getIfImmediateResponse() == 1){ + reDirectUrl = sysCode.getSystemCodeUrl().getRedirectUrlDev(); + } else { + reDirectUrl = sysCode.getSystemCodeUrl().getRedirectUrlProd(); + } } return reDirectUrl; } diff --git a/src/main/java/com/chint/application/out/LoginController.java b/src/main/java/com/chint/application/out/LoginController.java index a5ca4d37..c74b4052 100644 --- a/src/main/java/com/chint/application/out/LoginController.java +++ b/src/main/java/com/chint/application/out/LoginController.java @@ -131,17 +131,15 @@ public class LoginController { @ApiOperation("商旅平台移动端单点") @PostMapping("/login/sso/mobile") public Result loginSSOMobile(@RequestBody UserLoginParam userLoginParam) { - String employeeNo = feishuLoginStrategy.login(userLoginParam.getCode()); - + String timespan = userLoginParam.getTimespan() + "-M"; + userLoginParam.setTimespan(timespan); userLoginParam.setSfno(employeeNo); UserLoginResult userLoginResult = authenticateService .authenticateEmployeeNo(userLoginParam); - //异步执行更新用户信息到同程 User currentUser = BaseContext.getCurrentUser(); loginEventBoarder(currentUser); - return Result.Success(CommonMessageConstant.SUCCESS, userLoginResult); } diff --git a/src/main/java/com/chint/application/out/OrderDetailController.java b/src/main/java/com/chint/application/out/OrderDetailController.java index 01930e59..54dbd4e9 100644 --- a/src/main/java/com/chint/application/out/OrderDetailController.java +++ b/src/main/java/com/chint/application/out/OrderDetailController.java @@ -3,6 +3,7 @@ package com.chint.application.out; import com.chint.application.dtos.*; import com.chint.application.dtos.mapper.RouteOrderMapper; import com.chint.application.dtos.response.OrderDetailRes; +import com.chint.application.dtos.response.RouteOrderPageRes; import com.chint.application.queryies.OrderDetailQuery; import com.chint.domain.aggregates.order.RouteOrder; import com.chint.domain.aggregates.user.User; @@ -202,6 +203,13 @@ public class OrderDetailController { return Result.Success(SUCCESS, orderDetailResPageResult); } +// @ApiOperation("查询我的订单根据行程规划单分类") +// @PostMapping("/query/page/route") +// public Result> queryOrderDetailByRoute(@RequestBody OrderDetailQueryParam orderDetailQueryParam) { +// PageResult orderDetailResPageResult = orderDetailPageQuery.orderDetailPageQuery(orderDetailQueryParam); +// return Result.Success(SUCCESS, orderDetailResPageResult); +// } + @ApiOperation("查询携程订单") @PostMapping("/public/query/cTrip") public Result queryOrderDetail(@RequestBody OrderDetailQueryParam orderDetailQueryParam) { diff --git a/src/main/java/com/chint/application/queryies/OrderQuery.java b/src/main/java/com/chint/application/queryies/OrderQuery.java index e08ebf6f..fa38ba24 100644 --- a/src/main/java/com/chint/application/queryies/OrderQuery.java +++ b/src/main/java/com/chint/application/queryies/OrderQuery.java @@ -2,6 +2,7 @@ package com.chint.application.queryies; import cn.hutool.core.bean.BeanUtil; import com.chint.application.dtos.RoutOrderFieldParam; +import com.chint.application.dtos.mapper.OrderDetailMapper; import com.chint.application.dtos.mapper.RouteOrderMapper; import com.chint.application.dtos.response.*; import com.chint.application.dtos.trip.*; @@ -39,8 +40,7 @@ import java.util.stream.Stream; import static com.chint.infrastructure.constant.FSSCConstant.*; import static com.chint.infrastructure.constant.LegConstant.*; -import static com.chint.infrastructure.constant.LocationConstant.LOCATION_LEVEL_CITY; -import static com.chint.infrastructure.constant.LocationConstant.LOCATION_LEVEL_COUNTY; +import static com.chint.infrastructure.constant.LocationConstant.*; import static com.chint.infrastructure.constant.OrderConstant.ORDER_EVENT_CANCEL_NAME; import static com.chint.infrastructure.constant.OrderConstant.ORDER_EVENT_PREPARE_NAME; import static com.chint.infrastructure.constant.RouteConstant.*; @@ -365,23 +365,27 @@ public class OrderQuery { List locationListAfterNotNull = locationList.stream().filter(Objects::nonNull).toList(); for (Location location : locationListAfterNotNull) { - if (location.getLocationEnName() == null) { - //这里的代码来补充地理位置的英文名 - Integer level = location.getLevel(); - if (level.equals(LOCATION_LEVEL_CITY)) { - PrefectureLevelCityInfoEntity cityInfo = prefectureLevelRepository.findByCityId(location.getCityId()); - location.setLocationEnName(cityInfo.getCityEnName()); - } else if (level.equals(LOCATION_LEVEL_COUNTY) && location.getLocationShortName().contains("D")) { - DistrictPOIInfoEntity byCityId = districtInfoRepository.findByCityId(location.getCityId()); - location.setLocationEnName(byCityId.getDistrictEnName()); - } else if (level.equals(LOCATION_LEVEL_COUNTY)) { - CountryLevelInfoEntity byCityId = countryLevelInfoRepository.findByCityId(location.getCityId()); - location.setLocationEnName(byCityId.getCountyEnName()); - } else { - location.setLocationEnName("unknown"); + location.setLocationEnName( + switch (location.getLocationType()) { + case LOCATION_TYPE_CITY -> + Optional.ofNullable(prefectureLevelRepository.findByCityId(location.getCityId())) + .map(PrefectureLevelCityInfoEntity::getCityEnName) + .orElse("unknown"); + case LOCATION_TYPE_DISTRICT -> + Optional.ofNullable(districtInfoRepository.findByCityId(location.getCityId())) + .map(DistrictPOIInfoEntity::getDistrictEnName) + .orElse("unknown"); + case LOCATION_TYPE_COUNTY -> + Optional.ofNullable(countryLevelInfoRepository.findByCityId(location.getCityId())) + .map(CountryLevelInfoEntity::getCountyEnName) + .orElse("unknown"); + default -> "unknown"; + } + ); + if (location.getLocationEnName() != null) { + locationRepository.save(location); } - locationRepository.saveAll(List.of(location)); } callbackDataBuilder.cityList() .cityName(location.getLocationName()) @@ -395,24 +399,20 @@ public class OrderQuery { ScheduleDetail.ScheduleDetailBuilder scheduleDetailBuilder = ScheduleDetail .builder() .legId(leg.getLegId()); - if (!leg.getLegType().equals(LEG_TYPE_OTHER)) { - Location originLocation = leg.getOriginLocation(); - if (originLocation != null) { - scheduleDetailBuilder - .startCity(originLocation.getLocationName()) - .startCityName(originLocation.getLocationName()) - .startCityEnName(originLocation.getLocationEnName()); - } - - Location destinationLocation = leg.getDestinationLocation(); - if (destinationLocation != null) { - scheduleDetailBuilder - .endCityName(destinationLocation.getLocationName()) - .endCity(destinationLocation.getLocationName()) - .endCityEnName(destinationLocation.getLocationEnName()); - } + Location originLocation = leg.getOriginLocation(); + if (originLocation != null) { + scheduleDetailBuilder + .startCity(originLocation.getLocationName()) + .startCityName(originLocation.getLocationName()) + .startCityEnName(originLocation.getLocationEnName()); + } + Location destinationLocation = leg.getDestinationLocation(); + if (destinationLocation != null) { + scheduleDetailBuilder + .endCityName(destinationLocation.getLocationName()) + .endCity(destinationLocation.getLocationName()) + .endCityEnName(destinationLocation.getLocationEnName()); } - if (leg.getLegType().equals(LEG_TYPE_HOTEL)) { scheduleDetailBuilder .roomCount("1") @@ -442,15 +442,6 @@ public class OrderQuery { .locationList(locationList1.stream().map(LocationRes::copyFrom).toList()); } } - -// if (leg.getLegType().equals(LEG_TYPE_OTHER) && Objects.requireNonNull(leg.getLegExtensionField()).getAmountType().equals(LEG_OTHER_AMOUNT_TYPE_VISA)) { -// scheduleDetailBuilder.expenseTypeId("6770f575013211eabce29fde958f48e4") -// .travelType("LOCAL_OTHER") -// .scheduleType("VISA"); -// } else { -// scheduleDetailBuilder -// } - return scheduleDetailBuilder .scheduleNum(leg.getLegNo()) .scheduleType(translateLegType(leg.getLegType())) @@ -486,6 +477,24 @@ public class OrderQuery { return callbackDataBuilder.ScheduleDetail(scheduleDetails).done().build(); } +// private String getLocationEnName(Location location) { +// return switch (location.getLocationType()) { +// case LOCATION_TYPE_CITY -> Optional.ofNullable(prefectureLevelRepository.findByCityId(location.getCityId())) +// .map(PrefectureLevelCityInfoEntity::getCityEnName) +// .orElse("unknown"); +// case LOCATION_TYPE_DISTRICT -> +// Optional.ofNullable(districtInfoRepository.findByCityId(location.getCityId())) +// .map(DistrictPOIInfoEntity::getDistrictEnName) +// .orElse("unknown"); +// case LOCATION_TYPE_COUNTY -> +// Optional.ofNullable(countryLevelInfoRepository.findByCityId(location.getCityId())) +// .map(CountryLevelInfoEntity::getCountyEnName) +// .orElse("unknown"); +// default -> "unknown"; +// }; +// } + + private String translateLegType(Integer legType) { return switch (legType) { case LegConstant.LEG_TYPE_TRAIN -> TRIP_CALLBACK_TRAIN_TYPE; @@ -499,7 +508,6 @@ public class OrderQuery { public RouteOrderRes queryRouteRes(RouteOrder routeOrder) { RouteOrderRes routeOrderRes = RouteOrderRes.copyFrom(routeOrder); - List legItems = routeOrder.getLegItems(); if (legItems != null && !legItems.isEmpty()) { //这里使用领域事件进行检查leg的订单状态 ,用户每次想要查看行程都会进行一次检查 @@ -510,16 +518,12 @@ public class OrderQuery { List orderDetailResList = routeOrder .getOrderDetails() .stream() - .map(OrderDetailRes::copyFrom) + .filter(it -> !it.getOrderStatus().equals(ORDER_EVENT_CANCEL_NAME) && !it.getOrderStatus().equals(ORDER_EVENT_PREPARE_NAME)) + .map(OrderDetailMapper::copyFromExtension) .toList(); User user = userRepository.findByUserEmployeeNo(routeOrder.getUserId()); routeOrderRes.setUserName(user.getName()); routeOrderRes.setOrderDetailRes(orderDetailResList); - routeOrderRes.setOrderDetailRes(routeOrderRes - .getOrderDetailRes() - .stream() - .filter(it -> !it.getOrderStatus().equals(ORDER_EVENT_CANCEL_NAME) && !it.getOrderStatus().equals(ORDER_EVENT_PREPARE_NAME)) - .toList()); } return routeOrderRes; } diff --git a/src/main/java/com/chint/application/system/UserController.java b/src/main/java/com/chint/application/system/UserController.java index 1883185b..b6565410 100644 --- a/src/main/java/com/chint/application/system/UserController.java +++ b/src/main/java/com/chint/application/system/UserController.java @@ -117,8 +117,8 @@ public class UserController { @PostMapping("/add/role") public Result addRoleUser(@RequestBody RoleOrgParam roleOrgParam) { //查询已有权限 - List exist=roleUserRepository.findByUserId(roleOrgParam.getUserId()); - List roleIdList=roleOrgParam.getRoleIdList(); + List exist = roleUserRepository.findByUserId(roleOrgParam.getUserId()); + List roleIdList = roleOrgParam.getRoleIdList(); roleIdList.removeAll(exist.stream().map(RoleUser::getRoleId).toList()); if (roleIdList.isEmpty()) { return Result.Success(); @@ -174,6 +174,6 @@ public class UserController { @ApiOperation("用户角色分页查询") @PostMapping("/role/pageQuery") public Result> rolePageQuery(@RequestBody RolePageQuery rolePageQuery) { - return Result.Success(SUCCESS,userDomainService.userPageQuery(rolePageQuery)); + return Result.Success(SUCCESS, userDomainService.userPageQuery(rolePageQuery)); } } diff --git a/src/main/java/com/chint/domain/aggregates/order/RouteRequestLeg.java b/src/main/java/com/chint/domain/aggregates/order/RouteRequestLeg.java index bd017d87..00a44593 100644 --- a/src/main/java/com/chint/domain/aggregates/order/RouteRequestLeg.java +++ b/src/main/java/com/chint/domain/aggregates/order/RouteRequestLeg.java @@ -18,7 +18,6 @@ public class RouteRequestLeg implements Serializable { @Id private Long id; private Long routeRequestId; - private Long routeRequestKey; private Long legId; @Transient private Leg leg; diff --git a/src/main/java/com/chint/domain/aggregates/system/SystemAnnouncement.java b/src/main/java/com/chint/domain/aggregates/system/SystemAnnouncement.java index 4dd750ad..db43b0d1 100644 --- a/src/main/java/com/chint/domain/aggregates/system/SystemAnnouncement.java +++ b/src/main/java/com/chint/domain/aggregates/system/SystemAnnouncement.java @@ -110,4 +110,12 @@ public class SystemAnnouncement implements Serializable { return this; } + public SystemAnnouncement updateStatusByExpiryDate(){ + LocalDateTime expiryDate = this.getExpiryDate(); + if (expiryDate.isBefore(LocalDateTime.now())) { + this.setStatus("0"); + } + return this; + } + } diff --git a/src/main/java/com/chint/domain/factoriy/order/RouteOrderFactory.java b/src/main/java/com/chint/domain/factoriy/order/RouteOrderFactory.java index 07f84449..464bcd3b 100644 --- a/src/main/java/com/chint/domain/factoriy/order/RouteOrderFactory.java +++ b/src/main/java/com/chint/domain/factoriy/order/RouteOrderFactory.java @@ -98,6 +98,7 @@ public class RouteOrderFactory implements OrderFactory { requestByRoute.setRouteRequestLegList(routeRequestLegs); requestByRoute.setCreateTime(LocalDateTime.now()); requestByRoute.setUpdateTime(LocalDateTime.now()); + requestByRoute.setSupplierName(supplier); return requestByRoute; } diff --git a/src/main/java/com/chint/domain/factoriy/order_detail/CTripOrderExtensionFactoryImpl.java b/src/main/java/com/chint/domain/factoriy/order_detail/CTripOrderExtensionFactoryImpl.java index 8d2e4641..bf962c4e 100644 --- a/src/main/java/com/chint/domain/factoriy/order_detail/CTripOrderExtensionFactoryImpl.java +++ b/src/main/java/com/chint/domain/factoriy/order_detail/CTripOrderExtensionFactoryImpl.java @@ -185,7 +185,6 @@ public class CTripOrderExtensionFactoryImpl implements OrderExtensionFactory { String orderNo = flightOrderBasicInfo.getOrderID(); String journeyNo = flightOrderBasicInfo.getJourneyID(); RouteOrder routeOrder = routeRequestDomainService.getRouteOrder(journeyNo); - return buildFlightOrderDetail(flightOrderInfoEntity, routeOrder, orderNo); } diff --git a/src/main/java/com/chint/domain/factoriy/order_record/AmapOrderRecordExtensionFactory.java b/src/main/java/com/chint/domain/factoriy/order_record/AmapOrderRecordExtensionFactory.java index f853f558..71eebd22 100644 --- a/src/main/java/com/chint/domain/factoriy/order_record/AmapOrderRecordExtensionFactory.java +++ b/src/main/java/com/chint/domain/factoriy/order_record/AmapOrderRecordExtensionFactory.java @@ -2,17 +2,20 @@ package com.chint.domain.factoriy.order_record; import com.chint.domain.aggregates.order.OrderDetail; import com.chint.domain.aggregates.order.RouteOrder; +import com.chint.domain.aggregates.order.RouterOrderExtensionField; import com.chint.domain.aggregates.order.order_record.OrderCarRecord; import com.chint.domain.aggregates.order.order_record.OrderFlightRecord; import com.chint.domain.aggregates.order.order_record.OrderHotelRecord; import com.chint.domain.aggregates.order.order_record.OrderTrainRecord; import com.chint.domain.aggregates.order.order_record.amap_order_record.AmapCarOrderRecord; -import com.chint.infrastructure.util.BigDecimalCalculator; +import com.chint.infrastructure.util.DateTimeUtil; import com.chint.interfaces.rest.amap.dto.settlement.FinishedOrderResponse; import com.chint.interfaces.rest.data_center.user.UserHttpRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.time.Duration; +import java.time.LocalDateTime; import java.util.Optional; import static com.chint.domain.service.supplier.SupplierUtil.getBelongSysType; @@ -61,20 +64,42 @@ public class AmapOrderRecordExtensionFactory implements OrderRecordExtensionFact } else { orderStatus = "1"; } + +// orderCarRecord.loadBasicOrderInfo(carRecordData.getAmapOrderId(), +// orderStatus, +// carRecordData.getGmtCreate()) +// .loadBelongDeport( +// routeOrder.stream().flatMap(order -> +// Optional.ofNullable(order.getRouterOrderExtensionField().getBelongDeptCode()).stream() +// ).findFirst().orElseGet(() -> +// userHttpRequest.belongDeport(orderCarRecord.getBookingUserCode(), orderCarRecord.getAccountCompanyName())) +// ); + orderCarRecord.loadBasicOrderInfo(carRecordData.getAmapOrderId(), orderStatus, carRecordData.getGmtCreate()) .loadBelongDeport( - routeOrder.stream().flatMap(order -> - Optional.ofNullable(order.getRouterOrderExtensionField().getBelongDeptCode()).stream() - ).findFirst().orElseGet(()-> - userHttpRequest.belongDeport(orderCarRecord.getBookingUserCode(), orderCarRecord.getAccountCompanyName())) + routeOrder.stream() + .flatMap(order -> + Optional.of(order) + .map(RouteOrder::getRouterOrderExtensionField) + .map(RouterOrderExtensionField::getBelongDeptCode) + .stream() + ) + .findFirst() + .orElseGet(() -> + userHttpRequest.belongDeport(orderCarRecord.getBookingUserCode(), orderCarRecord.getAccountCompanyName())) ); String ds = carRecordData.getDs(); + + //车辆运行时间 + String gmtCreateStartTime106 = carRecordData.getGmtCreateStartTime106(); + String gmtCreateEndTime106 = carRecordData.getGmtCreateEndTime106(); + orderCarRecord.loadTravelInfo( - carRecordData.getGmtCreateStartTime106(), - carRecordData.getGmtCreateEndTime106(), + gmtCreateStartTime106, + gmtCreateEndTime106, carRecordData.getCityName(), carRecordData.getEndCity(), carRecordData.getStartName(), @@ -86,17 +111,19 @@ public class AmapOrderRecordExtensionFactory implements OrderRecordExtensionFact ).loadFinancialInfo( ds.substring(0, 6), ds, - String.valueOf(carRecordData.getOrderAmount()), - BigDecimalCalculator.add(String.valueOf(carRecordData.getOrderAmount()), String.valueOf(carRecordData.getServicefee())) + String.valueOf(carRecordData.getEnterpriseAmount()), + String.valueOf(carRecordData.getEnterpriseAmount()) ).loadFeeDetails( "", "", String.valueOf(carRecordData.getServicefee()), String.valueOf(carRecordData.getCancelFee()), String.valueOf(carRecordData.getHighwayFee()), - "" + "高速费" ); - + orderCarRecord.setNoTaxAmt(carRecordData.getTotalCouponAmount() == 0 ? String.valueOf(carRecordData.getTotalCouponAmount()) + : "-" + carRecordData.getTotalCouponAmount()); + orderCarRecord.setTaxAmt(String.valueOf(carRecordData.getOrderAmount())); Double enterpriseAmount = carRecordData.getEnterpriseAmount(); Double individualAmount = carRecordData.getIndividualAmount(); String paymentType; @@ -113,6 +140,10 @@ public class AmapOrderRecordExtensionFactory implements OrderRecordExtensionFact outApplyRecordId = split[split.length - 1]; } orderCarRecord.loadSystemInfo(SUPPLIER_AMAP_FSSC, getBelongSysType(split[4]), split[1], split[0]); + //补充遗漏的字段 + orderCarRecord.setProjectOrderNo(split[2]); + orderCarRecord.setOfflineCcomyCode(split[3]); + orderCarRecord.loadPayment( paymentType, String.valueOf(enterpriseAmount), @@ -131,6 +162,20 @@ public class AmapOrderRecordExtensionFactory implements OrderRecordExtensionFact carRecordData.getAmapOrderId(), carRecordData.getAmapOrderId() ); + + //兼容测试环境获取运行时间 + if (gmtCreateStartTime106 != null && gmtCreateStartTime106.length() > 18 && + gmtCreateEndTime106 != null && gmtCreateEndTime106.length() > 18 && + Double.parseDouble(orderCarRecord.getRunTime()) <= 0) { + LocalDateTime runStartTime = DateTimeUtil.strToTime(gmtCreateStartTime106); + LocalDateTime runEndTime = DateTimeUtil.strToTime(gmtCreateEndTime106); + Duration runtimeDuration = Duration.between(runStartTime, runEndTime); + long runtimeInMinutes = runtimeDuration.toMinutes(); + orderCarRecord.setRunTime(String.valueOf(runtimeInMinutes)); + } else { + orderCarRecord.setRunTime("0"); + } + orderDetail.ifPresentOrElse(orderCarRecord::loadComplianceInfo, orderCarRecord::loadComplianceInfoNot); return orderCarRecord; } diff --git a/src/main/java/com/chint/domain/repository/SupplierRepository.java b/src/main/java/com/chint/domain/repository/SupplierRepository.java index 0b6c1577..3650c5c5 100644 --- a/src/main/java/com/chint/domain/repository/SupplierRepository.java +++ b/src/main/java/com/chint/domain/repository/SupplierRepository.java @@ -6,6 +6,10 @@ import java.util.Optional; public interface SupplierRepository { Supplier save(Supplier supplier); + Optional findById(Long id); + Optional findBySupplierName(String supplierName); + + Iterable findAll(); } diff --git a/src/main/java/com/chint/domain/repository/SystemAnnouncementRepository.java b/src/main/java/com/chint/domain/repository/SystemAnnouncementRepository.java index 85b10ebe..7a1c17f1 100644 --- a/src/main/java/com/chint/domain/repository/SystemAnnouncementRepository.java +++ b/src/main/java/com/chint/domain/repository/SystemAnnouncementRepository.java @@ -8,6 +8,8 @@ import java.util.Optional; public interface SystemAnnouncementRepository { SystemAnnouncement save(SystemAnnouncement systemAnnouncement); + void saveAll(List systemAnnouncementList); + Optional findById(Long id); Optional findNew(); diff --git a/src/main/java/com/chint/domain/service/LegDomainService.java b/src/main/java/com/chint/domain/service/LegDomainService.java index 9d064e99..07b4b956 100644 --- a/src/main/java/com/chint/domain/service/LegDomainService.java +++ b/src/main/java/com/chint/domain/service/LegDomainService.java @@ -12,7 +12,6 @@ import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.List; -import java.util.Optional; import static com.chint.infrastructure.constant.CommonMessageConstant.LEG_CHANGE_MAX_ERROR; import static com.chint.infrastructure.constant.LegConstant.*; @@ -171,30 +170,48 @@ public class LegDomainService { } public List queryLegsCanSync(RouteOrder routeOrder, String supplierName) { + // 获取所有Leg items并查询位置信息 List legItems = routeOrder.getLegItems(); queryLocation(legItems); - legItems = legItems.stream() + + // 过滤Leg items + List filteredLegItems = legItems.stream() .filter(it -> !it.getLegType().equals(LEG_TYPE_OTHER) && it.legIsInternal()) .toList(); - // 通过查看供应商的商品类型,来进行同步 - legItems = ifCanSync(legItems, routeOrder, supplierName); - legItems.forEach(Leg::reloadStatus); - return legItems; - } - private List ifCanSync(List legs, RouteOrder routeOrder, String supplierName) { + // 根据供应商名称查找供应商并进行处理 return supplierRepository.findBySupplierName(supplierName) .map(supplier -> { - List productTypes = supplier.getSupplierProductList() - .stream() - .filter(it -> it.getIfCanOrder().equals(1)) - .map(SupplierProduct::getProductType) - .toList(); - return legs.stream() - .filter(leg -> productTypes.contains(leg.getLegType()) && checkLegCompatibility(leg, routeOrder, supplier)) - .toList(); + List syncAbleLegItems = ifCanSync(filteredLegItems, routeOrder, supplier); + syncAbleLegItems.forEach(Leg::reloadStatus); + return syncAbleLegItems; }) - .orElse(legs); + .orElse(filteredLegItems); + } + + public List queryLegsCanSync(RouteOrder routeOrder, Supplier supplier) { + // 获取所有Leg items并查询位置信息 + List legItems = routeOrder.getLegItems(); + queryLocation(legItems); + // 过滤Leg items + List filteredLegItems = legItems.stream() + .filter(it -> !it.getLegType().equals(LEG_TYPE_OTHER) && it.legIsInternal()) + .toList(); + List syncAbleLegItems = ifCanSync(filteredLegItems, routeOrder, supplier); + syncAbleLegItems.forEach(Leg::reloadStatus); + return syncAbleLegItems; + } + + + private List ifCanSync(List legs, RouteOrder routeOrder, Supplier supplier) { + List productTypes = supplier.getSupplierProductList() + .stream() + .filter(it -> it.getIfCanOrder().equals(1)) + .map(SupplierProduct::getProductType) + .toList(); + return legs.stream() + .filter(leg -> productTypes.contains(leg.getLegType()) && checkLegCompatibility(leg, routeOrder, supplier)) + .toList(); } private boolean checkLegCompatibility(Leg leg, RouteOrder routeOrder, Supplier supplier) { diff --git a/src/main/java/com/chint/domain/service/OrderDomainService.java b/src/main/java/com/chint/domain/service/OrderDomainService.java index eee00405..5bbf89bb 100644 --- a/src/main/java/com/chint/domain/service/OrderDomainService.java +++ b/src/main/java/com/chint/domain/service/OrderDomainService.java @@ -83,6 +83,9 @@ public class OrderDomainService { @Autowired private BPMOrderDomainService bpmOrderDomainService; + @Autowired + private SupplierRepository supplierRepository; + private Set companyBlackList = new HashSet<>(); public RouteOrder saveOrder(RouteOrder routeOrder) { @@ -174,6 +177,8 @@ public class OrderDomainService { } } + + private boolean isSpecialEventType(Integer orderEventType) { return orderEventType.equals(ORDER_EVENT_ETA) || orderEventType.equals(ORDER_EVENT_CHANGE) || diff --git a/src/main/java/com/chint/domain/service/RouteRequestDomainService.java b/src/main/java/com/chint/domain/service/RouteRequestDomainService.java index c571d4e9..4c722052 100644 --- a/src/main/java/com/chint/domain/service/RouteRequestDomainService.java +++ b/src/main/java/com/chint/domain/service/RouteRequestDomainService.java @@ -1,5 +1,6 @@ package com.chint.domain.service; +import com.chint.application.commands.RouteAutoSyncCommand; import com.chint.domain.aggregates.order.*; import com.chint.domain.aggregates.supplier.Supplier; import com.chint.domain.exceptions.CommandException; @@ -13,6 +14,7 @@ import com.chint.domain.service.order_sync.SupplierOrderSync; import com.chint.domain.service.order_sync.SyncAdapter; import com.chint.domain.service.supplier.SupplierAdapterSelector; import com.chint.domain.value_object.SyncLegData; +import com.chint.infrastructure.echo_framework.annotation.ListenTo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -21,7 +23,8 @@ import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; -import static com.chint.infrastructure.constant.LegConstant.*; +import static com.chint.infrastructure.constant.LegConstant.LEG_EVENT_APPROVAL; +import static com.chint.infrastructure.constant.LegConstant.LEG_EVENT_NOT_ORDERED; import static com.chint.infrastructure.constant.RouteRequestConstant.ROUTE_REQUEST_STATUS_PREPARE; @Service @@ -72,13 +75,33 @@ public class RouteRequestDomainService { // legEventFactory.creatLegEvent(command.getLegEventType()) // )); + + @ListenTo(command = "RouteAutoSyncCommand", order = 0) + public RouteRequest syncRouteRequestToSupplierAuto(RouteAutoSyncCommand command) { + RouteOrder routeOrder = command.getRouteOrder(); + legDomainService.checkLegIfStartApproval(routeOrder); + + supplierRepository.findAll() + .forEach(it -> { + List legs = legDomainService.queryLegsCanSync(routeOrder, it); + List legIdList = legs.stream().map(leg -> leg.getLegId()).toList(); + RouteRequest routeRequest = getRouteRequest(routeOrder, legIdList, it.getName()); + + }); + return null; + } + public RouteRequest syncRouteRequestToSupplier(SyncLegData syncLegData) { RouteOrder routeOrder = routeRepository.queryById(syncLegData.getRouteId()); legDomainService.checkLegIfStartApproval(routeOrder); List legIds = syncLegData.getLegIds(); String supplierName = syncLegData.getSupplierName(); + return createAndSyncRouteRequest(routeOrder, legIds, supplierName); + } + + private RouteRequest createAndSyncRouteRequest(RouteOrder routeOrder, List legIds, String supplierName) { RouteRequest routeRequest = getRouteRequest(routeOrder, legIds, supplierName); - if (routeRequest.getStatus().equals(ROUTE_REQUEST_STATUS_PREPARE)) { + if (routeRequest.getStatus().equals(ROUTE_REQUEST_STATUS_PREPARE) && routeRequest.getSupplier() == null) { //如果是刚生成的订单需要加入行程规划单当中 //保存供应商信息 routeRequest.setSupplier(supplierName); @@ -87,23 +110,10 @@ public class RouteRequestDomainService { //如果是不是刚生成的,需要调整差旅申请单的行程 loadLegInfo(routeRequest, routeOrder, legIds); } - - List legs = routeRequest.getRouteRequestLegList() + routeRequest.getRouteRequestLegList() .stream() .map(RouteRequestLeg::getLeg) - .toList(); - - if (legs.isEmpty()) { - throw new CommandException("订单的行程不能为空"); - } - - List needSyncLegs = legs.stream().filter(it -> !it.getLegType().equals(LEG_TYPE_OTHER)).toList(); - if (needSyncLegs.isEmpty()) { - throw new CommandException("有所选的行程规划单不存在需要同步的行程"); - } - - legs.forEach(it -> it.addEvent(legEventFactory.creatLegEvent(LEG_EVENT_NOT_ORDERED))); - + .forEach(it -> it.addEvent(legEventFactory.creatLegEvent(LEG_EVENT_NOT_ORDERED))); supplierRepository.findBySupplierName(supplierName) .ifPresentOrElse( supplier -> syncRouteRequest(routeRequest, supplier, routeOrder), @@ -130,9 +140,7 @@ public class RouteRequestDomainService { List legIds = syncLegData.getLegIds(); Long routeId = syncLegData.getRouteId(); RouteOrder routeOrder = routeRepository.queryById(routeId); - Optional optionalRouteRequest = findRouteRequest(routeOrder, syncLegData); - optionalRouteRequest.ifPresent(routeRequest -> { List legs = getLegsFromRouteRequest(routeRequest, routeOrder); diff --git a/src/main/java/com/chint/domain/service/UserDomainService.java b/src/main/java/com/chint/domain/service/UserDomainService.java index 3e1ce13d..4855453e 100644 --- a/src/main/java/com/chint/domain/service/UserDomainService.java +++ b/src/main/java/com/chint/domain/service/UserDomainService.java @@ -6,6 +6,7 @@ import com.chint.application.dtos.system.RoleUserDto; import com.chint.domain.aggregates.user.Role; import com.chint.domain.aggregates.user.RoleUser; import com.chint.domain.aggregates.user.User; +import com.chint.domain.repository.RoleRepository; import com.chint.infrastructure.repository.jdbc.JdbcRoleRepository; import com.chint.infrastructure.repository.jdbc.JdbcRoleUserRepository; import com.chint.infrastructure.repository.jdbc.JdbcUserRepository; @@ -23,6 +24,7 @@ public class UserDomainService { private JdbcUserRepository jdbcUserRepository; @Autowired private JdbcRoleRepository jdbcRoleRepository; + @Autowired private JdbcRoleUserRepository jdbcRoleUserRepository; diff --git a/src/main/java/com/chint/domain/service/auth/AuthenticateServiceImpl.java b/src/main/java/com/chint/domain/service/auth/AuthenticateServiceImpl.java index 39192dd6..dded8b59 100644 --- a/src/main/java/com/chint/domain/service/auth/AuthenticateServiceImpl.java +++ b/src/main/java/com/chint/domain/service/auth/AuthenticateServiceImpl.java @@ -74,7 +74,9 @@ public class AuthenticateServiceImpl implements AuthenticateService { private UserLoginResult getUserLoginResult(User user) { UserLoginParam userLoginParam = user.getUserLoginParam(); String companyCode = userLoginParam.getCompanyCode(); - if (companyCode != null && !companyCode.isEmpty()) { + if (user.getCompanyCode() == null && + companyCode != null && + !companyCode.isEmpty()) { user.setCompanyCode(companyCode); } user.setUserLoginParam(userLoginParam); diff --git a/src/main/java/com/chint/domain/service/leg_event/LegEventHandler.java b/src/main/java/com/chint/domain/service/leg_event/LegEventHandler.java index 7decb217..a8a4803d 100644 --- a/src/main/java/com/chint/domain/service/leg_event/LegEventHandler.java +++ b/src/main/java/com/chint/domain/service/leg_event/LegEventHandler.java @@ -22,6 +22,7 @@ import com.chint.domain.value_object.SyncLegData; import com.chint.infrastructure.constant.CommonMessageConstant; import com.chint.infrastructure.constant.LegConstant; import com.chint.infrastructure.constant.RouteConstant; +import com.chint.infrastructure.echo_framework.command.Command; import com.chint.infrastructure.echo_framework.dispatch.ResultContainer; import com.chint.infrastructure.util.BaseContext; import com.chint.infrastructure.util.OrderNo; @@ -145,6 +146,9 @@ public class LegEventHandler implements LegEventService { //保存routeOrder的状态 RouteOrder save = routeRepository.save(routeOrder); command.order(save); + + //异步执行自动同步功能 + Command.of(RouteAutoSyncCommand.class).route(save).async().sendToQueue(); } @Transactional diff --git a/src/main/java/com/chint/domain/service/order_record/AmapOrderRecordGenerator.java b/src/main/java/com/chint/domain/service/order_record/AmapOrderRecordGenerator.java index 15d2b992..3e5e01f9 100644 --- a/src/main/java/com/chint/domain/service/order_record/AmapOrderRecordGenerator.java +++ b/src/main/java/com/chint/domain/service/order_record/AmapOrderRecordGenerator.java @@ -114,7 +114,7 @@ public class AmapOrderRecordGenerator implements OrderRecordGenerator { Map> collect = routeOrderNoList.parallelStream().collect(Collectors.toMap(Function.identity(), it -> routeOrderList.stream().filter(routeOrder -> routeOrder != null && routeOrder.checkIfMine(it)).findFirst())); List orderCarRecordList = amapCarOrderRecordList - .stream() + .parallelStream() .map(it -> orderRecordExtensionFactory.createCarOrderRecord(it, collect.get(it.getOutApplyRecordId()))) .toList(); return orderDetailDomainService.saveCarOrderRecordBatch(orderCarRecordList); diff --git a/src/main/java/com/chint/domain/service/order_record/LYOrderRecordDomainService.java b/src/main/java/com/chint/domain/service/order_record/LYOrderRecordDomainService.java index 915e7059..582c0011 100644 --- a/src/main/java/com/chint/domain/service/order_record/LYOrderRecordDomainService.java +++ b/src/main/java/com/chint/domain/service/order_record/LYOrderRecordDomainService.java @@ -89,11 +89,11 @@ public class LYOrderRecordDomainService { List routeOrderList = routeRequestDomainService.getRouteOrder(routeOrderNoList); Map> collect = routeOrderNoList.parallelStream().collect(Collectors.toMap(Function.identity(), it -> routeOrderList.stream().filter(routeOrder ->routeOrder != null && routeOrder.checkIfMine(it)).findFirst())); - List orderCarRecordList = recordsTotal + List orderFlightRecordList = recordsTotal .stream() .map(it -> lyOrderRecordExtensionFactory.createFlightOrderRecord(it, collect.get(it.getOutApplayOrderNo()))) .toList(); - orderDetailDomainService.saveFlightOrderRecordBatch(orderCarRecordList); + orderDetailDomainService.saveFlightOrderRecordBatch(orderFlightRecordList); jdbcLyOrderFlightRecord.updateStatusByNullStatus(); } @@ -129,7 +129,7 @@ public class LYOrderRecordDomainService { .map(it -> lyOrderRecordExtensionFactory.createHotelOrderRecord(it, collect.get(it.getOutApplayOrderNo()))) .toList(); orderDetailDomainService.saveHotelOrderRecordBatch(orderHotelRecordList); - jdbcLyOrderFlightRecord.updateStatusByNullStatus(); + jdbcLyOrderHotelRecord.updateStatusByNullStatus(); } @@ -164,7 +164,7 @@ public class LYOrderRecordDomainService { .map(it -> lyOrderRecordExtensionFactory.createTrainOrderRecord(it, collect.get(it.getOutApplayOrderNo()))) .toList(); orderDetailDomainService.saveTrainOrderRecordBatch(orderTrainRecordList); - jdbcLyOrderFlightRecord.updateStatusByNullStatus(); + jdbcLyOrderTrainRecord.updateStatusByNullStatus(); } @@ -199,7 +199,7 @@ public class LYOrderRecordDomainService { .map(it -> lyOrderRecordExtensionFactory.createCarOrderRecord(it, collect.get(it.getOutApplayOrderNo()))) .toList(); orderDetailDomainService.saveCarOrderRecordBatch(orderCarRecordList); - jdbcLyOrderFlightRecord.updateStatusByNullStatus(); + jdbcLyOrderCarRecord.updateStatusByNullStatus(); } diff --git a/src/main/java/com/chint/domain/service/order_sync/SupplierOrderSync.java b/src/main/java/com/chint/domain/service/order_sync/SupplierOrderSync.java index 33eff32a..9c762d2f 100644 --- a/src/main/java/com/chint/domain/service/order_sync/SupplierOrderSync.java +++ b/src/main/java/com/chint/domain/service/order_sync/SupplierOrderSync.java @@ -5,9 +5,11 @@ import com.chint.domain.aggregates.order.*; import com.chint.domain.aggregates.supplier.Supplier; import com.chint.domain.aggregates.supplier.SupplierProduct; import com.chint.domain.exceptions.AuthException; +import com.chint.domain.exceptions.CommandException; import com.chint.domain.service.supplier.SupplierAdapter; import java.util.List; +import java.util.Optional; import static com.chint.infrastructure.constant.LegConstant.*; @@ -21,60 +23,118 @@ public interface SupplierOrderSync extends SupplierAdapter { boolean cancelRouteRequest(RouteRequest routeRequest); default boolean syncRouteRequest(RouteRequest routeRequest, Supplier supplier) { + return syncRouteRequestInternal(routeRequest, supplier, true); + } + + default boolean syncRouteRequestWithoutException(RouteRequest routeRequest, Supplier supplier) { + return syncRouteRequestInternal(routeRequest, supplier, false); + } + + private boolean syncRouteRequestInternal(RouteRequest routeRequest, Supplier supplier, boolean throwError) { + // Check if routeRequest or supplier is null if (routeRequest == null || supplier == null) { throw new AuthException("验证差旅申请单失败,请联系管理员"); } + + + // Extract routeRequestFields RouteRequestFields routeRequestFields = routeRequest.getRouteRequestFields(); + + // Create list of legs from routeRequest List legList = routeRequest.getRouteRequestLegList() .stream() .map(RouteRequestLeg::getLeg) .toList(); - legList.forEach(leg -> { - switch (leg.getLegType()) { - case LEG_TYPE_TRAIN -> trainProductCheck(routeRequestFields, supplier); - case LEG_TYPE_AIRPLANE -> flightProductCheck(routeRequestFields, supplier); - case LEG_TYPE_HOTEL -> hotelProductCheck(routeRequestFields, supplier); - case LEG_TYPE_TAXI -> carProductCheck(routeRequestFields, supplier); + + // Legs can not be empty + if (legList.isEmpty()) { + if (throwError) { + throw new CommandException("订单的行程不能为空"); + } else { + return false; } - }); - return syncRouteRequest(routeRequest); + } + + // Legs can not be other type + List needSyncLegs = legList.stream().filter(it -> !it.getLegType().equals(LEG_TYPE_OTHER)).toList(); + if (needSyncLegs.isEmpty()) { + if (throwError) { + throw new CommandException("有所选的行程规划单不存在需要同步的行程"); + } else { + return false; + } + } + + // Introduce a flag to track if any check fails + boolean isValid = true; + + // Process each leg + for (Leg leg : legList) { + // Perform product check based on leg type and update the isValid flag + switch (leg.getLegType()) { + case LEG_TYPE_TRAIN -> + isValid = isValid && productCheckWrapper(routeRequestFields, supplier.trainSupplierProduct(), supplier, "火车", throwError); + case LEG_TYPE_AIRPLANE -> + isValid = isValid && productCheckWrapper(routeRequestFields, supplier.flightSupplierProduct(), supplier, "机票", throwError); + case LEG_TYPE_HOTEL -> + isValid = isValid && productCheckWrapper(routeRequestFields, supplier.hotelSupplierProduct(), supplier, "酒店", throwError); + case LEG_TYPE_TAXI -> + isValid = isValid && productCheckWrapper(routeRequestFields, supplier.carSupplierProduct(), supplier, "打车", throwError); + } + + // If any check fails and throwError is false, break the loop + if (!isValid && !throwError) { + break; + } + } + + // If all checks pass, sync the route request + if (isValid) { + return syncRouteRequest(routeRequest); + } else { + return false; // Indicate that the request was not synced due to validation failure + } } - private void carProductCheck(RouteRequestFields routeRequestFields, Supplier supplier) { - supplier.carSupplierProduct() - .ifPresent(carSupplierProduct -> productCheck(routeRequestFields, carSupplierProduct, supplier, "打车")); + private boolean productCheckWrapper(RouteRequestFields routeRequestFields, + Optional supplierProductOpt, + Supplier supplier, + String legCnName, + boolean throwError) { + return supplierProductOpt.map(supplierProduct -> + productCheck(routeRequestFields, supplierProduct, supplier, legCnName, throwError)).orElse(true); } - private void flightProductCheck(RouteRequestFields routeRequestFields, Supplier supplier) { - supplier.flightSupplierProduct() - .ifPresent(flightSupplierProduct -> productCheck(routeRequestFields, flightSupplierProduct, supplier, "机票")); - } - - private void hotelProductCheck(RouteRequestFields routeRequestFields, Supplier supplier) { - supplier.hotelSupplierProduct() - .ifPresent(hotelSupplierProduct -> productCheck(routeRequestFields, hotelSupplierProduct, supplier, "酒店")); - } - - private void trainProductCheck(RouteRequestFields routeRequestFields, Supplier supplier) { - supplier.trainSupplierProduct() - .ifPresent(trainSupplierProduct -> productCheck(routeRequestFields, trainSupplierProduct, supplier, "火车")); - } - - private void productCheck(RouteRequestFields routeRequestFields, - SupplierProduct supplierProduct, - Supplier supplier, - String legCnName) { + // General product check method + private boolean productCheck(RouteRequestFields routeRequestFields, + SupplierProduct supplierProduct, + Supplier supplier, + String legCnName, + boolean throwError) { if (!supplierProduct.checkStandardLevelIfInUse(routeRequestFields.getStandardLevel())) { - throw new AuthException("你目前的差标暂不支持使用" + supplier.getCnName() + legCnName); + if (throwError) { + throw new AuthException("你目前的差标暂不支持使用" + supplier.getCnName() + legCnName + "。"); + } + return false; } if (supplierProduct.checkSysCodeIfNotUse(routeRequestFields.getSysCode())) { - throw new AuthException("你目前的来源系统暂不支持使用" + supplier.getCnName() + legCnName); + if (throwError) { + throw new AuthException("你目前的来源系统暂不支持使用" + supplier.getCnName() + legCnName + "。"); + } + return false; } - if (supplierProduct.checkSysCodeIfNotUse(routeRequestFields.getAccountCompany())) { - throw new AuthException("你目前的公司暂不支持使用" + supplier.getCnName() + legCnName); + if (supplierProduct.checkCompanyIfNotUse(routeRequestFields.getAccountCompany())) { + if (throwError) { + throw new AuthException("你目前的公司暂不支持使用" + supplier.getCnName() + legCnName + "。"); + } + return false; } - if (supplierProduct.checkSysCodeIfNotUse(routeRequestFields.getAccountCompanyName())) { - throw new AuthException("你目前的公司暂不支持使用" + supplier.getCnName() + legCnName); + if (supplierProduct.checkCompanyIfNotUse(routeRequestFields.getAccountCompanyName())) { + if (throwError) { + throw new AuthException("你目前的公司暂不支持使用" + supplier.getCnName() + legCnName + "。"); + } + return false; } + return true; } } diff --git a/src/main/java/com/chint/infrastructure/echo_framework/annotation/ListenTo.java b/src/main/java/com/chint/infrastructure/echo_framework/annotation/ListenTo.java index bf5ee290..861052d7 100644 --- a/src/main/java/com/chint/infrastructure/echo_framework/annotation/ListenTo.java +++ b/src/main/java/com/chint/infrastructure/echo_framework/annotation/ListenTo.java @@ -9,4 +9,5 @@ import java.lang.annotation.*; public @interface ListenTo { String command(); long order(); + boolean async() default false; } \ No newline at end of file diff --git a/src/main/java/com/chint/infrastructure/echo_framework/command/Command.java b/src/main/java/com/chint/infrastructure/echo_framework/command/Command.java index 22dd10ee..9cf286d1 100644 --- a/src/main/java/com/chint/infrastructure/echo_framework/command/Command.java +++ b/src/main/java/com/chint/infrastructure/echo_framework/command/Command.java @@ -11,6 +11,7 @@ import lombok.NoArgsConstructor; @NoArgsConstructor public abstract class Command { private String commandName; + private boolean ifSync = false; public Properties sendToQueue() { return CommandDispatcher.dispatch(this); @@ -26,4 +27,9 @@ public abstract class Command { throw new CommandException("command create error :" + e.getMessage()); } } + + public Command async() { + ifSync = true; + return this; + } } \ No newline at end of file diff --git a/src/main/java/com/chint/infrastructure/echo_framework/manager/EventManager.java b/src/main/java/com/chint/infrastructure/echo_framework/manager/EventManager.java index 7f993e35..577fec13 100644 --- a/src/main/java/com/chint/infrastructure/echo_framework/manager/EventManager.java +++ b/src/main/java/com/chint/infrastructure/echo_framework/manager/EventManager.java @@ -23,6 +23,7 @@ import org.springframework.transaction.support.TransactionTemplate; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.*; +import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -104,23 +105,30 @@ public class EventManager implements ApplicationContextAware, BeanNameAware, Ini List containers = listenerMethods.getOrDefault(command.getCommandName(), Collections.emptyList()); List resultContainers = new ArrayList<>(); containers.forEach(container -> { - - Object result = null; try { - result = container.getMethod().invoke(container.getBean(), command); + if (command.isIfSync()) { + CompletableFuture.runAsync(() -> { + try { + container.getMethod().invoke(container.getBean(), command); + } catch (IllegalAccessException | InvocationTargetException e) { + e.printStackTrace(); + } + }); + } else { + Object result = container.getMethod().invoke(container.getBean(), command); + if (result instanceof ResultContainer) { + resultContainers.add((ResultContainer) result); + } + } } catch (IllegalAccessException | InvocationTargetException e) { throw new RuntimeException(e); } - if (result instanceof ResultContainer) { - resultContainers.add((ResultContainer) result); - } - }); + return resultContainers; } private static List processTransitionCommand(Command command) { - System.out.println(transitionMethods); List containers = transitionMethods.getOrDefault(command.getCommandName(), Collections.emptyList()); List resultContainers = new ArrayList<>(); transactionTemplate.execute(transactionStatus -> { diff --git a/src/main/java/com/chint/infrastructure/repository/SupplierRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/SupplierRepositoryImpl.java index 9eebaf64..5707430c 100644 --- a/src/main/java/com/chint/infrastructure/repository/SupplierRepositoryImpl.java +++ b/src/main/java/com/chint/infrastructure/repository/SupplierRepositoryImpl.java @@ -7,6 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Repository; +import java.util.List; import java.util.Optional; @Repository @@ -30,4 +31,9 @@ public class SupplierRepositoryImpl implements SupplierRepository { public Optional findBySupplierName(String supplierName) { return jdbcSupplierRepository.findByName(supplierName); } + + @Override + public Iterable findAll() { + return jdbcSupplierRepository.findAll(); + } } diff --git a/src/main/java/com/chint/infrastructure/repository/SystemAnnouncementRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/SystemAnnouncementRepositoryImpl.java index 9686d8b1..9b5ba1c0 100644 --- a/src/main/java/com/chint/infrastructure/repository/SystemAnnouncementRepositoryImpl.java +++ b/src/main/java/com/chint/infrastructure/repository/SystemAnnouncementRepositoryImpl.java @@ -25,6 +25,12 @@ public class SystemAnnouncementRepositoryImpl implements SystemAnnouncementRepos return jdbcSystemAnnouncementRepository.save(systemAnnouncement); } + @Override + public void saveAll(List systemAnnouncementList) { + jdbcSystemAnnouncementRepository.saveAll(systemAnnouncementList) + .forEach(it -> cacheEvictAnnouncement(it.getAnnouncementId())); + } + @Cacheable(value = "SystemAnnouncement", key = "#id") @Override public Optional findById(Long id) { @@ -47,4 +53,9 @@ public class SystemAnnouncementRepositoryImpl implements SystemAnnouncementRepos public List findEffective() { return jdbcSystemAnnouncementRepository.findByStatus("1"); } + + @CacheEvict(value = "SystemAnnouncement", key = "#id") + public void cacheEvictAnnouncement(Long id) { + + } } diff --git a/src/main/java/com/chint/interfaces/rest/ctrip/in/CTripNoteController.java b/src/main/java/com/chint/interfaces/rest/ctrip/in/CTripNoteController.java index b37f392d..223df83b 100644 --- a/src/main/java/com/chint/interfaces/rest/ctrip/in/CTripNoteController.java +++ b/src/main/java/com/chint/interfaces/rest/ctrip/in/CTripNoteController.java @@ -3,7 +3,6 @@ package com.chint.interfaces.rest.ctrip.in; import cn.hutool.core.bean.BeanUtil; import com.chint.application.commands.OrderStatusChangeCommand; import com.chint.application.commands.SupplierCallBackErrorCommand; -import com.chint.domain.aggregates.order.OrderDetail; import com.chint.domain.repository.SupplierCallBackLogRepository; import com.chint.domain.service.SystemDomainService; import com.chint.domain.service.supplier.SupplierService; @@ -172,24 +171,7 @@ public class CTripNoteController { .outOrderStatus(orderStatus) .orderNo(orderId) .productType(legType); - - OrderDetail orderDetail = supplierService.handleSupplierCallback(supplierCallbackData); - -// OrderStatusChangeCommand command = Command.of(OrderStatusChangeCommand.class) -// .orderDetail(orderDetail) -// .orderNo(orderId) -// .outStatus(orderStatus); -// -// Integer eventType = CTripUtils.outStatusMapToEventType(legType, orderStatus); -// String etaReason = CTripUtils.getETAReason(response, legType); -// -// command.eventType(eventType) -// .extension(etaReason) -// .sendToQueue(); - -// if (legType.equals(LEG_TYPE_HOTEL)) { -// checkHotelIfRefund(response, command); -// } + supplierService.handleSupplierCallback(supplierCallbackData); return Result.Success("成功收到消息"); } diff --git a/src/main/java/com/chint/interfaces/rest/ctrip/tools/CTripUtils.java b/src/main/java/com/chint/interfaces/rest/ctrip/tools/CTripUtils.java index 24848ee0..4b81f124 100644 --- a/src/main/java/com/chint/interfaces/rest/ctrip/tools/CTripUtils.java +++ b/src/main/java/com/chint/interfaces/rest/ctrip/tools/CTripUtils.java @@ -204,6 +204,7 @@ public class CTripUtils { !"Confirmed".equals(status) && !"Wait".equals(status) && !"CancellationFailed".equals(status) && + !"Cancelled".equals(status) && !"submitFailed".equals(status) && !"Approve_G".equals(status) && !"Approving".equals(status) && diff --git a/src/main/java/com/chint/interfaces/rest/ly/in/CommonController.java b/src/main/java/com/chint/interfaces/rest/ly/in/CommonController.java index f94e1c90..d7414caa 100644 --- a/src/main/java/com/chint/interfaces/rest/ly/in/CommonController.java +++ b/src/main/java/com/chint/interfaces/rest/ly/in/CommonController.java @@ -87,33 +87,33 @@ public class CommonController { @PostMapping("/back") public LYNoteResponse Back(@RequestBody Notification notification) { -// int notifyType = notification.getNotifyType(); -// switch (notifyType) { -// //进行订单数据回推 -// case 1 -> getOrderFlight(notification); -// case 3 -> getOrderHotel(notification); -// case 5 -> getOrderTrain(notification); -// case 6 -> getOrderCar(notification); -// default -> LYNoteResponse.success(); -// } - - - if (ifForwardRequest) { - CompletableFuture.runAsync(() -> { - log.info("转发同程订单状态推送"); - LYNoteResponse response = basePostRequest - .post(forwardRequestBaseUrl + forwardRequestPath, notification, LYNoteResponse.class); - if (response.getResCode().equals("100")) { - log.info("转发同程订单状态推送成功"); - } else { - log.info("转发同程订单状态推送失败"); - } - }); + int notifyType = notification.getNotifyType(); + switch (notifyType) { + //进行订单数据回推 + case 1 -> getOrderFlight(notification); + case 3 -> getOrderHotel(notification); + case 5 -> getOrderTrain(notification); + case 6 -> getOrderCar(notification); + default -> LYNoteResponse.success(); } - String json = gson.toJson(notification); - log.info("存入Redis{}", json); - redisTemplate.opsForList().leftPush(CommonMessageConstant.COMMON_BACK, json); + +// if (ifForwardRequest) { +// CompletableFuture.runAsync(() -> { +// log.info("转发同程订单状态推送"); +// LYNoteResponse response = basePostRequest +// .post(forwardRequestBaseUrl + forwardRequestPath, notification, LYNoteResponse.class); +// if (response.getResCode().equals("100")) { +// log.info("转发同程订单状态推送成功"); +// } else { +// log.info("转发同程订单状态推送失败"); +// } +// }); +// } +// +// String json = gson.toJson(notification); +// log.info("存入Redis{}", json); +// redisTemplate.opsForList().leftPush(CommonMessageConstant.COMMON_BACK, json); return new LYNoteResponse("100", "OK"); } diff --git a/src/main/java/com/chint/interfaces/rest/ly/tools/LYOrderUtil.java b/src/main/java/com/chint/interfaces/rest/ly/tools/LYOrderUtil.java index 60384968..e3b4062b 100644 --- a/src/main/java/com/chint/interfaces/rest/ly/tools/LYOrderUtil.java +++ b/src/main/java/com/chint/interfaces/rest/ly/tools/LYOrderUtil.java @@ -31,6 +31,7 @@ public class LYOrderUtil { public static boolean checkTrainStatus(String status) { return !"N".equals(status) && !"D".equals(status) && + !"C".equals(status) && !"S".equals(status) && !"G".equals(status) && !"H".equals(status) && @@ -80,6 +81,7 @@ public class LYOrderUtil { !"22".equals(status) && !"60".equals(status) && !"67".equals(status) && + !"96".equals(status) && !"99".equals(status); } @@ -120,7 +122,11 @@ public class LYOrderUtil { !"11".equals(status) && !"12".equals(status) && !"13".equals(status) && - !"14".equals(status); + !"14".equals(status) && + !"15".equals(status) && + !"16".equals(status) && + !"17".equals(status) && + !"18".equals(status); } public static Integer mapCarStatus(Integer status) { diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-test.yml index 7cb8c90e..f816e398 100644 --- a/src/main/resources/application-test.yml +++ b/src/main/resources/application-test.yml @@ -52,7 +52,6 @@ ly: baseUrl: https://api.dttrip.cn/openapi ifForwardRequest: true forwardRequestBaseUrl: https://gxdev03.chint.com/routeapi - #高德 amap: eId: 201107 diff --git a/src/test/java/com/chint/CTripTest.java b/src/test/java/com/chint/CTripTest.java index 6faf442c..5ea3d079 100644 --- a/src/test/java/com/chint/CTripTest.java +++ b/src/test/java/com/chint/CTripTest.java @@ -250,7 +250,7 @@ public class CTripTest { @Test void search() { BaseContext.setCurrentUser(user); - SearchOrderResponse response = orderSearchRequest.searchOrderResponseByOrderId("32430240547"); + SearchOrderResponse response = orderSearchRequest.searchOrderResponseByOrderId("32002090029"); System.out.println(response); } diff --git a/src/test/java/com/chint/LYTest.java b/src/test/java/com/chint/LYTest.java index d042b74d..4041a50b 100644 --- a/src/test/java/com/chint/LYTest.java +++ b/src/test/java/com/chint/LYTest.java @@ -820,7 +820,7 @@ public class LYTest { @Test void searchTrain() { - TrainDetailResponse trainOrderDetail = lySearchRequest.getTrainOrderDetail("DT24041770487265905"); + TrainDetailResponse trainOrderDetail = lySearchRequest.getTrainOrderDetail("DTC24061977736328100"); Gson gson = new Gson(); String json = gson.toJson(trainOrderDetail); System.out.println(json); @@ -828,7 +828,7 @@ public class LYTest { @Test void searchHotel() { - HotelDetailResponse hotelOrderDetail = lySearchRequest.getHotelOrderDetail("HO20240321165300961176"); + HotelDetailResponse hotelOrderDetail = lySearchRequest.getHotelOrderDetail("HO20240406120100189791"); Gson gson = new Gson(); String json = gson.toJson(hotelOrderDetail); System.out.println(json); diff --git a/src/test/java/com/chint/RouteApplicationTests.java b/src/test/java/com/chint/RouteApplicationTests.java index 8a7bc2c8..aa5f6879 100644 --- a/src/test/java/com/chint/RouteApplicationTests.java +++ b/src/test/java/com/chint/RouteApplicationTests.java @@ -321,7 +321,7 @@ class RouteApplicationTests { @Test void loginSignProd() { - String sfno = "230228069"; + String sfno = "220921136"; String syscode = "FSSC"; String billcode = "CLSQ240225000099"; String companycode = "正泰集团股份有限公司";