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
019353c0
Commit
019353c0
authored
Jun 19, 2023
by
caotao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.车辆系统重启后线程丢失后无法结束里程。
parent
47f280da
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
140 additions
and
2 deletions
+140
-2
CarIotNewListener.java
...a/com/yeejoin/equipmanage/listener/CarIotNewListener.java
+2
-2
ThreadCar.java
...c/main/java/com/yeejoin/equipmanage/thread/ThreadCar.java
+1
-0
ThreadCarMileageTreatment.java
...yeejoin/equipmanage/thread/ThreadCarMileageTreatment.java
+127
-0
AmostEquipApplication.java
...quip/src/main/java/com/yeejoin/AmostEquipApplication.java
+10
-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 @
019353c0
...
@@ -71,7 +71,7 @@ public class CarIotNewListener extends EmqxListener {
...
@@ -71,7 +71,7 @@ public class CarIotNewListener extends EmqxListener {
this
.
updateCarLocation
(
jsonObject
,
iotCode
);
this
.
updateCarLocation
(
jsonObject
,
iotCode
);
//如果map中已经存在该设备或者该设备有但是线程已经执行了
//如果map中已经存在该设备或者该设备有但是线程已经执行了
if
((!
deviceInfo
.
containsKey
(
iotCode
))
||
(
deviceInfo
.
containsKey
(
iotCode
)
&&
deviceInfo
.
get
(
iotCode
)
==
null
))
{
if
((!
deviceInfo
.
containsKey
(
iotCode
))
||
(
deviceInfo
.
containsKey
(
iotCode
)
&&
deviceInfo
.
get
(
iotCode
)
==
null
))
{
ThreadCar
threadCar
=
new
ThreadCar
(
iotCode
,
jsonObject
,
this
.
iWlCarMileageService
,
this
.
iotFeign
,
this
.
iCarService
,
this
.
emqkeeper
,
clipping_time
);
ThreadCar
threadCar
=
new
ThreadCar
(
topic
,
jsonObject
,
this
.
iWlCarMileageService
,
this
.
iotFeign
,
this
.
iCarService
,
this
.
emqkeeper
,
clipping_time
);
deviceInfo
.
put
(
iotCode
,
threadCar
);
deviceInfo
.
put
(
iotCode
,
threadCar
);
threadCar
.
start
();
threadCar
.
start
();
}
}
...
@@ -87,7 +87,7 @@ public class CarIotNewListener extends EmqxListener {
...
@@ -87,7 +87,7 @@ public class CarIotNewListener extends EmqxListener {
deviceInfo
.
get
(
iotCode
).
interrupt
();
deviceInfo
.
get
(
iotCode
).
interrupt
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
}
}
ThreadCar
threadCar
=
new
ThreadCar
(
iotCode
,
jsonObject
,
this
.
iWlCarMileageService
,
this
.
iotFeign
,
this
.
iCarService
,
this
.
emqkeeper
,
clipping_time
);
ThreadCar
threadCar
=
new
ThreadCar
(
topic
,
jsonObject
,
this
.
iWlCarMileageService
,
this
.
iotFeign
,
this
.
iCarService
,
this
.
emqkeeper
,
clipping_time
);
deviceInfo
.
put
(
iotCode
,
threadCar
);
deviceInfo
.
put
(
iotCode
,
threadCar
);
//更新车辆的最新坐标数据
//更新车辆的最新坐标数据
deviceLastInfo
.
put
(
iotCode
,
coordinate
);
deviceLastInfo
.
put
(
iotCode
,
coordinate
);
...
...
amos-boot-module/amos-boot-module-biz/amos-boot-module-equip-biz/src/main/java/com/yeejoin/equipmanage/thread/ThreadCar.java
View file @
019353c0
...
@@ -50,6 +50,7 @@ public class ThreadCar extends Thread {
...
@@ -50,6 +50,7 @@ public class ThreadCar extends Thread {
JSONObject
lastObj
=
null
;
JSONObject
lastObj
=
null
;
WlCarMileage
last
=
null
;
WlCarMileage
last
=
null
;
try
{
try
{
System
.
out
.
println
(
"-------------------------"
+
this
.
topic
+
"结束坐标开始计时------------------------------"
);
this
.
sleep
(
clippingTime
);
this
.
sleep
(
clippingTime
);
//业务处理
//业务处理
//如果十分钟没有坐标,则需要设置结束标记
//如果十分钟没有坐标,则需要设置结束标记
...
...
amos-boot-module/amos-boot-module-biz/amos-boot-module-equip-biz/src/main/java/com/yeejoin/equipmanage/thread/ThreadCarMileageTreatment.java
0 → 100644
View file @
019353c0
package
com
.
yeejoin
.
equipmanage
.
thread
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
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.service.impl.CarServiceImpl
;
import
com.yeejoin.equipmanage.service.impl.WlCarMileageServiceImpl
;
import
com.yeejoin.equipmanage.utils.CarUtils
;
import
liquibase.pro.packaged.E
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
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.HashMap
;
import
java.util.List
;
@Component
public
class
ThreadCarMileageTreatment
extends
Thread
{
@Autowired
private
WlCarMileageServiceImpl
wlCarMileageServiceImpl
;
@Autowired
CarServiceImpl
carServiceImpl
;
@Autowired
private
IotFeign
iotFeign
;
@Value
(
"${mileage.clippingtime}"
)
private
Long
clipping_time
;
@Override
public
void
run
()
{
HashMap
<
String
,
String
>
hashMap
=
new
HashMap
<>();
//toDo
WlCarMileage
last
=
null
;
JSONObject
lastObj
=
null
;
List
<
WlCarMileage
>
wlCarMileageList
=
wlCarMileageServiceImpl
.
list
(
new
QueryWrapper
<
WlCarMileage
>().
isNull
(
"end_time"
));
wlCarMileageList
.
forEach
(
wlCarMileage
->
{
Car
car
=
carServiceImpl
.
getOne
(
new
QueryWrapper
<
Car
>().
eq
(
"iot_code"
,
wlCarMileage
.
getIotCode
()));
String
coordinateSting
=
String
.
valueOf
(
car
.
getLongitude
())
+
String
.
valueOf
(
car
.
getLatitude
());
hashMap
.
put
(
car
.
getIotCode
(),
coordinateSting
);
});
try
{
Thread
.
sleep
(
clipping_time
);
for
(
int
i
=
0
;
i
<
wlCarMileageList
.
size
();
i
++)
{
WlCarMileage
wlCarMileage
=
wlCarMileageList
.
get
(
i
);
Car
car
=
carServiceImpl
.
getOne
(
new
QueryWrapper
<
Car
>().
eq
(
"iot_code"
,
wlCarMileage
.
getIotCode
()));
String
coordinateSting
=
String
.
valueOf
(
car
.
getLongitude
())
+
String
.
valueOf
(
car
.
getLatitude
());
if
(
coordinateSting
.
equals
(
hashMap
.
get
(
car
.
getIotCode
())))
{
String
iotCode
=
car
.
getIotCode
();
String
measurement
=
"0THMcLKR"
;
String
deviceName
=
iotCode
.
replace
(
measurement
,
""
);
last
=
wlCarMileageServiceImpl
.
getOne
(
new
LambdaQueryWrapper
<
WlCarMileage
>().
eq
(
WlCarMileage:
:
getIotCode
,
iotCode
)
.
isNull
(
WlCarMileage:
:
getEndLongitude
).
isNull
(
WlCarMileage:
:
getEndLatitude
)
.
orderByDesc
(
WlCarMileage:
:
getStartTime
).
last
(
"limit 1"
));
ResponseModel
<
List
<
Object
>>
result
=
iotFeign
.
getLiveData
(
measurement
,
deviceName
,
last
.
getStartTime
(),
new
Date
(
new
Date
().
getTime
()
+
2000
));
List
<
Object
>
list
=
result
.
getResult
();
if
(
list
!=
null
&&
list
.
size
()
>
0
)
{
// 过滤空坐标
List
<
Object
>
filterList
=
new
ArrayList
<
Object
>();
for
(
int
j
=
0
;
j
<
list
.
size
();
j
++)
{
JSONObject
Obj
=
JSONObject
.
parseObject
(
JSONObject
.
toJSONString
(
list
.
get
(
j
)));
if
(
Obj
.
get
(
"FireCar_Longitude"
)
!=
null
&&
Obj
.
get
(
"FireCar_Latitude"
)
!=
null
&&
Obj
.
getDoubleValue
(
"FireCar_Longitude"
)
!=
0
&&
Obj
.
getDoubleValue
(
"FireCar_Latitude"
)
!=
0
)
{
filterList
.
add
(
list
.
get
(
j
));
// 获取第一个不为空的坐标
if
(
lastObj
==
null
)
{
lastObj
=
Obj
;
}
}
}
// JSONObject lastObj =
// JSONObject.parseObject(JSONObject.toJSONString(list.get(list.size() - 1)));
if
(
lastObj
==
null
)
{
lastObj
=
new
JSONObject
();
lastObj
.
put
(
"FireCar_Longitude"
,
0.0
);
lastObj
.
put
(
"FireCar_Latitude"
,
0.0
);
lastObj
.
put
(
"time"
,
0
);
lastObj
.
put
(
"FireCar_Speed"
,
0
);
}
double
endLongitude
=
lastObj
.
getDoubleValue
(
"FireCar_Longitude"
);
double
endLatitude
=
lastObj
.
getDoubleValue
(
"FireCar_Latitude"
);
// 230215180624
// Date endTime =UTCToCST(lastObj.getString("time"));
Date
endTime
=
new
Date
();
long
takeTime
=
(
endTime
.
getTime
()
/
1000
*
1000
)
-
(
last
.
getStartTime
().
getTime
()
/
1000
*
1000
);
last
.
setEndLongitude
(
endLongitude
);
last
.
setEndLatitude
(
endLatitude
);
last
.
setEndTime
(
endTime
);
last
.
setEndName
(
CarUtils
.
getAddress
(
endLongitude
,
endLatitude
));
last
.
setEndSpeed
(
lastObj
.
getIntValue
(
"FireCar_Speed"
));
last
.
setTakeTime
(
takeTime
);
double
travel
=
0.0
;
// 获取里程
for
(
int
k
=
0
;
k
<
filterList
.
size
()
-
1
;
k
++)
{
JSONObject
start
=
JSONObject
.
parseObject
(
JSONObject
.
toJSONString
(
filterList
.
get
(
k
)));
JSONObject
end
=
JSONObject
.
parseObject
(
JSONObject
.
toJSONString
(
filterList
.
get
(
k
+
1
)));
travel
+=
CoordinateUtil
.
distance
(
start
.
getDoubleValue
(
"FireCar_Latitude"
),
start
.
getDoubleValue
(
"FireCar_Longitude"
),
end
.
getDoubleValue
(
"FireCar_Latitude"
),
end
.
getDoubleValue
(
"FireCar_Longitude"
));
}
last
.
setTravel
(
new
BigDecimal
(
travel
/
1000
).
setScale
(
1
,
BigDecimal
.
ROUND_HALF_UP
).
doubleValue
());
wlCarMileageServiceImpl
.
updateById
(
last
);
}
}
}
}
catch
(
Exception
exception
)
{
exception
.
printStackTrace
();
}
}
}
amos-boot-system-equip/src/main/java/com/yeejoin/AmostEquipApplication.java
View file @
019353c0
...
@@ -3,6 +3,7 @@ package com.yeejoin;
...
@@ -3,6 +3,7 @@ package com.yeejoin;
import
com.yeejoin.amos.boot.biz.common.utils.oConvertUtils
;
import
com.yeejoin.amos.boot.biz.common.utils.oConvertUtils
;
import
com.yeejoin.equipmanage.listener.CarIotListener
;
import
com.yeejoin.equipmanage.listener.CarIotListener
;
import
com.yeejoin.equipmanage.listener.CarIotNewListener
;
import
com.yeejoin.equipmanage.listener.CarIotNewListener
;
import
com.yeejoin.equipmanage.thread.ThreadCarMileageTreatment
;
import
org.eclipse.paho.client.mqttv3.MqttException
;
import
org.eclipse.paho.client.mqttv3.MqttException
;
import
org.mybatis.spring.annotation.MapperScan
;
import
org.mybatis.spring.annotation.MapperScan
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
...
@@ -54,6 +55,10 @@ public class AmostEquipApplication {
...
@@ -54,6 +55,10 @@ public class AmostEquipApplication {
@Autowired
@Autowired
private
CarIotNewListener
carIotNewListener
;
private
CarIotNewListener
carIotNewListener
;
@Autowired
private
ThreadCarMileageTreatment
threadCarMileageTreatment
;
public
static
void
main
(
String
[]
args
)
throws
UnknownHostException
{
public
static
void
main
(
String
[]
args
)
throws
UnknownHostException
{
ConfigurableApplicationContext
context
=
SpringApplication
.
run
(
AmostEquipApplication
.
class
,
args
);
ConfigurableApplicationContext
context
=
SpringApplication
.
run
(
AmostEquipApplication
.
class
,
args
);
...
@@ -82,4 +87,9 @@ public class AmostEquipApplication {
...
@@ -82,4 +87,9 @@ public class AmostEquipApplication {
void
initMqtt
()
throws
MqttException
{
void
initMqtt
()
throws
MqttException
{
emqKeeper
.
getMqttClient
().
subscribe
(
"+/+/property"
,
1
,
carIotNewListener
);
emqKeeper
.
getMqttClient
().
subscribe
(
"+/+/property"
,
1
,
carIotNewListener
);
}
}
//江西电建服务重启后对于未计时且未结束的里程的进行处理
@Bean
void
initCarMelige
()
{
threadCarMileageTreatment
.
start
();
}
}
}
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