修复代理填单缓存问题

This commit is contained in:
lulz1 2024-03-12 15:39:25 +08:00
parent 1a521b7a8d
commit fd6783b1f4
8 changed files with 84 additions and 23 deletions

View File

@ -1,5 +1,6 @@
package com.chint.application.commands;
import com.chint.domain.aggregates.order.RouteOrder;
import com.chint.domain.value_object.ApproveRouteData;
import com.chint.infrastructure.echo_framework.command.Command;
import lombok.Data;
@ -11,6 +12,7 @@ public class OrderApprovalStartCommand extends Command {
private Integer LegEventType = LEG_EVENT_APPROVAL;
private Long LegId;
private ApproveRouteData data;
private RouteOrder routeOrder;
public OrderApprovalStartCommand legId(Long LegId) {
this.setLegId(LegId);
@ -21,4 +23,9 @@ public class OrderApprovalStartCommand extends Command {
this.data = data;
return this;
}
public OrderApprovalStartCommand order(RouteOrder order) {
this.routeOrder = order;
return this;
}
}

View File

@ -0,0 +1,33 @@
package com.chint.application.in;
import com.chint.infrastructure.util.Result;
import com.chint.interfaces.rest.ctrip.order.CTripOrderRecordAutoSave;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import static com.chint.infrastructure.constant.CommonMessageConstant.SUCCESS;
@RestController
@RequestMapping("/public")
public class AutoWorkController {
@Autowired
private CTripOrderRecordAutoSave cTripOrderRecordAutoSave;
@Transactional
@ApiOperation("自动拉取携程昨天的流水号每天晚上8点执行")
@PostMapping("/cTrip/record/save")
public Result<String> autoSaveCTripRecord(){
cTripOrderRecordAutoSave.saveAll();
return Result.Success(SUCCESS);
}
}

View File

@ -129,7 +129,7 @@ public class LegEventHandler implements LegEventService {
String endTime = data.getEndTime();
if (startTime != null && endTime != null) {
if(startTime.contains("T") && endTime.contains("T")){
if (startTime.contains("T") && endTime.contains("T")) {
routeOrder.setStartTime(LocalDate.parse(startTime, formatterWithT).atStartOfDay());
routeOrder.setEndTime(LocalDate.parse(endTime, formatterWithT).atStartOfDay().plusHours(23).plusMinutes(59).plusSeconds(59));
} else {
@ -139,7 +139,8 @@ public class LegEventHandler implements LegEventService {
}
//保存routeOrder的状态
routeRepository.save(routeOrder);
RouteOrder save = routeRepository.save(routeOrder);
command.order(save);
} else if (routeOrder.getOrderStatus() > ORDER_STATUS_PREPARE) {
throw new CommandException(ORDER_STATUS_ERROR);
} else {

View File

@ -1,6 +1,6 @@
package com.chint.infrastructure.cache;
import com.chint.application.commands.OrderCreateCommand;
import com.chint.application.commands.OrderApprovalStartCommand;
import com.chint.domain.aggregates.order.ApproveOrderNo;
import com.chint.domain.aggregates.order.RouteOrder;
import com.chint.domain.aggregates.user.User;
@ -127,25 +127,21 @@ public class RouteCacheService {
public RouteOrder cacheRouteOrder(RouteOrder routeOrder) {
String approverId = routeOrder.getUserId();
String creatorId = routeOrder.getApproveOrderNo().getCreator();
String creatorId = null;
if (routeOrder.getApproveOrderNo() != null && routeOrder.getApproveOrderNo().getCreator() != null) {
creatorId = routeOrder.getApproveOrderNo().getCreator();
}
Long routeId = routeOrder.getRouteId();
// Update cache for both the approver and the creator
addRouteIdCacheForUser(approverId, routeId);
if (!approverId.equals(creatorId) && creatorId != null) { // Check to avoid duplicate updates for the same ID
if (creatorId != null && !approverId.equals(creatorId)) { // Check to avoid duplicate updates for the same ID
addRouteIdCacheForUser(creatorId, routeId);
}
// Cache the actual route order
return routeCacheManage.cacheRouteOrder(routeOrder);
}
@ListenTo(command = "OrderCreateCommand", order = 1)
public void addRouteIdWhenCreateRouteOrder(OrderCreateCommand command) {
}
public void addRouteIdCacheForUser(String userId, Long routeId) {
if (userId == null) return;
// Fetch, invalidate, and update the cache in an optimized manner if possible
@ -153,7 +149,7 @@ public class RouteCacheService {
if (routeIds == null || routeIds.size() <= 2) {
preloadUserRoutes(userId);
routeIds = routeCacheManage.getRouteIdsByEmployeeNo(userId, null, null);
if(routeIds == null){
if (routeIds == null) {
routeIds = new ArrayList<>();
}
}

View File

@ -35,7 +35,7 @@ public class JwtTokenAdminInterceptor implements HandlerInterceptor {
return dealWithClientInfo(token);
}
}
if (request.getRequestURI().contains("/pubilc")) {
if (request.getRequestURI().contains("/public")) {
return true;
}
if (token == null) {

View File

@ -95,10 +95,7 @@ public class RouteRepositoryImpl implements RouteRepository {
RouteOrder save = jdbcRouteRepository.save(routeOrder);
Long routeId = save.getRouteId();
routeCacheService.invalidateRouteCache(routeId);
//尝试为用户维护缓存
routeCacheService.addRouteIdCacheForUser(routeOrder.getUserId(), routeId);
routeCacheService.addRouteIdCacheForUser(routeOrder.getApproveOrderNo().getCreator(), routeId);
routeCacheService.cacheRouteOrder(save);
return save;
}

View File

@ -26,8 +26,14 @@ public class CTripOrderRecordAutoSave {
@Autowired
private CTripOrderDetailRepository cTripOrderDetailRepository;
// 每天晚上8点执行
@Scheduled(cron = "0 0 20 * * ?")
public void saveAll(){
this.cTripFlightRecordAutoSave();
this.cTripHotelRecordAutoSave();
this.cTripTrainRecordAutoSave();
this.cTripCarRecordAutoSave();
}
public void cTripFlightRecordAutoSave() {
OrderFlightResponse flightOrder = cTripOrderDetailRequest.getFlightOrder();
List<OrderFlightResponse.FlightOrderAccountSettlementInfo> flightOrderAccountSettlementList = flightOrder
@ -43,7 +49,7 @@ public class CTripOrderRecordAutoSave {
}
}
@Scheduled(cron = "0 0 20 * * ?")
public void cTripHotelRecordAutoSave() {
OrderHotelResponse hotelOrder = cTripOrderDetailRequest.getHotelOrder();
List<OrderHotelResponse.HotelAccountSettlementInfo> lstHtlSettlement = hotelOrder.getLstHtlSettlement();
@ -57,7 +63,7 @@ public class CTripOrderRecordAutoSave {
}
}
@Scheduled(cron = "0 0 20 * * ?")
public void cTripTrainRecordAutoSave() {
OrderTrainResponse trainOrder = cTripOrderDetailRequest.getTrainOrder();
List<OrderTrainResponse.CorpTrainAccountSettlement> lstTrainSettlement = trainOrder.getLstTrainSettlement();
@ -71,7 +77,7 @@ public class CTripOrderRecordAutoSave {
}
}
@Scheduled(cron = "0 0 20 * * ?")
public void cTripCarRecordAutoSave() {
OrderCarResponse carOrder = cTripOrderDetailRequest.getCarOrder();
List<OrderCarResponse.CarOrderAccountSettlementDetail> settlementList = carOrder.getCarOrderAccountSettlementList();

View File

@ -2,7 +2,10 @@ package com.chint;
import com.chint.domain.aggregates.order.RouteOrder;
import com.chint.infrastructure.cache.RouteCacheManage;
import com.chint.infrastructure.cache.RouteCacheService;
import com.chint.interfaces.rest.ctrip.CTripLocationHttpRequest;
import com.google.gson.Gson;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@ -16,6 +19,11 @@ public class CacheTest {
@Autowired
private RedisTemplate<String,RouteOrder> redisTemplate;
@Autowired
private RouteCacheService routeCacheService;
@Autowired
private RouteCacheManage routeCacheManage;
// @Test
public void getAllRouteOrderById(){
@ -25,4 +33,17 @@ public class CacheTest {
System.out.println(o);
}
}
@Test
public void getUserRouteIds(){
List<Long> ids = routeCacheManage.getRouteIdsByEmployeeNo("181026006" , null, null);
for (Long id : ids) {
System.out.println(id);
}
}
@Test
public void getRouteIdFromCache(){
RouteOrder routeById = routeCacheManage.getRouteById(1046L);
}
}