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