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 fakeOrderNo;
private LegData legData;
private Integer ifApprove;
private String extension;
}

View File

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

View File

@ -1,6 +1,9 @@
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.services.OrderApplicationService;
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.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
@RequestMapping("/order")
@ -53,7 +57,6 @@ public class OrderController {
}
@ApiOperation("同步行程规划单到供应商")
@PostMapping("/sync")
public Result<String> syncOrder(@RequestBody SyncLegData syncLegData) {

View File

@ -104,7 +104,7 @@ public class OrderApplicationService {
LegData legData = addLegData.getLegData();
List<Leg> legs = processLegData(legData, routeOrder); //创建行程节点
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) {
routeRepository.saveTempRouteOrder(routeOrder, 24L); //如果是未审批状态的话 将行程规划单保存到redis
} else {
@ -168,7 +168,8 @@ public class OrderApplicationService {
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);
String changeReason = legData.getChangeReason();
if (changeReason != null) {
@ -181,7 +182,9 @@ public class OrderApplicationService {
leg.setRouteId(routeOrder.getRouteId());
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());
}

View File

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

View File

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

View File

@ -7,63 +7,63 @@ import java.util.function.Function;
public abstract class AbstractGenericRepository<T, ID> {
// protected final GenericCacheRepository<T, ID> cacheRepository;
// protected final JdbcGenericRepository<T, ID> jdbcRepository;
// 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;
// }
protected final GenericCacheRepository<T, ID> cacheRepository;
protected final JdbcGenericRepository<T, ID> jdbcRepository;
protected final String cachePrefix;
// public <V> T findByField(Function<T, V> fieldGetter, String fieldPrefix, String fieldValue) {
// ID id = cacheRepository.findIdFromCache(fieldPrefix, fieldValue.toString());
// if (id == null) {
// T entity = findByFieldFromDatabase(fieldValue);
// if (entity != null) {
// CompletableFuture.runAsync(() -> updateCache(entity));
// }
// return entity;
// }
// return findById(id);
// }
// protected abstract String getPrefix();
//
// protected abstract List<T> findByFieldFromDatabase(String 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;
// }
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) {
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;
//@Component
public class GenericCacheRepository<T, ID> {
// @Autowired
// private RedisTemplate<String, T> redisTemplate;
//
// @Autowired
// private RedisTemplate<String, ID> redisTemplateId;
//
// private final Class<T> entityType;
// private final Class<ID> idType;
//
// public GenericCacheRepository(Class<T> entityType, Class<ID> idType) {
// this.entityType = entityType;
// this.idType = idType;
// }
//
// private String getKey(String prefix, Object value) {
// return prefix + "::" + value;
// }
//
// public T cache(String prefix, ID id, T entity) {
// String key = getKey(prefix, id);
// redisTemplate.opsForValue().set(key, entity);
// return entity;
// }
//
// public void cacheEvict(String prefix, ID id) {
// String key = getKey(prefix, id);
// redisTemplate.delete(key);
// }
//
// public T findFromCache(String prefix, ID id) {
// 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();
// return redisTemplate.opsForValue().multiGet(keys);
// }
//
// public ID cacheFieldToId(String fieldPrefix, String fieldValue, ID id) {
// String key = getKey(fieldPrefix, fieldValue);
// redisTemplateId.opsForValue().set(key, id);
// return id;
// }
//
// public ID findIdFromCache(String fieldPrefix, String fieldValue) {
// 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();
// return redisTemplateId.opsForValue().multiGet(keys);
// }
//
// public void cacheEvictFieldToId(String fieldPrefix, String fieldValue) {
// String key = getKey(fieldPrefix, fieldValue);
// redisTemplateId.delete(key);
// }
private final RedisTemplate<String, T> redisTemplate;
private final RedisTemplate<String, ID> redisTemplateId;
private final Class<T> entityType;
private final Class<ID> idType;
public GenericCacheRepository(RedisTemplate<String, T> redisTemplate,
RedisTemplate<String, ID> redisTemplateId,
Class<T> entityType,
Class<ID> idType) {
this.redisTemplate = redisTemplate;
this.redisTemplateId = redisTemplateId;
this.entityType = entityType;
this.idType = idType;
}
private String getKey(String prefix, Object value) {
return prefix + "::" + value;
}
public T cache(String prefix, ID id, T entity) {
String key = getKey(prefix, id);
redisTemplate.opsForValue().set(key, entity);
return entity;
}
public void cacheEvict(String prefix, ID id) {
String key = getKey(prefix, id);
redisTemplate.delete(key);
}
public T findFromCache(String prefix, ID id) {
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();
return redisTemplate.opsForValue().multiGet(keys);
}
public ID cacheFieldToId(String fieldPrefix, String fieldValue, ID id) {
String key = getKey(fieldPrefix, fieldValue);
redisTemplateId.opsForValue().set(key, id);
return id;
}
public ID findIdFromCache(String fieldPrefix, String fieldValue) {
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();
return redisTemplateId.opsForValue().multiGet(keys);
}
public void cacheEvictFieldToId(String fieldPrefix, String fieldValue) {
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);
List<T> findAll();
List<T> findByIdIn(List<ID> ids);
}

View File

@ -1,10 +1,8 @@
package com.chint.infrastructure.repository;
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.repository.RouteRepository;
import com.chint.domain.service.LegDomainService;
import com.chint.domain.value_object.OrderQueryData;
import com.chint.infrastructure.cache.RouteCacheService;
import com.chint.infrastructure.repository.jdbc.JdbcRouteRepository;
@ -51,6 +49,9 @@ public class RouteRepositoryImpl implements RouteRepository {
@Override
public RouteOrder reloadRouteOrderInCache(RouteOrder routeOrder) {
if (routeOrder.getRouteId() == null) {
return 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.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.jdbc.JdbcSystemCodeRepository;
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.List;
import java.util.Set;
@Repository
public class UserRepositoryImpl implements UserRepository {
@ -29,6 +30,11 @@ public class UserRepositoryImpl implements UserRepository {
return jdbcUserRepository.findByEmployeeNo(employeeNo);
}
@Override
public List<User> findByEmployeeNoIn(Set<String> employeeNoSet) {
return List.of();
}
@CacheEvict(value = "UserEmployeeNoCache", key = "#user.employeeNo")
@Override

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

Binary file not shown.

View File

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

View File

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