From 08b68c503f12a28399f0c70e460ee6af8b7185ea Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期一, 10 二月 2025 12:46:13 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/asrs/domain/enums/NotifyMsgType.java | 47 ++++
src/main/java/com/zy/asrs/controller/OpenController.java | 15 +
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java | 246 +-----------------------
src/main/java/com/zy/asrs/utils/NotifyUtils.java | 113 +++++++++++
src/main/java/com/zy/asrs/task/NotifyScheduler.java | 126 ++++++++++++
src/main/java/com/zy/core/MainProcess.java | 7
src/main/java/com/zy/core/enums/RedisKeyType.java | 2
src/main/java/com/zy/asrs/domain/NotifyDto.java | 37 +++
8 files changed, 350 insertions(+), 243 deletions(-)
diff --git a/src/main/java/com/zy/asrs/controller/OpenController.java b/src/main/java/com/zy/asrs/controller/OpenController.java
index 54e013d..da84136 100644
--- a/src/main/java/com/zy/asrs/controller/OpenController.java
+++ b/src/main/java/com/zy/asrs/controller/OpenController.java
@@ -1,14 +1,20 @@
package com.zy.asrs.controller;
import com.core.common.R;
+import com.zy.asrs.domain.NotifyDto;
+import com.zy.asrs.domain.enums.NotifyMsgType;
import com.zy.asrs.domain.param.CancelTaskParam;
import com.zy.asrs.domain.param.CompleteTaskParam;
import com.zy.asrs.domain.param.CreateMoveTaskParam;
+import com.zy.asrs.utils.NotifyUtils;
import com.zy.common.service.CommonService;
import com.zy.core.dispatcher.ShuttleDispatchUtils;
+import com.zy.core.enums.SlaveType;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
@Slf4j
@RestController
@@ -19,6 +25,8 @@
private CommonService commonService;
@Autowired
private ShuttleDispatchUtils shuttleDispatchUtils;
+ @Autowired
+ private NotifyUtils notifyUtils;
@PostMapping("/createMoveTask")
public R createMoveTask(@RequestBody CreateMoveTaskParam param) {
@@ -56,4 +64,11 @@
return R.error("浠诲姟鍙栨秷澶辫触");
}
+ @GetMapping("/test")
+ public R test() {
+ notifyUtils.notify(String.valueOf(SlaveType.Shuttle), 1, "9999", NotifyMsgType.SHUTTLE_MOVING);
+ notifyUtils.notify(String.valueOf(SlaveType.Shuttle), 2, "9999", NotifyMsgType.SHUTTLE_MOVE_COMPLETE);
+ return R.ok();
+ }
+
}
diff --git a/src/main/java/com/zy/asrs/domain/NotifyDto.java b/src/main/java/com/zy/asrs/domain/NotifyDto.java
new file mode 100644
index 0000000..38d2f6a
--- /dev/null
+++ b/src/main/java/com/zy/asrs/domain/NotifyDto.java
@@ -0,0 +1,37 @@
+package com.zy.asrs.domain;
+
+import lombok.Data;
+
+@Data
+public class NotifyDto {
+
+ private Long id;
+
+ //璁惧绫诲瀷
+ private String deviceType;
+
+ //璁惧鍙�
+ private Integer device;
+
+ //宸ヤ綔鍙�
+ private String taskNo;
+
+ //娑堟伅绫诲瀷
+ private String msgType;
+
+ //娑堟伅鍐呭
+ private String content;
+
+ //澶辫触閲嶈瘯娆℃暟
+ private Integer failTimes = 3;
+
+ //閲嶈瘯娆℃暟
+ private Integer retryTimes = 0;
+
+ //閲嶈瘯闂撮殧榛樿30s
+ private Integer retryTime = 30;
+
+ //涓婃閲嶈瘯鏃堕棿
+ private Long lastRetryTime = 0L;
+
+}
diff --git a/src/main/java/com/zy/asrs/domain/enums/NotifyMsgType.java b/src/main/java/com/zy/asrs/domain/enums/NotifyMsgType.java
new file mode 100644
index 0000000..11feb74
--- /dev/null
+++ b/src/main/java/com/zy/asrs/domain/enums/NotifyMsgType.java
@@ -0,0 +1,47 @@
+package com.zy.asrs.domain.enums;
+
+public enum NotifyMsgType {
+ SHUTTLE_START_TAKE("shuttle_start_take", "灏忚溅寮�濮嬪彇璐�"),
+ SHUTTLE_TRANSPORT("shuttle_transport", "灏忚溅閫佽揣涓�"),
+ SHUTTLE_DELIVERY("shuttle_delivery", "灏忚溅鏀捐揣瀹屾垚"),
+ SHUTTLE_MOVING("shuttle_moving", "灏忚溅绉诲姩涓�"),
+ SHUTTLE_MOVE_COMPLETE("shuttle_move_complete", "灏忚溅绉诲姩瀹屾垚"),
+ SHUTTLE_POWER_LOW("shuttle_power_low", "灏忚溅浣庣數閲�"),
+ SHUTTLE_POWER_START("shuttle_power_start", "灏忚溅寮�濮嬪厖鐢�"),
+ SHUTTLE_POWER_COMPLETE("shuttle_power_complete", "灏忚溅鍏呯數瀹屾垚"),
+ SHUTTLE_ERROR("shuttle_error", "灏忚溅寮傚父"),
+ FORK_LIFT_ERROR("fork_lift_error", "璐у弶鎻愬崌鏈哄紓甯�"),
+ ;
+
+ public String flag;
+ public String desc;
+
+ NotifyMsgType(String flag, String desc) {
+ this.flag = flag;
+ this.desc = desc;
+ }
+
+ public static NotifyMsgType get(String flag) {
+ if (null == flag) {
+ return null;
+ }
+ for (NotifyMsgType type : NotifyMsgType.values()) {
+ if (type.flag.equals(flag)) {
+ return type;
+ }
+ }
+ return null;
+ }
+
+ public static NotifyMsgType get(NotifyMsgType type) {
+ if (null == type) {
+ return null;
+ }
+ for (NotifyMsgType type2 : NotifyMsgType.values()) {
+ if (type2 == type) {
+ return type2;
+ }
+ }
+ return null;
+ }
+}
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 dc1bfb5..3760f91 100644
--- a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -1,9 +1,11 @@
package com.zy.asrs.service.impl;
import com.alibaba.fastjson.JSON;
+import com.zy.asrs.domain.enums.NotifyMsgType;
import com.zy.asrs.entity.*;
import com.zy.asrs.mapper.*;
import com.zy.asrs.service.*;
+import com.zy.asrs.utils.NotifyUtils;
import com.zy.asrs.utils.Utils;
import com.zy.common.model.*;
import com.zy.common.model.enums.NavigationMapType;
@@ -82,6 +84,8 @@
private ShuttleAction shuttleAction;
@Autowired
private ForkLiftAction forkLiftAction;
+ @Autowired
+ private NotifyUtils notifyUtils;
// /**
@@ -851,10 +855,12 @@
//310.灏忚溅绉诲姩涓� ==> 311.灏忚溅绉诲姩瀹屾垚
wrkMast.setWrkSts(WrkStsType.COMPLETE_MOVE.sts);
shuttleThread.setSyncTaskNo(0);
+ notifyUtils.notify(String.valueOf(SlaveType.Shuttle), shuttleProtocol.getShuttleNo(), String.valueOf(wrkMast.getWrkNo()), NotifyMsgType.SHUTTLE_MOVE_COMPLETE);//瑙﹀彂閫氱煡
} else if (wrkMast.getWrkSts() == WrkStsType.CHARGE_SHUTTLE_WORKING.sts) {
//204.灏忚溅鍏呯數涓� ==> 205.灏忚溅鍏呯數瀹屾垚
wrkMast.setWrkSts(WrkStsType.CHARGE_SHUTTLE_COMPLETE.sts);
shuttleThread.setSyncTaskNo(0);
+ notifyUtils.notify(String.valueOf(SlaveType.Shuttle), shuttleProtocol.getShuttleNo(), String.valueOf(wrkMast.getWrkNo()), NotifyMsgType.SHUTTLE_POWER_COMPLETE);//瑙﹀彂閫氱煡
}else {
continue;
}
@@ -1561,206 +1567,6 @@
// }
/**
- * 鍑哄簱 ===>> 宸ヤ綔妗d俊鎭啓鍏ed鏄剧ず鍣�
- */
- public void ledExecute() {
-// try {
-// for (LedSlave led : slaveProperties.getLed()) {
-// // 鑾峰彇杈撻�佺嚎plc绾跨▼
-// DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, led.getDevpPlcId());
-// // 鍛戒护闆嗗悎
-// List<LedCommand> commands = new ArrayList<>();
-// // 宸ヤ綔妗i泦鍚�
-// List<WrkMast> wrkMasts = new ArrayList<>();
-// List<WrkMastLog> wrkMastLogs = new ArrayList<>();
-// for (Integer staNo : led.getStaArr()) {
-// // 鑾峰彇鍙夎溅绔欑偣
-// StaProtocol staProtocol = devpThread.getStation().get(staNo);
-// if (null == staProtocol || null == staProtocol.getWorkNo() || 0 == staProtocol.getWorkNo() || !staProtocol.isLoading()) {
-// continue;
-// } else {
-// staProtocol = staProtocol.clone();
-// }
-// // 鑾峰彇宸ヤ綔妗f暟鎹�
-// WrkMast wrkMast = wrkMastMapper.selectById(staProtocol.getWorkNo());
-// Integer wrkNo = staProtocol.getWorkNo().intValue();
-// Integer ioType = null;
-// String sourceLocNo = null;
-// String locNo = null;
-// Integer wrkStaNo = null;
-// String barcode = null;
-// if (wrkMast == null) {
-// //鏌ヨ鍘嗗彶妗�
-// WrkMastLog wrkMastLog = wrkMastLogMapper.selectLatestByWorkNo(staProtocol.getWorkNo().intValue());
-// if (wrkMastLog == null) {
-// continue;
-// }
-// ioType = wrkMastLog.getIoType();
-// sourceLocNo = wrkMastLog.getSourceLocNo();
-// locNo = wrkMastLog.getLocNo();
-// wrkStaNo = wrkMastLog.getStaNo();
-// barcode = wrkMastLog.getBarcode();
-// wrkMastLogs.add(wrkMastLog);
-// }else {
-// if (wrkMast.getWrkSts() < 14 || wrkMast.getIoType() < 100) {
-// continue;
-// }
-// ioType = wrkMast.getIoType();
-// sourceLocNo = wrkMast.getSourceLocNo();
-// locNo = wrkMast.getLocNo();
-// wrkStaNo = wrkMast.getStaNo();
-// barcode = wrkMast.getBarcode();
-// wrkMasts.add(wrkMast);
-// }
-// // 缁勮鍛戒护
-// LedCommand ledCommand = new LedCommand();
-// ledCommand.setWorkNo(wrkNo);
-// ledCommand.setIoType(ioType);
-// // 鍑哄簱妯″紡
-// switch (ioType) {
-// case 101:
-// ledCommand.setTitle("鍏ㄦ澘鍑哄簱");
-// break;
-// case 103:
-// ledCommand.setTitle("鎷f枡鍑哄簱");
-// break;
-// case 104:
-// ledCommand.setTitle("骞舵澘鍑哄簱");
-// break;
-// case 107:
-// ledCommand.setTitle("鐩樼偣鍑哄簱");
-// break;
-// case 110:
-// ledCommand.setTitle("绌烘澘鍑哄簱");
-// ledCommand.setEmptyMk(true);
-// break;
-// default:
-// News.error("浠诲姟鍏ュ嚭搴撶被鍨嬮敊璇紒锛侊紒[宸ヤ綔鍙凤細{}] [鍏ュ嚭搴撶被鍨嬶細{}]", wrkNo, ioType);
-// break;
-// }
-// ledCommand.setSourceLocNo(sourceLocNo);
-// ledCommand.setLocNo(locNo);
-// ledCommand.setStaNo(wrkStaNo);
-// ledCommand.setBarcode(barcode);
-// if (ioType != 110 && ioType != 10) {
-// List<WrkDetl> wrkDetls = wrkDetlService.selectList(new EntityWrapper<WrkDetl>().eq("wrk_no", wrkNo));
-// if (!wrkDetls.isEmpty()) {
-// wrkDetls.forEach(wrkDetl -> {
-// double remainNum = wrkDetl.getStock() - wrkDetl.getAnfme();//鍓╀綑鏁伴噺
-// if (remainNum < 0) {
-// remainNum = 0;
-// }
-// String matnr = wrkDetl.getMatnr();
-// Mat mat = matService.selectByMatnr(wrkDetl.getMatnr());
-// if (mat != null) {
-// if (!mat.getMatnr().equals(mat.getMatnr2())) {
-// matnr += " - " + mat.getMatnr2();
-// }
-// }
-// ledCommand.getMatDtos().add(new MatDto(matnr, wrkDetl.getMaktx(), wrkDetl.getAnfme(), remainNum, wrkDetl.getSpecs(), wrkDetl.getSuppCode(), wrkDetl.getOrderNo()));
-// });
-// }else {
-// List<WrkDetlLog> wrkDetlLogs = wrkDetlLogService.selectLatestByWorkNo(wrkNo, barcode);
-// for (WrkDetlLog wrkDetlLog : wrkDetlLogs) {
-// double remainNum = wrkDetlLog.getStock() - wrkDetlLog.getAnfme();//鍓╀綑鏁伴噺
-// if (remainNum < 0) {
-// remainNum = 0;
-// }
-// String matnr = wrkDetlLog.getMatnr();
-// Mat mat = matService.selectByMatnr(wrkDetlLog.getMatnr());
-// if (mat != null) {
-// if (!mat.getMatnr().equals(mat.getMatnr2())) {
-// matnr += " - " + mat.getMatnr2();
-// }
-// }
-// ledCommand.getMatDtos().add(new MatDto(matnr, wrkDetlLog.getMaktx(), wrkDetlLog.getAnfme(), remainNum, wrkDetlLog.getSpecs(), wrkDetlLog.getSuppCode()));
-// }
-// }
-// commands.add(ledCommand);
-// }
-// Set<Integer> workNos = null;
-// if (!wrkMasts.isEmpty()) {
-// workNos = wrkMasts.stream().map(WrkMast::getWrkNo).collect(Collectors.toSet());
-// }else {
-// workNos = wrkMastLogs.stream().map(WrkMastLog::getWrkNo).collect(Collectors.toSet());
-// }
-// // 鑾峰彇LED绾跨▼
-// LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, led.getId());
-// // 鐩稿悓宸ヤ綔鍙烽泦鍚堝垯杩囨护
-// if (CollectionUtils.equals(ledThread.getWorkNos(), workNos)) {
-// continue;
-// }
-// // 鍛戒护涓嬪彂 -------------------------------------------------------------------------------
-// if (!commands.isEmpty()) {
-// if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(1, commands))) {
-// log.error("{}鍙稬ED鍛戒护涓嬪彂澶辫触锛侊紒锛乕ip锛歿}] [port锛歿}]", led.getId(), led.getIp(), led.getPort());
-// continue;
-// } else {
-// ledThread.setLedMk(false);
-// }
-// }
-//
-// try {
-// // 淇敼涓绘。led鏍囪
-// for (WrkMast wrkMast : wrkMasts) {
-// wrkMast.setOveMk("Y");
-// wrkMast.setModiTime(new Date());
-// if (wrkMastMapper.updateById(wrkMast) == 0) {
-// throw new CoolException("鏇存柊宸ヤ綔妗eけ璐�");
-// }
-// }
-//
-// // 鏇存柊绾跨▼褰撳墠宸ヤ綔鍙烽泦鍚�
-// ledThread.setWorkNos(workNos);
-//
-// } catch (Exception e) {
-// e.printStackTrace();
-// TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
-// }
-//
-// }
-// } catch (Exception e) {
-// e.printStackTrace();
-// }
- }
-
- /**
- * 鍏朵粬 ===>> LED鏄剧ず鍣ㄥ浣嶏紝鏄剧ず榛樿淇℃伅
- */
- public void ledReset() {
-// try {
-// for (LedSlave led : slaveProperties.getLed()) {
-// // 鑾峰彇杈撻�佺嚎plc绾跨▼
-// DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, led.getDevpPlcId());
-// // 鍛戒护闆嗗悎
-// boolean reset = true;
-// for (Integer staNo : led.getStaArr()) {
-// // 鑾峰彇鍙夎溅绔欑偣
-// StaProtocol staProtocol = devpThread.getStation().get(staNo);
-// if (staProtocol == null) {
-// continue;
-// }
-// if (staProtocol.isLoading()) {
-// reset = false;
-// break;
-// }
-// }
-// // 鑾峰彇led绾跨▼
-// LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, led.getId());
-// // led鏄剧ず榛樿鍐呭
-// if (reset) {
-// ledThread.setLedMk(true);
-// if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(2, new ArrayList<>()))) {
-// log.error("{}鍙稬ED鍛戒护涓嬪彂澶辫触锛侊紒锛乕ip锛歿}] [port锛歿}]", led.getId(), led.getIp(), led.getPort());
-// }
-// }
-// }
-// } catch (Exception e) {
-// e.printStackTrace();
-// }
- }
-
- /**
* 鍥涘悜绌挎杞︾數閲忔娴� ===>> 鍙戣捣鍏呯數
*/
public synchronized void loopShuttleCharge() {
@@ -1988,6 +1794,8 @@
//涓嬪彂浠诲姟
shuttleAction.assignWork(shuttleProtocol.getShuttleNo(), assignCommand);
+
+ notifyUtils.notify(String.valueOf(SlaveType.Shuttle), shuttleProtocol.getShuttleNo(), String.valueOf(wrkMast.getWrkNo()), NotifyMsgType.SHUTTLE_POWER_START);//瑙﹀彂閫氱煡
return false;
}
return true;
@@ -2188,6 +1996,8 @@
if (wrkMastService.updateById(wrkMast)) {
//涓嬪彂浠诲姟
shuttleAction.assignWork(shuttleProtocol.getShuttleNo(), assignCommand);
+ //瑙﹀彂閫氱煡
+ notifyUtils.notify(String.valueOf(SlaveType.Shuttle), shuttleProtocol.getShuttleNo(), String.valueOf(wrkMast.getWrkNo()), NotifyMsgType.SHUTTLE_MOVING);
return false;
}
return false;
@@ -2402,41 +2212,5 @@
}
return true;
}
-
-// //鎵弿璁惧PakMk鏍囪鏄惁瓒呮椂
-// public synchronized void scanDevicePakMk() {
-// try {
-// //鎵弿灏忚溅
-// for (ShuttleSlave slave : slaveProperties.getShuttle()) {
-// NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, slave.getId());
-// NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
-// if (shuttleProtocol == null) {
-// continue;
-// }
-//
-// if ((System.currentTimeMillis() - shuttleProtocol.getSendTime() > (1000 * 60 * 5)) && shuttleProtocol.getPakMk()) {
-// //璁惧瓒呰繃5鍒嗛挓杩樻病澶嶄綅鏍囪
-// shuttleProtocol.setPakMk(false);//澶嶄綅鏍囪
-// }
-// }
-//
-// //鎵弿鎻愬崌鏈�
-// for (LiftSlave slave : slaveProperties.getLift()) {
-// LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, slave.getId());
-// LiftProtocol liftProtocol = liftThread.getLiftProtocol();
-// if (liftProtocol == null) {
-// continue;
-// }
-//
-// if ((System.currentTimeMillis() - liftProtocol.getSendTime() > (1000 * 60 * 5)) && liftProtocol.getPakMk()) {
-// //璁惧瓒呰繃5鍒嗛挓杩樻病澶嶄綅鏍囪
-// liftProtocol.setPakMk(false);//澶嶄綅鏍囪
-// }
-// }
-// } catch (Exception e) {
-// e.printStackTrace();
-// }
-//
-// }
}
diff --git a/src/main/java/com/zy/asrs/task/NotifyScheduler.java b/src/main/java/com/zy/asrs/task/NotifyScheduler.java
new file mode 100644
index 0000000..601d9aa
--- /dev/null
+++ b/src/main/java/com/zy/asrs/task/NotifyScheduler.java
@@ -0,0 +1,126 @@
+package com.zy.asrs.task;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.zy.asrs.domain.NotifyDto;
+import com.zy.asrs.utils.NotifyUtils;
+import com.zy.common.utils.HttpHandler;
+import com.zy.common.utils.RedisUtil;
+import com.zy.core.enums.SlaveType;
+import com.zy.core.model.ForkLiftSlave;
+import com.zy.core.model.ShuttleSlave;
+import com.zy.core.properties.SlaveProperties;
+import com.zy.system.entity.Config;
+import com.zy.system.service.ConfigService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+@Component
+@Slf4j
+public class NotifyScheduler {
+
+ @Autowired
+ private RedisUtil redisUtil;
+ @Autowired
+ private NotifyUtils notifyUtils;
+ @Autowired
+ private SlaveProperties slaveProperties;
+ @Autowired
+ private ConfigService configService;
+
+ @Scheduled(cron = "0/3 * * * * ? ")
+ public synchronized void notifyShuttle(){
+ for (ShuttleSlave slave : slaveProperties.getShuttle()) {
+ notifyMsg(String.valueOf(SlaveType.Shuttle), slave.getId());
+ }
+ }
+
+ @Scheduled(cron = "0/3 * * * * ? ")
+ public synchronized void notifyForkLift(){
+ for (ForkLiftSlave slave : slaveProperties.getForkLift()) {
+ notifyMsg(String.valueOf(SlaveType.ForkLift), slave.getId());
+ }
+ }
+
+ private synchronized void notifyMsg(String deviceType, Integer device) {
+ Config notifyEnableConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "notifyEnable"));
+ if(notifyEnableConfig == null){
+ return;
+ }
+ String notifyEnable = notifyEnableConfig.getValue();
+ if (!notifyEnable.equals("Y")) {
+ return;
+ }
+
+ Config notifyUriConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "notifyUri"));
+ if(notifyUriConfig == null){
+ return;
+ }
+ String notifyUri = notifyUriConfig.getValue();
+
+ Config notifyUriPathConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "notifyUriPath"));
+ if(notifyUriPathConfig == null){
+ return;
+ }
+ String notifyUriPath = notifyUriPathConfig.getValue();
+
+ List<String> keys = notifyUtils.takeKeys(deviceType, device);
+ if(keys == null){
+ return;
+ }
+
+ if (keys.isEmpty()) {
+ return;
+ }
+
+ for (String key : keys) {
+ Object object = redisUtil.get(key);
+ if (object == null) {
+ continue;
+ }
+ NotifyDto notifyDto = (NotifyDto) object;
+
+ if (System.currentTimeMillis() - notifyDto.getLastRetryTime() < 1000 * notifyDto.getRetryTime()) {
+ continue;
+ }
+
+ try {
+ //瑙﹀彂閫氱煡
+ String response = new HttpHandler.Builder()
+ .setUri(notifyUri)
+ .setPath(notifyUriPath)
+ .setJson(JSON.toJSONString(notifyDto))
+ .build()
+ .doPost();
+ JSONObject jsonObject = JSON.parseObject(response);
+ Integer code = jsonObject.getInteger("code");
+ if(code == 200){
+ //閫氱煡鎴愬姛
+ redisUtil.del(key);
+ return;
+ }
+ }catch (Exception e){
+ e.printStackTrace();
+ }
+
+ //閫氱煡澶辫触
+ int times = notifyDto.getRetryTimes() + 1;
+ if (times >= notifyDto.getFailTimes()) {
+ //瓒呰繃娆℃暟
+ redisUtil.del(key);
+ return;
+ }
+
+ notifyDto.setLastRetryTime(System.currentTimeMillis());
+ notifyDto.setRetryTimes(times);
+ redisUtil.set(key, notifyDto);
+ return;
+ }
+ }
+
+}
diff --git a/src/main/java/com/zy/asrs/utils/NotifyUtils.java b/src/main/java/com/zy/asrs/utils/NotifyUtils.java
new file mode 100644
index 0000000..6a1f480
--- /dev/null
+++ b/src/main/java/com/zy/asrs/utils/NotifyUtils.java
@@ -0,0 +1,113 @@
+package com.zy.asrs.utils;
+
+import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.core.common.SnowflakeIdWorker;
+import com.zy.asrs.domain.NotifyDto;
+import com.zy.asrs.domain.enums.NotifyMsgType;
+import com.zy.common.utils.RedisUtil;
+import com.zy.core.enums.RedisKeyType;
+import com.zy.core.enums.SlaveType;
+import com.zy.system.entity.Config;
+import com.zy.system.service.ConfigService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+@Component
+public class NotifyUtils {
+
+ @Autowired
+ private RedisUtil redisUtil;
+ @Autowired
+ private SnowflakeIdWorker snowflakeIdWorker;
+ @Autowired
+ private ConfigService configService;
+
+ public synchronized boolean notify(String deviceType, Integer device, String taskNo, NotifyMsgType msgType) {
+ SlaveType type = SlaveType.findInstance(deviceType);
+ if (type == null) {
+ return false;
+ }
+ return append(type, device, taskNo, msgType);
+ }
+
+ public synchronized List<String> takeKeys(String deviceType, Integer device) {
+ String key = getKey(deviceType, device);
+ if(key == null){
+ return null;
+ }
+
+ Set keys = redisUtil.keys(key + "*");
+ if (keys == null) {
+ return null;
+ }
+
+ List<String> list = new ArrayList<>();
+ for (Object object : keys) {
+ list.add(object.toString());
+ }
+ return list;
+ }
+
+ public String getKey(String deviceType, Integer device) {
+ SlaveType type = SlaveType.findInstance(deviceType);
+ if (type == null) {
+ return null;
+ }
+ String key = null;
+ switch (type) {
+ case Shuttle:
+ key = RedisKeyType.QUEUE_SHUTTLE.key + device;
+ break;
+ case ForkLift:
+ key = RedisKeyType.QUEUE_FORK_LIFT.key + device;
+ break;
+ default:
+ return null;
+ }
+
+ return key;
+ }
+
+ private boolean append(SlaveType deviceType, Integer device, String taskNo, NotifyMsgType msgType) {
+ String key = null;
+ switch (deviceType) {
+ case Shuttle:
+ key = RedisKeyType.QUEUE_SHUTTLE.key + device;
+ break;
+ case ForkLift:
+ key = RedisKeyType.QUEUE_FORK_LIFT.key + device;
+ break;
+ default:
+ return false;
+ }
+
+ NotifyDto dto = new NotifyDto();
+ dto.setId(snowflakeIdWorker.nextId());
+ dto.setDeviceType(String.valueOf(deviceType));
+ dto.setDevice(device);
+ dto.setMsgType(msgType.flag);
+ dto.setContent(msgType.desc);
+ dto.setTaskNo(taskNo);
+
+ //閲嶈瘯娆℃暟
+ Config notifyFailTimesConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "notifyFailTimes"));
+ if (notifyFailTimesConfig != null) {
+ dto.setFailTimes(Integer.parseInt(notifyFailTimesConfig.getValue()));
+ }
+
+ //閲嶈瘯闂撮殧
+ Config notifyRetryTimeConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "notifyRetryTime"));
+ if (notifyRetryTimeConfig != null) {
+ dto.setRetryTime(Integer.parseInt(notifyRetryTimeConfig.getValue()));
+ }
+
+ redisUtil.set(key + "_" + dto.getId(), dto);
+ return true;
+ }
+
+}
diff --git a/src/main/java/com/zy/core/MainProcess.java b/src/main/java/com/zy/core/MainProcess.java
index 2d10c2a..1778208 100644
--- a/src/main/java/com/zy/core/MainProcess.java
+++ b/src/main/java/com/zy/core/MainProcess.java
@@ -66,16 +66,9 @@
mainService.recErr();
// // 鍏ュ簱 ===>> 绌烘爤鏉垮垵濮嬪寲鍏ュ簱,鍙夎溅鍏ュ簱绔欐斁璐�
// mainService.storeEmptyPlt();
-// // 鍑哄簱 ===>> 宸ヤ綔妗d俊鎭啓鍏ed鏄剧ず鍣�
-// mainService.ledExecute();
-// // 鍏朵粬 ===>> LED鏄剧ず鍣ㄥ浣嶏紝鏄剧ず榛樿淇℃伅
-// mainService.ledReset();
// 绌挎杞� ===>> 灏忚溅鐢甸噺妫�娴嬪厖鐢�
mainService.loopShuttleCharge();
mainService.executeShuttleCharge();
-
-// //鎵弿璁惧PakMk鏍囪鏄惁瓒呮椂
-// mainService.scanDevicePakMk();
// 闂撮殧
Thread.sleep(200);
diff --git a/src/main/java/com/zy/core/enums/RedisKeyType.java b/src/main/java/com/zy/core/enums/RedisKeyType.java
index 821dc8e..fb0f9f7 100644
--- a/src/main/java/com/zy/core/enums/RedisKeyType.java
+++ b/src/main/java/com/zy/core/enums/RedisKeyType.java
@@ -8,6 +8,8 @@
FORK_LIFT_FLAG("fork_lift_"),
MAP("realtimeBasMap_"),
BASIC_MAP("basicMap_"),
+ QUEUE_SHUTTLE("queue_shuttle_"),
+ QUEUE_FORK_LIFT("queue_fork_lift_"),
;
public String key;
--
Gitblit v1.9.1