Compare commits

..

9 Commits

Author SHA1 Message Date
刘汗青
52772494d4 fix(schedule): 修复重量读取逻辑及配置更新
- 更新Redis和数据库地址
- 优化重量秤数据读取与资源关闭
- 使用数据库重量并处理低于40kg的默认值
- 修复调度线程命名及查询返回类型
2026-08-31 10:31:46 +08:00
刘汗青
2272a89b2a 添加现场存活日志校验 2026-05-18 15:21:26 +08:00
刘汗青
b4ed427de9 修改出库任务优先级 2026-05-13 14:30:55 +08:00
liuhanqing
8e60b8e9c1 现场调度修改 2026-04-29 10:42:40 +08:00
liuhanqing
f2e0c086eb 现场调度修改 2026-04-13 16:48:37 +08:00
liuhanqing
c85e53ac1d 现场调度修改 2026-04-02 09:13:03 +08:00
liuhanqing
9938ca3a41 现场调度修改 2026-04-02 09:10:58 +08:00
liuhanqing
2def16ad4b 现场调度修改 2026-04-02 08:46:02 +08:00
liuhanqing
cdc8ae9e45 现场调度修改 2026-03-19 15:01:04 +08:00
18 changed files with 498 additions and 233 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

@@ -0,0 +1,21 @@
package com.ruoyi;
import com.ruoyi.schedule.ScheduleThread;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
@Component
public class MyStartupRunner implements CommandLineRunner {
@Autowired
private ScheduleThread scheduleThread;
@Override
public void run(String... args) throws Exception {
// 这里编写项目启动后要执行的方法逻辑
//System.out.println("项目启动成功后自动执行此方法");
scheduleThread.startAllThread();
scheduleThread.startAllThread2();
}
}

View File

@@ -17,5 +17,6 @@ public class ReceiveJob {
private String jobId;
private String roadwayId;
private String warehouseId;
private Long priority;
}

View File

@@ -127,4 +127,11 @@ public interface IApiService
* @return
*/
AjaxResult selectMydoJobByTrayCodeAndEntranceId(HashMap<String, Object> paramMap);
/**
* 主动获取任务
* @param jobParam
* @return
*/
AjaxResult outMyJobXf(JobParam jobParam);
}

View File

@@ -368,6 +368,7 @@ public class ApiServiceImpl implements IApiService {
mydoJob.setCreateTime(DateUtils.getNowDate());
mydoJob.setExecutionPhase("0");
mydoJob.setWarehouseId(receiveOutJob.getWarehouseId());
mydoJob.setPriority(receiveOutJob.getPriority());
int i = mydoJobService.insertMydoJob(mydoJob);
if (i > 0) {
return AjaxResult.success();
@@ -389,4 +390,15 @@ public class ApiServiceImpl implements IApiService {
}
}
@Override
public AjaxResult outMyJobXf(JobParam jobParam) {
RequestLog requestLog = requestLogService.getRequestLog(XF_OUT_JOB_URL, "出库作业下发成功", JSONUtil.toJsonStr(jobParam));
InterfaceReceive bean = JSONUtil.toBean(requestLog.getResponseBody(), InterfaceReceive.class);
if ("1".equals(requestLog.getIsSuccessful())) {
return AjaxResult.success(bean.getData());
} else {
return AjaxResult.error(bean.getMsg());
}
}
}

View File

@@ -14,6 +14,7 @@ public class Constant {
public static final String RE_ASSIGN_URL = WMS_BASE_URL+"reAssign";
public static final String RE_MATERIAL_URL = WMS_BASE_URL+"reMaterial";
public static final String REQUEST_ENTER_URL = WMS_BASE_URL+"requestEnterByTrayCodeAndEntranceId";
public static final String XF_OUT_JOB_URL = WMS_BASE_URL+"outJobStart";
public static final String WAREHOUSE_01 = "01";

View File

@@ -182,6 +182,40 @@ public class MydoJobServiceImpl implements IMydoJobService
@Override
public Map<String, List<MydoJobScreen>> selectJobListByWarehouseIdAndType(String warehouseId, String type) {
Map<String, List<MydoJobScreen>> map = new HashMap<>();
if ("01".equals(warehouseId)){
map.put("1",new ArrayList<>());
map.put("2",new ArrayList<>());
map.put("3",new ArrayList<>());
MydoJob outParam = new MydoJob();
outParam.setWarehouseId(warehouseId);
outParam.setExitId(type);
List<MydoJobScreen> outMydoJobs = mydoJobMapper.selectJobListByWarehouseIdAndType(outParam);
if (CollUtil.isNotEmpty(outMydoJobs)){
Map<String, List<MydoJobScreen>> collect = outMydoJobs.stream().collect(Collectors.groupingBy(MydoJobScreen::getRoadwayId));
for (String roadwayId : collect.keySet()) {
if (map.containsKey(roadwayId)){
List<MydoJobScreen> mydoJobs = map.get(roadwayId);
mydoJobs.addAll(collect.get(roadwayId));
map.put(roadwayId,mydoJobs);
}
}
}
MydoJob inParam = new MydoJob();
inParam.setWarehouseId(warehouseId);
inParam.setEntranceId(type);
List<MydoJobScreen> inMydoJobs = mydoJobMapper.selectJobListByWarehouseIdAndType(inParam);
if (CollUtil.isNotEmpty(inMydoJobs)) {
Map<String, List<MydoJobScreen>> collect = inMydoJobs.stream().collect(Collectors.groupingBy(MydoJobScreen::getRoadwayId));
for (String roadwayId : collect.keySet()) {
if (map.containsKey(roadwayId)){
List<MydoJobScreen> mydoJobs = map.get(roadwayId);
mydoJobs.addAll(collect.get(roadwayId));
map.put(roadwayId,mydoJobs);
}
}
}
return map;
}else {
map.put("1",new ArrayList<>());
map.put("2",new ArrayList<>());
map.put("3",new ArrayList<>());
@@ -216,8 +250,12 @@ public class MydoJobServiceImpl implements IMydoJobService
}
}
}
map.put("1",map.get("4"));
map.put("2",map.get("5"));
map.put("3",map.get("6"));
return map;
}
}
@Override
public List<MydoJob> selectOutMydoJobList(MydoJob outJobParam) {

View File

@@ -161,32 +161,40 @@ public class ScheduleThread {
* 开始线程
*/
public void startAllThread() {
if (plcSsjReadCustomThread !=null){
plcSsjReadCustomThread.getThread().setName("输送机读取线程");
plcSsjReadCustomThread.getThread().start();
}
if (plcDdj1ReadCustomThread!=null){
plcDdj1ReadCustomThread.getThread().setName("ddj1读取线程");
plcDdj1ReadCustomThread.getThread().start();
}
if (plcDdj2ReadCustomThread!=null){
plcDdj2ReadCustomThread.getThread().setName("ddj2读取线程");
plcDdj2ReadCustomThread.getThread().start();
}
if (plcDdj3ReadCustomThread!=null){
plcDdj3ReadCustomThread.getThread().setName("ddj3读取线程");
plcDdj3ReadCustomThread.getThread().start();
}
if (plcDdj4ReadCustomThread!=null){
plcDdj4ReadCustomThread.getThread().setName("ddj4读取线程");
plcDdj4ReadCustomThread.getThread().start();
}
if (plcDdj5ReadCustomThread!=null){
plcDdj5ReadCustomThread.getThread().setName("ddj5读取线程");
plcDdj5ReadCustomThread.getThread().start();
}
/*plcDdj2ReadCustomThread.getThread().start();
plcDdj3ReadCustomThread.getThread().start();
plcDdj4ReadCustomThread.getThread().start();
plcDdj5ReadCustomThread.getThread().start();
plcDdj6ReadCustomThread.getThread().start();*/
if (plcDdj6ReadCustomThread!=null){
plcDdj6ReadCustomThread.getThread().setName("ddj6读取线程");
plcDdj6ReadCustomThread.getThread().start();
}
isRun = true;
}
@@ -194,32 +202,40 @@ public class ScheduleThread {
* 开启线程2
*/
public void startAllThread2() {
if (monitoringCustomThread!=null){
monitoringCustomThread.thread.setName("监控线程");
monitoringCustomThread.thread.start();
}
if (ddj1CustomThread!=null){
ddj1CustomThread.thread.setName("ddj1调度线程");
ddj1CustomThread.thread.start();
}
if (ddj2CustomThread!=null){
ddj2CustomThread.thread.setName("ddj2调度线程");
ddj2CustomThread.thread.start();
}
if (ddj3CustomThread!=null){
ddj3CustomThread.thread.setName("ddj3调度线程");
ddj3CustomThread.thread.start();
}
if (ddj4CustomThread!=null){
ddj4CustomThread.thread.setName("ddj4调度线程");
ddj4CustomThread.thread.start();
}
if (ddj5CustomThread!=null){
ddj5CustomThread.thread.setName("ddj5调度线程");
ddj5CustomThread.thread.start();
}
/*ddj2CustomThread.thread.start();
ddj3CustomThread.thread.start();
ddj4CustomThread.thread.start();
ddj5CustomThread.thread.start();
ddj6CustomThread.thread.start();*/
if (ddj6CustomThread!=null){
ddj6CustomThread.thread.setName("ddj6调度线程");
ddj6CustomThread.thread.start();
}
isRun2 = true;
}
@@ -232,11 +248,15 @@ public class ScheduleThread {
plcDdj1ReadCustomThread.runnable.isRun = false;
plcDdj1ReadCustomThread.thread.interrupt();
plcDdj2ReadCustomThread.runnable.isRun = false;
plcDdj2ReadCustomThread.thread.interrupt();
plcDdj3ReadCustomThread.runnable.isRun = false;
plcDdj3ReadCustomThread.thread.interrupt();
plcDdj4ReadCustomThread.runnable.isRun = false;
plcDdj4ReadCustomThread.thread.interrupt();
plcDdj5ReadCustomThread.runnable.isRun = false;
plcDdj5ReadCustomThread.thread.interrupt();
plcDdj6ReadCustomThread.runnable.isRun = false;
plcDdj6ReadCustomThread.thread.interrupt();
plcReadInit();
isRun = false;
}
@@ -247,8 +267,18 @@ public class ScheduleThread {
public void stopAllThread2() {
monitoringCustomThread.runnable.isRun = false;
monitoringCustomThread.thread.interrupt();
ddj1CustomThread.runnable.isRun = false;
ddj1CustomThread.thread.interrupt();
ddj2CustomThread.runnable.isRun = false;
ddj2CustomThread.thread.interrupt();
ddj3CustomThread.runnable.isRun = false;
ddj3CustomThread.thread.interrupt();
ddj4CustomThread.runnable.isRun = false;
ddj4CustomThread.thread.interrupt();
ddj5CustomThread.runnable.isRun = false;
ddj5CustomThread.thread.interrupt();
ddj6CustomThread.runnable.isRun = false;
ddj6CustomThread.thread.interrupt();
scheduleInit();
isRun2 = false;
}

View File

@@ -37,6 +37,7 @@ public class PlcDdjRead extends Thread {
@Override
public void run() {
int i = 0;
while (isRun) {
try {
if (IsConnect()) {
@@ -45,9 +46,13 @@ public class PlcDdjRead extends Thread {
} else {
reConnect();
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
i++;
if (i==100){
log.info("读取线程执行正常");
i=0;
}
} catch (Exception e) {
log.error(e.getMessage(),e);
log.info("********IP:" + this.ip + " port:" + this.port + "端口号 " + e.getMessage());
}

View File

@@ -46,6 +46,7 @@ public class PlcSsjRead implements Runnable {
@Override
public void run() {
int i = 0;
while (isRun) {
try {
if (IsConnect()) {
@@ -72,11 +73,13 @@ public class PlcSsjRead implements Runnable {
} else {
reConnect();
}
} catch (InterruptedException e) {
// 捕获中断异常,退出循环
Thread.currentThread().interrupt(); // 重新设置中断标志
return;
i++;
if (i==100){
log.info("读取线程执行正常");
i=0;
}
} catch (Exception e) {
log.error(e.getMessage(),e);
log.info("********IP:" + this.ip + " port:" + this.port + "读取数据异常 " + e.getMessage());
}

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,37 +81,42 @@ 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);
}
@Override
public void run() {
init();
int i = 0;
while (isRun) {
try {
for (String type : ddjCodeList.keySet()) {
for (String ddjCode : ddjCodeList.get(type)) {
MsgDdj msgDdj = PlcDdjRead.deviceDdjMap.get(ddjCode);
try {
if (ObjUtil.isNotNull(msgDdj)) {
generateInBoundPickQueue(msgDdj);
generateInBoundLoadQueue(msgDdj);
generateOutBoundQueue(msgDdj);
setOutSsjStatus(msgDdj);
ddjTask(msgDdj);
} else {
log.error("堆垛机设备为空");
}
} catch (RuntimeException e) {
log.error(e.getMessage(), e);
}
}
}
try {
i++;
if (i == 100) {
log.info("ddj{},循环完成", ddjCodeList);
i = 0;
}
Thread.sleep(1500);
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
@@ -150,14 +158,14 @@ public abstract class BaseDdjThread implements Runnable, DdjThreadInterface {
switch (exitId) {
case "1":
List<DeviceSsj> outSsj1 = getDeviceSsjs("outSsj1");
if (outSsj1.stream().allMatch(ssj -> ssj.getKx() == 1 && ssj.getTaskNo() == 0 )) {
if (outSsj1.stream().allMatch(ssj -> ssj.getKx() == 1 && ssj.getTaskNo() == 0 && ddj.getHczt() == 0 && ddj.getYxxf()==1)) {
outSsj = outSsj1.get(0).getDeviceCode();
if (StrUtil.isNotEmpty(outSsj)) {
break;
}
}
List<DeviceSsj> outSsj2 = getDeviceSsjs("outSsj2");
if (outSsj2.stream().allMatch(ssj -> ssj.getKx() == 1 && ssj.getTaskNo() == 0 )) {
if (outSsj2.stream().allMatch(ssj -> ssj.getKx() == 1 && ssj.getTaskNo() == 0 && ddj.getHczt() == 0 && ddj.getYxxf()==1)) {
outSsj = outSsj2.get(0).getDeviceCode();
if (StrUtil.isNotEmpty(outSsj)) {
break;
@@ -166,14 +174,14 @@ public abstract class BaseDdjThread implements Runnable, DdjThreadInterface {
break;
case "2":
List<DeviceSsj> outSsj3 = getDeviceSsjs("outSsj3");
if (outSsj3.stream().allMatch(ssj -> ssj.getKx() == 1 && ssj.getTaskNo() == 0 )) {
if (outSsj3.stream().allMatch(ssj -> ssj.getKx() == 1 && ssj.getTaskNo() == 0 && ddj.getHczt() == 0 && ddj.getYxxf()==1)) {
outSsj = outSsj3.get(0).getDeviceCode();
if (StrUtil.isNotEmpty(outSsj)) {
break;
}
}
List<DeviceSsj> outSsj4 = getDeviceSsjs("outSsj4");
if (outSsj4.stream().allMatch(ssj -> ssj.getKx() == 1 && ssj.getTaskNo() == 0)) {
if (outSsj4.stream().allMatch(ssj -> ssj.getKx() == 1 && ssj.getTaskNo() == 0 && ddj.getHczt() == 0 && ddj.getYxxf()==1)) {
outSsj = outSsj4.get(0).getDeviceCode();
if (StrUtil.isNotEmpty(outSsj)) {
break;
@@ -257,7 +265,7 @@ public abstract class BaseDdjThread implements Runnable, DdjThreadInterface {
createRollbackQueue(ddj, 1);
} else if (!"00000000".equals(trayCode) && !"000000".equals(trayCode)) {
log.info("258- 扫码成功 trayCode:{}",trayCode);
log.info("258- 扫码成功 ddj:{} trayCode:{}",ddj.getId(),trayCode);
trayCode = trayCode.substring(trayCode.length() - 4);
MydoJob param = new MydoJob();
param.setTrayCode(trayCode);
@@ -323,7 +331,7 @@ public abstract class BaseDdjThread implements Runnable, DdjThreadInterface {
ddjDeviceExecutionQueue.setRwlx(DDJ_RWLX_2);
ddjDeviceExecutionQueue.setSpare4(trayCode);
ddjDeviceExecutionQueueService.insertDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
log.info("324- 任务生成成功 trayCode:{}",trayCode);
log.info("324- 任务生成成功 ddj:{} trayCode:{}",ddj.getId(),trayCode);
inJob.setStatus("3");
inJob.setStartTime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
@@ -419,14 +427,19 @@ public abstract class BaseDdjThread implements Runnable, DdjThreadInterface {
int rkqq = ssj.getRkqq();
if (taskNo > 0 && rkqq == 1) {
//log.info("取货任务 任务号{}",taskNo);
DdjDeviceExecutionQueue ddjQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(Convert.toLong(taskNo), ddj.getId());
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);
DdjDeviceExecutionQueue ddjQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(Convert.toLong(taskNo), ddj.getId());
if (ObjUtil.isNull(ddjQueue)) {
log.info("取货任务 任务号:{} 重量:{}",taskNo,aDouble);
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();
ddjDeviceExecutionQueue.setUuid(IdUtil.simpleUUID());
@@ -446,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) {
//写入超重信号
@@ -490,12 +503,17 @@ public abstract class BaseDdjThread implements Runnable, DdjThreadInterface {
if (ObjUtil.isNotNull(mydoJob)) {
//回传完成信号
ddjTaskFinish(rwh, ddj.getId(), 1);
log.info("堆垛机完成任务 ddj:{},taskNo:{} rwlx:{}",ddj.getId(),rwh,ddjDeviceExecutionQueue.getRwlx() );
}
} else if (ddjDeviceExecutionQueue.getRwlx() == 4) {
ddjTaskFinish(rwh, ddj.getId(), 2);
log.info("堆垛机完成任务 ddj:{},taskNo:{} rwlx:{}",ddj.getId(),rwh,ddjDeviceExecutionQueue.getRwlx() );
} else if (ddjDeviceExecutionQueue.getRwlx() == 1) {
if (hczt == 0) {
ddjTaskFinish(ddj.getRwh(), ddj.getId(), 2);
log.info("堆垛机完成任务 ddj:{},taskNo:{} rwlx:{}",ddj.getId(),rwh,ddjDeviceExecutionQueue.getRwlx());
}
}
}
@@ -526,12 +544,14 @@ public abstract class BaseDdjThread implements Runnable, DdjThreadInterface {
Long rwh = ddj.getRwh();
String trayCode = ddj.getTrayCode();
MydoJob mydoJob = mydoJobService.selectMydoJobByTaskNo(rwh);
String oldCargoSpaceId = mydoJob.getCargoSpaceId();
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(rwh, ddj.getId());
if ("0".equals(mydoJob.getFaultFlag()) && "1".equals(ddjDeviceExecutionQueue.getSpare1())) {
mydoJob.setStatus("1");
mydoJobService.updateMydoJob(mydoJob);
AjaxResult ajaxResult = apiService.reAssign(new JobParam(mydoJob.getJobId(), trayCode, ddjDeviceExecutionQueue.getRwh().toString()));
if (ajaxResult.isSuccess()) {
mydoJob = mydoJobService.selectMydoJobByTaskNo(rwh);
mydoJob.setFaultFlag("2");
mydoJobService.updateMydoJob(mydoJob);
@@ -542,6 +562,8 @@ public abstract class BaseDdjThread implements Runnable, DdjThreadInterface {
ddjDeviceExecutionQueue.setSpare1("0");
ddjDeviceExecutionQueue.setDdjxf("0");
ddjDeviceExecutionQueueService.updateDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
log.info("放货有货,重分货位 ddj:{},rwh:{} 原货位:{} 新货位:{}",ddj.getId(),rwh,oldCargoSpaceId,mydoJob.getCargoSpaceId());
}
}
}
@@ -556,12 +578,17 @@ public abstract class BaseDdjThread implements Runnable, DdjThreadInterface {
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(rwh, ddj.getId());
//找到对应任务 调用api接口 取货无货,重新分配单据
if (ObjUtil.isNotNull(ddjDeviceExecutionQueue)) {
AjaxResult ajaxResult = apiService.reMaterial(new JobParam(rwh.toString(), null, null));
MydoJob mydoJob = mydoJobService.selectMydoJobByTaskNo(rwh);
if (ObjUtil.isNotNull(mydoJob)){
AjaxResult ajaxResult = apiService.reMaterial(new JobParam(mydoJob.getJobId(), null, rwh.toString()));
if (ajaxResult.isSuccess()) {
//作废作业
InvalidMydoJob(rwh, ddj.getId());
log.info("取货无货 作废作业 ddj:{},rwh:{}",ddj.getId(),rwh);
}
}
}
}
/*
@@ -585,7 +612,7 @@ public abstract class BaseDdjThread implements Runnable, DdjThreadInterface {
ddjDeviceExecutionQueueService.updateDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
mydoJob.setFaultFlag("0");
mydoJobService.updateMydoJob(mydoJob);
log.info("托盘堆垛机重新下发任务成功 rwh:{}", rwh);
log.info("托盘堆垛机重新下发任务成功 ddj:{} rwh:{}",ddj.getId(), ddjDeviceExecutionQueue.getRwh());
} else {
log.error("托盘堆垛机重新下发任务失败!!!!!!!");
}
@@ -600,11 +627,17 @@ public abstract class BaseDdjThread implements Runnable, DdjThreadInterface {
List<DdjDeviceExecutionQueue> ddjDeviceExecutionQueues1 = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueList(ddjDeviceExecutionRunningQueueParam);
if (CollUtil.isNotEmpty(ddjDeviceExecutionQueues1)) {
log.info("正在执行任务 {}", 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;
}
if (ddj.getSbzt() == 0 && ddj.getHczt() == 0) {
if (ddj.getHczt() == 0) {
//无货待机 只查询入库取货扫码或者出库队列
ArrayList<Integer> rwlxList = new ArrayList<>();
rwlxList.add(DDJ_RWLX_1);
@@ -619,16 +652,26 @@ public abstract class BaseDdjThread implements Runnable, DdjThreadInterface {
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueues.get(0);
int i = issuedDDJTask(ddj, ddjDeviceExecutionQueue);
if (i == 1) {
if (ddjDeviceExecutionQueue.getRwlx() ==DDJ_RWLX_3){
MydoJob mydoJob = mydoJobService.selectMydoJobByTaskNo(ddjDeviceExecutionQueue.getRwh());
if (ObjUtil.isNotNull(mydoJob)){
//通知出库任务开始
AjaxResult ajaxResult = apiService.outMyJobXf(new JobParam(mydoJob.getJobId(), null, ddjDeviceExecutionQueue.getRwh().toString()));
if (ajaxResult.isSuccess()) {
log.info("通知出库任务开始成功 ddj:{},rwh:{}",ddj.getId(),ddjDeviceExecutionQueue.getRwh());
}
}
}
//更新开始时间,修改ddjxf为已下发1
ddjDeviceExecutionQueue.setXfsj(DateUtil.formatDateTime(DateUtil.date()));
ddjDeviceExecutionQueue.setDdjxf("1");
ddjDeviceExecutionQueueService.updateDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
log.info("托盘堆垛机下发任务成功 rwh:{}", ddjDeviceExecutionQueue.getRwh());
log.info("托盘堆垛机下发任务成功 ddj:{} rwh:{}",ddj.getId(), ddjDeviceExecutionQueue.getRwh());
} else {
log.error("托盘堆垛机下发任务失败!!!!!!!");
log.error("托盘堆垛机下发任务失败!!!!!!!ddj:{} rwh:{}",ddj.getId(), ddjDeviceExecutionQueue.getRwh());
}
}
} else if ((ddj.getSbzt() == 0 || ddj.getSbzt()==1047) && ddj.getHczt() == 1) {
} else if (ddj.getHczt() == 1) {
//有货待机 只查询入库放货队列和 无任务 未扫码回滚 队列
DdjDeviceExecutionQueue ddjDeviceExecutionQueueParam = new DdjDeviceExecutionQueue();
ddjDeviceExecutionQueueParam.setDdjxf("0");
@@ -646,9 +689,9 @@ public abstract class BaseDdjThread implements Runnable, DdjThreadInterface {
ddjDeviceExecutionQueue.setXfsj(DateUtil.formatDateTime(DateUtil.date()));
ddjDeviceExecutionQueue.setDdjxf("1");
ddjDeviceExecutionQueueService.updateDdjDeviceExecutionQueue(ddjDeviceExecutionQueue);
log.info("托盘堆垛机下发任务成功 rwh:{}", ddjDeviceExecutionQueue.getRwh());
log.info("托盘堆垛机下发任务成功 ddj:{} rwh:{}",ddj.getId(), ddjDeviceExecutionQueue.getRwh());
} else {
log.error("托盘堆垛机下发任务失败!!!!!!!");
log.error("托盘堆垛机下发任务失败!!!!!!ddj:{} rwh:{}",ddj.getId(), ddjDeviceExecutionQueue.getRwh());
}
}
}

View File

@@ -43,20 +43,32 @@ public class Ddj5Thread extends BaseDdjThread {
ssjList.put("outSsj2", outSsj2);
//初始化巷道口 排 列 层
roadwayMap.put("L1003", Arrays.asList(1, 1, 1));
roadwayMap.put("L1004", Arrays.asList(2, 1, 1));
roadwayMap.put("L1003", Arrays.asList(1, 0, 1));
roadwayMap.put("L1004", Arrays.asList(2, 0, 1));
//未扫码 回退任务号 无入库任务在此基础+100
roadwayRollback.put("L1003", 94);
roadwayRollback.put("L1004", 95);
//初始化称重设备连接ip port
czRoadwayMap.put("L1003", "172.19.40.216:4001");
czRoadwayMap.put("L1004", "172.19.40.217:4001");
/*czOverMap.put("L1003", "DB502.12");
czOverMap.put("L1004", "DB502.26");*/
outJobMap.put("L1003", "DB502.38");
outJobMap.put("L1004", "DB502.52");
log.info("Ddj5Thread init");
}
@Override
public HashMap<String, Object> getParamMap(String trayCode,Integer height,double weight) {
HashMap<String, Object> paramMap = new HashMap<>();
paramMap.put("trayCode", trayCode);
paramMap.put("warehouseId",WAREHOUSE_02);
paramMap.put("roadwayId",ROADWAY_ID_02);
paramMap.put("roadwayId",ROADWAY_ID_05);
paramMap.put("height",height);
paramMap.put("weight",weight);
return paramMap;
@@ -66,7 +78,7 @@ public class Ddj5Thread extends BaseDdjThread {
public MydoJob getOutJobParam() {
MydoJob mydoJob = new MydoJob();
mydoJob.setWarehouseId(WAREHOUSE_02);
mydoJob.setRoadwayId(String.valueOf(ROADWAY_ID_02));
mydoJob.setRoadwayId(String.valueOf(ROADWAY_ID_05));
mydoJob.setStatus("1");
return mydoJob;

View File

@@ -43,11 +43,22 @@ public class Ddj6Thread extends BaseDdjThread {
ssjList.put("outSsj2", outSsj2);
//初始化巷道口 排 列 层
roadwayMap.put("L1005", Arrays.asList(1, 1, 1));
roadwayMap.put("L1006", Arrays.asList(2, 1, 1));
roadwayMap.put("L1005", Arrays.asList(1, 0, 1));
roadwayMap.put("L1006", Arrays.asList(2, 0, 1));
//未扫码 回退任务号 无入库任务在此基础+100
roadwayRollback.put("L1005", 96);
roadwayRollback.put("L1006", 97);
//初始化称重设备连接ip port
czRoadwayMap.put("L1005", "172.19.40.218:4001");
czRoadwayMap.put("L1006", "172.19.40.219:4001");
/*czOverMap.put("L1003", "DB502.12");
czOverMap.put("L1004", "DB502.26");*/
outJobMap.put("L1005", "DB502.66");
outJobMap.put("L1006", "DB502.80");
log.info("Ddj6Thread init");
}
@@ -57,10 +68,9 @@ public class Ddj6Thread extends BaseDdjThread {
HashMap<String, Object> paramMap = new HashMap<>();
paramMap.put("trayCode", trayCode);
paramMap.put("warehouseId",WAREHOUSE_02);
paramMap.put("roadwayId",ROADWAY_ID_03);
paramMap.put("roadwayId",ROADWAY_ID_06);
paramMap.put("height",height);
paramMap.put("weight",weight);
return paramMap;
}
@@ -68,7 +78,7 @@ public class Ddj6Thread extends BaseDdjThread {
public MydoJob getOutJobParam() {
MydoJob mydoJob = new MydoJob();
mydoJob.setWarehouseId(WAREHOUSE_02);
mydoJob.setRoadwayId(String.valueOf(ROADWAY_ID_03));
mydoJob.setRoadwayId(String.valueOf(ROADWAY_ID_06));
mydoJob.setStatus("1");
return mydoJob;
@@ -86,4 +96,5 @@ public class Ddj6Thread extends BaseDdjThread {
return "1";
}
}

View File

@@ -45,14 +45,18 @@ public class MonitoringThread implements Runnable {
@Override
public void run() {
init();
int i =0;
while (isRun){
try {
for (String ssjCode : PlcSsjRead.deviceSsjMap.keySet()) {
try {
DeviceSsj deviceSsj = PlcSsjRead.deviceSsjMap.get(ssjCode);
deviceSsjService.updateDeviceSsj(deviceSsj);
int taskNo = deviceSsj.getTaskNo();
//输送机外形异常 101-前超长 102-后超长 103-左超宽 104-右超宽 105-超高 106-超重
if (deviceSsj.getException() >= 101 && deviceSsj.getException() <= 106 && deviceSsj.getTaskNo()>0) {
if (deviceSsj.getException() >= 101 && deviceSsj.getException() <= 120 && deviceSsj.getTaskNo()>0) {
BasFaultRecord param = new BasFaultRecord();
param.setTaskNo(Convert.toStr(deviceSsj.getTaskNo()));
param.setDeviceId(Convert.toStr(deviceSsj.getDeviceCode()));
@@ -88,6 +92,53 @@ public class MonitoringThread implements Runnable {
}
}
if (taskNo >= 50 && taskNo < 200) {
//扫码失败+0 无任务+100 无货位+20 已存在当前托盘+40
/*
"L2001", 80 "L2002", 81 "L2007", 82 "L2008", 83 "L2003", 84 "L2004", 85
"L2009", 86 "L2010", 87 "L2005", 88 "L2006", 89 "L2011", 90 "L2012", 91
"L1001", 92 "L1002", 93 "L1003", 94 "L1004", 95 "L1005", 96 "L1006", 97
*/
String trayCode = null;
if (taskNo>100){
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(Convert.toLong(taskNo), Convert.toInt(deviceSsj.getId()));
if (ObjUtil.isNotNull(ddjDeviceExecutionQueue)) {
trayCode = ddjDeviceExecutionQueue.getSpare4();
}
}
BasFaultRecord param = new BasFaultRecord();
param.setTaskNo(Convert.toStr(taskNo));
param.setDeviceId(ssjCode);
param.setJobId("0");
List<BasFaultRecord> basFaultRecords = basFaultRecordService.selectBasFaultRecordList(param);
if (CollUtil.isEmpty(basFaultRecords)) {
BasFaultRecord record = new BasFaultRecord();
record.setId(IdUtil.simpleUUID());
record.setDeviceId(ssjCode);
record.setDeviceName(ssjCode);
record.setDeviceType("ssj");
record.setTaskNo(Convert.toStr(taskNo));
record.setStartTime(DateUtil.formatDateTime(new Date()));
if (taskNo >= 80 && taskNo <= 97) {
//扫码失败
record.setFault(getDdjZt(107, trayCode));
} else if (taskNo >= 100 && taskNo < 120) {
//无货位
record.setFault(getDdjZt(108, trayCode));
} else if (taskNo >= 120 && taskNo < 140) {
//已存在当前托盘
record.setFault(getDdjZt(109, trayCode));
} else {
//无任务
record.setFault(getDdjZt(110, trayCode));
}
record.setJobId("0");
basFaultRecordService.insertBasFaultRecord(record);
}
}
//取走托盘 恢复异常
if (deviceSsj.getTaskNo() == 0 && deviceSsj.getKx() == 1) {
//查询记录 更新故障结束时间
@@ -102,8 +153,13 @@ public class MonitoringThread implements Runnable {
basFaultRecordService.updateBasFaultRecord(record);
}
}
} catch (Exception e) {
log.error(e.getMessage(),e);
}
}
for (String ddjCode : PlcDdjRead.deviceDdjMap.keySet()) {
try {
MsgDdj msgDdj = PlcDdjRead.deviceDdjMap.get(ddjCode);
msgDdjService.updateMsgDdj(msgDdj);
//记录异常
@@ -142,49 +198,15 @@ public class MonitoringThread implements Runnable {
basFaultRecordService.updateBasFaultRecord(record);
}
}
if (msgDdj.getRwh() >= 50 && msgDdj.getRwh() < 200) {
//扫码失败+0 无任务+100 无货位+20 已存在当前托盘+40
long taskNo = msgDdj.getRwh();
/*
"L2001", 80 "L2002", 81 "L2007", 82 "L2008", 83 "L2003", 84 "L2004", 85
"L2009", 86 "L2010", 87 "L2005", 88 "L2006", 89 "L2011", 90 "L2012", 91
"L1001", 92 "L1002", 93 "L1003", 94 "L1004", 95 "L1005", 96 "L1006", 97
*/
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(taskNo, msgDdj.getId());
if (ObjUtil.isNotNull(ddjDeviceExecutionQueue)) {
String trayCode = ddjDeviceExecutionQueue.getSpare4();
BasFaultRecord param = new BasFaultRecord();
param.setTaskNo(Convert.toStr(msgDdj.getRwh()));
param.setDeviceId(Convert.toStr(ddjDeviceExecutionQueue.getSpare2()));
param.setJobId("0");
List<BasFaultRecord> basFaultRecords = basFaultRecordService.selectBasFaultRecordList(param);
if (CollUtil.isEmpty(basFaultRecords)) {
BasFaultRecord record = new BasFaultRecord();
record.setId(IdUtil.simpleUUID());
record.setDeviceId(param.getDeviceName());
record.setDeviceName(param.getDeviceName());
record.setDeviceType("ssj");
record.setTaskNo(Convert.toStr(taskNo));
record.setStartTime(DateUtil.formatDateTime(new Date()));
if (taskNo >= 80 && taskNo <= 97) {
//扫码失败
record.setFault(getDdjZt(107, trayCode));
} else if (taskNo >= 100 && taskNo < 120) {
//无货位
record.setFault(getDdjZt(108, trayCode));
} else if (taskNo >= 120 && taskNo < 140) {
//已存在当前托盘
record.setFault(getDdjZt(109, trayCode));
} else {
//无任务
record.setFault(getDdjZt(110, trayCode));
}
record.setJobId("0");
basFaultRecordService.insertBasFaultRecord(record);
}
} catch (Exception e) {
log.error(e.getMessage(),e);
}
}
i++;
if (i==100){
log.info("监控线程循环完成");
i=0;
}
Thread.sleep(1500);
} catch (Exception e) {
@@ -208,7 +230,13 @@ public class MonitoringThread implements Runnable {
return "超高";
} else if (value == 106) {
return "超重";
} else {
} else if (value==112){
return "输送超时";
}else if (value==113){
return "变频器报警";
}else if (value==114){
return "开关异常";
}else {
return "未知";
}
}

View File

@@ -1,57 +1,100 @@
package com.ruoyi.schedule.util;
import cn.hutool.core.convert.Convert;
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;
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();
) {
Thread.sleep(100);
byte[] bytes = new byte[10];
int read = is.read(bytes);
if (read!=-1){
String weight = byteArrayToCharArray(bytes, "UTF-8");
weight = weight.substring(1,8);
weight = weight.replace("=","");
Socket socket = null;
InputStream is = null;
try {
socket = new Socket();
socket.connect(new InetSocketAddress(ip, por), 1000);
socket.setSoTimeout(10000);
is = socket.getInputStream();
if (weight.length() == 7 && !weight.equals("0000000")) {
byte[] clearBuf = new byte[4096];
long endClearTime = System.currentTimeMillis() + 800;
while (System.currentTimeMillis() < endClearTime) {
if (is.available() > 0) {
is.read(clearBuf);
} else {
Thread.sleep(50);
}
}
Thread.sleep(200);
byte[] bytes = new byte[256];
int read = is.read(bytes);
if (read != -1) {
String[] weightList = byteArrayToCharArray(bytes, "UTF-8").split("\r\n");
System.out.println(Arrays.toString(weightList));
String weight = getMostFrequentByHutool(weightList);
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;
}
/**
* 将byte数组按指定编码转为char数组
* @param byteArr 输入的byte数组
* @param charset 字符编码(如UTF-8、GBK、ASCII)
* @return 转换后的char数组
* @throws UnsupportedEncodingException 编码不支持时抛出
*/
public static String getMostFrequentByHutool(String[] strArray) {
if (strArray == null || strArray.length == 0) {
return null;
}
List<String> strList = CollUtil.newArrayList(strArray);
Map<String, Integer> countMap = CollUtil.countMap(strList);
String mostFrequent = null;
int maxCount = 0;
for (Map.Entry<String, Integer> entry : countMap.entrySet()) {
if (entry.getValue() > maxCount) {
maxCount = entry.getValue();
mostFrequent = entry.getKey();
}
}
return mostFrequent;
}
public static String byteArrayToCharArray(byte[] byteArr, String charset) throws UnsupportedEncodingException {
if (byteArr == null) {
return null;
}
// 核心:先将byte数组按指定编码转为String,再转为char数组
return new String(byteArr, charset);
}
public static void main(String[] args) {
CheckWeight checkWeight = new CheckWeight();
System.out.println(checkWeight.sendWeight("172.19.50.75", 4001));
System.out.println(sendWeight("172.19.50.75", 4001));
}
}

View File

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

View File

@@ -249,5 +249,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and status = #{status}
and roadway_id = #{roadwayId}
and warehouse_id = #{warehouseId}
order by priority desc,create_time asc
</select>
</mapper>

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>