场景模型测试工具
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

225 lines
11 KiB

<?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="sceneCode" column="scene_code"/>
<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="sceneId" column="scene_id" />
<result property="sceneName" column="scene_name" />
<result property="sceneCode" column="scene_code"/>
<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" />
<result property="sceneRemark" column="scene_remark" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
</resultMap>
<resultMap type="com.psdc.entity.res.PsdcSceneRes" id="SceneResMap">
<result property="sceneId" column="scene_id" />
<result property="sceneName" column="scene_name" />
<result property="sceneCode" column="scene_code"/>
<result property="userId" column="user_id"/>
<result property="sceneRemark" column="scene_remark" />
<result property="createTime" column="create_time" />
<result property="isJudge" column="is_judge" />
<result property="judgeDevice" column="judge_device" />
<result property="judgeElement" column="judge_element" />
<result property="judgeData" column="judge_data" />
</resultMap>
<!-- 通过ID查询单条数据 -->
<select id="querySceneNameById" resultType="java.lang.String">
Select scene_name From psdc_scene Where scene_code = #{sceneCode} GROUP BY scene_name
</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,scene_code,user_id,device_id,device_sn,scene_context,scene_key,scene_value)
values (#{sceneName},#{sceneCode},#{userId},#{deviceId},#{deviceSn},#{sceneContext},#{sceneKey},#{sceneValue})
</insert>
<insert id="InsertSceneData" parameterType="com.psdc.entity.vo.SceneVo" useGeneratedKeys="true">
Insert into psdc_scene(scene_name,scene_code,user_id,device_id,device_sn,is_judge,judge_device,judge_element,judge_data,scene_context,scene_key,scene_value,scene_remark, create_by, create_time)
Values
<foreach collection="sceneRecord" item="entity" separator=",">
(#{entity.sceneName}, #{entity.sceneCode},#{entity.userId}, #{entity.deviceId}, #{entity.deviceSn},#{entity.isJudge},#{entity.judgeDevice},#{entity.judgeElement},#{entity.judgeData}, #{entity.sceneContext}, #{entity.sceneKey}, #{entity.sceneValue},#{entity.sceneRemark},#{entity.createBy},#{entity.createTime})
</foreach>
</insert>
<update id="UpdateSceneData">
<foreach collection="sceneRecord" item="item" index="index" open="" close="" separator=";">
Update psdc_scene
<set>
<if test="item.sceneName != null and item.sceneName != ''">
`scene_name`= #{item.sceneName},
</if>
<if test="item.sceneContext != null and item.sceneContext != ''">
`scene_context` = #{item.sceneContext},
</if>
<if test="item.sceneValue != null and item.sceneValue != ''">
`scene_value` = ${item.sceneValue},
</if>
<if test="item.sceneRemark != null and item.sceneRemark != ''">
scene_remark = #{item.sceneRemark},
</if>
</set>
<where>
<if test="item.sceneCode != null and item.sceneCode != ''">
And scene_code = ${item.sceneCode}
</if>
<if test="item.userId != null and item.userId != ''">
And user_id = ${item.userId}
</if>
<if test="item.deviceId != null and item.deviceId != ''">
And device_id = ${item.deviceId}
</if>
<if test="item.sceneKey != null and item.sceneKey != ''">
And scene_key = #{item.sceneKey}
</if>
</where>
</foreach>
</update>
<!-- 更新数据 -->
<update id="update">
Update psdc_scene
<set>
<if test="sceneName != null and sceneName != ''">
scene_name = #{sceneName},
</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>
<if test="sceneId != null and sceneId != ''">
scene_id = #{sceneId}
</if>
<if test="sceneCode != null and sceneCode != ''">
And scene_code = #{sceneCode}
</if>
</where>
</update>
<!--通过主键删除-->
<delete id="deleteById">
delete from psdc_scene where scene_id = #{sceneId}
</delete>
<delete id="deleteBySceneName">
Delete From psdc_scene Where scene_code = #{sceneCode}
</delete>
<!-- 根据用户ID查询策略信息-->
<select id="queryByUserId" resultMap="SceneVoMap">
Select ps.scene_id,ps.scene_name,ps.scene_code,ps.user_id,pd.device_name,ps.device_id,pd.device_sn,ps.scene_context,ps.scene_key,ps.scene_value,
ps.scene_remark,ps.create_by,ps.create_time,ps.update_by,ps.update_time
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="queryBySceneCode" resultMap="PsdcSceneMap">
select * from psdc_scene where scene_code = #{sceneCode}
</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.scene_code,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.scene_code,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.scene_code,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="findSceneByUserAndSceneCode" resultMap="SceneVoMap">
Select ps.scene_id,ps.scene_name,ps.scene_code,ps.user_id,pd.device_name,ps.device_id,pd.device_sn,ps.scene_context,ps.scene_key,ps.scene_value,
ps.scene_remark,ps.scene_remark,ps.create_by,ps.create_time
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="sceneCode != null and sceneCode != ''">
And ps.scene_code = #{sceneCode}
</if>
<if test="sceneName != null and sceneName != ''">
And ps.scene_name Like concat('%', #{sceneName}, '%')
</if>
</where>
</select>
<select id="queryScenes" resultMap="SceneResMap">
Select ps.scene_id,ps.scene_name,ps.scene_code,ps.user_id,is_judge,judge_device,judge_element,judge_data,pd.device_name,ps.device_id,pd.device_sn,ps.scene_context,ps.scene_key,ps.scene_value,
ps.scene_remark,ps.create_by,ps.create_time
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="sceneCode != null and sceneCode != ''">
And ps.scene_code = #{sceneCode}
</if>
</where>
Group By ps.scene_code
</select>
</mapper>