diff --git a/src/main/java/com/chint/application/commands/UserDisabledCommand.java b/src/main/java/com/chint/application/commands/UserDisabledCommand.java new file mode 100644 index 00000000..6926a35f --- /dev/null +++ b/src/main/java/com/chint/application/commands/UserDisabledCommand.java @@ -0,0 +1,18 @@ +package com.chint.application.commands; + +import com.chint.domain.aggregates.user.User; +import com.chint.infrastructure.echo_framework.command.Command; +import lombok.Data; + +import java.util.List; + +@Data +public class UserDisabledCommand extends Command { + private User user; + private List userList; + + public UserDisabledCommand 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 a697b024..52256ce9 100644 --- a/src/main/java/com/chint/application/in/AutoWorkController.java +++ b/src/main/java/com/chint/application/in/AutoWorkController.java @@ -12,6 +12,7 @@ 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.chint.interfaces.rest.user.BatchUserWorker; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -38,6 +39,18 @@ public class AutoWorkController { @Autowired private LyStatementOrder lyStatementOrder; + @Autowired + private BatchUserWorker batchUserWorker; + + + @ApiOperation("用户状态检查,离职用户将关闭开卡") + @PostMapping("/user/status/check") + public Result autoCheckUserStatus(){ + batchUserWorker.checkUserStatus(); + return Result.Success(SUCCESS); + } + + @Transactional @ApiOperation("自动拉取昨天的流水号,每天晚上8点执行") @PostMapping("/cTrip/record/save") diff --git a/src/main/java/com/chint/application/out/LoginController.java b/src/main/java/com/chint/application/out/LoginController.java index 543a7381..f0734e8c 100644 --- a/src/main/java/com/chint/application/out/LoginController.java +++ b/src/main/java/com/chint/application/out/LoginController.java @@ -150,11 +150,9 @@ public class LoginController { @PostMapping("/AN/login/sso") public Result ANLoginSSO(@RequestBody UserLoginParam userLoginParam) { String employeeNo = anFeiShuLoginStrategy.login(userLoginParam.getCode()); - userLoginParam.setSfno(employeeNo); UserLoginResult userLoginResult = authenticateService .authenticateEmployeeNo(userLoginParam); - //异步执行更新用户信息到同程 User currentUser = BaseContext.getCurrentUser(); loginEventBoarder(currentUser); @@ -163,7 +161,6 @@ public class LoginController { private void loginEventBoarder(User user) { - Command.of(UserSFCommand.class).user(user).sendToQueue(); Command.of(UserLoginCommand.class).user(user).sendToQueue(); user.setSyncTime(LocalDateTime.now()); userRepository.save(user); diff --git a/src/main/java/com/chint/application/out/UserController.java b/src/main/java/com/chint/application/out/UserController.java index 0703dee8..8fbf135b 100644 --- a/src/main/java/com/chint/application/out/UserController.java +++ b/src/main/java/com/chint/application/out/UserController.java @@ -7,7 +7,7 @@ import com.chint.domain.aggregates.user.UserDepartmentInfo; import com.chint.domain.repository.UserRepository; import com.chint.infrastructure.util.BaseContext; import com.chint.infrastructure.util.Result; -import com.chint.interfaces.rest.user.PushUser; +import com.chint.interfaces.rest.user.BatchUserWorker; import com.chint.interfaces.rest.user.UserHttpRequest; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; @@ -22,7 +22,7 @@ import static com.chint.infrastructure.constant.CommonMessageConstant.SUCCESS; public class UserController { @Autowired - private PushUser pushUser; + private BatchUserWorker pushUser; @Autowired private UserRepository userRepository; 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 2fb565dc..00b5dd75 100644 --- a/src/main/java/com/chint/domain/aggregates/user/User.java +++ b/src/main/java/com/chint/domain/aggregates/user/User.java @@ -57,6 +57,7 @@ public class User implements Serializable { private String phoneNumber; private String password; private LocalDateTime syncTime; + private Integer status; @Transient private String manaLevel; @Transient @@ -82,6 +83,12 @@ public class User implements Serializable { if (this.userDepartmentInfoList == null || this.userDepartmentInfoList.isEmpty()) { //如果发现 用户的 部门信息为空, 那么直接调用 sf查询 Command.of(UserSFCommand.class).user(this).sendToQueue(); + } else { + for (UserDepartmentInfo userDepartmentInfo : userDepartmentInfoList) { + if (userDepartmentInfo.getUname() == null) { + Command.of(UserSFCommand.class).user(this).sendToQueue(); + } + } } if (userDepartmentInfoList == null) { throw new NotFoundException(SF_DATA_NOT_EXIST); @@ -116,7 +123,6 @@ public class User implements Serializable { UserDepartmentInfo fallbackDeptInfo = getFallbackDeptInfo(); loadInfoFromDeptInfo(fallbackDeptInfo); } - return this; } 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 0499e5d0..3ab722ee 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 @@ -392,9 +392,6 @@ public class CTripOrderExtensionFactoryImpl implements OrderExtensionFactory { hotelOrderDetail = new HotelOrderDetail(); } - -// hotelOrderDetail.setSupplier(SUPPLIER_C_TRIP_EXTENSION_NAME); - hotelOrderDetail.setTrvaleSysType(TRAVAL_SYS_TYPE_CTRIP); if (routeOrder != null) { @@ -421,7 +418,10 @@ public class CTripOrderExtensionFactoryImpl implements OrderExtensionFactory { user = userRepository.findByUserEmployeeNo(EmployeeNo); } - Optional first = routeOrder.getOrderDetails().stream().filter(orderDetail -> orderDetail.getOrderNo().equals(orderNo)).findFirst(); + Optional first = routeOrder + .getOrderDetails() + .stream() + .filter(orderDetail -> orderDetail.getOrderNo().equals(orderNo)).findFirst(); first.ifPresent(orderDetail -> { OrderEvent lastEvent = orderDetail.getLastEvent(); if (lastEvent != null) { @@ -546,6 +546,8 @@ public class CTripOrderExtensionFactoryImpl implements OrderExtensionFactory { @Override public HotelOrderDetail updateHotelOrderDetailData(HotelOrderDetail hotelOrderDetail, Object hotelOrderInfo) { + + return null; } diff --git a/src/main/java/com/chint/domain/repository/UserRepository.java b/src/main/java/com/chint/domain/repository/UserRepository.java index daa981bf..02700cbf 100644 --- a/src/main/java/com/chint/domain/repository/UserRepository.java +++ b/src/main/java/com/chint/domain/repository/UserRepository.java @@ -2,8 +2,20 @@ package com.chint.domain.repository; import com.chint.domain.aggregates.user.User; +import java.util.List; + public interface UserRepository { User findById(Long id); + User findByUserEmployeeNo(String employeeNo); + User save(User user); + + void saveAll(List userList); + + List findAll(); + + List findByStatus(Integer status); + + List findByStatusIsNull(); } \ No newline at end of file diff --git a/src/main/java/com/chint/domain/service/OrderDomainService.java b/src/main/java/com/chint/domain/service/OrderDomainService.java index b17aa300..196aff5b 100644 --- a/src/main/java/com/chint/domain/service/OrderDomainService.java +++ b/src/main/java/com/chint/domain/service/OrderDomainService.java @@ -16,6 +16,7 @@ import com.chint.infrastructure.echo_framework.annotation.ListenTo; import com.chint.infrastructure.echo_framework.command.Command; import com.chint.infrastructure.repository.jdbc.JdbcLegRepository; import com.chint.infrastructure.repository.jdbc.JdbcOrderDetailRepository; +import com.chint.infrastructure.util.DateTimeUtil; import com.chint.interfaces.rest.bpm.BPMParamFactory; import com.chint.interfaces.rest.bpm.BPMRequest; import com.chint.interfaces.rest.ctrip.CTripOrderSearchRequest; @@ -211,7 +212,7 @@ public class OrderDomainService { if (!orderEventType.equals(ORDER_EVENT_ETA) && orderDetail.getProductType().equals(LEG_TYPE_AIRPLANE)) { cTripFlightRefundAndChangeOrder(orderDetail.getOrderNo()); } - if (!orderEventType.equals(ORDER_EVENT_ETA) && orderDetail.getProductType().equals(LEG_TYPE_HOTEL)) { + if (orderDetail.getProductType().equals(LEG_TYPE_HOTEL)) { cTripHotelRefundAndChangeOrder(orderDetail.getOrderNo()); } if (!orderEventType.equals(ORDER_EVENT_ETA) && orderDetail.getProductType().equals(LEG_TYPE_TAXI)) { @@ -309,17 +310,16 @@ public class OrderDomainService { private void cTripHotelRefundAndChangeOrder(String orderNo) { SearchOrderResponse response = cTripOrderSearchRequest.searchOrderResponseByOrderId(orderNo); - HotelOrderInfoEntity flightOrderInfoEntity = response.getItineraryList().get(0).getHotelOrderInfoList().get(0); - List refundInfo = flightOrderInfoEntity.getRefundInfo(); + HotelOrderInfoEntity hotelOrderInfoEntity = response.getItineraryList().get(0).getHotelOrderInfoList().get(0); + List refundInfo = hotelOrderInfoEntity.getRefundInfo(); if (refundInfo != null && !refundInfo.isEmpty()) { for (RefundInfo flightRefundInfo : refundInfo) { - if (flightOrderInfoEntity.getOrderDetailStatus().equals("Cancelled")) { - Command.of(RefundOrderGenerateCommand.class).Info(String.valueOf(flightRefundInfo.getRefundInfoID()), - flightOrderInfoEntity.getOrderID(), - "-" + flightRefundInfo.getRefundCustomerAmount(), - "4", - flightOrderInfoEntity.getCancelTime()).sendToQueue(); - } + Command.of(RefundOrderGenerateCommand.class) + .Info(String.valueOf(flightRefundInfo.getRefundInfoID()), + hotelOrderInfoEntity.getOrderID(), + "-" + flightRefundInfo.getRefundCustomerAmount(), + "4", + DateTimeUtil.timeToStrCommon(LocalDateTime.now())).sendToQueue(); } } } @@ -425,7 +425,7 @@ public class OrderDomainService { } public RouteOrder checkRouteOrderStatus(RouteOrder routeOrder) { - if(routeOrder.getOrderStatus() == null ) { + if (routeOrder.getOrderStatus() == null) { routeOrder.reloadStatus(); routeRepository.save(routeOrder); } diff --git a/src/main/java/com/chint/infrastructure/repository/UserRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/UserRepositoryImpl.java index 007e0ca6..01be279d 100644 --- a/src/main/java/com/chint/infrastructure/repository/UserRepositoryImpl.java +++ b/src/main/java/com/chint/infrastructure/repository/UserRepositoryImpl.java @@ -8,6 +8,9 @@ import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Repository; +import java.util.ArrayList; +import java.util.List; + @Repository public class UserRepositoryImpl implements UserRepository { @@ -32,4 +35,28 @@ public class UserRepositoryImpl implements UserRepository { public User save(User user) { return jdbcUserRepository.save(user); } + + @Override + public void saveAll(List userList) { + jdbcUserRepository.saveAll(userList); + } + + + @Override + public List findAll() { + List userList = new ArrayList<>(); + jdbcUserRepository.findAll() + .forEach(userList::add); + return userList; + } + + @Override + public List findByStatus(Integer status) { + return jdbcUserRepository.findByStatus(status); + } + + @Override + public List findByStatusIsNull() { + return jdbcUserRepository.findByStatusIsNull(); + } } diff --git a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcUserRepository.java b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcUserRepository.java index a50339ee..b04780fa 100644 --- a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcUserRepository.java +++ b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcUserRepository.java @@ -4,8 +4,13 @@ import com.chint.domain.aggregates.user.User; import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public interface JdbcUserRepository extends CrudRepository { User findByEmployeeNo(String employeeNo); + List findByStatus(Integer status); + + List findByStatusIsNull(); } diff --git a/src/main/java/com/chint/interfaces/rest/amap/AmapUserRequest.java b/src/main/java/com/chint/interfaces/rest/amap/AmapUserRequest.java index d1a4fa32..95b11275 100644 --- a/src/main/java/com/chint/interfaces/rest/amap/AmapUserRequest.java +++ b/src/main/java/com/chint/interfaces/rest/amap/AmapUserRequest.java @@ -1,5 +1,6 @@ package com.chint.interfaces.rest.amap; +import com.chint.application.commands.UserDisabledCommand; import com.chint.application.commands.UserLoginCommand; import com.chint.domain.aggregates.user.User; import com.chint.domain.repository.UserNameRepository; @@ -80,6 +81,17 @@ public class AmapUserRequest implements UserSync { return user; } + @ListenTo(command = "UserDisabledCommand",order = 0) + @Override + public Boolean disableUserToSupplier(UserDisabledCommand command) { + User user = command.getUser(); + String updateUserUrl = BaseUrl + USER_UPDATE_PATH; + UserParam userParamByUser = createUserParamByUser(user); + userParamByUser.setStatus(0); + BaseResponse post = amapRequest.post(updateUserUrl, userParamByUser, BaseResponse.class); + return post.getCode().equals(1); + } + @Data public static class UserParam extends BaseRequestParam { private String userId; // 用户Id 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 e0534244..2f38eb76 100644 --- a/src/main/java/com/chint/interfaces/rest/ctrip/CTripUserSaveRequest.java +++ b/src/main/java/com/chint/interfaces/rest/ctrip/CTripUserSaveRequest.java @@ -1,5 +1,6 @@ package com.chint.interfaces.rest.ctrip; +import com.chint.application.commands.UserDisabledCommand; import com.chint.application.commands.UserLoginCommand; import com.chint.domain.aggregates.user.User; import com.chint.domain.repository.UserNameRepository; @@ -86,6 +87,11 @@ public class CTripUserSaveRequest implements UserSync { } public void saveUserToCTrip(User user) { + AuthenticationListRequest authenticationListRequest = buildUserParam(user); + postRequest.post(userUrl, authenticationListRequest, AuthenticationResponseList.class); + } + + private AuthenticationListRequest buildUserParam(User user) { String ticket = ticketRequest.loadTicket(); AuthenticationEntity authenticationEntity = buildAuthenticationEntityWithUser(user); AuthenticationListRequest authenticationListRequest = new AuthenticationListRequest(); @@ -96,7 +102,7 @@ public class CTripUserSaveRequest implements UserSync { authenticationInfo.setSequence("0"); authenticationInfo.setAuthentication(authenticationEntity); authenticationListRequest.setAuthenticationInfoList(List.of(authenticationInfo)); - postRequest.post(userUrl, authenticationListRequest, AuthenticationResponseList.class); + return authenticationListRequest; } @@ -105,12 +111,12 @@ public class CTripUserSaveRequest implements UserSync { userNameRepository.findByEmployeeNo(user.getEmployeeNo()).ifPresentOrElse(it -> authenticationEntity.setName(it.getIdName()), () -> authenticationEntity.setName(user.getName())); authenticationEntity.setEmployeeID(user.getEmployeeNo()); - authenticationEntity.setValid(user.getWorkStatus().charAt(0)); + authenticationEntity.setValid(user.getWorkStatus() == null ? 'A' : 'I'); authenticationEntity.setSubAccountName(subAccountName); return authenticationEntity; } - @ListenTo(command = "UserLoginCommand",order = 1) + @ListenTo(command = "UserLoginCommand", order = 1) @Override public User syncUserInfoToSupplier(UserLoginCommand command) { User user = command.getUser(); @@ -122,4 +128,18 @@ public class CTripUserSaveRequest implements UserSync { } return user; } + + @ListenTo(command = "UserDisabledCommand", order = 1) + @Override + public Boolean disableUserToSupplier(UserDisabledCommand command) { + User user = command.getUser(); + AuthenticationListRequest authenticationListRequest = buildUserParam(user); + List authenticationInfoList = authenticationListRequest.getAuthenticationInfoList(); + if (authenticationInfoList != null && !authenticationInfoList.isEmpty()) { + AuthenticationInfo authenticationInfo = authenticationInfoList.get(0); + authenticationInfo.getAuthentication().setValid('I'); + } + AuthenticationResponseList response = postRequest.post(userUrl, authenticationListRequest, AuthenticationResponseList.class); + return response.getResult().equals("Success"); + } } 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 65fc79b4..d3c6f0cc 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 @@ -1,5 +1,6 @@ package com.chint.interfaces.rest.ctrip.in; +import cn.hutool.core.bean.BeanUtil; import com.chint.application.commands.OrderStatusChangeCommand; import com.chint.domain.aggregates.order.OrderDetail; import com.chint.domain.repository.SupplierCallBackLogRepository; @@ -15,6 +16,7 @@ import com.chint.interfaces.rest.ctrip.dto.put.CTripStatusNotification; import com.chint.interfaces.rest.ctrip.dto.search.ItineraryEntity; import com.chint.interfaces.rest.ctrip.dto.search.SearchOrderResponse; import com.chint.interfaces.rest.ctrip.dto.search.hotel.HotelOrderInfoEntity; +import com.chint.interfaces.rest.ctrip.dto.search.hotel.RefundInfo; import com.chint.interfaces.rest.ctrip.tools.CTripUtils; import com.google.gson.Gson; import lombok.extern.slf4j.Slf4j; @@ -29,9 +31,11 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.List; import java.util.concurrent.TimeUnit; import static com.chint.infrastructure.constant.LegConstant.*; +import static com.chint.infrastructure.constant.OrderConstant.ORDER_EVENT_REFUND; import static com.chint.infrastructure.constant.OrderConstant.ORDER_STATUS_REFUSE_MSG; import static com.chint.infrastructure.constant.SupplierNameConstant.SUPPLIER_C_TRIP; @@ -159,7 +163,12 @@ public class CTripNoteController { .extension(getETAReason(response, LEG_TYPE_AIRPLANE)); break; case LEG_TYPE_HOTEL: - command.eventType(CTripUtils.mapHotelStatus(orderStatus)) + Integer eventType = CTripUtils.mapHotelStatus(orderStatus); + if (!eventType.equals(ORDER_EVENT_REFUND)) { + //如果是酒店的话会存在部分退款的情况 ,需要额外发送一个部分退款状态 + checkHotelIfRefund(response, command); + } + command.eventType(eventType) .extension(getETAReason(response, LEG_TYPE_HOTEL)); break; case LEG_TYPE_TRAIN: @@ -175,6 +184,21 @@ public class CTripNoteController { return Result.Success("成功收到消息"); } + + private void checkHotelIfRefund(SearchOrderResponse response, OrderStatusChangeCommand command) { + ItineraryEntity itineraryEntity = response.getItineraryList().get(0); + List hotelOrderInfoList = itineraryEntity.getHotelOrderInfoList(); + if (hotelOrderInfoList != null && !hotelOrderInfoList.isEmpty()) { + HotelOrderInfoEntity hotelOrderInfoEntity = hotelOrderInfoList.get(0); + List refundInfo = hotelOrderInfoEntity.getRefundInfo(); + if (refundInfo != null && !refundInfo.isEmpty()) { + OrderStatusChangeCommand orderStatusChangeCommand = BeanUtil + .copyProperties(command, OrderStatusChangeCommand.class); + orderStatusChangeCommand.outStatus("部分退款").eventType(ORDER_EVENT_REFUND).sendToQueue(); + } + } + } + private String getETAReason(SearchOrderResponse response, Integer productType) { ItineraryEntity itineraryEntity = response.getItineraryList().get(0); return switch (productType) { 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 7d7939a4..b71b8edc 100644 --- a/src/main/java/com/chint/interfaces/rest/ly/LYUserRequest.java +++ b/src/main/java/com/chint/interfaces/rest/ly/LYUserRequest.java @@ -1,5 +1,6 @@ package com.chint.interfaces.rest.ly; +import com.chint.application.commands.UserDisabledCommand; import com.chint.application.commands.UserLoginCommand; import com.chint.domain.aggregates.user.User; import com.chint.domain.repository.UserNameRepository; @@ -113,4 +114,16 @@ public class LYUserRequest implements UserSync { } return user; } + + @ListenTo(command = "UserDisabledCommand",order = 3) + @Override + public Boolean disableUserToSupplier(UserDisabledCommand command) { + User user = command.getUser(); + EmployeeEntity employeeEntity = user2LYEmployee(user); + employeeEntity.setWorkingState(0); + EmployeeRequest employeeData = new EmployeeRequest(); + employeeData.setParam(employeeEntity); + UserResponse post = postRequest.post(userUrl, employeeData, UserResponse.class); + return post.isSuccess(); + } } diff --git a/src/main/java/com/chint/interfaces/rest/user/PushUser.java b/src/main/java/com/chint/interfaces/rest/user/BatchUserWorker.java similarity index 84% rename from src/main/java/com/chint/interfaces/rest/user/PushUser.java rename to src/main/java/com/chint/interfaces/rest/user/BatchUserWorker.java index 97709727..f5ef29b2 100644 --- a/src/main/java/com/chint/interfaces/rest/user/PushUser.java +++ b/src/main/java/com/chint/interfaces/rest/user/BatchUserWorker.java @@ -1,5 +1,6 @@ package com.chint.interfaces.rest.user; +import com.chint.application.commands.UserDisabledCommand; import com.chint.dc.api.DataCenterResult; import com.chint.dc.api.dto.DataCenterOption; import com.chint.dc.api.service.DataCenterService; @@ -7,6 +8,7 @@ import com.chint.domain.aggregates.user.User; import com.chint.domain.repository.StaffRankRepository; import com.chint.domain.repository.UserRepository; import com.chint.domain.service.JTCompanyDomainService; +import com.chint.infrastructure.echo_framework.command.Command; import com.chint.interfaces.rest.ctrip.CTripUserSaveRequest; import com.chint.interfaces.rest.ly.LYUserRequest; import com.chint.interfaces.rest.user.dto.AccessKeyDTO; @@ -35,7 +37,7 @@ import static com.chint.infrastructure.constant.SFConstant.*; @Slf4j @Component -public class PushUser { +public class BatchUserWorker { @Value("${sf.systemId}") private String systemId; @@ -79,12 +81,38 @@ public class PushUser { } } + public void checkUserStatus() { + List userList = userRepository.findByStatus(1); + List byStatusIsNull = userRepository.findByStatusIsNull(); + userList.addAll(byStatusIsNull); + List userStatusChangeList = new ArrayList<>(); + for (User user : userList) { + List userSFDataFromOpenApi = userSFRequest.getUserSFDataFromOpenApi(user); + for (UserDataDTO userDataDTO : userSFDataFromOpenApi) { + user.addDeptInfo(userDataDTO); + } + List userDataDTOList = userSFDataFromOpenApi + .stream() + .filter(it -> it.getStatus().equals("A")) + .toList(); + if (userDataDTOList.isEmpty()) { + //如果这里不存在状态为A的SF数据,说明他已经处于离职状态 + user.setStatus(0); + user.loadInfoFromDept(); + Command.of(UserDisabledCommand.class).user(user).sendToQueue(); + userStatusChangeList.add(user); + } + } + if (!userStatusChangeList.isEmpty()) { + userRepository.saveAll(userStatusChangeList); + } + } + public List getUserSFDataFromOpenApiBatch() { int pageSize = 1000; int page = 1; List list = new ArrayList<>(); boolean shouldContinue = true; - while (shouldContinue) { int start = (page - 1) * pageSize; log.info("Pulling user data. Page={}", page); @@ -135,12 +163,12 @@ public class PushUser { shouldContinue = false; } } - return list.stream() .filter(user -> user.getEmployeeNo() != null) .collect(Collectors.toList()); } + private List parseUserData(DataCenterResult result) { Type type = new TypeToken>() { }.getType(); @@ -175,7 +203,6 @@ public class PushUser { Optional.ofNullable(userRepository.findByUserEmployeeNo(user.getEmployeeNo())) .ifPresentOrElse( it -> { -// user.setUserId(it.getUserId()); if (it.checkSyncTime()) { it.setWorkStatus(user.getWorkStatus()); asyncUser(it); diff --git a/src/main/java/com/chint/interfaces/rest/user/UserHttpRequestImpl.java b/src/main/java/com/chint/interfaces/rest/user/UserHttpRequestImpl.java index 92896d84..1a99c06a 100644 --- a/src/main/java/com/chint/interfaces/rest/user/UserHttpRequestImpl.java +++ b/src/main/java/com/chint/interfaces/rest/user/UserHttpRequestImpl.java @@ -1,10 +1,11 @@ package com.chint.interfaces.rest.user; +import com.chint.application.commands.UserDisabledCommand; +import com.chint.application.commands.UserLoginCommand; import com.chint.application.commands.UserSFCommand; import com.chint.domain.aggregates.standards.Ranks; import com.chint.domain.aggregates.standards.StaffRank; -import com.chint.domain.aggregates.system.JTCompany; import com.chint.domain.aggregates.user.User; import com.chint.domain.aggregates.user.UserDepartmentInfo; import com.chint.domain.exceptions.NotFoundException; @@ -15,6 +16,7 @@ import com.chint.domain.service.JTCompanyDomainService; import com.chint.domain.service.RankDomainService; import com.chint.infrastructure.constant.SFConstant; import com.chint.infrastructure.echo_framework.annotation.ListenTo; +import com.chint.infrastructure.echo_framework.command.Command; import com.chint.infrastructure.util.BaseContext; import com.chint.infrastructure.util.StringCheck; import com.chint.interfaces.rest.base.PostRequest; @@ -120,6 +122,15 @@ public class UserHttpRequestImpl implements UserHttpRequest { } + @ListenTo(command = "UserLoginCommand", order = 0) + public void loadSfInfo(UserLoginCommand command) { + User user = command.getUser(); + if (user.checkSyncTime()) { + loadSFInfo(Command.of(UserSFCommand.class).user(user)); + } + } + + @ListenTo(command = "UserSFCommand", order = 0) public User loadSFInfo(UserSFCommand command) { User user = command.getUser(); @@ -139,6 +150,14 @@ public class UserHttpRequestImpl implements UserHttpRequest { for (UserDataDTO userDataDTO : fromJson) { user.addDeptInfo(userDataDTO); } + + if(fromJson.isEmpty()){ + user.setStatus(0); + user.loadInfoFromDept(); + Command.of(UserDisabledCommand.class).user(user).sendToQueue(); + } else { + user.setStatus(1); + } return user; } diff --git a/src/main/java/com/chint/interfaces/rest/user/UserSync.java b/src/main/java/com/chint/interfaces/rest/user/UserSync.java index f26ffadf..33235351 100644 --- a/src/main/java/com/chint/interfaces/rest/user/UserSync.java +++ b/src/main/java/com/chint/interfaces/rest/user/UserSync.java @@ -1,10 +1,11 @@ package com.chint.interfaces.rest.user; +import com.chint.application.commands.UserDisabledCommand; 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); + + Boolean disableUserToSupplier(UserDisabledCommand command); } diff --git a/src/test/java/com/chint/AmapTest.java b/src/test/java/com/chint/AmapTest.java index dc412579..a10e0bdd 100644 --- a/src/test/java/com/chint/AmapTest.java +++ b/src/test/java/com/chint/AmapTest.java @@ -34,6 +34,9 @@ public class AmapTest { @Autowired private AmapLocationRequest amapLocationRequest; + @Autowired + private OrderDetailRequest orderDetailRequest; + private Gson gson = new Gson(); private User user = new User(1L, "230615020", 1, "卢麟哲", "lulz1@chint.com", "15857193365", "A30000001"); @@ -43,41 +46,48 @@ public class AmapTest { @Autowired private SettleBillRequest settleBillRequest; + @Test + public void search() { + Gson gson = new Gson(); + OrderDetailResponse orderDetailResponse = orderDetailRequest.queryOrderDetail("40920084001340019626730137"); + System.out.println(gson.toJson(orderDetailResponse)); + } + /** * 完单数据查询 */ @Test public void pageFinishedOrder() { - List responses= settleBillRequest.pageFinishedOrder("20240401", "20240431"); + List responses = settleBillRequest.pageFinishedOrder("20240401", "20240431"); System.out.println(responses); } - @Test + @Test public void createUser() { BaseResponse baseResponse = amapUserRequest.createUser(user2); System.out.println(gson.toJson(baseResponse)); } @Test - public void queryUser(){ + public void queryUser() { UserQueryResponse userQueryResponse = amapUserRequest.queryUser(user2); System.out.println(gson.toJson(userQueryResponse)); } @Test - public void updateUser(){ + public void updateUser() { BaseResponse baseResponse = amapUserRequest.updateUser(user); System.out.println(gson.toJson(baseResponse)); } @Test - public void login(){ + public void login() { H5LoginResponse h5LoginResponse = amapLoginRequest.h5Login(user); System.out.println(gson.toJson(h5LoginResponse.getRedirectUrl())); } @Test - public void queryLocation(){ + public void queryLocation() { LocationResponse locationQuery = amapLocationRequest.locationQuery("北京"); System.out.println(gson.toJson(locationQuery.getData())); } @@ -85,10 +95,8 @@ public class AmapTest { @Autowired private TokenRequest tokenRequest; - @Autowired - private OrderDetailRequest orderDetailRequest; - @Test + @Test public void gaoDe() { // TokenDto.UserInfo userInfo = new TokenDto.UserInfo(); // userInfo.setUserId("230615020"); @@ -114,7 +122,7 @@ public class AmapTest { /** * 取消订单 */ -// @Test + // @Test public void cancelOrder() { takeCarRequest.cancelOrder("20240301", "行程变更"); } diff --git a/src/test/java/com/chint/RouteApplicationTests.java b/src/test/java/com/chint/RouteApplicationTests.java index a083c865..547d86be 100644 --- a/src/test/java/com/chint/RouteApplicationTests.java +++ b/src/test/java/com/chint/RouteApplicationTests.java @@ -10,7 +10,6 @@ import com.chint.domain.aggregates.location.basedata.CountryLevelInfoEntity; import com.chint.domain.aggregates.location.basedata.PrefectureLevelCityInfoEntity; import com.chint.domain.aggregates.order.Leg; import com.chint.domain.aggregates.order.Location; -import com.chint.domain.aggregates.order.RouteOrder; import com.chint.domain.aggregates.order.order_record.ctrip_order_record.CTripHotelRecord; import com.chint.domain.aggregates.user.User; import com.chint.domain.repository.*; @@ -38,7 +37,7 @@ import com.chint.interfaces.rest.ly.dto.hotelorderdatapushbach.OrderInfo; import com.chint.interfaces.rest.ly.dto.search.response.hotel.HotelDetailResponse; import com.chint.interfaces.rest.ly.dto.strokepush.StrokePushResult; import com.chint.interfaces.rest.ly.dto.strokepush.TrainChange.TrainChangeRequest; -import com.chint.interfaces.rest.user.PushUser; +import com.chint.interfaces.rest.user.BatchUserWorker; import com.chint.interfaces.rest.user.UserHttpRequest; import com.chint.interfaces.rest.user.UserHttpRequestImpl; import com.chint.interfaces.rest.user.UserSFRequest; @@ -49,17 +48,14 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.SpringBootTest; -import java.time.Instant; import java.time.LocalDate; import java.time.LocalDateTime; -import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.*; import java.util.stream.Collectors; import static com.chint.infrastructure.constant.LocationConstant.*; import static com.chint.infrastructure.constant.RankConstant.DEFAULT_RANK_NAME; -import static com.chint.infrastructure.util.DateTimeUtil.formatter; import static com.chint.infrastructure.util.DateTimeUtil.lastMonthStr; @Slf4j @@ -134,7 +130,7 @@ class RouteApplicationTests { private UserSFRequest userSFRequest; @Autowired - private PushUser pushUser; + private BatchUserWorker pushUser; @Autowired