完成用户载入部门信息

This commit is contained in:
Superdandan 2024-04-04 16:20:51 +08:00
parent 41e0ee3906
commit d500c7e701
12 changed files with 223 additions and 50 deletions

View File

@ -30,13 +30,9 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.time.Duration;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import static com.chint.infrastructure.constant.BPMConstant.AN_FSSC;
import static com.chint.infrastructure.constant.BPMConstant.FSSC;
@Slf4j @Slf4j
@RestController @RestController
@RequestMapping("/public") @RequestMapping("/public")
@ -200,20 +196,7 @@ public class LoginController {
private void syncUserInfoToSupplier(User user) { private void syncUserInfoToSupplier(User user) {
// 给定的 LocalDateTime 实例示例中为2024年3月1日15:00 // 给定的 LocalDateTime 实例示例中为2024年3月1日15:00
LocalDateTime lastSyncTime = user.getSyncTime(); if (user.checkSyncTime()) {
if (lastSyncTime == null) {
asyncUser(user);
return;
}
// 获取当前时间
LocalDateTime now = LocalDateTime.now();
// 计算当前时间与给定时间之间的持续时间
Duration duration = Duration.between(lastSyncTime, now);
// 判断是否超过一天
if (duration.toDays() >= 1) {
asyncUser(user); asyncUser(user);
} else { } else {
log.info("未超过一天,不执行同步。"); log.info("未超过一天,不执行同步。");

View File

@ -78,6 +78,8 @@ public class RouteOrder implements Serializable {
@Transient @Transient
private String supplierCNName; private String supplierCNName;
@MappedCollection(idColumn = "route_id")
private RouterOrderExtensionField routerOrderExtensionField;
@MappedCollection(idColumn = "route_id", keyColumn = "route_order_key") @MappedCollection(idColumn = "route_id", keyColumn = "route_order_key")
private List<Leg> legItems; private List<Leg> legItems;

View File

@ -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;
}

View File

@ -71,8 +71,16 @@ public class OrderCarRecord extends OrderBaseRecord {
private String orderSource; // 预订来源线上/线下 private String orderSource; // 预订来源线上/线下
private String payAmount;//支付总金额 private String payAmount;//支付总金额
private String receiptsNumOrigin;//支付总金额 private String receiptsNumOrigin;//支付总金额
private String belongDeport; //归属部门
public OrderCarRecord loadBelongDeport(String belongDeport
) {
// 行程信息
this.setBelongDeport(belongDeport);
return this;
}
//添加行程信息 //添加行程信息
public OrderCarRecord loadTravelInfo(String startTime, public OrderCarRecord loadTravelInfo(String startTime,
String arriveTime, String arriveTime,

View File

@ -80,6 +80,14 @@ public class OrderFlightRecord extends OrderBaseRecord {
private String createTime; private String createTime;
private String receiptsNumOrigin;//原差旅申请单单号 private String receiptsNumOrigin;//原差旅申请单单号
private String payAmount; private String payAmount;
private String belongDeport; //归属部门
public OrderFlightRecord loadBelongDeport(String belongDeport
) {
// 行程信息
this.setBelongDeport(belongDeport);
return this;
}
// 加载基础订单信息 // 加载基础订单信息
public OrderFlightRecord loadBasicOrderInfo(String orderNo, public OrderFlightRecord loadBasicOrderInfo(String orderNo,

View File

@ -79,6 +79,14 @@ public class OrderHotelRecord extends OrderBaseRecord {
private String orderStatus; private String orderStatus;
private String createTime; private String createTime;
private String receiptsNumOrigin;//支付总金额 private String receiptsNumOrigin;//支付总金额
private String belongDeport; //归属部门
public OrderHotelRecord loadBelongDeport(String belongDeport
) {
// 行程信息
this.setBelongDeport(belongDeport);
return this;
}
// 加载基础订单信息 // 加载基础订单信息
public OrderHotelRecord loadBasicOrderInfo(String orderNo, public OrderHotelRecord loadBasicOrderInfo(String orderNo,

View File

@ -73,6 +73,14 @@ public class OrderTrainRecord extends OrderBaseRecord{
private String trainTime; // 发车时间 yyyy-MM-dd HH:mm:ss private String trainTime; // 发车时间 yyyy-MM-dd HH:mm:ss
private String yxId; // 影像比对ID private String yxId; // 影像比对ID
private String receiptsNumOrigin;//原差旅申请单单号 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) { public OrderTrainRecord loadBasicOrderInfo(Long id, String orderNo, String orderStatus, String createTime) {
this.setId(id); this.setId(id);

View File

@ -19,10 +19,12 @@ import org.springframework.data.relational.core.mapping.Table;
import java.io.Serial; import java.io.Serial;
import java.io.Serializable; import java.io.Serializable;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.time.Duration;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; 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.AuthMessageConstant.USER_FSSC_SYSTEM_LIST;
import static com.chint.infrastructure.constant.BPMConstant.*; 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<UserDepartmentInfo> first = this.userDepartmentInfoList
.stream()
.filter(it -> it.getIfPrimary() == 1)
.findFirst();
return first.map(this::lowestDept).orElse(null);
}
public String lowestDeptCode(String companyName) {
Optional<UserDepartmentInfo> 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) { public User addDeptInfo(UserDepartmentInfo userDepartmentInfo) {
if (this.userDepartmentInfoList == null) { if (this.userDepartmentInfoList == null) {
this.userDepartmentInfoList = new ArrayList<>(); this.userDepartmentInfoList = new ArrayList<>();

View File

@ -63,7 +63,7 @@ public class UserDepartmentInfo implements Serializable {
this.ifPrimary = ifPrimary; this.ifPrimary = ifPrimary;
} }
@Data
public static class Builder { public static class Builder {
private User user; private User user;
private String companyCode; private String companyCode;

View File

@ -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.OrderHotelRecord;
import com.chint.domain.aggregates.order.order_record.OrderTrainRecord; 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.order.order_record.ctrip_order_record.*;
import com.chint.domain.aggregates.user.User;
import com.chint.domain.repository.LocationRepository; import com.chint.domain.repository.LocationRepository;
import com.chint.domain.repository.RouteRepository; import com.chint.domain.repository.RouteRepository;
import com.chint.domain.repository.UserRepository;
import com.chint.domain.service.OrderDetailDomainService; import com.chint.domain.service.OrderDetailDomainService;
import com.chint.infrastructure.repository.jdbc.JdbcCtripHotelOrderDetailRepository; import com.chint.infrastructure.repository.jdbc.JdbcCtripHotelOrderDetailRepository;
import com.chint.infrastructure.util.DateTimeUtil; import com.chint.infrastructure.util.DateTimeUtil;
import com.chint.interfaces.rest.user.UserHttpRequest;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -35,6 +38,11 @@ public class CTripOrderRecordExtensionFactory implements OrderRecordExtensionFac
@Autowired @Autowired
private LocationRepository locationRepository; private LocationRepository locationRepository;
@Autowired
private UserRepository userRepository;
@Autowired
private UserHttpRequest userHttpRequest;
private OrderRecordBasic buildWithRecord(CTripCarRecord cTripCarRecord) { private OrderRecordBasic buildWithRecord(CTripCarRecord cTripCarRecord) {
OrderRecordBasic orderRecordBasic = new OrderRecordBasic(); OrderRecordBasic orderRecordBasic = new OrderRecordBasic();
CTripCarPassengerInfo cTripCarPassengerInfo = cTripCarRecord.getCTripCarPassengerInfo(); CTripCarPassengerInfo cTripCarPassengerInfo = cTripCarRecord.getCTripCarPassengerInfo();
@ -66,7 +74,6 @@ public class CTripOrderRecordExtensionFactory implements OrderRecordExtensionFac
} else { } else {
orderRecordBasic.setBelongSysType(BELONG_SYS_TYPE_NOT); orderRecordBasic.setBelongSysType(BELONG_SYS_TYPE_NOT);
} }
return orderRecordBasic; return orderRecordBasic;
} }
@ -173,6 +180,14 @@ public class CTripOrderRecordExtensionFactory implements OrderRecordExtensionFac
"", "",
cTripCarRecordBase.getCreateTime())); cTripCarRecordBase.getCreateTime()));
//这里添加归属部门编号 , 这里兼容测试环境 如果行程规划单已经有这个值 那么直接取 没有的话查找用户的部门获取
Optional<RouterOrderExtensionField> routerOrderExtensionField = byOrderNo
.flatMap(it -> Optional.ofNullable(it.getRouterOrderExtensionField()));
routerOrderExtensionField.ifPresentOrElse(it -> orderCarRecord.loadBelongDeport(it.getBelongDeptCode()),
() -> orderCarRecord.loadBelongDeport(
belongDeport(orderCarRecord.getBookingUserCode(), orderCarRecord.getAccountCompanyName())
));
return orderCarRecord; return orderCarRecord;
} }
@ -367,6 +382,15 @@ public class CTripOrderRecordExtensionFactory implements OrderRecordExtensionFac
.loadBasicOrderInfo(String.valueOf(cTripFlightRecordBase.getOrderId()), .loadBasicOrderInfo(String.valueOf(cTripFlightRecordBase.getOrderId()),
"", "",
cTripFlightRecordBase.getCreateTime())); cTripFlightRecordBase.getCreateTime()));
//这里添加归属部门编号 , 这里兼容测试环境 如果行程规划单已经有这个值 那么直接取 没有的话查找用户的部门获取
Optional<RouterOrderExtensionField> routerOrderExtensionField = byOrderNo
.flatMap(it -> Optional.ofNullable(it.getRouterOrderExtensionField()));
routerOrderExtensionField.ifPresentOrElse(it -> orderFlightRecord.loadBelongDeport(it.getBelongDeptCode()),
() -> orderFlightRecord.loadBelongDeport(
belongDeport(orderFlightRecord.getBookingUserCode(), orderFlightRecord.getAccountCompanyName())
));
return orderFlightRecord; return orderFlightRecord;
} }
@ -553,6 +577,28 @@ public class CTripOrderRecordExtensionFactory implements OrderRecordExtensionFac
cTripHotelOrderDetail.getDept2(), cTripHotelOrderDetail.getDept2(),
cTripHotelOrderDetail.getDept3()); cTripHotelOrderDetail.getDept3());
//这里添加归属部门编号 , 这里兼容测试环境 如果行程规划单已经有这个值 那么直接取 没有的话查找用户的部门获取
Optional<RouterOrderExtensionField> routerOrderExtensionField = byOrderNo
.flatMap(it -> Optional.ofNullable(it.getRouterOrderExtensionField()));
routerOrderExtensionField.ifPresentOrElse(it -> orderHotelRecord.loadBelongDeport(it.getBelongDeptCode()),
() -> orderHotelRecord.loadBelongDeport(
belongDeport(orderHotelRecord.getBookingUserCode(), orderHotelRecord.getAccountCompanyName())
));
return orderHotelRecord; 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", "");
}
} }

View File

@ -4,4 +4,6 @@ import com.chint.domain.aggregates.user.User;
public interface UserHttpRequest { public interface UserHttpRequest {
User loadUserInfo(User user); User loadUserInfo(User user);
User loadUserDeptInfo(User user);
} }

View File

@ -4,8 +4,10 @@ package com.chint.interfaces.rest.user;
import com.chint.domain.aggregates.standards.Ranks; import com.chint.domain.aggregates.standards.Ranks;
import com.chint.domain.aggregates.standards.StaffRank; import com.chint.domain.aggregates.standards.StaffRank;
import com.chint.domain.aggregates.user.User; 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.JTCompanyRepository;
import com.chint.domain.repository.StaffRankRepository; import com.chint.domain.repository.StaffRankRepository;
import com.chint.domain.repository.UserRepository;
import com.chint.domain.service.JTCompanyDomainService; import com.chint.domain.service.JTCompanyDomainService;
import com.chint.domain.service.RankDomainService; import com.chint.domain.service.RankDomainService;
import com.chint.infrastructure.constant.SFConstant; import com.chint.infrastructure.constant.SFConstant;
@ -57,10 +59,12 @@ public class UserHttpRequestImpl implements UserHttpRequest {
@Autowired @Autowired
private JTCompanyRepository jtCompanyRepository; private JTCompanyRepository jtCompanyRepository;
@Value("${sf.systemId}") @Value("${sf.systemId}")
private String systemId; private String systemId;
@Autowired
private UserRepository userRepository;
@Override @Override
public User loadUserInfo(User user) { public User loadUserInfo(User user) {
loadSFInfo(user); loadSFInfo(user);
@ -115,20 +119,13 @@ public class UserHttpRequestImpl implements UserHttpRequest {
} }
private User loadSingleSF(UserDataDTO userData, User user) { private User loadSingleSF(UserDataDTO userData, User user) {
getDataFromUserSFData(user, userData); getDataFromUserSFData(user, userData);
String sysCode = jtCompanyDomainService.findSystemCodeByCompanyCode(user.getCompanyCode()); String sysCode = jtCompanyDomainService.findSystemCodeByCompanyCode(user.getCompanyCode());
user.addFssc(userData.getCompany_cn(), sysCode); user.addFssc(userData.getCompany_cn(), sysCode);
// if (user.getCompanyCode().equals(XN_COMPANY_CODE)) { //根据同步时间来决定是否要同步部门信息
// user.addXNFssc(FSSC_LOAD_URL, postRequest); if (user.checkSyncTime()) {
// } addDeptInfo(userData, user, true);
// //如果用户的公司编码属于集团 那么加入集团财务共享跳转地址 }
// if (jtCompanyDomainService.ifCompanyInJT(null, userData.getCompany())) {
// user.addJTFssc(userData.getCompany_cn(), FSSC_LOAD_URL, postRequest);
// }
return user; return user;
} }
@ -153,6 +150,30 @@ public class UserHttpRequestImpl implements UserHttpRequest {
// 检查并处理JT公司和XN公司的特殊情况 // 检查并处理JT公司和XN公司的特殊情况
processSpecialCompanies(userDataDTOS, user); 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; return user;
} }
@ -172,24 +193,6 @@ public class UserHttpRequestImpl implements UserHttpRequest {
list.forEach(it -> user.addFssc(it.getCompany_cn(), list.forEach(it -> user.addFssc(it.getCompany_cn(),
jtCompanyDomainService.findSystemCodeByCompanyCode(it.getCompany()))); jtCompanyDomainService.findSystemCodeByCompanyCode(it.getCompany())));
// Set<String> companyCodes = userDataDTOS.stream()
// .map(UserDataDTO::getCompany)
// .collect(Collectors.toSet());
//
//
// List<String> 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) { private User getDataFromUserSFData(User user, UserDataDTO userData) {
@ -205,4 +208,21 @@ public class UserHttpRequestImpl implements UserHttpRequest {
return user; return user;
} }
public User loadUserDeptInfo(User user) {
List<UserDataDTO> 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);
}
} }