From bfa2e83a6da512ab319c0a4cbb01e3e30f1a3ed1 Mon Sep 17 00:00:00 2001 From: lulz1 Date: Wed, 24 Apr 2024 12:43:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=99=BB=E5=BD=95=E7=9A=84?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF=E5=90=8C=E6=AD=A5=E9=80=BB?= =?UTF-8?q?=E8=BE=91=20=EF=BC=8C=20=E4=BF=AE=E6=94=B9=E5=8F=96=E6=B6=88?= =?UTF-8?q?=E5=B7=AE=E6=97=85=E7=94=B3=E8=AF=B7=E5=8D=95=E7=BC=BA=E5=A4=B1?= =?UTF-8?q?=E8=A1=8C=E7=A8=8B=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commands/UserLoginCommand.java | 15 ++++++ .../application/in/AutoWorkController.java | 20 +------- .../application/out/LoginController.java | 51 +++---------------- .../chint/domain/aggregates/user/User.java | 12 ++--- .../service/leg_event/LegEventHandler.java | 19 +++++-- .../cache/RouteCacheService.java | 15 ++++++ .../export/OrderDetailExportFactory.java | 15 +++--- .../chint/infrastructure/util/SystemUtil.java | 2 +- .../rest/ctrip/CTripUserSaveRequest.java | 21 +++++++- .../interfaces/rest/ly/LYUserRequest.java | 20 +++++++- .../chint/interfaces/rest/user/PushUser.java | 1 - .../chint/interfaces/rest/user/UserSync.java | 10 ++++ src/main/resources/application.yml | 2 +- .../java/com/chint/RouteApplicationTests.java | 4 +- 14 files changed, 121 insertions(+), 86 deletions(-) create mode 100644 src/main/java/com/chint/application/commands/UserLoginCommand.java create mode 100644 src/main/java/com/chint/interfaces/rest/user/UserSync.java diff --git a/src/main/java/com/chint/application/commands/UserLoginCommand.java b/src/main/java/com/chint/application/commands/UserLoginCommand.java new file mode 100644 index 00000000..c8da05db --- /dev/null +++ b/src/main/java/com/chint/application/commands/UserLoginCommand.java @@ -0,0 +1,15 @@ +package com.chint.application.commands; + +import com.chint.domain.aggregates.user.User; +import com.chint.infrastructure.echo_framework.command.Command; +import lombok.Data; + +@Data +public class UserLoginCommand extends Command { + private User user; + + public UserLoginCommand user(User user) { + this.user = user; + 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 990d6118..a697b024 100644 --- a/src/main/java/com/chint/application/in/AutoWorkController.java +++ b/src/main/java/com/chint/application/in/AutoWorkController.java @@ -1,29 +1,19 @@ package com.chint.application.in; - -import com.alibaba.fastjson.JSON; import com.chint.application.commands.LYOrderRecordGenerateCommand; -import com.chint.application.dtos.AuthenticationSignDto; import com.chint.application.dtos.CTripRecordMonthSaveDTO; -import com.chint.domain.aggregates.order.OrderDetail; import com.chint.domain.aggregates.order.RouteOrder; import com.chint.domain.factoriy.order_record.LyStatementOrder; -import com.chint.infrastructure.config.LogConfig.Dto.LogPageDto; -import com.chint.infrastructure.config.LogConfig.SystemLog; -import com.chint.infrastructure.constant.CommonMessageConstant; import com.chint.infrastructure.echo_framework.command.Command; import com.chint.application.commands.OrderRecordGenerateCommand; -import com.chint.domain.factoriy.order_record.LyStatementOrder; -import com.chint.infrastructure.echo_framework.command.Command; import com.chint.infrastructure.repository.jdbc.JdbcRouteRepository; -import com.chint.infrastructure.util.BeanCopyUtils; import com.chint.infrastructure.util.DateTimeUtil; import com.chint.infrastructure.util.PageResult; import com.chint.infrastructure.util.Result; import com.chint.interfaces.rest.ctrip.order.CTripOrderRecordAutoSave; import com.chint.interfaces.rest.ly.reconciliation.dto.PageInfo; -import com.google.gson.Gson; import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; @@ -32,15 +22,11 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import com.chint.application.commands.OrderRecordGenerateCommand; -import java.time.LocalDate; -import java.time.format.DateTimeFormatter; -import java.util.ArrayList; -import java.util.List; import static com.chint.infrastructure.constant.CommonMessageConstant.SUCCESS; + @RestController @RequestMapping("/public") public class AutoWorkController { @@ -52,7 +38,6 @@ public class AutoWorkController { @Autowired private LyStatementOrder lyStatementOrder; - @Transactional @ApiOperation("自动拉取昨天的流水号,每天晚上8点执行") @PostMapping("/cTrip/record/save") @@ -104,5 +89,4 @@ public class AutoWorkController { PageResult routeOrderPageResult = PageResult.totalPageNum(res.getTotalElements(), res.toList()); return Result.Success(SUCCESS, routeOrderPageResult); } - } diff --git a/src/main/java/com/chint/application/out/LoginController.java b/src/main/java/com/chint/application/out/LoginController.java index cdd853fb..d02a5a39 100644 --- a/src/main/java/com/chint/application/out/LoginController.java +++ b/src/main/java/com/chint/application/out/LoginController.java @@ -2,6 +2,7 @@ package com.chint.application.out; import com.chint.application.commands.OrderCreateCommand; +import com.chint.application.commands.UserLoginCommand; import com.chint.application.services.login.strategy.ANFeiShuLoginStrategy; import com.chint.application.services.login.strategy.FeishuLoginStrategy; import com.chint.application.services.login.strategy.PailaLoginStrategy; @@ -27,7 +28,6 @@ import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; import java.time.LocalDateTime; @@ -104,12 +104,10 @@ public class LoginController { //发送创建行程订单命令 Command.of(OrderCreateCommand.class).of(currentUser).sendToQueue(); } - syncUserInfoToSupplier(currentUser); + loginEventBoarder(currentUser); //清除职级信息 userLoginResult.getUser().setProfLevel(null); userLoginResult.getUser().setManaLevel(null); - //登录成功之后对该用户的行程规划单进行缓存 - cacheUserRouteOrder(currentUser.getEmployeeNo()); return Result.Success(CommonMessageConstant.SUCCESS, userLoginResult); } else { return Result.error(AuthMessageConstant.SIGN_ERROR); @@ -128,13 +126,11 @@ public class LoginController { //异步执行更新用户信息到同程 User currentUser = userLoginResult.getUser(); - syncUserInfoToSupplier(currentUser); + loginEventBoarder(currentUser); //清除职级信息 userLoginResult.getUser().setProfLevel(null); userLoginResult.getUser().setManaLevel(null); - //登录成功之后对该用户的行程规划单进行缓存 - cacheUserRouteOrder(currentUser.getEmployeeNo()); return Result.Success(CommonMessageConstant.SUCCESS, userLoginResult); } @@ -150,14 +146,12 @@ public class LoginController { //异步执行更新用户信息到同程 User currentUser = userLoginResult.getUser(); - syncUserInfoToSupplier(currentUser); + loginEventBoarder(currentUser); //清除职级信息 userLoginResult.getUser().setProfLevel(null); userLoginResult.getUser().setManaLevel(null); - //登录成功之后对该用户的行程规划单进行缓存 - cacheUserRouteOrder(currentUser.getEmployeeNo()); return Result.Success(CommonMessageConstant.SUCCESS, userLoginResult); } @@ -172,50 +166,19 @@ public class LoginController { //异步执行更新用户信息到同程 User currentUser = userLoginResult.getUser(); - syncUserInfoToSupplier(currentUser); + loginEventBoarder(currentUser); //清除职级信息 userLoginResult.getUser().setProfLevel(null); userLoginResult.getUser().setManaLevel(null); - //登录成功之后对该用户的行程规划单进行缓存 - cacheUserRouteOrder(currentUser.getEmployeeNo()); return Result.Success(CommonMessageConstant.SUCCESS, userLoginResult); } - private void syncUserInfoToSupplier(User user) { - // 给定的 LocalDateTime 实例,示例中为2024年3月1日15:00 - if (user.checkSyncTime()) { - asyncUser(user); - } else { - log.info("未超过一天,不执行同步。"); - } - } - - public void asyncUser(User user) { - // 如果超过一天,执行同步代码 - CompletableFuture.runAsync(() -> { - BaseContext.setCurrentUser(user); - lyUserRequest.saveCurrentUser(); - BaseContext.removeCurrentUser(); - }); - //异步执行更新用户信息到携程 - CompletableFuture.runAsync(() -> { - BaseContext.setCurrentUser(user); - cTripUserSaveRequest.saveUserToCTrip(); - BaseContext.removeCurrentUser(); - }); - // 发送保存用户同步时间 + private void loginEventBoarder(User user) { + Command.of(UserLoginCommand.class).user(user).sendToQueue(); user.setSyncTime(LocalDateTime.now()); userRepository.save(user); } - - private void cacheUserRouteOrder(String employeeNo) { - //登录成功之后对该用户的行程规划单进行缓存 - CompletableFuture.runAsync(() -> { - log.info("开始缓存" + employeeNo + "用户的行程规划单"); - routeCacheService.preloadUserRoutes(employeeNo); - }); - } } diff --git a/src/main/java/com/chint/domain/aggregates/user/User.java b/src/main/java/com/chint/domain/aggregates/user/User.java index 5be2127a..532ef9a1 100644 --- a/src/main/java/com/chint/domain/aggregates/user/User.java +++ b/src/main/java/com/chint/domain/aggregates/user/User.java @@ -47,6 +47,12 @@ public class User implements Serializable { private String phoneNumber; private String password; private LocalDateTime syncTime; + @Transient + private String manaLevel; + @Transient + private String profLevel; + @Transient + private String qualityLevel; @MappedCollection(idColumn = "user_id", keyColumn = "user_key") private List userDepartmentInfoList; @Transient @@ -60,12 +66,6 @@ public class User implements Serializable { @Transient private String workStatus; @Transient - private String manaLevel; - @Transient - private String profLevel; - @Transient - private String qualityLevel; - @Transient private UserLoginParam 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 0502fa22..580ef82b 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 @@ -16,7 +16,6 @@ import com.chint.domain.service.LegDomainService; import com.chint.domain.service.OrderDomainService; import com.chint.domain.service.RouteRequestDomainService; import com.chint.domain.service.order_sync.SyncAdapter; -import com.chint.domain.value_object.ApprovalSimpleData; import com.chint.domain.value_object.ApproveRouteData; import com.chint.domain.value_object.OrderLegData; import com.chint.domain.value_object.SyncLegData; @@ -35,13 +34,13 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.List; import java.util.Optional; import static com.chint.infrastructure.constant.BPMConstant.*; import static com.chint.infrastructure.constant.CommonMessageConstant.LEG_CHANGE_MAX_ERROR; +import static com.chint.infrastructure.constant.CommonMessageConstant.NOT_FOUND; import static com.chint.infrastructure.constant.DataMessageConstant.DATA_NOT_FOUND; import static com.chint.infrastructure.constant.LegConstant.*; import static com.chint.infrastructure.constant.OrderConstant.*; @@ -207,6 +206,9 @@ public class LegEventHandler implements LegEventService { String orderNo = data.getSelfOrderNo(); RouteOrder routeOrder = routeRequestDomainService.getRouteOrder(orderNo); //获取行程规划单创建者作为该订单 + if (routeOrder == null) { + throw new OrderException(NOT_FOUND + "单号为" + orderNo); + } String employeeNo = routeOrder.getUserId(); User byUserEmployeeNo = userRepository.findByUserEmployeeNo(employeeNo); BaseContext.setCurrentUser(byUserEmployeeNo); @@ -307,8 +309,15 @@ public class LegEventHandler implements LegEventService { List routeRequestList = routeOrder.getRouteRequestList(); - if(routeRequestList != null && !routeRequestList.isEmpty()) { - routeRequestList.forEach(it->syncAdapter.of(it.getSupplier()).cancelRouteRequest(it)); + if (routeRequestList != null && !routeRequestList.isEmpty()) { + routeRequestList.forEach(it -> { + List legIds = it.getRouteRequestLegList().stream().map(RouteRequestLeg::getLegId).toList(); + it.reloadGenerateRequestLegs(routeOrder.getLegItems() + .stream() + .filter(leg -> legIds.contains(leg.getLegId())) + .toList()); + syncAdapter.of(it.getSupplier()).cancelRouteRequest(it); + }); } else { if (!list.isEmpty() && !syncAdapter.of(routeOrder.getSupplierName()).cancelSyncSupplierOrder(routeOrder)) { throw new CommandException("订单取消失败"); @@ -389,7 +398,7 @@ public class LegEventHandler implements LegEventService { } case ANYS_BPM -> { JTH3ChangeDto jth3ChangeDto = new JTH3ChangeDto(); - bpmRequest.change(jth3ChangeDto,AN_FSSC,userId,accountCompany); + bpmRequest.change(jth3ChangeDto, AN_FSSC, userId, accountCompany); } default -> throw new NotFoundException(DATA_NOT_FOUND); } diff --git a/src/main/java/com/chint/infrastructure/cache/RouteCacheService.java b/src/main/java/com/chint/infrastructure/cache/RouteCacheService.java index 99b8b87b..6206ad6e 100644 --- a/src/main/java/com/chint/infrastructure/cache/RouteCacheService.java +++ b/src/main/java/com/chint/infrastructure/cache/RouteCacheService.java @@ -1,17 +1,23 @@ package com.chint.infrastructure.cache; +import com.chint.application.commands.UserLoginCommand; import com.chint.domain.aggregates.order.ApproveOrderNo; import com.chint.domain.aggregates.order.RouteOrder; import com.chint.domain.aggregates.user.User; +import com.chint.infrastructure.echo_framework.annotation.ListenTo; import com.chint.infrastructure.repository.jdbc.JdbcRouteRepository; import com.chint.infrastructure.util.BaseContext; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.List; import java.util.Objects; +import java.util.Optional; +import java.util.concurrent.CompletableFuture; +@Slf4j @Service public class RouteCacheService { @Autowired @@ -21,7 +27,16 @@ public class RouteCacheService { private JdbcRouteRepository jdbcRouteRepository; + @ListenTo(command = "UserLoginCommand", order = 9) + public void loginAndPreloadUserRoutes(UserLoginCommand command) { + Optional.ofNullable(command.getUser()) + .flatMap(it -> Optional.ofNullable(it.getEmployeeNo())) + .ifPresent(it -> CompletableFuture.runAsync(() -> preloadUserRoutes(it))); + } + + public List preloadUserRoutes(String employeeNo) { + log.info("开始缓存用户行程规划单"); List routeOrders = jdbcRouteRepository.findByUserIdOrApproveOrderNo_Creator(employeeNo, employeeNo); for (RouteOrder routeOrder : routeOrders) { routeCacheManage.cacheRouteOrder(routeOrder); diff --git a/src/main/java/com/chint/infrastructure/export/OrderDetailExportFactory.java b/src/main/java/com/chint/infrastructure/export/OrderDetailExportFactory.java index e9cb84f3..e543e71a 100644 --- a/src/main/java/com/chint/infrastructure/export/OrderDetailExportFactory.java +++ b/src/main/java/com/chint/infrastructure/export/OrderDetailExportFactory.java @@ -35,9 +35,9 @@ public class OrderDetailExportFactory { orderDetailExport.setProjectCode(it.getProjectOrderNo()); orderDetailExport.setSupplierName(translateSupplierName(it.getTrvaleSysType())); User byUserEmployeeNo = null; - if (it.getUserCode() != null) { + if (it.getUserCode() != null && !it.getUserCode().isEmpty()) { byUserEmployeeNo = userRepository.findByUserEmployeeNo(it.getUserCode()); - } else if (it.getBookingUserCode() != null) { + } else if (it.getBookingUserCode() != null && !it.getBookingUserCode().isEmpty()) { byUserEmployeeNo = userRepository.findByUserEmployeeNo(it.getBookingUserCode()); } if (byUserEmployeeNo != null) { @@ -74,7 +74,7 @@ public class OrderDetailExportFactory { orderDetailExport.setProjectCode(it.getProjectOrderNo()); orderDetailExport.setSupplierName(translateSupplierName(it.getTrvaleSysType())); User byUserEmployeeNo = null; - if (it.getBookingUserCode() != null) { + if (it.getBookingUserCode() != null && !it.getBookingUserCode().isEmpty()) { byUserEmployeeNo = userRepository.findByUserEmployeeNo(it.getBookingUserCode()); } if (byUserEmployeeNo != null) { @@ -111,9 +111,9 @@ public class OrderDetailExportFactory { orderDetailExport.setProjectCode(it.getProjectOrderNo()); orderDetailExport.setSupplierName(translateSupplierName(it.getTrvaleSysType())); User byUserEmployeeNo = null; - if (it.getUserCode() != null) { + if (it.getUserCode() != null && !it.getUserCode().isEmpty()) { byUserEmployeeNo = userRepository.findByUserEmployeeNo(it.getUserCode()); - } else if (it.getBookingUserCode() != null) { + } else if (it.getBookingUserCode() != null && !it.getBookingUserCode().isEmpty()) { byUserEmployeeNo = userRepository.findByUserEmployeeNo(it.getBookingUserCode()); } if (byUserEmployeeNo != null) { @@ -150,9 +150,9 @@ public class OrderDetailExportFactory { orderDetailExport.setProjectCode(it.getProjectOrderNo()); orderDetailExport.setSupplierName(translateSupplierName(it.getTrvaleSysType())); User byUserEmployeeNo = null; - if (it.getUserCode() != null) { + if (it.getUserCode() != null && !it.getUserCode().isEmpty()) { byUserEmployeeNo = userRepository.findByUserEmployeeNo(it.getUserCode()); - } else if (it.getBookingUserCode() != null) { + } else if (it.getBookingUserCode() != null && !it.getBookingUserCode().isEmpty()) { byUserEmployeeNo = userRepository.findByUserEmployeeNo(it.getBookingUserCode()); } if (byUserEmployeeNo != null) { @@ -191,6 +191,7 @@ public class OrderDetailExportFactory { return "未知"; } return switch (orderStatus) { + case "0" -> "已取消"; case "1" -> "预定成功"; case "2" -> "改签成功"; case "3" -> "退费成功"; diff --git a/src/main/java/com/chint/infrastructure/util/SystemUtil.java b/src/main/java/com/chint/infrastructure/util/SystemUtil.java index d4a10ec3..d7242b5c 100644 --- a/src/main/java/com/chint/infrastructure/util/SystemUtil.java +++ b/src/main/java/com/chint/infrastructure/util/SystemUtil.java @@ -9,7 +9,7 @@ public class SystemUtil { case BELONG_SYS_TYPE_FSSC -> BELONG_SYS_CODE_FSSC; case BELONG_SYS_TYPE_H3BPM -> BELONG_SYS_CODE_H3BPM; case BELONG_SYS_TYPE_XNFSSC -> BELONG_SYS_CODE_XNFSSC; - case BELONG_SYS_TYPE_ANFSSC -> BELONG_SYS_CODE_XNFSSC; + case BELONG_SYS_TYPE_ANFSSC -> BELONG_SYS_CODE_ANFSSC; default -> BELONG_SYS_TYPE_NOT; }; } diff --git a/src/main/java/com/chint/interfaces/rest/ctrip/CTripUserSaveRequest.java b/src/main/java/com/chint/interfaces/rest/ctrip/CTripUserSaveRequest.java index e2101d7f..e0534244 100644 --- a/src/main/java/com/chint/interfaces/rest/ctrip/CTripUserSaveRequest.java +++ b/src/main/java/com/chint/interfaces/rest/ctrip/CTripUserSaveRequest.java @@ -1,8 +1,10 @@ package com.chint.interfaces.rest.ctrip; +import com.chint.application.commands.UserLoginCommand; import com.chint.domain.aggregates.user.User; import com.chint.domain.repository.UserNameRepository; import com.chint.infrastructure.constant.CTripConstant; +import com.chint.infrastructure.echo_framework.annotation.ListenTo; import com.chint.infrastructure.util.BaseContext; import com.chint.interfaces.rest.base.PostRequest; import com.chint.interfaces.rest.ctrip.dto.AuthenticationResponseList; @@ -10,15 +12,19 @@ import com.chint.interfaces.rest.ctrip.dto.user.AuthenticationEntity; import com.chint.interfaces.rest.ctrip.dto.user.AuthenticationInfo; import com.chint.interfaces.rest.ctrip.dto.user.AuthenticationListRequest; import com.chint.interfaces.rest.user.UserHttpRequest; +import com.chint.interfaces.rest.user.UserSync; import jakarta.annotation.PostConstruct; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import java.util.List; +import java.util.concurrent.CompletableFuture; +@Slf4j @Service -public class CTripUserSaveRequest { +public class CTripUserSaveRequest implements UserSync { @Autowired private PostRequest postRequest; @@ -103,4 +109,17 @@ public class CTripUserSaveRequest { authenticationEntity.setSubAccountName(subAccountName); return authenticationEntity; } + + @ListenTo(command = "UserLoginCommand",order = 1) + @Override + public User syncUserInfoToSupplier(UserLoginCommand command) { + User user = command.getUser(); + // 如果超过一天,执行同步代码 + if (user.checkSyncTime()) { + CompletableFuture.runAsync(() -> saveUserToCTrip(user)); + } else { + log.info("未超过一天,不执行携程同步"); + } + return user; + } } diff --git a/src/main/java/com/chint/interfaces/rest/ly/LYUserRequest.java b/src/main/java/com/chint/interfaces/rest/ly/LYUserRequest.java index bad63bfd..7d7939a4 100644 --- a/src/main/java/com/chint/interfaces/rest/ly/LYUserRequest.java +++ b/src/main/java/com/chint/interfaces/rest/ly/LYUserRequest.java @@ -1,23 +1,28 @@ package com.chint.interfaces.rest.ly; +import com.chint.application.commands.UserLoginCommand; import com.chint.domain.aggregates.user.User; import com.chint.domain.repository.UserNameRepository; +import com.chint.infrastructure.echo_framework.annotation.ListenTo; import com.chint.infrastructure.util.BaseContext; import com.chint.interfaces.rest.ly.dto.user.EmployeeEntity; import com.chint.interfaces.rest.ly.dto.user.EmployeeRequest; import com.chint.interfaces.rest.ly.dto.user.UserResponse; import com.chint.interfaces.rest.user.UserHttpRequest; +import com.chint.interfaces.rest.user.UserSync; import jakarta.annotation.PostConstruct; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import java.util.concurrent.CompletableFuture; + import static com.chint.infrastructure.constant.LYConstant.L_Y_USER_PATH; @Slf4j @Service -public class LYUserRequest { +public class LYUserRequest implements UserSync { @Value("${ly.baseUrl}") @@ -95,4 +100,17 @@ public class LYUserRequest { employeeEntity.setPositionLevelName(standardLevel); return employeeEntity; } + + @ListenTo(command = "UserLoginCommand",order = 0) + @Override + public User syncUserInfoToSupplier(UserLoginCommand command) { + User user = command.getUser(); + // 如果超过一天,执行同步代码 + if (user.checkSyncTime()) { + CompletableFuture.runAsync(() -> saveCurrentUser(user)); + } else { + log.info("未超过一天,不执行同程同步"); + } + return user; + } } diff --git a/src/main/java/com/chint/interfaces/rest/user/PushUser.java b/src/main/java/com/chint/interfaces/rest/user/PushUser.java index 4e7ccf04..97709727 100644 --- a/src/main/java/com/chint/interfaces/rest/user/PushUser.java +++ b/src/main/java/com/chint/interfaces/rest/user/PushUser.java @@ -202,7 +202,6 @@ public class PushUser { if (list == null) { return true; } - return list.isEmpty(); } } diff --git a/src/main/java/com/chint/interfaces/rest/user/UserSync.java b/src/main/java/com/chint/interfaces/rest/user/UserSync.java new file mode 100644 index 00000000..f26ffadf --- /dev/null +++ b/src/main/java/com/chint/interfaces/rest/user/UserSync.java @@ -0,0 +1,10 @@ +package com.chint.interfaces.rest.user; + +import com.chint.application.commands.UserLoginCommand; +import com.chint.domain.aggregates.user.User; + +import java.lang.reflect.Modifier; + +public interface UserSync { + User syncUserInfoToSupplier(UserLoginCommand command); +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 9325ffc5..186068ee 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -8,7 +8,7 @@ spring: password: ${chint.datasource.password} hikari: minimum-idle: 20 - maximum-pool-size: 50 # 连接池最大连接数 + maximum-pool-size: 60 # 连接池最大连接数 idle-timeout: 300000 # 空闲连接超时时间(毫秒) max-lifetime: 1800000 # 连接的最长生命周期(毫秒) connection-timeout: 60000 # 连接超时时间(毫秒) diff --git a/src/test/java/com/chint/RouteApplicationTests.java b/src/test/java/com/chint/RouteApplicationTests.java index 13bcf76e..87621dab 100644 --- a/src/test/java/com/chint/RouteApplicationTests.java +++ b/src/test/java/com/chint/RouteApplicationTests.java @@ -286,7 +286,7 @@ class RouteApplicationTests { @Test void loginSignProd() { - String sfno = "220607056"; + String sfno = "240305077"; String syscode = "FSSC"; String billcode = "CLSQ240225000099"; String companycode = "正泰集团股份有限公司"; @@ -1294,4 +1294,6 @@ class RouteApplicationTests { } System.out.println(rankName); } + + }