开源版新增规则脚本

This commit is contained in:
kerwincui
2024-04-23 16:34:20 +08:00
parent de7e2529a3
commit 054e414b48
50 changed files with 7233 additions and 13 deletions

View File

@@ -0,0 +1,136 @@
<?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.fastbee.iot.mapper.SceneDeviceMapper">
<resultMap type="SceneDevice" id="SceneDeviceResult">
<result property="sceneDeviceId" column="scene_device_id" />
<result property="serialNumber" column="serial_number" />
<result property="productId" column="product_id" />
<result property="productName" column="product_name" />
<result property="scriptId" column="script_id" />
<result property="sceneId" column="scene_id" />
<result property="source" column="source" />
<result property="type" column="type" />
</resultMap>
<resultMap type="com.fastbee.iot.domain.Scene" id="SceneResult">
<result property="sceneId" column="scene_id" />
<result property="chainName" column="chain_name" />
<result property="elData" column="el_data" />
</resultMap>
<sql id="selectSceneDeviceVo">
select scene_device_id, serial_number, product_id, product_name, script_id, scene_id, source,type from iot_scene_device
</sql>
<select id="selectSceneDeviceList" parameterType="SceneDevice" resultMap="SceneDeviceResult">
<include refid="selectSceneDeviceVo"/>
<where>
<if test="serialNumber != null and serialNumber != ''"> and serial_number = #{serialNumber}</if>
<if test="productId != null "> and product_id = #{productId}</if>
<if test="productName != null "> and product_name = #{productName}</if>
<if test="scriptId != null "> and script_id = #{scriptId}</if>
<if test="sceneId != null "> and scene_id = #{sceneId}</if>
<if test="source != null "> and source = #{source}</if>
</where>
</select>
<select id="selectTriggerDeviceRelateScenes" parameterType="SceneDevice" resultMap="SceneResult">
select s.scene_id,s.chain_name
from (select distinct scene_id from iot_scene_device where type = 2 and (serial_number = #{serialNumber} OR product_id = #{productId})) d
left join iot_scene s on s.scene_id=d.scene_id
where s.`enable`= 1
</select>
<select id="selectSceneDeviceBySceneDeviceId" parameterType="Long" resultMap="SceneDeviceResult">
<include refid="selectSceneDeviceVo"/>
where scene_device_id = #{sceneDeviceId}
</select>
<select id="listSceneProductBind" resultType="com.fastbee.iot.model.SceneDeviceBindVO">
select d.scene_id, s.scene_name, d.product_id
from iot_scene_device d
left join iot_scene s on d.scene_id = s.scene_id
where d.product_id in
<foreach item="productId" collection="array" open="(" separator="," close=")">
#{productId}
</foreach>
</select>
<select id="listSceneDeviceBind" resultType="com.fastbee.iot.model.SceneDeviceBindVO">
select d.scene_id, s.scene_name, d.serial_number
from iot_scene_device d
left join iot_scene s on d.scene_id = s.scene_id
where d.serial_number = #{serialNumber}
</select>
<insert id="insertSceneDevice" parameterType="SceneDevice" useGeneratedKeys="true" keyProperty="sceneDeviceId" >
insert into iot_scene_device
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="serialNumber != null">serial_number,</if>
<if test="productId != null">product_id,</if>
<if test="productName != null">product_name,</if>
<if test="scriptId != null">script_id,</if>
<if test="sceneId != null">scene_id,</if>
<if test="source != null">source,</if>
<if test="type != null">type,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="serialNumber != null">#{serialNumber},</if>
<if test="productId != null">#{productId},</if>
<if test="productName != null">#{productName},</if>
<if test="scriptId != null">#{scriptId},</if>
<if test="sceneId != null">#{sceneId},</if>
<if test="source != null">#{source},</if>
<if test="type != null">#{type},</if>
</trim>
</insert>
<update id="updateSceneDevice" parameterType="SceneDevice">
update iot_scene_device
<trim prefix="SET" suffixOverrides=",">
<if test="serialNumber != null">serial_number = #{serialNumber},</if>
<if test="productId != null">product_id = #{productId},</if>
<if test="productName != null">product_name = #{productName},</if>
<if test="scriptId != null">script_id = #{scriptId},</if>
<if test="sceneId != null">scene_id = #{sceneId},</if>
<if test="source != null">source = #{source},</if>
<if test="type != null">type = #{type},</if>
</trim>
where scene_device_id = #{sceneDeviceId}
</update>
<delete id="deleteSceneDeviceBySceneDeviceId" parameterType="Long">
delete from iot_scene_device where scene_device_id = #{sceneDeviceId}
</delete>
<delete id="deleteSceneDeviceBySceneDeviceIds" parameterType="String">
delete from iot_scene_device where scene_device_id in
<foreach item="sceneDeviceId" collection="array" open="(" separator="," close=")">
#{sceneDeviceId}
</foreach>
</delete>
<insert id="insertSceneDeviceList" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="sceneDeviceId">
insert into iot_scene_device (serial_number,product_id,product_name, script_id,scene_id,source,type)
VALUES
<foreach collection ="list" item="sceneDevice" separator =",">
(#{sceneDevice.serialNumber},
#{sceneDevice.productId},
#{sceneDevice.productName},
#{sceneDevice.scriptId},
#{sceneDevice.sceneId},
#{sceneDevice.source},
#{sceneDevice.type})
</foreach >
</insert>
<delete id="deleteSceneDeviceBySceneIds" parameterType="String">
delete from iot_scene_device where scene_id in
<foreach item="sceneId" collection="array" open="(" separator="," close=")">
#{sceneId}
</foreach>
</delete>
</mapper>

View File

@@ -0,0 +1,141 @@
<?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.fastbee.iot.mapper.SceneMapper">
<resultMap type="com.fastbee.iot.domain.Scene" id="SceneResult">
<result property="sceneId" column="scene_id" />
<result property="sceneName" column="scene_name" />
<result property="chainName" column="chain_name" />
<result property="userId" column="user_id" />
<result property="userName" column="user_name" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="remark" column="remark" />
<result property="cond" column="cond" />
<result property="silentPeriod" column="silent_period" />
<result property="executeMode" column="execute_mode" />
<result property="executeDelay" column="execute_delay" />
<result property="hasAlert" column="has_alert" />
<result property="enable" column="enable" />
<result property="elData" column="el_data" />
<result property="applicationName" column="application_name" />
</resultMap>
<sql id="selectSceneVo">
select scene_id, scene_name,chain_name, user_id, user_name, create_by, create_time, update_by, update_time, remark, cond, silent_period, execute_mode, execute_delay, has_alert, enable, el_data, application_name from iot_scene
</sql>
<sql id="selectSceneListVo">
select scene_id, scene_name,chain_name, user_id, user_name, create_by, create_time, update_by, update_time, remark, cond, silent_period, execute_mode, execute_delay, has_alert, enable, application_name from iot_scene
</sql>
<select id="selectSceneList" parameterType="Scene" resultMap="SceneResult">
<include refid="selectSceneListVo"/>
<where>
<if test="sceneName != null and sceneName != ''"> and scene_name like concat('%', #{sceneName}, '%')</if>
<if test="userId != null "> and user_id = #{userId}</if>
<if test="userName != null and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
<if test="cond != null "> and cond = #{cond}</if>
<if test="silentPeriod != null "> and silent_period = #{silentPeriod}</if>
<if test="executeMode != null "> and execute_mode = #{executeMode}</if>
<if test="executeDelay != null "> and execute_delay = #{executeDelay}</if>
<if test="hasAlert != null "> and has_alert = #{hasAlert}</if>
<if test="enable != null "> and enable = #{enable}</if>
</where>
order by create_time desc
</select>
<select id="selectSceneBySceneId" parameterType="Long" resultMap="SceneResult">
<include refid="selectSceneVo"/>
where scene_id = #{sceneId}
</select>
<select id="selectSceneListBySceneIds" parameterType="String" resultMap="SceneResult">
<include refid="selectSceneVo"/>
where scene_id in
<foreach item="sceneId" collection="array" open="(" separator="," close=")">
#{sceneId}
</foreach>
</select>
<insert id="insertScene" parameterType="com.fastbee.iot.domain.Scene" useGeneratedKeys="true" keyProperty="sceneId">
insert into iot_scene
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="sceneName != null and sceneName != ''">scene_name,</if>
<if test="chainName != null and chainName != ''">chain_name,</if>
<if test="userId != null">user_id,</if>
<if test="userName != null and userName != ''">user_name,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
<if test="remark != null">remark,</if>
<if test="cond != null">cond,</if>
<if test="silentPeriod != null">silent_period,</if>
<if test="executeMode != null">execute_mode,</if>
<if test="executeDelay != null">execute_delay,</if>
<if test="hasAlert != null">has_alert,</if>
<if test="enable != null">enable,</if>
<if test="elData != null">el_data,</if>
<if test="applicationName != null and applicationName != ''">application_name,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="sceneName != null and sceneName != ''">#{sceneName},</if>
<if test="chainName != null and chainName != ''">#{chainName},</if>
<if test="userId != null">#{userId},</if>
<if test="userName != null and userName != ''">#{userName},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="remark != null">#{remark},</if>
<if test="cond != null">#{cond},</if>
<if test="silentPeriod != null">#{silentPeriod},</if>
<if test="executeMode != null">#{executeMode},</if>
<if test="executeDelay != null">#{executeDelay},</if>
<if test="hasAlert != null">#{hasAlert},</if>
<if test="enable != null">#{enable},</if>
<if test="elData != null">#{elData},</if>
<if test="applicationName != null and applicationName != ''">#{applicationName},</if>
</trim>
</insert>
<update id="updateScene" parameterType="com.fastbee.iot.domain.Scene">
update iot_scene
<trim prefix="SET" suffixOverrides=",">
<if test="sceneName != null and sceneName != ''">scene_name = #{sceneName},</if>
<if test="chainName != null and chainName != ''">chain_name = #{chainName},</if>
<if test="userId != null">user_id = #{userId},</if>
<if test="userName != null and userName != ''">user_name = #{userName},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="cond != null">cond = #{cond},</if>
<if test="silentPeriod != null">silent_period = #{silentPeriod},</if>
<if test="executeMode != null">execute_mode = #{executeMode},</if>
<if test="executeDelay != null">execute_delay = #{executeDelay},</if>
<if test="hasAlert != null">has_alert = #{hasAlert},</if>
<if test="enable != null">enable = #{enable},</if>
<if test="elData != null">el_data = #{elData},</if>
<if test="applicationName != null and applicationName != ''">application_name = #{applicationName},</if>
</trim>
where scene_id = #{sceneId}
</update>
<delete id="deleteSceneBySceneId" parameterType="Long">
delete from iot_scene where scene_id = #{sceneId}
</delete>
<delete id="deleteSceneBySceneIds" parameterType="String">
delete from iot_scene where scene_id in
<foreach item="sceneId" collection="array" open="(" separator="," close=")">
#{sceneId}
</foreach>
</delete>
</mapper>

View File

@@ -0,0 +1,222 @@
<?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.fastbee.iot.mapper.SceneScriptMapper">
<resultMap type="SceneScript" id="SceneScriptResult">
<result property="scriptId" column="script_id"/>
<result property="sceneId" column="scene_id"/>
<result property="productId" column="product_id"/>
<result property="productName" column="product_name"/>
<result property="source" column="source"/>
<result property="scriptPurpose" column="script_purpose"/>
<result property="id" column="id"/>
<result property="name" column="name"/>
<result property="value" column="value"/>
<result property="operator" column="operator"/>
<result property="type" column="type"/>
<result property="deviceCount" column="device_count"/>
<result property="jobId" column="job_id"/>
<result property="cronExpression" column="cron_expression"/>
<result property="isAdvance" column="is_advance"/>
<result property="parentId" column="parent_id"/>
<result property="parentName" column="parent_name"/>
<result property="arrayIndex" column="array_index"/>
<result property="arrayIndexName" column="array_index_name"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
</resultMap>
<sql id="selectSceneScriptVo">
select script_id,
scene_id,
product_id,
product_name,
source,
script_purpose,
id,
name,
value,
operator,
type,
device_count,
job_id,
cron_expression,
is_advance,
parent_id,
parent_name,
array_index,
array_index_name,
create_by,
create_time
from iot_scene_script
</sql>
<select id="selectSceneScriptList" parameterType="SceneScript" resultMap="SceneScriptResult">
<include refid="selectSceneScriptVo"/>
<where>
<if test="scriptId != null ">and script_id = #{scriptId}</if>
<if test="sceneId != null ">and scene_id = #{sceneId}</if>
<if test="productId != null ">and product_id = #{productId}</if>
<if test="productName != null ">and product_name = #{productName}</if>
<if test="source != null ">and source = #{source}</if>
<if test="scriptPurpose != null ">and script_purpose = #{scriptPurpose}</if>
<if test="name != null and name != ''">and name like concat('%', #{name}, '%')</if>
<if test="value != null and value != ''">and value = #{value}</if>
<if test="operator != null and operator != ''">and operator = #{operator}</if>
<if test="type != null ">and type = #{type}</if>
<if test="jobId != null ">and job_id = #{jobId}</if>
<if test="cronExpression != null and cronExpression != ''">and cron_expression = #{cronExpression}</if>
<if test="isAdvance != null ">and is_advance = #{isAdvance}</if>
<if test="parentId != null and parentId != ''">and parent_id = #{parentId}</if>
<if test="parentName != null and parentName != ''">and parent_name like concat('%', #{parentName}, '%')
</if>
<if test="arrayIndex != null and arrayIndex != ''">and array_index = #{arrayIndex}</if>
<if test="arrayIndexName != null and arrayIndexName != ''">and array_index_name like concat('%',
#{arrayIndexName}, '%')
</if>
</where>
</select>
<select id="selectSceneScriptBySceneScriptId" parameterType="String" resultMap="SceneScriptResult">
<include refid="selectSceneScriptVo"/>
where script_id = #{scriptId}
</select>
<select id="listSceneScriptByPurpose" resultMap="SceneScriptResult">
<include refid="selectSceneScriptVo"/>
where scene_id in
<foreach collection="sceneIdList" item="sceneId" open="(" separator="," close=")">
#{sceneId}
</foreach>
and script_purpose = #{scriptPurpose}
</select>
<insert id="insertSceneScript" parameterType="SceneScript" useGeneratedKeys="false">
insert into iot_scene_script
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="scriptId != null">script_id,</if>
<if test="sceneId != null">scene_id,</if>
<if test="productId != null">product_id,</if>
<if test="productName != null">product_name,</if>
<if test="source != null">source,</if>
<if test="scriptPurpose != null">script_purpose,</if>
<if test="id != null">id,</if>
<if test="name != null">name,</if>
<if test="value != null">value,</if>
<if test="operator != null">operator,</if>
<if test="type != null">type,</if>
<if test="deviceCount != null">device_count,</if>
<if test="jobId != null">job_id,</if>
<if test="cronExpression != null">cron_expression,</if>
<if test="isAdvance != null">is_advance,</if>
<if test="parentId != null">parent_id,</if>
<if test="parentName != null">parent_name,</if>
<if test="arrayIndex != null">array_index,</if>
<if test="arrayIndexName != null">array_index_name,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="scriptId != null">#{scriptId},</if>
<if test="sceneId != null">#{sceneId},</if>
<if test="productId != null">#{productId},</if>
<if test="productName != null">#{productName},</if>
<if test="source != null">#{source},</if>
<if test="scriptPurpose != null">#{scriptPurpose},</if>
<if test="id != null">#{id},</if>
<if test="name != null">#{name},</if>
<if test="value != null">#{value},</if>
<if test="operator != null">#{operator},</if>
<if test="type != null">#{type},</if>
<if test="deviceCount != null">#{deviceCount},</if>
<if test="jobId != null">#{jobId},</if>
<if test="cronExpression != null">#{cronExpression},</if>
<if test="isAdvance != null">#{isAdvance},</if>
<if test="parentId != null">#{parentId},</if>
<if test="parentName != null">#{parentName},</if>
<if test="arrayIndex != null">#{arrayIndex},</if>
<if test="arrayIndexName != null">#{arrayIndexName},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
</trim>
</insert>
<update id="updateSceneScript" parameterType="SceneScript">
update iot_scene_script
<trim prefix="SET" suffixOverrides=",">
<if test="scriptId != null">script_id = #{scriptId},</if>
<if test="sceneId != null">scene_id = #{sceneId},</if>
<if test="productId != null">product_id = #{productId},</if>
<if test="productName != null">product_name = #{productName},</if>
<if test="source != null">source = #{source},</if>
<if test="scriptPurpose != null">script_purpose = #{scriptPurpose},</if>
<if test="id != null">id = #{id},</if>
<if test="name != null">name = #{name},</if>
<if test="value != null">value = #{value},</if>
<if test="operator != null">operator = #{operator},</if>
<if test="type != null">type = #{type},</if>
<if test="deviceCount != null">device_count = #{deviceCount},</if>
<if test="jobId != null">job_id = #{jobId},</if>
<if test="cronExpression != null">cron_expression = #{cronExpression},</if>
<if test="isAdvance != null">is_advance = #{isAdvance},</if>
<if test="parentId != null">parent_id = #{parentId},</if>
<if test="parentName != null">parent_name = #{parentName},</if>
<if test="arrayIndex != null">array_index = #{arrayIndex},</if>
<if test="arrayIndexName != null">array_index_name = #{arrayIndexName},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
</trim>
where script_id = #{scriptId}
</update>
<delete id="deleteSceneScriptBySceneScriptId" parameterType="String">
delete
from iot_scene_script
where script_id = #{scriptId}
</delete>
<delete id="deleteSceneScriptBySceneScriptIds" parameterType="String">
delete from iot_scene_script where script_id in
<foreach item="sceneScriptId" collection="array" open="(" separator="," close=")">
#{scriptId}
</foreach>
</delete>
<insert id="insertSceneScriptList" parameterType="java.util.List">
insert into iot_scene_script (script_id,scene_id,product_id,product_name,source,script_purpose,id, name,value,operator,type,device_count,job_id,
cron_expression,is_advance,parent_id,parent_name,array_index,array_index_name,create_by,create_time)
VALUES
<foreach collection="list" item="sceneScript" separator=",">
(#{sceneScript.scriptId},
#{sceneScript.sceneId},
#{sceneScript.productId},
#{sceneScript.productName},
#{sceneScript.source},
#{sceneScript.scriptPurpose},
#{sceneScript.id},
#{sceneScript.name},
#{sceneScript.value},
#{sceneScript.operator},
#{sceneScript.type},
#{sceneScript.deviceCount},
#{sceneScript.jobId},
#{sceneScript.cronExpression},
#{sceneScript.isAdvance},
#{sceneScript.parentId},
#{sceneScript.parentName},
#{sceneScript.arrayIndex},
#{sceneScript.arrayIndexName},
#{sceneScript.createBy},
#{sceneScript.createTime})
</foreach>
</insert>
<delete id="deleteSceneScriptBySceneIds" parameterType="String">
delete from iot_scene_script where scene_id in
<foreach item="sceneId" collection="array" open="(" separator="," close=")">
#{sceneId}
</foreach>
</delete>
</mapper>

View File

@@ -0,0 +1,209 @@
<?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.fastbee.iot.mapper.ScriptMapper">
<resultMap type="com.fastbee.iot.domain.Script" id="RuleScriptResult">
<result property="userId" column="user_id" />
<result property="userName" column="user_name" />
<result property="sceneId" column="scene_id" />
<result property="productId" column="product_id" />
<result property="productName" column="product_name" />
<result property="scriptEvent" column="script_event" />
<result property="scriptAction" column="script_action" />
<result property="scriptPurpose" column="script_purpose" />
<result property="scriptOrder" column="script_order" />
<result property="applicationName" column="application_name" />
<result property="scriptId" column="script_id" />
<result property="scriptName" column="script_name" />
<result property="scriptData" column="script_data" />
<result property="scriptType" column="script_type" />
<result property="scriptLanguage" column="script_language" />
<result property="enable" column="enable" />
<result property="delFlag" column="del_flag" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="remark" column="remark" />
</resultMap>
<sql id="selectRuleScriptVo">
select user_id, user_name, scene_id,product_id,product_name,script_event,script_action,script_purpose,script_order,application_name, script_id, script_name, script_data, script_type, script_language,enable, del_flag, create_by, create_time, update_by, update_time, remark,product_id from iot_script
</sql>
<sql id="selectRuleScriptList">
select user_id, user_name, scene_id,product_id,product_name, script_event,script_action,script_purpose,script_order,application_name, script_id, script_name, script_type, script_language,enable, create_by, create_time, update_by, update_time,product_id from iot_script
</sql>
<select id="selectRuleScriptList" parameterType="com.fastbee.iot.model.ScriptCondition" resultMap="RuleScriptResult">
<include refid="selectRuleScriptList"/>
<where>
<if test="applicationName != null and applicationName != ''"> and application_name like concat('%', #{applicationName}, '%')</if>
<if test="scriptId != null and scriptId != ''"> and script_id = #{scriptId}</if>
<if test="userId != null and userId != ''"> and user_id = #{userId}</if>
<if test="sceneId != null and sceneId != ''"> and scene_id = #{sceneId}</if>
<if test="productId != null and productId != ''"> and product_id = #{productId}</if>
<if test="scriptEvent != null and scriptEvent != ''"> and script_event = #{scriptEvent}</if>
<if test="scriptAction != null and scriptAction != ''"> and script_action = #{scriptAction}</if>
<if test="scriptPurpose != null and scriptPurpose != ''"> and script_purpose = #{scriptPurpose}</if>
<if test="scriptName != null and scriptName != ''"> and script_name like concat('%', #{scriptName}, '%')</if>
<if test="scriptType != null and scriptType != ''"> and script_type = #{scriptType}</if>
<if test="enable != null"> and enable = #{enable}</if>
<if test="scriptLanguage != null and scriptLanguage != ''"> and script_language = #{scriptLanguage}</if>
</where>
order by script_order
</select>
<select id="selectRuleScriptIdArray" parameterType="com.fastbee.iot.model.ScriptCondition" resultType="String">
select script_id from iot_script
<where>
<if test="applicationName != null and applicationName != ''"> and application_name like concat('%', #{applicationName}, '%')</if>
<if test="sceneId != null and sceneId != ''"> and scene_id = #{sceneId}</if>
<if test="productId != null and productId != ''"> and product_id = #{productId}</if>
<if test="scriptId != null and scriptId != ''"> and script_id = #{scriptId}</if>
<if test="scriptEvent != null and scriptEvent != ''"> and script_event = #{scriptEvent}</if>
<if test="scriptAction != null and scriptAction != ''"> and script_action = #{scriptAction}</if>
<if test="scriptPurpose != null and scriptPurpose != ''"> and script_purpose = #{scriptPurpose}</if>
<if test="enable != null"> and enable = #{enable}</if>
<if test="scriptLanguage != null and scriptLanguage != ''"> and script_language = #{scriptLanguage}</if>
<if test="userId != null and userId != ''"> and (user_id = #{userId} or user_id = #{tencentId})</if>
</where>
order by script_order
</select>
<select id="selectRuleScriptIdCount" parameterType="String" resultType="int">
select count(script_id) from iot_script where script_id = #{scriptId}
</select>
<select id="selectRuleScriptById" parameterType="String" resultMap="RuleScriptResult">
<include refid="selectRuleScriptVo"/>
where script_id = #{scriptId}
</select>
<insert id="insertRuleScript" parameterType="Script" useGeneratedKeys="false">
insert into iot_script
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="userId != null and userId != ''">user_id,</if>
<if test="userName != null and userName != ''">user_name,</if>
<if test="sceneId != null">scene_id,</if>
<if test="scriptEvent != null ">script_event,</if>
<if test="scriptAction != null ">script_action,</if>
<if test="scriptPurpose != null ">script_purpose,</if>
<if test="scriptOrder != null ">script_order,</if>
<if test="applicationName != null and applicationName != ''">application_name,</if>
<if test="scriptId != null and scriptId != ''">script_id,</if>
<if test="scriptName != null and scriptName != ''">script_name,</if>
<if test="scriptData != null">script_data,</if>
<if test="scriptType != null ">script_type,</if>
<if test="scriptLanguage != null and scriptLanguage != ''">script_language,</if>
<if test="enable != null">enable,</if>
<if test="delFlag != null and delFlag != ''">del_flag,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
<if test="remark != null">remark,</if>
<if test="productId != null">product_id,</if>
<if test="productName != null">product_name,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="userId != null and userId != ''">#{userId},</if>
<if test="userName != null and userName != ''">#{userName},</if>
<if test="sceneId != null">#{sceneId},</if>
<if test="scriptEvent != null ">#{scriptEvent},</if>
<if test="scriptAction != null ">#{scriptAction},</if>
<if test="scriptPurpose != null ">#{scriptPurpose},</if>
<if test="scriptOrder != null ">#{scriptOrder},</if>
<if test="applicationName != null and applicationName != ''">#{applicationName},</if>
<if test="scriptId != null and scriptId != ''">#{scriptId},</if>
<if test="scriptName != null and scriptName != ''">#{scriptName},</if>
<if test="scriptData != null">#{scriptData},</if>
<if test="scriptType != null ">#{scriptType},</if>
<if test="scriptLanguage != null and scriptLanguage != ''">#{scriptLanguage},</if>
<if test="enable != null">#{enable},</if>
<if test="delFlag != null and delFlag != ''">#{delFlag},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="remark != null">#{remark},</if>
<if test="productId != null">#{productId},</if>
<if test="productName != null">#{productName},</if>
</trim>
</insert>
<update id="updateRuleScript" parameterType="Script">
update iot_script
<trim prefix="SET" suffixOverrides=",">
<if test="userId != null and userId != ''">user_id = #{userId},</if>
<if test="userName != null and userName != ''">user_name = #{userName},</if>
<if test="sceneId != null and sceneId != ''">scene_id = #{sceneId},</if>
<if test="scriptEvent != null ">script_event = #{scriptEvent},</if>
<if test="scriptAction != null ">script_action = #{scriptAction},</if>
<if test="scriptPurpose != null ">script_purpose = #{scriptPurpose},</if>
<if test="scriptOrder != null ">script_order = #{scriptOrder},</if>
<if test="applicationName != null and applicationName != ''">application_name = #{applicationName},</if>
<if test="scriptId != null and scriptId != ''">script_id = #{scriptId},</if>
<if test="scriptName != null and scriptName != ''">script_name = #{scriptName},</if>
<if test="scriptData != null">script_data = #{scriptData},</if>
<if test="scriptType != null ">script_type = #{scriptType},</if>
<if test="scriptLanguage != null and scriptLanguage != ''">script_language = #{scriptLanguage},</if>
<if test="enable != null">enable = #{enable},</if>
<if test="delFlag != null and delFlag != ''">del_flag = #{delFlag},</if>
<if test="createBy != null and createBy != ''">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="productId != null">product_id = #{productId},</if>
<if test="productName != null">product_name = #{productName},</if>
</trim>
where script_id = #{scriptId}
</update>
<delete id="deleteRuleScriptById" parameterType="String">
delete from iot_script where script_id = #{scriptId}
</delete>
<delete id="deleteRuleScriptByIds" parameterType="String">
delete from iot_script where script_id in
<foreach item="scriptId" collection="array" open="(" separator="," close=")">
#{scriptId}
</foreach>
</delete>
<insert id="insertRuleScriptList" parameterType="java.util.List">
insert into iot_script (user_id,user_name,scene_id,script_event, script_action, script_purpose,script_order,
application_name,script_id,script_name,script_data,script_type,script_language,enable,create_by,create_time,product_id,product_name)
VALUES
<foreach collection ="list" item="ruleScript" separator =",">
(#{ruleScript.userId},
#{ruleScript.userName},
#{ruleScript.sceneId},
#{ruleScript.scriptEvent},
#{ruleScript.scriptAction},
#{ruleScript.scriptPurpose},
#{ruleScript.scriptOrder},
#{ruleScript.applicationName},
#{ruleScript.scriptId},
#{ruleScript.scriptName},
#{ruleScript.scriptData},
#{ruleScript.scriptType},
#{ruleScript.scriptLanguage},
#{ruleScript.enable},
#{ruleScript.createBy},
#{ruleScript.createTime},
#{ruleScript.productId},
#{ruleScript.productName})
</foreach >
</insert>
<delete id="deleteRuleScriptBySceneIds" parameterType="String">
delete from iot_script where scene_id in
<foreach item="sceneId" collection="array" open="(" separator="," close=")">
#{sceneId}
</foreach>
</delete>
</mapper>