提交 6b040855 authored 作者: huyufan's avatar huyufan

修改bug 货单编号生成

上级 e802a68e
...@@ -33,40 +33,41 @@ public class OrderGoodsIdGenerate { ...@@ -33,40 +33,41 @@ public class OrderGoodsIdGenerate {
public long getOrderGoodsId(Integer size) { public long getOrderGoodsId(Integer size) {
long baseStart = Long.parseLong(DateUtils.formatDate(LocalDate.now(), "yyyyMMdd").get() + "00001");
Object o = redisTemplate.opsForValue().get(RedisConstants.ORDER_GOODS_ID_GENERATE);
if (o == null) {
RLock rLock = null; RLock rLock = null;
try { try {
rLock = redissonClient.getLock(RedisConstants.ORDER_NO_BLOCK + type); rLock = redissonClient.getLock(RedisConstants.ORDER_NO_BLOCK + type);
rLock.lock(5, TimeUnit.SECONDS); rLock.lock(5, TimeUnit.SECONDS);
long baseStart = Long.parseLong(DateUtils.formatDate(LocalDate.now(), "yyyyMMdd").get() + "00001"); o = redisTemplate.opsForValue().get(RedisConstants.ORDER_GOODS_ID_GENERATE);
Object o = redisTemplate.opsForHash().get(RedisConstants.ORDER_GOODS_ID, type);
if (o == null) { if (o == null) {
Long maxOrderGoodsId = null; Long maxOrderGoodsId = null;
String maxID = orderGoodsDao.getMaxOrderGoodsId(type); String maxID = orderGoodsDao.getMaxOrderGoodsId();
if (StringUtils.isNotBlank(maxID)) { if (StringUtils.isNotBlank(maxID)) {
maxOrderGoodsId = Long.valueOf(maxID.substring(2)); maxOrderGoodsId = Long.valueOf(maxID.substring(2));
} }
if (maxOrderGoodsId == null) { if (maxOrderGoodsId == null) {
maxOrderGoodsId = 0L; maxOrderGoodsId = baseStart;
} }
if (baseStart > maxOrderGoodsId) { if (baseStart == maxOrderGoodsId) {
redisTemplate.opsForHash().put(RedisConstants.ORDER_GOODS_ID, type, String.valueOf(baseStart + size)); redisTemplate.opsForValue().increment(RedisConstants.ORDER_GOODS_ID_GENERATE, size);
return baseStart; return baseStart;
} else { } else {
long orderGoodsId = maxOrderGoodsId + size; redisTemplate.opsForValue().increment(RedisConstants.ORDER_GOODS_ID_GENERATE, size);
redisTemplate.opsForHash().put(RedisConstants.ORDER_GOODS_ID, type, String.valueOf(orderGoodsId)); return maxOrderGoodsId;
return maxOrderGoodsId + 1;
} }
} else { } else {
long redisOrderGoodsId = Long.parseLong(o.toString()); long redisOrderGoodsId = Long.parseLong(o.toString());
if (redisOrderGoodsId < baseStart) { if (redisOrderGoodsId < baseStart) {
redisOrderGoodsId = baseStart; redisOrderGoodsId = baseStart;
} }
long orderGoodsId = redisOrderGoodsId + size;
redisTemplate.opsForHash().put(RedisConstants.ORDER_GOODS_ID, type, String.valueOf(orderGoodsId)); redisTemplate.opsForValue().increment(RedisConstants.ORDER_GOODS_ID_GENERATE, size);
return redisOrderGoodsId; return redisOrderGoodsId;
} }
} catch (Exception e) { } catch (Exception e) {
throw new ServiceSystemException(PerformanceResultEnum.ORDER_GOODS_ID_GENERATE_LOCK, e.getMessage()); throw new ServiceSystemException(PerformanceResultEnum.ORDER_GOODS_ID_GENERATE_LOCK, e.getMessage());
...@@ -80,6 +81,17 @@ public class OrderGoodsIdGenerate { ...@@ -80,6 +81,17 @@ public class OrderGoodsIdGenerate {
log.error("redis 货单ID生成 分布式锁释放异常!", e); log.error("redis 货单ID生成 分布式锁释放异常!", e);
} }
} }
} else {
long redisOrderGoodsId = Long.parseLong(o.toString());
if (redisOrderGoodsId < baseStart) {
redisOrderGoodsId = baseStart;
}
redisTemplate.opsForValue().increment(RedisConstants.ORDER_GOODS_ID_GENERATE, size);
return redisOrderGoodsId;
}
} }
} }
...@@ -6,7 +6,7 @@ public class RedisConstants { ...@@ -6,7 +6,7 @@ public class RedisConstants {
public static final String ORDER_GOODS_ID ="clx-performance:orderGoodsId:"; public static final String ORDER_GOODS_ID ="clx-performance:orderGoodsId:";
public static final String ORDER_GOODS_ID_GENERATE ="clx-performance:orderGoodsId:generate";
public static final String ZJXL_TRUCK_TRACE_LIST = "clx-performance:zjxl_truck_trace_list:"; public static final String ZJXL_TRUCK_TRACE_LIST = "clx-performance:zjxl_truck_trace_list:";
......
...@@ -24,7 +24,7 @@ import java.util.List; ...@@ -24,7 +24,7 @@ import java.util.List;
public interface OrderGoodsDao extends BaseDao<OrderGoodsMapper, OrderGoods, Integer> { public interface OrderGoodsDao extends BaseDao<OrderGoodsMapper, OrderGoods, Integer> {
boolean updateWeight(@Param("orderId")Integer orderId, @Param("weight") BigDecimal weight); boolean updateWeight(@Param("orderId")Integer orderId, @Param("weight") BigDecimal weight);
String getMaxOrderGoodsId(String type); String getMaxOrderGoodsId();
Optional<OrderGoods> getByOrderGoodsNo(String orderGoodsNo); Optional<OrderGoods> getByOrderGoodsNo(String orderGoodsNo);
......
...@@ -35,8 +35,8 @@ public class OrderGoodsDaoImpl extends BaseDaoImpl<OrderGoodsMapper, OrderGoods, ...@@ -35,8 +35,8 @@ public class OrderGoodsDaoImpl extends BaseDaoImpl<OrderGoodsMapper, OrderGoods,
} }
@Override @Override
public String getMaxOrderGoodsId(String type) { public String getMaxOrderGoodsId() {
return baseMapper.getMaxOrderGoodsId(type); return baseMapper.getMaxOrderGoodsId();
} }
@Override @Override
......
...@@ -29,7 +29,7 @@ public interface OrderGoodsMapper extends BaseMapper<OrderGoods> { ...@@ -29,7 +29,7 @@ public interface OrderGoodsMapper extends BaseMapper<OrderGoods> {
int updateWeight(@Param("orderId") Integer orderId, @Param("weight") BigDecimal weight); int updateWeight(@Param("orderId") Integer orderId, @Param("weight") BigDecimal weight);
@SelectProvider(type = OrderGoodsSqlProvider.class, method = "getMaxOrderGoodsId") @SelectProvider(type = OrderGoodsSqlProvider.class, method = "getMaxOrderGoodsId")
String getMaxOrderGoodsId(String type); String getMaxOrderGoodsId();
@SelectProvider(type = OrderGoodsSqlProvider.class, method = "pageOrderGoodsList") @SelectProvider(type = OrderGoodsSqlProvider.class, method = "pageOrderGoodsList")
IPage<OrderGoodsVO> pageOrderGoodsList(Page<OrderGoodsVO> page, PageOrderGoodsListParam param); IPage<OrderGoodsVO> pageOrderGoodsList(Page<OrderGoodsVO> page, PageOrderGoodsListParam param);
......
...@@ -16,7 +16,6 @@ public class OrderGoodsSqlProvider { ...@@ -16,7 +16,6 @@ public class OrderGoodsSqlProvider {
public String getMaxOrderGoodsId(String type) { public String getMaxOrderGoodsId(String type) {
return "SELECT s.order_goods_no FROM `order_goods` s WHERE s. id = ( SELECT max(id) FROM order_goods )"; return "SELECT s.order_goods_no FROM `order_goods` s WHERE s. id = ( SELECT max(id) FROM order_goods )";
// return "SELECT s.order_goods_no FROM `order_goods` s WHERE s. id = ( SELECT max(id) FROM order_goods where order_goods_type = '" + type + "')";
} }
public String pageOrderGoodsList(@Param("param") PageOrderGoodsListParam param) { public String pageOrderGoodsList(@Param("param") PageOrderGoodsListParam param) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论