From d500c7e701b27dbed2352ad2814ffa0552c9966f Mon Sep 17 00:00:00 2001 From: Superdandan <1033719135@qq.com> Date: Thu, 4 Apr 2024 16:20:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E7=94=A8=E6=88=B7=E8=BD=BD?= =?UTF-8?q?=E5=85=A5=E9=83=A8=E9=97=A8=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/out/LoginController.java | 19 +---- .../domain/aggregates/order/RouteOrder.java | 2 + .../order/RouterOrderExtensionField.java | 26 ++++++ .../order/order_record/OrderCarRecord.java | 8 ++ .../order/order_record/OrderFlightRecord.java | 8 ++ .../order/order_record/OrderHotelRecord.java | 8 ++ .../order/order_record/OrderTrainRecord.java | 8 ++ .../chint/domain/aggregates/user/User.java | 62 ++++++++++++++ .../aggregates/user/UserDepartmentInfo.java | 2 +- .../CTripOrderRecordExtensionFactory.java | 48 ++++++++++- .../interfaces/rest/user/UserHttpRequest.java | 2 + .../rest/user/UserHttpRequestImpl.java | 80 ++++++++++++------- 12 files changed, 223 insertions(+), 50 deletions(-) create mode 100644 src/main/java/com/chint/domain/aggregates/order/RouterOrderExtensionField.java diff --git a/src/main/java/com/chint/application/out/LoginController.java b/src/main/java/com/chint/application/out/LoginController.java index d09f78bf..aa1efbde 100644 --- a/src/main/java/com/chint/application/out/LoginController.java +++ b/src/main/java/com/chint/application/out/LoginController.java @@ -30,13 +30,9 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; -import java.time.Duration; import java.time.LocalDateTime; import java.util.concurrent.CompletableFuture; -import static com.chint.infrastructure.constant.BPMConstant.AN_FSSC; -import static com.chint.infrastructure.constant.BPMConstant.FSSC; - @Slf4j @RestController @RequestMapping("/public") @@ -200,20 +196,7 @@ public class LoginController { private void syncUserInfoToSupplier(User user) { // 给定的 LocalDateTime 实例,示例中为2024年3月1日15:00 - LocalDateTime lastSyncTime = user.getSyncTime(); - - if (lastSyncTime == null) { - asyncUser(user); - return; - } - // 获取当前时间 - LocalDateTime now = LocalDateTime.now(); - - // 计算当前时间与给定时间之间的持续时间 - Duration duration = Duration.between(lastSyncTime, now); - - // 判断是否超过一天 - if (duration.toDays() >= 1) { + if (user.checkSyncTime()) { asyncUser(user); } else { log.info("未超过一天,不执行同步。"); diff --git a/src/main/java/com/chint/domain/aggregates/order/RouteOrder.java b/src/main/java/com/chint/domain/aggregates/order/RouteOrder.java index 83abd914..3e88d7c7 100644 --- a/src/main/java/com/chint/domain/aggregates/order/RouteOrder.java +++ b/src/main/java/com/chint/domain/aggregates/order/RouteOrder.java @@ -78,6 +78,8 @@ public class RouteOrder implements Serializable { @Transient private String supplierCNName; + @MappedCollection(idColumn = "route_id") + private RouterOrderExtensionField routerOrderExtensionField; @MappedCollection(idColumn = "route_id", keyColumn = "route_order_key") private List legItems; diff --git a/src/main/java/com/chint/domain/aggregates/order/RouterOrderExtensionField.java b/src/main/java/com/chint/domain/aggregates/order/RouterOrderExtensionField.java new file mode 100644 index 00000000..29dfb26f --- /dev/null +++ b/src/main/java/com/chint/domain/aggregates/order/RouterOrderExtensionField.java @@ -0,0 +1,26 @@ +package com.chint.domain.aggregates.order; + +import lombok.Data; +import org.springframework.data.annotation.Id; +import org.springframework.data.relational.core.mapping.Column; +import org.springframework.data.relational.core.mapping.Table; + +import java.io.Serial; +import java.io.Serializable; + + +@Data +@Table("route_order_extension_field") +public class RouterOrderExtensionField implements Serializable { + + @Serial + private static final long serialVersionUID = 2212312435311609990L; + @Id + private Long id; + @Column("route_id") + private Long routeId; + + private String belongDeptCode; + + +} diff --git a/src/main/java/com/chint/domain/aggregates/order/order_record/OrderCarRecord.java b/src/main/java/com/chint/domain/aggregates/order/order_record/OrderCarRecord.java index c0df4fcf..6c76a6be 100644 --- a/src/main/java/com/chint/domain/aggregates/order/order_record/OrderCarRecord.java +++ b/src/main/java/com/chint/domain/aggregates/order/order_record/OrderCarRecord.java @@ -71,8 +71,16 @@ public class OrderCarRecord extends OrderBaseRecord { private String orderSource; // 预订来源:线上/线下 private String payAmount;//支付总金额 private String receiptsNumOrigin;//支付总金额 + private String belongDeport; //归属部门 + public OrderCarRecord loadBelongDeport(String belongDeport + ) { + // 行程信息 + this.setBelongDeport(belongDeport); + return this; + } + //添加行程信息 public OrderCarRecord loadTravelInfo(String startTime, String arriveTime, diff --git a/src/main/java/com/chint/domain/aggregates/order/order_record/OrderFlightRecord.java b/src/main/java/com/chint/domain/aggregates/order/order_record/OrderFlightRecord.java index 5967781b..b27dc60d 100644 --- a/src/main/java/com/chint/domain/aggregates/order/order_record/OrderFlightRecord.java +++ b/src/main/java/com/chint/domain/aggregates/order/order_record/OrderFlightRecord.java @@ -80,6 +80,14 @@ public class OrderFlightRecord extends OrderBaseRecord { private String createTime; private String receiptsNumOrigin;//原差旅申请单单号 private String payAmount; + private String belongDeport; //归属部门 + + public OrderFlightRecord loadBelongDeport(String belongDeport + ) { + // 行程信息 + this.setBelongDeport(belongDeport); + return this; + } // 加载基础订单信息 public OrderFlightRecord loadBasicOrderInfo(String orderNo, diff --git a/src/main/java/com/chint/domain/aggregates/order/order_record/OrderHotelRecord.java b/src/main/java/com/chint/domain/aggregates/order/order_record/OrderHotelRecord.java index befe93e2..52acf941 100644 --- a/src/main/java/com/chint/domain/aggregates/order/order_record/OrderHotelRecord.java +++ b/src/main/java/com/chint/domain/aggregates/order/order_record/OrderHotelRecord.java @@ -79,6 +79,14 @@ public class OrderHotelRecord extends OrderBaseRecord { private String orderStatus; private String createTime; private String receiptsNumOrigin;//支付总金额 + private String belongDeport; //归属部门 + + public OrderHotelRecord loadBelongDeport(String belongDeport + ) { + // 行程信息 + this.setBelongDeport(belongDeport); + return this; + } // 加载基础订单信息 public OrderHotelRecord loadBasicOrderInfo(String orderNo, diff --git a/src/main/java/com/chint/domain/aggregates/order/order_record/OrderTrainRecord.java b/src/main/java/com/chint/domain/aggregates/order/order_record/OrderTrainRecord.java index 7387fd4b..d9a30807 100644 --- a/src/main/java/com/chint/domain/aggregates/order/order_record/OrderTrainRecord.java +++ b/src/main/java/com/chint/domain/aggregates/order/order_record/OrderTrainRecord.java @@ -73,6 +73,14 @@ public class OrderTrainRecord extends OrderBaseRecord{ private String trainTime; // 发车时间 yyyy-MM-dd HH:‌mm:ss private String yxId; // 影像比对ID private String receiptsNumOrigin;//原差旅申请单单号 + private String belongDeport; //归属部门 + + public OrderTrainRecord loadBelongDeport(String belongDeport + ) { + // 行程信息 + this.setBelongDeport(belongDeport); + return this; + } // 加载基础订单信息 public OrderTrainRecord loadBasicOrderInfo(Long id, String orderNo, String orderStatus, String createTime) { this.setId(id); 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 f18560d3..09050fda 100644 --- a/src/main/java/com/chint/domain/aggregates/user/User.java +++ b/src/main/java/com/chint/domain/aggregates/user/User.java @@ -19,10 +19,12 @@ import org.springframework.data.relational.core.mapping.Table; import java.io.Serial; import java.io.Serializable; import java.lang.reflect.Type; +import java.time.Duration; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Optional; import static com.chint.infrastructure.constant.AuthMessageConstant.USER_FSSC_SYSTEM_LIST; import static com.chint.infrastructure.constant.BPMConstant.*; @@ -72,6 +74,66 @@ public class User implements Serializable { } + public UserDepartmentInfo.Builder addDeptInfo() { + return new UserDepartmentInfo.Builder(this); + } + + public String lowestDeptCode() { + Optional first = this.userDepartmentInfoList + .stream() + .filter(it -> it.getIfPrimary() == 1) + .findFirst(); + return first.map(this::lowestDept).orElse(null); + } + + public String lowestDeptCode(String companyName) { + Optional first = this.userDepartmentInfoList + .stream() + .filter(it -> it.getCompanyName().equals(companyName)) + .findFirst(); + return first.map(this::lowestDept).orElse(null); + } + + private String lowestDept(UserDepartmentInfo userDepartmentInfo) { + if (userDepartmentInfo.getDepartmentCodeSeven() != null) { + return userDepartmentInfo.getDepartmentCodeSeven(); + } + if (userDepartmentInfo.getDepartmentCodeSix() != null) { + return userDepartmentInfo.getDepartmentCodeSix(); + } + if (userDepartmentInfo.getDepartmentCodeFive() != null) { + return userDepartmentInfo.getDepartmentCodeFive(); + } + if (userDepartmentInfo.getDepartmentCodeFour() != null) { + return userDepartmentInfo.getDepartmentCodeFour(); + } + if (userDepartmentInfo.getDepartmentCodeThree() != null) { + return userDepartmentInfo.getDepartmentCodeThree(); + } + if (userDepartmentInfo.getDepartmentCodeTwo() != null) { + return userDepartmentInfo.getDepartmentCodeTwo(); + } + if (userDepartmentInfo.getDepartmentCodeOne() != null) { + return userDepartmentInfo.getDepartmentCodeOne(); + } + if (userDepartmentInfo.getCompanyCode() != null) { + return userDepartmentInfo.getCompanyCode(); + } + return null; + } + + public Boolean checkSyncTime() { + if (this.syncTime == null) { + return true; + } + // 获取当前时间 + LocalDateTime now = LocalDateTime.now(); + // 计算当前时间与给定时间之间的持续时间 + Duration duration = Duration.between(syncTime, now); + // 判断是否超过一天 + return duration.toDays() >= 1; + } + public User addDeptInfo(UserDepartmentInfo userDepartmentInfo) { if (this.userDepartmentInfoList == null) { this.userDepartmentInfoList = new ArrayList<>(); diff --git a/src/main/java/com/chint/domain/aggregates/user/UserDepartmentInfo.java b/src/main/java/com/chint/domain/aggregates/user/UserDepartmentInfo.java index 51ab774e..6127bfd3 100644 --- a/src/main/java/com/chint/domain/aggregates/user/UserDepartmentInfo.java +++ b/src/main/java/com/chint/domain/aggregates/user/UserDepartmentInfo.java @@ -63,7 +63,7 @@ public class UserDepartmentInfo implements Serializable { this.ifPrimary = ifPrimary; } - @Data + public static class Builder { private User user; private String companyCode; diff --git a/src/main/java/com/chint/domain/factoriy/order_record/CTripOrderRecordExtensionFactory.java b/src/main/java/com/chint/domain/factoriy/order_record/CTripOrderRecordExtensionFactory.java index f11cd154..4f3c246e 100644 --- a/src/main/java/com/chint/domain/factoriy/order_record/CTripOrderRecordExtensionFactory.java +++ b/src/main/java/com/chint/domain/factoriy/order_record/CTripOrderRecordExtensionFactory.java @@ -7,11 +7,14 @@ 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.ctrip_order_record.*; +import com.chint.domain.aggregates.user.User; import com.chint.domain.repository.LocationRepository; import com.chint.domain.repository.RouteRepository; +import com.chint.domain.repository.UserRepository; import com.chint.domain.service.OrderDetailDomainService; import com.chint.infrastructure.repository.jdbc.JdbcCtripHotelOrderDetailRepository; import com.chint.infrastructure.util.DateTimeUtil; +import com.chint.interfaces.rest.user.UserHttpRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -35,6 +38,11 @@ public class CTripOrderRecordExtensionFactory implements OrderRecordExtensionFac @Autowired private LocationRepository locationRepository; + @Autowired + private UserRepository userRepository; + @Autowired + private UserHttpRequest userHttpRequest; + private OrderRecordBasic buildWithRecord(CTripCarRecord cTripCarRecord) { OrderRecordBasic orderRecordBasic = new OrderRecordBasic(); CTripCarPassengerInfo cTripCarPassengerInfo = cTripCarRecord.getCTripCarPassengerInfo(); @@ -66,7 +74,6 @@ public class CTripOrderRecordExtensionFactory implements OrderRecordExtensionFac } else { orderRecordBasic.setBelongSysType(BELONG_SYS_TYPE_NOT); } - return orderRecordBasic; } @@ -173,6 +180,14 @@ public class CTripOrderRecordExtensionFactory implements OrderRecordExtensionFac "", cTripCarRecordBase.getCreateTime())); + //这里添加归属部门编号 , 这里兼容测试环境 , 如果行程规划单已经有这个值 , 那么直接取, 没有的话,查找用户的部门获取 + Optional routerOrderExtensionField = byOrderNo + .flatMap(it -> Optional.ofNullable(it.getRouterOrderExtensionField())); + routerOrderExtensionField.ifPresentOrElse(it -> orderCarRecord.loadBelongDeport(it.getBelongDeptCode()), + () -> orderCarRecord.loadBelongDeport( + belongDeport(orderCarRecord.getBookingUserCode(), orderCarRecord.getAccountCompanyName()) + )); + return orderCarRecord; } @@ -367,6 +382,15 @@ public class CTripOrderRecordExtensionFactory implements OrderRecordExtensionFac .loadBasicOrderInfo(String.valueOf(cTripFlightRecordBase.getOrderId()), "", cTripFlightRecordBase.getCreateTime())); + + + //这里添加归属部门编号 , 这里兼容测试环境 , 如果行程规划单已经有这个值 , 那么直接取, 没有的话,查找用户的部门获取 + Optional routerOrderExtensionField = byOrderNo + .flatMap(it -> Optional.ofNullable(it.getRouterOrderExtensionField())); + routerOrderExtensionField.ifPresentOrElse(it -> orderFlightRecord.loadBelongDeport(it.getBelongDeptCode()), + () -> orderFlightRecord.loadBelongDeport( + belongDeport(orderFlightRecord.getBookingUserCode(), orderFlightRecord.getAccountCompanyName()) + )); return orderFlightRecord; } @@ -553,6 +577,28 @@ public class CTripOrderRecordExtensionFactory implements OrderRecordExtensionFac cTripHotelOrderDetail.getDept2(), cTripHotelOrderDetail.getDept3()); + + //这里添加归属部门编号 , 这里兼容测试环境 , 如果行程规划单已经有这个值 , 那么直接取, 没有的话,查找用户的部门获取 + Optional routerOrderExtensionField = byOrderNo + .flatMap(it -> Optional.ofNullable(it.getRouterOrderExtensionField())); + routerOrderExtensionField.ifPresentOrElse(it -> orderHotelRecord.loadBelongDeport(it.getBelongDeptCode()), + () -> orderHotelRecord.loadBelongDeport( + belongDeport(orderHotelRecord.getBookingUserCode(), orderHotelRecord.getAccountCompanyName()) + )); return orderHotelRecord; } + + private String belongDeport(String accountCompanyName, String employeeNo) { + User user = userRepository.findByUserEmployeeNo(employeeNo); + if (user.getUserDepartmentInfoList() == null || user.getUserDepartmentInfoList().isEmpty()) { + userHttpRequest.loadUserDeptInfo(user); + } + String deptCode = user.lowestDeptCode(accountCompanyName); + if (deptCode == null) { + //根据入账公司没有找到部门编码的话,直接获取主岗编码 + deptCode = user.lowestDeptCode(); + } + //清除部门编码里面的字母 + return deptCode.replaceAll("\\D", ""); + } } diff --git a/src/main/java/com/chint/interfaces/rest/user/UserHttpRequest.java b/src/main/java/com/chint/interfaces/rest/user/UserHttpRequest.java index 9566c07f..41092f5e 100644 --- a/src/main/java/com/chint/interfaces/rest/user/UserHttpRequest.java +++ b/src/main/java/com/chint/interfaces/rest/user/UserHttpRequest.java @@ -4,4 +4,6 @@ import com.chint.domain.aggregates.user.User; public interface UserHttpRequest { User loadUserInfo(User user); + + User loadUserDeptInfo(User user); } \ No newline at end of file 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 da97aaa0..fd72becd 100644 --- a/src/main/java/com/chint/interfaces/rest/user/UserHttpRequestImpl.java +++ b/src/main/java/com/chint/interfaces/rest/user/UserHttpRequestImpl.java @@ -4,8 +4,10 @@ package com.chint.interfaces.rest.user; import com.chint.domain.aggregates.standards.Ranks; import com.chint.domain.aggregates.standards.StaffRank; import com.chint.domain.aggregates.user.User; +import com.chint.domain.aggregates.user.UserDepartmentInfo; import com.chint.domain.repository.JTCompanyRepository; import com.chint.domain.repository.StaffRankRepository; +import com.chint.domain.repository.UserRepository; import com.chint.domain.service.JTCompanyDomainService; import com.chint.domain.service.RankDomainService; import com.chint.infrastructure.constant.SFConstant; @@ -57,10 +59,12 @@ public class UserHttpRequestImpl implements UserHttpRequest { @Autowired private JTCompanyRepository jtCompanyRepository; - @Value("${sf.systemId}") private String systemId; + @Autowired + private UserRepository userRepository; + @Override public User loadUserInfo(User user) { loadSFInfo(user); @@ -115,20 +119,13 @@ public class UserHttpRequestImpl implements UserHttpRequest { } private User loadSingleSF(UserDataDTO userData, User user) { - getDataFromUserSFData(user, userData); - String sysCode = jtCompanyDomainService.findSystemCodeByCompanyCode(user.getCompanyCode()); - user.addFssc(userData.getCompany_cn(), sysCode); -// if (user.getCompanyCode().equals(XN_COMPANY_CODE)) { -// user.addXNFssc(FSSC_LOAD_URL, postRequest); -// } -// //如果用户的公司编码属于集团 ,那么加入集团财务共享跳转地址 -// if (jtCompanyDomainService.ifCompanyInJT(null, userData.getCompany())) { -// user.addJTFssc(userData.getCompany_cn(), FSSC_LOAD_URL, postRequest); -// } - + //根据同步时间来决定是否要同步部门信息 + if (user.checkSyncTime()) { + addDeptInfo(userData, user, true); + } return user; } @@ -153,6 +150,30 @@ public class UserHttpRequestImpl implements UserHttpRequest { // 检查并处理JT公司和XN公司的特殊情况 processSpecialCompanies(userDataDTOS, user); + for (UserDataDTO userDataDTO : userDataDTOS) { + if (userDataDTO.getPersonIdExternal().equals(userDataDTO.getLoginUsername())) { + addDeptInfo(userDataDTO, user, true); + } else { + addDeptInfo(userDataDTO, user, false); + } + } + return user; + } + + private User addDeptInfo(UserDataDTO userData, User user, Boolean ifPrimary) { + UserDepartmentInfo.Builder builder = user.addDeptInfo() + .companyInfo(userData.getCompany(), userData.getCompany_cn()) + .deptOne(userData.getUnit1(), userData.getUnit1_cn()) + .deptTwo(userData.getUnit2(), userData.getUnit2_cn()) + .deptThree(userData.getUnit3(), userData.getUnit3_cn()) + .deptFour(userData.getUnit4(), userData.getUnit4_cn()) + .deptFive(userData.getUnit5(), userData.getUnit5_cn()) + .deptSix(null, null) + .deptSeven(null, null); + if (ifPrimary) { + builder.primary(); + } + builder.addToUser(); return user; } @@ -172,24 +193,6 @@ public class UserHttpRequestImpl implements UserHttpRequest { list.forEach(it -> user.addFssc(it.getCompany_cn(), jtCompanyDomainService.findSystemCodeByCompanyCode(it.getCompany()))); -// Set companyCodes = userDataDTOS.stream() -// .map(UserDataDTO::getCompany) -// .collect(Collectors.toSet()); -// -// -// List inJtCompanyCodes = companyCodes -// .stream() -// .filter(code -> jtCompanyDomainService.ifCompanyInJT(null, code)) -// .toList(); -// -// for (String inJtCompanyCode : inJtCompanyCodes) { -// JTCompany byCompanyCode = jtCompanyRepository.findByCompanyCode(inJtCompanyCode); -// user.addJTFssc(byCompanyCode.getCompanyName(), FSSC_LOAD_URL, postRequest); -// } -// -// if (companyCodes.contains(XN_COMPANY_CODE)) { -// user.addXNFssc(FSSC_LOAD_URL, postRequest); -// } } private User getDataFromUserSFData(User user, UserDataDTO userData) { @@ -205,4 +208,21 @@ public class UserHttpRequestImpl implements UserHttpRequest { return user; } + public User loadUserDeptInfo(User user) { + List userDataDTOList = userSFRequest.getUserSFDataFromOpenApi(user); + if (userDataDTOList != null && userDataDTOList.size() == 1) { + addDeptInfo(userDataDTOList.get(0), user, true); + } + + if (userDataDTOList != null && userDataDTOList.size() > 1) { + for (UserDataDTO userDataDTO : userDataDTOList) { + if (userDataDTO.getPersonIdExternal().equals(userDataDTO.getLoginUsername())) { + addDeptInfo(userDataDTO, user, true); + } else { + addDeptInfo(userDataDTO, user, false); + } + } + } + return userRepository.save(user); + } } \ No newline at end of file