DeviceJourneyMapper.xml
4.42 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?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.com.glsx.admin.modules.mapper.DeviceJourneyMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.admin.modules.entity.DeviceJourney">
<!--
WARNING - @mbg.generated
-->
<id column="id" jdbcType="INTEGER" property="id"/>
<result column="sn" jdbcType="VARCHAR" property="sn"/>
<result column="vd_id" jdbcType="INTEGER" property="vdId"/>
<result column="begin_time" jdbcType="TIMESTAMP" property="beginTime"/>
<result column="end_time" jdbcType="TIMESTAMP" property="endTime"/>
<result column="begin_address" jdbcType="VARCHAR" property="beginAddress"/>
<result column="end_address" jdbcType="VARCHAR" property="endAddress"/>
<result column="mileage" jdbcType="INTEGER" property="mileage"/>
<result column="del_flag" jdbcType="TINYINT" property="delFlag"/>
<result column="created_date" jdbcType="TIMESTAMP" property="createdDate"/>
<result column="created_by" jdbcType="INTEGER" property="createdBy"/>
<result column="updated_date" jdbcType="TIMESTAMP" property="updatedDate"/>
<result column="updated_by" jdbcType="INTEGER" property="updatedBy"/>
</resultMap>
<sql id="Base_Column_List">
<!--
WARNING - @mbg.generated
-->
id, sn, vd_id, begin_time, end_time, begin_address, end_address, mileage, del_flag,
created_date, created_by, updated_date, updated_by
</sql>
<select id="selectBySnAndBeginTime" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_device_journey
<where>
and sn = #{sn}
and begin_time = #{beginTime}
</where>
limit 1
</select>
<select id="listJourneyBySn" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_device_journey
<where>
and vd_id is not null
and sn in
<foreach collection="snList" item="sn" index="index" open="(" close=")" separator=",">
#{sn}
</foreach>
and begin_time <![CDATA[ >= ]]> #{journeyStartTime}
and begin_time <![CDATA[ <= ]]> #{journeyEndTime}
</where>
</select>
<select id="statisticsDeviceJourneyWithWeek"
resultType="cn.com.glsx.admin.modules.model.dto.UserBehaviorWeekDTO">
SELECT
YEAR(begin_time) AS yearInt,
WEEK(begin_time,1) AS weekInt,
SUM(mileage)/1000 AS weekNum
FROM t_device_journey
WHERE sn = #{sn}
AND del_flag = 0
GROUP BY yearInt, weekInt
ORDER BY yearInt, weekInt
</select>
<select id="statisticsDeviceJourneyWithDay"
resultType="cn.com.glsx.admin.modules.model.dto.UserBehaviorDayDTO">
SELECT
YEAR(begin_time) AS yearInt,
MONTH(begin_time) AS monthInt,
DAY(begin_time) AS dayInt,
SUM(mileage)/1000 AS dayNum
FROM t_device_journey
WHERE sn = #{sn}
AND del_flag = 0
GROUP BY dayInt
ORDER BY dayInt
</select>
<select id="statisUsageBySnGroupByWeek"
resultType="cn.com.glsx.admin.modules.model.vo.VehicleUsageAnalysisPointVO">
SELECT DATE_FORMAT(DATE_ADD(begin_time, INTERVAL (6-WEEKDAY(begin_time)) DAY), '%Y-%m-%d') AS x, count(distinct date(begin_time)) AS y
FROM t_device_journey
where sn = #{sn} and del_flag = 0
group by x
order by x
</select>
<select id="statisMileageBySnGroupByDate"
resultType="cn.com.glsx.admin.modules.model.vo.VehicleUsageAnalysisPointVO">
SELECT DATE_FORMAT(begin_time, '%Y-%m-%d') AS x, sum(mileage)/1000 AS y
FROM t_device_journey
WHERE sn = #{sn} and del_flag = 0
GROUP BY x
ORDER BY x
</select>
<select id="getDailyMileageBySn"
resultType="cn.com.glsx.admin.modules.model.vo.DeviceDailyMileageVO">
SELECT DATE_FORMAT(begin_time, '%Y-%m-%d') AS date, ROUND(SUM(mileage)/1000) AS totalMileage
FROM t_device_journey
WHERE sn = #{sn} AND del_flag = 0
AND begin_time <![CDATA[ >= ]]> #{startTime}
AND begin_time <![CDATA[ <= ]]> #{endTime}
GROUP BY date
ORDER BY date
</select>
</mapper>