<?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.eppatrollinepoint.dao.EpPatrolLinePointDao">
  <!-- Result Map -->
  <resultMap id="BaseResultMap" type="com.devplatform.equipment.modules.eppatrollinepoint.bean.EpPatrolLinePoint">
    <result column="id" property="id"/>
    <result column="layer_id" property="layerId"/>
    <result column="line_id" property="lineId"/>
    <result column="point_id" property="pointId"/>
    <result column="sys_sign" property="sysSign"/>
    <result column="create_user_id" property="createUserId"/>
    <result column="create_time" property="createTime"/>
    <result column="order_num" property="orderNum"/>
    <result column="point_name" property="pointName"/>
    <result column="byx3" property="byx3"/>
    <result column="station_id" property="stationId"/>
    <result column="deleted" property="deleted"/>
    <result column="byx1" property="byx1"/>
    <result column="byx2" property="byx2"/>
  </resultMap>

  <!-- ep_patrol_line_point table all fields -->
  <sql id="Base_Column_List">
		id,layer_id,line_id,point_id,sys_sign,create_user_id,create_time,order_num,point_name,byx3,byx1,byx2,deleted,station_id
	</sql>

  <!-- 公共查询条件 -->
  <sql id="Example_Where_Clause">
    where deleted=0
    <if test="id!=null and id!=''">and id = #{id}</if>
    <if test="layerId!=null and layerId!=''">and layer_id = #{layerId}</if>
    <if test="lineId!=null and lineId!=''">and line_id = #{lineId}</if>
    <if test="pointId!=null and pointId!=''">and point_id = #{pointId}</if>
    <if test="sysSign!=null and sysSign!=''">and sys_sign = #{sysSign}</if>
    <if test="createUserId!=null and createUserId!=''">and create_user_id = #{createUserId}</if>
    <if test="createTime!=null ">and create_time = #{createTime}</if>
    <if test="orderNum!=null">and order_num = #{orderNum}</if>
    <if test="pointName!=null and pointName!=''">and point_name = #{pointName}</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 = #{deleted}</if>
    <if test="byx1!=null and byx1!=''">and byx1 = #{byx1}</if>
    <if test="byx2!=null and byx2!=''">and byx2 = #{byx2}</if>
  </sql>

  <delete id="deleteByLineId" parameterType="string">
    DELETE FROM ep_patrol_line_point WHERE line_id = #{lineId}
    <if test="stationId!=null and stationId!=''">and station_id = #{stationId}</if>
  </delete>
  <select id="countByPatrolId" parameterType="string" resultType="java.lang.Integer">
    SELECT count(1) FROM ep_patrol_line_point WHERE point_id = #{id}
    <if test="stationId!=null and stationId!=''">and station_id = #{stationId}</if>
  </select>
  <select id="getTreeListByLineId"
    parameterType="string" resultType="com.devplatform.equipment.modules.eppatrollinepoint.bean.EpPatrolLinePoint">
    SELECT eplp.*,epp.coordinate_x as coordinateX,epp.coordinate_y as coordinateY,
    epp.`name` as name,epp.byx2 as pointByx2
    FROM ep_patrol_line_point eplp
    left join ep_patrol_point epp on epp.id = eplp.point_id and epp.station_id = eplp.station_id
    WHERE eplp.line_id = #{lineId}
    <if test="stationId!=null and stationId!=''">and eplp.station_id = #{stationId}</if>
    ORDER BY eplp.order_num
  </select>

  <select id="getResultByLineId"
    parameterType="string" resultType="com.devplatform.equipment.modules.eppatrollinepoint.bean.EpPatrolLinePoint">
    SELECT eplp.*,epp.coordinate_x as coordinateX,epp.coordinate_y as coordinateY,
    epp.`name` as name,eppr.patrol_time AS patrolTime,eppp.arrival_time AS arrivalTime,eppl.start_time AS startTime,eppl.end_time AS endTime
    FROM ep_patrol_line_point eplp
    left join ep_patrol_point epp on epp.id = eplp.point_id and epp.station_id = eplp.station_id
    Left join ep_patrol_point_result eppr on epp.id = eppr.point_id and eppr.station_id = eplp.station_id
    LEFT JOIN ep_patrol_plan_point eppp on eppp.point_id = eplp.point_id and eppp.station_id = eplp.station_id
    LEFT JOIN ep_patrol_plan eppl on eppl.id = eppp.plan_id and eppl.station_id = eplp.station_id
    WHERE eppp.plan_id = #{planId} and  eplp.line_id = #{lineId}
    <if test="stationId!=null and stationId!=''">and eplp.station_id = #{stationId}</if>
    ORDER BY eplp.order_num
  </select>


</mapper>