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

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

    <!-- 字段 -->
    <sql id="Field">
        f
        .
        RECORD_ID
        ,
        f.CORPINFO_ID,
        f.USER_NAME,
        f.EVENT_TIME,
        f.DEPT_NAME,
        f.CARD_NO,
        f.AREA_NAME,
        f.DEV_SN,
        f.DOOR_NAME,
        f.READER_NAME,
        f.READER,
        f.VERIFY_MODE_NAME,
        f.ISDELETE,
        f.DEV_NAME,
        f.CREATOR,
        f.CREATTIME,
        f.OPERATOR,
        f.OPERATTIME
    </sql>

    <!-- 字段用于新增 -->
    <sql id="Field2">
        RECORD_ID
        ,
        CORPINFO_ID,
        USER_NAME,
        EVENT_TIME,
        DEPT_NAME,
        CARD_NO,
        AREA_NAME,
        DEV_SN,
        DOOR_NAME,
        READER_NAME,
        READER,
        VERIFY_MODE_NAME,
        ISDELETE,
        DEV_NAME,
        CREATOR,
        CREATTIME,
        OPERATOR,
        OPERATTIME
    </sql>

    <!-- 字段值 -->
    <sql id="FieldValue">
        #{RECORD_ID}
        ,
        #{CORPINFO_ID},
        #{USER_NAME},
        #{EVENT_TIME},
        #{DEPT_NAME},
        #{CARD_NO},
        #{AREA_NAME},
        #{DEV_SN},
        #{DOOR_NAME},
        #{READER_NAME},
        #{READER},
        #{VERIFY_MODE_NAME},
        #{ISDELETE},
        #{DEV_NAME},
        #{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="USER_NAME != null and USER_NAME != ''">
            USER_NAME = #{USER_NAME},
        </if>
        <if test="EVENT_TIME != null and EVENT_TIME != ''">
            EVENT_TIME = #{EVENT_TIME},
        </if>
        <if test="DEPT_NAME != null and DEPT_NAME != ''">
            DEPT_NAME = #{DEPT_NAME},

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

        </if>
        <if test="AREA_NAME != null and AREA_NAME != ''">
            AREA_NAME = #{AREA_NAME},
        </if>
        <if test="DEV_SN != null and DEV_SN != ''">
            DEV_SN = #{DEV_SN},
        </if>
        <if test="DOOR_NAME != null and DOOR_NAME != ''">
            DOOR_NAME = #{DOOR_NAME},
        </if>
        <if test="READER_NAME != null and READER_NAME != ''">
            READER_NAME = #{READER_NAME},
        </if>
        <if test="READER != null and READER != ''">
            READER = #{READER},
        </if>
        <if test="VERIFY_MODE_NAME != null and VERIFY_MODE_NAME != ''">
            VERIFY_MODE_NAME = #{VERIFY_MODE_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>,g.GATE_NAME,a.AREA_NAME AREA_NAME_WHB
        from
        <include refid="tableName"></include>
        f
        left join mkmj_area_gate g on f.DEV_SN = g.GATE_NUMBER
        left join mkmj_area a on a.AREA_ID = g.AREA_ID
        where f.ISDELETE = 0 and f.CORPINFO_ID = #{pd.CORPINFO_ID}
        and g.ISDELETE = 0
        <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
            (
            f.AREA_NAME LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%') or
            f.DOOR_NAME LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
            <!--	根据需求自己加检索条件
       or
      字段2 LIKE CONCAT(CONCAT('%', #{pd.KEYWORDS}),'%')
  -->
            )
        </if>
        <if test="pd.STARTTIME != null and pd.STARTTIME != ''">
            and DATE_FORMAT(CONCAT(#{pd.STARTTIME},' 00:00:00'),'%Y-%m-%d %H:%i:%s') &lt;=
            DATE_FORMAT(f.EVENT_TIME,'%Y-%m-%d %H:%i:%s')

        </if>
        <if test="pd.ENDTIME != null and pd.ENDTIME != ''">
            and DATE_FORMAT(CONCAT(#{pd.ENDTIME},' 23:59:59'),'%Y-%m-%d %H:%i:%s') &gt;=
            DATE_FORMAT(f.EVENT_TIME,'%Y-%m-%d %H:%i:%s')
        </if>
        ORDER BY f.EVENT_TIME DESC
    </select>

    <select id="getBIEntryExitPeoLoglistPage" resultType="com.zcloud.entity.PageData">
        SELECT
        <include refid="Field"></include>,g.GATE_NAME
        FROM
        <include refid="tableName"></include>
        f
        left join mkmj_area_gate g on f.DEV_SN = g.GATE_NUMBER
        WHERE f.ISDELETE = 0 AND f.CORPINFO_ID = #{pd.CORPINFO_ID} and g.GATE_POSITION = 0
        ORDER BY f.EVENT_TIME DESC
    </select>

    <select id="getBIPeopleFieldCondition" resultType="com.zcloud.entity.PageData">
        select
        <include refid="Field"></include>
        from
        <include refid="tableName"></include>
        f
        where f.ISDELETE = 0 and f.CORPINFO_ID = #{CORPINFO_ID}
    </select>

</mapper>
