<?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.njcn.mapper.configuration.TerminalLogsMapper'>
    <resultMap type="TerminalLogs" id="getResultMap" autoMapping="true">
        <id column="LOGS_INDEX" property="logsIndex"/>
    </resultMap>
    <select id="selectLogs" resultMap="getResultMap">
        SELECT *
        FROM PQS_TERMINALLOGS
        where updateTime between #{startTime} and #{endTime}
        ORDER BY UPDATETIME desc
    </select>

    <select id="selectLog" resultMap="getResultMap">
        SELECT *
        FROM PQS_TERMINALLOGS
        WHERE TERMINAL_TYPE = #{terminalType}
          and updateTime between #{startTime} and #{endTime}
        ORDER BY UPDATETIME desc
    </select>

    <select id="selectLogByDevId" resultMap="getResultMap">
        SELECT b.name as objIndex,a.updatetime as updateTime,c.name as userIndex,a.TERMINAL_DESCRIBE as terminalDescribe
        FROM PQS_TERMINALLOGS a
        inner join pq_device b on a.obj_index= b.dev_index
        inner join pqs_user c on a.user_index = c.user_index
        WHERE a.TERMINAL_TYPE = #{terminalType}
        and a.obj_index = #{devId}
        and a.updateTime between #{startTime} and #{endTime}

        ORDER BY a.UPDATETIME desc
    </select>

    <insert id="batchAddTerminalLogs" parameterType="com.njcn.pojo.configuration.TerminalLogs">
        insert into pqs_terminallogs
        (logs_index,obj_index,terminal_describe,updatetime,user_index,terminal_type)
        <foreach collection="list" open="(" close=")" item="item" separator="union all">
            select
            #{item.logsIndex},#{item.objIndex},#{item.terminalDescribe},#{item.updateTime},#{item.userIndex},#{item.terminalType}
            from dual
        </foreach>
    </insert>
</mapper>
