case when td.source = 1 then '有线' when td.source = 0 then '无线' else '--' end as deviceTypeStr,
case when tv.type_id is null then tv.model_name else
concat(tv.sub_brand_name,'/',tv.series_name,'/',tv.type_name) end modelName,
tv.vehicle_type vehicleType,
...
...
@@ -416,9 +417,9 @@
from t_vehicle tv
left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
left join t_workorder tw on tw.id = tv.workorder_id
left join t_device td on td.sn = tvd.sn and td.del_flag = 0
left join (select * from (SELECT * FROM t_device_freq order by created_date desc) temp GROUP BY temp.sn) ddf
on ddf.vehicle_id = tv.id and ddf.sn = td.sn
left join t_device td on td.sn = tvd.sn
left join t_device_location tdl on tdl.sn = tvd.sn
left join (select vehicle_id, sn, status from (SELECT * FROM t_device_freq order by created_date desc) temp GROUP BY temp.sn) ddf on ddf.vehicle_id = tv.id and ddf.sn = td.sn
where tv.del_flag = 0
and tvd.bind_status = 1
and tvd.del_flag = 0
...
...
@@ -446,6 +447,25 @@
<iftest="vehicleUsages != null">
and tv.vehicle_usages = #{vehicleUsages}
</if>
<iftest="checkedUserIdsStr != null and checkedUserIdsStr !=''">
and find_in_set(tv.created_by,#{checkedUserIdsStr})
</if>
<iftest="deviceState != null">
<choose>
<whentest="deviceState == 0"><!-- 行驶中-->
and (td.source=1) and speed>0 and ((timestampdiff(SECOND,tdl.last_gps_time,now())) <![CDATA[<]]> 600 or (timestampdiff(SECOND,tdl.last_bs_time,now())) <![CDATA[<]]> 600)
</when>
<whentest="deviceState == 1"><!-- 静止-->
and (td.source=1) and (speed=0 or speed is null) and ((timestampdiff(SECOND,tdl.last_gps_time,now())) <![CDATA[<]]> 600 or (timestampdiff(SECOND,tdl.last_bs_time,now())) <![CDATA[<]]> 600)
</when>
<whentest="deviceState == 2"><!-- 离线-->
and (timestampdiff(SECOND,tdl.last_gps_time,now())) > #{offlineTime} and (timestampdiff(SECOND,tdl.last_bs_time,now())) > #{offlineTime}
</when>
<whentest="deviceState == 3"><!-- 在线-->
and (timestampdiff(SECOND,tdl.last_gps_time,now()) < #{offlineTime} or timestampdiff(SECOND,tdl.last_bs_time,now()) < #{offlineTime})
</when>
</choose>
</if>
order by tvd.created_date desc,tv.id,vdId
</select>
...
...
@@ -459,8 +479,8 @@
tv.vin ,
tvd.sn ,
td.source deviceType,
case when tv.type_id is null then tv.model_name else
concat(tv.sub_brand_name,'/',tv.series_name,'/',tv.type_name) end as modelName,
case when td.source = 1 then '有线' when td.source = 0 then '无线' else '--' end as deviceTypeStr,
case when tv.type_id is null then tv.model_name else concat(tv.sub_brand_name,'/',tv.series_name,'/',tv.type_name) end as modelName,
tv.vehicle_type vehicleType,
tv.vehicle_usages vehicleUsages,
tvd.created_date activateTime,
...
...
@@ -470,8 +490,8 @@
left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
left join t_workorder tw on tw.id = tv.workorder_id
left join t_device td on td.sn = tvd.sn
left join (select * from (SELECT * FROM t_device_freq order by created_date desc) temp GROUP BY temp.sn) ddf
on ddf.vehicle_id = tv.id and ddf.sn = td.sn
left join t_device_location tdl on tdl.sn = tvd.sn
left join (select vehicle_id, sn, status from (SELECT * FROM t_device_freq order by created_date desc) temp GROUP BY temp.sn) ddf on ddf.vehicle_id = tv.id and ddf.sn = td.sn
where tv.del_flag = 0
and tvd.bind_status = 1
and tvd.del_flag = 0
...
...
@@ -499,6 +519,25 @@
<iftest="vehicleUsages != null">
and tv.vehicle_usages = #{vehicleUsages}
</if>
<iftest="checkedUserIdsStr != null and checkedUserIdsStr !=''">
and find_in_set(tv.created_by,#{checkedUserIdsStr})
</if>
<iftest="deviceState != null">
<choose>
<whentest="deviceState == 0"><!-- 行驶中-->
and (td.source=1) and speed>0 and ((timestampdiff(SECOND,tdl.last_gps_time,now())) <![CDATA[<]]> 600 or (timestampdiff(SECOND,tdl.last_bs_time,now())) <![CDATA[<]]> 600)
</when>
<whentest="deviceState == 1"><!-- 静止-->
and (td.source=1) and (speed=0 or speed is null) and ((timestampdiff(SECOND,tdl.last_gps_time,now())) <![CDATA[<]]> 600 or (timestampdiff(SECOND,tdl.last_bs_time,now())) <![CDATA[<]]> 600)
</when>
<whentest="deviceState == 2"><!-- 离线-->
and (timestampdiff(SECOND,tdl.last_gps_time,now())) > #{offlineTime} and (timestampdiff(SECOND,tdl.last_bs_time,now())) > #{offlineTime}
</when>
<whentest="deviceState == 3"><!-- 在线-->
and (timestampdiff(SECOND,tdl.last_gps_time,now()) < #{offlineTime} or timestampdiff(SECOND,tdl.last_bs_time,now()) < #{offlineTime})