From 850e55ff5202328d82aa6c562a08b79bc7c95d04 Mon Sep 17 00:00:00 2001 From: lulz1 Date: Fri, 26 Apr 2024 16:04:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=AB=98=E5=BE=B7=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/commands/UserSFCommand.java | 15 +++ .../application/out/LoginController.java | 23 +--- .../CTripFlightTripInfo.java | 18 ++- .../chint/domain/aggregates/user/User.java | 126 +++++++++++++++++- .../aggregates/user/UserDepartmentInfo.java | 104 ++++++++++----- .../CTripOrderRecordExtensionFactory.java | 29 ++++ .../service/auth/AuthenticateServiceImpl.java | 4 - .../domain/value_object/UserLoginResult.java | 13 +- .../com/chint/domain/value_object/UserVO.java | 25 ++++ .../constant/AuthMessageConstant.java | 1 + .../constant/CommonMessageConstant.java | 1 + .../rest/amap/AmapLocationRequest.java | 2 +- .../rest/user/UserHttpRequestImpl.java | 83 +++++------- src/test/java/com/chint/LYTest.java | 2 +- 14 files changed, 316 insertions(+), 130 deletions(-) create mode 100644 src/main/java/com/chint/application/commands/UserSFCommand.java create mode 100644 src/main/java/com/chint/domain/value_object/UserVO.java diff --git a/src/main/java/com/chint/application/commands/UserSFCommand.java b/src/main/java/com/chint/application/commands/UserSFCommand.java new file mode 100644 index 00000000..c1463a89 --- /dev/null +++ b/src/main/java/com/chint/application/commands/UserSFCommand.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 UserSFCommand extends Command { + private User user; + + public UserSFCommand user(User user) { + this.user = user; + return this; + } +} diff --git a/src/main/java/com/chint/application/out/LoginController.java b/src/main/java/com/chint/application/out/LoginController.java index d02a5a39..26611a9e 100644 --- a/src/main/java/com/chint/application/out/LoginController.java +++ b/src/main/java/com/chint/application/out/LoginController.java @@ -95,7 +95,7 @@ public class LoginController { .authenticateEmployeeNo(userLoginParam); //异步执行更新用户信息到同程 - User currentUser = userLoginResult.getUser(); + User currentUser = BaseContext.getCurrentUser(); if (billcode != null) { if (companycode == null) { @@ -105,9 +105,6 @@ public class LoginController { Command.of(OrderCreateCommand.class).of(currentUser).sendToQueue(); } loginEventBoarder(currentUser); - //清除职级信息 - userLoginResult.getUser().setProfLevel(null); - userLoginResult.getUser().setManaLevel(null); return Result.Success(CommonMessageConstant.SUCCESS, userLoginResult); } else { return Result.error(AuthMessageConstant.SIGN_ERROR); @@ -125,11 +122,8 @@ public class LoginController { .authenticateEmployeeNo(userLoginParam); //异步执行更新用户信息到同程 - User currentUser = userLoginResult.getUser(); + User currentUser = BaseContext.getCurrentUser(); loginEventBoarder(currentUser); - //清除职级信息 - userLoginResult.getUser().setProfLevel(null); - userLoginResult.getUser().setManaLevel(null); return Result.Success(CommonMessageConstant.SUCCESS, userLoginResult); } @@ -145,13 +139,9 @@ public class LoginController { .authenticateEmployeeNo(userLoginParam); //异步执行更新用户信息到同程 - User currentUser = userLoginResult.getUser(); + User currentUser = BaseContext.getCurrentUser(); loginEventBoarder(currentUser); - //清除职级信息 - userLoginResult.getUser().setProfLevel(null); - userLoginResult.getUser().setManaLevel(null); - return Result.Success(CommonMessageConstant.SUCCESS, userLoginResult); } @@ -165,13 +155,8 @@ public class LoginController { .authenticateEmployeeNo(userLoginParam); //异步执行更新用户信息到同程 - User currentUser = userLoginResult.getUser(); + User currentUser = BaseContext.getCurrentUser(); loginEventBoarder(currentUser); - - //清除职级信息 - userLoginResult.getUser().setProfLevel(null); - userLoginResult.getUser().setManaLevel(null); - return Result.Success(CommonMessageConstant.SUCCESS, userLoginResult); } diff --git a/src/main/java/com/chint/domain/aggregates/order/order_record/ctrip_order_record/CTripFlightTripInfo.java b/src/main/java/com/chint/domain/aggregates/order/order_record/ctrip_order_record/CTripFlightTripInfo.java index 304f9744..b670657b 100644 --- a/src/main/java/com/chint/domain/aggregates/order/order_record/ctrip_order_record/CTripFlightTripInfo.java +++ b/src/main/java/com/chint/domain/aggregates/order/order_record/ctrip_order_record/CTripFlightTripInfo.java @@ -60,13 +60,17 @@ public class CTripFlightTripInfo implements Serializable { private String AirlineName; public static CTripFlightTripInfo of(OrderFlightResponse.FlightTripRecordInfo flightTripRecordInfo) { - CTripFlightTripInfo cTripFlightTripInfo = BeanUtil.copyProperties(flightTripRecordInfo, CTripFlightTripInfo.class); - cTripFlightTripInfo.setValidFlag(flightTripRecordInfo.isValidFlag() ? 1 : 0); - cTripFlightTripInfo.setOpenTranFlag(flightTripRecordInfo.isOpenTranFlag() ? 1 : 0); - cTripFlightTripInfo.setSharedFlag(flightTripRecordInfo.isSharedFlag() ? 1 : 0); - cTripFlightTripInfo.setSurfaceFlag(flightTripRecordInfo.isSurfaceFlag() ? 1 : 0); - cTripFlightTripInfo.setTicketNoStatusName(translateTicketStatus(flightTripRecordInfo.getTicketNoStatus())); - return cTripFlightTripInfo; + if(flightTripRecordInfo == null) { + return null; + } else { + CTripFlightTripInfo cTripFlightTripInfo = BeanUtil.copyProperties(flightTripRecordInfo, CTripFlightTripInfo.class); + cTripFlightTripInfo.setValidFlag(flightTripRecordInfo.isValidFlag() ? 1 : 0); + cTripFlightTripInfo.setOpenTranFlag(flightTripRecordInfo.isOpenTranFlag() ? 1 : 0); + cTripFlightTripInfo.setSharedFlag(flightTripRecordInfo.isSharedFlag() ? 1 : 0); + cTripFlightTripInfo.setSurfaceFlag(flightTripRecordInfo.isSurfaceFlag() ? 1 : 0); + cTripFlightTripInfo.setTicketNoStatusName(translateTicketStatus(flightTripRecordInfo.getTicketNoStatus())); + return cTripFlightTripInfo; + } } private static String translateTicketStatus(Integer ticketNoStatus) { 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 532ef9a1..7ac142f7 100644 --- a/src/main/java/com/chint/domain/aggregates/user/User.java +++ b/src/main/java/com/chint/domain/aggregates/user/User.java @@ -1,11 +1,19 @@ package com.chint.domain.aggregates.user; +import cn.hutool.core.bean.BeanUtil; import com.auth0.jwt.interfaces.Claim; import com.auth0.jwt.interfaces.DecodedJWT; +import com.chint.application.commands.UserSFCommand; import com.chint.domain.aggregates.system.FsscSystem; +import com.chint.domain.exceptions.NotFoundException; import com.chint.domain.value_object.UserLoginParam; +import com.chint.domain.value_object.UserVO; import com.chint.infrastructure.constant.AuthMessageConstant; +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; +import com.chint.interfaces.rest.user.dto.UserDataDTO; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import lombok.AllArgsConstructor; @@ -25,7 +33,9 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.function.Predicate; +import static com.chint.infrastructure.constant.AuthMessageConstant.SF_DATA_NOT_EXIST; import static com.chint.infrastructure.constant.AuthMessageConstant.USER_FSSC_SYSTEM_LIST; import static com.chint.infrastructure.constant.BPMConstant.*; import static com.chint.infrastructure.constant.FSSCConstant.*; @@ -68,13 +78,82 @@ public class User implements Serializable { @Transient private UserLoginParam userLoginParam; + public User loadInfoFromDept() { + if (this.userDepartmentInfoList == null || this.userDepartmentInfoList.isEmpty()) { + //如果发现 用户的 部门信息为空, 那么直接调用 sf查询 + Command.of(UserSFCommand.class).user(this).sendToQueue(); + } + if (userDepartmentInfoList == null) { + throw new NotFoundException(SF_DATA_NOT_EXIST); + } else if (userDepartmentInfoList.size() > 1) { + // 获取公司代码,优先从用户获取,若为空则从登录参数中获取 + String companyCode = Optional.ofNullable(this.getCompanyCode()) + .orElseGet(() -> { + User currentUser = BaseContext.getCurrentUser(); + if (currentUser != null && currentUser.getUserLoginParam() != null) { + return currentUser.getUserLoginParam().getCompanyCode(); + } + return null; + }); + + // 确保在没有有效的公司代码时使用安全默认值 + if (companyCode == null) { + companyCode = ""; // 使用空字符串或其他逻辑确定的默认值 + } + + // 根据公司代码获取对应的UserDataDTO + String finalCompanyCode = companyCode; + Predicate matchCompanyCode = StringCheck.isFirstCharacterChinese(companyCode) ? + departmentInfo -> departmentInfo.getCompanyName().equals(finalCompanyCode) : + departmentInfo -> departmentInfo.getCompanyCode().equals(finalCompanyCode); + + UserDepartmentInfo userDepartmentInfo = userDepartmentInfoList.stream() + .filter(matchCompanyCode) + .findFirst() + .orElseGet(this::getFallbackDeptInfo); + loadInfoFromDeptInfo(userDepartmentInfo); + } else { + UserDepartmentInfo fallbackDeptInfo = getFallbackDeptInfo(); + loadInfoFromDeptInfo(fallbackDeptInfo); + } + + return this; + } + + public UserVO mapToVO() { + return BeanUtil.copyProperties(this, UserVO.class); + } + + private UserDepartmentInfo getFallbackDeptInfo() { + return userDepartmentInfoList.stream() + .filter(UserDepartmentInfo::ifPrimary) + .findFirst() + .orElseGet(() -> userDepartmentInfoList.get(0)); + } + + private User loadInfoFromDeptInfo(UserDepartmentInfo userDepartmentInfo) { + this.setCompanyCode(userDepartmentInfo.getCompanyCode()); + this.setWorkStatus(userDepartmentInfo.getStatus()); + this.setGender(userDepartmentInfo.getGender()); + this.setName(userDepartmentInfo.getUname()); + this.setPhoneNumber(userDepartmentInfo.getMobilePhone()); + this.setCompanyName(userDepartmentInfo.getCompanyName()); + if (userDepartmentInfo.getCustManaLevel() != null) { + this.setManaLevel(userDepartmentInfo.getCustManaLevel()); + } else { + this.setManaLevel(userDepartmentInfo.getCustManaLevelF()); + } + this.setProfLevel(userDepartmentInfo.getCustProfLevel()); + this.setQualityLevel(userDepartmentInfo.getCustQualityLevel()); + return this; + } public User(String employeeNo) { this.employeeNo = employeeNo; } public UserDepartmentInfo.Builder addDeptInfo() { - return new UserDepartmentInfo.Builder(this); + return new UserDepartmentInfo.Builder(); } public UserDepartmentInfo getDepartmentInfo() { @@ -273,8 +352,45 @@ public class User implements Serializable { return XN_FSSC_REDIRECT_PATH_APPROVAL_ONE + employeeNo + FSSC_REDIRECT_PATH_APPROVAL_TWO; } -// public User startAddDept(){ -// -// -// } + public User addDeptInfo(UserDataDTO userData) { + UserDepartmentInfo.Builder builder = this.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) + .loadWorkInfo(userData.getCust_manaLevel(), + userData.getCust_manaLevelF(), + userData.getCust_profLevel(), + userData.getCust_techLevel(), + userData.getCust_qualityLevel()) + .userInfo(userData.getMobilePhone(), + userData.getUname(), + userData.getGender(), + userData.getStatus()); + UserDepartmentInfo userDepartmentInfo = builder.finish(); + if (userData.getPersonIdExternal().equals(userData.getLoginUsername())) { + userDepartmentInfo.setIfPrimary(1); + } else { + userDepartmentInfo.setIfPrimary(0); + } + List userDepartmentInfoList = this.getUserDepartmentInfoList(); + List result = new ArrayList<>(); + if (userDepartmentInfoList != null && !userDepartmentInfoList.isEmpty()) { + if (userDepartmentInfoList.contains(userDepartmentInfo)) { + return this; + } + List list = userDepartmentInfoList.stream().distinct().toList(); + if (userDepartmentInfo.ifPrimary()) { + list.forEach(it -> it.setIfPrimary(0)); + } + result.addAll(list); + } + result.add(userDepartmentInfo); + this.setUserDepartmentInfoList(result); + return this; + } } \ No newline at end of file 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 9777b071..37719f70 100644 --- a/src/main/java/com/chint/domain/aggregates/user/UserDepartmentInfo.java +++ b/src/main/java/com/chint/domain/aggregates/user/UserDepartmentInfo.java @@ -41,8 +41,22 @@ public class UserDepartmentInfo implements Serializable { private String departmentNameSeven; private Integer ifPrimary; - public String getDeptInfo(){ - return departmentNameOne + "-" + departmentNameTwo + + private String mobilePhone; + private String uname; + private String gender; + private String custManaLevel; + private String custManaLevelF; + private String custProfLevel; + private String custTechLevel; + private String custQualityLevel; + private String status; + + public boolean ifPrimary(){ + return ifPrimary == 1; + } + + public String getDeptInfo() { + return departmentNameOne + "-" + departmentNameTwo + "-" + departmentNameThree + "-" + departmentNameFour + "-" + departmentNameFive + "-" + departmentNameSix + "-" + departmentNameSeven; } @@ -74,19 +88,14 @@ public class UserDepartmentInfo implements Serializable { @Override public int hashCode() { - return Objects.hash(companyCode, companyName, departmentCodeOne, departmentNameOne, departmentCodeTwo, departmentNameTwo, departmentCodeThree, departmentNameThree, departmentCodeFour, departmentNameFour, departmentCodeFive, departmentNameFive, departmentCodeSix, departmentNameSix, departmentCodeSeven, departmentNameSeven,ifPrimary); + return Objects.hash(companyCode, companyName, departmentCodeOne, departmentNameOne, departmentCodeTwo, departmentNameTwo, departmentCodeThree, departmentNameThree, departmentCodeFour, departmentNameFour, departmentCodeFive, departmentNameFive, departmentCodeSix, departmentNameSix, departmentCodeSeven, departmentNameSeven, ifPrimary); } - public Builder start(User user) { - return new Builder(user); + public Builder start() { + return new Builder(); } - public UserDepartmentInfo(String companyCode, String companyName, String departmentCodeOne, - String departmentNameOne, String departmentCodeTwo, String departmentNameTwo, - String departmentCodeThree, String departmentNameThree, String departmentCodeFour, - String departmentNameFour, String departmentCodeFive, String departmentNameFive, - String departmentCodeSix, String departmentNameSix, String departmentCodeSeven, - String departmentNameSeven, Integer ifPrimary) { + public UserDepartmentInfo(String companyCode, String companyName, String departmentCodeOne, String departmentNameOne, String departmentCodeTwo, String departmentNameTwo, String departmentCodeThree, String departmentNameThree, String departmentCodeFour, String departmentNameFour, String departmentCodeFive, String departmentNameFive, String departmentCodeSix, String departmentNameSix, String departmentCodeSeven, String departmentNameSeven, Integer ifPrimary, String mobilePhone, String uname, String gender, String custManaLevel, String custManaLevelF, String custProfLevel, String custTechLevel, String custQualityLevel, String status) { this.companyCode = companyCode; this.companyName = companyName; this.departmentCodeOne = departmentCodeOne; @@ -104,11 +113,18 @@ public class UserDepartmentInfo implements Serializable { this.departmentCodeSeven = departmentCodeSeven; this.departmentNameSeven = departmentNameSeven; this.ifPrimary = ifPrimary; + this.mobilePhone = mobilePhone; + this.uname = uname; + this.gender = gender; + this.custManaLevel = custManaLevel; + this.custManaLevelF = custManaLevelF; + this.custProfLevel = custProfLevel; + this.custTechLevel = custTechLevel; + this.custQualityLevel = custQualityLevel; + this.status = status; } - public static class Builder { - private User user; private String companyCode; private String companyName; private String departmentCodeOne; @@ -126,10 +142,15 @@ public class UserDepartmentInfo implements Serializable { private String departmentCodeSeven; private String departmentNameSeven; private Integer ifPrimary; - - public Builder(User user) { - this.user = user; - } + private String mobilePhone; + private String uname; + private String gender; + private String custManaLevel; + private String custManaLevelF; + private String custProfLevel; + private String custTechLevel; + private String custQualityLevel; + private String status; public Builder companyInfo(String companyCode, String companyName) { this.companyCode = companyCode; @@ -184,7 +205,28 @@ public class UserDepartmentInfo implements Serializable { return this; } - public UserDepartmentInfo addToUser() { + public Builder loadWorkInfo(String custManaLevel, + String custManaLevelF, + String custProfLevel, + String custTechLevel, + String custQualityLevel) { + this.custManaLevel = custManaLevel; + this.custManaLevelF = custManaLevelF; + this.custProfLevel = custProfLevel; + this.custTechLevel = custTechLevel; + this.custQualityLevel = custQualityLevel; + return this; + } + + public Builder userInfo(String mobilePhone, String uname, String gender, String status) { + this.mobilePhone = mobilePhone; + this.uname = uname; + this.gender = gender; + this.status = status; + return this; + } + + public UserDepartmentInfo finish() { UserDepartmentInfo userDepartmentInfo = new UserDepartmentInfo(companyCode, companyName, departmentCodeOne, @@ -201,22 +243,16 @@ public class UserDepartmentInfo implements Serializable { departmentNameSix, departmentCodeSeven, departmentNameSeven, - ifPrimary); - if (userDepartmentInfo.getIfPrimary() == null || userDepartmentInfo.getIfPrimary() != 1) { - userDepartmentInfo.setIfPrimary(0); - } - List userDepartmentInfoList = user.getUserDepartmentInfoList(); - List result = new ArrayList<>(); - if(userDepartmentInfoList != null && !userDepartmentInfoList.isEmpty()) { - List list = userDepartmentInfoList.stream().distinct().toList(); - user.setUserDepartmentInfoList(list); - if(userDepartmentInfoList.contains(userDepartmentInfo)){ - return userDepartmentInfo; - } - result.addAll(userDepartmentInfoList); - } - result.add(userDepartmentInfo); - user.setUserDepartmentInfoList(result); + ifPrimary, + mobilePhone, + uname, + gender, + custManaLevel, + custManaLevelF, + custProfLevel, + custTechLevel, + custQualityLevel, + status); return userDepartmentInfo; } } 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 bdfe432e..5dacbe32 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 @@ -240,6 +240,15 @@ public class CTripOrderRecordExtensionFactory implements OrderRecordExtensionFac } }, () -> orderCarRecord.setOrderStatus("0")); + //修正携程成中心错误的问题 + if (byOrderNo.isPresent()) { + RouteOrder routeOrder = byOrderNo.get(); + ApproveOrderNo approveOrderNo = routeOrder.getApproveOrderNo(); + if (approveOrderNo != null) { + orderCarRecord.setOfflineCcomyCode(approveOrderNo.getCostCenter()); + } + } + return orderCarRecord; } @@ -476,6 +485,14 @@ public class CTripOrderRecordExtensionFactory implements OrderRecordExtensionFac } }, () -> orderFlightRecord.setOrderStatus("0")); + //修正携程成中心错误的问题 + if (byOrderNo.isPresent()) { + RouteOrder routeOrder = byOrderNo.get(); + ApproveOrderNo approveOrderNo = routeOrder.getApproveOrderNo(); + if (approveOrderNo != null) { + orderFlightRecord.setOfflineCcomyCode(approveOrderNo.getCostCenter()); + } + } return orderFlightRecord; } @@ -701,6 +718,18 @@ public class CTripOrderRecordExtensionFactory implements OrderRecordExtensionFac orderHotelRecord.setOrderStatus("0"); } }, () -> orderHotelRecord.setOrderStatus("0")); + + + //修正携程成中心错误的问题 + if (byOrderNo.isPresent()) { + RouteOrder routeOrder = byOrderNo.get(); + ApproveOrderNo approveOrderNo = routeOrder.getApproveOrderNo(); + if (approveOrderNo != null) { + orderHotelRecord.setOfflineCcomyCode(approveOrderNo.getCostCenter()); + } + } + + return orderHotelRecord; } 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 10990efd..2c8973cd 100644 --- a/src/main/java/com/chint/domain/service/auth/AuthenticateServiceImpl.java +++ b/src/main/java/com/chint/domain/service/auth/AuthenticateServiceImpl.java @@ -59,7 +59,6 @@ public class AuthenticateServiceImpl implements AuthenticateService { if (user != null) { // 部分数据需要通过查询外部的http来获取 user.setUserLoginParam(userLoginParam); - BaseContext.setCurrentUser(user); return getUserLoginResult(user); } else { User newUser = userFactory.create(userLoginParam.getSfno()); @@ -68,14 +67,12 @@ public class AuthenticateServiceImpl implements AuthenticateService { httpRequest.loadUserInfo(newUser); userRepository.save(newUser); newUser.setUserLoginParam(userLoginParam); - BaseContext.setCurrentUser(newUser); return getUserLoginResult(newUser); } } private UserLoginResult getUserLoginResult(User user) { UserLoginParam userLoginParam = user.getUserLoginParam(); - BaseContext.setCurrentUser(user); user.setCompanyCode(userLoginParam.getCompanyCode()); user.setUserLoginParam(userLoginParam); httpRequest.loadUserInfo(user); @@ -93,7 +90,6 @@ public class AuthenticateServiceImpl implements AuthenticateService { claims.put(USER_FSSC_SYSTEM_LIST, json.gson().toJson(fsscSystemList)); claims.put(USER_STANDARD_LEVEL, user.getStandardLevel()); String jwt = JWTUtil.createJWT(claims); - //这里已经是完成的用户信息里, 因此将用户信息保存到threadLocal当中 BaseContext.setCurrentUser(user); return UserLoginResult.buildWithUser(user).loadToken(Token.of(jwt)); diff --git a/src/main/java/com/chint/domain/value_object/UserLoginResult.java b/src/main/java/com/chint/domain/value_object/UserLoginResult.java index 325c4aa0..414cf072 100644 --- a/src/main/java/com/chint/domain/value_object/UserLoginResult.java +++ b/src/main/java/com/chint/domain/value_object/UserLoginResult.java @@ -6,31 +6,24 @@ import lombok.Data; @Data public class UserLoginResult { - private User user; + private UserVO user; private Token token; // private String redirectUrl; public UserLoginResult(User user) { - this.user = user; + this.user = user.mapToVO(); this.token = null; } - public User getUser() { + public UserVO getUser() { return user; } - public void setUser(User user) { - this.user = user; - } public Token getToken() { return token; } - public void setToken(Token token) { - this.token = token; - } - public static UserLoginResult buildWithUser(User user) { return new UserLoginResult(user); } diff --git a/src/main/java/com/chint/domain/value_object/UserVO.java b/src/main/java/com/chint/domain/value_object/UserVO.java new file mode 100644 index 00000000..0e34d2ab --- /dev/null +++ b/src/main/java/com/chint/domain/value_object/UserVO.java @@ -0,0 +1,25 @@ +package com.chint.domain.value_object; + +import com.chint.domain.aggregates.system.FsscSystem; +import lombok.Data; +import org.springframework.data.annotation.Transient; + +import java.time.LocalDateTime; +import java.util.List; + +@Data +public class UserVO { + private Long userId; + private String employeeNo; + private Integer employeeLevel; + private String name; + private String email; + private String gender; + private String phoneNumber; + private String password; + private LocalDateTime syncTime; + private List fsscSystemList; + private String standardLevel; + private String companyCode; + private String companyName; +} diff --git a/src/main/java/com/chint/infrastructure/constant/AuthMessageConstant.java b/src/main/java/com/chint/infrastructure/constant/AuthMessageConstant.java index b4ba648c..cae331fd 100644 --- a/src/main/java/com/chint/infrastructure/constant/AuthMessageConstant.java +++ b/src/main/java/com/chint/infrastructure/constant/AuthMessageConstant.java @@ -8,6 +8,7 @@ public class AuthMessageConstant { public static final String JWT_EXPIRED = "登录信息已过期"; public static final String JWT_REQUIRED = "需要 JWT 令牌"; public static final String JWT_ACCESS_DENIED = "JWT 令牌不足以访问此资源"; + public static final String SF_DATA_NOT_EXIST = "sf信息不存在,请联系管理员"; // 用户认证消息 public static final String AUTHENTICATION_FAILED = "认证失败"; public static final String LOGIN_SUCCESS = "登录成功"; diff --git a/src/main/java/com/chint/infrastructure/constant/CommonMessageConstant.java b/src/main/java/com/chint/infrastructure/constant/CommonMessageConstant.java index e2875cba..68b9927b 100644 --- a/src/main/java/com/chint/infrastructure/constant/CommonMessageConstant.java +++ b/src/main/java/com/chint/infrastructure/constant/CommonMessageConstant.java @@ -7,6 +7,7 @@ public class CommonMessageConstant { public static final String SYNC_FAILURE_TRAIN = "携程暂不支持火车票预订"; public static final String DUPLICATE_ERROR = "数据重复"; public static final String NOT_FOUND = "未找到相关数据"; + public static final String EMPLOYEE_NO_NOT_EXIST = "未找到相关数据"; public static final String INVALID_REQUEST = "无效的请求"; public static final String ACCESS_DENIED = "访问被拒绝"; public static final String SERVER_ERROR = "服务器错误"; diff --git a/src/main/java/com/chint/interfaces/rest/amap/AmapLocationRequest.java b/src/main/java/com/chint/interfaces/rest/amap/AmapLocationRequest.java index 83bb4ccb..c5d24dad 100644 --- a/src/main/java/com/chint/interfaces/rest/amap/AmapLocationRequest.java +++ b/src/main/java/com/chint/interfaces/rest/amap/AmapLocationRequest.java @@ -27,7 +27,7 @@ public class AmapLocationRequest { return amapRequest.post(BaseUrl + AMAP_LOCATION_PATH, param, LocationResponse.class); } - + @Cacheable(value = "AmapLocationACode" , key = "#locationName") public String getACodeByLocationName(String locationName) { LocationResponse locationQuery = locationQuery(locationName); Optional amapCityInfo = Optional.ofNullable(locationQuery.getData()) 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 0c4ea60e..92896d84 100644 --- a/src/main/java/com/chint/interfaces/rest/user/UserHttpRequestImpl.java +++ b/src/main/java/com/chint/interfaces/rest/user/UserHttpRequestImpl.java @@ -1,16 +1,20 @@ package com.chint.interfaces.rest.user; +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; 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; +import com.chint.infrastructure.echo_framework.annotation.ListenTo; import com.chint.infrastructure.util.BaseContext; import com.chint.infrastructure.util.StringCheck; import com.chint.interfaces.rest.base.PostRequest; @@ -24,6 +28,7 @@ import java.util.List; import java.util.Optional; import java.util.function.Predicate; +import static com.chint.infrastructure.constant.CommonMessageConstant.EMPLOYEE_NO_NOT_EXIST; import static com.chint.infrastructure.constant.RankConstant.DEFAULT_RANK_NAME; import static com.chint.infrastructure.constant.RankConstant.JT_COMPANY_CODE; @@ -65,12 +70,19 @@ public class UserHttpRequestImpl implements UserHttpRequest { @Autowired private UserRepository userRepository; + @Override public User loadUserInfo(User user) { //这个方法 逻辑进行修改 , 首先通过查询 表的方式 , 如果部分数据为空 , 那么就要查询 sf信息获取 - user = loadSFInfo(user); - if (user == null) { - return null; + user.loadInfoFromDept(); + //根据员工的登录信息,来创建fssc基础跳转信息 + List userDepartmentInfoList = user.getUserDepartmentInfoList() + .stream() + .filter(it -> jtCompanyDomainService.ifCompanyInJT(null, it.getCompanyCode())) + .toList(); + for (UserDepartmentInfo userDepartmentInfo : userDepartmentInfoList) { + String sysCode = jtCompanyDomainService.findSystemCodeByCompanyCode(userDepartmentInfo.getCompanyCode()); + user.addFssc(userDepartmentInfo.getCompanyName(), sysCode); } return loadRankCode(user); } @@ -107,7 +119,13 @@ public class UserHttpRequestImpl implements UserHttpRequest { return user; } - private User loadSFInfo(User user) { + + @ListenTo(command = "UserSFCommand", order = 0) + public User loadSFInfo(UserSFCommand command) { + User user = command.getUser(); + if (user == null || user.getEmployeeNo() == null) { + throw new NotFoundException(EMPLOYEE_NO_NOT_EXIST); + } List userSFDataFromOpenApi = userSFRequest .getUserSFDataFromOpenApi(user); if (userSFDataFromOpenApi == null) { @@ -117,11 +135,9 @@ public class UserHttpRequestImpl implements UserHttpRequest { .stream() .filter(userDataDTO -> userDataDTO.getStatus().equals("A")) .toList(); - if (fromJson.size() == 1) { - UserDataDTO userData = fromJson.get(0); - loadSingleSF(userData, user); - } else { - loadBatchSF(fromJson, user); + + for (UserDataDTO userDataDTO : fromJson) { + user.addDeptInfo(userDataDTO); } return user; } @@ -132,7 +148,7 @@ public class UserHttpRequestImpl implements UserHttpRequest { user.addFssc(userData.getCompany_cn(), sysCode); //根据同步时间来决定是否要同步部门信息 if (user.checkSyncTime()) { - addDeptInfo(userData, user, true); + user.addDeptInfo(userData); } return user; } @@ -174,11 +190,7 @@ public class UserHttpRequestImpl implements UserHttpRequest { processSpecialCompanies(userDataDTOS, user); for (UserDataDTO userDataDTO : userDataDTOS) { - if (userDataDTO.getPersonIdExternal().equals(userDataDTO.getLoginUsername())) { - addDeptInfo(userDataDTO, user, true); - } else { - addDeptInfo(userDataDTO, user, false); - } + user.addDeptInfo(userDataDTO); } return user; } @@ -206,24 +218,6 @@ public class UserHttpRequestImpl implements UserHttpRequest { 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; - } - private UserDataDTO getFallbackUserData(List userDataDTOS) { // 若无匹配,则优先使用主岗数据,否则使用列表中的第一个 return userDataDTOS.stream() @@ -263,20 +257,11 @@ public class UserHttpRequestImpl implements UserHttpRequest { if (userDataDTOList == null) { return null; } - if (userDataDTOList.size() == 1) { - addDeptInfo(userDataDTOList.get(0), user, true); - } - if (userDataDTOList.size() > 1) { - for (UserDataDTO userDataDTO : userDataDTOList) { - if (userDataDTO.getPersonIdExternal().equals(userDataDTO.getLoginUsername())) { - addDeptInfo(userDataDTO, user, true); - } else { - addDeptInfo(userDataDTO, user, false); - } - } - } - if(user.getName() == null || user.getName().isEmpty() || user.getName().isBlank()){ - getDataFromUserSFData(user,userDataDTOList.get(0)); + + userDataDTOList.forEach(user::addDeptInfo); + + if (user.getName() == null || user.getName().isEmpty() || user.getName().isBlank()) { + getDataFromUserSFData(user, userDataDTOList.get(0)); } return userRepository.save(user); @@ -299,9 +284,9 @@ public class UserHttpRequestImpl implements UserHttpRequest { } //这里执行去重逻辑 , 因出现部分员工的部分信息重复的问题 - if(userDepartmentInfoList != null && userDepartmentInfoList.size() > 1){ + if (userDepartmentInfoList != null && userDepartmentInfoList.size() > 1) { List userDepartmentInfos = userDepartmentInfoList.stream().distinct().toList(); - if(userDepartmentInfos.size() < userDepartmentInfoList.size()){ + if (userDepartmentInfos.size() < userDepartmentInfoList.size()) { user.setUserDepartmentInfoList(userDepartmentInfos); userRepository.save(user); } diff --git a/src/test/java/com/chint/LYTest.java b/src/test/java/com/chint/LYTest.java index 3acabdc0..17a9646a 100644 --- a/src/test/java/com/chint/LYTest.java +++ b/src/test/java/com/chint/LYTest.java @@ -832,7 +832,7 @@ public class LYTest { @Test void searchHotel() { - HotelDetailResponse hotelOrderDetail = lySearchRequest.getHotelOrderDetail("HO20240401145300516689"); + HotelDetailResponse hotelOrderDetail = lySearchRequest.getHotelOrderDetail("HO20240410160000601814"); Gson gson = new Gson(); String json = gson.toJson(hotelOrderDetail); System.out.println(json);