fix:修复因缓存问题,无法添加行程的问题

This commit is contained in:
lulz1 2024-07-05 13:02:39 +08:00
parent c166e430d5
commit ef1720d871
15 changed files with 153 additions and 133 deletions

View File

@ -10,4 +10,6 @@ public class AddLegData {
private String sysCode; private String sysCode;
private String fakeOrderNo; private String fakeOrderNo;
private LegData legData; private LegData legData;
private Integer ifApprove;
private String extension;
} }

View File

@ -184,7 +184,7 @@ public class AutoWorkController {
@PostMapping("/ly/record/save") @PostMapping("/ly/record/save")
public Result<String> autoSaveLYRecord() { public Result<String> autoSaveLYRecord() {
//同步拉取上月数据 //同步拉取上月数据
lyStatementOrder.saveAll(); // lyStatementOrder.saveAll();
//将未转换的结算数据生成为财务共享需要的数据 //将未转换的结算数据生成为财务共享需要的数据
try { try {
Command.of(LYOrderRecordGenerateCommand.class).sendToQueue(); Command.of(LYOrderRecordGenerateCommand.class).sendToQueue();

View File

@ -1,6 +1,9 @@
package com.chint.application.in; package com.chint.application.in;
import com.chint.application.dtos.*; import com.chint.application.dtos.AddLegData;
import com.chint.application.dtos.DeleteLegData;
import com.chint.application.dtos.FinishOrderParam;
import com.chint.application.dtos.LegApprovalParam;
import com.chint.application.queryies.OrderQuery; import com.chint.application.queryies.OrderQuery;
import com.chint.application.services.OrderApplicationService; import com.chint.application.services.OrderApplicationService;
import com.chint.domain.aggregates.order.RouteOrder; import com.chint.domain.aggregates.order.RouteOrder;
@ -20,7 +23,8 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import static com.chint.infrastructure.constant.CommonMessageConstant.*; import static com.chint.infrastructure.constant.CommonMessageConstant.FAILURE;
import static com.chint.infrastructure.constant.CommonMessageConstant.SUCCESS;
@RestController @RestController
@RequestMapping("/order") @RequestMapping("/order")
@ -53,7 +57,6 @@ public class OrderController {
} }
@ApiOperation("同步行程规划单到供应商") @ApiOperation("同步行程规划单到供应商")
@PostMapping("/sync") @PostMapping("/sync")
public Result<String> syncOrder(@RequestBody SyncLegData syncLegData) { public Result<String> syncOrder(@RequestBody SyncLegData syncLegData) {

View File

@ -104,7 +104,7 @@ public class OrderApplicationService {
LegData legData = addLegData.getLegData(); LegData legData = addLegData.getLegData();
List<Leg> legs = processLegData(legData, routeOrder); //创建行程节点 List<Leg> legs = processLegData(legData, routeOrder); //创建行程节点
legDomainService.queryLocation(legs); legDomainService.queryLocation(legs);
legs.forEach(leg -> handleLegEvents(leg, addLegData.getLegData(), routeOrder)); legs.forEach(leg -> handleLegEvents(leg, addLegData, routeOrder));
if (routeOrder.getApproveOrderNo() != null && routeOrder.getApproveOrderNo().getActualOrderNo() == null) { if (routeOrder.getApproveOrderNo() != null && routeOrder.getApproveOrderNo().getActualOrderNo() == null) {
routeRepository.saveTempRouteOrder(routeOrder, 24L); //如果是未审批状态的话 将行程规划单保存到redis routeRepository.saveTempRouteOrder(routeOrder, 24L); //如果是未审批状态的话 将行程规划单保存到redis
} else { } else {
@ -168,7 +168,8 @@ public class OrderApplicationService {
return leg; return leg;
} }
private void handleLegEvents(Leg leg, LegData legData, RouteOrder routeOrder) { private void handleLegEvents(Leg leg, AddLegData addLegData, RouteOrder routeOrder) {
LegData legData = addLegData.getLegData();
legDomainService.addPreEvent(leg); legDomainService.addPreEvent(leg);
String changeReason = legData.getChangeReason(); String changeReason = legData.getChangeReason();
if (changeReason != null) { if (changeReason != null) {
@ -181,7 +182,9 @@ public class OrderApplicationService {
leg.setRouteId(routeOrder.getRouteId()); leg.setRouteId(routeOrder.getRouteId());
ApproveOrderNo approveOrderNo = routeOrder.getApproveOrderNo(); ApproveOrderNo approveOrderNo = routeOrder.getApproveOrderNo();
if (!routeOrder.getOrderStatus().equals(ORDER_STATUS_PREPARE) && approveOrderNo.getSysCode().equals("ANFSSC")) { if (!routeOrder.getOrderStatus().equals(ORDER_STATUS_PREPARE) && approveOrderNo.getSysCode().equals("ANFSSC") &&
addLegData.getIfApprove() == 1
) {
//这里加入一个待审批事件 //这里加入一个待审批事件
leg.addEvent(LegApprovalEvent.prepare()); leg.addEvent(LegApprovalEvent.prepare());
} }

View File

@ -172,10 +172,12 @@ public class AmapOrderRecordExtensionFactory implements OrderRecordExtensionFact
Duration runtimeDuration = Duration.between(runStartTime, runEndTime); Duration runtimeDuration = Duration.between(runStartTime, runEndTime);
long runtimeInMinutes = runtimeDuration.toMinutes(); long runtimeInMinutes = runtimeDuration.toMinutes();
orderCarRecord.setRunTime(String.valueOf(runtimeInMinutes)); orderCarRecord.setRunTime(String.valueOf(runtimeInMinutes));
} else { }
if (Double.parseDouble(orderCarRecord.getRunTime()) <= 0) {
orderCarRecord.setRunTime("0"); orderCarRecord.setRunTime("0");
} }
orderDetail.ifPresentOrElse(orderCarRecord::loadComplianceInfo, orderCarRecord::loadComplianceInfoNot); orderDetail.ifPresentOrElse(orderCarRecord::loadComplianceInfo, orderCarRecord::loadComplianceInfoNot);
return orderCarRecord; return orderCarRecord;
} }

View File

@ -3,12 +3,15 @@ package com.chint.domain.repository;
import com.chint.domain.aggregates.user.User; import com.chint.domain.aggregates.user.User;
import java.util.List; import java.util.List;
import java.util.Set;
public interface UserRepository { public interface UserRepository {
User findById(Long id); User findById(Long id);
User findByUserEmployeeNo(String employeeNo); User findByUserEmployeeNo(String employeeNo);
List<User> findByEmployeeNoIn(Set<String> employeeNoSet);
User save(User user); User save(User user);
void saveAll(List<User> userList); void saveAll(List<User> userList);

View File

@ -7,63 +7,63 @@ import java.util.function.Function;
public abstract class AbstractGenericRepository<T, ID> { public abstract class AbstractGenericRepository<T, ID> {
// protected final GenericCacheRepository<T, ID> cacheRepository; protected final GenericCacheRepository<T, ID> cacheRepository;
// protected final JdbcGenericRepository<T, ID> jdbcRepository; protected final JdbcGenericRepository<T, ID> jdbcRepository;
// protected final String cachePrefix; protected final String cachePrefix;
//
// protected AbstractGenericRepository(GenericCacheRepository<T, ID> cacheRepository,
// JdbcGenericRepository<T, ID> jdbcRepository,
// String cachePrefix) {
// this.cacheRepository = cacheRepository;
// this.jdbcRepository = jdbcRepository;
// this.cachePrefix = cachePrefix;
// }
//
// public T save(T entity) {
// T savedEntity = jdbcRepository.save(entity);
// updateCache(savedEntity);
// return savedEntity;
// }
//
// public T findById(ID id) {
// T entity = cacheRepository.findFromCache(cachePrefix, id);
// if (entity == null) {
// Optional<T> optionalEntity = jdbcRepository.findById(id);
// if (optionalEntity.isPresent()) {
// entity = optionalEntity.get();
// T finalEntity = entity;
// CompletableFuture.runAsync(() -> updateCache(finalEntity));
// }
// }
// return entity;
// }
// public <V> T findByField(Function<T, V> fieldGetter, String fieldPrefix, String fieldValue) { protected AbstractGenericRepository(GenericCacheRepository<T, ID> cacheRepository,
// ID id = cacheRepository.findIdFromCache(fieldPrefix, fieldValue.toString()); JdbcGenericRepository<T, ID> jdbcRepository,
// if (id == null) { String cachePrefix) {
// T entity = findByFieldFromDatabase(fieldValue); this.cacheRepository = cacheRepository;
// if (entity != null) { this.jdbcRepository = jdbcRepository;
// CompletableFuture.runAsync(() -> updateCache(entity)); this.cachePrefix = cachePrefix;
// } }
// return entity;
// } public T save(T entity) {
// return findById(id); T savedEntity = jdbcRepository.save(entity);
// } updateCache(savedEntity);
return savedEntity;
// protected abstract String getPrefix(); }
//
// protected abstract List<T> findByFieldFromDatabase(String fieldValue); public T findById(ID id) {
// T entity = cacheRepository.findFromCache(cachePrefix, id);
// protected abstract List<T> findByFieldInFromDatabase(List<String> fieldValueList); if (entity == null) {
// Optional<T> optionalEntity = jdbcRepository.findById(id);
// protected abstract void updateCache(T entity); if (optionalEntity.isPresent()) {
// entity = optionalEntity.get();
// protected void updateFieldCache(String fieldName, String fieldValue, ID id) { T finalEntity = entity;
// cacheRepository.cacheEvictFieldToId(fieldName, fieldValue); CompletableFuture.runAsync(() -> updateCache(finalEntity));
// cacheRepository.cacheFieldToId(fieldName, fieldValue, id); }
// } }
// return entity;
// protected String getFieldPrefix(String fieldName) { }
// return cachePrefix + "::" + fieldName;
// } public <V> T findByField(Function<T, V> fieldGetter, String fieldPrefix) {
ID id = cacheRepository.findIdFromCache(fieldPrefix, fieldGetter.toString());
if (id == null) {
T entity = findByFieldFromDatabase(fieldGetter);
if (entity != null) {
CompletableFuture.runAsync(() -> updateCache(entity));
}
return entity;
}
return findById(id);
}
protected abstract String getPrefix();
protected abstract <V> T findByFieldFromDatabase(V fieldValue);
protected abstract List<T> findByFieldInFromDatabase(List<String> fieldValueList);
protected abstract void updateCache(T entity);
protected void updateFieldCache(String fieldName, String fieldValue, ID id) {
cacheRepository.cacheEvictFieldToId(fieldName, fieldValue);
cacheRepository.cacheFieldToId(fieldName, fieldValue, id);
}
protected String getFieldPrefix(String fieldName) {
return cachePrefix + "::" + fieldName;
}
} }

View File

@ -6,66 +6,67 @@ import org.springframework.stereotype.Component;
import java.util.List; import java.util.List;
//@Component
public class GenericCacheRepository<T, ID> { public class GenericCacheRepository<T, ID> {
// @Autowired private final RedisTemplate<String, T> redisTemplate;
// private RedisTemplate<String, T> redisTemplate; private final RedisTemplate<String, ID> redisTemplateId;
// private final Class<T> entityType;
// @Autowired private final Class<ID> idType;
// private RedisTemplate<String, ID> redisTemplateId;
// public GenericCacheRepository(RedisTemplate<String, T> redisTemplate,
// private final Class<T> entityType; RedisTemplate<String, ID> redisTemplateId,
// private final Class<ID> idType; Class<T> entityType,
// Class<ID> idType) {
// public GenericCacheRepository(Class<T> entityType, Class<ID> idType) { this.redisTemplate = redisTemplate;
// this.entityType = entityType; this.redisTemplateId = redisTemplateId;
// this.idType = idType; this.entityType = entityType;
// } this.idType = idType;
// }
// private String getKey(String prefix, Object value) {
// return prefix + "::" + value; private String getKey(String prefix, Object value) {
// } return prefix + "::" + value;
// }
// public T cache(String prefix, ID id, T entity) {
// String key = getKey(prefix, id); public T cache(String prefix, ID id, T entity) {
// redisTemplate.opsForValue().set(key, entity); String key = getKey(prefix, id);
// return entity; redisTemplate.opsForValue().set(key, entity);
// } return entity;
// }
// public void cacheEvict(String prefix, ID id) {
// String key = getKey(prefix, id); public void cacheEvict(String prefix, ID id) {
// redisTemplate.delete(key); String key = getKey(prefix, id);
// } redisTemplate.delete(key);
// }
// public T findFromCache(String prefix, ID id) {
// String key = getKey(prefix, id); public T findFromCache(String prefix, ID id) {
// return redisTemplate.opsForValue().get(key); String key = getKey(prefix, id);
// } return redisTemplate.opsForValue().get(key);
// }
// public List<T> cacheBatchByIds(String prefix, List<ID> ids) {
// List<String> keys = ids.stream().map(id -> getKey(prefix, id)).toList(); public List<T> cacheBatchByIds(String prefix, List<ID> ids) {
// return redisTemplate.opsForValue().multiGet(keys); List<String> keys = ids.stream().map(id -> getKey(prefix, id)).toList();
// } return redisTemplate.opsForValue().multiGet(keys);
// }
// public ID cacheFieldToId(String fieldPrefix, String fieldValue, ID id) {
// String key = getKey(fieldPrefix, fieldValue); public ID cacheFieldToId(String fieldPrefix, String fieldValue, ID id) {
// redisTemplateId.opsForValue().set(key, id); String key = getKey(fieldPrefix, fieldValue);
// return id; redisTemplateId.opsForValue().set(key, id);
// } return id;
// }
// public ID findIdFromCache(String fieldPrefix, String fieldValue) {
// String key = getKey(fieldPrefix, fieldValue); public ID findIdFromCache(String fieldPrefix, String fieldValue) {
// return redisTemplateId.opsForValue().get(key); String key = getKey(fieldPrefix, fieldValue);
// } return redisTemplateId.opsForValue().get(key);
// }
// public List<ID> findIdsFromCache(String fieldPrefix, List<String> fieldValueList) {
// List<String> keys = fieldValueList.stream().map(fieldValue -> getKey(fieldPrefix, fieldValue)).toList(); public List<ID> findIdsFromCache(String fieldPrefix, List<String> fieldValueList) {
// return redisTemplateId.opsForValue().multiGet(keys); List<String> keys = fieldValueList.stream().map(fieldValue -> getKey(fieldPrefix, fieldValue)).toList();
// } return redisTemplateId.opsForValue().multiGet(keys);
// }
// public void cacheEvictFieldToId(String fieldPrefix, String fieldValue) {
// String key = getKey(fieldPrefix, fieldValue); public void cacheEvictFieldToId(String fieldPrefix, String fieldValue) {
// redisTemplateId.delete(key); String key = getKey(fieldPrefix, fieldValue);
// } redisTemplateId.delete(key);
}
} }

View File

@ -11,4 +11,6 @@ public interface JdbcGenericRepository<T, ID> extends CrudRepository<T, ID> {
Optional<T> findById(ID id); Optional<T> findById(ID id);
List<T> findAll(); List<T> findAll();
List<T> findByIdIn(List<ID> ids);
} }

View File

@ -1,10 +1,8 @@
package com.chint.infrastructure.repository; package com.chint.infrastructure.repository;
import com.chint.domain.aggregates.order.ApproveOrderNo; import com.chint.domain.aggregates.order.ApproveOrderNo;
import com.chint.domain.aggregates.order.Leg;
import com.chint.domain.aggregates.order.RouteOrder; import com.chint.domain.aggregates.order.RouteOrder;
import com.chint.domain.repository.RouteRepository; import com.chint.domain.repository.RouteRepository;
import com.chint.domain.service.LegDomainService;
import com.chint.domain.value_object.OrderQueryData; import com.chint.domain.value_object.OrderQueryData;
import com.chint.infrastructure.cache.RouteCacheService; import com.chint.infrastructure.cache.RouteCacheService;
import com.chint.infrastructure.repository.jdbc.JdbcRouteRepository; import com.chint.infrastructure.repository.jdbc.JdbcRouteRepository;
@ -51,6 +49,9 @@ public class RouteRepositoryImpl implements RouteRepository {
@Override @Override
public RouteOrder reloadRouteOrderInCache(RouteOrder routeOrder) { public RouteOrder reloadRouteOrderInCache(RouteOrder routeOrder) {
if (routeOrder.getRouteId() == null) {
return routeOrder;
}
return routeCacheService.reloadRouteOrderInCache(routeOrder); return routeCacheService.reloadRouteOrderInCache(routeOrder);
} }

View File

@ -2,9 +2,6 @@ package com.chint.infrastructure.repository;
import com.chint.domain.aggregates.system.SystemCode; import com.chint.domain.aggregates.system.SystemCode;
import com.chint.domain.repository.SystemCodeRepository; import com.chint.domain.repository.SystemCodeRepository;
import com.chint.infrastructure.echo_framework.repository.AbstractGenericRepository;
import com.chint.infrastructure.echo_framework.repository.GenericCacheRepository;
import com.chint.infrastructure.echo_framework.repository.JdbcGenericRepository;
import com.chint.infrastructure.repository.cache.CacheSystemCodeRepository; import com.chint.infrastructure.repository.cache.CacheSystemCodeRepository;
import com.chint.infrastructure.repository.jdbc.JdbcSystemCodeRepository; import com.chint.infrastructure.repository.jdbc.JdbcSystemCodeRepository;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;

View File

@ -10,6 +10,7 @@ import org.springframework.stereotype.Repository;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set;
@Repository @Repository
public class UserRepositoryImpl implements UserRepository { public class UserRepositoryImpl implements UserRepository {
@ -29,6 +30,11 @@ public class UserRepositoryImpl implements UserRepository {
return jdbcUserRepository.findByEmployeeNo(employeeNo); return jdbcUserRepository.findByEmployeeNo(employeeNo);
} }
@Override
public List<User> findByEmployeeNoIn(Set<String> employeeNoSet) {
return List.of();
}
@CacheEvict(value = "UserEmployeeNoCache", key = "#user.employeeNo") @CacheEvict(value = "UserEmployeeNoCache", key = "#user.employeeNo")
@Override @Override

BIN
src/main/resources/app.jar Normal file

Binary file not shown.

View File

@ -250,7 +250,7 @@ public class CTripTest {
@Test @Test
void search() { void search() {
BaseContext.setCurrentUser(user); BaseContext.setCurrentUser(user);
SearchOrderResponse response = orderSearchRequest.searchOrderResponseByOrderId("32952443950"); SearchOrderResponse response = orderSearchRequest.searchOrderResponseByOrderId("32055893290");
System.out.println(response); System.out.println(response);
} }

View File

@ -821,7 +821,7 @@ public class LYTest {
@Test @Test
void searchTrain() { void searchTrain() {
TrainDetailResponse trainOrderDetail = lySearchRequest.getTrainOrderDetail("DT24051673807741786"); TrainDetailResponse trainOrderDetail = lySearchRequest.getTrainOrderDetail("DT24060776494132172");
Gson gson = new Gson(); Gson gson = new Gson();
String json = gson.toJson(trainOrderDetail); String json = gson.toJson(trainOrderDetail);
System.out.println(json); System.out.println(json);
@ -829,7 +829,7 @@ public class LYTest {
@Test @Test
void searchHotel() { void searchHotel() {
HotelDetailResponse hotelOrderDetail = lySearchRequest.getHotelOrderDetail("HO20240321143500052669"); HotelDetailResponse hotelOrderDetail = lySearchRequest.getHotelOrderDetail("HO20240415140900363081");
Gson gson = new Gson(); Gson gson = new Gson();
String json = gson.toJson(hotelOrderDetail); String json = gson.toJson(hotelOrderDetail);
System.out.println(json); System.out.println(json);