Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
amos-boot-biz
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
项目统一框架
amos-boot-biz
Commits
e0922755
Commit
e0922755
authored
Jun 03, 2023
by
caotao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
车辆轨迹按照10分钟划分逻辑优化提交
parent
359d290c
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
73 additions
and
11 deletions
+73
-11
CarIotNewListener.java
...a/com/yeejoin/equipmanage/listener/CarIotNewListener.java
+0
-0
IWlCarMileageService.java
...com/yeejoin/equipmanage/service/IWlCarMileageService.java
+2
-1
WlCarMileageServiceImpl.java
...oin/equipmanage/service/impl/WlCarMileageServiceImpl.java
+7
-0
ThreadCar.java
...c/main/java/com/yeejoin/equipmanage/thread/ThreadCar.java
+59
-10
CarUtils.java
...src/main/java/com/yeejoin/equipmanage/utils/CarUtils.java
+5
-0
No files found.
amos-boot-module/amos-boot-module-biz/amos-boot-module-equip-biz/src/main/java/com/yeejoin/equipmanage/listener/CarIotNewListener.java
View file @
e0922755
This diff is collapsed.
Click to expand it.
amos-boot-module/amos-boot-module-biz/amos-boot-module-equip-biz/src/main/java/com/yeejoin/equipmanage/service/IWlCarMileageService.java
View file @
e0922755
...
...
@@ -30,6 +30,7 @@ public interface IWlCarMileageService extends IService<WlCarMileage> {
* 里程切分(0点若里程未结束,自动切分设置结束信息,并开始新里程)
*/
void
mileageSegmentation
();
//根据iot编码查询是否有未结束里程
Boolean
getUncompleteMileagByIotCode
(
String
iotCode
);
}
amos-boot-module/amos-boot-module-biz/amos-boot-module-equip-biz/src/main/java/com/yeejoin/equipmanage/service/impl/WlCarMileageServiceImpl.java
View file @
e0922755
...
...
@@ -3,6 +3,7 @@ package com.yeejoin.equipmanage.service.impl;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
...
...
@@ -384,6 +385,12 @@ public class WlCarMileageServiceImpl extends ServiceImpl<WlCarMileageMapper, WlC
log
.
info
(
"轨迹切分任务执行完成.............."
);
}
@Override
public
Boolean
getUncompleteMileagByIotCode
(
String
iotCode
)
{
Integer
integer
=
this
.
count
(
new
QueryWrapper
<
WlCarMileage
>().
select
(
"1"
).
lambda
().
eq
(
WlCarMileage:
:
getIotCode
,
iotCode
).
isNull
(
WlCarMileage:
:
getEndTime
));
return
integer
<=
0
;
}
private
String
getAddress
(
double
longitude
,
double
lantitude
)
{
StringBuilder
api
=
new
StringBuilder
(
GUIDE_ADDRESS_URL
);
...
...
amos-boot-module/amos-boot-module-biz/amos-boot-module-equip-biz/src/main/java/com/yeejoin/equipmanage/thread/ThreadCar.java
View file @
e0922755
package
com
.
yeejoin
.
equipmanage
.
thread
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.yeejoin.equipmanage.common.entity.Car
;
import
com.yeejoin.equipmanage.common.entity.WlCarMileage
;
import
com.yeejoin.equipmanage.common.utils.CoordinateUtil
;
import
com.yeejoin.equipmanage.fegin.IotFeign
;
import
com.yeejoin.equipmanage.service.ICarService
;
import
com.yeejoin.equipmanage.service.IWlCarMileageService
;
import
com.yeejoin.equipmanage.utils.CarUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.eclipse.paho.client.mqttv3.MqttException
;
import
org.eclipse.paho.client.mqttv3.MqttMessage
;
import
org.typroject.tyboot.component.emq.EmqKeeper
;
import
org.typroject.tyboot.core.restful.utils.ResponseModel
;
import
java.math.BigDecimal
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Timer
;
import
java.util.concurrent.TimeUnit
;
public
class
ThreadCar
extends
Thread
{
@Autowired
private
IWlCarMileageService
iWlCarMileageService
;
@Autowired
private
IotFeign
iotFeign
;
private
String
topic
;
private
Long
clippingTime
;
ICarService
iCarService
;
private
EmqKeeper
emqkeeper
;
private
JSONObject
jsonObject
;
public
ThreadCar
(
String
topic
,
JSONObject
jsonObject
){
public
ThreadCar
(
String
topic
,
JSONObject
jsonObject
,
IWlCarMileageService
iWlCarMileageService
,
IotFeign
iotFeign
,
ICarService
iCarService
,
EmqKeeper
emqkeeper
,
Long
clippingTime
)
{
this
.
topic
=
topic
;
this
.
jsonObject
=
jsonObject
;
this
.
iWlCarMileageService
=
iWlCarMileageService
;
this
.
iotFeign
=
iotFeign
;
this
.
iCarService
=
iCarService
;
this
.
emqkeeper
=
emqkeeper
;
this
.
clippingTime
=
clippingTime
;
}
@Override
public
void
run
()
{
//toDo
// 获取最后一个有坐标的数据
JSONObject
lastObj
=
null
;
WlCarMileage
last
=
null
;
WlCarMileage
last
=
null
;
try
{
T
hread
.
sleep
(
600000
);
T
imeUnit
.
MILLISECONDS
.
sleep
(
Long
.
valueOf
((
long
)
(
clippingTime
))
);
//业务处理
//如果十分钟没有坐标,则需要设置结束标记
// 获取结束坐标
String
measurement
=
topic
.
split
(
"/"
)[
0
];
String
deviceName
=
topic
.
split
(
"/"
)[
1
];
String
iotCode
=
measurement
+
deviceName
;
last
=
iWlCarMileageService
last
=
iWlCarMileageService
.
getOne
(
new
LambdaQueryWrapper
<
WlCarMileage
>().
eq
(
WlCarMileage:
:
getIotCode
,
iotCode
)
.
isNull
(
WlCarMileage:
:
getEndLongitude
).
isNull
(
WlCarMileage:
:
getEndLatitude
)
.
orderByDesc
(
WlCarMileage:
:
getStartTime
).
last
(
"limit 1"
));
...
...
@@ -79,7 +94,7 @@ public class ThreadCar extends Thread {
// 230215180624
// Date endTime =UTCToCST(lastObj.getString("time"));
Date
endTime
=
new
Date
(
jsonObject
.
getLong
(
"time"
)
);
Date
endTime
=
new
Date
();
long
takeTime
=
(
endTime
.
getTime
()
/
1000
*
1000
)
-
(
last
.
getStartTime
().
getTime
()
/
1000
*
1000
);
last
.
setEndLongitude
(
endLongitude
);
last
.
setEndLatitude
(
endLatitude
);
...
...
@@ -98,10 +113,44 @@ public class ThreadCar extends Thread {
}
last
.
setTravel
(
new
BigDecimal
(
travel
/
1000
).
setScale
(
1
,
BigDecimal
.
ROUND_HALF_UP
).
doubleValue
());
iWlCarMileageService
.
updateById
(
last
);
this
.
pushCarInfoToMap
(
jsonObject
,
topic
);
this
.
interrupt
();
}
}
catch
(
Exception
exception
)
{
iWlCarMileageService
.
updateById
(
last
);
}
}
public
void
pushCarInfoToMap
(
JSONObject
jsonObject
,
String
iotCode
)
{
if
(
jsonObject
.
containsKey
(
"FireCar_Longitude"
)
&&
jsonObject
.
containsKey
(
"FireCar_Latitude"
))
{
// 获取开始坐标
double
startLongitude
=
jsonObject
.
getDoubleValue
(
"FireCar_Longitude"
);
double
startLatitude
=
jsonObject
.
getDoubleValue
(
"FireCar_Latitude"
);
int
direction
=
jsonObject
.
getIntValue
(
"direction"
);
// 地图推送消息
Car
car
=
iCarService
.
getOne
(
new
LambdaQueryWrapper
<
Car
>().
eq
(
Car:
:
getIotCode
,
iotCode
));
if
(
car
!=
null
&&
startLongitude
!=
0
&&
startLatitude
!=
0
)
{
JSONArray
sendArr
=
new
JSONArray
();
JSONObject
sendObj
=
new
JSONObject
();
sendObj
.
put
(
"id"
,
String
.
valueOf
(
car
.
getId
()));
sendObj
.
put
(
"direction"
,
direction
);
sendObj
.
put
(
"longitude"
,
String
.
valueOf
(
startLongitude
));
sendObj
.
put
(
"latitude"
,
String
.
valueOf
(
startLatitude
));
sendObj
.
put
(
"carNum"
,
car
.
getCarNum
());
sendObj
.
put
(
"bizOrgName"
,
car
.
getBizOrgName
());
sendArr
.
add
(
sendObj
);
MqttMessage
mqttMessage
=
new
MqttMessage
();
mqttMessage
.
setPayload
(
sendArr
.
toJSONString
().
getBytes
());
car
.
setLongitude
(
startLongitude
);
car
.
setLatitude
(
startLatitude
);
iCarService
.
updateById
(
car
);
try
{
emqkeeper
.
getMqttClient
().
publish
(
"car/location"
,
mqttMessage
);
}
catch
(
MqttException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
}
}
}
...
...
amos-boot-module/amos-boot-module-biz/amos-boot-module-equip-biz/src/main/java/com/yeejoin/equipmanage/utils/CarUtils.java
View file @
e0922755
package
com
.
yeejoin
.
equipmanage
.
utils
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.yeejoin.equipmanage.common.entity.Car
;
import
org.eclipse.paho.client.mqttv3.MqttException
;
import
org.eclipse.paho.client.mqttv3.MqttMessage
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment