<?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.alarms.dao.AlarmsPlanStepDao">
  <!-- Result Map -->
  <resultMap id="BaseResultMap" type="com.devplatform.equipment.modules.alarms.bean.AlarmsPlanStep">
    <result column="id" property="id"/>
    <result column="alarms_id" property="alarmsId"/>
    <result column="plan_id" property="planId"/>
    <result column="step_id" property="stepId"/>
    <result column="instruct_id" property="instructId"/>
    <result column="action_id" property="actionId"/>
    <result column="action_name" property="actionName"/>
    <result column="system_code" property="systemCode"/>
    <result column="resource_id" property="resourceId"/>
    <result column="run_mode" property="runMode"/>
    <result column="status" property="status"/>
    <result column="deleted" property="deleted"/>
    <result column="create_time" property="createTime"/>
    <result column="create_user_id" property="createUserId"/>
    <result column="update_time" property="updateTime"/>
    <result column="end_time" property="endTime"/>
    <result column="update_user_id" property="updateUserId"/>
    <result column="or_id" property="orId"/>
    <result column="sort" property="sort"/>
    <result column="byx1" property="byx1"/>
    <result column="byx2" property="byx2"/>
    <result column="byx3" property="byx3"/>
    <result column="sys_sign" property="sysSign"/>
  </resultMap>

  <!-- alarms_plan_step table all fields -->
  <sql id="Base_Column_List">
        id,alarms_id,plan_id,step_id,instruct_id,resource_id,action_id,action_name,system_code,run_mode,status,deleted,create_time,create_user_id,update_time,update_user_id,end_time,or_id,sort,byx1,byx2,byx3,sys_sign
    </sql>

  <!-- 公共查询条件 -->
  <sql id="Example_Where_Clause">
    where deleted=0
    <if test="id!=null and id!=''">and id = #{id}</if>
    <if test="alarmsId!=null and alarmsId!=''">and alarms_id = #{alarmsId}</if>
    <if test="planId!=null and planId!=''">and plan_id = #{planId}</if>
    <if test="stepId!=null and stepId!=''">and step_id = #{stepId}</if>
    <if test="instructId!=null and instructId!=''">and instruct_id = #{instructId}</if>
    <if test="runMode!=null ">and run_mode = #{runMode}</if>
    <if test="status!=null ">and status = #{status}</if>
    <if test="deleted!=null ">and deleted = #{deleted}</if>
    <if test="createTime!=null ">and create_time = #{createTime}</if>
    <if test="createUserId!=null and createUserId!=''">and create_user_id = #{createUserId}</if>
    <if test="updateTime!=null ">and update_time = #{updateTime}</if>
    <if test="updateUserId!=null and updateUserId!=''">and update_user_id = #{updateUserId}</if>
    <if test="orId!=null and orId!=''">and or_id = #{orId}</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="sysSign!=null and sysSign!=''">and sys_sign = #{sysSign}</if>
  </sql>

  <!--报警处理(应急预案)步骤信息的service接口实现类-->
  <select id="getPlanStepList" parameterType="java.lang.String" resultMap="BaseResultMap">
        SELECT ps.id,
               ps.alarms_id,
               ps.run_mode,
               ps.system_code,
               ps.action_name,
               li.`name` AS resName,
               sd.`name` AS exeName,
               ps.update_time,
               ps.update_user_id,
               ps.end_time,
               pi.type   AS instructType,
               ps.`status`,
               ps.sort,
               pr.content
        FROM alarms_plan_step ps
                 LEFT JOIN plan_register_step pr ON ps.step_id = pr.id
                 LEFT JOIN plan_register_instruct pi ON ps.instruct_id = pi.id
                 LEFT JOIN li_resource li ON ps.resource_id = li.id
                 LEFT JOIN sys_dictionary sd ON pr.type = sd.id
        WHERE ps.deleted = 0
          AND ps.alarms_id = #{alarmsId}
        ORDER BY ps.sort
    </select>

  <!--报警处理(应急预案)步骤信息的service接口实现类-->
  <select id="getPlanStepList1" parameterType="java.lang.String" resultType="java.util.HashMap">
        SELECT ps.id,
               ps.alarms_id                               AS alarmsId,
               ps.run_mode                                AS runMode,
               ps.system_code                             AS systemCode,
               ps.action_name                             AS actionName,
               ps.resource_id                             AS resourceId,
               ai.event_number                            AS alarmsCode,
               li.`name`                                  AS resName,
               sd.`name`                                  AS exeName,
               ps.update_time                             AS updateTime,
               ps.update_user_id                          AS updateUserId,
               ps.end_time                                AS endTime,
               pi.type                                    AS instructType,
               ps.`status`,
               ps.sort,
               pr.content,
               li.name                                    AS resourceName,
               li.code                                    AS resourceCode,
               li.type                                    AS resourceType,
               li.line_id,
               li.line_name                               AS lineName,
               li.station_id                              AS stationId,
               li.station_name                            AS stationName,
               CONCAT(li.line_name, '-', li.station_name) AS lineStationName,
               li.tier_id                                 AS tierId,
               li.sub_system                              AS subSystem,
               li.sub_code                                AS subCode,
               li.address_code                            AS addressCode,
               li.port,
               li.username,
               li.password,
               li.xpoint,
               li.ypoint,
               li.deploy_location                         AS deployLocation,
               li.attached_info                           AS attachedInfo,
               li.remark,
               li.icon,
               li.parent_name                             AS parentName,
               brand
        FROM alarms_plan_step ps
                 LEFT JOIN alarms_info ai ON ai.id = ps.alarms_id AND ai.deleted = 0
                 LEFT JOIN plan_register_step pr ON ps.step_id = pr.id
                 LEFT JOIN plan_register_instruct pi ON ps.instruct_id = pi.id
                 LEFT JOIN li_resource li ON ps.resource_id = li.id
                 LEFT JOIN sys_dictionary sd ON pr.type = sd.id
        WHERE ps.deleted = 0
          AND ps.alarms_id = #{alarmsId}
        ORDER BY ps.sort
    </select>

  <resultMap id="ResultMap" type="java.util.HashMap">
    <result column="id" property="id"/>
    <result column="alarms_id" property="alarmsId"/>
    <result column="plan_id" property="planId"/>
    <result column="step_id" property="stepId"/>
    <result column="instruct_id" property="instructId"/>
    <result column="system_code" property="systemCode"/>
    <result column="resource_id" property="resourceId"/>
    <result column="run_mode" property="runMode"/>
    <result column="status" property="status"/>
    <result column="deleted" property="deleted"/>
    <result column="create_time" property="createTime"/>
    <result column="create_user_id" property="createUserId"/>
    <result column="update_time" property="updateTime"/>
    <result column="end_time" property="endTime"/>
    <result column="update_user_id" property="updateUserId"/>
    <result column="or_id" property="orId"/>
    <result column="sort" property="sort"/>
    <result column="byx1" property="byx1"/>
    <result column="byx2" property="byx2"/>
    <result column="byx3" property="byx3"/>

    <result column="resourceName" property="resourceName"/>
    <result column="resourceCode" property="resourceCode"/>
    <result column="resourceType" property="resourceType"/>
    <result column="line_id" property="lineId"/>
    <result column="line_name" property="lineName"/>
    <result column="station_id" property="stationId"/>
    <result column="station_name" property="stationName"/>
    <result column="tier_id" property="tierId"/>
    <result column="sub_system" property="subSystem"/>
    <result column="sub_code" property="subCode"/>
    <result column="address_code" property="addressCode"/>
    <result column="port" property="port"/>
    <result column="username" property="username"/>
    <result column="password" property="password"/>
    <result column="xpoint" property="xpoint"/>
    <result column="ypoint" property="ypoint"/>
    <result column="deploy_location" property="deployLocation"/>
    <result column="operator_id" property="operatorId"/>
    <result column="operator_name" property="operatorName"/>
    <result column="attached_info" property="attachedInfo"/>
    <result column="remark" property="remark"/>
    <result column="icon" property="icon"/>
    <result column="parent_name" property="parentName"/>
    <result column="brand" property="brand"/>
  </resultMap>

</mapper>


