<?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.videotaskresource.dao.VideoTaskResourceDao">
  <!-- Result Map -->
  <resultMap id="BaseResultMap" type="com.devplatform.equipment.modules.videotaskresource.bean.VideoTaskResource">
    <result column="id" property="id"/>
    <result column="task_id" property="taskId"/>
    <result column="resource_id" property="resourceId"/>
    <result column="sort" property="sort"/>
    <result column="sys_sign" property="sysSign"/>
    <result column="byx1" property="byx1"/>
    <result column="byx2" property="byx2"/>
    <result column="byx3" property="byx3"/>
    <result column="deleted" property="deleted"/>
    <result column="station_id" property="stationId"/>
  </resultMap>

  <!-- video_task_resource table all fields -->
  <sql id="Base_Column_List">
		id,task_id,resource_id,sort,sys_sign,byx1,byx2,byx3,deleted,station_id
	</sql>

  <!-- 公共查询条件 -->
  <sql id="Example_Where_Clause">
    where deleted=0
    <if test="id!=null and id!=''">and id = #{id}</if>
    <if test="taskId!=null and taskId!=''">and task_id = #{taskId}</if>
    <if test="resourceId!=null and resourceId!=''">and resource_id = #{resourceId}</if>
    <if test="sort!=null and sort!=''">and sort = #{sort}</if>
    <if test="sysSign!=null and sysSign!=''">and sys_sign = #{sysSign}</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="deleted!=null ">and deleted = #{deleted}</if>
    <if test="stationId!=null and stationId!=''">and station_id = #{stationId}</if>
  </sql>

  <select id="queryByTaskId" parameterType="string" resultType="map">
    SELECT
    vtr.id as id,vtr.task_id as taskId,vtr.resource_id as resourceId,vtr.sort as sort,
    lr.code as code , lr.name as name,lr.line_name as lineName,lr.station_name as stationName,lr.deploy_location deployLocation,
    lr.port as port,lr.address_code as ip,lr.username as username,lr.password as password,lr.byx1,lr.byx2,sd.name as type
    FROM video_task_resource vtr
    left join li_resource lr on lr.id = vtr.resource_id and lr.station_id=vtr.station_id
    left join sys_dictionary sd on lr.type = sd.id and sd.station_id=vtr.station_id
    WHERE vtr.task_id = #{taskId}
    <if test="stationId!=null and stationId!=''">and vtr.station_id = #{stationId}</if>
    order by vtr.sort
  </select>
  <select id="getMaxSort" resultType="integer">
    select max(sort) FROM video_task_resource WHERE task_id = #{taskId}
    <if test="stationId!=null and stationId!=''">and station_id = #{stationId}</if>
  </select>

</mapper>


