<?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.invadedefence.dao.InvadeDefenceDao">
  <!-- Result Map -->
  <resultMap id="BaseResultMap" type="com.devplatform.equipment.modules.invadedefence.bean.InvadeDefence">
    <result column="id" property="id"/>
    <result column="tier_id" property="tierId"/>
    <result column="station_id" property="stationId"/>
    <result column="name" property="name"/>
    <result column="remark" property="remark"/>
    <result column="xpoint" property="xpoint"/>
    <result column="ypoint" property="ypoint"/>
    <result column="xlongit" property="xlongit"/>
    <result column="ylat" property="ylat"/>
    <result column="width" property="width"/>
    <result column="height" property="height"/>
    <result column="status" property="status"/>
    <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="byx1" property="byx1"/>
    <result column="byx2" property="byx2"/>
    <result column="byx3" property="byx3"/>
    <result column="sys_sign" property="sysSign"/>
  </resultMap>

  <!-- invade_defence table all fields -->
  <sql id="Base_Column_List">
		id,tier_id,station_id,name,remark,xpoint,ypoint,xlongit,ylat,width,height,status,deleted,create_user_id,create_time,update_user_id,update_time,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="tierId!=null and tierId!=''">and tier_id = #{tierId}</if>
    <if test="stationId!=null and stationId!=''">and station_id = #{stationId}</if>
    <if test="name!=null and name!=''">and name = #{name}</if>
    <if test="remark!=null and remark!=''">and remark = #{remark}</if>
    <if test="xpoint!=null and xpoint!=''">and xpoint = #{xpoint}</if>
    <if test="ypoint!=null and ypoint!=''">and ypoint = #{ypoint}</if>
    <if test="width!=null and width!=''">and width = #{width}</if>
    <if test="height!=null and height!=''">and height = #{height}</if>
    <if test="status!=null and status!=''">and status = #{status}</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="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>
  <update id="delete" parameterType="string">
    UPDATE invade_defence SET deleted=1 WHERE id =#{id} AND deleted=0
    <if test="stationId!=null and stationId!=''">and station_id = #{stationId}</if>
  </update>
  <select id="getByStationId" parameterType="string" resultType="com.devplatform.equipment.modules.invadedefence.bean.InvadeDefence">
    SELECT
    <include refid="Base_Column_List"></include>
    FROM invade_defence WHERE deleted=0 AND station_id =#{stationId} order by create_time desc
  </select>
  <select id="getByTierId" resultType="com.devplatform.equipment.modules.invadedefence.bean.InvadeDefence">
    SELECT
    <include refid="Base_Column_List"></include>
    FROM invade_defence WHERE deleted=0 AND tier_id =#{tierId}
    <if test="stationId!=null and stationId!=''">and station_id = #{stationId}</if>
    order by create_time desc
  </select>
  <select id="queryByAllList" parameterType="string" resultType="com.devplatform.equipment.modules.invadedefence.bean.InvadeDefence">
    SELECT
    <include refid="Base_Column_List"></include>
    FROM invade_defence WHERE deleted=0
    <if test="stationId!=null and stationId!=''">and station_id = #{stationId}</if>
    order by create_time desc
  </select>
  <select id="queryByEnshrine" resultType="com.devplatform.equipment.modules.invadedefence.bean.InvadeDefence">
    select inv.* from invade_defence inv
    left join li_enshrine le on inv.id = le.resource_id and inv.station_id = le.station_id
    where inv.deleted = 0 and le.deleted = 0 and le.byx1 = '1'
    <if test="name!=null and name!=''">
      and INSTR(inv.name, #{name})
    </if>
    <if test="createUserId!=null and createUserId!=''">
      and inv.create_user_id = #{createUserId}
    </if>
    <if test="stationId!=null and stationId!=''">and inv.station_id = #{stationId}</if>
    order by inv.create_time desc
  </select>


</mapper>


