Commit 55246658 authored by wanghao's avatar wanghao

1 扫码绑定托盘,上料,机械臂整体测试

parent e9aecf8a
...@@ -10,9 +10,9 @@ import com.zehong.system.domain.modbus.ModbusDeviceData; ...@@ -10,9 +10,9 @@ import com.zehong.system.domain.modbus.ModbusDeviceData;
import com.zehong.system.modbus.util.Modbus4jUtils; import com.zehong.system.modbus.util.Modbus4jUtils;
import com.zehong.system.service.ITEquipmentAlarmDataService; import com.zehong.system.service.ITEquipmentAlarmDataService;
import com.zehong.system.service.ITEquipmentInfoService; import com.zehong.system.service.ITEquipmentInfoService;
import com.zehong.web.task.AgingCabinetInspectionAndPowerCheckTask; import com.zehong.system.task.AgingCabinetInspectionAndPowerCheckTask;
import com.zehong.web.task.CheckPowerOnCommandEvent; import com.zehong.system.task.CheckPowerOnCommandEvent;
import com.zehong.web.task.PowerOffCommandEvent; import com.zehong.system.task.PowerOffCommandEvent;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisher;
......
...@@ -27,6 +27,12 @@ ...@@ -27,6 +27,12 @@
<artifactId>spring-boot-configuration-processor</artifactId> <artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<!-- 定时任务-->
<dependency>
<groupId>com.zehong</groupId>
<artifactId>zhmes-agecal-quartz</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>
\ No newline at end of file
...@@ -20,6 +20,8 @@ public interface TEquipmentInfoMapper ...@@ -20,6 +20,8 @@ public interface TEquipmentInfoMapper
*/ */
public TEquipmentInfo selectTEquipmentInfoById(Long fEquipmentId); public TEquipmentInfo selectTEquipmentInfoById(Long fEquipmentId);
public TEquipmentInfo selectTEquipmentInfoByCode(String fEquipmentCode);
/** /**
* 查询生产设备信息列表 * 查询生产设备信息列表
* *
......
...@@ -27,6 +27,8 @@ public interface TStoreyInfoMapper ...@@ -27,6 +27,8 @@ public interface TStoreyInfoMapper
*/ */
public TStoreyInfo selectTStoreyInfoByCode(String fStoreyCode); public TStoreyInfo selectTStoreyInfoByCode(String fStoreyCode);
public void unbindByCode(TStoreyInfo tStoreyInfo);
// 新增方法:查询离机械臂最近的空闲层 // 新增方法:查询离机械臂最近的空闲层
public TStoreyInfo selectNearestFreeStorey(); public TStoreyInfo selectNearestFreeStorey();
/** /**
......
...@@ -47,6 +47,7 @@ public interface TTrayInfoMapper ...@@ -47,6 +47,7 @@ public interface TTrayInfoMapper
*/ */
public int updateTTrayInfo(TTrayInfo tTrayInfo); public int updateTTrayInfo(TTrayInfo tTrayInfo);
public int unbindByCode(TTrayInfo tTrayInfo);
/** /**
* 删除托盘信息 * 删除托盘信息
* *
......
...@@ -8,17 +8,21 @@ import java.util.Date; ...@@ -8,17 +8,21 @@ import java.util.Date;
import java.util.List; import java.util.List;
import com.zehong.common.utils.DateUtils; import com.zehong.common.utils.DateUtils;
import com.zehong.common.utils.StringUtils; import com.zehong.common.utils.StringUtils;
import com.zehong.system.domain.TEquipmentInfo;
import com.zehong.system.domain.TStoreyInfo; import com.zehong.system.domain.TStoreyInfo;
import com.zehong.system.domain.TTrayInfo; import com.zehong.system.domain.TTrayInfo;
import com.zehong.system.mapper.TEquipmentInfoMapper;
import com.zehong.system.mapper.TStoreyInfoMapper; import com.zehong.system.mapper.TStoreyInfoMapper;
import com.zehong.system.mapper.TTrayInfoMapper; import com.zehong.system.mapper.TTrayInfoMapper;
import com.zehong.system.modbus.util.Modbus4jUtils; import com.zehong.system.modbus.util.Modbus4jUtils;
import com.zehong.system.netty.handler.NettyUdpServerHandler; import com.zehong.system.netty.handler.NettyUdpServerHandler;
import com.zehong.system.service.websocket.RobotArmWebSocketHandler; import com.zehong.system.service.websocket.RobotArmWebSocketHandler;
import com.zehong.system.task.CheckPowerOnCommandEvent;
import com.zehong.system.udp.UdpCommandSender; import com.zehong.system.udp.UdpCommandSender;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.zehong.system.mapper.RobotArmCommandMapper; import com.zehong.system.mapper.RobotArmCommandMapper;
import com.zehong.system.domain.RobotArmCommand; import com.zehong.system.domain.RobotArmCommand;
...@@ -50,6 +54,9 @@ public class RobotArmCommandServiceImpl implements IRobotArmCommandService ...@@ -50,6 +54,9 @@ public class RobotArmCommandServiceImpl implements IRobotArmCommandService
@Resource @Resource
private TStoreyInfoMapper storeyInfoMapper; private TStoreyInfoMapper storeyInfoMapper;
@Resource
private TEquipmentInfoMapper equipmentInfoMapper;;
@Resource @Resource
private TTrayInfoMapper tTrayInfoMapper; private TTrayInfoMapper tTrayInfoMapper;
...@@ -61,6 +68,9 @@ public class RobotArmCommandServiceImpl implements IRobotArmCommandService ...@@ -61,6 +68,9 @@ public class RobotArmCommandServiceImpl implements IRobotArmCommandService
@Value("${robot.arm.udp.port}") @Value("${robot.arm.udp.port}")
private int robotArmPort; private int robotArmPort;
@Resource
private ApplicationEventPublisher eventPublisher; // 新增事件发布器
private SocketAddress getRobotAddress() { private SocketAddress getRobotAddress() {
try { try {
return new InetSocketAddress( return new InetSocketAddress(
...@@ -131,10 +141,46 @@ public class RobotArmCommandServiceImpl implements IRobotArmCommandService ...@@ -131,10 +141,46 @@ public class RobotArmCommandServiceImpl implements IRobotArmCommandService
// 发送上电指令 // 发送上电指令
try { try {
// 发送上电指令给机械臂 // 上料的指令 需要去上电
String udpMessage = String.format("POWER_ON,%s,%s", command.getTrayCode(), command.getStoreyCode()); if("0".equals(command.getType())){
udpCommandSender.sendCommandThrowError(udpMessage); // 发送上电指令给机械臂
String storeyCode = command.getStoreyCode();
String equitmentCode = "";
Integer registerOffset = null;
if(storeyCode.contains("-")) {
String[] parts = storeyCode.split("-");
equitmentCode = parts[0];
registerOffset = Integer.parseInt(parts[1]);
TEquipmentInfo tEquipmentInfo = equipmentInfoMapper.selectTEquipmentInfoByCode(equitmentCode);
if(tEquipmentInfo != null) {
String powerOutageIp = tEquipmentInfo.getfPowerOutageIp();
Integer powerOutagePort = tEquipmentInfo.getfPowerOutagePort();
if(StringUtils.isNotBlank(powerOutageIp) && powerOutagePort != null) {
eventPublisher.publishEvent(new CheckPowerOnCommandEvent(
this,
equitmentCode,
powerOutageIp,
powerOutagePort,
registerOffset
));
}
}
}
// 下料的话 得解除 托盘 和 层的绑定关系
} else {
TStoreyInfo tStoreyInfo = new TStoreyInfo();
tStoreyInfo.setfStoreyCode(command.getStoreyCode());
tStoreyInfo.setUpdateTime(new Date());
storeyInfoMapper.unbindByCode(tStoreyInfo);
TTrayInfo tTrayInfo = new TTrayInfo();
tTrayInfo.setfTrayCode(command.getTrayCode());
tTrayInfo.setUpdateTime(new Date());
tTrayInfo.setfUnbindingTime(new Date());
tTrayInfoMapper.unbindByCode(tTrayInfo);
}
command.setStatus("4"); command.setStatus("4");
log.info("指令执行成功,状态设置为4"); log.info("指令执行成功,状态设置为4");
} catch (Exception e) { } catch (Exception e) {
......
package com.zehong.web.task; package com.zehong.system.task;
import com.serotonin.modbus4j.ModbusMaster; import com.serotonin.modbus4j.ModbusMaster;
import com.serotonin.modbus4j.exception.ErrorResponseException; import com.serotonin.modbus4j.exception.ErrorResponseException;
...@@ -15,7 +15,6 @@ import org.slf4j.Logger; ...@@ -15,7 +15,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.context.request.async.DeferredResult;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.*; import java.util.*;
......
package com.zehong.web.task; package com.zehong.system.task;
import com.serotonin.modbus4j.ModbusMaster; import com.serotonin.modbus4j.ModbusMaster;
import com.serotonin.modbus4j.exception.ErrorResponseException; import com.serotonin.modbus4j.exception.ErrorResponseException;
......
package com.zehong.web.task; package com.zehong.system.task;
import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEvent;
......
package com.zehong.web.task; package com.zehong.system.task;
import com.zehong.system.domain.TEquipmentAlarmData; import com.zehong.system.domain.TEquipmentAlarmData;
import com.zehong.system.domain.TStoreyInfo; import com.zehong.system.domain.TStoreyInfo;
import com.zehong.system.mapper.TStoreyInfoMapper; import com.zehong.system.mapper.TStoreyInfoMapper;
......
package com.zehong.web.task; package com.zehong.system.task;
import org.quartz.*; import org.quartz.*;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.Instant; import java.time.Instant;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.Date; import java.util.Date;
...@@ -19,7 +19,7 @@ import java.util.Date; ...@@ -19,7 +19,7 @@ import java.util.Date;
public class DeviceTaskScheduler { public class DeviceTaskScheduler {
private static final Logger log = LoggerFactory.getLogger(DeviceTaskScheduler.class); private static final Logger log = LoggerFactory.getLogger(DeviceTaskScheduler.class);
@Autowired @Resource
private Scheduler scheduler; private Scheduler scheduler;
/** /**
* 创建设备监控任务 * 创建设备监控任务
......
package com.zehong.web.task; package com.zehong.system.task;
import com.serotonin.modbus4j.ModbusMaster; import com.serotonin.modbus4j.ModbusMaster;
import com.serotonin.modbus4j.exception.ModbusInitException; import com.serotonin.modbus4j.exception.ModbusInitException;
import com.serotonin.modbus4j.exception.ModbusTransportException; import com.serotonin.modbus4j.exception.ModbusTransportException;
import com.zehong.common.utils.StringUtils; import com.zehong.common.utils.StringUtils;
import com.zehong.system.domain.RobotArmCommand;
import com.zehong.system.domain.TEquipmentAlarmData; import com.zehong.system.domain.TEquipmentAlarmData;
import com.zehong.system.domain.TStoreyInfo; import com.zehong.system.domain.TStoreyInfo;
import com.zehong.system.mapper.RobotArmCommandMapper;
import com.zehong.system.mapper.TStoreyInfoMapper; import com.zehong.system.mapper.TStoreyInfoMapper;
import com.zehong.system.modbus.util.Modbus4jUtils; import com.zehong.system.modbus.util.Modbus4jUtils;
import com.zehong.system.service.ITEquipmentAlarmDataService; import com.zehong.system.service.ITEquipmentAlarmDataService;
...@@ -13,10 +15,10 @@ import com.zehong.system.service.ITStoreyInfoService; ...@@ -13,10 +15,10 @@ import com.zehong.system.service.ITStoreyInfoService;
import org.quartz.*; import org.quartz.*;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Date;
/** /**
* @author lenovo * @author lenovo
...@@ -34,8 +36,11 @@ public class FinalExecutionJob implements Job { ...@@ -34,8 +36,11 @@ public class FinalExecutionJob implements Job {
@Resource @Resource
private TStoreyInfoMapper tStoreyInfoMapper; private TStoreyInfoMapper tStoreyInfoMapper;
@Autowired @Resource
private Scheduler scheduler; private Scheduler scheduler;
@Resource
private RobotArmCommandMapper robotArmCommandMapper;
@Override @Override
public void execute(JobExecutionContext context) { public void execute(JobExecutionContext context) {
JobDataMap data = context.getJobDetail().getJobDataMap(); JobDataMap data = context.getJobDetail().getJobDataMap();
...@@ -69,6 +74,9 @@ public class FinalExecutionJob implements Job { ...@@ -69,6 +74,9 @@ public class FinalExecutionJob implements Job {
// 3. 清理相关任务 // 3. 清理相关任务
cleanUpJobs(fStoreyId,context); cleanUpJobs(fStoreyId,context);
// 4. 发送 下料指令
createRoboticArm(tStoreyInfo.getfTrayCode(),tStoreyInfo.getfStoreyCode());
log.info("设备[{}]最终业务逻辑执行完成", fStoreyId); log.info("设备[{}]最终业务逻辑执行完成", fStoreyId);
} catch (Exception e) { } catch (Exception e) {
// 记录异常 // 记录异常
...@@ -79,7 +87,17 @@ public class FinalExecutionJob implements Job { ...@@ -79,7 +87,17 @@ public class FinalExecutionJob implements Job {
alarmDataService.insertTEquipmentAlarmData(alarmData); alarmDataService.insertTEquipmentAlarmData(alarmData);
} }
} }
}
private void createRoboticArm(String trayCode,String storeyCode) {
// 创建机械臂任务
RobotArmCommand robotArmCommand = new RobotArmCommand();
robotArmCommand.setType("1");
robotArmCommand.setStatus("1");
robotArmCommand.setTrayCode(trayCode);
robotArmCommand.setStoreyCode(storeyCode);
robotArmCommand.setCreateTime(new Date());
robotArmCommandMapper.insertRobotArmCommand(robotArmCommand);
} }
private void cleanUpJobs(String deviceId,JobExecutionContext context) throws SchedulerException { private void cleanUpJobs(String deviceId,JobExecutionContext context) throws SchedulerException {
......
package com.zehong.web.task; package com.zehong.system.task;
import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEvent;
......
...@@ -66,6 +66,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -66,6 +66,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectTEquipmentInfoVo"/> <include refid="selectTEquipmentInfoVo"/>
where f_equipment_id = #{fEquipmentId} where f_equipment_id = #{fEquipmentId}
</select> </select>
<select id="selectTEquipmentInfoByCode" parameterType="string" resultMap="TEquipmentInfoResult">
<include refid="selectTEquipmentInfoVo"/>
where f_equipment_code = #{fEquipmentCode}
</select>
<insert id="insertTEquipmentInfo" parameterType="TEquipmentInfo" useGeneratedKeys="true" keyProperty="fEquipmentId"> <insert id="insertTEquipmentInfo" parameterType="TEquipmentInfo" useGeneratedKeys="true" keyProperty="fEquipmentId">
insert into t_equipment_info insert into t_equipment_info
......
...@@ -128,6 +128,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -128,6 +128,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where f_storey_id = #{fStoreyId} where f_storey_id = #{fStoreyId}
</update> </update>
<update id="unbindByCode" parameterType="TStoreyInfo">
update t_storey_info
<trim prefix="SET" suffixOverrides=",">
<if test="fStatus != null">f_status = #{fStatus},</if>
<if test="fAgingStartTime == null">f_aging_start_time = null,</if>
<if test="fUpdateTime != null">f_update_time = #{fUpdateTime},</if>
</trim>
where f_storey_code = #{fStoreyCode}
</update>
<delete id="deleteTStoreyInfoById" parameterType="Long"> <delete id="deleteTStoreyInfoById" parameterType="Long">
delete from t_storey_info where f_storey_id = #{fStoreyId} delete from t_storey_info where f_storey_id = #{fStoreyId}
</delete> </delete>
......
...@@ -98,6 +98,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -98,6 +98,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where f_tray_id = #{fTrayId} where f_tray_id = #{fTrayId}
</update> </update>
<update id="unbindByCode" parameterType="TTrayInfo">
update t_tray_info
set f_storey_code = null,
f_status = 2,
f_unbinding_time = #{fUnbindingTime}
where f_tray_code = #{fTrayCode}
</update>
<delete id="deleteTTrayInfoById" parameterType="Long"> <delete id="deleteTTrayInfoById" parameterType="Long">
delete from t_tray_info where f_tray_id = #{fTrayId} delete from t_tray_info where f_tray_id = #{fTrayId}
</delete> </delete>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment