From 6017ff0fac73ee771282f8c4711f20ec9ca67bd7 Mon Sep 17 00:00:00 2001 From: Junjie <fallin.jie@qq.com> Date: 星期二, 07 十一月 2023 08:54:13 +0800 Subject: [PATCH] #Redis Key Type --- src/main/java/com/zy/core/thread/LiftThread.java | 8 ++-- src/main/java/com/zy/asrs/controller/ConsoleController.java | 7 ++- src/main/java/com/zy/asrs/task/RealtimeBasMapScheduler.java | 3 + src/main/java/com/zy/common/utils/NavigateMapUtils.java | 5 +- src/main/java/com/zy/asrs/controller/ShuttleController.java | 20 ++++----- src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java | 8 ++-- src/main/java/com/zy/core/thread/NyShuttleThread.java | 18 ++++----- src/main/java/com/zy/core/enums/RedisKeyType.java | 15 +++++++ src/main/java/com/zy/common/utils/NavigateMapData.java | 3 + src/main/java/com/zy/asrs/controller/LiftController.java | 17 ++++---- 10 files changed, 60 insertions(+), 44 deletions(-) diff --git a/src/main/java/com/zy/asrs/controller/ConsoleController.java b/src/main/java/com/zy/asrs/controller/ConsoleController.java index a88397f..3c08969 100644 --- a/src/main/java/com/zy/asrs/controller/ConsoleController.java +++ b/src/main/java/com/zy/asrs/controller/ConsoleController.java @@ -27,6 +27,7 @@ import com.zy.core.cache.OutputQueue; import com.zy.core.cache.SlaveConnection; import com.zy.core.enums.CrnModeType; +import com.zy.core.enums.RedisKeyType; import com.zy.core.enums.SlaveType; import com.zy.core.model.CrnSlave; import com.zy.core.model.DevpSlave; @@ -312,7 +313,7 @@ @GetMapping("/map/{lev}/auth") @ManagerAuth public R getMapFromRedis(@PathVariable Integer lev) { - Object data = redisUtil.get("realtimeBasMap_" + lev); + Object data = redisUtil.get(RedisKeyType.MAP.key + lev); if (data == null) { return R.error(); } @@ -401,7 +402,7 @@ } //灏嗘暟鎹簱鍦板浘鏁版嵁瀛樺叆redis - redisUtil.set("realtimeBasMap_" + i, JSON.toJSONString(basMap)); + redisUtil.set(RedisKeyType.MAP.key + i, JSON.toJSONString(basMap)); } return R.ok(); } @@ -436,7 +437,7 @@ } //灏嗘暟鎹簱鍦板浘鏁版嵁瀛樺叆redis - redisUtil.set("realtimeBasMap_" + lev, JSON.toJSONString(basMap)); + redisUtil.set(RedisKeyType.MAP.key + lev, JSON.toJSONString(basMap)); return R.ok(); } diff --git a/src/main/java/com/zy/asrs/controller/LiftController.java b/src/main/java/com/zy/asrs/controller/LiftController.java index 50f8d46..9249c42 100644 --- a/src/main/java/com/zy/asrs/controller/LiftController.java +++ b/src/main/java/com/zy/asrs/controller/LiftController.java @@ -19,6 +19,7 @@ import com.zy.core.cache.SlaveConnection; import com.zy.core.enums.LiftProtocolStatusType; import com.zy.core.enums.NyLiftTaskModelType; +import com.zy.core.enums.RedisKeyType; import com.zy.core.enums.SlaveType; import com.zy.core.model.LiftSlave; import com.zy.core.model.Task; @@ -299,7 +300,7 @@ @RequestMapping(value = "/command/query") public R liftCommandQuery(@RequestParam("wrkNo") Integer wrkNo) { - Object o = redisUtil.get("lift_wrk_no_" + wrkNo); + Object o = redisUtil.get(RedisKeyType.LIFT.key + wrkNo); if (o == null) { return R.error(); } @@ -311,13 +312,13 @@ @RequestMapping(value = "/command/rollback") public R liftCommandRollback(@RequestParam("wrkNo") Integer wrkNo , @RequestParam("commandStep") Integer commandStep) { - Object o = redisUtil.get("lift_wrk_no_" + wrkNo); + Object o = redisUtil.get(RedisKeyType.LIFT.key + wrkNo); if (o == null) { return R.error(); } LiftRedisCommand redisCommand = JSON.parseObject(o.toString(), LiftRedisCommand.class); redisCommand.setCommandStep(commandStep); - redisUtil.set("lift_wrk_no_" + wrkNo, JSON.toJSONString(redisCommand)); + redisUtil.set(RedisKeyType.LIFT.key + wrkNo, JSON.toJSONString(redisCommand)); return R.ok(); } @@ -326,7 +327,7 @@ public R liftCommandCompleteSwitch(@RequestParam("wrkNo") Integer wrkNo , @RequestParam("commandStep") Integer commandStep , @RequestParam("complete") Integer complete) { - Object o = redisUtil.get("lift_wrk_no_" + wrkNo); + Object o = redisUtil.get(RedisKeyType.LIFT.key + wrkNo); if (o == null) { return R.error(); } @@ -335,14 +336,14 @@ List<NyLiftCommand> commands = assignCommand.getCommands(); NyLiftCommand command = commands.get(commandStep); command.setComplete(complete != 0); - redisUtil.set("lift_wrk_no_" + wrkNo, JSON.toJSONString(redisCommand)); + redisUtil.set(RedisKeyType.LIFT.key + wrkNo, JSON.toJSONString(redisCommand)); return R.ok(); } //閲嶅惎浠诲姟(鍛戒护) @RequestMapping(value = "/command/restart") public R liftCommandCompleteSwitch(@RequestParam("wrkNo") Integer wrkNo) { - Object o = redisUtil.get("lift_wrk_no_" + wrkNo); + Object o = redisUtil.get(RedisKeyType.LIFT.key + wrkNo); if (o == null) { return R.error(); } @@ -368,11 +369,11 @@ //鍒犻櫎浠诲姟(鍛戒护) @RequestMapping(value = "/command/del") public R liftCommandDel(@RequestParam("wrkNo") Integer wrkNo) { - Object o = redisUtil.get("lift_wrk_no_" + wrkNo); + Object o = redisUtil.get(RedisKeyType.LIFT.key + wrkNo); if (o == null) { return R.error(); } - redisUtil.del("lift_wrk_no_" + wrkNo); + redisUtil.del(RedisKeyType.LIFT.key + wrkNo); return R.ok(); } diff --git a/src/main/java/com/zy/asrs/controller/ShuttleController.java b/src/main/java/com/zy/asrs/controller/ShuttleController.java index d2f0e51..18777ea 100644 --- a/src/main/java/com/zy/asrs/controller/ShuttleController.java +++ b/src/main/java/com/zy/asrs/controller/ShuttleController.java @@ -2,12 +2,10 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.core.annotations.ManagerAuth; import com.core.common.BaseRes; import com.core.common.Cools; import com.core.common.R; -import com.core.common.SpringUtils; import com.core.exception.CoolException; import com.zy.asrs.domain.param.ShuttleOperatorParam; import com.zy.asrs.domain.vo.*; @@ -94,7 +92,7 @@ shuttleData.put("moveAdvancePath", null);//绌挎杞﹂璁¤矾寰� if (shuttleProtocol.getTaskNo() != 0) { //瀛樺湪浠诲姟锛岃幏鍙栨寚浠� - Object object = redisUtil.get("shuttle_wrk_no_" + shuttleProtocol.getTaskNo()); + Object object = redisUtil.get(RedisKeyType.SHUTTLE.key + shuttleProtocol.getTaskNo()); if (object != null) { ShuttleRedisCommand redisCommand = JSON.parseObject(object.toString(), ShuttleRedisCommand.class); shuttleData.put("moveAdvancePath", redisCommand.getAssignCommand().getNodes());//绌挎杞﹂璁¤矾寰� @@ -186,7 +184,7 @@ @RequestMapping(value = "/command/query") public R shuttleCommandQuery(@RequestParam("wrkNo") Integer wrkNo) { - Object o = redisUtil.get("shuttle_wrk_no_" + wrkNo); + Object o = redisUtil.get(RedisKeyType.SHUTTLE.key + wrkNo); if (o == null) { return R.error(); } @@ -198,13 +196,13 @@ @RequestMapping(value = "/command/rollback") public R shuttleCommandRollback(@RequestParam("wrkNo") Integer wrkNo , @RequestParam("commandStep") Integer commandStep) { - Object o = redisUtil.get("shuttle_wrk_no_" + wrkNo); + Object o = redisUtil.get(RedisKeyType.SHUTTLE.key + wrkNo); if (o == null) { return R.error(); } ShuttleRedisCommand redisCommand = JSON.parseObject(o.toString(), ShuttleRedisCommand.class); redisCommand.setCommandStep(commandStep); - redisUtil.set("shuttle_wrk_no_" + wrkNo, JSON.toJSONString(redisCommand)); + redisUtil.set(RedisKeyType.SHUTTLE.key + wrkNo, JSON.toJSONString(redisCommand)); return R.ok(); } @@ -213,7 +211,7 @@ public R shuttleCommandCompleteSwitch(@RequestParam("wrkNo") Integer wrkNo , @RequestParam("commandStep") Integer commandStep , @RequestParam("complete") Integer complete) { - Object o = redisUtil.get("shuttle_wrk_no_" + wrkNo); + Object o = redisUtil.get(RedisKeyType.SHUTTLE.key + wrkNo); if (o == null) { return R.error(); } @@ -222,14 +220,14 @@ List<NyShuttleHttpCommand> commands = assignCommand.getCommands(); NyShuttleHttpCommand command = commands.get(commandStep); command.setComplete(complete != 0); - redisUtil.set("shuttle_wrk_no_" + wrkNo, JSON.toJSONString(redisCommand)); + redisUtil.set(RedisKeyType.SHUTTLE.key + wrkNo, JSON.toJSONString(redisCommand)); return R.ok(); } //閲嶅惎浠诲姟(鍛戒护) @RequestMapping(value = "/command/restart") public R shuttleCommandCompleteSwitch(@RequestParam("wrkNo") Integer wrkNo) { - Object o = redisUtil.get("shuttle_wrk_no_" + wrkNo); + Object o = redisUtil.get(RedisKeyType.SHUTTLE.key + wrkNo); if (o == null) { return R.error(); } @@ -255,11 +253,11 @@ //鍒犻櫎浠诲姟(鍛戒护) @RequestMapping(value = "/command/del") public R liftCommandDel(@RequestParam("wrkNo") Integer wrkNo) { - Object o = redisUtil.get("shuttle_wrk_no_" + wrkNo); + Object o = redisUtil.get(RedisKeyType.SHUTTLE.key + wrkNo); if (o == null) { return R.error(); } - redisUtil.del("shuttle_wrk_no_" + wrkNo); + redisUtil.del(RedisKeyType.SHUTTLE.key + wrkNo); return R.ok(); } diff --git a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java index f7ef1d0..f32b182 100644 --- a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java +++ b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java @@ -634,7 +634,7 @@ */ public synchronized void initRealtimeBasMap() { for (int i = 1; i <= 10; i++) {//鎬诲叡鍥涘眰妤� - Object data = redisUtil.get("realtimeBasMap_" + i); + Object data = redisUtil.get(RedisKeyType.MAP.key + i); if (data == null) {//redis鍦板浘鏁版嵁涓虹┖锛屼粠鏁版嵁搴撲腑鑾峰彇 BasMap basMap = basMapService.selectLatestMap(i); if (basMap == null) { @@ -656,7 +656,7 @@ } //灏嗘暟鎹簱鍦板浘鏁版嵁瀛樺叆redis - redisUtil.set("realtimeBasMap_" + i, JSON.toJSONString(basMap)); + redisUtil.set(RedisKeyType.MAP.key + i, JSON.toJSONString(basMap)); } } } @@ -667,7 +667,7 @@ public synchronized void restartTaskFromRedis() { HashMap<Object, Object> map = redisUtil.getRedis(); for (Object key : map.keySet()) { - if (key.toString().contains("lift_wrk_no_")) {//鎻愬崌鏈轰换鍔� + if (key.toString().contains(RedisKeyType.LIFT.key)) {//鎻愬崌鏈轰换鍔� LiftRedisCommand redisCommand = JSON.parseObject(map.get(key).toString(), LiftRedisCommand.class); if (redisCommand == null) { continue; @@ -690,7 +690,7 @@ liftProtocol.setTaskNo(redisCommand.getWrkNo());//灏嗘彁鍗囨満绾跨▼鍒嗛厤浠诲姟鍙� liftProtocol.setProtocolStatus(LiftProtocolStatusType.WORKING);//宸ヤ綔鐘舵�� - }else if(key.toString().contains("shuttle_wrk_no_")){//鍥涘悜绌挎杞︿换鍔� + }else if(key.toString().contains(RedisKeyType.SHUTTLE.key)){//鍥涘悜绌挎杞︿换鍔� ShuttleRedisCommand redisCommand = JSON.parseObject(map.get(key).toString(), ShuttleRedisCommand.class); if (redisCommand == null) { continue; diff --git a/src/main/java/com/zy/asrs/task/RealtimeBasMapScheduler.java b/src/main/java/com/zy/asrs/task/RealtimeBasMapScheduler.java index 0f99bc2..659decc 100644 --- a/src/main/java/com/zy/asrs/task/RealtimeBasMapScheduler.java +++ b/src/main/java/com/zy/asrs/task/RealtimeBasMapScheduler.java @@ -4,6 +4,7 @@ import com.zy.asrs.entity.BasMap; import com.zy.asrs.service.BasMapService; import com.zy.common.utils.RedisUtil; +import com.zy.core.enums.RedisKeyType; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; @@ -26,7 +27,7 @@ @Scheduled(cron = "1 * * * * ? ") private void execute(){ for (int i = 1; i <= 4; i++) {//鎬诲叡鍥涘眰妤� - Object data = redisUtil.get("realtimeBasMap_" + i); + Object data = redisUtil.get(RedisKeyType.MAP.key + i); if (data == null) { continue; } diff --git a/src/main/java/com/zy/common/utils/NavigateMapData.java b/src/main/java/com/zy/common/utils/NavigateMapData.java index eb2fe6a..fcc7422 100644 --- a/src/main/java/com/zy/common/utils/NavigateMapData.java +++ b/src/main/java/com/zy/common/utils/NavigateMapData.java @@ -9,6 +9,7 @@ import com.zy.common.model.MapNode; import com.zy.common.model.NavigateNode; import com.zy.common.model.enums.NavigationMapType; +import com.zy.core.enums.RedisKeyType; import com.zy.core.enums.ShuttleTaskModeType; import org.springframework.stereotype.Component; @@ -84,7 +85,7 @@ */ public int[][] getDataFromRedis(Integer mapType, List<int[]> whitePoints, List<int[]> shuttlePoints) { RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class); - Object o = redisUtil.get("realtimeBasMap_" + lev); + Object o = redisUtil.get(RedisKeyType.MAP.key + lev); if (o == null) { return null; } diff --git a/src/main/java/com/zy/common/utils/NavigateMapUtils.java b/src/main/java/com/zy/common/utils/NavigateMapUtils.java index ad25bb3..325da95 100644 --- a/src/main/java/com/zy/common/utils/NavigateMapUtils.java +++ b/src/main/java/com/zy/common/utils/NavigateMapUtils.java @@ -6,6 +6,7 @@ import com.zy.common.model.MapNode; import com.zy.common.model.NavigateNode; import com.zy.common.model.enums.NavigationMapType; +import com.zy.core.enums.RedisKeyType; import org.springframework.stereotype.Component; import java.util.ArrayList; @@ -24,7 +25,7 @@ try { NavigateMapData navigateMapData = new NavigateMapData(lev); - Object o = redisUtil.get("realtimeBasMap_" + lev); + Object o = redisUtil.get(RedisKeyType.MAP.key + lev); if (o == null) { return false; } @@ -69,7 +70,7 @@ basMap.setData(JSON.toJSONString(lists)); basMap.setUpdateTime(new Date()); //灏嗘暟鎹簱鍦板浘鏁版嵁瀛樺叆redis - redisUtil.set("realtimeBasMap_" + lev, JSON.toJSONString(basMap)); + redisUtil.set(RedisKeyType.MAP.key + lev, JSON.toJSONString(basMap)); return true; } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/java/com/zy/core/enums/RedisKeyType.java b/src/main/java/com/zy/core/enums/RedisKeyType.java new file mode 100644 index 0000000..8ad3660 --- /dev/null +++ b/src/main/java/com/zy/core/enums/RedisKeyType.java @@ -0,0 +1,15 @@ +package com.zy.core.enums; + +public enum RedisKeyType { + + SHUTTLE("shuttle_wrk_no_"), + LIFT("lift_wrk_no_"), + MAP("realtimeBasMap_") + ; + + public String key; + + RedisKeyType(String key) { + this.key = key; + } +} diff --git a/src/main/java/com/zy/core/thread/LiftThread.java b/src/main/java/com/zy/core/thread/LiftThread.java index 935c90c..d14f4a4 100644 --- a/src/main/java/com/zy/core/thread/LiftThread.java +++ b/src/main/java/com/zy/core/thread/LiftThread.java @@ -329,7 +329,7 @@ redisCommand.setCommandStep(0);//鍛戒护鎵ц姝ュ簭 redisCommand.setAssignCommand(assignCommand);//鍛戒护 //浠诲姟鏁版嵁淇濆瓨鍒皉edis - redisUtil.set("lift_wrk_no_" + assignCommand.getTaskNo(), JSON.toJSONString(redisCommand)); + redisUtil.set(RedisKeyType.LIFT.key + assignCommand.getTaskNo(), JSON.toJSONString(redisCommand)); liftProtocol.setAssignCommand(assignCommand); liftProtocol.setProtocolStatus(LiftProtocolStatusType.WORKING); //鎵ц涓嬪彂浠诲姟 @@ -344,7 +344,7 @@ } WrkMastMapper wrkMastMapper = SpringUtils.getBean(WrkMastMapper.class); - Object o = redisUtil.get("lift_wrk_no_" + wrkNo); + Object o = redisUtil.get(RedisKeyType.LIFT.key + wrkNo); if (o == null) { return false; } @@ -399,11 +399,11 @@ commandStep++; redisCommand.setCommandStep(commandStep); //浠诲姟鏁版嵁淇濆瓨鍒皉edis - redisUtil.set("lift_wrk_no_" + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand)); + redisUtil.set(RedisKeyType.LIFT.key + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand)); }else { //宸叉墽琛屽畬鎴� //鍒犻櫎redis - redisUtil.del("lift_wrk_no_" + redisCommand.getWrkNo()); + redisUtil.del(RedisKeyType.LIFT.key + redisCommand.getWrkNo()); //瀵逛富绾跨▼鎶涘嚭绛夊緟纭鐘舵�亀aiting liftProtocol.setProtocolStatus(LiftProtocolStatusType.WAITING); diff --git a/src/main/java/com/zy/core/thread/NyShuttleThread.java b/src/main/java/com/zy/core/thread/NyShuttleThread.java index 255604a..6d381d2 100644 --- a/src/main/java/com/zy/core/thread/NyShuttleThread.java +++ b/src/main/java/com/zy/core/thread/NyShuttleThread.java @@ -10,7 +10,6 @@ import com.zy.asrs.utils.Utils; import com.zy.common.model.NavigateNode; -import com.zy.common.model.NyShuttleOperaResult; import com.zy.common.service.CommonService; import com.zy.common.utils.*; import com.zy.core.News; @@ -29,7 +28,6 @@ import lombok.Data; import lombok.extern.slf4j.Slf4j; -import javax.swing.*; import java.io.IOException; import java.net.Socket; import java.text.MessageFormat; @@ -358,7 +356,7 @@ shuttleProtocol.setAssignCommand(assignCommand); shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.WORKING); //浠诲姟鏁版嵁淇濆瓨鍒皉edis - redisUtil.set("shuttle_wrk_no_" + assignCommand.getTaskNo(), JSON.toJSONString(redisCommand)); + redisUtil.set(RedisKeyType.SHUTTLE.key + assignCommand.getTaskNo(), JSON.toJSONString(redisCommand)); //鎵ц涓嬪彂浠诲姟 executeWork(assignCommand.getTaskNo()); } @@ -374,7 +372,7 @@ WrkMastMapper wrkMastMapper = SpringUtils.getBean(WrkMastMapper.class); WrkMast wrkMast = wrkMastMapper.selectByWorkNo(wrkNo.intValue()); - Object o = redisUtil.get("shuttle_wrk_no_" + wrkNo); + Object o = redisUtil.get(RedisKeyType.SHUTTLE.key + wrkNo); if (o == null) { return false; } @@ -429,7 +427,7 @@ lastCommand.setComplete(true);//鍏朵粬鍛戒护榛樿璁や负瀹屾垚 } //浠诲姟鏁版嵁淇濆瓨鍒皉edis - redisUtil.set("shuttle_wrk_no_" + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand)); + redisUtil.set(RedisKeyType.SHUTTLE.key + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand)); if (!lastCommand.getComplete()) { //涓婁竴鏉′换鍔℃湭瀹屾垚锛岀姝笅鍙戝懡浠� @@ -440,7 +438,7 @@ NyShuttleHttpCommand endCommand = commands.get(commands.size() - 1); if (endCommand.getComplete()) { //鍒犻櫎redis - redisUtil.del("shuttle_wrk_no_" + redisCommand.getWrkNo()); + redisUtil.del(RedisKeyType.SHUTTLE.key + redisCommand.getWrkNo()); if (!assignCommand.getCharge()) { //瀵逛富绾跨▼鎶涘嚭绛夊緟纭鐘舵�亀aiting @@ -534,7 +532,7 @@ //鏇存柊redis鏁版嵁 redisCommand.setCommandStep(commandStep); //浠诲姟鏁版嵁淇濆瓨鍒皉edis - redisUtil.set("shuttle_wrk_no_" + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand)); + redisUtil.set(RedisKeyType.SHUTTLE.key + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand)); return true; } @@ -546,7 +544,7 @@ return false; } - Object o = redisUtil.get("shuttle_wrk_no_" + wrkNo); + Object o = redisUtil.get(RedisKeyType.SHUTTLE.key + wrkNo); if (o == null) { return false; } @@ -630,7 +628,7 @@ return false; } - Object o = redisUtil.get("shuttle_wrk_no_" + wrkNo); + Object o = redisUtil.get(RedisKeyType.SHUTTLE.key + wrkNo); if (o == null) { return false; } @@ -716,7 +714,7 @@ // assignCommand.setCommands(commands); // redisCommand.setAssignCommand(assignCommand); // //浠诲姟鏁版嵁淇濆瓨鍒皉edis -// redisUtil.set("shuttle_wrk_no_" + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand)); +// redisUtil.set(RedisKeyType.SHUTTLE.key + redisCommand.getWrkNo(), JSON.toJSONString(redisCommand)); // return false;//褰撳墠涓嶅彲琛岃蛋锛岀瓑寰呬笅涓�娆℃墽琛岃蛋鏂拌矾寰� // } -- Gitblit v1.9.1