src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/zy/common/config/RedisConfig.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/zy/common/constant/RedisConstantType.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/zy/common/utils/RedisUtil.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -14,6 +14,7 @@ import com.zy.asrs.service.*; import com.zy.asrs.utils.Utils; import com.zy.asrs.utils.VersionUtils; import com.zy.common.constant.RedisConstantType; import com.zy.common.model.LocTypeDto; import com.zy.common.model.MatDto; import com.zy.common.model.SearchLocParam; @@ -22,6 +23,7 @@ import com.zy.common.utils.CollectionUtils; import com.zy.common.utils.HttpHandler; import com.zy.common.utils.News; import com.zy.common.utils.RedisUtil; import com.zy.core.CrnThread; import com.zy.core.DevpThread; import com.zy.core.cache.MessageQueue; @@ -95,6 +97,8 @@ private WrkMastLogService wrkMastLogService; @Autowired private ConfigService configService; @Autowired private RedisUtil redisUtil; @Value("${wms.url}") private String wmsUrl; @@ -656,6 +660,11 @@ continue; } Object object = redisUtil.get(RedisConstantType.CRN_MOVE_LOCK); if (object != null) { continue; } List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>() .eq("crn_no", crn.getId())); if (!wrkMasts.isEmpty()) { @@ -681,6 +690,8 @@ News.error("堆垛机移动命令下发失败,堆垛机号={},任务数据={}", crnProtocol.getCrnNo(), JSON.toJSON(crnCommand)); } crnThread.setBackHpFlag(true); redisUtil.set(RedisConstantType.CRN_MOVE_LOCK + crn.getId(), "lock", 60); } } } src/main/java/com/zy/common/config/RedisConfig.java
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.cache.annotation.CachingConfigurerSupport; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.core.*; import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; @@ -14,7 +15,7 @@ * Redis配置类 * Created by vincent on 2019-12-23 */ //@Configuration @Configuration //@EnableCaching // 开启数据缓存机制 public class RedisConfig extends CachingConfigurerSupport { src/main/java/com/zy/common/constant/RedisConstantType.java
New file @@ -0,0 +1,7 @@ package com.zy.common.constant; public class RedisConstantType { public static final String CRN_MOVE_LOCK = "CRN_MOVE_LOCK_"; } src/main/java/com/zy/common/utils/RedisUtil.java
@@ -2,8 +2,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; @@ -13,13 +15,20 @@ * redisTemplate封装 * */ //@Component @Component public class RedisUtil { @Autowired private RedisTemplate<String, Object> redisTemplate; // @Autowired // private RedisTemplate<String, Object> redisTemplate; public RedisUtil(RedisTemplate<String, Object> redisTemplate) { @Autowired private RedisTemplate redisTemplate; public RedisTemplate getRedisTemplate() { return redisTemplate; } public RedisUtil(RedisTemplate redisTemplate) { this.redisTemplate = redisTemplate; } @@ -96,6 +105,21 @@ } /** * 获取全部数据 * @return */ public HashMap<Object, Object> getRedis() { Set<String> keys = redisTemplate.keys("*"); HashMap<Object, Object> map = new HashMap<>(); for (String key : keys) { Object value = redisTemplate.opsForValue().get(key); map.put(key, value); } return map;//返回全部数据集合 } /** * 普通缓存放入 * * @param key 键 @@ -105,6 +129,34 @@ public boolean set(String key, Object value) { try { redisTemplate.opsForValue().set(key, value); long start = System.currentTimeMillis(); while (System.currentTimeMillis() - start < 10000) {//有效期10s Object o = redisTemplate.opsForValue().get(key); if (o == null) { continue; } if (o.equals(value)) { break; } } return true; } catch (Exception e) { e.printStackTrace(); return false; } } /** * 普通缓存放入-异步 * * @param key 键 * @param value 值 * @return true成功 false失败 */ public boolean setAsync(String key, Object value) { try { redisTemplate.opsForValue().set(key, value); return true; } catch (Exception e) { e.printStackTrace();