Commit 7396d993 张少辉

1.增加三色灯亮灯功能

1 个父辈 9dd7f709
...@@ -3,7 +3,9 @@ package com.neotel.smfcore.custom.haobo; ...@@ -3,7 +3,9 @@ package com.neotel.smfcore.custom.haobo;
import com.neotel.smfcore.core.api.SmfApi; import com.neotel.smfcore.core.api.SmfApi;
import com.neotel.smfcore.core.device.util.DataCache; import com.neotel.smfcore.core.device.util.DataCache;
import com.neotel.smfcore.core.storage.service.po.Storage; import com.neotel.smfcore.core.storage.service.po.Storage;
import com.neotel.smfcore.core.system.service.po.DataLog;
import com.neotel.smfcore.core.system.util.DevicesStatusUtil; import com.neotel.smfcore.core.system.util.DevicesStatusUtil;
import com.neotel.smfcore.core.system.util.TaskService;
import com.neotel.smfcore.custom.haobo.bean.PosDiff; import com.neotel.smfcore.custom.haobo.bean.PosDiff;
import com.neotel.smfcore.custom.haobo.bean.PosTotalDiffResult; import com.neotel.smfcore.custom.haobo.bean.PosTotalDiffResult;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -29,6 +31,9 @@ public class HaoBoNlpPosHandler { ...@@ -29,6 +31,9 @@ public class HaoBoNlpPosHandler {
@Autowired @Autowired
private DataCache dataCache; private DataCache dataCache;
@Autowired
private TaskService taskService;
ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(1); ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(1);
@PostConstruct @PostConstruct
...@@ -39,8 +44,82 @@ public class HaoBoNlpPosHandler { ...@@ -39,8 +44,82 @@ public class HaoBoNlpPosHandler {
@Override @Override
public void run() { public void run() {
handlePos(); handlePos();
handleTriColorLight();
}
}, 30, 2, TimeUnit.SECONDS);
}
}
// 新增:定义静态缓存,记录每个货架(cid)上一次点亮的灯通道
private static final Map<String, Integer> LAST_LIGHT_CHANNEL_CACHE = new HashMap<>();
private void handleTriColorLight() {
int left = 81;
int right = 82;
int buzzer = 9;
int color_green = 10;
int color_yellow = 11;
int color_red = 12;
for (Storage storage : dataCache.getAllStorage().values()) {
if (storage.isNLPHBShelf()) {
boolean hasTask = false;
boolean hasException = false;
Collection<DataLog> queueTasks = taskService.getQueueTasks(storage.getCid());
if (queueTasks != null && !queueTasks.isEmpty()) {
hasTask = true;
}
List<List<String>> lastDeviceData = DevicesStatusUtil.getDeviceData(storage.getCid());
List<String> lastHasReelPosErrorList = new ArrayList<>();
List<String> lastNoReelPosErrorList = new ArrayList<>();
if (lastDeviceData != null && lastDeviceData.size() == 2) {
lastHasReelPosErrorList = lastDeviceData.get(0);
lastNoReelPosErrorList = lastDeviceData.get(1);
} }
}, 30, 5, TimeUnit.SECONDS); if (lastHasReelPosErrorList != null && !lastHasReelPosErrorList.isEmpty()) {
hasException = true;
}
if (lastNoReelPosErrorList != null && !lastNoReelPosErrorList.isEmpty()) {
hasException = true;
}
int ioBoardAddress = left;
if (storage.getCid().endsWith("A")) {
ioBoardAddress = left;
} else if (storage.getCid().endsWith("B")) {
ioBoardAddress = right;
}
int channel = color_green;
if (hasException) {
channel = color_red;
} else if (!hasException && hasTask) {
channel = color_yellow;
} else {
channel = color_green;
}
// ===== 核心修改:首次无缓存则全部关闭,非首次关闭上一个灯 =====
String cid = storage.getCid();
Integer lastChannel = LAST_LIGHT_CHANNEL_CACHE.get(cid);
if (lastChannel == null) {
// 第一次操作:全部关闭绿、黄、红三个通道
haoboApi.controlIoBoard(ioBoardAddress, color_green, false);
haoboApi.controlIoBoard(ioBoardAddress, color_yellow, false);
haoboApi.controlIoBoard(ioBoardAddress, color_red, false);
} else if (lastChannel != channel) {
// 非首次且通道不同:仅关闭上一次点亮的灯
haoboApi.controlIoBoard(ioBoardAddress, lastChannel, false);
}
// 点亮本次目标灯(原有逻辑保留)
haoboApi.controlIoBoard(ioBoardAddress, channel, true);
// 更新缓存,记录本次点亮的通道
LAST_LIGHT_CHANNEL_CACHE.put(cid, channel);
// ==============================================
}
} }
} }
...@@ -65,23 +144,19 @@ public class HaoBoNlpPosHandler { ...@@ -65,23 +144,19 @@ public class HaoBoNlpPosHandler {
PosTotalDiffResult posTotalDiffResult = calculateAndPrintPosDiff(oldDeviceData, newData); PosTotalDiffResult posTotalDiffResult = calculateAndPrintPosDiff(oldDeviceData, newData);
List<String> totalAddList = posTotalDiffResult.getTotalAddList(); List<String> totalAddList = posTotalDiffResult.getTotalAddList();
List<String> totalReduceList = posTotalDiffResult.getTotalReduceList(); List<String> totalReduceList = posTotalDiffResult.getTotalReduceList();
haoboApi.lightUpSomeLampBeads(totalAddList,totalReduceList); haoboApi.lightUpSomeLampBeads(totalAddList, totalReduceList);
DevicesStatusUtil.updateDeviceData(cid, newData); DevicesStatusUtil.updateDeviceData(cid, newData);
} }
} }
} }
/** /**
* 计算并打印新旧货位数据的差异,同时返回合并后的总新增/总减少列表 * 计算并打印新旧货位数据的差异,同时返回合并后的总新增/总减少列表
*
* @param oldDeviceData 旧设备数据(二维列表:[库存独有列表, 已用独有列表]) * @param oldDeviceData 旧设备数据(二维列表:[库存独有列表, 已用独有列表])
* @param newData 新计算的差异数据(二维列表:[库存独有列表, 已用独有列表]) * @param newData 新计算的差异数据(二维列表:[库存独有列表, 已用独有列表])
* @return PosTotalDiffResult 合并后的总新增、总减少货位列表 * @return PosTotalDiffResult 合并后的总新增、总减少货位列表
*/ */
private PosTotalDiffResult calculateAndPrintPosDiff(List<List<String>> oldDeviceData, List<List<String>> newData) { private PosTotalDiffResult calculateAndPrintPosDiff(List<List<String>> oldDeviceData, List<List<String>> newData) {
......
...@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject; ...@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
import com.neotel.smfcore.common.exception.ApiException; import com.neotel.smfcore.common.exception.ApiException;
import com.neotel.smfcore.common.utils.DateUtil; import com.neotel.smfcore.common.utils.DateUtil;
import com.neotel.smfcore.common.utils.HttpHelper; import com.neotel.smfcore.common.utils.HttpHelper;
import com.neotel.smfcore.common.utils.StringUtils;
import com.neotel.smfcore.core.api.listener.BaseSmfApiListener; import com.neotel.smfcore.core.api.listener.BaseSmfApiListener;
import com.neotel.smfcore.core.device.util.DataCache; import com.neotel.smfcore.core.device.util.DataCache;
import com.neotel.smfcore.core.order.enums.ORDER_COLOR; import com.neotel.smfcore.core.order.enums.ORDER_COLOR;
...@@ -31,6 +32,10 @@ public class HaoboApi extends BaseSmfApiListener { ...@@ -31,6 +32,10 @@ public class HaoboApi extends BaseSmfApiListener {
@Value("${api.lightUpSomeLampBeadsUrl:}") @Value("${api.lightUpSomeLampBeadsUrl:}")
private String lightUpSomeLampBeadsUrl =""; private String lightUpSomeLampBeadsUrl ="";
@Value("${api.controlIoBoardUrl:}")
private String controlIoBoardUrl ="";
@Autowired @Autowired
private DataCache dataCache; private DataCache dataCache;
...@@ -40,6 +45,7 @@ public class HaoboApi extends BaseSmfApiListener { ...@@ -40,6 +45,7 @@ public class HaoboApi extends BaseSmfApiListener {
getInventoryUrl = dataCache.getConfigCache("api.haobo.getInventory", getInventoryUrl); getInventoryUrl = dataCache.getConfigCache("api.haobo.getInventory", getInventoryUrl);
lightUpLabelUrl = dataCache.getConfigCache("api.haobo.lightUpLabel", lightUpLabelUrl); lightUpLabelUrl = dataCache.getConfigCache("api.haobo.lightUpLabel", lightUpLabelUrl);
lightUpSomeLampBeadsUrl = dataCache.getConfigCache("api.haobo.lightUpSomeLampBeads", lightUpSomeLampBeadsUrl); lightUpSomeLampBeadsUrl = dataCache.getConfigCache("api.haobo.lightUpSomeLampBeads", lightUpSomeLampBeadsUrl);
controlIoBoardUrl = dataCache.getConfigCache("api.haobo.controlIoBoard", controlIoBoardUrl);
} }
@Override @Override
...@@ -98,7 +104,10 @@ public class HaoboApi extends BaseSmfApiListener { ...@@ -98,7 +104,10 @@ public class HaoboApi extends BaseSmfApiListener {
List<GetInventoryResponse.DataItem> data = result.getData(); List<GetInventoryResponse.DataItem> data = result.getData();
if (data != null && !data.isEmpty()) { if (data != null && !data.isEmpty()) {
for (GetInventoryResponse.DataItem item : data) { for (GetInventoryResponse.DataItem item : data) {
hasReelPosNameList.add(item.getExternalLocation()); String externalLocation = item.getExternalLocation();
if (StringUtils.isNotEmpty(externalLocation)){
hasReelPosNameList.add(externalLocation);
}
} }
} }
} }
...@@ -125,6 +134,34 @@ public class HaoboApi extends BaseSmfApiListener { ...@@ -125,6 +134,34 @@ public class HaoboApi extends BaseSmfApiListener {
} }
} }
/**
* {
* "controllerIp": "127.0.0.1",
* "port": 5003,
* "ioBoardAddress": 82,
* "channel": 12,
* "isOpen": false
* }
* @param ioBoardAddress
* @param channel
* @param isOpen
*/
protected void controlIoBoard(int ioBoardAddress, int channel, boolean isOpen) {
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("controllerIp", "127.0.0.1");
paramMap.put("port", 5003);
paramMap.put("ioBoardAddress", ioBoardAddress);
paramMap.put("channel", channel);
paramMap.put("isOpen", isOpen);
try {
log.info("控制IO板请求参数为:" + JSON.toJSONString(paramMap));
String result = HttpHelper.postJson(controlIoBoardUrl, paramMap);
log.info("控制IO板返回结果为:" + result);
} catch (ApiException e) {
log.info("控制IO板异常:", e);
}
}
protected void lightUpSomeLampBeads(List<String> onPosNameList, List<String> offPosNameList) { protected void lightUpSomeLampBeads(List<String> onPosNameList, List<String> offPosNameList) {
// 1. 前置校验:无任何货位数据时直接返回 // 1. 前置校验:无任何货位数据时直接返回
boolean hasOnData = onPosNameList != null && !onPosNameList.isEmpty(); boolean hasOnData = onPosNameList != null && !onPosNameList.isEmpty();
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!