<?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.GateCarRecordMapper">

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

    <!-- 字段 -->
    <sql id="Field">
        f.RECORD_ID,
        f.TURNSTILES_ID,
        f.CORPINFO_ID,
        f.TICKET,
        f.ENTRANCE_DATE,
        f.ENTRANCE_TURNSTILES_NAME,
        f.LEAVE_DATE,
        f.LEAVE_TURNSTILES_NAME,
        f.ISDELETE,
        f.CREATOR,
        f.CREATTIME,
        f.OPERATOR,
        f.OPERATTIME
    </sql>

    <!-- 字段用于新增 -->
    <sql id="Field2">
        RECORD_ID,
        TURNSTILES_ID,
        CORPINFO_ID,
        TICKET,
        ENTRANCE_DATE,
        ENTRANCE_TURNSTILES_NAME,
        LEAVE_DATE,
        LEAVE_TURNSTILES_NAME,
        ISDELETE,
        CREATOR,
        CREATTIME,
        OPERATOR,
        OPERATTIME
    </sql>

    <!-- 字段值 -->
    <sql id="FieldValue">
        #{RECORD_ID},
        #{TURNSTILES_ID},
        #{CORPINFO_ID},
        #{TICKET},
        #{ENTRANCE_DATE},
        #{ENTRANCE_TURNSTILES_NAME},
        #{LEAVE_DATE},
        #{LEAVE_TURNSTILES_NAME},
        #{ISDELETE},
        #{CREATOR},
        #{CREATTIME},
        #{OPERATOR},
        #{OPERATTIME}
    </sql>

    <!-- 新增-->
    <insert id="save" parameterType="pd">
        insert into
        <include refid="tableName"></include>
        (
        <include refid="Field2"></include>
        ) values (
        <include refid="FieldValue"></include>
        )
    </insert>

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

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

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

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

    <!-- 通过ID获取数据 -->
    <select id="findById" parameterType="pd" resultType="pd">
        select
        <include refid="Field"></include>
        from
        <include refid="tableName"></include>
        f
        where
        f.RECORD_ID = #{RECORD_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>
    <select id="getBIEntryExitCarlistPage" resultType="com.zcloud.entity.PageData">
        select
        <include refid="Field"></include>
        from
        <include refid="tableName"></include>
        f
        where f.ISDELETE = 0  and f.CORPINFO_ID = #{pd.CORPINFO_ID}
    </select>


    <select id="getBICarFieldCondition" resultType="com.zcloud.entity.PageData">
        SELECT
        <include refid="Field"/>
        FROM
        <include refid="tableName"/> f
        WHERE f.ISDELETE = 0 AND f.CORPINFO_ID = #{CORPINFO_ID}
    </select>


</mapper>
