VehicleDeviceMapper.xml
9.83 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<?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.stdinterface.modules.mapper.VehicleDeviceMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.stdinterface.modules.entity.VehicleDevice">
<!--
WARNING - @mbg.generated
-->
<id column="id" jdbcType="INTEGER" property="id"/>
<result column="vehicle_id" jdbcType="INTEGER" property="vehicleId"/>
<result column="sn" jdbcType="VARCHAR" property="sn"/>
<result column="bind_status" jdbcType="TINYINT" property="bindStatus"/>
<result column="trial_type" jdbcType="TINYINT" property="trialType"/>
<result column="his_type" jdbcType="TINYINT" property="hisType"/>
<result column="wire_type" jdbcType="TINYINT" property="wireType"/>
<result column="active_flag" jdbcType="TINYINT" property="activeFlag"/>
<result column="active_location_date" jdbcType="TIMESTAMP" property="activeLocationDate"/>
<result column="active_location_lng" jdbcType="VARCHAR" property="activeLocationLng"/>
<result column="active_location_lat" jdbcType="VARCHAR" property="activeLocationLat"/>
<result column="active_location_type" jdbcType="TINYINT" property="activeLocationType"/>
<result column="active_location_address" jdbcType="VARCHAR" property="activeLocationAddress"/>
<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, vehicle_id, sn, bind_status, trial_type, his_type, wire_type, active_flag, active_location_date,
active_location_lng, active_location_lat, active_location_type, active_location_address,
del_flag, created_date, created_by, updated_date, updated_by
</sql>
<select id="getVdIdbySn" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_vehicle_device
where sn = #{sn}
and bind_status = 2
and his_type = 1
order by id desc limit 1
</select>
<select id="selectBindingDeviceBySn" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_vehicle_device
where del_flag = 0
and sn = #{sn}
and bind_status = 1
limit 1
</select>
<select id="selectBindingDevices" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_vehicle_device
where del_flag = 0
and bind_status = 1
and sn in
<foreach collection="sns" separator="," open="(" close=")" item="item">
#{item}
</foreach>
</select>
<select id="selectBindingDevicesByVehicleId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_vehicle_device
where del_flag = 0
and bind_status = 1
and vehicle_id = #{vehicleId}
</select>
<select id="selectVehicleDevcieBySn" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_vehicle_device
where del_flag = 0
and bind_status = 1
and sn = #{sn}
order by id desc limit 1
</select>
<select id="getUnActiveInfoSnList" resultType="java.lang.String">
select sn
from t_vehicle_device
where del_flag = 0
and bind_status = 1
and left(created_date, 10) <![CDATA[ >= ]]> #{dayTimeFormat}
and active_location_date is null
</select>
<select id="getAllUnActiveInfoSnList" resultType="java.lang.String">
select sn
from t_vehicle_device
where del_flag = 0
and bind_status = 1
and active_location_date is null
</select>
<update id="updateVehicleDeviceBysn">
update t_vehicle_device
set active_location_date = #{activeLocationDate},
active_location_type = #{activeLocationType},
active_location_lat = #{activeLocationLat},
active_location_lng = #{activeLocationLng},
active_location_address = #{activeLocationAddress}
where sn = #{sn}
and del_flag = 0
and bind_status = 1
</update>
<select id="selectByVehicleId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_vehicle_device
<where>
and bind_status = 1
and del_flag = 0
and vehicle_id = #{vehicleId}
</where>
order by id
</select>
<select id="selectBindDeviceBySn" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_vehicle_device
<where>
sn = #{sn}
and bind_status = 1
and del_flag = 0
limit 1
</where>
</select>
<select id="countBindVehicleByCreatedIds" resultType="java.lang.Integer">
select ifnull(count(*),0) from t_vehicle tv where tv.created_by in
<foreach collection="createdIds" separator="," open="(" close=")" item="item">
#{item}
</foreach>
and tv.del_flag =0;
</select>
<select id="listCreatedIdByTenantId" resultType="java.lang.Integer">
select id from t_user tu where tu.tenant_id = #{tenantId} and tu.del_flag =0
</select>
<select id="countActiveSnByCreatedIds" resultType="java.lang.Integer">
select ifnull(count(*),0)
from t_vehicle tv,t_vehicle_device tvd
where tv.id =tvd.vehicle_id
and tv.created_by in
<foreach collection="createdIds" separator="," open="(" close=")" item="item">
#{item}
</foreach>
and tv.del_flag =0 and tvd.bind_status =1;
</select>
<select id="getOfflineDeviceWithAuth" resultType="java.lang.Integer">
select ifnull(count(distinct tvd.id),0)
from t_vehicle tv
left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
left join t_device td on td.sn = tvd.sn
left join t_device_location tdl on tdl.sn = td.sn
WHERE tvd.del_flag = 0 and tv.del_flag = 0 and tvd.bind_status = 1
and ((timestampdiff(SECOND, tdl.last_gps_time, now()) > #{search.offlineTime} and timestampdiff(SECOND, tdl.last_bs_time, now()) > #{search.offlineTime})
or (tdl.last_gps_time is null and tdl.last_bs_time is null)
or (tdl.last_gps_time is null and timestampdiff(SECOND, tdl.last_bs_time, now()) > #{search.offlineTime})
or (timestampdiff(SECOND, tdl.last_gps_time, now()) > #{search.offlineTime} and tdl.last_bs_time is null)
)
<if test="search.offlineSnStr != null and search.offlineSnStr != ''">
and tvd.sn not in (${search.offlineSnStr})
</if>
and tv.created_by in
<foreach collection="createdIds" separator="," open="(" close=")" item="item">
#{item}
</foreach>
</select>
<select id="listSocStatItems" resultType="cn.com.glsx.stdinterface.modules.model.sxj.SocStatItem">
select tdp.sn, tdp.alarm_time as socTime, tdp.soc
from t_vehicle tv
inner join t_vehicle_device tvd on tvd.vehicle_id = tv.id
inner join t_device td on td.sn = tvd.sn
inner join t_device_power tdp on td.sn = tdp.sn
where tvd.del_flag = 0 and tv.del_flag = 0 and tvd.bind_status = 1
and td.del_flag = 0 and tdp.del_flag = 0
and tv.created_by in
<foreach collection="createdIds" separator="," open="(" close=")" item="item">
#{item}
</foreach>
and td.source = 0
</select>
<select id="listSXJSnListPage" resultType="cn.com.glsx.stdinterface.dto.VehicleDto">
select tvd.sn, tv.vin,tvd.wire_type as wireType,tdp.soc, tvd.created_date as createDate
from t_vehicle tv
left join t_vehicle_device tvd on tv.id =tvd.vehicle_id
left join t_device_power tdp on tvd.sn = tdp.sn and tdp.del_flag = 0 and tdp.vd_id = tvd.id
where tvd.del_flag = 0
and tv.created_by in (
select id from t_user tu where tu.tenant_id =#{tenantId} and tu.del_flag =0
) and tv.del_flag =0 and tvd.bind_status =1
</select>
<select id="listOfflineAlarmInfo" resultType="cn.com.glsx.stdinterface.dto.sxj.OfflineAlarmInfo">
select
tdl.id as Id,
tvd.sn as Imei,
tdl.last_gps_time as lastGpsTime,
tdl.last_bs_time as lastBsTime,
tv.vin as VinNumber,
case tvd.wire_type when 1 then '2'
when 0 then '1' else tvd.wire_type end as DeviceType
from t_vehicle tv
left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
inner join t_device td on td.sn = tvd.sn
inner join t_device_location tdl on tdl.sn = td.sn
where tv.del_flag = 0 and td.del_flag = 0
and tvd.bind_status = 1
and tvd.del_flag = 0
and tv.created_by in
<foreach collection="createdIds" separator="," open="(" close=")" item="item">
#{item}
</foreach>
<if test="offlineStartTime != null and offlineStartTime != ''">
and ((tdl.last_gps_time < #{offlineStartTime} and tdl.last_bs_time < #{offlineStartTime})
or (tdl.last_gps_time is null and tdl.last_bs_time is null)
or (tdl.last_gps_time is null and tdl.last_bs_time < #{offlineStartTime})
or (tdl.last_gps_time < #{offlineStartTime} and tdl.last_bs_time is null)
)
</if>
order by tvd.id desc
</select>
</mapper>