<?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.zcloud.mapper.datasource.integratedmanagement.GateMachineAreaGateMapper">

    <!--表名 -->
    <sql id="tableName">
        MKMJ_AREA_GATE
    </sql>

    <!-- 字段 -->
    <sql id="Field">
        f
        .
        AREA_GATE_ID
        ,
        f.AREA_ID,
        f.GATE_NUMBER,
        f.GATE_NAME,
        f.GATE_TYPE,
        f.GATE_CATEGORY,
        f.GATE_MODEL,
        f.GATE_POSITION,
        f.LONGITUDE,
        f.LATITUDE,
        f.CORPINFO_ID,
        f.CREATOR,
        f.CREATTIME,
        f.OPERATOR,
        f.OPERATTIME,
        f.ISDELETE
    </sql>

    <!-- 字段用于新增 -->
    <sql id="Field2">
        AREA_GATE_ID
        ,
        AREA_ID,
        GATE_NUMBER,
        GATE_NAME,
        GATE_TYPE,
        GATE_CATEGORY,
        GATE_MODEL,
        LONGITUDE,
        LATITUDE,
        CORPINFO_ID,
        CREATOR,
        CREATTIME,
        OPERATOR,
        OPERATTIME,
        ISDELETE
    </sql>

    <!-- 字段值 -->
    <sql id="FieldValue">
        #{AREA_GATE_ID},
        #{AREA_ID},
        #{GATE_NUMBER},
        #{GATE_NAME},
        #{GATE_TYPE},
        #{GATE_CATEGORY},
        #{GATE_MODEL},
        #{LONGITUDE},
        #{LATITUDE},
        #{CORPINFO_ID},
        #{CREATOR},
        #{CREATTIME},
        #{OPERATOR},
        #{OPERATTIME},
        #{ISDELETE}
    </sql>
    <sql id="FieldValue2">
        #{item.AREA_GATE_ID},
        #{item.AREA_ID},
        #{item.GATE_NUMBER},
        #{item.GATE_NAME},
        #{item.GATE_TYPE},
        #{item.GATE_CATEGORY},
        #{item.GATE_MODEL},
        #{item.LONGITUDE},
        #{item.LATITUDE},
        #{item.CORPINFO_ID},
        #{item.CREATOR},
        #{item.CREATTIME},
        #{item.OPERATOR},
        #{item.OPERATTIME},
        #{item.ISDELETE}
    </sql>

    <!-- 新增-->
    <insert id="save" parameterType="pd">
        insert into
        <include refid="tableName"></include>
        (
        <include refid="Field2"></include>
        ) values (
        <include refid="FieldValue"></include>
        )
    </insert>
    <insert id="saveBatch">
        insert into
        <include refid="tableName"></include>
        (
        <include refid="Field2"></include>
        ) values
        <foreach collection="list" item="item" index="index" separator=",">
            (
            <include refid="FieldValue2"></include>
            )
        </foreach>
    </insert>

    <!-- 修改 -->
    <update id="edit" parameterType="pd">
        update
        <include refid="tableName"></include>
        set
        <if test="GATE_NUMBER != null and GATE_NUMBER != ''">
            GATE_NUMBER = #{GATE_NUMBER},
        </if>
        <if test="GATE_NAME != null and GATE_NAME != ''">
            GATE_NAME = #{GATE_NAME},

        </if>
        <if test="GATE_TYPE != null and GATE_TYPE != ''">
            GATE_TYPE = #{GATE_TYPE},

        </if>

        <if test="GATE_CATEGORY != null and GATE_CATEGORY != ''">
            GATE_CATEGORY = #{GATE_CATEGORY},

        </if>
        <if test="GATE_MODEL != null and GATE_MODEL != ''">
            GATE_MODEL = #{GATE_MODEL},

        </if>
        <if test="GATE_POSITION != null and GATE_POSITION != ''">
            GATE_POSITION = #{GATE_POSITION},

        </if>
        <if test="LONGITUDE != null and LONGITUDE != ''">
            LONGITUDE = #{LONGITUDE},

        </if>
        <if test="LATITUDE != null and LATITUDE != ''">
            LATITUDE = #{LATITUDE},
        </if>
        OPERATOR = #{OPERATOR},
        OPERATTIME = #{OPERATTIME}
        where
        AREA_GATE_ID = #{AREA_GATE_ID}
    </update>

    <!-- 通过ID获取数据 -->
    <select id="findById" parameterType="pd" resultType="pd">
        select
        <include refid="Field"></include>
        from
        <include refid="tableName"></include>
        f
        where
        f.AREA_GATE_ID = #{AREA_GATE_ID}
    </select>

    <!-- 列表 -->
    <select id="datalistPage" parameterType="page" resultType="pd">
        select
        <include refid="Field"></include>
        from
        <include refid="tableName"></include>
        f
        where f.ISDELETE = 0  and f.CORPINFO_ID = #{pd.CORPINFO_ID}
        <if test="pd.AREA_ID != null and pd.AREA_ID != ''">
            and f.AREA_ID = #{pd.AREA_ID}
        </if>
        <if test="pd.KEYWORDS != null and pd.KEYWORDS != ''"><!-- 关键词检索 -->
            and
            (

            GATE_NAME LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
            <!--	根据需求自己加检索条件
       or
      字段2 LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
  -->
            )
        </if>
    </select>


    <!-- 批量删除 -->
    <delete id="deleteAll" parameterType="String">
        update
        <include refid="tableName"></include>
        set
        ISDELETE = 1
        where
        AREA_GATE_ID in
        <foreach item="item" index="index" collection="ArrayDATA_IDS" open="(" separator="," close=")">
            #{item}
        </foreach>
    </delete>

</mapper>
