瀏覽代碼

首次提交

龙伟 1 年之前
父節點
當前提交
c08e3c2216

+ 1 - 1
ruoyi-common/src/main/java/com/ruoyi/common/constant/CacheConstants.java

@@ -57,6 +57,6 @@ public class CacheConstants {
     /**
      * 装机成本 redis key
      */
-    public static final String INSTALLATION_COST_TASK_NO = "installation_cost_task_no:";
+    public static final String INSTALLATION_COST = "installation_cost";
 
 }

+ 5 - 7
summary/src/main/java/com/ruoyi/projetctCost/run/InstallationCostSummaryCallable.java

@@ -44,10 +44,8 @@ public class InstallationCostSummaryCallable implements Callable<Boolean> {
         IMesInfoService mesInfoService = serviceBeenFactory.getMesInfoService();
         List<MesInfo> mesInfos = mesInfoService.selectMesInfoByKeyIdRange(startId, endId);
         for (int i = 0; i < mesInfos.size(); i++) {
-            log.info(""+i);
             MesInfo mesInfo = mesInfos.get(i);
             String taskno = mesInfo.getTaskno();
-            log.info(taskno);
             while (value.equals(mark)) {
                 value = redisLockMethodUtil.redisCacheTaskNoLock(taskno, uuid, redisCache);
             }
@@ -63,11 +61,11 @@ public class InstallationCostSummaryCallable implements Callable<Boolean> {
 
             boolean bool = redisLockMethodUtil.redisCacheTaskNoUnlock(taskno, uuid, value, redisCache);
 
-//            if (!bool) {
-//                if (record == 3) return false;
-//                i--;
-//                record += 1;
-//            }
+            if (!bool) {
+                if (record == 3) return false;
+                i--;
+                record += 1;
+            }
             value = BigDecimal.valueOf(-1);
         }
         return true;

+ 24 - 10
summary/src/main/java/com/ruoyi/projetctCost/util/RedisLockMethodUtil.java

@@ -36,21 +36,33 @@ public class RedisLockMethodUtil {
         lock.lock();
         BigDecimal value = BigDecimal.valueOf(0);
         try {
-            String cacheStringUUID = (String) redisCache.getCacheMapValue(CacheConstants.INSTALLATION_COST_TASK_NO + taskNo, CacheConstants.UUID);
+            Map<String, Object> cacheMap = redisCache.getCacheMapValue(CacheConstants.INSTALLATION_COST, taskNo);
+
+            String cacheStringUUID = null;
+            if (cacheMap != null) {
+                cacheStringUUID = (String) cacheMap.get(CacheConstants.UUID);
+            }
             UUID cacheUUID = null;
             if (cacheStringUUID != null) {
                 cacheUUID = UUID.fromString(cacheStringUUID);
             }
+
             if (ObjectUtils.isEmpty(cacheUUID) || Objects.equals(cacheUUID, new UUID(0L, 0L))) {
-                redisCache.setCacheMapValue(CacheConstants.INSTALLATION_COST_TASK_NO + taskNo, CacheConstants.UUID, uuid);
+                HashMap<String, Object> cache = new HashMap<>();
+                cache.put(CacheConstants.UUID, uuid);
+                redisCache.setCacheMapValue(CacheConstants.INSTALLATION_COST, taskNo, cache);
             }
-            Map<String, Object> cacheMap = redisCache.getCacheMap(CacheConstants.INSTALLATION_COST_TASK_NO + taskNo);
-            String stringUUID = (String) cacheMap.get(CacheConstants.UUID);
+
+            Map<String, Object> taskNoMap = redisCache.getCacheMapValue(CacheConstants.INSTALLATION_COST, taskNo);
+
+            String stringUUID = (String) taskNoMap.get(CacheConstants.UUID);
             UUID redisCacheUUID = UUID.fromString(stringUUID);
-            BigDecimal cacheValue = (BigDecimal) cacheMap.get(CacheConstants.VALUE);
+            BigDecimal cacheValue = (BigDecimal) taskNoMap.get(CacheConstants.VALUE);
+
             if (Objects.equals(redisCacheUUID, uuid)) {
                 if (Objects.isNull(cacheValue)) {
-                    redisCache.setCacheMapValue(CacheConstants.INSTALLATION_COST_TASK_NO + taskNo, CacheConstants.VALUE, value);
+                    taskNoMap.put(CacheConstants.VALUE, value);
+                    redisCache.setCacheMapValue(CacheConstants.INSTALLATION_COST, taskNo, taskNoMap);
                 } else {
                     value = cacheValue;
                 }
@@ -64,13 +76,15 @@ public class RedisLockMethodUtil {
     }
 
     public boolean redisCacheTaskNoUnlock(String taskNo, UUID uuid, BigDecimal value, RedisCache redisCache) {
-        String cacheStrUUID = (String) redisCache.getCacheMapValue(CacheConstants.INSTALLATION_COST_TASK_NO + taskNo, CacheConstants.UUID);
-        if (ObjectUtils.isEmpty(cacheStrUUID)) return false;
+        HashMap<String, Object> cacheMap = redisCache.getCacheMapValue(CacheConstants.INSTALLATION_COST, taskNo);
+        if (ObjectUtils.isEmpty(cacheMap)) return false;
 
-        HashMap<String, Object> cacheMap = new HashMap<>();
+        String stringUUID = (String) cacheMap.get(CacheConstants.UUID);
+        UUID cacheUUID = UUID.fromString(stringUUID);
+        if (ObjectUtils.isEmpty(cacheUUID) || !Objects.equals(uuid, cacheUUID)) return false;
         cacheMap.put(CacheConstants.UUID, new UUID(0L, 0L));
         cacheMap.put(CacheConstants.VALUE, value);
-        redisCache.setCacheMap(CacheConstants.INSTALLATION_COST_TASK_NO + taskNo, cacheMap);
+        redisCache.setCacheMapValue(CacheConstants.INSTALLATION_COST, taskNo,cacheMap);
         return true;
     }
 }