<?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.eppatrolplan.dao.EpPatrolPlanDao">
  <!-- Result Map -->
  <resultMap id="BaseResultMap" type="com.devplatform.equipment.modules.eppatrolplan.bean.EpPatrolPlan">
    <result column="id" property="id"/>
    <result column="station_id" property="stationId"/>
    <result column="line_id" property="lineId"/>
    <result column="line_name" property="lineName"/>
    <result column="name" property="name"/>
    <result column="patroller" property="patrollerId"/>
    <result column="start_time" property="startTime"/>
    <result column="end_time" property="endTime"/>
    <result column="circle" property="circle"/>
    <result column="status" property="status"/>
    <result column="sys_sign" property="sysSign"/>
    <result column="deleted" property="deleted"/>
    <result column="create_user_id" property="createUserId"/>
    <result column="create_time" property="createTime"/>
    <result column="update_user_id" property="updateUserId"/>
    <result column="update_time" property="updateTime"/>
    <result column="remark" property="remark"/>
    <result column="patroller_name" property="patrollerName"/>
    <result column="line_station_name" property="lineStationName"/>
    <result column="byx1" property="byx1"/>
    <result column="byx2" property="byx2"/>
    <result column="byx3" property="byx3"/>
  </resultMap>

  <!-- ep_patrol_plan table all fields -->
  <sql id="Base_Column_List">
		id,station_id,line_id,line_name,name,patroller_id,start_time,end_time,circle,status,sys_sign,deleted,create_user_id,create_time,update_user_id,update_time,remark,patroller_name,line_station_name,byx1,byx2,byx3
	</sql>

  <!-- 公共查询条件 -->
  <sql id="Example_Where_Clause">
    where deleted=0
    <if test="id!=null and id!=''">and id = #{id}</if>
    <if test="stationId!=null and stationId!=''">and station_id = #{stationId}</if>
    <if test="lineId!=null and lineId!=''">and line_id = #{lineId}</if>
    <if test="lineName!=null and lineName!=''">and line_name = #{lineName}</if>
    <if test="name!=null and name!=''">and name = #{name}</if>
    <if test="patrollerId!=null and patrollerId!=''">and patroller_id = #{patrollerId}</if>
    <if test="startTime!=null ">and start_time = #{startTime}</if>
    <if test="endTime!=null ">and end_time = #{endTime}</if>
    <if test="circle!=null ">and circle = #{circle}</if>
    <if test="status!=null ">and status = #{status}</if>
    <if test="sysSign!=null and sysSign!=''">and sys_sign = #{sysSign}</if>
    <if test="deleted!=null ">and deleted = #{deleted}</if>
    <if test="createUserId!=null and createUserId!=''">and create_user_id = #{createUserId}</if>
    <if test="createTime!=null ">and create_time = #{createTime}</if>
    <if test="updateUserId!=null and updateUserId!=''">and update_user_id = #{updateUserId}</if>
    <if test="updateTime!=null ">and update_time = #{updateTime}</if>
    <if test="remark!=null and remark!=''">and remark = #{remark}</if>
    <if test="patrollerName!=null and patrollerName!=''">and patroller_name = #{patrollerName}</if>
    <if test="lineStationName!=null and lineStationName!=''">and line_station_name = #{lineStationName}</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>
  <update id="deleteByPlanId" parameterType="string">
    UPDATE ep_patrol_plan SET deleted =1,sys_sign=#{sysSign} WHERE id =#{id} AND deleted=0
    <if test="stationId!=null and stationId!=''">and station_id = #{stationId}</if>
  </update>
  <select id="queryPageByCount" parameterType="com.devplatform.equipment.modules.eppatrolplan.model.EpPatrolPlanModel"
    resultType="java.lang.Integer">

    select count(1) from ep_patrol_plan
    <include refid="queryPageByListClause"></include>
  </select>
  <select id="queryPageByList" parameterType="com.devplatform.equipment.modules.eppatrolplan.model.EpPatrolPlanModel"
    resultType="com.devplatform.equipment.modules.eppatrolplan.bean.EpPatrolPlan">
    select * from ep_patrol_plan
    <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>
  <select id="countByStationIdAndName" parameterType="string" resultType="java.lang.Integer">
		select count(1) from ep_patrol_plan WHERE station_id = #{param1} AND  name=#{param2} and deleted = 0
	</select>
  <select id="countByStationIdAndNameAndId" parameterType="string" resultType="java.lang.Integer">
		select count(1) from ep_patrol_plan WHERE station_id = #{param1} AND  name=#{param2} AND id!=#{param3} and deleted = 0
	</select>
  <select id="countByLineId" parameterType="string" resultType="java.lang.Integer">
    SELECT count(1) FROM ep_patrol_plan WHERE line_id = #{lineId} AND deleted = 0
    <if test="stationId!=null and stationId!=''">and station_id = #{stationId}</if>
  </select>

  <sql id="queryPageByListClause">
    where deleted=0
    <if test="stationId!=null and stationId!=''">and station_id = #{stationId}</if>
    <if test="lineName!=null and lineName!=''">and INSTR(line_name, #{lineName})</if>
    <if test="name!=null and name!=''">and INSTR(name, #{name})</if>

  </sql>
</mapper>


