iot-gateway/src/main/resources/mappers/iotMappers/EventMapper.xml
zhuangtianxiang 6f4a7a3345 refactor(iot): 重构设备和事件相关代码
- 修改设备和事件的 Mapper、Repository、Service 层代码
- 优化查询接口,改用 DeviceVo 和 EventVo 返回结果
- 移除不必要的关联查询,提高查询效率- 修正部分字段名称和数据类型,使其更加合理
2024-12-12 14:37:08 +08:00

58 lines
2.6 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.tsl.repo.EventRepository">
<resultMap id="EventMap" type="com.zsc.edu.gateway.modules.iot.tsl.entity.Event">
<id column="id" property="id"/>
<result column="product_id" property="productId"/>
<result column="type" property="type"/>
<result column="identifier" property="identifier"/>
<result column="name" property="name"/>
<result column="remark" property="remark"/>
<collection property="outputs" 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="page" resultMap="EventMap">
select e.*,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
from iot_event e
left join iot_event_param ep on e.id=ep.event_id
left join iot_param ip on ep.param_id = ip.id
<where>
<if test="query.name != null and query.name != ''">
and e.name like CONCAT('%', #{query.name}, '%')
</if>
<if test="query.level != null and query.level != ''">
and e.level = #{query.level}
</if>
<if test="query.productId !=null">
and e.product_id = #{query.productId}
</if>
</where>
</select>
<select id="selectById" resultMap="EventMap">
select e.*,
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
from iot_event e
left join iot_event_param ep on e.id = ep.event_id
left join iot_param ip on ep.param_id = ip.id
where e.id = #{id}
</select>
</mapper>