fix:修复因缓存出现的bug

This commit is contained in:
lulz1 2024-07-14 19:17:06 +08:00
parent fe764bc2ab
commit 6a76da4f15
5 changed files with 25 additions and 5 deletions

View File

@ -190,7 +190,7 @@ public class OrderApplicationService {
leg.setRouteId(routeOrder.getRouteId());
ApproveOrderNo approveOrderNo = routeOrder.getApproveOrderNo();
if (routeOrder.getApproveOrderNo().getActualOrderNo() != null && addLegData.getIfApprove() == 1) {
if (routeOrder.getApproveOrderNo().getActualOrderNo() != null && addLegData.getIfApprove() != null && addLegData.getIfApprove() == 1) {
//这里加入一个待审批事件
if (checkIfNeedApprove(routeOrder)) {
leg.addEvent(LegApprovalEvent.prepare());

View File

@ -4,10 +4,16 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serial;
import java.io.Serializable;
@Data
@NoArgsConstructor
public class FsscSystem {
public class FsscSystem implements Serializable {
@Serial
private static final long serialVersionUID = 8890173691234912036L;
private String systemName;
private String systemCode;
private String redirectUrl;

View File

@ -84,6 +84,9 @@ public class SystemOrganizationRepositoryImpl implements SystemOrganizationRepos
@Override
public List<SystemOrganization> findByIdIn(List<Long> ids) {
if (ids == null || ids.isEmpty()) {
return List.of();
}
List<SystemOrganization> fromCacheByIdIn = cacheSystemOrganizationRepository.getFromCacheByIdIn(ids);
List<Long> fromCacheOrg = fromCacheByIdIn.stream()
.filter(Objects::nonNull)
@ -167,7 +170,12 @@ public class SystemOrganizationRepositoryImpl implements SystemOrganizationRepos
@Override
public Optional<SystemOrganization> findByOrgCodeContainingOrOrgNameContaining(String orgCode, String orgName) {
return Optional.ofNullable(cacheSystemOrganizationRepository.cacheOrgCodeById(orgCode, null))
Optional<Long> cacheOrgCodeById = Optional
.ofNullable(cacheSystemOrganizationRepository.cacheOrgCodeById(orgCode, null));
if (cacheOrgCodeById.isEmpty()) {
cacheSystemOrganizationRepository.cacheEvictOrgCodeById(orgCode);
}
Optional<SystemOrganization> systemOrganizationOptional = cacheOrgCodeById
.flatMap(id -> Optional.ofNullable(cacheSystemOrganizationRepository.cacheById(id, null)))
.or(() -> Stream.of(
jdbcSystemOrganizationRepository.findByOrgCode(orgCode).stream().findFirst(),
@ -176,6 +184,10 @@ public class SystemOrganizationRepositoryImpl implements SystemOrganizationRepos
.filter(Optional::isPresent)
.map(Optional::get)
.findFirst());
if(cacheOrgCodeById.isEmpty() && systemOrganizationOptional.isPresent()) {
updateSystemOrganizationCache(systemOrganizationOptional.get());
}
return systemOrganizationOptional;
}

View File

@ -78,8 +78,8 @@ public class UserRepositoryImpl extends AbstractGenericRepository<User, Long> im
@Override
public User findByUserEmployeeNo(String employeeNo) {
return this.findByField("EmployeeNo", employeeNo)
.orElseThrow(() -> new CommandException("Employee Not Found"));
Optional<User> employee = this.findByField("EmployeeNo", employeeNo);
return employee.orElse(null);
}
@Override

View File

@ -5,9 +5,11 @@ import com.chint.domain.aggregates.system.SystemOrganization;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.support.NullValue;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Repository;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;