<?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="cn.cecep.talroad.mapper.AmDoorMonitorAccountFiMapper">

    <resultMap type="cn.cecep.talroad.domain.AmDoorMonitorAccountFi" id="AmDoorMonitorAccountFiResult">
        <result property="id"    column="id"    />
        <result property="factoryId"    column="factory_id"    />
        <result property="lpnCode"    column="lpn_code"    />
        <result property="entryType"    column="entry_type"    />
        <result property="entryTime"    column="entry_time"    />
        <result property="carTeam"    column="car_team"    />
        <result property="dischargeStage"    column="discharge_stage"    />
        <result property="ngineCode"    column="ngine_code"    />
        <result property="ioType"    column="io_type"    />
        <result property="cargoQuantity"    column="cargo_quantity"    />
        <result property="drivingLicenseImage"    column="driving_license_image"    />
        <result property="accessoryListImage"    column="accessory_list_image"    />
    </resultMap>


    <sql id="selectAmDoorMonitorAccountFiVo">
        select id, factory_id, lpn_code, entry_type, entry_time, car_team, discharge_stage, ngine_code, io_type, cargo_quantity, driving_license_image, accessory_list_image from m_am_door_monitor_account_fi
    </sql>

    <select id="selectAmDoorMonitorAccountFiList" parameterType="cn.cecep.talroad.domain.AmDoorMonitorAccountFi" resultMap="AmDoorMonitorAccountFiResult">
        <include refid="selectAmDoorMonitorAccountFiVo"/>
        <where>
            <if test="factoryId != null  and factoryId != ''"> and factory_id = #{factoryId}</if>
            <if test="lpnCode != null  and lpnCode != ''"> and lpn_code = #{lpnCode}</if>
            <if test="entryType != null  and entryType != ''"> and entry_type = #{entryType}</if>
            <if test="entryTime != null  and entryTime != ''"> and entry_time = #{entryTime}</if>
            <if test="carTeam != null  and carTeam != ''"> and car_team = #{carTeam}</if>
            <if test="dischargeStage != null  and dischargeStage != ''"> and discharge_stage = #{dischargeStage}</if>
            <if test="ngineCode != null  and ngineCode != ''"> and ngine_code = #{ngineCode}</if>
            <if test="ioType != null  and ioType != ''"> and io_type = #{ioType}</if>
            <if test="cargoQuantity != null  and cargoQuantity != ''"> and cargo_quantity = #{cargoQuantity}</if>
            <if test="drivingLicenseImage != null  and drivingLicenseImage != ''"> and driving_license_image = #{drivingLicenseImage}</if>
            <if test="accessoryListImage != null  and accessoryListImage != ''"> and accessory_list_image = #{accessoryListImage}</if>
        </where>
    </select>

    <select id="selectLabelAccount" resultType="cn.cecep.talroad.vo.AmDoorMonitorAccountFiVo">
        SELECT factory_id, discharge_stage,count(1) as quantity FROM "m_am_door_monitor_account_fi"
        where entry_time
            BETWEEN #{startTime} and #{endTime}
          and discharge_stage is not null
        GROUP BY factory_id,discharge_stage
    </select>
    <select id="selectLabel" resultType="cn.cecep.talroad.vo.AmDoorMonitorAccountFiVo">
        SELECT factory_id, string_agg(distinct discharge_stage,',') discharge_stage FROM "m_am_door_monitor_account_fi"
        where entry_time
            BETWEEN #{startTime} and #{endTime}
          and discharge_stage is not null
        GROUP BY factory_id
    </select>
    <select id="selectCarEntryCount" resultType="cn.cecep.talroad.vo.AmDoorMonitorAccountFiVo">
        SELECT factory_id,count(1) as quantity FROM "m_am_door_monitor_account_fi"
        where entry_time
            BETWEEN #{lastHourBegin} and #{lastHourEnd}
          and entry_time
            BETWEEN #{controlStartTime} and #{controlEndTime}
          and discharge_stage in('I','II','III','IV')
        GROUP BY factory_id

    </select>
</mapper>
