feat(video): 添加设备名称字段并优化巡检任务关联查询

- 在 Device 实体类中新增 deviceName 字段及其 getter/setter 方法
- 更新 DeviceMapper.xml,支持 device_name 字段的查询、插入和更新操作
- 修改 InspectionTask 实体类,增加 deviceIp 字段用于联查返回设备 IP
- 调整 InspectionTaskMapper.xml,通过左连接获取设备名称与 IP 信息- 移除冗余的 device_name 插入与更新逻辑
- 注释掉旧有的设备信息设置代码,避免重复赋值
- 更新 toString 方法以包含新的 deviceName 属性
This commit is contained in:
2025-10-09 09:54:40 +08:00
parent 99a8a943bc
commit 98042b237c
5 changed files with 48 additions and 19 deletions

View File

@@ -14,6 +14,8 @@ public class Device extends BaseEntity {
private Long deviceId; private Long deviceId;
@Excel(name = "IP地址") @Excel(name = "IP地址")
private String ip; private String ip;
@Excel(name = "设备名称")
private String deviceName;
@Excel( @Excel(
name = "设备类型(1=haikan,2=dahua)" name = "设备类型(1=haikan,2=dahua)"
) )
@@ -51,7 +53,7 @@ public class Device extends BaseEntity {
} }
public String toString() { public String toString() {
return "Device{deviceId=" + this.deviceId + ", ip='" + this.ip + "', type='" + this.type + "', mediaKey='" + this.mediaKey + "', userName='" + this.userName + "', password='" + this.password + "', url='" + this.url + "', enabledFlv='" + this.enabledFlv + "', enabledHls='" + this.enabledHls + "', mode='" + this.mode + "'}"; return "Device{deviceId=" + this.deviceId + ", deviceName='" + this.deviceName + "', ip='" + this.ip + "', type='" + this.type + "', mediaKey='" + this.mediaKey + "', userName='" + this.userName + "', password='" + this.password + "', url='" + this.url + "', enabledFlv='" + this.enabledFlv + "', enabledHls='" + this.enabledHls + "', mode='" + this.mode + "'}";
} }
public Long getDeviceId() { public Long getDeviceId() {
@@ -62,6 +64,14 @@ public class Device extends BaseEntity {
this.deviceId = deviceId; this.deviceId = deviceId;
} }
public String getDeviceName() {
return deviceName;
}
public void setDeviceName(String deviceName) {
this.deviceName = deviceName;
}
public String getIp() { public String getIp() {
return this.ip; return this.ip;
} }

View File

@@ -6,7 +6,7 @@ import java.util.Date;
/** /**
* 巡检任务对象 v_inspection_task * 巡检任务对象 v_inspection_task
* *
* @author ruoyi * @author ruoyi
* @date 2025-09-27 * @date 2025-09-27
*/ */
@@ -22,9 +22,12 @@ public class InspectionTask extends BaseEntity {
/** 设备ID */ /** 设备ID */
private Long deviceId; private Long deviceId;
/** 设备名称 */ /** 设备名称(联查返回) */
private String deviceName; private String deviceName;
/** 设备IP联查返回 */
private String deviceIp;
/** Cron表达式 */ /** Cron表达式 */
private String cronExpression; private String cronExpression;
@@ -57,11 +60,11 @@ public class InspectionTask extends BaseEntity {
public void setModelName(String modelName) { public void setModelName(String modelName) {
this.modelName = modelName; this.modelName = modelName;
} }
public String getModelName() { public String getModelName() {
return modelName; return modelName;
} }
public void setTaskId(Long taskId) { public void setTaskId(Long taskId) {
this.taskId = taskId; this.taskId = taskId;
} }
@@ -94,6 +97,14 @@ public class InspectionTask extends BaseEntity {
return deviceName; return deviceName;
} }
public String getDeviceIp() {
return deviceIp;
}
public void setDeviceIp(String deviceIp) {
this.deviceIp = deviceIp;
}
public void setCronExpression(String cronExpression) { public void setCronExpression(String cronExpression) {
this.cronExpression = cronExpression; this.cronExpression = cronExpression;
} }

View File

@@ -88,11 +88,11 @@ public class InspectionTaskServiceImpl implements InspectionTaskService {
inspectionTask.setAlarmCount(0L); inspectionTask.setAlarmCount(0L);
// 获取设备信息 // 获取设备信息
Device device = deviceService.selectDeviceByDeviceId(inspectionTask.getDeviceId()); // Device device = deviceService.selectDeviceByDeviceId(inspectionTask.getDeviceId());
//
if (device != null) { // if (device != null) {
inspectionTask.setDeviceName(device.getIp()); // inspectionTask.setDeviceName(device.getIp());
} // }
return inspectionTaskMapper.insertInspectionTask(inspectionTask); return inspectionTaskMapper.insertInspectionTask(inspectionTask);
} }
@@ -457,7 +457,7 @@ public class InspectionTaskServiceImpl implements InspectionTaskService {
alarm.setTaskId(task.getTaskId()); alarm.setTaskId(task.getTaskId());
alarm.setTaskName(task.getTaskName()); alarm.setTaskName(task.getTaskName());
alarm.setDeviceId(task.getDeviceId()); alarm.setDeviceId(task.getDeviceId());
alarm.setDeviceName(task.getDeviceName()); // alarm.setDeviceName(task.getDeviceName());
alarm.setAlarmType(best.getLabel()); alarm.setAlarmType(best.getLabel());
// 这里需要转换double为float // 这里需要转换double为float
alarm.setAlarmLevel(getAlarmLevel((float)best.getConfidence())); alarm.setAlarmLevel(getAlarmLevel((float)best.getConfidence()));

View File

@@ -6,6 +6,7 @@
<resultMap type="Device" id="DeviceResult"> <resultMap type="Device" id="DeviceResult">
<result property="deviceId" column="device_id" /> <result property="deviceId" column="device_id" />
<result property="deviceName" column="device_name" />
<result property="ip" column="ip" /> <result property="ip" column="ip" />
<result property="type" column="type" /> <result property="type" column="type" />
<result property="userName" column="user_name" /> <result property="userName" column="user_name" />
@@ -23,12 +24,13 @@
</resultMap> </resultMap>
<sql id="selectDeviceVo"> <sql id="selectDeviceVo">
select device_id, ip, type, user_name, password, url, mediaKey, enabledFlv, enabledHls, mode, create_by, create_time, update_by, update_time, remark from v_device select device_id, device_name, ip, type, user_name, password, url, mediaKey, enabledFlv, enabledHls, mode, create_by, create_time, update_by, update_time, remark from v_device
</sql> </sql>
<select id="selectDeviceList" parameterType="Device" resultMap="DeviceResult"> <select id="selectDeviceList" parameterType="Device" resultMap="DeviceResult">
<include refid="selectDeviceVo"/> <include refid="selectDeviceVo"/>
<where> <where>
<if test="deviceName != null and deviceName != ''"> and device_name like concat('%', #{deviceName}, '%')</if>
<if test="ip != null and ip != ''"> and ip = #{ip}</if> <if test="ip != null and ip != ''"> and ip = #{ip}</if>
<if test="type != null and type != ''"> and type = #{type}</if> <if test="type != null and type != ''"> and type = #{type}</if>
<if test="userName != null and userName != ''"> and user_name like concat('%', #{userName}, '%')</if> <if test="userName != null and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
@@ -49,6 +51,7 @@
<insert id="insertDevice" parameterType="Device" useGeneratedKeys="true" keyProperty="deviceId"> <insert id="insertDevice" parameterType="Device" useGeneratedKeys="true" keyProperty="deviceId">
insert into v_device insert into v_device
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
<if test="deviceName != null and deviceName != ''">device_name,</if>
<if test="ip != null and ip != ''">ip,</if> <if test="ip != null and ip != ''">ip,</if>
<if test="type != null and type != ''">type,</if> <if test="type != null and type != ''">type,</if>
<if test="userName != null and userName != ''">user_name,</if> <if test="userName != null and userName != ''">user_name,</if>
@@ -65,6 +68,7 @@
<if test="remark != null">remark,</if> <if test="remark != null">remark,</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="deviceName != null and deviceName != ''">#{deviceName},</if>
<if test="ip != null and ip != ''">#{ip},</if> <if test="ip != null and ip != ''">#{ip},</if>
<if test="type != null and type != ''">#{type},</if> <if test="type != null and type != ''">#{type},</if>
<if test="userName != null and userName != ''">#{userName},</if> <if test="userName != null and userName != ''">#{userName},</if>
@@ -85,6 +89,7 @@
<update id="updateDevice" parameterType="Device"> <update id="updateDevice" parameterType="Device">
update v_device update v_device
<trim prefix="SET" suffixOverrides=","> <trim prefix="SET" suffixOverrides=",">
<if test="deviceName != null and deviceName != ''">device_name = #{deviceName},</if>
<if test="ip != null and ip != ''">ip = #{ip},</if> <if test="ip != null and ip != ''">ip = #{ip},</if>
<if test="type != null and type != ''">type = #{type},</if> <if test="type != null and type != ''">type = #{type},</if>
<if test="userName != null and userName != ''">user_name = #{userName},</if> <if test="userName != null and userName != ''">user_name = #{userName},</if>

View File

@@ -9,6 +9,7 @@
<result property="taskName" column="task_name" /> <result property="taskName" column="task_name" />
<result property="deviceId" column="device_id" /> <result property="deviceId" column="device_id" />
<result property="deviceName" column="device_name" /> <result property="deviceName" column="device_name" />
<result property="deviceIp" column="device_ip" />
<result property="cronExpression" column="cron_expression" /> <result property="cronExpression" column="cron_expression" />
<result property="duration" column="duration" /> <result property="duration" column="duration" />
<result property="threshold" column="threshold" /> <result property="threshold" column="threshold" />
@@ -26,10 +27,15 @@
</resultMap> </resultMap>
<sql id="selectInspectionTaskVo"> <sql id="selectInspectionTaskVo">
select task_id, task_name, device_id, device_name, cron_expression, duration, select
threshold, enable_detection, status, execute_count, alarm_count, t.task_id, t.task_name, t.device_id,
last_execute_time, model_name, remark, create_by, create_time, update_by, update_time t.cron_expression, t.duration,
from v_inspection_task t.threshold, t.enable_detection, t.status, t.execute_count, t.alarm_count,
t.last_execute_time, t.model_name, t.remark, t.create_by, t.create_time, t.update_by, t.update_time,
d.device_name as device_name,
d.ip as device_ip
from v_inspection_task t
left join v_device d on t.device_id = d.device_id
</sql> </sql>
<select id="selectInspectionTaskList" parameterType="InspectionTask" resultMap="InspectionTaskResult"> <select id="selectInspectionTaskList" parameterType="InspectionTask" resultMap="InspectionTaskResult">
@@ -37,7 +43,7 @@
<where> <where>
<if test="taskName != null and taskName != ''"> and task_name like concat('%', #{taskName}, '%')</if> <if test="taskName != null and taskName != ''"> and task_name like concat('%', #{taskName}, '%')</if>
<if test="deviceId != null"> and device_id = #{deviceId}</if> <if test="deviceId != null"> and device_id = #{deviceId}</if>
<if test="deviceName != null and deviceName != ''"> and device_name like concat('%', #{deviceName}, '%')</if> <if test="deviceName != null and deviceName != ''"> and d.device_name like concat('%', #{deviceName}, '%')</if>
<if test="status != null and status != ''"> and status = #{status}</if> <if test="status != null and status != ''"> and status = #{status}</if>
<if test="enableDetection != null and enableDetection != ''"> and enable_detection = #{enableDetection}</if> <if test="enableDetection != null and enableDetection != ''"> and enable_detection = #{enableDetection}</if>
<if test="modelName != null and modelName != ''"> and model_name = #{modelName}</if> <if test="modelName != null and modelName != ''"> and model_name = #{modelName}</if>
@@ -61,7 +67,6 @@
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
<if test="taskName != null and taskName != ''">task_name,</if> <if test="taskName != null and taskName != ''">task_name,</if>
<if test="deviceId != null">device_id,</if> <if test="deviceId != null">device_id,</if>
<if test="deviceName != null">device_name,</if>
<if test="cronExpression != null and cronExpression != ''">cron_expression,</if> <if test="cronExpression != null and cronExpression != ''">cron_expression,</if>
<if test="duration != null">duration,</if> <if test="duration != null">duration,</if>
<if test="threshold != null">threshold,</if> <if test="threshold != null">threshold,</if>
@@ -78,7 +83,6 @@
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="taskName != null and taskName != ''">#{taskName},</if> <if test="taskName != null and taskName != ''">#{taskName},</if>
<if test="deviceId != null">#{deviceId},</if> <if test="deviceId != null">#{deviceId},</if>
<if test="deviceName != null">#{deviceName},</if>
<if test="cronExpression != null and cronExpression != ''">#{cronExpression},</if> <if test="cronExpression != null and cronExpression != ''">#{cronExpression},</if>
<if test="duration != null">#{duration},</if> <if test="duration != null">#{duration},</if>
<if test="threshold != null">#{threshold},</if> <if test="threshold != null">#{threshold},</if>
@@ -99,7 +103,6 @@
<trim prefix="SET" suffixOverrides=","> <trim prefix="SET" suffixOverrides=",">
<if test="taskName != null and taskName != ''">task_name = #{taskName},</if> <if test="taskName != null and taskName != ''">task_name = #{taskName},</if>
<if test="deviceId != null">device_id = #{deviceId},</if> <if test="deviceId != null">device_id = #{deviceId},</if>
<if test="deviceName != null">device_name = #{deviceName},</if>
<if test="cronExpression != null and cronExpression != ''">cron_expression = #{cronExpression},</if> <if test="cronExpression != null and cronExpression != ''">cron_expression = #{cronExpression},</if>
<if test="duration != null">duration = #{duration},</if> <if test="duration != null">duration = #{duration},</if>
<if test="threshold != null">threshold = #{threshold},</if> <if test="threshold != null">threshold = #{threshold},</if>