现场调度修改

This commit is contained in:
liuhanqing
2026-04-13 16:48:37 +08:00
parent c85e53ac1d
commit f2e0c086eb
3 changed files with 37 additions and 38 deletions

View File

@@ -419,13 +419,13 @@ public abstract class BaseDdjThread implements Runnable, DdjThreadInterface {
int rkqq = ssj.getRkqq(); int rkqq = ssj.getRkqq();
if (taskNo > 0 && rkqq == 1) { if (taskNo > 0 && rkqq == 1) {
//log.info("取货任务 任务号{}",taskNo); //log.info("取货任务 任务号{}",taskNo);
//todo 连接称重 并保存数据
String czDeviceIpPort = czRoadwayMap.get(ssj.getDeviceCode());
String[] split = czDeviceIpPort.split(":");
String weight = CheckWeight.sendWeight(split[0], Convert.toInt(split[1]));
Double aDouble = Convert.toDouble(weight);
DdjDeviceExecutionQueue ddjQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(Convert.toLong(taskNo), ddj.getId()); DdjDeviceExecutionQueue ddjQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(Convert.toLong(taskNo), ddj.getId());
if (ObjUtil.isNull(ddjQueue)) { if (ObjUtil.isNull(ddjQueue)) {
//todo 连接称重 并保存数据
String czDeviceIpPort = czRoadwayMap.get(ssj.getDeviceCode());
String[] split = czDeviceIpPort.split(":");
String weight = CheckWeight.sendWeight(split[0], Convert.toInt(split[1]));
Double aDouble = Convert.toDouble(weight);
log.info("取货任务 ddj:{} 任务号:{} 重量:{}",ddj.getId(),taskNo,aDouble); log.info("取货任务 ddj:{} 任务号:{} 重量:{}",ddj.getId(),taskNo,aDouble);
if (aDouble > 0 && aDouble < 1500) { if (aDouble > 0 && aDouble < 1500) {
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = new DdjDeviceExecutionQueue(); DdjDeviceExecutionQueue ddjDeviceExecutionQueue = new DdjDeviceExecutionQueue();
@@ -614,7 +614,13 @@ public abstract class BaseDdjThread implements Runnable, DdjThreadInterface {
List<DdjDeviceExecutionQueue> ddjDeviceExecutionQueues1 = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueList(ddjDeviceExecutionRunningQueueParam); List<DdjDeviceExecutionQueue> ddjDeviceExecutionQueues1 = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueList(ddjDeviceExecutionRunningQueueParam);
if (CollUtil.isNotEmpty(ddjDeviceExecutionQueues1)) { if (CollUtil.isNotEmpty(ddjDeviceExecutionQueues1)) {
log.info("ddj:{} 正在执行任务 {}",ddj.getId(), ddjDeviceExecutionQueues1.get(0).getRwh()); log.info("ddj:{} 已下发任务号 {} ddj当前任务号 {}",ddj.getId(), ddjDeviceExecutionQueues1.get(0).getRwh(),ddj.getRwh());
if (!ddj.getRwh().equals(ddjDeviceExecutionQueues1.get(0).getRwh())){
int i = issuedDDJTask(ddj, ddjDeviceExecutionQueues1.get(0));
if (i == 1) {
log.info("ddj:{} 重新下发任务 {}",ddj.getId(), ddjDeviceExecutionQueues1.get(0).getRwh());
}
}
return; return;
} }

View File

@@ -1,7 +1,6 @@
package com.ruoyi.schedule.util; package com.ruoyi.schedule.util;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import java.io.InputStream; import java.io.InputStream;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
@@ -19,14 +18,30 @@ public class CheckWeight {
Socket socket = new Socket(ip, por); Socket socket = new Socket(ip, por);
InputStream is = socket.getInputStream(); InputStream is = socket.getInputStream();
) { ) {
Thread.sleep(1000); // ====================== 【安全清空历史,不会死循环】 ======================
byte[] bytes = new byte[100]; // 只清空 300ms 内收到的历史数据
// 时间到立刻停止清空,开始读最新重量
byte[] clearBuf = new byte[4096];
long endClearTime = System.currentTimeMillis() + 1000; // 最多清300毫秒
while (System.currentTimeMillis() < endClearTime) {
if (is.available() > 0) {
is.read(clearBuf);
} else {
Thread.sleep(5);
}
}
// ========================================================================
// 清空完成 → 读取最新数据
Thread.sleep(100);
byte[] bytes = new byte[256];
int read = is.read(bytes); int read = is.read(bytes);
if (read!=-1){ if (read != -1) {
String[] weightList = byteArrayToCharArray(bytes, "UTF-8").split("\r\n"); String[] weightList = byteArrayToCharArray(bytes, "UTF-8").split("\r\n");
System.out.println(Arrays.toString(weightList)); System.out.println(Arrays.toString(weightList));
String weight = getMostFrequentByHutool(weightList); String weight = getMostFrequentByHutool(weightList);
weight = weight.replace("=","").replace("\r","").replace("\n",""); weight = weight.replace("=", "").replace("\r", "").replace("\n", "");
if (!weight.equals("0000000")) { if (!weight.equals("0000000")) {
zhi = weight; zhi = weight;
@@ -38,57 +53,34 @@ public class CheckWeight {
} }
return zhi; return zhi;
} }
/**
* 用 Hutool 找出数组中出现次数最多的字符串
* @param strArray 目标字符串数组
* @return 出现次数最多的字符串(空数组返回 null,多最大值返回第一个)
*/
/**
* 兼容所有 Hutool 版本:找出数组中出现次数最多的字符串
* @param strArray 目标字符串数组
* @return 出现次数最多的字符串(空数组返回 null,多最大值返回第一个)
*/
public static String getMostFrequentByHutool(String[] strArray) { public static String getMostFrequentByHutool(String[] strArray) {
// 1. 空值校验 + 数组转 List
if (strArray == null || strArray.length == 0) { if (strArray == null || strArray.length == 0) {
return null; return null;
} }
List<String> strList = CollUtil.newArrayList(strArray); List<String> strList = CollUtil.newArrayList(strArray);
// 2. 用 Hutool 统计频次(所有版本都支持)
Map<String, Integer> countMap = CollUtil.countMap(strList); Map<String, Integer> countMap = CollUtil.countMap(strList);
// 3. 手动遍历找最大值(替代不存在的 getMaxKey 方法)
String mostFrequent = null; String mostFrequent = null;
int maxCount = 0; int maxCount = 0;
// 遍历 Map 条目,Hutool 5.x 及以上都支持 entrySet 遍历
for (Map.Entry<String, Integer> entry : countMap.entrySet()) { for (Map.Entry<String, Integer> entry : countMap.entrySet()) {
if (entry.getValue() > maxCount) { if (entry.getValue() > maxCount) {
maxCount = entry.getValue(); maxCount = entry.getValue();
mostFrequent = entry.getKey(); mostFrequent = entry.getKey();
} }
} }
return mostFrequent; return mostFrequent;
} }
/**
* 将byte数组按指定编码转为char数组
* @param byteArr 输入的byte数组
* @param charset 字符编码(如UTF-8、GBK、ASCII)
* @return 转换后的char数组
* @throws UnsupportedEncodingException 编码不支持时抛出
*/
public static String byteArrayToCharArray(byte[] byteArr, String charset) throws UnsupportedEncodingException { public static String byteArrayToCharArray(byte[] byteArr, String charset) throws UnsupportedEncodingException {
if (byteArr == null) { if (byteArr == null) {
return null; return null;
} }
// 核心:先将byte数组按指定编码转为String,再转为char数组
return new String(byteArr, charset); return new String(byteArr, charset);
} }
public static void main(String[] args) { public static void main(String[] args) {
CheckWeight checkWeight = new CheckWeight(); System.out.println(sendWeight("172.19.50.75", 4001));
System.out.println(checkWeight.sendWeight("172.19.50.75", 4001));
} }
} }

View File

@@ -6,7 +6,8 @@ spring:
druid: druid:
#主数据信息 #主数据信息
master: master:
url: jdbc:sqlserver://172.19.1.119:1433;databaseName=FT541-wcs; # url: jdbc:sqlserver://172.19.1.119:1433;databaseName=FT541-wcs;
url: jdbc:sqlserver://172.19.1.119:1433;databaseName=FT541-wcs-2;
username: sa username: sa
password: Flrd0914. password: Flrd0914.
# 从库数据源 # 从库数据源