From ab7e5162c22653ab5842b85752f5dbaf19f2ac90 Mon Sep 17 00:00:00 2001 From: lulz1 Date: Tue, 16 Jul 2024 15:36:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E9=AB=98=E5=8E=8B?= =?UTF-8?q?=E7=BB=93=E7=AE=97=E6=9F=A5=E8=AF=A2=E6=95=B0=E6=8D=AE=E4=B8=8D?= =?UTF-8?q?=E5=AE=8C=E5=85=A8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aggregates/standards/RanksOrder.java | 20 ++++++ .../aggregates/standards/RanksOrgCode.java | 20 ++++++ .../repository/RanksOrderRepository.java | 10 +++ .../repository/RanksOrgCodeRepository.java | 9 +++ .../repository/RanksOrderRepositoryImpl.java | 69 +++++++++++++++++++ .../RanksOrgCodeRepositoryImpl.java | 28 ++++++++ .../jdbc/JdbcRanksOrderRepository.java | 15 ++++ .../jdbc/JdbcRanksOrgCodeRepository.java | 13 ++++ .../data_center/user/UserHttpRequest.java | 3 +- .../data_center/user/UserHttpRequestImpl.java | 59 ++++++++++------ src/test/java/com/chint/LYTest.java | 2 +- .../java/com/chint/RouteApplicationTests.java | 4 +- 12 files changed, 227 insertions(+), 25 deletions(-) create mode 100644 src/main/java/com/chint/domain/aggregates/standards/RanksOrder.java create mode 100644 src/main/java/com/chint/domain/aggregates/standards/RanksOrgCode.java create mode 100644 src/main/java/com/chint/domain/repository/RanksOrderRepository.java create mode 100644 src/main/java/com/chint/domain/repository/RanksOrgCodeRepository.java create mode 100644 src/main/java/com/chint/infrastructure/repository/RanksOrderRepositoryImpl.java create mode 100644 src/main/java/com/chint/infrastructure/repository/RanksOrgCodeRepositoryImpl.java create mode 100644 src/main/java/com/chint/infrastructure/repository/jdbc/JdbcRanksOrderRepository.java create mode 100644 src/main/java/com/chint/infrastructure/repository/jdbc/JdbcRanksOrgCodeRepository.java diff --git a/src/main/java/com/chint/domain/aggregates/standards/RanksOrder.java b/src/main/java/com/chint/domain/aggregates/standards/RanksOrder.java new file mode 100644 index 00000000..a0b064a0 --- /dev/null +++ b/src/main/java/com/chint/domain/aggregates/standards/RanksOrder.java @@ -0,0 +1,20 @@ +package com.chint.domain.aggregates.standards; + +import lombok.Data; +import org.springframework.data.annotation.Id; +import org.springframework.data.relational.core.mapping.Table; + +import java.io.Serial; +import java.io.Serializable; + +@Data +@Table("rank_order") +public class RanksOrder implements Serializable { + @Serial + private static final long serialVersionUID = 978169273211358470L; + @Id + private Long id; + private String rankName; + private Integer rankOrderValue; + private String extension; +} diff --git a/src/main/java/com/chint/domain/aggregates/standards/RanksOrgCode.java b/src/main/java/com/chint/domain/aggregates/standards/RanksOrgCode.java new file mode 100644 index 00000000..9da127d4 --- /dev/null +++ b/src/main/java/com/chint/domain/aggregates/standards/RanksOrgCode.java @@ -0,0 +1,20 @@ +package com.chint.domain.aggregates.standards; + +import lombok.Data; +import org.springframework.data.annotation.Id; +import org.springframework.data.relational.core.mapping.Table; + +import java.io.Serial; +import java.io.Serializable; + +@Data +@Table("rank_org_code") +public class RanksOrgCode implements Serializable { + @Serial + private static final long serialVersionUID = 1231251689922134470L; + @Id + private Long id; + private String parentOrgCode; + private String orgCode; + private String extension; +} diff --git a/src/main/java/com/chint/domain/repository/RanksOrderRepository.java b/src/main/java/com/chint/domain/repository/RanksOrderRepository.java new file mode 100644 index 00000000..7b42c6c8 --- /dev/null +++ b/src/main/java/com/chint/domain/repository/RanksOrderRepository.java @@ -0,0 +1,10 @@ +package com.chint.domain.repository; + +import com.chint.domain.aggregates.standards.RanksOrder; + +import java.util.List; +import java.util.Set; + +public interface RanksOrderRepository { + List findByRankNameIn(Set rankNames); +} diff --git a/src/main/java/com/chint/domain/repository/RanksOrgCodeRepository.java b/src/main/java/com/chint/domain/repository/RanksOrgCodeRepository.java new file mode 100644 index 00000000..6f83c2b9 --- /dev/null +++ b/src/main/java/com/chint/domain/repository/RanksOrgCodeRepository.java @@ -0,0 +1,9 @@ +package com.chint.domain.repository; + +import com.chint.domain.aggregates.standards.RanksOrgCode; + +import java.util.Optional; + +public interface RanksOrgCodeRepository { + Optional findByOrgCode(String orgCode); +} diff --git a/src/main/java/com/chint/infrastructure/repository/RanksOrderRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/RanksOrderRepositoryImpl.java new file mode 100644 index 00000000..39da7f1f --- /dev/null +++ b/src/main/java/com/chint/infrastructure/repository/RanksOrderRepositoryImpl.java @@ -0,0 +1,69 @@ +package com.chint.infrastructure.repository; + +import com.chint.domain.aggregates.standards.RanksOrder; +import com.chint.domain.repository.RanksOrderRepository; +import com.chint.infrastructure.echo_framework.repository.AbstractGenericRepository; +import com.chint.infrastructure.echo_framework.repository.GenericCacheRepository; +import com.chint.infrastructure.repository.jdbc.JdbcRanksOrderRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Repository; + +import java.util.List; +import java.util.Optional; +import java.util.Set; + +@Repository +public class RanksOrderRepositoryImpl extends AbstractGenericRepository implements RanksOrderRepository { + + @Autowired + private JdbcRanksOrderRepository jdbcRanksOrderRepository; + @Autowired + private RedisTemplate redisTemplate; + @Autowired + private RedisTemplate redisTemplateId; + + @Autowired + public RanksOrderRepositoryImpl(RedisTemplate redisTemplate, + RedisTemplate redisTemplateId) { + super(new GenericCacheRepository<>(redisTemplate, redisTemplateId, RanksOrder.class, Long.class)); + } + + @Override + public List findByRankNameIn(Set rankNames) { + return findByFieldsIn("RankName", + rankNames, + RanksOrder::getRankName, + (set) -> jdbcRanksOrderRepository.findByRankNameIn(set.stream().toList())); + } + + @Override + public RanksOrder save(RanksOrder entity) { + return jdbcRanksOrderRepository.save(entity); + } + + @Override + protected Optional findByIdFromDB(Long aLong) { + return jdbcRanksOrderRepository.findById(aLong); + } + + @Override + protected List findByIdsInFromDB(Set longs) { + return jdbcRanksOrderRepository.findByIdIn(longs.stream().toList()); + } + + @Override + protected Long getPrimaryKeys(RanksOrder entity) { + return entity.getId(); + } + + @Override + protected String getPrefix() { + return "RanksOrder"; + } + + @Override + protected String beforeUpdateCache() { + return ""; + } +} diff --git a/src/main/java/com/chint/infrastructure/repository/RanksOrgCodeRepositoryImpl.java b/src/main/java/com/chint/infrastructure/repository/RanksOrgCodeRepositoryImpl.java new file mode 100644 index 00000000..4635e664 --- /dev/null +++ b/src/main/java/com/chint/infrastructure/repository/RanksOrgCodeRepositoryImpl.java @@ -0,0 +1,28 @@ +package com.chint.infrastructure.repository; + +import com.chint.domain.aggregates.standards.RanksOrgCode; +import com.chint.domain.aggregates.user.User; +import com.chint.domain.repository.RanksOrgCodeRepository; +import com.chint.infrastructure.repository.jdbc.JdbcRanksOrgCodeRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Repository; + +import java.util.Optional; + +@Repository +public class RanksOrgCodeRepositoryImpl implements RanksOrgCodeRepository { + + @Autowired + private JdbcRanksOrgCodeRepository jdbcRanksOrgCodeRepository; + + + @Cacheable(value = "Ranks::OrgCode", key = "#orgCode") + @Override + public Optional findByOrgCode(String orgCode) { + return jdbcRanksOrgCodeRepository.findByOrgCode(orgCode).stream().findFirst(); + } + + +} diff --git a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcRanksOrderRepository.java b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcRanksOrderRepository.java new file mode 100644 index 00000000..238e58e6 --- /dev/null +++ b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcRanksOrderRepository.java @@ -0,0 +1,15 @@ +package com.chint.infrastructure.repository.jdbc; + +import com.chint.domain.aggregates.standards.RanksOrder; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface JdbcRanksOrderRepository extends CrudRepository { + + List findByRankNameIn(List rankNames); + List findByIdIn(List rankIds); + +} diff --git a/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcRanksOrgCodeRepository.java b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcRanksOrgCodeRepository.java new file mode 100644 index 00000000..65eb28ae --- /dev/null +++ b/src/main/java/com/chint/infrastructure/repository/jdbc/JdbcRanksOrgCodeRepository.java @@ -0,0 +1,13 @@ +package com.chint.infrastructure.repository.jdbc; + +import com.chint.domain.aggregates.standards.RanksOrgCode; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface JdbcRanksOrgCodeRepository extends CrudRepository { + + List findByOrgCode(String orgCode); +} diff --git a/src/main/java/com/chint/interfaces/rest/data_center/user/UserHttpRequest.java b/src/main/java/com/chint/interfaces/rest/data_center/user/UserHttpRequest.java index ec832c3f..5929a2eb 100644 --- a/src/main/java/com/chint/interfaces/rest/data_center/user/UserHttpRequest.java +++ b/src/main/java/com/chint/interfaces/rest/data_center/user/UserHttpRequest.java @@ -1,7 +1,6 @@ package com.chint.interfaces.rest.data_center.user; import com.chint.domain.aggregates.user.User; -import com.chint.domain.aggregates.user.UserCustomCode; public interface UserHttpRequest { User loadUserInfo(User user); @@ -10,5 +9,7 @@ public interface UserHttpRequest { User loadUserDeptInfo(User user); + User loadRankCode(User user); + String belongDeport(String employeeNo, String accountCompanyName); } \ No newline at end of file diff --git a/src/main/java/com/chint/interfaces/rest/data_center/user/UserHttpRequestImpl.java b/src/main/java/com/chint/interfaces/rest/data_center/user/UserHttpRequestImpl.java index 1c613ad2..5b71e1e3 100644 --- a/src/main/java/com/chint/interfaces/rest/data_center/user/UserHttpRequestImpl.java +++ b/src/main/java/com/chint/interfaces/rest/data_center/user/UserHttpRequestImpl.java @@ -5,14 +5,14 @@ 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.RanksOrder; +import com.chint.domain.aggregates.standards.RanksOrgCode; 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.exceptions.AuthException; 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.repository.*; import com.chint.domain.service.JTCompanyDomainService; import com.chint.domain.service.RankDomainService; import com.chint.infrastructure.constant.SFConstant; @@ -25,8 +25,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; -import java.util.List; -import java.util.Optional; +import java.util.*; import static com.chint.infrastructure.constant.CommonMessageConstant.EMPLOYEE_NO_NOT_EXIST; import static com.chint.infrastructure.constant.RankConstant.DEFAULT_RANK_NAME; @@ -64,6 +63,12 @@ public class UserHttpRequestImpl implements UserHttpRequest { @Autowired private JTCompanyRepository jtCompanyRepository; + @Autowired + private RanksOrderRepository ranksOrderRepository; + + @Autowired + private RanksOrgCodeRepository ranksOrgCodeRepository; + @Value("${sf.systemId}") private String systemId; @@ -96,25 +101,37 @@ public class UserHttpRequestImpl implements UserHttpRequest { } public User loadRankCode(User user) { - String rankName = null; - //默认先查找职级表里的内容 - Optional> staffRank = staffRankRepository - .findRankNameByEmployNoAndJTCompany(user.getEmployeeNo(), user.getCompanyCode()); - if (staffRank.isPresent() && !staffRank.get().isEmpty()) { - rankName = staffRank.get().get(0).getEmployeeLevel(); + String rankName; + //如果表里没有维护他的职级 , 那么取是sf号的职级 + if (user.getManaLevel() != null) { + rankName = user.getManaLevel(); + } else if (user.getProfLevel() != null) { + rankName = user.getProfLevel(); + } else if (user.getQualityLevel() != null) { + rankName = user.getQualityLevel(); } else { - //如果表里没有维护他的职级 , 那么取是sf号的职级 - if (user.getManaLevel() != null) { - rankName = user.getManaLevel(); - } else if (user.getProfLevel() != null) { - rankName = user.getProfLevel(); - } else if (user.getQualityLevel() != null) { - rankName = user.getQualityLevel(); - } else { - rankName = DEFAULT_RANK_NAME; + rankName = DEFAULT_RANK_NAME; + } + //默认先查找职级表里的内容 + Optional staffRank = staffRankRepository + .findRankNameByEmployNoAndJTCompany(user.getEmployeeNo(), user.getCompanyCode()) + .flatMap(it -> it.stream().findFirst()); + if (staffRank.isPresent()) { + rankName = staffRank.get().getEmployeeLevel(); + //如果存在自定义职级,那么就开始比较职级大小 + //这里执行rank排序规则 + Optional max = ranksOrderRepository + .findByRankNameIn(Set.of(rankName, staffRank.get().getEmployeeLevel())) + .stream() + .filter(Objects::nonNull) + .max(Comparator.comparing(RanksOrder::getRankOrderValue)); + if (max.isPresent()) { + rankName = max.get().getRankName(); } } - Ranks ranks = rankDomainService.queryRanks(rankName, user.getCompanyCode()); + + Optional orgCode = ranksOrgCodeRepository.findByOrgCode(user.getCompanyCode()); + Ranks ranks = rankDomainService.queryRanks(rankName, orgCode.isPresent() ? orgCode.get().getParentOrgCode() : user.getCompanyCode()); if (ranks == null) { if (rankName.contains("L")) { rankName = rankName.replace("L", "P"); diff --git a/src/test/java/com/chint/LYTest.java b/src/test/java/com/chint/LYTest.java index 09b19711..b8855c10 100644 --- a/src/test/java/com/chint/LYTest.java +++ b/src/test/java/com/chint/LYTest.java @@ -821,7 +821,7 @@ public class LYTest { @Test void searchTrain() { - TrainDetailResponse trainOrderDetail = lySearchRequest.getTrainOrderDetail("DT24062077869838419"); + TrainDetailResponse trainOrderDetail = lySearchRequest.getTrainOrderDetail("DT24061677314144436"); Gson gson = new Gson(); String json = gson.toJson(trainOrderDetail); System.out.println(json); diff --git a/src/test/java/com/chint/RouteApplicationTests.java b/src/test/java/com/chint/RouteApplicationTests.java index 7e116cc0..4e160877 100644 --- a/src/test/java/com/chint/RouteApplicationTests.java +++ b/src/test/java/com/chint/RouteApplicationTests.java @@ -346,10 +346,10 @@ class RouteApplicationTests { @Test void testPushBatch() throws UnsupportedEncodingException { - List billcodeList = List.of("CLS24070300047"); + List billcodeList = List.of("CLS24070800088"); List sfnoList = List.of( - "220208019" + "221213065" ); System.out.println(billcodeList.size());