diff --git a/jsowell-admin/src/main/java/com/jsowell/service/PileService.java b/jsowell-admin/src/main/java/com/jsowell/service/PileService.java index 214b84151..cf82ef42f 100644 --- a/jsowell-admin/src/main/java/com/jsowell/service/PileService.java +++ b/jsowell-admin/src/main/java/com/jsowell/service/PileService.java @@ -16,7 +16,7 @@ import com.jsowell.common.exception.BusinessException; import com.jsowell.common.util.DateUtils; import com.jsowell.common.util.SecurityUtils; import com.jsowell.common.util.StringUtils; -import com.jsowell.common.util.id.SnUtils; +import com.jsowell.pile.util.SnUtils; import com.jsowell.pile.service.*; import com.jsowell.pile.domain.MemberBasicInfo; import com.jsowell.pile.domain.OrderBasicInfo; diff --git a/jsowell-admin/src/test/java/SpringBootTestController.java b/jsowell-admin/src/test/java/SpringBootTestController.java index 93ebf8af9..d451aa21b 100644 --- a/jsowell-admin/src/test/java/SpringBootTestController.java +++ b/jsowell-admin/src/test/java/SpringBootTestController.java @@ -34,7 +34,7 @@ import com.jsowell.common.util.*; import com.jsowell.common.util.Cp56Time2a.Cp56Time2aUtil; import com.jsowell.common.util.http.HttpUtils; import com.jsowell.common.util.id.IdUtils; -import com.jsowell.common.util.id.SnUtils; +import com.jsowell.pile.util.SnUtils; import com.jsowell.common.util.id.SnowflakeIdWorker; import com.jsowell.common.util.ip.AddressUtils; import com.jsowell.netty.handler.HeartbeatRequestHandler; diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/mapper/PileBasicInfoMapper.java b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/PileBasicInfoMapper.java index 742dab56a..af028c09a 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/mapper/PileBasicInfoMapper.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/mapper/PileBasicInfoMapper.java @@ -157,4 +157,10 @@ public interface PileBasicInfoMapper { * 批量修改充电桩运营商 */ void updatePileMerchantBatch(@Param("pileIdList") List pileIdList, @Param("newMerchantId") String newMerchantId); + + /** + * 获取最新一条桩的数据 + * @return + */ + PileBasicInfo getMaxNumPileInfo(); } diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/IPileBasicInfoService.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/IPileBasicInfoService.java index 5b1504579..b5353c21c 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/IPileBasicInfoService.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/IPileBasicInfoService.java @@ -177,4 +177,9 @@ public interface IPileBasicInfoService { * @return */ List getGroundLockInfo(String stationId); + + /** + * 获取最新建一条桩的信息 + */ + PileBasicInfo getMaxNumPileInfo(); } diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileBasicInfoServiceImpl.java b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileBasicInfoServiceImpl.java index 971f89722..2a8752368 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileBasicInfoServiceImpl.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/service/impl/PileBasicInfoServiceImpl.java @@ -788,4 +788,13 @@ public class PileBasicInfoServiceImpl implements IPileBasicInfoService { } return resultList; } + + /** + * 获取最新一条桩的数据 + * @return + */ + @Override + public PileBasicInfo getMaxNumPileInfo() { + return pileBasicInfoMapper.getMaxNumPileInfo(); + } } diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/id/SnUtils.java b/jsowell-pile/src/main/java/com/jsowell/pile/util/SnUtils.java similarity index 62% rename from jsowell-common/src/main/java/com/jsowell/common/util/id/SnUtils.java rename to jsowell-pile/src/main/java/com/jsowell/pile/util/SnUtils.java index eb072840b..54f67961d 100644 --- a/jsowell-common/src/main/java/com/jsowell/common/util/id/SnUtils.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/util/SnUtils.java @@ -1,8 +1,11 @@ -package com.jsowell.common.util.id; +package com.jsowell.pile.util; import com.google.common.collect.Lists; import com.jsowell.common.constant.CacheConstants; import com.jsowell.common.core.redis.RedisCache; +import com.jsowell.common.util.StringUtils; +import com.jsowell.pile.domain.PileBasicInfo; +import com.jsowell.pile.service.IPileBasicInfoService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -20,7 +23,10 @@ public class SnUtils { private static Logger logger = LoggerFactory.getLogger(SnUtils.class); @Autowired - public RedisCache redisCache; + private RedisCache redisCache; + + @Autowired + private IPileBasicInfoService pileBasicInfoService; private String prefix = "88"; @@ -35,6 +41,17 @@ public class SnUtils { String key = CacheConstants.PILE_SN_GENERATE_KEY + prefix; String increResult = null; try { + String pileNum = redisCache.getCacheObject(key); + if (StringUtils.isBlank(pileNum)) { + // 缓存中没有,从数据库中取 + PileBasicInfo pileInfo = pileBasicInfoService.getMaxNumPileInfo(); + String pileSn = pileInfo.getSn(); + // 将前四位截取,并将后面转为long + long pileSnNum = Long.parseLong(StringUtils.substring(pileSn, 4, pileSn.length())); + // 再将该值存入数据库 + redisCache.setCacheObject(key, pileSnNum); + + } Long increNum = redisCache.increment(key, 1); // 年份 int year = LocalDate.now().getYear() - 2000; @@ -46,7 +63,13 @@ public class SnUtils { return increResult; } - + 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); + } /** * 生成sn号 diff --git a/jsowell-pile/src/main/resources/mapper/pile/PileBasicInfoMapper.xml b/jsowell-pile/src/main/resources/mapper/pile/PileBasicInfoMapper.xml index 74d9862fe..1087f3bad 100644 --- a/jsowell-pile/src/main/resources/mapper/pile/PileBasicInfoMapper.xml +++ b/jsowell-pile/src/main/resources/mapper/pile/PileBasicInfoMapper.xml @@ -399,4 +399,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + \ No newline at end of file diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/amap/util/AMapUtils.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/amap/util/AMapUtils.java index 2a9823e05..faf413328 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/amap/util/AMapUtils.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/amap/util/AMapUtils.java @@ -1,7 +1,6 @@ package com.jsowell.thirdparty.amap.util; import com.alibaba.fastjson2.JSONObject; -import com.jsowell.common.util.id.SnUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value;