调度代码修改

This commit is contained in:
liuhanqing
2025-10-31 16:48:25 +08:00
parent 20075650a9
commit 1a70460257
17 changed files with 185 additions and 230 deletions

View File

@@ -0,0 +1,37 @@
package com.ruoyi.api.controller;
import com.ruoyi.api.service.ITestService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@RestController
@RequestMapping("/test")
public class TestController {
@Resource
private ITestService testService;
@GetMapping("/sendSsjData")
public String sendSsjData(Integer id) {
boolean b = testService.sendSsjData(id);
if (!b) {
return "error";
}
return "success";
}
@GetMapping("/sendDdjData")
public String sendDdjData(Integer id) {
boolean b = testService.sendDdjData(id);
if (!b) {
return "error";
}
return "success";
}
}

View File

@@ -0,0 +1,8 @@
package com.ruoyi.api.service;
public interface ITestService {
boolean sendSsjData(Integer id);
boolean sendDdjData(Integer id);
}

View File

@@ -0,0 +1,69 @@
package com.ruoyi.api.service.impl;
import com.ruoyi.api.service.ITestService;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.domain.SendData;
import com.ruoyi.device.ddj.domain.MsgDdj;
import com.ruoyi.device.ddj.mapper.MsgDdjMapper;
import com.ruoyi.device.ssj.domain.DeviceSsj;
import com.ruoyi.device.ssj.mapper.DeviceSsjMapper;
import com.ruoyi.schedule.plcRead.ssj.PlcSsjRead;
import com.ruoyi.schedule.plcRead.util.Tools;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service
public class TestServiceImpl implements ITestService {
@Resource
private MsgDdjMapper msgDdjMapper;
@Resource
private DeviceSsjMapper deviceSsjMapper;
@Override
public boolean sendDdjData(Integer id) {
MsgDdj msgDdj = msgDdjMapper.selectSendData(id);
SendData czfs = new SendData(Tools.INT, msgDdj.getCzfs());
SendData sbzt = new SendData(Tools.INT, msgDdj.getSbzt());
SendData rwh = new SendData(Tools.DINT, Convert.toInt(msgDdj.getRwh()));
SendData hczt = new SendData(Tools.INT, msgDdj.getHczt());
SendData jdbz = new SendData(Tools.INT, msgDdj.getJdbz());
SendData yph = new SendData(Tools.INT, msgDdj.getYph());
SendData ylh = new SendData(Tools.INT, msgDdj.getYlh());
SendData ych = new SendData(Tools.INT, msgDdj.getYch());
SendData mbph = new SendData(Tools.INT, msgDdj.getMbph());
SendData mblh = new SendData(Tools.INT, msgDdj.getMblh());
SendData mbch = new SendData(Tools.INT, msgDdj.getMbch());
SendData yxxf = new SendData(Tools.INT, msgDdj.getYxxf());
SendData xtxh = new SendData(Tools.INT, msgDdj.getXtxh());
SendData trayCode = new SendData(Tools.INT, Convert.toInt(msgDdj.getSpare2()));
byte[] bytes = Tools.sendData(czfs, sbzt, rwh, hczt, jdbz, yph, ylh, ych, mbph, mblh, mbch, yxxf, xtxh, trayCode);
int i = PlcSsjRead.WriteToSSJ("DB41.0", bytes);
if (i == 1) {
System.out.println("写入成功");
return true;
}
return false;
}
@Override
public boolean sendSsjData(Integer id) {
DeviceSsj deviceSsj = deviceSsjMapper.selectSendData(id);
SendData kx = new SendData(Tools.INT, deviceSsj.getKx());
SendData dw = new SendData(Tools.INT, deviceSsj.getDw());
SendData rkqq = new SendData(Tools.INT, deviceSsj.getRkqq());
SendData taskNo = new SendData(Tools.DINT, deviceSsj.getTaskNo());
byte[] bytes = Tools.sendData(kx, dw, rkqq, taskNo);
int i = PlcSsjRead.WriteToSSJ(deviceSsj.getPlcDbReadAddress(), bytes);
if (i == 1) {
System.out.println("写入成功");
return true;
}
return false;
}
}

View File

@@ -5,11 +5,11 @@ public class TaskType {
/**
* 堆垛机任务类型
*/
//1-二楼双向
//入库取货扫码
public static final int DDJ_RWLX_1 = 1;
//2-一楼单向
//入库放货
public static final int DDJ_RWLX_2 = 2;
//3-一楼双向
//出库
public static final int DDJ_RWLX_3 = 3;
}

View File

@@ -5,15 +5,15 @@ import com.ruoyi.device.ddj.domain.MsgDdj;
/**
* 堆垛机状态表Mapper接口
*
*
* @author ruoyi
* @date 2025-09-22
*/
public interface MsgDdjMapper
public interface MsgDdjMapper
{
/**
* 查询堆垛机状态表
*
*
* @param id 堆垛机状态表主键
* @return 堆垛机状态表
*/
@@ -21,7 +21,7 @@ public interface MsgDdjMapper
/**
* 查询堆垛机状态表列表
*
*
* @param msgDdj 堆垛机状态表
* @return 堆垛机状态表集合
*/
@@ -29,7 +29,7 @@ public interface MsgDdjMapper
/**
* 新增堆垛机状态表
*
*
* @param msgDdj 堆垛机状态表
* @return 结果
*/
@@ -37,7 +37,7 @@ public interface MsgDdjMapper
/**
* 修改堆垛机状态表
*
*
* @param msgDdj 堆垛机状态表
* @return 结果
*/
@@ -45,7 +45,7 @@ public interface MsgDdjMapper
/**
* 删除堆垛机状态表
*
*
* @param id 堆垛机状态表主键
* @return 结果
*/
@@ -53,9 +53,11 @@ public interface MsgDdjMapper
/**
* 批量删除堆垛机状态表
*
*
* @param ids 需要删除的数据主键集合
* @return 结果
*/
public int deleteMsgDdjByIds(Long[] ids);
MsgDdj selectSendData(Integer id);
}

View File

@@ -5,15 +5,15 @@ import com.ruoyi.device.ssj.domain.DeviceSsj;
/**
* 输送机Mapper接口
*
*
* @author ruoyi
* @date 2025-07-04
*/
public interface DeviceSsjMapper
public interface DeviceSsjMapper
{
/**
* 查询输送机
*
*
* @param id 输送机主键
* @return 输送机
*/
@@ -21,7 +21,7 @@ public interface DeviceSsjMapper
/**
* 查询输送机列表
*
*
* @param deviceSsj 输送机
* @return 输送机集合
*/
@@ -29,7 +29,7 @@ public interface DeviceSsjMapper
/**
* 新增输送机
*
*
* @param deviceSsj 输送机
* @return 结果
*/
@@ -37,7 +37,7 @@ public interface DeviceSsjMapper
/**
* 修改输送机
*
*
* @param deviceSsj 输送机
* @return 结果
*/
@@ -45,7 +45,7 @@ public interface DeviceSsjMapper
/**
* 删除输送机
*
*
* @param id 输送机主键
* @return 结果
*/
@@ -53,9 +53,11 @@ public interface DeviceSsjMapper
/**
* 批量删除输送机
*
*
* @param ids 需要删除的数据主键集合
* @return 结果
*/
public int deleteDeviceSsjByIds(Long[] ids);
DeviceSsj selectSendData(Integer id);
}

View File

@@ -109,31 +109,31 @@ public class ScheduleThread {
break;
case 2:
msgDdj.setPlcDbReadAddress("DB42.0");
PlcDdjRead plcDdjRead2 = new PlcDdjRead(ddjList, new PlcConnectInfo("127.0.0.1", 102));
PlcDdjRead plcDdjRead2 = new PlcDdjRead(ddjList, new PlcConnectInfo("127.0.0.2", 102));
Thread plcDdjReadThread2 = new Thread(plcDdjRead2);
plcDdj2ReadCustomThread = new CustomThread<PlcDdjRead>(plcDdjReadThread2, plcDdjRead2);
break;
case 3:
msgDdj.setPlcDbReadAddress("DB42.0");
PlcDdjRead plcDdjRead3 = new PlcDdjRead(ddjList, new PlcConnectInfo("127.0.0.1", 102));
PlcDdjRead plcDdjRead3 = new PlcDdjRead(ddjList, new PlcConnectInfo("127.0.0.3", 102));
Thread plcDdjReadThread3 = new Thread(plcDdjRead3);
plcDdj3ReadCustomThread = new CustomThread<PlcDdjRead>(plcDdjReadThread3, plcDdjRead3);
break;
case 4:
msgDdj.setPlcDbReadAddress("DB42.0");
PlcDdjRead plcDdjRead4 = new PlcDdjRead(ddjList, new PlcConnectInfo("127.0.0.1", 102));
PlcDdjRead plcDdjRead4 = new PlcDdjRead(ddjList, new PlcConnectInfo("127.0.0.4", 102));
Thread plcDdjReadThread4 = new Thread(plcDdjRead4);
plcDdj4ReadCustomThread = new CustomThread<PlcDdjRead>(plcDdjReadThread4, plcDdjRead4);
break;
case 5:
msgDdj.setPlcDbReadAddress("DB42.0");
PlcDdjRead plcDdjRead5 = new PlcDdjRead(ddjList, new PlcConnectInfo("127.0.0.1", 102));
PlcDdjRead plcDdjRead5 = new PlcDdjRead(ddjList, new PlcConnectInfo("127.0.0.5", 102));
Thread plcDdjReadThread5 = new Thread(plcDdjRead5);
plcDdj5ReadCustomThread = new CustomThread<PlcDdjRead>(plcDdjReadThread5, plcDdjRead5);
break;
case 6:
msgDdj.setPlcDbReadAddress("DB42.0");
PlcDdjRead plcDdjRead6 = new PlcDdjRead(ddjList, new PlcConnectInfo("127.0.0.1", 102));
PlcDdjRead plcDdjRead6 = new PlcDdjRead(ddjList, new PlcConnectInfo("127.0.0.6", 102));
Thread plcDdjReadThread6 = new Thread(plcDdjRead6);
plcDdj6ReadCustomThread = new CustomThread<PlcDdjRead>(plcDdjReadThread6, plcDdjRead6);
break;
@@ -148,11 +148,11 @@ public class ScheduleThread {
public void startAllThread() {
plcSsjReadCustomThread.getThread().start();
plcDdj1ReadCustomThread.getThread().start();
/*plcDdj2ReadCustomThread.getThread().start();
plcDdj2ReadCustomThread.getThread().start();
plcDdj3ReadCustomThread.getThread().start();
plcDdj4ReadCustomThread.getThread().start();
plcDdj5ReadCustomThread.getThread().start();
plcDdj6ReadCustomThread.getThread().start();*/
plcDdj6ReadCustomThread.getThread().start();
isRun = true;
}

View File

@@ -60,7 +60,7 @@ public class PlcDdjRead extends Thread {
Thread.currentThread().interrupt();
return;
} catch (Exception e) {
log.info("********IP:" + this.ip + " port:" + this.port + "<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>쳣 " + e.getMessage());
log.info("********IP:" + this.ip + " port:" + this.port + "端口号 " + e.getMessage());
}
}
@@ -96,9 +96,9 @@ public class PlcDdjRead extends Thread {
siemensS7Net.setPort(this.port);
siemensS7Net.setRack((byte) 0);
siemensS7Net.setSlot((byte) 1);
OperateResult connect = siemensS7Net.ConnectServer();
if (connect.IsSuccess) {
log.info("********IP:" + this.ip + " port:" + this.port + "连接成功 ");
setIsConnect(true);
readWriteNet = siemensS7Net;
}
@@ -124,7 +124,7 @@ public class PlcDdjRead extends Thread {
void reConnect() {
closeServer();
ConnectServer();
log.info("重新连接 SSJ-PLC");
log.info("重新连接 Ddj-PLC");
}
void closeServer() {

View File

@@ -28,8 +28,7 @@ import lombok.extern.slf4j.Slf4j;
import java.util.*;
import static com.ruoyi.common.TaskStatusCode.*;
import static com.ruoyi.common.TaskType.DDJ_RWLX_2;
import static com.ruoyi.common.TaskType.DDJ_RWLX_3;
import static com.ruoyi.common.TaskType.*;
@Slf4j
public abstract class BaseDdjThread implements Runnable, DdjThreadInterface {
@@ -272,7 +271,7 @@ public abstract class BaseDdjThread implements Runnable, DdjThreadInterface {
ddjDeviceExecutionQueue.setMblh(integers.get(1));
ddjDeviceExecutionQueue.setMbch(integers.get(2));
ddjDeviceExecutionQueue.setDdjxf("0");
ddjDeviceExecutionQueue.setRwlx(1);
ddjDeviceExecutionQueue.setRwlx(DDJ_RWLX_1);
ddjDeviceExecutionQueue.setScsj(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
ddjDeviceExecutionQueue.setMlfs(3);
ddjDeviceExecutionQueue.setSpare1("0");
@@ -293,10 +292,7 @@ public abstract class BaseDdjThread implements Runnable, DdjThreadInterface {
//完成作业
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(rwh, ddj.getId());
if (ObjUtil.isNotNull(ddjDeviceExecutionQueue)){
if (ddjDeviceExecutionQueue.getRwlx()==1){
//完成队列
ddjTaskFinish(rwh, ddj.getId(),2);
}else {
if (ddjDeviceExecutionQueue.getRwlx()==2 || ddjDeviceExecutionQueue.getRwlx()==3 ){
MydoJob mydoJob = mydoJobService.selectMydoJobByTaskNo(rwh);
if (ObjUtil.isNotNull(mydoJob)){
//回传完成信号
@@ -305,6 +301,17 @@ public abstract class BaseDdjThread implements Runnable, DdjThreadInterface {
}
}
}
if (ddj.getCzfs() == 5 && ddj.getSbzt() == 3 && ddj.getJdbz() == 5) {
Long rwh = ddj.getRwh();
//完成作业
DdjDeviceExecutionQueue ddjDeviceExecutionQueue = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueByRwh(rwh, ddj.getId());
if (ObjUtil.isNotNull(ddjDeviceExecutionQueue)){
if (ddjDeviceExecutionQueue.getRwlx()==1){
//完成队列
ddjTaskFinish(rwh, ddj.getId(),2);
}
}
}
/*
第二部分
@@ -392,6 +399,14 @@ public abstract class BaseDdjThread implements Runnable, DdjThreadInterface {
}
//正常下发
if (ddj.getYxxf() == 1 && ddj.getCzfs() == 5) {
DdjDeviceExecutionQueue ddjDeviceExecutionRunningQueueParam = new DdjDeviceExecutionQueue();
ddjDeviceExecutionRunningQueueParam.setDdjxf("1");
List<DdjDeviceExecutionQueue> ddjDeviceExecutionQueues1 = ddjDeviceExecutionQueueService.selectDdjDeviceExecutionQueueList(ddjDeviceExecutionRunningQueueParam);
if (CollUtil.isNotEmpty(ddjDeviceExecutionQueues1)){
log.info("正在执行任务 {}", ddjDeviceExecutionQueues1.get(0).getRwh());
return;
}
if (ddj.getSbzt() == 0) {
//无货待机 只查询入库取货扫码或者出库队列
ArrayList<Integer> rwlxList = new ArrayList<>();

View File

@@ -4,27 +4,23 @@ import com.ruoyi.job.domain.MydoJob;
import java.util.HashMap;
/**
* 堆垛机线程接口
* 定义堆垛机线程必须实现的方法
*/
public interface DdjThreadInterface {
/**
* 获取参数映射
* @param trayCode 托盘代码
* @return 参数映射
*/
HashMap<String, Object> getParamMap(String trayCode);
/**
* 获取出库任务参数
* @return 出库任务参数
*/
MydoJob getOutJobParam();
/**
* 初始化设备
*/
void init();
}
}

View File

@@ -1,183 +0,0 @@
package com.ruoyi.web.controller.tool;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
/**
* swagger 用户测试方法
*
* @author ruoyi
*/
@Api("用户信息管理")
@RestController
@RequestMapping("/test/user")
public class TestController extends BaseController
{
private final static Map<Integer, UserEntity> users = new LinkedHashMap<Integer, UserEntity>();
{
users.put(1, new UserEntity(1, "admin", "admin123", "15888888888"));
users.put(2, new UserEntity(2, "ry", "admin123", "15666666666"));
}
@ApiOperation("获取用户列表")
@GetMapping("/list")
public R<List<UserEntity>> userList()
{
List<UserEntity> userList = new ArrayList<UserEntity>(users.values());
return R.ok(userList);
}
@ApiOperation("获取用户详细")
@ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "int", paramType = "path", dataTypeClass = Integer.class)
@GetMapping("/{userId}")
public R<UserEntity> getUser(@PathVariable Integer userId)
{
if (!users.isEmpty() && users.containsKey(userId))
{
return R.ok(users.get(userId));
}
else
{
return R.fail("用户不存在");
}
}
@ApiOperation("新增用户")
@ApiImplicitParams({
@ApiImplicitParam(name = "userId", value = "用户id", dataType = "Integer", dataTypeClass = Integer.class),
@ApiImplicitParam(name = "username", value = "用户名称", dataType = "String", dataTypeClass = String.class),
@ApiImplicitParam(name = "password", value = "用户密码", dataType = "String", dataTypeClass = String.class),
@ApiImplicitParam(name = "mobile", value = "用户手机", dataType = "String", dataTypeClass = String.class)
})
@PostMapping("/save")
public R<String> save(UserEntity user)
{
if (StringUtils.isNull(user) || StringUtils.isNull(user.getUserId()))
{
return R.fail("用户ID不能为空");
}
users.put(user.getUserId(), user);
return R.ok();
}
@ApiOperation("更新用户")
@PutMapping("/update")
public R<String> update(@RequestBody UserEntity user)
{
if (StringUtils.isNull(user) || StringUtils.isNull(user.getUserId()))
{
return R.fail("用户ID不能为空");
}
if (users.isEmpty() || !users.containsKey(user.getUserId()))
{
return R.fail("用户不存在");
}
users.remove(user.getUserId());
users.put(user.getUserId(), user);
return R.ok();
}
@ApiOperation("删除用户信息")
@ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "int", paramType = "path", dataTypeClass = Integer.class)
@DeleteMapping("/{userId}")
public R<String> delete(@PathVariable Integer userId)
{
if (!users.isEmpty() && users.containsKey(userId))
{
users.remove(userId);
return R.ok();
}
else
{
return R.fail("用户不存在");
}
}
}
@ApiModel(value = "UserEntity", description = "用户实体")
class UserEntity
{
@ApiModelProperty("用户ID")
private Integer userId;
@ApiModelProperty("用户名称")
private String username;
@ApiModelProperty("用户密码")
private String password;
@ApiModelProperty("用户手机")
private String mobile;
public UserEntity()
{
}
public UserEntity(Integer userId, String username, String password, String mobile)
{
this.userId = userId;
this.username = username;
this.password = password;
this.mobile = mobile;
}
public Integer getUserId()
{
return userId;
}
public void setUserId(Integer userId)
{
this.userId = userId;
}
public String getUsername()
{
return username;
}
public void setUsername(String username)
{
this.username = username;
}
public String getPassword()
{
return password;
}
public void setPassword(String password)
{
this.password = password;
}
public String getMobile()
{
return mobile;
}
public void setMobile(String mobile)
{
this.mobile = mobile;
}
}

View File

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

View File

@@ -34,7 +34,7 @@ server:
# 日志配置
logging:
level:
com.ruoyi: info
com.ruoyi: debug
org.springframework: warn
# 用户配置

View File

@@ -54,6 +54,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectDeviceSsjVo"/>
where id = #{id}
</select>
<select id="selectSendData" resultMap="DeviceSsjResult">
select id, device_code , name , type, ip_address, plc_db_read_address, is_active, create_time, plc_db_write_address, rkqq, kx, dw, tray_code, task_no,exception,tray_size,allow_put from device_ssj_test
where id = #{id}
</select>
<insert id="insertDeviceSsj" parameterType="DeviceSsj" useGeneratedKeys="true" keyProperty="id">
insert into device_ssj

View File

@@ -58,6 +58,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectMsgDdjVo"/>
where id = #{id}
</select>
<select id="selectSendData" resultMap="MsgDdjResult">
select id, name, rwh, jdbz, sbzt, czfs, yxxf, yph, ylh, ych, mbph, mblh, mbch, xtxh, dqxd, hczt, spare1, spare2, spare3 from msg_ddj_test
where id = #{id}
</select>
<insert id="insertMsgDdj" parameterType="MsgDdj">
insert into msg_ddj

View File

@@ -60,7 +60,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</foreach>
</if>
</where>
order by scsj desc
order by scsj asc
</select>
<select id="selectDdjDeviceExecutionQueueByUuid" parameterType="String" resultMap="DdjDeviceExecutionQueueResult">

View File

@@ -119,6 +119,7 @@ public class SecurityConfig
.antMatchers("/agv/api/**").permitAll()
.antMatchers("/device/api/**").permitAll()
.antMatchers("/wcs2Wms/api/**").permitAll()
.antMatchers("/test/**").permitAll()
.antMatchers("/largeScreen/monitor/**").permitAll()
// 除上面外的所有请求全部需要鉴权认证
.anyRequest().authenticated();