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
dc746016
Commit
dc746016
authored
Jun 01, 2023
by
caotao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
车辆轨迹按照10分钟划分初版代码提交
parent
7adf00a6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
545 additions
and
129 deletions
+545
-129
View3dController.java
.../com/yeejoin/equipmanage/controller/View3dController.java
+124
-124
IotFeign.java
...src/main/java/com/yeejoin/equipmanage/fegin/IotFeign.java
+2
-2
CarIotNewListener.java
...a/com/yeejoin/equipmanage/listener/CarIotNewListener.java
+247
-0
ThreadCar.java
...c/main/java/com/yeejoin/equipmanage/thread/ThreadCar.java
+108
-0
CarUtils.java
...src/main/java/com/yeejoin/equipmanage/utils/CarUtils.java
+55
-0
AmostEquipApplication.java
...quip/src/main/java/com/yeejoin/AmostEquipApplication.java
+9
-3
No files found.
amos-boot-module/amos-boot-module-biz/amos-boot-module-equip-biz/src/main/java/com/yeejoin/equipmanage/controller/View3dController.java
View file @
dc746016
package
com
.
yeejoin
.
equipmanage
.
controller
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.yeejoin.equipmanage.common.response.Common3dResponse
;
import
com.yeejoin.equipmanage.common.response.Common3dResponseUtil
;
import
com.yeejoin.equipmanage.common.utils.CommonResponseUtil
;
import
com.yeejoin.equipmanage.common.vo.EquipFor3DVO
;
import
com.yeejoin.equipmanage.common.vo.EquipmentSpecific3dVo
;
import
com.yeejoin.equipmanage.common.vo.RetrieveParams
;
import
com.yeejoin.equipmanage.service.IAreaService
;
import
com.yeejoin.equipmanage.service.IEquipmentSpecificSerivce
;
import
com.yeejoin.equipmanage.service.IFireFightingSystemService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Lazy
;
import
org.springframework.web.bind.annotation.*
;
import
org.typroject.tyboot.core.foundation.enumeration.UserType
;
import
org.typroject.tyboot.core.restful.doc.TycloudOperation
;
import
org.typroject.tyboot.core.restful.utils.ResponseModel
;
import
java.util.HashMap
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* @ProjectName: EquipManageRoot
* @Package: com.yeejoin.equipmanage.controller
* @ClassName: View3dController
* @Author: Jianqiang Gao
* @Description: 三维controller
* @Date: 2021/5/28 9:39
* @Version: 1.0
*/
@RestController
@RequestMapping
(
"/api/view3d"
)
@Api
(
tags
=
"数字换流站"
)
public
class
View3dController
extends
AbstractBaseController
{
@Autowired
private
IFireFightingSystemService
fireFightingSystemService
;
@Lazy
@Autowired
private
IEquipmentSpecificSerivce
equipmentSpecificSerivce
;
@Autowired
private
IAreaService
areaService
;
@GetMapping
(
value
=
"/get3dFightingSystemList"
)
@TycloudOperation
(
ApiLevel
=
UserType
.
AGENCY
)
@ApiOperation
(
httpMethod
=
"GET"
,
value
=
"获取三维消防系统信息"
,
notes
=
"获取三维消防系统信息"
)
public
ResponseModel
get3dFightingSystemList
()
{
return
CommonResponseUtil
.
success
(
fireFightingSystemService
.
get3dFightingSystemList
());
}
// @Permission
@GetMapping
(
value
=
"/get3dFightingSysEquipCount"
)
@TycloudOperation
(
ApiLevel
=
UserType
.
AGENCY
)
@ApiOperation
(
httpMethod
=
"GET"
,
value
=
"获取三维消防系统装备及统计信息"
,
notes
=
"获取三维消防系统装备及统计信息"
)
public
ResponseModel
get3dFightingSysEquipCount
(
@RequestParam
(
name
=
"pageNum"
)
String
pageNum
,
@RequestParam
(
name
=
"pageSize"
)
String
pageSize
,
@RequestParam
(
name
=
"id"
)
Long
id
,
@RequestParam
(
name
=
"status"
,
required
=
false
)
Integer
status
,
@RequestParam
(
name
=
"name"
,
required
=
false
)
String
name
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
// List<EquipmentSpecific3dVo> equipList = equipmentSpecificSerivce.get3dFightingSysEquipList(id, status, name);
List
<
LinkedHashMap
>
countMap
=
equipmentSpecificSerivce
.
get3dFightingSysEquipCount
(
id
,
status
,
name
);
EquipFor3DVO
equipment
=
new
EquipFor3DVO
(
id
,
status
,
name
);
map
.
put
(
"equipList"
,
this
.
listPage
(
pageNum
,
pageSize
,
equipment
));
map
.
put
(
"countMap"
,
countMap
);
return
CommonResponseUtil
.
success
(
map
);
}
public
ResponseModel
listPage
(
String
pageNum
,
String
pageSize
,
EquipFor3DVO
equipment
)
{
Page
<
EquipmentSpecific3dVo
>
pageBean
;
IPage
<
EquipmentSpecific3dVo
>
page
;
if
(
StringUtils
.
isBlank
(
pageNum
)
||
StringUtils
.
isBlank
(
pageSize
))
{
pageBean
=
new
Page
<>(
0
,
Long
.
MAX_VALUE
);
}
else
{
pageBean
=
new
Page
<>(
Integer
.
parseInt
(
pageNum
),
Integer
.
parseInt
(
pageSize
));
}
page
=
equipmentSpecificSerivce
.
listPage
(
pageBean
,
equipment
);
return
CommonResponseUtil
.
success
(
page
);
}
/**
* 获取指定层级区域树,起步2级树
*/
@TycloudOperation
(
ApiLevel
=
UserType
.
AGENCY
)
@ApiOperation
(
"获取指定层级区域树"
)
@GetMapping
(
value
=
"/getAreaTierTree"
)
public
Common3dResponse
getAreaTierTree
(
@RequestParam
Integer
tier
)
{
return
Common3dResponseUtil
.
success
(
areaService
.
getAreaTierTree
(
tier
));
}
@GetMapping
(
value
=
"/retrieve/all"
)
@TycloudOperation
(
ApiLevel
=
UserType
.
AGENCY
)
@ApiOperation
(
httpMethod
=
"GET"
,
value
=
"风险区域、物理区域设备部件列表查询"
,
notes
=
"风险区域、物理区域设备部件列表查询"
)
public
ResponseModel
retrieveAll
(
@RequestBody
RetrieveParams
params
)
{
String
orgCode
=
this
.
getOrgCode
();
String
token
=
this
.
getToken
();
String
appKey
=
this
.
getAppKey
();
String
product
=
this
.
getProduct
();
// return view3dService.retrieveAll(params.getType(),
// params.getRiskSourceId(),
// params.getInputText(),
// params.getCurrent(),
// params.getPageSize(),
// orgCode,
// params.getDataLevel(),
// params.getProtectObjName(),
// token,appKey,product);
return
null
;
}
}
\ No newline at end of file
//package com.yeejoin.equipmanage.controller;
//
//import com.baomidou.mybatisplus.core.metadata.IPage;
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
//import com.yeejoin.equipmanage.common.response.Common3dResponse;
//import com.yeejoin.equipmanage.common.response.Common3dResponseUtil;
//import com.yeejoin.equipmanage.common.utils.CommonResponseUtil;
//import com.yeejoin.equipmanage.common.vo.EquipFor3DVO;
//import com.yeejoin.equipmanage.common.vo.EquipmentSpecific3dVo;
//import com.yeejoin.equipmanage.common.vo.RetrieveParams;
//import com.yeejoin.equipmanage.service.IAreaService;
//import com.yeejoin.equipmanage.service.IEquipmentSpecificSerivce;
//import com.yeejoin.equipmanage.service.IFireFightingSystemService;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Lazy;
//import org.springframework.web.bind.annotation.*;
//import org.typroject.tyboot.core.foundation.enumeration.UserType;
//import org.typroject.tyboot.core.restful.doc.TycloudOperation;
//import org.typroject.tyboot.core.restful.utils.ResponseModel;
//
//import java.util.HashMap;
//import java.util.LinkedHashMap;
//import java.util.List;
//import java.util.Map;
//
///**
// * @ProjectName: EquipManageRoot
// * @Package: com.yeejoin.equipmanage.controller
// * @ClassName: View3dController
// * @Author: Jianqiang Gao
// * @Description: 三维controller
// * @Date: 2021/5/28 9:39
// * @Version: 1.0
// */
//@RestController
//@RequestMapping("/api/view3d")
//@Api(tags = "数字换流站")
//public cView3dController extends AbstractBaseController {
//
// @Autowired
// private IFireFightingSystemService fireFightingSystemService;
// @Lazy
// @Autowired
// private IEquipmentSpecificSerivce equipmentSpecificSerivce;
//
// @Autowired
// private IAreaService areaService;
//
// @GetMapping(value = "/get3dFightingSystemList")
// @TycloudOperation(ApiLevel = UserType.AGENCY)
// @ApiOperation(httpMethod = "GET", value = "获取三维消防系统信息", notes = "获取三维消防系统信息")
// public ResponseModel get3dFightingSystemList() {
// return CommonResponseUtil.success(fireFightingSystemService.get3dFightingSystemList());
// }
//
//// @Permission
// @GetMapping(value = "/get3dFightingSysEquipCount")
// @TycloudOperation(ApiLevel = UserType.AGENCY)
// @ApiOperation(httpMethod = "GET", value = "获取三维消防系统装备及统计信息", notes = "获取三维消防系统装备及统计信息")
// public ResponseModel get3dFightingSysEquipCount(@RequestParam(name = "pageNum") String pageNum,
// @RequestParam(name = "pageSize") String pageSize,
// @RequestParam(name = "id") Long id,
// @RequestParam(name = "status", required = false) Integer status,
// @RequestParam(name = "name", required = false) String name) {
// Map<String, Object> map = new HashMap<>();
//// List<EquipmentSpecific3dVo> equipList = equipmentSpecificSerivce.get3dFightingSysEquipList(id, status, name);
// List<LinkedHashMap> countMap = equipmentSpecificSerivce.get3dFightingSysEquipCount(id, status, name);
// EquipFor3DVO equipment = new EquipFor3DVO(id, status, name);
// map.put("equipList", this.listPage(pageNum, pageSize, equipment));
// map.put("countMap", countMap);
// return CommonResponseUtil.success(map);
// }
//
//
// public ResponseModel listPage(String pageNum, String pageSize, EquipFor3DVO equipment) {
// Page<EquipmentSpecific3dVo> pageBean;
// IPage<EquipmentSpecific3dVo> page;
// if (StringUtils.isBlank(pageNum) || StringUtils.isBlank(pageSize)) {
// pageBean = new Page<>(0, Long.MAX_VALUE);
// } else {
// pageBean = new Page<>(Integer.parseInt(pageNum), Integer.parseInt(pageSize));
// }
// page = equipmentSpecificSerivce.listPage(pageBean, equipment);
// return CommonResponseUtil.success(page);
// }
//
// /**
// * 获取指定层级区域树,起步2级树
// */
// @TycloudOperation(ApiLevel = UserType.AGENCY)
// @ApiOperation("获取指定层级区域树")
// @GetMapping(value = "/getAreaTierTree")
// public Common3dResponse getAreaTierTree(@RequestParam Integer tier) {
// return Common3dResponseUtil.success(areaService.getAreaTierTree(tier));
// }
//
// @GetMapping(value = "/retrieve/all")
// @TycloudOperation(ApiLevel = UserType.AGENCY)
// @ApiOperation(httpMethod = "GET", value = "风险区域、物理区域设备部件列表查询", notes = "风险区域、物理区域设备部件列表查询")
// public ResponseModel retrieveAll(@RequestBody RetrieveParams params) {
//
// String orgCode = this.getOrgCode();
// String token = this.getToken();
// String appKey = this.getAppKey();
// String product = this.getProduct();
//
//// return view3dService.retrieveAll(params.getType(),
//// params.getRiskSourceId(),
//// params.getInputText(),
//// params.getCurrent(),
//// params.getPageSize(),
//// orgCode,
//// params.getDataLevel(),
//// params.getProtectObjName(),
//// token,appKey,product);
//
// return null;
// }
//
//}
\ No newline at end of file
amos-boot-module/amos-boot-module-biz/amos-boot-module-equip-biz/src/main/java/com/yeejoin/equipmanage/fegin/IotFeign.java
View file @
dc746016
...
...
@@ -14,8 +14,8 @@ import java.util.Map;
/**
* @author DELL
*/
@FeignClient
(
name
=
"${iot.vehicle.track}"
,
path
=
"iot"
,
configuration
=
{
FeignConfiguration
.
class
})
//
@FeignClient(name = "AMOS-API-IOT", path = "iot", configuration = { FeignConfiguration.class }, url = "http://39.98.224.23:33001")
//
@FeignClient(name = "${iot.vehicle.track}", path = "iot", configuration = {FeignConfiguration.class})
@FeignClient
(
name
=
"AMOS-API-IOT"
,
path
=
"iot"
,
configuration
=
{
FeignConfiguration
.
class
},
url
=
"http://39.98.224.23:33001"
)
public
interface
IotFeign
{
@RequestMapping
(
value
=
"/v1/livedata/list"
,
method
=
RequestMethod
.
GET
,
consumes
=
"application/json"
)
...
...
amos-boot-module/amos-boot-module-biz/amos-boot-module-equip-biz/src/main/java/com/yeejoin/equipmanage/listener/CarIotNewListener.java
0 → 100644
View file @
dc746016
package
com
.
yeejoin
.
equipmanage
.
listener
;
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.thread.ThreadCar
;
import
org.eclipse.paho.client.mqttv3.MqttMessage
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.typroject.tyboot.component.emq.EmqKeeper
;
import
org.typroject.tyboot.component.emq.EmqxListener
;
import
org.typroject.tyboot.core.restful.utils.ResponseModel
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.math.BigDecimal
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
@Component
public
class
CarIotNewListener
extends
EmqxListener
{
@Autowired
private
IWlCarMileageService
iWlCarMileageService
;
@Autowired
private
ICarService
iCarService
;
@Autowired
private
IotFeign
iotFeign
;
private
final
String
GUIDE_KEY
=
"813684495d9a3981dd2c7694916fe404"
;
private
final
String
GUIDE_URL
=
"https://restapi.amap.com/v3/geocode/regeo?"
;
@Autowired
private
EmqKeeper
emqkeeper
;
private
static
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
// 用于根据topicId 也就是物联设备id 存储对应的线程来进行计时
private
static
HashMap
<
String
,
ThreadCar
>
deviceInfo
=
new
HashMap
();
@Override
public
void
processMessage
(
String
topic
,
MqttMessage
message
)
throws
Exception
{
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
message
.
toString
());
//如果map中已经存在该设备或者该设备有但是线程已经执行了
if
((!
deviceInfo
.
containsKey
(
topic
))
||
(
deviceInfo
.
containsKey
(
topic
)
&&
deviceInfo
.
get
(
topic
)
==
null
))
{
ThreadCar
threadCar
=
new
ThreadCar
(
topic
,
jsonObject
);
deviceInfo
.
put
(
topic
,
threadCar
);
threadCar
.
start
();
}
else
{
Long
startTime
=
new
Date
().
getTime
();
Long
endTime
=
jsonObject
.
getLong
(
"time"
);
if
((
startTime
-
endTime
)
<=
600000
){
deviceInfo
.
get
(
topic
).
interrupt
();
ThreadCar
threadCar
=
new
ThreadCar
(
topic
,
jsonObject
);
deviceInfo
.
put
(
topic
,
threadCar
);
threadCar
.
start
();
}
}
if
(
jsonObject
.
containsKey
(
"startUp"
)
||
jsonObject
.
containsKey
(
"FireCar_Longitude"
))
{
System
.
out
.
println
(
topic
);
System
.
out
.
println
(
message
);
String
measurement
=
topic
.
split
(
"/"
)[
0
];
String
deviceName
=
topic
.
split
(
"/"
)[
1
];
String
iotCode
=
measurement
+
deviceName
;
if
(
jsonObject
.
containsKey
(
"startUp"
))
{
if
(
jsonObject
.
getBooleanValue
(
"startUp"
))
{
WlCarMileage
wlCarMileage
=
new
WlCarMileage
();
wlCarMileage
.
setIotCode
(
iotCode
);
wlCarMileage
.
setDate
(
new
Date
());
// 获取开始坐标
double
startLongitude
=
jsonObject
.
getDoubleValue
(
"FireCar_Longitude"
);
double
startLatitude
=
jsonObject
.
getDoubleValue
(
"FireCar_Latitude"
);
// String currentTime = "20"+jsonObject.getString("currentTime");
wlCarMileage
.
setStartLongitude
(
startLongitude
);
wlCarMileage
.
setStartLatitude
(
startLatitude
);
// Date startTime = UTCToCST();
Date
startTime
=
new
Date
(
jsonObject
.
getLong
(
"time"
));
wlCarMileage
.
setStartTime
(
startTime
);
wlCarMileage
.
setStartName
(
getAddress
(
startLongitude
,
startLatitude
));
wlCarMileage
.
setStartSpeed
(
jsonObject
.
getIntValue
(
"FireCar_Speed"
));
try
{
iWlCarMileageService
.
save
(
wlCarMileage
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
iWlCarMileageService
.
save
(
wlCarMileage
);
}
}
else
{
// 获取结束坐标
WlCarMileage
last
=
iWlCarMileageService
.
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
)
{
// 获取最后一个有坐标的数据
JSONObject
lastObj
=
null
;
// 过滤空坐标
List
<
Object
>
filterList
=
new
ArrayList
<
Object
>();
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
JSONObject
Obj
=
JSONObject
.
parseObject
(
JSONObject
.
toJSONString
(
list
.
get
(
i
)));
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
(
i
));
// 获取第一个不为空的坐标
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
(
jsonObject
.
getLong
(
"time"
));
long
takeTime
=
(
endTime
.
getTime
()
/
1000
*
1000
)
-
(
last
.
getStartTime
().
getTime
()
/
1000
*
1000
);
last
.
setEndLongitude
(
endLongitude
);
last
.
setEndLatitude
(
endLatitude
);
last
.
setEndTime
(
endTime
);
last
.
setEndName
(
getAddress
(
endLongitude
,
endLatitude
));
last
.
setEndSpeed
(
lastObj
.
getIntValue
(
"FireCar_Speed"
));
last
.
setTakeTime
(
takeTime
);
double
travel
=
0.0
;
// 获取里程
for
(
int
i
=
0
;
i
<
filterList
.
size
()
-
1
;
i
++)
{
JSONObject
start
=
JSONObject
.
parseObject
(
JSONObject
.
toJSONString
(
filterList
.
get
(
i
)));
JSONObject
end
=
JSONObject
.
parseObject
(
JSONObject
.
toJSONString
(
filterList
.
get
(
i
+
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
());
try
{
iWlCarMileageService
.
updateById
(
last
);
}
catch
(
Exception
e
)
{
iWlCarMileageService
.
updateById
(
last
);
}
}
}
}
else
if
(
jsonObject
.
containsKey
(
"FireCar_Longitude"
))
{
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
);
emqkeeper
.
getMqttClient
().
publish
(
"car/location"
,
mqttMessage
);
}
}
}
}
}
public
String
getAddress
(
double
longitude
,
double
lantitude
)
{
StringBuilder
api
=
new
StringBuilder
(
GUIDE_URL
);
api
.
append
(
"key="
).
append
(
GUIDE_KEY
).
append
(
"&location="
).
append
(
longitude
).
append
(
","
).
append
(
lantitude
)
.
append
(
"&radius=1000"
).
append
(
"&batch=false"
).
append
(
"&extensions=base"
).
append
(
"&roadlevel=0"
)
.
append
(
"&batch=false"
);
StringBuilder
res
=
new
StringBuilder
();
BufferedReader
in
=
null
;
try
{
System
.
out
.
println
(
api
.
toString
());
URL
url
=
new
URL
(
api
.
toString
());
HttpURLConnection
conn
=
(
HttpURLConnection
)
url
.
openConnection
();
conn
.
setDoOutput
(
true
);
conn
.
setRequestMethod
(
"POST"
);
in
=
new
BufferedReader
(
new
InputStreamReader
(
conn
.
getInputStream
(),
"UTF-8"
));
String
line
;
while
((
line
=
in
.
readLine
())
!=
null
)
{
res
.
append
(
line
).
append
(
"\n"
);
}
JSONObject
object
=
JSONObject
.
parseObject
(
res
.
toString
());
System
.
out
.
println
(
object
);
JSONObject
regeocode
=
object
.
getJSONObject
(
"regeocode"
);
String
address
=
regeocode
.
getString
(
"formatted_address"
);
if
(
"[]"
.
equals
(
address
))
{
System
.
out
.
println
(
"===============无效坐标:"
+
longitude
+
","
+
lantitude
);
address
=
"无效坐标"
;
}
res
=
new
StringBuilder
(
address
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
if
(
in
!=
null
)
{
in
.
close
();
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
return
res
.
toString
();
}
public
Date
UTCToCST
(
String
UTCStr
)
throws
ParseException
{
Date
date
=
sdf
.
parse
(
UTCStr
);
System
.
out
.
println
(
"UTC时间: "
+
date
);
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
date
);
calendar
.
set
(
Calendar
.
HOUR
,
calendar
.
get
(
Calendar
.
HOUR
)
+
8
);
return
calendar
.
getTime
();
}
}
amos-boot-module/amos-boot-module-biz/amos-boot-module-equip-biz/src/main/java/com/yeejoin/equipmanage/thread/ThreadCar.java
0 → 100644
View file @
dc746016
package
com
.
yeejoin
.
equipmanage
.
thread
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
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.IWlCarMileageService
;
import
com.yeejoin.equipmanage.utils.CarUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.typroject.tyboot.core.restful.utils.ResponseModel
;
import
java.math.BigDecimal
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
public
class
ThreadCar
extends
Thread
{
@Autowired
private
IWlCarMileageService
iWlCarMileageService
;
@Autowired
private
IotFeign
iotFeign
;
private
String
topic
;
private
JSONObject
jsonObject
;
public
ThreadCar
(
String
topic
,
JSONObject
jsonObject
){
this
.
topic
=
topic
;
this
.
jsonObject
=
jsonObject
;
}
@Override
public
void
run
()
{
//toDo
// 获取最后一个有坐标的数据
JSONObject
lastObj
=
null
;
WlCarMileage
last
=
null
;
try
{
Thread
.
sleep
(
600000
);
//业务处理
//如果十分钟没有坐标,则需要设置结束标记
// 获取结束坐标
String
measurement
=
topic
.
split
(
"/"
)[
0
];
String
deviceName
=
topic
.
split
(
"/"
)[
1
];
String
iotCode
=
measurement
+
deviceName
;
last
=
iWlCarMileageService
.
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
i
=
0
;
i
<
list
.
size
();
i
++)
{
JSONObject
Obj
=
JSONObject
.
parseObject
(
JSONObject
.
toJSONString
(
list
.
get
(
i
)));
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
(
i
));
// 获取第一个不为空的坐标
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
(
jsonObject
.
getLong
(
"time"
));
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
i
=
0
;
i
<
filterList
.
size
()
-
1
;
i
++)
{
JSONObject
start
=
JSONObject
.
parseObject
(
JSONObject
.
toJSONString
(
filterList
.
get
(
i
)));
JSONObject
end
=
JSONObject
.
parseObject
(
JSONObject
.
toJSONString
(
filterList
.
get
(
i
+
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
());
iWlCarMileageService
.
updateById
(
last
);
this
.
interrupt
();
}
}
catch
(
Exception
exception
)
{
iWlCarMileageService
.
updateById
(
last
);
}
}
}
amos-boot-module/amos-boot-module-biz/amos-boot-module-equip-biz/src/main/java/com/yeejoin/equipmanage/utils/CarUtils.java
0 → 100644
View file @
dc746016
package
com
.
yeejoin
.
equipmanage
.
utils
;
import
com.alibaba.fastjson.JSONObject
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
public
class
CarUtils
{
private
static
final
String
GUIDE_KEY
=
"813684495d9a3981dd2c7694916fe404"
;
private
static
final
String
GUIDE_URL
=
"https://restapi.amap.com/v3/geocode/regeo?"
;
public
static
String
getAddress
(
double
longitude
,
double
lantitude
)
{
StringBuilder
api
=
new
StringBuilder
(
GUIDE_URL
);
api
.
append
(
"key="
).
append
(
GUIDE_KEY
).
append
(
"&location="
).
append
(
longitude
).
append
(
","
).
append
(
lantitude
)
.
append
(
"&radius=1000"
).
append
(
"&batch=false"
).
append
(
"&extensions=base"
).
append
(
"&roadlevel=0"
)
.
append
(
"&batch=false"
);
StringBuilder
res
=
new
StringBuilder
();
BufferedReader
in
=
null
;
try
{
System
.
out
.
println
(
api
.
toString
());
URL
url
=
new
URL
(
api
.
toString
());
HttpURLConnection
conn
=
(
HttpURLConnection
)
url
.
openConnection
();
conn
.
setDoOutput
(
true
);
conn
.
setRequestMethod
(
"POST"
);
in
=
new
BufferedReader
(
new
InputStreamReader
(
conn
.
getInputStream
(),
"UTF-8"
));
String
line
;
while
((
line
=
in
.
readLine
())
!=
null
)
{
res
.
append
(
line
).
append
(
"\n"
);
}
JSONObject
object
=
JSONObject
.
parseObject
(
res
.
toString
());
System
.
out
.
println
(
object
);
JSONObject
regeocode
=
object
.
getJSONObject
(
"regeocode"
);
String
address
=
regeocode
.
getString
(
"formatted_address"
);
if
(
"[]"
.
equals
(
address
))
{
System
.
out
.
println
(
"===============无效坐标:"
+
longitude
+
","
+
lantitude
);
address
=
"无效坐标"
;
}
res
=
new
StringBuilder
(
address
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
if
(
in
!=
null
)
{
in
.
close
();
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
return
res
.
toString
();
}
}
amos-boot-system-equip/src/main/java/com/yeejoin/AmostEquipApplication.java
View file @
dc746016
...
...
@@ -2,6 +2,7 @@ package com.yeejoin;
import
com.yeejoin.amos.boot.biz.common.utils.oConvertUtils
;
import
com.yeejoin.equipmanage.listener.CarIotListener
;
import
com.yeejoin.equipmanage.listener.CarIotNewListener
;
import
org.eclipse.paho.client.mqttv3.MqttException
;
import
org.mybatis.spring.annotation.MapperScan
;
import
org.slf4j.Logger
;
...
...
@@ -19,6 +20,7 @@ import org.springframework.context.annotation.ComponentScan;
import
org.springframework.context.annotation.FilterType
;
import
org.springframework.core.env.Environment
;
import
org.springframework.scheduling.annotation.EnableAsync
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
import
org.springframework.transaction.annotation.EnableTransactionManagement
;
import
org.springframework.web.client.RestTemplate
;
import
org.typroject.tyboot.component.emq.EmqKeeper
;
...
...
@@ -46,10 +48,14 @@ public class AmostEquipApplication {
@Autowired
private
EmqKeeper
emqKeeper
;
// @Autowired
// private CarIotListener carIotListener;
@Autowired
private
CarIotListener
carIotListener
;
private
CarIotNewListener
carIotNewListener
;
public
static
void
main
(
String
[]
args
)
throws
UnknownHostException
{
public
static
void
main
(
String
[]
args
)
throws
UnknownHostException
{
ConfigurableApplicationContext
context
=
SpringApplication
.
run
(
AmostEquipApplication
.
class
,
args
);
Environment
env
=
context
.
getEnvironment
();
String
ip
=
InetAddress
.
getLocalHost
().
getHostAddress
();
...
...
@@ -74,6 +80,6 @@ public class AmostEquipApplication {
*/
@Bean
void
initMqtt
()
throws
MqttException
{
emqKeeper
.
getMqttClient
().
subscribe
(
"+/+/property"
,
1
,
carIotListener
);
emqKeeper
.
getMqttClient
().
subscribe
(
"+/+/property"
,
1
,
carIot
New
Listener
);
}
}
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