Просмотр исходного кода

场景码生成 去掉内部锁

dsx 2 лет назад
Родитель
Сommit
887a6a3005

+ 19 - 28
src/main/java/com/fdkankan/contro/service/impl/Scene3dNumServiceImpl.java

@@ -49,7 +49,7 @@ public class Scene3dNumServiceImpl extends ServiceImpl<IScene3dNumMapper, Scene3
     private int cachePageSize;
     @Value("${scene.num.threshold:10000}")
     private int threshold;
-    @Value("${scene.num.prefix:V4-}")
+    @Value("${scene.num.prefix}")
     private String numPrefix;
     @Value("${scene.num.batchSize:100}")
     private int batchSize;
@@ -106,35 +106,26 @@ public class Scene3dNumServiceImpl extends ServiceImpl<IScene3dNumMapper, Scene3
 
     @Override
     public void batchCreateSceneNum(boolean force) {
-        String lockKey = String.format(RedisLockKey.LOCK_BATCH_CREATE_NUM);
-        boolean lock = redisLockUtil.lock(lockKey, RedisKey.EXPIRE_TIME_10_MINUTE);
-        if(!lock){
-            return;
-        }
-        try {
-            if (!force) {
-                long count = this.count(new LambdaQueryWrapper<Scene3dNum>().eq(Scene3dNum::getUsed, CommonStatus.NO.code()));
-                if (count > threshold) {
-                    return;
-                }
+        if (!force) {
+            long count = this.count(new LambdaQueryWrapper<Scene3dNum>().eq(Scene3dNum::getUsed, CommonStatus.NO.code()));
+            if (count > threshold) {
+                return;
             }
-            int batchCnt = threshold / batchSize + (threshold % batchSize > 0 ? 1 : 0);
-            for (int i = 0; i < batchCnt; i++){
-                Set<String> numSet = this.turnCreateSceneNum(batchSize);
-                List<Scene3dNum> scene3dNumList = numSet.parallelStream().map(num -> {
-                    Scene3dNum scene3dNum = new Scene3dNum();
-                    scene3dNum.setNum(num);
-                    return scene3dNum;
-                }).collect(Collectors.toList());
-                try{
-                    this.saveBatch(scene3dNumList);
-                }catch (Exception e){
-                    log.error("场景码插入异常!");
-                    e.printStackTrace();
-                }
+        }
+        int batchCnt = threshold / batchSize + (threshold % batchSize > 0 ? 1 : 0);
+        for (int i = 0; i < batchCnt; i++){
+            Set<String> numSet = this.turnCreateSceneNum(batchSize);
+            List<Scene3dNum> scene3dNumList = numSet.parallelStream().map(num -> {
+                Scene3dNum scene3dNum = new Scene3dNum();
+                scene3dNum.setNum(num);
+                return scene3dNum;
+            }).collect(Collectors.toList());
+            try{
+                this.saveBatch(scene3dNumList);
+            }catch (Exception e){
+                log.error("场景码插入异常!");
+                e.printStackTrace();
             }
-        }finally {
-            redisLockUtil.unlockLua(lockKey);
         }
     }