|
|
|
<?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.psdc.mapper.PsdcSceneMapper">
|
|
|
|
<resultMap type="com.psdc.entity.PsdcScene" id="PsdcSceneMap">
|
|
|
|
<result property="sceneId" column="scene_id" />
|
|
|
|
<result property="sceneName" column="scene_name" />
|
|
|
|
<result property="userId" column="user_id"/>
|
|
|
|
<result property="deviceId" column="device_id" />
|
|
|
|
<result property="deviceSn" column="device_sn" />
|
|
|
|
<result property="sceneContext" column="scene_context" />
|
|
|
|
<result property="sceneKey" column="scene_key" />
|
|
|
|
<result property="sceneValue" column="scene_value" />
|
|
|
|
</resultMap>
|
|
|
|
|
|
|
|
<resultMap type="com.psdc.entity.vo.SceneVo" id="SceneVoMap">
|
|
|
|
<result property="sceneName" column="scene_name" />
|
|
|
|
<result property="userId" column="user_id"/>
|
|
|
|
<result property="deviceName" column="device_name"/>
|
|
|
|
<result property="deviceId" column="device_id" />
|
|
|
|
<result property="deviceSn" column="device_sn" />
|
|
|
|
<result property="sceneContext" column="scene_context" />
|
|
|
|
<result property="sceneKey" column="scene_key" />
|
|
|
|
<result property="sceneValue" column="scene_value" />
|
|
|
|
</resultMap>
|
|
|
|
|
|
|
|
<!-- 通过ID查询单条数据 -->
|
|
|
|
<select id="queryById" resultMap="PsdcSceneMap">
|
|
|
|
select
|
|
|
|
scene_id,scene_name,user_id,device_id,device_sn,scene_context,scene_key,scene_value
|
|
|
|
from psdc_scene
|
|
|
|
where scene_id = #{sceneId}
|
|
|
|
</select>
|
|
|
|
|
|
|
|
<select id="sceneList" resultMap="PsdcSceneMap">
|
|
|
|
SELECT * FROM `psdc_scene` WHERE user_id = ${userId} Group By scene_name
|
|
|
|
</select>
|
|
|
|
|
|
|
|
<!--新增数据-->
|
|
|
|
<insert id="insert" keyProperty="UNDEFINED_ID" useGeneratedKeys="true">
|
|
|
|
insert into psdc_scene(scene_name,user_id,device_id,device_sn,scene_context,scene_key,scene_value)
|
|
|
|
values (#{sceneName},#{userId},#{deviceId},#{deviceSn},#{sceneContext},#{sceneKey},#{sceneValue})
|
|
|
|
</insert>
|
|
|
|
|
|
|
|
<!-- 更新数据 -->
|
|
|
|
<update id="update">
|
|
|
|
update psdc_scene
|
|
|
|
<set>
|
|
|
|
<if test="sceneName != null and sceneName != ''">
|
|
|
|
scene_name = #{sceneName},
|
|
|
|
</if>
|
|
|
|
<if test="userId != null and userId != ''">
|
|
|
|
user_id = #{userId},
|
|
|
|
</if>
|
|
|
|
<if test="deviceId != null and deviceId != ''">
|
|
|
|
device_id = #{deviceId},
|
|
|
|
</if>
|
|
|
|
<if test="deviceSn != null and deviceSn != ''">
|
|
|
|
device_sn = #{deviceSn},
|
|
|
|
</if>
|
|
|
|
<if test="sceneContext != null and sceneContext != ''">
|
|
|
|
scene_context = #{sceneContext},
|
|
|
|
</if>
|
|
|
|
<if test="sceneKey != null and sceneKey != ''">
|
|
|
|
scene_key = #{sceneKey},
|
|
|
|
</if>
|
|
|
|
<if test="sceneValue != null and sceneValue != ''">
|
|
|
|
scene_value = #{sceneValue},
|
|
|
|
</if>
|
|
|
|
</set>
|
|
|
|
where scene_id = #{sceneId}
|
|
|
|
</update>
|
|
|
|
|
|
|
|
<!--通过主键删除-->
|
|
|
|
<delete id="deleteById">
|
|
|
|
delete from psdc_scene where scene_id = #{sceneId}
|
|
|
|
</delete>
|
|
|
|
|
|
|
|
<!-- 根据用户ID查询策略信息-->
|
|
|
|
<select id="queryByUserId" resultMap="SceneVoMap">
|
|
|
|
select ps.scene_id,ps.scene_name,ps.user_id,pd.device_name,ps.device_id,pd.device_sn,ps.scene_context,ps.scene_key,ps.scene_value
|
|
|
|
from psdc_scene ps left join sys_user su on ps.user_id = su.user_id
|
|
|
|
left join psdc_device pd on ps.device_id = pd.device_id
|
|
|
|
where su.user_id = #{userId}
|
|
|
|
</select>
|
|
|
|
|
|
|
|
<!-- 根据用户ID查询策略信息-->
|
|
|
|
<select id="querySceneGroup" resultType="string">
|
|
|
|
select ps.scene_name
|
|
|
|
from psdc_scene ps left join sys_user su on ps.user_id = su.user_id
|
|
|
|
where su.user_id = #{userId} group by ps.scene_name
|
|
|
|
</select>
|
|
|
|
|
|
|
|
<!-- 根据用户ID查询策略信息-->
|
|
|
|
<select id="querySceneByDeviceId" resultMap="SceneVoMap">
|
|
|
|
select ps.scene_id,ps.scene_name,ps.user_id,pd.device_name,ps.device_id,pd.device_sn,ps.scene_context,ps.scene_key,ps.scene_value
|
|
|
|
from psdc_scene ps left join sys_user su on ps.user_id = su.user_id
|
|
|
|
left join psdc_device pd on ps.device_id = pd.device_id
|
|
|
|
where su.user_id = #{userId} and pd.device_id = #{deviceId}
|
|
|
|
</select>
|
|
|
|
|
|
|
|
<!-- 根据用户ID查询策略信息-->
|
|
|
|
<select id="querySceneByDeviceIdAndSceneName" resultMap="SceneVoMap">
|
|
|
|
select ps.scene_id,ps.scene_name,ps.user_id,pd.device_name,ps.device_id,pd.device_sn,ps.scene_context,ps.scene_key,ps.scene_value
|
|
|
|
from psdc_scene ps left join sys_user su on ps.user_id = su.user_id
|
|
|
|
left join psdc_device pd on ps.device_id = pd.device_id
|
|
|
|
where su.user_id = #{userId} and ps.device_id = #{deviceId} and ps.scene_name = #{sceneName}
|
|
|
|
</select>
|
|
|
|
|
|
|
|
<!-- 根据策略名称查询策略信息-->
|
|
|
|
<select id="queryBySceneName" resultMap="SceneVoMap">
|
|
|
|
select ps.scene_id,ps.scene_name,ps.user_id,pd.device_name,ps.device_id,pd.device_sn,ps.scene_context,ps.scene_key,ps.scene_value
|
|
|
|
from psdc_scene ps left join psdc_device pd on ps.device_id = pd.device_id
|
|
|
|
where ps.scene_name like concat('%', #{sceneName}, '%')
|
|
|
|
</select>
|
|
|
|
|
|
|
|
<select id="findSceneByUserAndSceneName" resultMap="SceneVoMap">
|
|
|
|
Select ps.scene_id,ps.scene_name,ps.user_id,pd.device_name,ps.device_id,pd.device_sn,ps.scene_context,ps.scene_key,ps.scene_value
|
|
|
|
From psdc_scene ps
|
|
|
|
Left join sys_user su On su.user_id = ps.user_id
|
|
|
|
Left join psdc_device pd On pd.device_id = ps.device_id
|
|
|
|
<where>
|
|
|
|
<if test="userId != null and userId != ''">
|
|
|
|
And su.user_id = #{userId}
|
|
|
|
</if>
|
|
|
|
<if test="sceneName != null and sceneName != ''">
|
|
|
|
And ps.scene_name Like concat('%', #{sceneName}, '%')
|
|
|
|
</if>
|
|
|
|
</where>
|
|
|
|
</select>
|
|
|
|
</mapper>
|