update 生成桩号缓存

This commit is contained in:
Lemon
2023-08-26 15:47:10 +08:00
parent a4df389c7d
commit 8b6b3b7d65
4 changed files with 33 additions and 11 deletions

View File

@@ -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<String> list = snUtils.generateSN(2);
// System.out.println(list);
}
@Test
public void testGenerateOccupyPileOrder() {
String memberId = "67569684";

View File

@@ -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) {

View File

@@ -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;
}
/**

View File

@@ -402,9 +402,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="getMaxNumPileInfo" resultMap="PileBasicInfoResult">
select
max(id),
id,
sn
from
pile_basic_info
order by
id desc
limit 1
</select>
</mapper>