20260416:给轮训任务添加执行时间(临时优化之后可撤销)
This commit is contained in:
parent
acea720181
commit
30a8100d64
@ -50,7 +50,7 @@ spring:
|
|||||||
host: 47.121.180.229 # 地址
|
host: 47.121.180.229 # 地址
|
||||||
port: 6379 # 端口,默认为6379
|
port: 6379 # 端口,默认为6379
|
||||||
database: 0 # 数据库索引
|
database: 0 # 数据库索引
|
||||||
password: fastbee # 密码
|
password: Yan@ancekong2026 # 密码
|
||||||
timeout: 10s # 连接超时时间
|
timeout: 10s # 连接超时时间
|
||||||
lettuce:
|
lettuce:
|
||||||
pool:
|
pool:
|
||||||
|
|||||||
@ -102,7 +102,7 @@ public class DevicePropFetchConsumer {
|
|||||||
//通过mqtt内部客户端 下发指令
|
//通过mqtt内部客户端 下发指令
|
||||||
case MQTT:
|
case MQTT:
|
||||||
publish(topic, commandData);
|
publish(topic, commandData);
|
||||||
log.info("=>MQTT-线程=[{}],轮询指令:[{}],主题:[{}]", Thread.currentThread().getName(), command, topic);
|
log.info("=>MQTT-线程=[{}],设备=[{}],轮询指令:[{}],主题:[{}]", Thread.currentThread().getName(), serialNumber, command, topic);
|
||||||
break;
|
break;
|
||||||
// 下发TCP客户端
|
// 下发TCP客户端
|
||||||
case TCP:
|
case TCP:
|
||||||
@ -110,13 +110,18 @@ public class DevicePropFetchConsumer {
|
|||||||
msg.setClientId(serialNumber);
|
msg.setClientId(serialNumber);
|
||||||
msg.setPayload(Unpooled.wrappedBuffer(commandData));
|
msg.setPayload(Unpooled.wrappedBuffer(commandData));
|
||||||
messageManager.requestR(serialNumber, msg, Message.class);
|
messageManager.requestR(serialNumber, msg, Message.class);
|
||||||
log.info("=>TCP-线程=[{}],轮询指令:[{}]", Thread.currentThread().getName(), command);
|
log.info("=>TCP-线程=[{}],设备=[{}],轮询指令:[{}]", Thread.currentThread().getName(), serialNumber, command);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// 指令间隔时间
|
// 指令间隔时间
|
||||||
Thread.sleep(3000);
|
Thread.sleep(3000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 临时:仅定时轮询有 deviceJob/jobId;手动下发不更新(避免 NPE)
|
||||||
|
if (Objects.equals(type, 2) && deviceJob.getJobId() != null) {
|
||||||
|
modbusJobService.updateTaskExecuteTime(deviceJob.getJobId());
|
||||||
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("线程错误e", e);
|
log.error("线程错误e", e);
|
||||||
} finally {
|
} finally {
|
||||||
@ -136,21 +141,12 @@ public class DevicePropFetchConsumer {
|
|||||||
handleSubDeviceStatus(modbusJobList);
|
handleSubDeviceStatus(modbusJobList);
|
||||||
List<String> commandList = modbusJobList.stream().map(ModbusJob::getCommand).collect(Collectors.toList());
|
List<String> commandList = modbusJobList.stream().map(ModbusJob::getCommand).collect(Collectors.toList());
|
||||||
|
|
||||||
// 检查是否有设备上电触发任务(cycleType=3)
|
|
||||||
// boolean hasPowerOnTrigger = modbusJobList.stream()
|
|
||||||
// .anyMatch(job -> job.getCycleType() != null && job.getCycleType() == 3);
|
|
||||||
|
|
||||||
// modbus-tcp 重新处理事务标识符
|
// modbus-tcp 重新处理事务标识符
|
||||||
String subSerialNumber = modbusJobList.get(0).getSubSerialNumber();
|
String subSerialNumber = modbusJobList.get(0).getSubSerialNumber();
|
||||||
String tcpKey = RedisKeyBuilder.buildModbusTcpCacheKey(subSerialNumber);
|
String tcpKey = RedisKeyBuilder.buildModbusTcpCacheKey(subSerialNumber);
|
||||||
String tcpObject = redisCache.getStrCacheObject(tcpKey);
|
String tcpObject = redisCache.getStrCacheObject(tcpKey);
|
||||||
List<String> tcpCommandList = new ArrayList<>();
|
List<String> tcpCommandList = new ArrayList<>();
|
||||||
|
|
||||||
// 如果是设备上电触发任务(cycleType=3),跳过事务ID处理,直接使用原始指令
|
|
||||||
// if (hasPowerOnTrigger) {
|
|
||||||
// log.info("检测到设备上电触发任务(cycleType=3),跳过事务ID处理,使用原始指令");
|
|
||||||
// tcpCommandList.addAll(commandList);
|
|
||||||
// } else
|
|
||||||
if (StringUtils.isNotEmpty(tcpObject)) {
|
if (StringUtils.isNotEmpty(tcpObject)) {
|
||||||
// 原有的事务ID处理逻辑
|
// 原有的事务ID处理逻辑
|
||||||
String tcpRuntimeCacheKey = RedisKeyBuilder.buildModbusTcpRuntimeCacheKey(subSerialNumber);
|
String tcpRuntimeCacheKey = RedisKeyBuilder.buildModbusTcpRuntimeCacheKey(subSerialNumber);
|
||||||
|
|||||||
@ -6,8 +6,8 @@ import org.quartz.JobExecutionContext;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 定时任务处理(禁止并发执行)
|
* 定时任务处理(禁止并发执行)
|
||||||
*
|
* 串行定时任务调度器
|
||||||
* @author ruoyi
|
* @author sumuxi, 2026-04-16
|
||||||
*/
|
*/
|
||||||
@DisallowConcurrentExecution
|
@DisallowConcurrentExecution
|
||||||
public class DeviceDisallowConcurrentExecution extends DeviceAbstractQuartzJob {
|
public class DeviceDisallowConcurrentExecution extends DeviceAbstractQuartzJob {
|
||||||
|
|||||||
@ -5,8 +5,8 @@ import org.quartz.JobExecutionContext;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 定时任务处理(允许并发执行)
|
* 定时任务处理(允许并发执行)
|
||||||
*
|
* 并发调度器
|
||||||
* @author ruoyi
|
* @author sumuxi, 2026-04-16
|
||||||
*/
|
*/
|
||||||
public class DeviceJobExecution extends DeviceAbstractQuartzJob {
|
public class DeviceJobExecution extends DeviceAbstractQuartzJob {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -44,6 +44,11 @@ public interface ModbusJobMapper {
|
|||||||
*/
|
*/
|
||||||
public int updateModbusJob(ModbusJob modbusJob);
|
public int updateModbusJob(ModbusJob modbusJob);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按设备定时任务 job_id 批量更新执行时间(排除上电触发 cycle_type=3)
|
||||||
|
*/
|
||||||
|
int updateTaskExecuteTime(ModbusJob modbusJob);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 清空执行时间
|
* 清空执行时间
|
||||||
*
|
*
|
||||||
|
|||||||
@ -69,4 +69,11 @@ public interface IModbusJobService {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<ModbusJob> selectDevicesJobByDeviceType(DeviceType deviceType, String serialNumber);
|
List<ModbusJob> selectDevicesJobByDeviceType(DeviceType deviceType, String serialNumber);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新任务执行时间
|
||||||
|
*
|
||||||
|
* @param jobId 任务ID
|
||||||
|
*/
|
||||||
|
void updateTaskExecuteTime(Long jobId);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,6 +24,7 @@ import org.springframework.util.CollectionUtils;
|
|||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -341,6 +342,22 @@ public class ModbusJobServiceImpl implements IModbusJobService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 临时方案:按 Quartz 设备任务 jobId 批量刷新同组轮询行的执行时间(见 Mapper 排除 cycle_type=3)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void updateTaskExecuteTime(Long jobId) {
|
||||||
|
|
||||||
|
if (jobId == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ModbusJob modbusJob = new ModbusJob();
|
||||||
|
modbusJob.setJobId(jobId);
|
||||||
|
modbusJob.setExecuteTime(new Date());
|
||||||
|
modbusJobMapper.updateTaskExecuteTime(modbusJob);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 组装并保存设备任务
|
* 组装并保存设备任务
|
||||||
* @param modbusJob 待新增的modbus任务
|
* @param modbusJob 待新增的modbus任务
|
||||||
|
|||||||
@ -96,6 +96,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
where task_id = #{taskId}
|
where task_id = #{taskId}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
|
<!-- 临时:按 job_id 批量写 execute_time,不覆盖上电触发任务 -->
|
||||||
|
<update id="updateTaskExecuteTime" parameterType="com.fastbee.iot.domain.ModbusJob">
|
||||||
|
update iot_modbus_job
|
||||||
|
set execute_time = #{executeTime}
|
||||||
|
where job_id = #{jobId}
|
||||||
|
and (cycle_type is null or cycle_type != 3)
|
||||||
|
</update>
|
||||||
|
|
||||||
<!-- 清空执行时间 -->
|
<!-- 清空执行时间 -->
|
||||||
<update id="clearExecuteTime" parameterType="Long">
|
<update id="clearExecuteTime" parameterType="Long">
|
||||||
update iot_modbus_job set execute_time = null where task_id = #{taskId}
|
update iot_modbus_job set execute_time = null where task_id = #{taskId}
|
||||||
|
|||||||
@ -77,7 +77,7 @@
|
|||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="执行时间" align="center" prop="executeTime" width="180">
|
<el-table-column label="执行时间" align="center" prop="executeTime" width="180">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<span v-if="scope.row.cycleType === 3 && scope.row.status === '1' && scope.row.executeTime">
|
<span v-if="scope.row.executeTime && showExecuteTime(scope.row)">
|
||||||
{{ parseTime(scope.row.executeTime, '{y}-{m}-{d} {h}:{i}:{s}') }}
|
{{ parseTime(scope.row.executeTime, '{y}-{m}-{d} {h}:{i}:{s}') }}
|
||||||
</span>
|
</span>
|
||||||
<span v-else>-</span>
|
<span v-else>-</span>
|
||||||
@ -518,6 +518,13 @@ export default {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
/** 执行时间列:周期/自定义有记录即展示;上电触发保持「已暂停且有记录」再展示 */
|
||||||
|
showExecuteTime(row) {
|
||||||
|
const t = row.cycleType;
|
||||||
|
if (t === 1 || t === 2) return true;
|
||||||
|
if (t === 3) return row.status === '1';
|
||||||
|
return false;
|
||||||
|
},
|
||||||
// 回填时间周期(remark -> cycles1/cycles2)
|
// 回填时间周期(remark -> cycles1/cycles2)
|
||||||
parseRemarkToCycles(cycleType, remark) {
|
parseRemarkToCycles(cycleType, remark) {
|
||||||
// 默认值
|
// 默认值
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user