Commit aba8c3ce authored by wanghao's avatar wanghao

1 管理界面 老化层 下料 去 生成 下料命令;同时 清理 定时任务

parent ceef2411
......@@ -37,6 +37,8 @@ public interface RobotArmCommandMapper
public List<RobotArmCommand> selectTopRunningRobotArmCommands();
public RobotArmCommand findNotCompletedCommand(String command);
public List<RobotArmCommand> findByType(String type);
/**
......
......@@ -20,6 +20,8 @@ public interface TStoreyInfoMapper
*/
public TStoreyInfo selectTStoreyInfoById(Long fStoreyId);
public TStoreyInfo selectByBlankingCommand(String blankingCommand);
/**
* 查询老化层信息
*
......
......@@ -77,6 +77,10 @@ public interface IRobotArmCommandService
void completeCommand(Long commandId);
public int findNotCompletedCommand(String command);
void generateBlankingCommand(String trayCode,String storeyCode,String command);
void sendHomeCommand();
void sendStopCommand();
......
......@@ -56,7 +56,6 @@ public class RobotArmCommandServiceImpl implements IRobotArmCommandService
@Resource
private TStoreyInfoMapper storeyInfoMapper;
@Resource
private TEquipmentInfoMapper equipmentInfoMapper;;
......@@ -146,7 +145,7 @@ public class RobotArmCommandServiceImpl implements IRobotArmCommandService
throw new RuntimeException(e);
}
}
// 如果是料,则 先把 t_story_info 设置为 运行中,占上位置,避免此时 再上料 是使用重复位置
// 如果是料,则 先把 t_story_info 设置为 运行中,占上位置,避免此时 再上料 是使用重复位置
} else {
TStoreyInfo tStoreyInfo = new TStoreyInfo();
tStoreyInfo.setfStoreyCode(command.getStoreyCode());
......@@ -180,24 +179,7 @@ public class RobotArmCommandServiceImpl implements IRobotArmCommandService
address,
"HOME"
);
List<RobotArmCommand> robotArmCommands = robotArmCommandMapper.selectTopRunningRobotArmCommands();
if(robotArmCommands.size() > 0) {
robotArmCommands.forEach(command -> {
command.setStatus("4");
command.setEndExecutionTime(new Date());
robotArmCommandMapper.updateRobotArmCommand(command);
});
for (RobotArmCommand robotArmCommand : robotArmCommands) {
String trayCode = robotArmCommand.getTrayCode();
String storeyCode = robotArmCommand.getStoreyCode();
}
}
initializationTrayAndStoreyInfo();
}
@Override
......@@ -209,6 +191,45 @@ public class RobotArmCommandServiceImpl implements IRobotArmCommandService
address,
"STOP"
);
initializationTrayAndStoreyInfo();
}
/**
* 回零 或 停止 时 初始化托盘和层信息
*/
private void initializationTrayAndStoreyInfo() {
List<RobotArmCommand> robotArmCommands = robotArmCommandMapper.selectTopRunningRobotArmCommands();
if(robotArmCommands.size() > 0) {
RobotArmCommand robotArmCommand = robotArmCommands.get(0);
robotArmCommand.setStatus("4");
robotArmCommand.setEndExecutionTime(new Date());
robotArmCommandMapper.updateRobotArmCommand(robotArmCommand);
String trayCode = robotArmCommand.getTrayCode();
String storeyCode = robotArmCommand.getStoreyCode();
// 如果是上料的话
TStoreyInfo tStoreyInfo = new TStoreyInfo();
if("0".equals(robotArmCommand.getType())) {
tStoreyInfo.setfStoreyCode(storeyCode);
tStoreyInfo.setfStatus("0");
tStoreyInfo.setUpdateTime(new Date());
storeyInfoMapper.updateStatusByCode(tStoreyInfo);
// 如果是下料的话 得把 下料的 流程走完
} else {
tStoreyInfo.setfStoreyCode(tStoreyInfo.getfStoreyCode());
tStoreyInfo.setUpdateTime(new Date());
tStoreyInfo.setfStatus("0");
tStoreyInfo.setfAgingStartTime(null);
tStoreyInfo.setfAgingEndTime(null);
storeyInfoMapper.unbindByCode(tStoreyInfo);
// 清理 托盘 和 层的关联关系
tTrayInfoMapper.clearStoreyCodeByStoreyCode(storeyCode);
}
}
}
/**
......@@ -224,6 +245,33 @@ public class RobotArmCommandServiceImpl implements IRobotArmCommandService
);
}
/**
* 生成下料指令
* @param command c
*/
@Override
public void generateBlankingCommand(String trayCode,String storeyCode,String command) {
// 创建机械臂任务
RobotArmCommand robotArmCommand = new RobotArmCommand();
robotArmCommand.setType("1");
robotArmCommand.setStatus("1");
robotArmCommand.setTrayCode(trayCode);
robotArmCommand.setStoreyCode(storeyCode);
robotArmCommand.setCreateTime(new Date());
robotArmCommand.setCommand(command);
robotArmCommandMapper.insertRobotArmCommand(robotArmCommand);
notifyCommandsUpdate();
}
@Override
public int findNotCompletedCommand(String command) {
RobotArmCommand notCompletedCommand = robotArmCommandMapper.findNotCompletedCommand(command);
if(notCompletedCommand != null) {
return 1;
}
return 0;
}
@Override
@Transactional
public void completeCommand(Long commandId) {
......
......@@ -9,13 +9,20 @@ import com.zehong.common.utils.DateUtils;
import com.zehong.common.utils.StringUtils;
import com.zehong.system.domain.TEquipmentInfo;
import com.zehong.system.domain.TStoreyInfo;
import com.zehong.system.domain.TTrayInfo;
import com.zehong.system.mapper.TEquipmentInfoMapper;
import com.zehong.system.mapper.TStoreyInfoMapper;
import com.zehong.system.mapper.TTrayInfoMapper;
import com.zehong.system.modbus.business.DeviceStatusReaderAndTimeSetter;
import com.zehong.system.modbus.handler.ModbusResultHandler;
import com.zehong.system.modbus.util.Modbus4jUtils;
import com.zehong.system.service.IRobotArmCommandService;
import com.zehong.system.service.ITStoreyInfoService;
import com.zehong.system.service.websocket.RobotArmWebSocketHandler;
import com.zehong.system.task.DeviceTaskScheduler;
import org.quartz.JobKey;
import org.quartz.SchedulerException;
import org.quartz.TriggerKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -41,6 +48,9 @@ public class TStoreyInfoServiceImpl implements ITStoreyInfoService
@Resource
private TStoreyInfoMapper tStoreyInfoMapper;
@Resource
private TTrayInfoMapper tTrayInfoMapper;
@Resource
private TEquipmentInfoMapper equipmentInfoMapper;
......@@ -48,10 +58,7 @@ public class TStoreyInfoServiceImpl implements ITStoreyInfoService
private IRobotArmCommandService robotArmCommandService;
@Resource
private DeviceStatusReaderAndTimeSetter deviceStatusReaderAndTimeSetter;
@Autowired
private ModbusResultHandler modbusResultHandler;
private DeviceTaskScheduler deviceTaskScheduler;
private final ExecutorService executorService = Executors.newFixedThreadPool(10);
......@@ -256,13 +263,35 @@ public class TStoreyInfoServiceImpl implements ITStoreyInfoService
}
/**
* 批量关灯
* 发送下料指令
* @return r
*/
@Override
public AjaxResult handleBlanking(String command) {
// 发送UDP指令
robotArmCommandService.sendCommand(command);
// 先不直接发送指令,而是 先生成 下料指令,去 提高 下料指令的效率
// robotArmCommandService.sendCommand(command);
int notCompletedCommand = robotArmCommandService.findNotCompletedCommand(command);
if(notCompletedCommand > 0) {
return AjaxResult.error("有未完成指令,请稍后再试");
} else {
// 根据指令 去查 老化层
TStoreyInfo tStoreyInfo = tStoreyInfoMapper.selectByBlankingCommand(command);
TTrayInfo tTrayInfo = tTrayInfoMapper.selectTTrayInfoByStoreyCode(tStoreyInfo.getfStoreyCode());
//还得去把没执行的 定时任务删掉,否则会导致 再次 发送下料指令
try {
deviceTaskScheduler.cleanExistingTasks(tStoreyInfo.getfStoreyId());
} catch (SchedulerException e) {
return AjaxResult.error("定时任务异常,请联系管理员");
}
if(tTrayInfo != null) {
robotArmCommandService.generateBlankingCommand(tTrayInfo.getfTrayCode(), tStoreyInfo.getfStoreyCode(), command);
}
}
return AjaxResult.success();
}
......
......@@ -82,7 +82,7 @@ public class DeviceTaskScheduler {
/**
* 清理已存在的任务 - 修复版本
*/
private void cleanExistingTasks(Long fStoreyId) throws SchedulerException {
public void cleanExistingTasks(Long fStoreyId) throws SchedulerException {
// 清理所有与这个fStoreyId相关的任务
Set<JobKey> jobKeys = scheduler.getJobKeys(GroupMatcher.jobGroupEquals(JOB_GROUP));
for (JobKey jobKey : jobKeys) {
......
......@@ -12,6 +12,7 @@ import com.zehong.system.mapper.RobotArmCommandMapper;
import com.zehong.system.mapper.TStoreyInfoMapper;
import com.zehong.system.mapper.TTrayInfoMapper;
import com.zehong.system.modbus.util.Modbus4jUtils;
import com.zehong.system.service.IRobotArmCommandService;
import com.zehong.system.service.ITEquipmentAlarmDataService;
import com.zehong.system.service.ITStoreyInfoService;
import com.zehong.system.service.websocket.RobotArmWebSocketHandler;
......@@ -46,7 +47,8 @@ public class FinalExecutionJob implements Job {
private Scheduler scheduler;
@Resource
private RobotArmCommandMapper robotArmCommandMapper;
private IRobotArmCommandService robotArmCommandService;
@Override
public void execute(JobExecutionContext context) {
// 1. 初始化变量,避免空指针
......@@ -127,7 +129,7 @@ public class FinalExecutionJob implements Job {
// cleanUpJobs(fStoreyId,context);
// 8. 发送机械臂指令(单独捕获异常)
try {
createRoboticArm(tStoreyInfo.getfTrayCode(), storeyCode, tStoreyInfo.getBlankingCommand());
robotArmCommandService.generateBlankingCommand(tStoreyInfo.getfTrayCode(), storeyCode, tStoreyInfo.getBlankingCommand());
log.info("机械臂指令发送完成:fStoreyId={}", fStoreyId);
} catch (Exception e) {
log.error("机械臂指令发送异常:fStoreyId={}", fStoreyId, e);
......@@ -175,19 +177,6 @@ public class FinalExecutionJob implements Job {
}
}
private void createRoboticArm(String trayCode,String storeyCode,String command) {
// 创建机械臂任务
RobotArmCommand robotArmCommand = new RobotArmCommand();
robotArmCommand.setType("1");
robotArmCommand.setStatus("1");
robotArmCommand.setTrayCode(trayCode);
robotArmCommand.setStoreyCode(storeyCode);
robotArmCommand.setCreateTime(new Date());
robotArmCommand.setCommand(command);
robotArmCommandMapper.insertRobotArmCommand(robotArmCommand);
notifyCommandsUpdate();
}
private void cleanUpJobs(Long fStoreyId,JobExecutionContext context) throws SchedulerException {
// 清理通信任务
JobKey commJobKey = new JobKey("COMM_" + fStoreyId, "DEVICE_TASKS");
......
......@@ -50,7 +50,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectRobotArmCommandVo"/>
where f_status = '2'
</select>
<select id="findNotCompletedCommand" resultMap="RobotArmCommandResult">
<include refid="selectRobotArmCommandVo"/>
where f_command = #{command} and f_status != '4'
</select>
<select id="selectRobotArmCommandById" parameterType="Long" resultMap="RobotArmCommandResult">
<include refid="selectRobotArmCommandVo"/>
where f_robot_arm_command_id = #{robotArmCommandId}
......
......@@ -76,6 +76,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectTStoreyInfoVo"/>
where f_storey_id = #{fStoreyId}
</select>
<select id="selectByBlankingCommand" parameterType="string" resultMap="TStoreyInfoResult">
<include refid="selectTStoreyInfoVo"/>
where storeyInfo.f_blanking_command = #{blankingCommand}
</select>
<select id="selectTStoreyInfoByCode" parameterType="String" resultMap="TStoreyInfoResult">
<include refid="selectTStoreyInfoVo"/>
......
......@@ -121,7 +121,7 @@ export default {
// 初始化WebSocket连接
initWebSocket() {
// 从环境变量获取基础URL,默认使用Nginx代理地址
const backendUrl = process.env.VUE_APP_API_BASE_URL || 'http://localhost:8082';
const backendUrl = process.env.VUE_APP_API_BASE_URL || 'http://localhost:8087';
// 根据需要切换不同的WebSocket端点
const wsPath = '/agecal/ws-aging-cabinet'; // 或 '/agecal/ws-aging-cabinet'
......
......@@ -230,7 +230,7 @@ export default {
methods: {
initWebSocket() {
// 从环境变量获取基础URL,默认使用Nginx代理地址
const backendUrl = process.env.VUE_APP_API_BASE_URL || 'http://localhost:8082';
const backendUrl = process.env.VUE_APP_API_BASE_URL || 'http://localhost:8087';
// 根据需要切换不同的WebSocket端点
const wsPath = '/agecal/ws-robot-arm'; // 或 '/agecal/ws-aging-cabinet'
......
......@@ -138,6 +138,8 @@
<el-tag type="danger" v-else-if="scope.row.fStatus === '2'">故障</el-tag>
<!-- 断电状态 - 橙色(warning) -->
<el-tag type="warning" v-else-if="scope.row.fStatus === '3'">断电</el-tag>
<!-- 老化完成 - 橙色(primary) -->
<el-tag type="primary" v-else-if="scope.row.fStatus === '4'">老化完成</el-tag>
</template>
</el-table-column>
<el-table-column label="报警时间" align="center" prop="fAlarmTime" width="180">
......@@ -444,7 +446,7 @@ export default {
return blanking(row.blankingCommand);
}).then(() => {
this.getList();
this.msgSuccess("上电成功");
this.msgSuccess("下料成功");
}).catch(() => {});
},
// 断电
......
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