Browse Source

feat(all): 修改工厂保存运单时重复的问题

dist.1.2.0^2
zhaoqiaobo 7 months ago
parent
commit
08fba6ef8a
  1. 81
      blade-service/logpm-factory/src/main/java/com/logpm/factory/pan/service/impl/PanFactoryDataServiceImpl.java

81
blade-service/logpm-factory/src/main/java/com/logpm/factory/pan/service/impl/PanFactoryDataServiceImpl.java

@ -9,8 +9,16 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.logpm.basic.entity.BasicMaterialEntity;
import com.logpm.basic.feign.IBasicMaterialClient;
import com.logpm.basicdata.entity.*;
import com.logpm.basicdata.feign.*;
import com.logpm.basicdata.entity.BasicdataBrandEntity;
import com.logpm.basicdata.entity.BasicdataCategoryEntity;
import com.logpm.basicdata.entity.BasicdataClientEntity;
import com.logpm.basicdata.entity.BasicdataStoreBusinessEntity;
import com.logpm.basicdata.entity.BasicdataWarehouseEntity;
import com.logpm.basicdata.feign.IBasicdataBrandClient;
import com.logpm.basicdata.feign.IBasicdataCategoryClient;
import com.logpm.basicdata.feign.IBasicdataClientClient;
import com.logpm.basicdata.feign.IBasicdataStoreBusinessClient;
import com.logpm.basicdata.feign.IBasicdataWarehouseClient;
import com.logpm.distribution.entity.DistributionParcelListEntity;
import com.logpm.distribution.entity.DistributionStockArticleEntity;
import com.logpm.distribution.feign.IDistributionParcelListClient;
@ -29,8 +37,23 @@ import com.logpm.factory.snm.bean.Resp;
import com.logpm.factory.snm.entity.PanFactoryOrder;
import com.logpm.factory.snm.entity.PanPackageInfo;
import com.logpm.factory.snm.entity.PanPackageList;
import com.logpm.oldproject.entity.*;
import com.logpm.oldproject.feign.*;
import com.logpm.oldproject.entity.AdvanceDetailEntity;
import com.logpm.oldproject.entity.AdvanceEntity;
import com.logpm.oldproject.entity.DetailProductEntity;
import com.logpm.oldproject.entity.OrderDetailEntity;
import com.logpm.oldproject.entity.TrayScanDesEntity;
import com.logpm.oldproject.entity.TrayScanEntity;
import com.logpm.oldproject.entity.WayBillEntity;
import com.logpm.oldproject.entity.WaybillDesEntity;
import com.logpm.oldproject.feign.IAdvanceClient;
import com.logpm.oldproject.feign.IAdvanceDetailClient;
import com.logpm.oldproject.feign.IDetailProductClient;
import com.logpm.oldproject.feign.IOrderDetailClient;
import com.logpm.oldproject.feign.ITrayScanClient;
import com.logpm.oldproject.feign.ITrayScanDesClient;
import com.logpm.oldproject.feign.IWarehouseClient;
import com.logpm.oldproject.feign.IWayBillClient;
import com.logpm.oldproject.feign.IWaybillDesClient;
import com.logpm.oldproject.vo.DistributionParcelListEntityVO;
import com.logpm.trunkline.entity.TrunklineAdvanceDetailEntity;
import com.logpm.trunkline.entity.TrunklineAdvanceEntity;
@ -47,13 +70,23 @@ import com.logpm.warehouse.feign.IWarehouseWaybillClient;
import com.logpm.warehouse.feign.IWarehouseWaybillDetailClient;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springblade.common.constant.TenantNum;
import org.springblade.common.constant.order.*;
import org.springblade.common.constant.orderpackage.*;
import org.springblade.common.constant.order.OrderFreezeStatusConstant;
import org.springblade.common.constant.order.OrderGroundingStatusConstant;
import org.springblade.common.constant.order.OrderReceiveStatusConstant;
import org.springblade.common.constant.order.OrderReservationStatusConstant;
import org.springblade.common.constant.order.OrderStatusConstant;
import org.springblade.common.constant.order.OrderStockupStatusConstant;
import org.springblade.common.constant.orderpackage.OrderPackageFreezeStatusConstant;
import org.springblade.common.constant.orderpackage.OrderPackageGroundingStatusConstant;
import org.springblade.common.constant.orderpackage.OrderPackageReservationStatusConstant;
import org.springblade.common.constant.orderpackage.OrderPackageStatusConstant;
import org.springblade.common.constant.orderpackage.OrderPackageStockupStatusConstant;
import org.springblade.common.exception.CustomerException;
import org.springblade.common.utils.CommonUtil;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.redis.lock.LockType;
import org.springblade.core.redis.lock.RedisLockClient;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.ObjectUtil;
@ -63,8 +96,12 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@Slf4j
@AllArgsConstructor
@ -114,6 +151,7 @@ public class PanFactoryDataServiceImpl implements IPanFactoryDataService {
private final BladeRedis redis;
private final RedisLockClient redisLockClient;
private final RedissonClient redissonClient;
private final IRegionFeign regionFeign;
private final IBasicdataBrandClient basicdataBrandClient;
@ -911,20 +949,17 @@ public class PanFactoryDataServiceImpl implements IPanFactoryDataService {
// log.info("###########saveWaybillEntity: 已有保存数据 waybillNo={}", waybillNo);
// return waybillId;
// }
String lockKey = "dealwithWaybillNo:" + waybillNo;
//通过运单号先去查询新系统是否存在这个运单号
WarehouseWaybillEntity warehouseWaybill = warehouseWaybillClient.findByWaybillNo(waybillNo);
String lockKey = "dealwithWaybillNo:lock:" + waybillNo;
Long aLong = null;
boolean flag = false;
RLock lock = redissonClient.getLock(lockKey);
try {
flag = redisLockClient.tryLock(lockKey, LockType.FAIR, 20000, 30000, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
if(flag){
//通过运单号先去查询新系统是否存在这个运单号
WarehouseWaybillEntity warehouseWaybill = warehouseWaybillClient.findByWaybillNo(waybillNo);
if (Objects.isNull(warehouseWaybill)) {
lock.lock();
warehouseWaybill = warehouseWaybillClient.findByWaybillNo(waybillNo);
log.info("#################handleDataToPlatform.warehouseWaybill: {}", warehouseWaybill);
if (Objects.isNull(warehouseWaybill)) {
redis.setEx("dealwithWaybillNo:" + waybillNo, waybillNo, 30L);
//如果新系统中不存在这个运单,那么就去查询老系统的运单数据
@ -1088,7 +1123,13 @@ public class PanFactoryDataServiceImpl implements IPanFactoryDataService {
}
//暂存单与运单的关联
saveAdvanceData(warehouseWaybill);
redisLockClient.unLock(lockKey, LockType.FAIR);
// redisLockClient.unLock(lockKey, LockType.FAIR);
}
} catch (Exception e) {
throw new RuntimeException(e);
}finally {
lock.unlock();
}
return aLong;
}

Loading…
Cancel
Save