TpESignRecordSMapper.xml 17.3 KB
<?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.zteits.park.mapper.smapper.TpESignRecordSMapper">
    <resultMap id="BaseResultMap" type="com.zteits.park.domain.TpESignRecord">
        <id column="id" jdbcType="BIGINT" property="id" />
        <result column="park_code" jdbcType="VARCHAR" property="parkCode" />
        <result column="device_code" jdbcType="VARCHAR" property="deviceCode" />
        <result column="charger_code" jdbcType="VARCHAR" property="chargerCode" />
        <result column="charger_name" jdbcType="VARCHAR" property="chargerName" />
        <result column="pl_no" jdbcType="VARCHAR" property="plNo" />
        <result column="pl_name" jdbcType="VARCHAR" property="plName" />
        <result column="park_area_codes" jdbcType="VARCHAR" property="parkAreaCodes" />
        <result column="park_area_names" jdbcType="VARCHAR" property="parkAreaNames" />
        <result column="sign_in_time" jdbcType="TIMESTAMP" property="signInTime" />
        <result column="sign_in_lonid" jdbcType="DOUBLE" property="signInLonid" />
        <result column="sign_in_latid" jdbcType="DOUBLE" property="signInLatid" />
        <result column="sign_in_distance" jdbcType="DOUBLE" property="signInDistance" />
        <result column="sign_in_scope" jdbcType="INTEGER" property="signInScope" />
        <result column="sign_in_type" jdbcType="CHAR" property="signInType" />
        <result column="status" jdbcType="CHAR" property="status" />
        <result column="sign_out_type" jdbcType="CHAR" property="signOutType" />
        <result column="sign_out_time" jdbcType="TIMESTAMP" property="signOutTime" />
        <result column="sign_out_lonid" jdbcType="DOUBLE" property="signOutLonid" />
        <result column="sign_out_latid" jdbcType="DOUBLE" property="signOutLatid" />
        <result column="sign_out_distance" jdbcType="DOUBLE" property="signOutDistance" />
        <result column="sign_out_scope" jdbcType="INTEGER" property="signOutScope" />
        <result column="data_status" jdbcType="INTEGER" property="dataStatus" />
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
        <result column="create_op" jdbcType="BIGINT" property="createOp" />
        <result column="modify_time" jdbcType="TIMESTAMP" property="modifyTime" />
        <result column="modify_op" jdbcType="BIGINT" property="modifyOp" />
        <result column="pl_area_block_id" jdbcType="BIGINT" property="plAreaBlockId" />
        <result column="point_all" jdbcType="INTEGER" property="pointAll" />
        <result column="radius_100" jdbcType="DOUBLE" property="radius100" />
        <result column="radius_200" jdbcType="DOUBLE" property="radius200" />
        <result column="radius_300" jdbcType="DOUBLE" property="radius300" />
        <result column="radius_400" jdbcType="DOUBLE" property="radius400" />
        <result column="radius_500" jdbcType="DOUBLE" property="radius500" />
        <result column="radius_600" jdbcType="DOUBLE" property="radius600" />
        <result column="radius_bak1" jdbcType="DOUBLE" property="radiusBak1" />
        <result column="radius_bak2" jdbcType="DOUBLE" property="radiusBak2" />
        <result column="radius_bak3" jdbcType="DOUBLE" property="radiusBak3" />
        <result column="radius_bak4" jdbcType="DOUBLE" property="radiusBak4" />
        <result column="radius_bak5" jdbcType="DOUBLE" property="radiusBak5" />
    </resultMap>
    <sql id="Base_Column_List">
        id, park_code, device_code, charger_code, charger_name, pl_no, pl_name, park_area_codes,
        park_area_names, sign_in_time, sign_in_lonid, sign_in_latid, sign_in_distance, sign_in_scope,
        sign_in_type, status, sign_out_type, sign_out_time, sign_out_lonid, sign_out_latid,
        sign_out_distance, sign_out_scope, data_status, create_time, create_op, modify_time,
        modify_op, pl_area_block_id, point_all, radius_100, radius_200, radius_300, radius_400,
        radius_500, radius_600, radius_bak1, radius_bak2, radius_bak3, radius_bak4, radius_bak5
    </sql>

    <select id="queryIndexSignRecord" resultType="com.zteits.clouds.api.dto.park.dto.IndexSignRecordDTO">
        SELECT
        t.park_code parkCode,
        t.charger_code chargerCode,
        t.modify_time modifyDate,
        t.status status,
        t.pl_name plName,
        t.charger_name chargeName
        FROM ((SELECT
        t1.park_code,
        t1.charger_code,
        t1.modify_time,
        t1.status,
        t1.pl_name,
        t1.charger_name
        FROM tp_e_sign_record t1,
        WHERE
        AND t1.data_status = 1
        and t1.sign_in_type = 1
        AND t1.status = 0
        order by t1.modify_time desc limit 10)
        UNION ALL

        (SELECT
        t1.park_code,
        t1.charger_code,
        t1.modify_time,
        t1.status,
        t1.pl_name,
        t1.charger_name
        FROM tp_e_sign_record t1,
        WHERE
        AND t1.data_status = 1
        AND t1.status = 1
        and t1.sign_in_type = 1
        order by t1.modify_time desc limit 10)
        ) t
        WHERE t.park_code IN
        <foreach collection="plNos" item="plNo" index="index" separator="," open="(" close=")">
            #{plNo}
        </foreach>
        ORDER BY t.modify_time DESC
    </select>

    <!--根据条件查询最新的签到记录-->
    <select id="queryLatestSign" parameterType="com.zteits.park.domain.TpESignRecord" resultMap="BaseResultMap">
        SELECT
        *
        FROM
        tp_e_sign_record
        WHERE
        id = (

        SELECT max( id ) id FROM tp_e_sign_record WHERE data_status = 1
        <if test="signInType != null ">
            and sign_in_type =#{signInType}
        </if>
        <if test="deviceCode != null ">
            and device_code =#{deviceCode}
        </if>
        <if test="plNo != null ">
            and pl_no =#{plNo}
        </if>
        <if test="chargerCode != null ">
            and charger_code =#{chargerCode}
        </if>
        )
    </select>
    
    <!--根据条件查询收费员签到记录-->
    <select id="querySignRecordByChargerCode" parameterType="com.zteits.clouds.api.dto.clouds.param.QueryEmployeeRequest" resultMap="BaseResultMap">


        SELECT
        *
        FROM
        tp_e_sign_record
        WHERE data_status = 1
        and sign_in_type = 1
        <if test="chargerCode != null ">
            and charger_code =#{chargerCode}
        </if>
        <if test="chargerCodes != null and chargerCodes.size>0">
            and charger_code in
            <foreach collection="chargerCodes" item="chargerCode" index="index" open="(" close=")" separator=",">
                #{chargerCode}
            </foreach>
        </if>
        <if test="beginTime != null and endTime != null">
            and sign_in_time between #{beginTime,jdbcType=TIMESTAMP} and #{endTime,jdbcType=TIMESTAMP}
        </if>
        <if test="distanceFlag != null">
            <if test="distanceFlag == 0">
                AND (sign_in_distance &lt;= #{distance}) AND (sign_out_distance &lt;= #{distance}  OR sign_out_distance IS NULL)
            </if>
            <if test="distanceFlag == 1">
                AND ((sign_in_distance &gt; #{distance} OR sign_in_distance IS NULL)
                OR (sign_out_distance &gt; #{distance}))
            </if>
        </if>
        order by sign_in_distance


    </select>
    <!--根据条件查询每个停车场收费员实际签到人数-->
    <select id="querySignNumByPlNos" parameterType="com.zteits.clouds.api.dto.clouds.param.QueryEmployeeRequest" 
    resultType="com.zteits.clouds.api.dto.park.dto.ParkinglotBasicFactsDTO">
        SELECT
            pl_no as plNo,
            count(DISTINCT charger_code) as signInTollCollector
        FROM
        tp_e_sign_record
        WHERE data_status = 1
        and sign_in_type = 1
        <if test="chargerCode != null ">
            and charger_code =#{chargerCode}
        </if>
        <if test="plNos != null and plNos.size>0">
            and pl_no in
            <foreach collection="plNos" item="plNo" index="index" open="(" close=")" separator=",">
                #{plNo}
            </foreach>
        </if>
        <if test="chargerCodes != null and chargerCodes.size>0">
            and charger_code in
            <foreach collection="chargerCodes" item="chargerCode" index="index" open="(" close=")" separator=",">
                #{chargerCode}
            </foreach>
        </if>
        <if test="beginTime != null and endTime != null">
            and sign_in_time between #{beginTime,jdbcType=TIMESTAMP} and #{endTime,jdbcType=TIMESTAMP}
        </if>
        <if test="distanceFlag != null">
            <if test="distanceFlag == 0">
                AND (sign_in_distance &lt;= #{distance}) AND (sign_out_distance &lt;= #{distance}  OR sign_out_distance IS NULL)
            </if>
             <if test="distanceFlag == 1">
                AND ((sign_in_distance &gt; #{distance} OR sign_in_distance IS NULL) 
                    OR (sign_out_distance &gt; #{distance}))
            </if>
        </if>
        group by pl_no
    </select>
    
    <resultMap id="signRecordMap" type="com.zteits.clouds.api.dto.park.dto.SignRecordDTO">
        <id column="id" jdbcType="BIGINT" property="id" />
        <result column="park_code" jdbcType="VARCHAR" property="parkCode" />
        <result column="device_code" jdbcType="VARCHAR" property="deviceCode" />
        <result column="charger_code" jdbcType="VARCHAR" property="chargerCode" />
        <result column="charger_name" jdbcType="VARCHAR" property="chargerName" />
        <result column="pl_no" jdbcType="VARCHAR" property="plNo" />
        <result column="pl_name" jdbcType="VARCHAR" property="plName" />
        <result column="park_area_codes" jdbcType="VARCHAR" property="parkAreaCodes" />
        <result column="park_area_names" jdbcType="VARCHAR" property="parkAreaNames" />
        <result column="sign_in_time" jdbcType="TIMESTAMP" property="signInTime" />
        <result column="sign_in_lonid" jdbcType="DOUBLE" property="signInLonid" />
        <result column="sign_in_latid" jdbcType="DOUBLE" property="signInLatid" />
        <result column="sign_in_distance" jdbcType="DOUBLE" property="signInDistance" />
        <result column="sign_in_scope" jdbcType="INTEGER" property="signInScope" />
        <result column="status" jdbcType="CHAR" property="status" />
        <result column="sign_out_type" jdbcType="CHAR" property="signOutType" />
        <result column="sign_out_time" jdbcType="TIMESTAMP" property="signOutTime" />
        <result column="sign_out_lonid" jdbcType="DOUBLE" property="signOutLonid" />
        <result column="sign_out_latid" jdbcType="DOUBLE" property="signOutLatid" />
        <result column="sign_out_distance" jdbcType="DOUBLE" property="signOutDistance" />
        <result column="sign_out_scope" jdbcType="INTEGER" property="signOutScope" />
        <result column="data_status" jdbcType="INTEGER" property="dataStatus" />
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
        <result column="create_op" jdbcType="BIGINT" property="createOp" />
        <result column="modify_time" jdbcType="TIMESTAMP" property="modifyTime" />
        <result column="modify_op" jdbcType="BIGINT" property="modifyOp" />
        <result column="pl_area_block_id" jdbcType="BIGINT" property="plAreaBlockId" />
        <result column="gpsRate" jdbcType="DOUBLE" property="gpsRate" />
    </resultMap>
    <!--根据条件查询收费员签到记录(带GPS阈值)-->
    <select id="querySignRecordAndRateByChargerCode" parameterType="com.zteits.clouds.api.dto.clouds.param.QueryEmployeeRequest" resultMap="signRecordMap">
        SELECT
			c.*
		FROM
			(
				SELECT
					a.*, b.inNum / (b.inNum + b.outNum) gpsRate
				FROM
					tp_e_sign_record a
				LEFT JOIN
		(SELECT
			t.sign_record_id,
			SUM(CASE WHEN t.sign_distance &lt;= #{distance} THEN 1 ELSE 0 END ) inNum,
			SUM(CASE WHEN t.sign_distance > #{distance} THEN 1 ELSE 0 END ) outNum
		FROM
			tp_e_employee_tail t
		WHERE
			t.data_state = 1
		GROUP BY t.sign_record_id)b ON a.id = b.sign_record_id
		WHERE a.data_status = 1
		and a.sign_in_type = 1
		<if test="chargerCode != null ">
            and a.charger_code =#{chargerCode}
        </if>
        <if test="chargerCodes != null and chargerCodes.size>0">
            and a.charger_code in
            <foreach collection="chargerCodes" item="chargerCode" index="index" open="(" close=")" separator=",">
                #{chargerCode}
            </foreach>
        </if>
        <if test="plNos != null and plNos.size>0">
            and a.pl_no in
            <foreach collection="plNos" item="plNo" index="index" open="(" close=")" separator=",">
                #{plNo}
            </foreach>
        </if>
        <if test="beginTime != null and endTime != null">
            and sign_in_time between #{beginTime,jdbcType=TIMESTAMP} and #{endTime,jdbcType=TIMESTAMP}
        </if>
        <if test="signInBeginTime != null ">
            and a.sign_in_time >= #{signInBeginTime,jdbcType=TIMESTAMP} 
        </if>
        <if test="signInEndTime != null">
            and a.sign_in_time &lt;= #{signInEndTime,jdbcType=TIMESTAMP}
        </if>
        
        <if test="signOutBeginTime != null">
            and a.sign_out_time >= #{signOutBeginTime,jdbcType=TIMESTAMP}
        </if>
        <if test="signOutEndTime != null">
            and a.sign_out_time &lt;= #{signOutEndTime,jdbcType=TIMESTAMP}
        </if>
        <if test="distanceFlag != null">
            <if test="distanceFlag == 0">
                AND (a.sign_in_distance &lt;= #{distance}) AND (a.sign_out_distance &lt;= #{distance}  OR a.sign_out_distance IS NULL)
            </if>
             <if test="distanceFlag == 1">
                AND ((a.sign_in_distance &gt; #{distance} OR a.sign_in_distance IS NULL) 
                    OR (a.sign_out_distance &gt; #{distance}))
            </if>
        </if>
		
		ORDER BY a.create_time DESC)c
		WHERE 1=1 
		<if test="distanceFlag != null">
			AND c.gpsRate >= #{gpsRate}
		</if>
        
        
    </select>
    
    <!--根据条件查询收费员签到记录(单表带GPS阈值)-->
    <select id="querySignRecordAndRateByChargerCodeNew" parameterType="com.zteits.clouds.api.dto.clouds.param.QueryEmployeeRequest" resultMap="signRecordMap">
    	SELECT
					a.*,(a.radius_${distanceCol})/100 as gpsRate
				FROM
					tp_e_sign_record a
		WHERE a.data_status = 1
		and a.sign_in_type = 1
		<if test="distance != null and distanceCol != null and distanceCol != ''">
			<if test ="distanceFlag == 0">
				and (a.radius_${distanceCol})/100 >= #{gpsRate}
			</if>
			<if test ="distanceFlag == 1">
				and (a.radius_${distanceCol})/100 &lt; #{gpsRate}
				and a.sign_out_time is not null
			</if>
			<if test ="distanceFlag == 2">
				and (a.radius_${distanceCol})/100 &lt; #{gpsRate}
				and a.sign_out_time is null
			</if>
			<if test ="distanceFlag == null">
				and (a.radius_${distanceCol})/100 >= 0
			</if>
		</if>
		<if test="chargerCode != null ">
            and a.charger_code =#{chargerCode}
        </if>
        <if test="chargerCodes != null and chargerCodes.size>0">
            and a.charger_code in
            <foreach collection="chargerCodes" item="chargerCode" index="index" open="(" close=")" separator=",">
                #{chargerCode}
            </foreach>
        </if>
        <if test="plNos != null and plNos.size>0">
            and a.pl_no in
            <foreach collection="plNos" item="plNo" index="index" open="(" close=")" separator=",">
                #{plNo}
            </foreach>
        </if>
        <if test="beginTime != null and endTime != null">
            and a.sign_in_time between #{beginTime,jdbcType=TIMESTAMP} and #{endTime,jdbcType=TIMESTAMP}
        </if>
        <if test="signInBeginTime != null ">
            and a.sign_in_time >= #{signInBeginTime,jdbcType=TIMESTAMP} 
        </if>
        <if test="signInEndTime != null">
            and a.sign_in_time &lt;= #{signInEndTime,jdbcType=TIMESTAMP}
        </if>
        
        <if test="signOutBeginTime != null">
            and a.sign_out_time >= #{signOutBeginTime,jdbcType=TIMESTAMP}
        </if>
        <if test="signOutEndTime != null">
            and a.sign_out_time &lt;= #{signOutEndTime,jdbcType=TIMESTAMP}
        </if>
        
        <if test="inBeginTime != null and inBeginTime != '' ">
            and TIME(a.sign_in_time) >= #{inBeginTime} 
        </if>
        <if test="inEndTime != null and inEndTime != '' ">
            and TIME(a.sign_in_time) &lt;= #{inEndTime}
        </if>
        <if test="outBeginTime != null and outBeginTime != '' ">
            and TIME(a.sign_out_time) >= #{outBeginTime}
        </if>
        <if test="outEndTime != null and  outEndTime != '' ">
            and TIME(a.sign_out_time) &lt;= #{outEndTime}
        </if>
        
		ORDER BY a.sign_in_distance
    </select>
    
    	<!--  <if test="distanceFlag != null">
            <if test="distanceFlag == 0">
                AND (a.sign_in_distance &lt;= #{distance}) AND (a.sign_out_distance &lt;= #{distance}  OR a.sign_out_distance IS NULL)
            </if>
             <if test="distanceFlag == 1">
                AND ((a.sign_in_distance &gt; #{distance} OR a.sign_in_distance IS NULL) 
                    OR (a.sign_out_distance &gt; #{distance})
                    OR (a.sign_out_distance is null)
                    )
            </if>
        </if> -->
</mapper>