diff --git a/jsowell-admin/src/test/java/SpringBootTestController.java b/jsowell-admin/src/test/java/SpringBootTestController.java index b97e9a80a..6a2a36f81 100644 --- a/jsowell-admin/src/test/java/SpringBootTestController.java +++ b/jsowell-admin/src/test/java/SpringBootTestController.java @@ -283,6 +283,18 @@ public class SpringBootTestController { System.out.println(JSON.toJSONString(list)); } + @Test + public void testGeneratePileSn() { + // String key = CacheConstants.PILE_SN_GENERATE_KEY + "88"; + // redisCache.setCacheObject(key, null); + // Long pileNum = redisCache.getCacheLong(key); + // System.out.println(pileNum); + + snUtils.getPileSn("88"); + // List list = snUtils.generateSN(2); + // System.out.println(list); + } + @Test public void testGenerateOccupyPileOrder() { String memberId = "67569684"; diff --git a/jsowell-common/src/main/java/com/jsowell/common/core/redis/RedisCache.java b/jsowell-common/src/main/java/com/jsowell/common/core/redis/RedisCache.java index 8f135f55d..2a4aa935e 100644 --- a/jsowell-common/src/main/java/com/jsowell/common/core/redis/RedisCache.java +++ b/jsowell-common/src/main/java/com/jsowell/common/core/redis/RedisCache.java @@ -168,6 +168,9 @@ public class RedisCache { public Long getCacheLong(final String key) { Long l = null; Object cacheObject = getCacheObject(key); + if (Objects.isNull(cacheObject)) { + return null; + } if (cacheObject instanceof Integer) { l = ((Integer) cacheObject).longValue(); } else if (cacheObject instanceof Long) { diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/util/SnUtils.java b/jsowell-pile/src/main/java/com/jsowell/pile/util/SnUtils.java index 54f67961d..b496c0be4 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/util/SnUtils.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/util/SnUtils.java @@ -36,20 +36,22 @@ public class SnUtils { * @param prefix 生成序列号的前缀 * @return */ - private String getPileSn(String prefix) { + public String getPileSn(String prefix) { //序列号前缀加特定标识,如系统模块名之类的 防止重复 String key = CacheConstants.PILE_SN_GENERATE_KEY + prefix; String increResult = null; try { - String pileNum = redisCache.getCacheObject(key); - if (StringUtils.isBlank(pileNum)) { + // 取缓存 + Integer pileNum = redisCache.getCacheObject(key); + if (pileNum == null) { // 缓存中没有,从数据库中取 PileBasicInfo pileInfo = pileBasicInfoService.getMaxNumPileInfo(); String pileSn = pileInfo.getSn(); // 将前四位截取,并将后面转为long - long pileSnNum = Long.parseLong(StringUtils.substring(pileSn, 4, pileSn.length())); + Long pileSnNum = Long.parseLong(StringUtils.substring(pileSn, 4, pileSn.length())); + // String pileSnNum = StringUtils.substring(pileSn, 4, pileSn.length()); // 再将该值存入数据库 - redisCache.setCacheObject(key, pileSnNum); + redisCache.setCacheObject(key, pileSnNum.intValue()); } Long increNum = redisCache.increment(key, 1); @@ -64,11 +66,13 @@ public class SnUtils { } public static void main(String[] args) { - String pileSn = "88230000002060"; - String substring = StringUtils.substring(pileSn, 4, pileSn.length()); - long l = Long.parseLong(substring); - System.out.println(substring); - System.out.println(l); + // String pileSn = "88230000002060"; + // String substring = StringUtils.substring(pileSn, 4, pileSn.length()); + // long l = Long.parseLong(substring); + // System.out.println(substring); + // System.out.println(l); + + Long a = 3147483647L; } /** diff --git a/jsowell-pile/src/main/resources/mapper/pile/PileBasicInfoMapper.xml b/jsowell-pile/src/main/resources/mapper/pile/PileBasicInfoMapper.xml index 1087f3bad..3d1f595f5 100644 --- a/jsowell-pile/src/main/resources/mapper/pile/PileBasicInfoMapper.xml +++ b/jsowell-pile/src/main/resources/mapper/pile/PileBasicInfoMapper.xml @@ -402,9 +402,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" \ No newline at end of file