Commit 7ca7f524 by 黄小葱

车辆监控--定位信息

1 parent 38dfd9c6
......@@ -11,4 +11,15 @@ public final class Constants {
* 删除标识 -1:删除
*/
public static final Integer DELETE_FLAG = -1;
/**
* 设备离线时间:三天 单位 s/秒
*/
public static final long OFFLINE_TIME_OTHER = 3 * 24 * 3600L;
/**
* 有源在线时间点 6分钟 单位 毫秒/ms
*/
public static final long ONLINE_SOURCE_TIME = 6 * 60 * 1000L;
}
......@@ -30,4 +30,22 @@ public final class ConstantsDevice {
* 设备在线状态 (3 在线)
*/
public static final int DEVICE_STATUS_ONLINE = 3;
/**
* 定位类型:gps:1
*/
public static final int DEVICE_LOCATION_GPS = 1;
/**
* 定位类型:基站:2
*/
public static final int DEVICE_LOCATION_BS = 2;
/**
* 1有源
*/
public static final int SOURCE_HAS = 1;
/**
* 0无源
*/
public static final int SOURCE_NO = 0;
}
......@@ -50,9 +50,8 @@ public class VehicleMonitorController {
@ApiOperation(value = "查询车辆位置信息接口")
@SysLog("查询车辆位置信息")
@GetMapping("/vehiclelocation")
public R vehicleLocationInfo(String sn, int refreshCount) {
vehicleMonitorSevice.getVehicleLocation(sn, refreshCount);
public R vehicleLocationInfo(String sn) {
vehicleMonitorSevice.getVehicleLocation(sn);
return null;
}
......
......@@ -3,7 +3,15 @@ package cn.com.glsx.admin.modules.mapper;
import cn.com.glsx.admin.modules.entity.Device;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
@Mapper
public interface DeviceMapper extends CommonBaseMapper<Device> {
/**
* 根据设备号查找设备信息
* @param sn
* @return
*/
@Select("select * from t_device where del_flag = 0 and sn = #{sn}")
Device getDeviceBySn(String sn);
}
\ No newline at end of file
......@@ -42,4 +42,11 @@ public interface VehicleMapper extends CommonBaseMapper<Vehicle> {
* @return
*/
List<TrialDriveVehicleExport> exportDriveVehicle(VehicleManageSearch search);
/**
* 根据设备号查找车辆信息
* @param sn
* @return
*/
Vehicle findVehicleInfoBySn(@Param("sn") String sn);
}
\ No newline at end of file
......@@ -2,6 +2,8 @@ package cn.com.glsx.admin.modules.model.param;
import lombok.Data;
import java.util.Set;
/**
* @Desc:设备定位信息
* @Author huangxc
......@@ -11,11 +13,43 @@ import lombok.Data;
public class DeviceLocationBo {
/**
* 设备号
*/
private String sn;
/**
* 状态(0 行驶中 1 静止 2离线 3 在线)
*/
private Integer status;
/**
* 状态时长
*/
private String statusTime;
/**
* 车架号
*/
private String vin;
/**
* 车主姓名
*/
private String ownerName;
/**
* 1有源 0无源
*/
private Integer source;
/**
* 设备电量
*/
private String battery;
/**
* 报警类型 1:断电报警 99:光感报警
*/
private Set<Integer> alarmTypeSet;
/**
* 是否显示 wifi定位按钮 1:显示
*/
private int wifiType;
/**
* gps位置信息
......@@ -27,9 +61,4 @@ public class DeviceLocationBo {
*/
private DeviceLocation bsLocation;
/**
* 是否显示 wifi定位按钮 1:显示
*/
private int wifiType;
}
package cn.com.glsx.admin.modules.service;
import cn.com.glsx.admin.common.constants.Constants;
import cn.com.glsx.admin.common.constants.ConstantsDevice;
import cn.com.glsx.admin.modules.entity.Device;
import cn.com.glsx.admin.modules.entity.Vehicle;
import cn.com.glsx.admin.modules.entity.VehicleDevice;
import cn.com.glsx.admin.modules.mapper.DeviceMapper;
import cn.com.glsx.admin.modules.mapper.VehicleDeviceMapper;
import cn.com.glsx.admin.modules.mapper.VehicleMapper;
import cn.com.glsx.admin.modules.model.export.TrackModelExport;
import cn.com.glsx.admin.modules.model.param.DeviceLocation;
import cn.com.glsx.admin.modules.model.param.DeviceLocationBo;
import cn.com.glsx.admin.modules.model.param.MonitorQueryBo;
import cn.com.glsx.admin.modules.utils.DateUtil;
import cn.com.glsx.alarm.api.AlarmFeignClient;
import cn.com.glsx.alarm.services.model.AlarmBo;
import cn.com.glsx.alarm.services.model.AlarmDto;
import cn.com.glsx.devicemonitor.api.dto.response.GpsBsData;
import cn.com.glsx.devicemonitor.api.dto.response.GpsLocation;
import cn.com.glsx.devicemonitor.api.enums.DeviceTypeRelationEnum;
import cn.com.glsx.devicemonitor.api.feign.GpsBsService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.glsx.plat.context.utils.PropertiesUtils;
import com.glsx.plat.core.web.R;
import lombok.extern.slf4j.Slf4j;
......@@ -24,7 +32,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* 项目名:ne-shield-trialdrive-admin
......@@ -46,6 +57,11 @@ public class VehicleMonitorSevice {
@Autowired
private VehicleMapper vehicleMapper;
@Autowired
private DeviceMapper deviceMapper;
@Autowired
private AlarmFeignClient alarmFeignClient;
public R getTrackHistory(MonitorQueryBo monitorQueryVo) {
log.info("调用ICE接口查询历史轨迹数据");
......@@ -121,9 +137,8 @@ public class VehicleMonitorSevice {
/**
* 获取车辆的位置信息
* @param sn
* @param refreshCount
*/
public DeviceLocationBo getVehicleLocation(String sn, int refreshCount) {
public DeviceLocationBo getVehicleLocation(String sn) {
DeviceLocationBo retLocation = new DeviceLocationBo();
R gpsBsDataR = gpsBsService.getLastGpsBsBySn(sn, DeviceTypeRelationEnum.GPS.getDeviceCode());
if (!gpsBsDataR.isSuccess()) {
......@@ -137,18 +152,171 @@ public class VehicleMonitorSevice {
GpsBsData gpsBsData = (GpsBsData) gpsBsDataR.getData();
GpsLocation bsLocation = gpsBsData.getBsLocation();
GpsLocation gpsLocation = gpsBsData.getGpsLocation();
DeviceLocation gpsLoca = parseLocationInfo(gpsLocation, ConstantsDevice.DEVICE_LOCATION_GPS);
DeviceLocation bsLoca = parseLocationInfo(bsLocation, ConstantsDevice.DEVICE_LOCATION_BS);
retLocation.setSn(sn);
retLocation.setGpsLocation(gpsLoca);
retLocation.setBsLocation(bsLoca);
//解析状态
parseDeviceStatus(gpsLocation, bsLocation, retLocation);
//构建基础信息
buildBaseInfo(retLocation, sn);
//构建报警数据
buildAlarmData(retLocation, sn);
logger.info("monitor track sn:" + sn + "status:" + retLocation.getStatus());
return retLocation;
}
return null;
/**
* 查找最外层的基础信息
* @param retLocation
*/
private void buildBaseInfo(DeviceLocationBo retLocation, String sn) {
//车辆信息
Vehicle vehicle = vehicleMapper.findVehicleInfoBySn(sn);
if (vehicle != null) {
retLocation.setVin(vehicle.getVin());
retLocation.setOwnerName(vehicle.getOwnerName());
}
//设备信息
Device device = deviceMapper.getDeviceBySn(sn);
retLocation.setSource(device.getSource());
}
private int parseDeviceStatus(GpsLocation gpsLocation, GpsLocation bsLocation, String sn, long offlineTime) {
/**
* 构建断电报警信息
* @param location
* @param sn
*/
private void buildAlarmData(DeviceLocationBo location, String sn) {
AlarmBo alarmBo = new AlarmBo();
alarmBo.setSnList(sn);
//查询拆除报警(断电和光感)
R<AlarmDto> searchR = alarmFeignClient.search(alarmBo);
if (searchR == null || !searchR.isSuccess()) {
logger.info("查找到拆除报警失败,sn:" + sn);
return;
}
List<AlarmDto> alarmDataList = JSON.parseArray(JSONArray.toJSONString(searchR.getData()), AlarmDto.class);
if (CollectionUtils.isEmpty(alarmDataList)) {
logger.info("未查找到拆除报警,sn:" + sn);
return;
}
Set<Integer> alarmSet = new HashSet<>();
for (AlarmDto alarmDto : alarmDataList) {
alarmSet.add(alarmDto.getAlarmType());
}
location.setAlarmTypeSet(alarmSet);
}
/**
* 设置基站或gps的信息
* @param location
* @param locatType
* @return
*/
private DeviceLocation parseLocationInfo(GpsLocation location, int locatType) {
DeviceLocation deviceLocation = new DeviceLocation();
if (location == null) {
return deviceLocation;
}
deviceLocation.setLat(location.getLat());
deviceLocation.setLng(location.getLng());
deviceLocation.setLocatType(locatType);
deviceLocation.setTime(location.getDateTime());
return deviceLocation;
}
/**
* 解析设备的状态
* @param gpsLocation
* @param bsLocation
* @param location
*/
private void parseDeviceStatus(GpsLocation gpsLocation, GpsLocation bsLocation, DeviceLocationBo location) {
if (gpsLocation == null && bsLocation == null) {
return ConstantsDevice.DEVICE_STATUS_OFFLINE;
location.setStatus(ConstantsDevice.DEVICE_STATUS_OFFLINE);
return;
}
long gpsDateLong = 0;
long bsDateLong = 0;
String speedStr = "";
if (gpsLocation != null) {
speedStr = gpsLocation.getSpeed();
String gpsDateTime = gpsLocation.getDateTime();
Date gpsDate = DateUtil.parseDate(gpsDateTime);
gpsDateLong = gpsDate != null ? gpsDate.getTime() : 0;
}
if (bsLocation != null) {
String bsDateTime = bsLocation.getDateTime();
Date bsDate = DateUtil.parseDate(bsDateTime);
bsDateLong = bsDate != null ? bsDate.getTime() : 0;
}
if (gpsDateLong == 0 && bsDateLong == 0) {
location.setStatus(ConstantsDevice.DEVICE_STATUS_OFFLINE);
return;
}
long trackTime = Math.max(gpsDateLong, bsDateLong);
long now = System.currentTimeMillis();
if (trackTime > now) {
trackTime = now;
}
Integer speed = 0;
try {
speed = Integer.parseInt(speedStr);
} catch (NumberFormatException num) {
logger.info("解析设备的速度异常,sn:" + location.getSn() + ";speed:" + speedStr);
}
parseStatus(location, speed, trackTime);
}
/**
*
* @param location
* @param speed
* @param trackTime
*/
private void parseStatus(DeviceLocationBo location, Integer speed, long trackTime) {
long now = System.currentTimeMillis();
long offlineTime = Constants.OFFLINE_TIME_OTHER * 1000;
if (now - trackTime > offlineTime) {
location.setStatus(ConstantsDevice.DEVICE_STATUS_OFFLINE);
location.setStatusTime(DateUtil.formatTimeInSec((now - trackTime) / 1000));
return;
}
//无源设备 在线
if (location.getSource() == ConstantsDevice.SOURCE_NO) {
location.setStatus(ConstantsDevice.DEVICE_STATUS_ONLINE);
location.setStatusTime(DateUtil.formatTimeInSec((now - trackTime) / 1000));
return;
}
//有源设备 有速度 判断是否行驶
parseSourceStatus(location, speed, trackTime);
}
return ConstantsDevice.DEVICE_STATUS_OFFLINE;
/**
* 解析有源设备的状态
* @param location
* @param speed
* @param trackTime
*/
public void parseSourceStatus(DeviceLocationBo location, Integer speed, long trackTime) {
long now = System.currentTimeMillis();
if (now - trackTime > Constants.ONLINE_SOURCE_TIME) {
//大于6分钟 有源在线
location.setStatus(ConstantsDevice.DEVICE_STATUS_ONLINE);
location.setStatusTime(DateUtil.formatTimeInSec((now - trackTime) / 1000));
return;
}
if (speed != null && speed > 0) {
//行驶状态
location.setStatus(ConstantsDevice.DEVICE_STATUS_DRIVING);
return;
}
//无速度 静止
location.setStatus(ConstantsDevice.DEVICE_STATUS_STATIC);
location.setStatusTime(DateUtil.formatTimeInSec((now - trackTime) / 1000));
}
}
......@@ -3,6 +3,7 @@ package cn.com.glsx.admin.modules.utils;
import cn.com.glsx.admin.common.constants.ConstantsElectricFence;
import org.apache.commons.lang.StringUtils;
import org.apache.http.client.utils.DateUtils;
import org.eclipse.jetty.util.StringUtil;
import java.text.DateFormat;
import java.text.ParseException;
......@@ -180,6 +181,9 @@ public class DateUtil extends org.apache.commons.lang.time.DateUtils {
}
public static Date parseDate(String date, String pattern) {
if (StringUtil.isBlank(date)) {
return null;
}
SimpleDateFormat formatter = new SimpleDateFormat(pattern);
try {
return formatter.parse(date);
......
......@@ -65,11 +65,11 @@
<sql id="search_sql_condition" >
<if test="searchKey != null and searchKey != '' ">
and (
ttds.shop_code like '%'#{name}'%'
or ttds.shop_name like '%'#{name}'%'
or tv.vin like '%'#{name}'%'
or tvd.sn like '%'#{name}'%'
or tv.model_name like '%'#{name}'%'
ttds.shop_code like '%'#{searchKey}'%'
or ttds.shop_name like '%'#{searchKey}'%'
or tv.vin like '%'#{searchKey}'%'
or tvd.sn like '%'#{searchKey}'%'
or tv.model_name like '%'#{searchKey}'%'
)
</if>
</sql>
......@@ -143,4 +143,15 @@
</if>
</select>
<select id="findVehicleInfoBySn" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from t_vehicle tv
inner join t_vehicle_device tvd on tvd.vehicle_id = tv.id
where tv.del_flag = 0 and tvd.bind_status = 1 and tvd.del_flag = 0
<if test="sn != null and sn != ''">
tvd.sn = #{sn}
</if>
</select>
</mapper>
\ No newline at end of file
[
{
"locType": 0,
"onlineState": 1,
"record": {
"alt": 65,
"bLat": 0,
"bLng": 0,
"dir": 133,
"gLat": 22601696,
"gLng": 113994684,
"gpsTime": 1621840068,
"lat": 22604588,
"lng": 113989712,
"speed": 0,
"storeTime": 1621840070
},
"subDevType": 2,
"userID": 75105200001
},
{
"locType": 0,
"onlineState": 1,
"record": {
"alt": 0,
"bLat": 0,
"bLng": 0,
"dir": 72,
"gLat": 22602008,
"gLng": 113994873,
"gpsTime": 1621841500,
"lat": 22604900,
"lng": 113989900,
"speed": 0,
"storeTime": 1621841507
},
"subDevType": 2,
"userID": 1610425254
}
]
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!