<?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.orvideomonitor.dao.OrVideoMonitorDao">
  <!-- Result Map -->
  <resultMap id="BaseResultMap" type="com.devplatform.equipment.modules.orvideomonitor.bean.OrVideoMonitor">
    <result column="id" property="id"/>
    <result column="resource_id" property="resourceId"/>
    <result column="station_id" property="stationId"/>
    <result column="resource_name" property="resourceName"/>
    <result column="instruction" property="instruction"/>
    <result column="action_name" property="actionName"/>
    <result column="result" property="result"/>
    <result column="create_user_id" property="createUserId"/>
    <result column="create_user" property="createUser"/>
    <result column="create_time" property="createTime"/>
    <result column="type" property="type"/>
    <result column="line_station_name" property="lineStationName"/>
    <result column="sys_sign" property="sysSign"/>
    <result column="link_rule_action_Id" property="linkRuleActionId"/>
    <result column="byx1" property="byx1"/>
    <result column="byx2" property="byx2"/>
    <result column="byx3" property="byx3"/>
  </resultMap>

  <!-- or_video_monitor table all fields -->
  <sql id="Base_Column_List">
		id,resource_id,resource_name,instruction,action_name,result,create_user_id,create_time,sys_sign,link_rule_action_Id,byx1,byx2,byx3
	</sql>

  <!-- 公共查询条件 -->
  <sql id="Example_Where_Clause">
    where deleted=0
    <if test="id!=null and id!=''">and id = #{id}</if>
    <if test="resourceId!=null and resourceId!=''">and resource_id = #{resourceId}</if>
    <if test="resourceName!=null and resourceName!=''">and resource_name = #{resourceName}</if>
    <if test="instruction!=null and instruction!=''">and instruction = #{instruction}</if>
    <if test="actionName!=null and actionName!=''">and action_name = #{actionName}</if>
    <if test="result!=null ">and result = #{result}</if>
    <if test="createUserId!=null and createUserId!=''">and create_user_id = #{createUserId}</if>
    <if test="createUser!=null and createUser!=''">and create_user = #{createUser}</if>
    <if test="createTime!=null ">and create_time = #{createTime}</if>
    <if test="type!=null and type!=''">and type = #{type}</if>
    <if test="line_station_name!=null and line_station_name!=''">and line_station_name = #{lineStationName}</if>
    <if test="sysSign!=null and sysSign!=''">and sys_sign = #{sysSign}</if>
    <if test="linkRuleActionId!=null and linkRuleActionId!=''">and link_rule_action_Id = #{linkRuleActionId}</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>
  </sql>
  <select id="queryPageByCount" parameterType="com.devplatform.equipment.modules.orvideomonitor.model.OrVideoMonitorModel" resultType="java.lang.Integer">
    select count(1) from or_video_monitor ovm
    <include refid="queryPageByListClause"></include>
  </select>
  <select id="queryPageByList" parameterType="com.devplatform.equipment.modules.orvideomonitor.model.OrVideoMonitorModel"
    resultType="com.devplatform.equipment.modules.orvideomonitor.bean.OrVideoMonitor">
    select ovm.* ,(select status from li_resource lr where lr.id = ovm.resource_id and lr.station_id = ovm.station_id) as status from or_video_monitor ovm
    <include refid="queryPageByListClause"></include>
    <if test="pager.orderCondition != null and pager.orderCondition != ''">
      ${pager.orderCondition}
    </if>
    <if test="pager.mysqlQueryCondition != null and pager.mysqlQueryCondition != ''">
      ${pager.mysqlQueryCondition}
    </if>
  </select>
  <sql id="queryPageByListClause">
    <where>
      <if test="id!=null and id!=''">and ovm.id = #{id}</if>
      <if test="resourceId!=null and resourceId!=''">and ovm.resource_id = #{resourceId}</if>
      <if test="stationId!=null and stationId!=''">and ovm.station_id = #{stationId}</if>
      <if test="resourceName!=null and resourceName!=''">and INSTR(ovm.resource_name, #{resourceName})</if>
      <if test="instruction!=null and instruction!=''">and ovm.instruction = #{instruction}</if>
      <if test="actionName!=null and actionName!=''">and ovm.action_name = #{actionName}</if>
      <if test="result!=null ">and ovm.result = #{result}</if>
      <if test="createUserId!=null and createUserId!=''">and ovm.create_user_id = #{createUserId}</if>
      <if test="startTime!=null">and ovm.create_time &gt;= #{startTime}</if>
      <if test="endTime!=null">and ovm.create_time &lt;= #{endTime}</if>
      <if test="sysSign!=null and sysSign!=''">and ovm.sys_sign = #{sysSign}</if>
    </where>
  </sql>

  <select id="queryById" resultType="java.util.Map">
    select og.id,og.instruction,og.resource_name as resourceName,
    og.line_station_name as lineStationName,og.create_user as createUser,
    lr.sub_system as subSystem,og.type,lr.status,lr.code,lr.address_code as addressCode,
    lr.port,lr.deploy_location as deployLocation,lr.attached_info as attachedInfo,og.action_name as actionName,
    la.params_name1 as paramsName1,
    (case when la.params_name1 != '预置位名称' then lra.params_value1 else (select sp.name from sys_preset sp where sp.id = lra.params_value1 and sp.station_id = lra.station_id) end) as paramsValue1,
    la.params_name2 as paramsName2,lra.params_value2 as paramsValue2,
    og.create_time as createTime,og.source,og.result,ai.event_level as eventLevel
    from or_video_monitor og
    left join li_resource lr on lr.id = og.resource_id and lr.station_id = og.station_id
    left join link_rule_action lra on lra.id = og.link_rule_action_Id and lra.station_id = og.station_id
    left join link_action la on la.id = lra.action_id and la.station_id = og.station_id
    left join alarms_info ai on ai.id = og.alarms_code and ai.station_id = og.station_id
    where og.id = #{id}
    <if test="stationId!=null and stationId!=''">and og.station_id = #{stationId}</if>
  </select>

  <select id="queryById1" resultType="java.util.Map">
    select og.id,og.instruction,og.resource_name as resourceName,
    og.line_station_name as lineStationName,og.create_user as createUser,
    lr.sub_system as subSystem,og.type,lr.status,lr.code,lr.address_code as addressCode,
    lr.port,lr.deploy_location as deployLocation,lr.attached_info as attachedInfo,og.action_name as actionName,
    la.params_name1 as paramsName1,
    (case when la.params_name1 != '预置位名称' then pi.param else (select sp.name from sys_preset sp where sp.id = pi.param and sp.station_id = pi.station_id) end) as paramsValue1,
    la.params_name2 as paramsName2,pi.param_two as paramsValue2,
    og.create_time as createTime,og.source,og.result,ai.event_level as eventLevel
    from or_video_monitor og
    left join li_resource lr on lr.id = og.resource_id and lr.station_id = og.station_id
    left join alarms_plan_step aps on aps.id = og.byx1 and aps.station_id = og.station_id
    LEFT JOIN plan_register_instruct pi ON aps.instruct_id = pi.id and pi.station_id = og.station_id
    left join link_action la on la.id = pi.type and la.station_id = og.station_id
    left join alarms_info ai on ai.id = og.alarms_code and ai.station_id = og.station_id
    where og.id = #{id}
    <if test="stationId!=null and stationId!=''">and og.station_id = #{stationId}</if>
  </select>

  <select id="queryById2" resultType="java.util.Map">
    select og.id,og.instruction,og.resource_name as resourceName,
    og.line_station_name as lineStationName,og.create_user as createUser,
    lr.sub_system as subSystem,og.type,lr.status,lr.code,lr.address_code as addressCode,
    lr.port,lr.deploy_location as deployLocation,lr.attached_info as attachedInfo,og.action_name as actionName,
    la.params_name1 as paramsName1,
    (case when la.params_name1 != '预置位名称' then pi.param else (select sp.name from sys_preset sp where sp.id = pi.param and sp.station_id = pi.station_id) end) as paramsValue1,
    la.params_name2 as paramsName2,pi.param_two as paramsValue2,
    og.create_time as createTime,og.source,og.result,ai.event_level as eventLevel
    from or_video_monitor og
    left join li_resource lr on lr.id = og.resource_id and lr.station_id = og.station_id
    left join plan_log_instruct pli on pli.id = og.byx2 and pli.station_id = og.station_id
    LEFT JOIN plan_register_instruct pi ON pli.instruct_id = pi.id and pi.station_id = og.station_id
    left join link_action la on la.id = pi.type and la.station_id = og.station_id
    left join alarms_info ai on ai.id = og.alarms_code and ai.station_id = og.station_id
    where og.id = #{id}
    <if test="stationId!=null and stationId!=''">and og.station_id = #{stationId}</if>
  </select>
</mapper>


