iot-gateway/src/main/resources/mappers/iot/DeviceMapper.xml
zhuangtianxiang 790aed76ea feat(iot): 优化设备管理功能
- 添加附件预览功能
- 修复设备列表查询条件
- 优化产品和设备控制器
- 调整 WebSocket连接逻辑
2025-03-20 19:34:00 +08:00

129 lines
6.4 KiB
XML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zsc.edu.gateway.modules.iot.device.repo.DeviceRepository">
<resultMap id="BaseResultMap" type="com.zsc.edu.gateway.modules.iot.device.vo.DeviceVo">
<id column="id" property="id"/>
<result column="name" property="name"/>
<result column="online" property="online"/>
<result column="state" property="state"/>
<result column="hardware_version" property="hardwareVersion"/>
<result column="firmware_version" property="firmwareVersion"/>
<result column="factory_id" property="factoryId"/>
<result column="client_id" property="clientId"/>
<result column="product_id" property="productId"/>
<result column="extend_params" property="extendParams" jdbcType="VARCHAR"
typeHandler="com.zsc.edu.gateway.framework.json.JsonbTypeHandler"/>
<result column="properties" property="properties" jdbcType="VARCHAR"
typeHandler="com.zsc.edu.gateway.framework.json.JsonbTypeHandler"/>
<result column="create_by" jdbcType="VARCHAR" property="deviceCreateBy"/>
<result column="update_by" jdbcType="VARCHAR" property="deviceUpdateBy"/>
<result column="create_time" jdbcType="DATE" property="deviceCreateTime"/>
<result column="update_time" jdbcType="DATE" property="deviceUpdateTime"/>
<result column="remark" jdbcType="VARCHAR" property="deviceRemark"/>
<result column="longitude" jdbcType="DOUBLE" property="longitude"/>
<result column="latitude" jdbcType="DOUBLE" property="latitude"/>
<result column="icon_id" jdbcType="VARCHAR" property="iconId"/>
<result column="preview_id" jdbcType="VARCHAR" property="previewId"/>
<result column="name" property="productName"/>
<result column="product_type" jdbcType="VARCHAR" property="productType"/>
<result column="model" property="model"/>
<result column="link" property="link"/>
<result column="create_by" jdbcType="VARCHAR" property="createBy"/>
<result column="update_by" jdbcType="VARCHAR" property="updateBy"/>
<result column="create_time" jdbcType="DATE" property="createTime"/>
<result column="update_time" jdbcType="DATE" property="updateTime"/>
<result column="remark" jdbcType="VARCHAR" property="remark"/>
<result column="enabled" jdbcType="BOOLEAN" property="enabled"/>
<association property="icon" javaType="com.zsc.edu.gateway.modules.attachment.entity.Attachment"
autoMapping="true"
columnPrefix="icon_">
<id column="id" property="id"/>
<result column="file_name" property="fileName"/>
</association>
<association property="preview" javaType="com.zsc.edu.gateway.modules.attachment.entity.Attachment"
autoMapping="true"
columnPrefix="preview_">
<id column="id" property="id"/>
<result column="file_name" property="fileName"/>
</association>
<collection property="params" ofType="com.zsc.edu.gateway.modules.iot.tsl.entity.Param" autoMapping="true"
columnPrefix="param_">
<id column="id" property="id"/>
<result column="data_type" property="dataType"/>
<result column="uint" property="uint"/>
<result column="type" property="type"/>
<result column="identifier" property="identifier"/>
<result column="name" property="name"/>
<result column="remark" property="remark"/>
</collection>
</resultMap>
<select id="findById" resultMap="BaseResultMap">
select d.*,
p.*,
ip.id as param_id,
ip.data_type as param_data_type,
ip.uint as param_uint,
ip.type as param_type,
ip.identifier as param_identifier,
ip.name as param_name,
ip.remark as param_remark,
ai.id as icon_id,
ai.file_name as icon_file_name,
ap.file_name as preview_file_name,
ap.id as preview_id
from iot_device d
left join iot_product p on d.product_id = p.id
left join iot_param ip on p.id = ip.foreign_id and ip.foreign_type = 3
left join attachment ai on d.icon_id = ai.id
left join attachment ap on d.preview_id = ap.id
where d.id = #{id}
</select>
<select id="selectPageByConditions" resultType="com.zsc.edu.gateway.modules.iot.device.entity.Device">
SELECT d.*, p.*
FROM iot_device d
LEFT JOIN iot_product p ON d.product_id = p.id
<where>
<if test="query.name != null and query.name != ''">
AND d.name LIKE concat('%', #{query.name}, '%')
</if>
<if test="query.clientId != null and query.clientId != ''">
AND d.client_id = #{query.clientId}
</if>
<if test="query.state != null and query.state != ''">
AND d.state = #{query.state}
</if>
<if test="query.isOnline != null and query.isOnline != ''">
AND d.online = #{query.isOnline}
</if>
<if test="query.productId != null and query.productId != ''">
AND d.product_id = #{query.productId}
</if>
</where>
</select>
<select id="selectListByName" resultMap="BaseResultMap">
select d.*,
p.*,
ip.id as param_id,
ip.data_type as param_data_type,
ip.uint as param_uint,
ip.type as param_type,
ip.identifier as param_identifier,
ip.name as param_name,
ip.remark as param_remark,
ai.id as icon_id,
ap.id as preview_id
from iot_device d
left join iot_product p on d.product_id = p.id
left join iot_param ip on p.id = ip.foreign_id and ip.foreign_type = 3
left join attachment ai on d.icon_id = ai.id
left join attachment ap on d.preview_id = ap.id
<if test="name != null">
WHERE d.name LIKE concat('%', #{name}, '%')
</if>
</select>
</mapper>