<?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.devplatform.equipment.modules.link.dao.LinkRuleActionDao">
  <!-- Result Map -->
  <resultMap id="BaseResultMap" type="com.devplatform.equipment.modules.link.bean.LinkRuleAction">
    <result column="id" property="id"/>
    <result column="rule_id" property="ruleId"/>
    <result column="action_id" property="actionId"/>
    <result column="sys_sign" property="sysSign"/>
    <result column="sort_value" property="sortValue"/>
    <result column="params_name1" property="paramsName1"/>
    <result column="params_value1" property="paramsValue1"/>
    <result column="params_name2" property="paramsName2"/>
    <result column="params_value2" property="paramsValue2"/>
    <result column="resource_id" property="resourceId"/>
    <result column="byx1" property="byx1"/>
    <result column="byx2" property="byx2"/>
    <result column="byx3" property="byx3"/>
    <result column="station_id" property="stationId"/>
    <result column="deleted" property="deleted"/>
  </resultMap>

  <!-- link_rule_action table all fields -->
  <sql id="Base_Column_List">
		id,rule_id,action_id,sys_sign,sort_value,params_name1,params_value1,params_name2,params_value2,resource_id,byx1,byx2,byx3,station_id,deleted
	</sql>

  <!-- 公共查询条件 -->
  <sql id="Example_Where_Clause">
    where deleted=0
    <if test="id!=null and id!=''">and id = #{id}</if>
    <if test="ruleId!=null and ruleId!=''">and rule_id = #{ruleId}</if>
    <if test="actionId!=null and actionId!=''">and action_id = #{actionId}</if>
    <if test="sysSign!=null and sysSign!=''">and sys_sign = #{sysSign}</if>
    <if test="sortValue!=null and sortValue!=''">and sort_value = #{sortValue}</if>
    <if test="paramsName1!=null and paramsName1!=''">and params_name1 = #{paramsName1}</if>
    <if test="paramsValue1!=null and paramsValue1!=''">and params_value1 = #{paramsValue1}</if>
    <if test="paramsName2!=null and paramsName2!=''">and params_name2 = #{paramsName2}</if>
    <if test="paramsValue2!=null and paramsValue2!=''">and params_value2 = #{paramsValue2}</if>
    <if test="resourceId!=null and resourceId!=''">and resource_id = #{resourceId}</if>
    <if test="byx1!=null and byx1!=''">and byx1 = #{byx1}</if>
    <if test="byx2!=null and byx2!=''">and byx2 = #{byx2}</if>
    <if test="byx3!=null and byx3!=''">and byx3 = #{byx3}</if>
    <if test="stationId!=null and stationId!=''">and station_id = #{stationId}</if>
    <if test="deleted!=null and deleted!=''">and deleted = #{deleted}</if>
  </sql>

  <select id="getListByRuleId" parameterType="Object" resultType="java.util.Map">
    select lra.id,
    lra.rule_id,
    lra.action_id,
    lra.sys_sign,
    lra.sort_value,
    la.params_name1,
    lra.params_value1,
    la.params_name2,
    lra.params_value2,
    lra.resource_id,
    lra.byx1,
    lra.byx2,
    lra.byx3,
    lra.station_id,
    lra.deleted,
    la.action_info,
    lr.name AS resourceName,
    lr.station_name AS stationName,
    lr.deploy_location AS deployLocation,
    la.byx1 AS unit1,
    la.byx2 AS unit2,
    sp.name as presetName
    from link_rule_action lra
    left join link_action la on la.id = lra.action_id and la.station_id = lra.station_id
    LEFT JOIN li_resource lr ON lr.id = lra.resource_id and lr.station_id = lra.station_id
    LEFT JOIN sys_preset sp ON sp.id = lra.params_value1 and sp.station_id = lra.station_id
    where lra.rule_id = #{ruleId}
    <if test="stationId!=null and stationId!=''">and lra.station_id = #{stationId}</if>
    order by lra.sort_value
  </select>

</mapper>


