fix(schedule): 修复重量读取逻辑及配置更新

- 更新Redis和数据库地址
- 优化重量秤数据读取与资源关闭
- 使用数据库重量并处理低于40kg的默认值
- 修复调度线程命名及查询返回类型
This commit is contained in:
刘汗青
2026-08-31 10:31:46 +08:00
parent 2272a89b2a
commit 52772494d4
5 changed files with 67 additions and 39 deletions

View File

@@ -130,6 +130,14 @@
<warName>${project.artifactId}</warName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>9</source>
<target>9</target>
</configuration>
</plugin>
</plugins>
<finalName>${project.artifactId}</finalName>
</build>

View File

@@ -212,7 +212,7 @@ public class ScheduleThread {
}
if (ddj2CustomThread!=null){
ddj2CustomThread.thread.setName("ddj5调度线程");
ddj2CustomThread.thread.setName("ddj2调度线程");
ddj2CustomThread.thread.start();
}

View File

@@ -14,6 +14,8 @@ import com.ruoyi.bas.cargospace.service.IBasCargoSpaceService;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.domain.SendData;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.device.cz.domain.SsjWeightInfo;
import com.ruoyi.device.cz.service.ISsjWeightInfoService;
import com.ruoyi.device.ddj.domain.MsgDdj;
import com.ruoyi.device.ddj.service.IMsgDdjService;
import com.ruoyi.device.ssj.domain.DeviceSsj;
@@ -46,6 +48,7 @@ public abstract class BaseDdjThread implements Runnable, DdjThreadInterface {
private IMsgDdjService msgDdjService;
private IMydoJobService mydoJobService;
private IBasCargoSpaceService basCargoSpaceService;
private ISsjWeightInfoService ssjWeightInfoService;
public Map<String, List<Integer>> roadwayMap = new HashMap<>();
private PlcDdjRead plcDdjRead;
private PlcSsjRead plcSsjRead;
@@ -78,6 +81,7 @@ public abstract class BaseDdjThread implements Runnable, DdjThreadInterface {
basCargoSpaceService = SpringUtils.getBean(IBasCargoSpaceService.class);
msgDdjService = SpringUtils.getBean(IMsgDdjService.class);
mydoJobService = SpringUtils.getBean(IMydoJobService.class);
ssjWeightInfoService = SpringUtils.getBean(ISsjWeightInfoService.class);
log.info("初始化服务 {},{},{},{}", apiService, ddjDeviceExecutionQueueService, ddjDeviceExecutionQueueFinishService, mydoJobService);
}
@@ -86,11 +90,11 @@ public abstract class BaseDdjThread implements Runnable, DdjThreadInterface {
init();
int i = 0;
while (isRun) {
for (String type : ddjCodeList.keySet()) {
try {
for (String type : ddjCodeList.keySet()) {
for (String ddjCode : ddjCodeList.get(type)) {
MsgDdj msgDdj = PlcDdjRead.deviceDdjMap.get(ddjCode);
try {
for (String ddjCode : ddjCodeList.get(type)) {
MsgDdj msgDdj = PlcDdjRead.deviceDdjMap.get(ddjCode);
if (ObjUtil.isNotNull(msgDdj)) {
generateInBoundPickQueue(msgDdj);
generateInBoundLoadQueue(msgDdj);
@@ -101,21 +105,18 @@ public abstract class BaseDdjThread implements Runnable, DdjThreadInterface {
} else {
log.error("堆垛机设备为空");
}
} catch (RuntimeException e) {
log.error(e.getMessage(), e);
}
}
}
}
i++;
if (i==100){
log.info("ddj{},循环完成",ddjCodeList);
i=0;
}
try {
i++;
if (i == 100) {
log.info("ddj{},循环完成", ddjCodeList);
i = 0;
}
Thread.sleep(1500);
} catch (InterruptedException e) {
log.error(e.getMessage(),e);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
@@ -433,6 +434,11 @@ public abstract class BaseDdjThread implements Runnable, DdjThreadInterface {
String[] split = czDeviceIpPort.split(":");
String weight = CheckWeight.sendWeight(split[0], Convert.toInt(split[1]));
Double aDouble = Convert.toDouble(weight);
if (aDouble<40){
aDouble = 40d;
}
SsjWeightInfo ssjWeightInfo = ssjWeightInfoService.selectWeightBySsjCodeAndRwh(taskNo, ssj.getDeviceCode());
aDouble = ssjWeightInfo.getWeight().doubleValue();
log.info("取货任务 ddj:{} 任务号:{} 重量:{}",ddj.getId(),taskNo,aDouble);
if (aDouble > 0 && aDouble < 1500) {
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = new DdjDeviceExecutionQueue();
@@ -453,7 +459,7 @@ public abstract class BaseDdjThread implements Runnable, DdjThreadInterface {
ddjDeviceExecutionQueue.setScsj(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
ddjDeviceExecutionQueue.setMlfs(3);
ddjDeviceExecutionQueue.setSpare1("0");
ddjDeviceExecutionQueue.setSpare3(Convert.toStr(weight));
ddjDeviceExecutionQueue.setSpare3(Convert.toStr(aDouble));
ddjDeviceExecutionQueueService.insertDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
} /*else if (aDouble>=1500) {
//写入超重信号

View File

@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.Arrays;
import java.util.List;
@@ -12,18 +13,17 @@ import java.util.Map;
public class CheckWeight {
public static String sendWeight(String ip, int por) {
String zhi = "0";
try (
Socket socket = new Socket(ip, por);
InputStream is = socket.getInputStream();
) {
// ====================== 【安全清空历史,不会死循环】 ======================
// 只清空 300ms 内收到的历史数据
// 时间到立刻停止清空,开始读最新重量
byte[] clearBuf = new byte[4096];
long endClearTime = System.currentTimeMillis() + 800; // 最多清300毫秒
Socket socket = null;
InputStream is = null;
try {
socket = new Socket();
socket.connect(new InetSocketAddress(ip, por), 1000);
socket.setSoTimeout(10000);
is = socket.getInputStream();
byte[] clearBuf = new byte[4096];
long endClearTime = System.currentTimeMillis() + 800;
while (System.currentTimeMillis() < endClearTime) {
if (is.available() > 0) {
is.read(clearBuf);
@@ -31,9 +31,7 @@ public class CheckWeight {
Thread.sleep(50);
}
}
// ========================================================================
// 清空完成 → 读取最新数据
Thread.sleep(200);
byte[] bytes = new byte[256];
int read = is.read(bytes);
@@ -41,15 +39,31 @@ public class CheckWeight {
String[] weightList = byteArrayToCharArray(bytes, "UTF-8").split("\r\n");
System.out.println(Arrays.toString(weightList));
String weight = getMostFrequentByHutool(weightList);
weight = weight.replace("=", "").replace("\r", "").replace("\n", "");
if (!weight.equals("0000000")) {
zhi = weight;
if (weight != null) {
weight = weight.replace("=", "").replace("\r", "").replace("\n", "");
if (!weight.equals("0000000")) {
zhi = weight;
}
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
// finally手动关闭流和socket
try {
if (is != null) {
is.close();
}
} catch (Exception ignored) {
ignored.printStackTrace();
}
try {
if (socket != null) {
socket.close();
}
} catch (Exception ignored) {
ignored.printStackTrace();
}
}
return zhi;
}

View File

@@ -84,10 +84,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectDdjDeviceExecutionQueueVo"/>
where rwh = #{rwh} and dev_id = #{devId}
</select>
<select id="selectOutJobCount">
select count(*) from ddj_device_execution_queue
where spare2=#{spare2}
<select id="selectOutJobCount" resultType="java.lang.Integer">
select count(*)
from ddj_device_execution_queue
where spare2 = #{spare2}
</select>