LocationTrackMapper.xml
2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?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="LocationTrackV1ServiceDaoImpl">
<insert id="saveLocationTrack" parameterType="com.java110.po.property.LocationTrackPo">
INSERT INTO location_track(user_id, longitude, latitude, report_time, bind_relation, loc_status, create_time)
VALUES(#{userId}, #{longitude}, #{latitude}, #{reportTime}, #{bindRelation}, #{locStatus}, NOW())
</insert>
<select id="queryLocationTracks" parameterType="map" resultType="map">
SELECT lt.*, pu.name AS user_name, pu.work_type
FROM location_track lt
LEFT JOIN property_user pu ON lt.user_id = pu.user_id
WHERE 1=1
<if test="userId != null and userId != ''">AND lt.user_id = #{userId}</if>
<if test="startTime != null and startTime != ''">AND lt.report_time >= #{startTime}</if>
<if test="endTime != null and endTime != ''">AND lt.report_time <= #{endTime}</if>
ORDER BY lt.report_time ASC
<if test="page != null and page != '' and row != null and row != ''">
LIMIT #{page}, #{row}
</if>
</select>
<select id="queryLocationTracksCount" parameterType="map" resultType="map">
SELECT COUNT(1) count FROM location_track lt WHERE 1=1
<if test="userId != null and userId != ''">AND lt.user_id = #{userId}</if>
<if test="startTime != null and startTime != ''">AND lt.report_time >= #{startTime}</if>
<if test="endTime != null and endTime != ''">AND lt.report_time <= #{endTime}</if>
</select>
<select id="queryLastLocationByUserId" parameterType="string" resultType="map">
SELECT * FROM location_track WHERE user_id = #{userId} ORDER BY report_time DESC LIMIT 1
</select>
<select id="queryAllLatestLocations" parameterType="map" resultType="map">
SELECT lt.user_id, lt.longitude, lt.latitude, lt.report_time, lt.loc_status,
COALESCE(pu.name, uu.name, lt.user_id) AS user_name,
COALESCE(pu.tel, uu.tel) AS tel,
COALESCE(pu.work_type, 'OTHER') AS work_type
FROM location_track lt
INNER JOIN (
SELECT user_id, MAX(report_time) AS max_time
FROM location_track
WHERE DATE(report_time) = CURDATE()
GROUP BY user_id
) latest ON lt.user_id = latest.user_id AND lt.report_time = latest.max_time
LEFT JOIN property_user pu ON lt.user_id = pu.user_id AND pu.status = 'ON'
LEFT JOIN u_user uu ON lt.user_id = uu.user_id
ORDER BY lt.report_time DESC
</select>
</mapper>