Commit dab2f3b0 by 黄小葱

设备最后定位 增加wifi、设备离线工具类、设备监控参数

1 parent 56a1fd5c
...@@ -36,6 +36,11 @@ ...@@ -36,6 +36,11 @@
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>com.glsx</groupId>
<artifactId>ne-shield-alarmcenter-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- ice --> <!-- ice -->
<dependency> <dependency>
<groupId>Ice</groupId> <groupId>Ice</groupId>
......
...@@ -25,7 +25,7 @@ import static java.util.TimeZone.getTimeZone; ...@@ -25,7 +25,7 @@ import static java.util.TimeZone.getTimeZone;
@EnableFeignClients(basePackages = {"cn.com.glsx.*.api"}) @EnableFeignClients(basePackages = {"cn.com.glsx.*.api"})
@EnableTransactionManagement @EnableTransactionManagement
@EnableMBeanExport(registration = RegistrationPolicy.IGNORE_EXISTING) @EnableMBeanExport(registration = RegistrationPolicy.IGNORE_EXISTING)
@SpringBootApplication(scanBasePackages = {"cn.com.glsx.devicemonitor.*"}) @SpringBootApplication(scanBasePackages = {"cn.com.glsx.*"})
public class Application { public class Application {
public static void main(String[] args) { public static void main(String[] args) {
......
package cn.com.glsx.devicemonitor.common;
/**
* 设备相关的常量类
*/
public final class ConstantsDevice {
/**
* 设备绑定车辆状态:1绑定
*/
public static final int BIND_VEHICLE_STATUS = 1;
/**
* 设备绑定车辆状态:2解绑
*/
public static final int UN_BIND_VEHICLE_STATUS = 2;
/**
* 设备在线状态 (0 行驶中)
*/
public static final int DEVICE_STATUS_DRIVING = 0;
/**
* 设备在线状态 (1 静止)
*/
public static final int DEVICE_STATUS_STATIC = 1;
/**
* 设备在线状态 (2 离线)
*/
public static final int DEVICE_STATUS_OFFLINE = 2;
/**
* 设备在线状态 (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;
/** 其他公司设备离线时间:三天 单位 s/秒*/
public static final long OFFLINE_TIME_OTHER = 3 * 24 * 3600L;
}
...@@ -15,9 +15,12 @@ import cn.com.glsx.devicemonitor.iceprotocol.poisearch.geopoint; ...@@ -15,9 +15,12 @@ import cn.com.glsx.devicemonitor.iceprotocol.poisearch.geopoint;
import cn.com.glsx.devicemonitor.modules.convert.DataLocationConvert; import cn.com.glsx.devicemonitor.modules.convert.DataLocationConvert;
import cn.com.glsx.devicemonitor.modules.entity.inner.DataBsLocation; import cn.com.glsx.devicemonitor.modules.entity.inner.DataBsLocation;
import cn.com.glsx.devicemonitor.modules.entity.inner.DataGpsLocation; import cn.com.glsx.devicemonitor.modules.entity.inner.DataGpsLocation;
import cn.com.glsx.devicemonitor.modules.model.WifiMapInfoModel;
import cn.com.glsx.devicemonitor.modules.utils.DateFormatUtil; import cn.com.glsx.devicemonitor.modules.utils.DateFormatUtil;
import cn.com.glsx.devicemonitor.modules.utils.GpsCorrect; import cn.com.glsx.devicemonitor.modules.utils.GpsCorrect;
import cn.com.glsx.devicemonitor.modules.utils.LocationUtil; import cn.com.glsx.devicemonitor.modules.utils.LocationUtil;
import cn.com.glsx.devicemonitor.modules.utils.MapUtil;
import cn.hutool.core.date.DateUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.ConvertUtils; import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
...@@ -396,4 +399,72 @@ public class HdaoGpsComponent { ...@@ -396,4 +399,72 @@ public class HdaoGpsComponent {
} }
return dataGpsLocationList; return dataGpsLocationList;
} }
/**
* 获取设备的mac地址串
* @param sn
* @param apType
* @return
*/
public GpsWifiGetResponse getLatestGpsWifiRecords(String sn, int apType) {
GpsWifiRequest req = new GpsWifiRequest();
GpsWifiGetResponseHolder res = new GpsWifiGetResponseHolder();
try {
req.userID = Long.parseLong(sn);
req.apType = apType;
boolean wifiRecordsFlag = this.daoGpsServicePrx.getLatestGpsWifiRecords(req, res);
if (!wifiRecordsFlag) {
log.info("getLatestGpsWifiRecords fail!! sn:" + sn);
return null;
}
GpsWifiGetResponse response = res.value;
int oprResult = response.oprResult;
if (oprResult == 0) {
return response;
}
if (oprResult == 1) {
log.info("no recod!!");
return null;
}
} catch (Exception var8) {
log.info("getLatestGpsWifiRecords:Exception!!!!message:" + var8.getMessage());
var8.printStackTrace();
return null;
}
log.info("failed!!");
return null;
}
public DataGpsLocation getWifiLocation(String sn) {
GpsWifiGetResponse wifiResponse = getLatestGpsWifiRecords(sn, 1);
if (wifiResponse == null) {
return null;
}
wifiData[] wifiDataArr = wifiResponse.records;
StringBuffer macStr = new StringBuffer();
for (wifiData data : wifiDataArr) {
String mac = data.mac;
macStr.append(mac);
macStr.append("|");
}
log.info("sn:" + sn + "mac:" + macStr.toString());
//解析mac地址获取定位
WifiMapInfoModel wifiMapInfoModel = MapUtil.getWifiLoactionByMac(macStr.toString());
if (wifiMapInfoModel == null || wifiMapInfoModel.getLocation() == null || wifiMapInfoModel.getType().equals("0")) {
log.info("解析mac 获取地址失败。定位类型:" + wifiMapInfoModel.getType());
return null;
}
String[] lngLat = wifiMapInfoModel.getLocation().split(",");
Date date = new Date(wifiResponse.gpsTime * 1000L);
DataGpsLocation gpsLocation = new DataGpsLocation();
gpsLocation.setSn(sn);
gpsLocation.setLat(lngLat[0]);
gpsLocation.setLng(lngLat[1]);
gpsLocation.setStoreTime(DateUtil.formatDateTime(date));
return gpsLocation;
}
} }
package cn.com.glsx.devicemonitor.modules.controller; package cn.com.glsx.devicemonitor.modules.controller;
import cn.com.glsx.devicemonitor.api.enums.DeviceTypeRelationEnum;
import cn.com.glsx.devicemonitor.common.BussinessExceptionEnum;
import cn.com.glsx.devicemonitor.common.ConstantsDevice;
import cn.com.glsx.devicemonitor.modules.model.DeviceDTO; import cn.com.glsx.devicemonitor.modules.model.DeviceDTO;
import cn.com.glsx.devicemonitor.modules.model.DeviceLocationBo;
import cn.com.glsx.devicemonitor.modules.service.DeviceService; import cn.com.glsx.devicemonitor.modules.service.DeviceService;
import com.glsx.plat.core.web.R; import com.glsx.plat.core.web.R;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -33,5 +37,24 @@ public class DeviceController { ...@@ -33,5 +37,24 @@ public class DeviceController {
return R.ok().data(deviceDTO); return R.ok().data(deviceDTO);
} }
/**
* 设备监控信息
* @param sn
* @return
*/
@GetMapping(value = "/getDeviceMonitorInfo")
public R getDeviceMonitorInfo(@NotBlank(message = "设备号不能为空") @RequestParam(value = "sn") String sn, @NotBlank(message = "设备编码不能为空") @RequestParam(value = "deviceCode") String deviceCode, Long offlineTime) {
if (!DeviceTypeRelationEnum.findByDeviceCode(deviceCode).equals(DeviceTypeRelationEnum.GPS)) {
return R.error(BussinessExceptionEnum.UNSUPORT_DEVICE.getCode(), BussinessExceptionEnum.UNSUPORT_DEVICE.getMessage());
}
if (offlineTime == null || offlineTime == 0) {
offlineTime = ConstantsDevice.OFFLINE_TIME_OTHER;
}
DeviceLocationBo deviceLocationBo = deviceService.getDeviceMonitorInfo(sn, offlineTime, DeviceTypeRelationEnum.findByDeviceCode(deviceCode));
return R.ok().data(deviceLocationBo);
}
} }
...@@ -2,24 +2,79 @@ package cn.com.glsx.devicemonitor.modules.model; ...@@ -2,24 +2,79 @@ package cn.com.glsx.devicemonitor.modules.model;
import lombok.Data; import lombok.Data;
import javax.persistence.Column; import java.util.Date;
@Data @Data
public class DeviceDTO { public class DeviceDTO {
/**
* 设备序列号
*/
private String sn; private String sn;
/** /**
* 1有源 0无源 * 国际移动用户识别码
*/ */
private Integer source; private String imsi;
/**
* 集成电路卡识别码
*/
private String iccid;
/**
* 国际移动设备识别码
*/
private String imei;
/**
* 用户识别卡
*/
private String sim;
/** /**
* 校验码 * 校验码
*/ */
private String checkCode; private String checkCode;
/** /**
* 设备类型 * 设备类型
*/ */
private Integer deviceType; private Integer deviceType;
/**
* 设备厂商
*/
private String manufacturer;
/**
* 型号id
*/
private Integer modelId;
/**
* 型号名称
*/
private String modelName;
/**
* 固件版本
*/
private String softVersion;
/**
* 1有源 0无源
*/
private Integer source;
/**
* 激活状态:0未激活,1激活
*/
private Integer activateStatus;
/**
* 激活时间
*/
private Date activateTime;
} }
package cn.com.glsx.devicemonitor.modules.model;
import cn.com.glsx.devicemonitor.api.dto.response.GpsLocation;
import lombok.Data;
import java.util.Set;
/**
* @Desc:设备定位信息
* @Author huangxc
* @Date 2021/5/24
*/
@Data
public class DeviceLocationBo {
/**
* 设备号
*/
private String sn;
/**
* 状态(0 行驶中 1 静止 2离线 3 在线)
*/
private Integer status;
/**
* 状态时长
*/
private String statusTime;
/**
* 1有源 0无源
*/
private Integer source;
/**
* 设备电量
*/
private Integer battery;
/**
* 报警类型 1:断电报警 99:光感报警
*/
private Set<Integer> alarmTypeSet;
/**
* gps数据
*/
private GpsLocation gpsLocation;
/**
* 基站数据
*/
private GpsLocation bsLocation;
/**
* wifi数据
*/
private GpsLocation wifiLocation;
}
package cn.com.glsx.devicemonitor.modules.model;
import lombok.Data;
/**
* 设备状态model
*/
@Data
public class DeviceStatusModel {
/**
* 设备号
*/
private String sn;
/**
* 状态(0 行驶中 1 静止 2离线 3 在线)
*/
private Integer status;
/**
* 状态时长
*/
private String statusTime;
/**
* 有源:1 无源:0
*/
private Integer source;
}
package cn.com.glsx.devicemonitor.modules.model;
/**
* @Desc:根据mac地址解析出的地址信息
* @Author huangxc
* @Date 2021/4/29
*/
public class WifiMapInfoModel {
/**
* 国家
*/
private String country;
/**
* 省
*/
private String province;
/**
* 城市
*/
private String city;
/**
* 城市编码
*/
private String citycode;
/**
* 定位附件的poi名称
*/
private String poi;
/**
* 区域编码
*/
private String adcode;
/**
* 街道
*/
private String street;
/**
* 道路名
*/
private String road;
/**
* 位置描述
*/
private String desc;
/**
* 定位类型, 0:没有得到定位结果;其他数字为:正常获取定位结果
*/
private String type;
/**
* 定位经纬度
*/
private String location;
/**
* 定位精度半径 单位:米
*/
private String radius;
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getProvince() {
return province;
}
public void setProvince(String province) {
this.province = province;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getCitycode() {
return citycode;
}
public void setCitycode(String citycode) {
this.citycode = citycode;
}
public String getPoi() {
return poi;
}
public void setPoi(String poi) {
this.poi = poi;
}
public String getAdcode() {
return adcode;
}
public void setAdcode(String adcode) {
this.adcode = adcode;
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getRoad() {
return road;
}
public void setRoad(String road) {
this.road = road;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public String getRadius() {
return radius;
}
public void setRadius(String radius) {
this.radius = radius;
}
}
package cn.com.glsx.devicemonitor.modules.service; package cn.com.glsx.devicemonitor.modules.service;
import cn.com.glsx.devicemonitor.api.enums.DeviceTypeRelationEnum;
import cn.com.glsx.devicemonitor.modules.model.DeviceDTO; import cn.com.glsx.devicemonitor.modules.model.DeviceDTO;
import cn.com.glsx.devicemonitor.modules.model.DeviceLocationBo;
public interface DeviceService { public interface DeviceService {
/** /**
...@@ -9,4 +11,10 @@ public interface DeviceService { ...@@ -9,4 +11,10 @@ public interface DeviceService {
* @return * @return
*/ */
DeviceDTO getDeviceBySn(String sn); DeviceDTO getDeviceBySn(String sn);
/**
* 设备监控数据
* @param sn
*/
DeviceLocationBo getDeviceMonitorInfo(String sn, long offlineTime, DeviceTypeRelationEnum deviceType);
} }
package cn.com.glsx.devicemonitor.modules.service.impl;
import cn.com.glsx.alarm.api.AlarmFeignClient;
import cn.com.glsx.alarm.api.DeviceLoginFeignClient;
import cn.com.glsx.alarm.api.DevicePowerFeignClient;
import cn.com.glsx.alarm.services.model.*;
import com.alibaba.nacos.common.utils.CollectionUtils;
import com.glsx.plat.core.web.R;
import com.google.gson.reflect.TypeToken;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Slf4j
@Service
public class AlarmCenterApiImpl {
@Autowired
private DeviceLoginFeignClient deviceLoginClient;
@Autowired
private DevicePowerFeignClient powerFeignClient;
@Autowired
private AlarmFeignClient alarmFeignClient;
/**
* 获取设备的device_login信息
* @param sns
* @return
*/
public List<DeviceLoginDto> listDeviceLoginBySns(String sns) {
DeviceLoginBo deviceLogin = new DeviceLoginBo();
deviceLogin.setSnlist(sns);
R<DeviceLoginDto> deviceLoginR = deviceLoginClient.findDeviceLogin(deviceLogin);
if (deviceLoginR.getCode() != 200 || !deviceLoginR.getMessage().equalsIgnoreCase("success")) {
log.info(sns + "find fial.code:" + deviceLoginR.getCode() + ";message:" + deviceLoginR.getMessage());
return null;
}
List<DeviceLoginDto> userList = deviceLoginR.getDataList(new TypeToken<List<DeviceLoginDto>>() {
}.getType());
return userList;
}
/**
* 获取单个设备的device_login信息
* @param sn
* @return
*/
public DeviceLoginDto getDeviceLoginBySn(String sn) {
List<DeviceLoginDto> deviceLoginDtos = listDeviceLoginBySns(sn);
if (CollectionUtils.isEmpty(deviceLoginDtos)) {
return null;
}
return deviceLoginDtos.get(0);
}
/**
* 批量查询设备电量 sn之间用逗号分割
* @param sns
* @return
*/
public List<DevicePowerDto> listDevicePowerBySns(String sns) {
DevicePowerBo devicePowerBo = new DevicePowerBo();
devicePowerBo.setSnlist(sns);
R<DevicePowerDto> powerR = powerFeignClient.findPower(devicePowerBo);
if (powerR.getCode() != 200 || !powerR.getMessage().equalsIgnoreCase("success")) {
log.info(sns + "find fial.code:" + powerR.getCode() + ";message:" + powerR.getMessage());
return null;
}
List<DevicePowerDto> powerList = powerR.getDataList(new TypeToken<List<DevicePowerDto>>() {
}.getType());
return powerList;
}
/**
* 获取单个设备的电量
* @param sn
* @return
*/
public DevicePowerDto getDevicePowerBySn(String sn) {
List<DevicePowerDto> devicePower = listDevicePowerBySns(sn);
if (CollectionUtils.isEmpty(devicePower)) {
return null;
}
return devicePower.get(0);
}
/**
* 获取光感、断电报警信息
* @param sns
* @return
*/
public List<AlarmDto> listAlarmDtoBySns(String sns) {
AlarmBo alarmBo = new AlarmBo();
alarmBo.setSnList(sns);
R<AlarmDto> searchR = alarmFeignClient.search(alarmBo);
if (searchR.getCode() != 200 || !searchR.getMessage().equalsIgnoreCase("success")) {
log.info(sns + "find fial.code:" + searchR.getCode() + ";message:" + searchR.getMessage());
return null;
}
List<AlarmDto> alarmList = searchR.getDataList(new TypeToken<List<AlarmDto>>() {
}.getType());
return alarmList;
}
}
package cn.com.glsx.devicemonitor.modules.service.impl; package cn.com.glsx.devicemonitor.modules.service.impl;
import cn.com.glsx.admin.common.util.DateUtils;
import cn.com.glsx.alarm.services.model.AlarmDto;
import cn.com.glsx.alarm.services.model.DeviceLoginDto;
import cn.com.glsx.alarm.services.model.DevicePowerDto;
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.modules.entity.Device; import cn.com.glsx.devicemonitor.modules.entity.Device;
import cn.com.glsx.devicemonitor.modules.mapper.DeviceMapper; import cn.com.glsx.devicemonitor.modules.mapper.DeviceMapper;
import cn.com.glsx.devicemonitor.modules.model.DeviceDTO; import cn.com.glsx.devicemonitor.modules.model.DeviceDTO;
import cn.com.glsx.devicemonitor.modules.model.DeviceLocationBo;
import cn.com.glsx.devicemonitor.modules.model.DeviceStatusModel;
import cn.com.glsx.devicemonitor.modules.service.DeviceService; import cn.com.glsx.devicemonitor.modules.service.DeviceService;
import cn.com.glsx.devicemonitor.modules.service.GpsBsLocationService;
import cn.com.glsx.devicemonitor.modules.utils.DeviceUtil;
import com.alibaba.nacos.common.utils.CollectionUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@Slf4j @Slf4j
@Service @Service
public class DeviceServiceImpl implements DeviceService { public class DeviceServiceImpl implements DeviceService {
...@@ -16,6 +32,12 @@ public class DeviceServiceImpl implements DeviceService { ...@@ -16,6 +32,12 @@ public class DeviceServiceImpl implements DeviceService {
@Autowired @Autowired
private DeviceMapper deviceMapper; private DeviceMapper deviceMapper;
@Autowired
private GpsBsLocationService gpsBsLocationService;
@Autowired
private AlarmCenterApiImpl alarmCenterApi;
@Override @Override
public DeviceDTO getDeviceBySn(String sn) { public DeviceDTO getDeviceBySn(String sn) {
Device device = deviceMapper.selectBySn(sn); Device device = deviceMapper.selectBySn(sn);
...@@ -23,4 +45,66 @@ public class DeviceServiceImpl implements DeviceService { ...@@ -23,4 +45,66 @@ public class DeviceServiceImpl implements DeviceService {
BeanUtils.copyProperties(device, deviceDTO); BeanUtils.copyProperties(device, deviceDTO);
return deviceDTO; return deviceDTO;
} }
@Override
public DeviceLocationBo getDeviceMonitorInfo(String sn, long offlineTime, DeviceTypeRelationEnum deviceType) {
Device device = deviceMapper.selectBySn(sn);
if (device == null) {
log.info(sn + " 设备未入库");
return null;
}
DeviceLocationBo deviceLocationBo = new DeviceLocationBo();
//1.基站、gps数据
GpsBsData gpsBsData = gpsBsLocationService.getLastGpsBsBySn(sn, deviceType);
if (gpsBsData != null) {
BeanUtils.copyProperties(gpsBsData, deviceLocationBo);
}
deviceLocationBo.setSource(device.getSource());
deviceLocationBo.setSn(sn);
//2. 在线状态
getDeviceOnlineStatus(deviceLocationBo, offlineTime);
//3. 电量
DevicePowerDto devicePower = alarmCenterApi.getDevicePowerBySn(sn);
if (devicePower != null) {
deviceLocationBo.setBattery(devicePower.getSoc());
}
//4. 报警数据
List<AlarmDto> alarmDtos = alarmCenterApi.listAlarmDtoBySns(sn);
Set<Integer> alarmTypeSet = new HashSet<>();
if (CollectionUtils.isNotEmpty(alarmDtos)) {
for (AlarmDto alarmDto : alarmDtos) {
alarmTypeSet.add(alarmDto.getAlarmType());
}
deviceLocationBo.setAlarmTypeSet(alarmTypeSet);
}
return deviceLocationBo;
}
/**
* 设备离线状态
* @param deviceLocationBo
* @param offlineTime
* @return
*/
public void getDeviceOnlineStatus(DeviceLocationBo deviceLocationBo, long offlineTime) {
DeviceLoginDto deviceLogin = alarmCenterApi.getDeviceLoginBySn(deviceLocationBo.getSn());
if (deviceLogin == null) {
return;
}
DeviceStatusModel statusModel = DeviceUtil.parseDeviceStatus(deviceLogin, deviceLocationBo.getSource(), offlineTime);
if (statusModel != null) {
deviceLocationBo.setStatus(statusModel.getStatus());
deviceLocationBo.setStatusTime(statusModel.getStatusTime());
}
GpsLocation bsLocation = deviceLocationBo.getBsLocation();
if (bsLocation != null) {
bsLocation.setStoreTime(DateUtils.formatDateTime(deviceLogin.getLastgprstime()));
}
GpsLocation gpsLocation = deviceLocationBo.getGpsLocation();
if (gpsLocation != null) {
gpsLocation.setStoreTime(DateUtils.formatDateTime(deviceLogin.getLastrttrack()));
}
}
} }
...@@ -10,6 +10,7 @@ import cn.com.glsx.devicemonitor.modules.convert.DataLocationConvert; ...@@ -10,6 +10,7 @@ import cn.com.glsx.devicemonitor.modules.convert.DataLocationConvert;
import cn.com.glsx.devicemonitor.modules.entity.inner.DataGpsLocation; import cn.com.glsx.devicemonitor.modules.entity.inner.DataGpsLocation;
import cn.com.glsx.devicemonitor.modules.service.GpsBsLocationService; import cn.com.glsx.devicemonitor.modules.service.GpsBsLocationService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -44,24 +45,30 @@ public class GpsBsLocationServiceImpl implements GpsBsLocationService { ...@@ -44,24 +45,30 @@ public class GpsBsLocationServiceImpl implements GpsBsLocationService {
Map<String, GpsBsData> gpsBsDataMap = new HashMap<>(); Map<String, GpsBsData> gpsBsDataMap = new HashMap<>();
// 2、补充位置数据,并转换地址 // 2、补充位置数据,并转换地址
for (DataGpsLocation dataGpsLocation : dataGpsLocationList) { for (DataGpsLocation dataGpsLocation : dataGpsLocationList) {
GpsBsData gpsBsData = gpsBsDataMap.get(dataGpsLocation.getSn()); String sn = dataGpsLocation.getSn();
GpsBsData gpsBsData = gpsBsDataMap.get(sn);
if (gpsBsData==null) { if (gpsBsData==null) {
gpsBsData = new GpsBsData(); gpsBsData = new GpsBsData();
gpsBsData.setSn(dataGpsLocation.getSn()); gpsBsData.setSn(sn);
gpsBsDataMap.put(dataGpsLocation.getSn(), gpsBsData); gpsBsDataMap.put(sn, gpsBsData);
} }
if (dataGpsLocation.getGeoLocationEnum().equals(GeoLocationEnum.GPS)) { if (dataGpsLocation.getGeoLocationEnum().equals(GeoLocationEnum.GPS)) {
gpsBsData.setGpsLocation(DataLocationConvert.convertDataToGpsLocation(dataGpsLocation)); gpsBsData.setGpsLocation(DataLocationConvert.convertDataToGpsLocation(dataGpsLocation));
// 2.1 如果是GPS,则补充获取基站的数据 // 2.1 如果是GPS,则补充获取基站的数据
DataGpsLocation bsLocation = hdaoGpsComponent.getDeviceLastGPSInfoFullByBs(dataGpsLocation.getSn(), gpsBsLastBatchRequest.getDeviceTypeRelationEnum()); DataGpsLocation bsLocation = hdaoGpsComponent.getDeviceLastGPSInfoFullByBs(sn, gpsBsLastBatchRequest.getDeviceTypeRelationEnum());
gpsBsData.setBsLocation(DataLocationConvert.convertDataToGpsLocation(bsLocation)); gpsBsData.setBsLocation(DataLocationConvert.convertDataToGpsLocation(bsLocation));
} else if (dataGpsLocation.getGeoLocationEnum().equals(GeoLocationEnum.BS)) { } else if (dataGpsLocation.getGeoLocationEnum().equals(GeoLocationEnum.BS)) {
gpsBsData.setBsLocation(DataLocationConvert.convertDataToGpsLocation(dataGpsLocation)); gpsBsData.setBsLocation(DataLocationConvert.convertDataToGpsLocation(dataGpsLocation));
// 2.2 如果是基站,则补充获取GPS的数据 // 2.2 如果是基站,则补充获取GPS的数据
DataGpsLocation gpsLocation = hdaoGpsComponent.getDeviceLastGpsInfoFull(dataGpsLocation.getSn(), gpsBsLastBatchRequest.getDeviceTypeRelationEnum()); DataGpsLocation gpsLocation = hdaoGpsComponent.getDeviceLastGpsInfoFull(sn, gpsBsLastBatchRequest.getDeviceTypeRelationEnum());
gpsBsData.setGpsLocation(DataLocationConvert.convertDataToGpsLocation(gpsLocation)); gpsBsData.setGpsLocation(DataLocationConvert.convertDataToGpsLocation(gpsLocation));
} }
//补充获取wifi的定位
DataGpsLocation wifiLocation = getDeviceLastWifiInfoBySn(sn);
if (wifiLocation != null) {
gpsBsData.setWifiLocation(DataLocationConvert.convertDataToGpsLocation(wifiLocation));
}
} }
return new ArrayList<GpsBsData>(gpsBsDataMap.values()); return new ArrayList<GpsBsData>(gpsBsDataMap.values());
...@@ -69,18 +76,39 @@ public class GpsBsLocationServiceImpl implements GpsBsLocationService { ...@@ -69,18 +76,39 @@ public class GpsBsLocationServiceImpl implements GpsBsLocationService {
@Override @Override
public GpsBsData getLastGpsBsBySn(String sn, DeviceTypeRelationEnum deviceTypeRelationEnum) { public GpsBsData getLastGpsBsBySn(String sn, DeviceTypeRelationEnum deviceTypeRelationEnum) {
GpsBsData gpsBsData = null; GpsBsData gpsBsData = new GpsBsData();
gpsBsData.setSn(sn);
//有的设备有基站没有gps或wifi
DataGpsLocation gpsLocation = hdaoGpsComponent.getDeviceLastGpsInfoFull(sn, deviceTypeRelationEnum); DataGpsLocation gpsLocation = hdaoGpsComponent.getDeviceLastGpsInfoFull(sn, deviceTypeRelationEnum);
if (gpsLocation != null) {
gpsBsData.setGpsLocation(DataLocationConvert.convertDataToGpsLocation(gpsLocation));
}
DataGpsLocation bsLocation = hdaoGpsComponent.getDeviceLastGPSInfoFullByBs(sn, deviceTypeRelationEnum); DataGpsLocation bsLocation = hdaoGpsComponent.getDeviceLastGPSInfoFullByBs(sn, deviceTypeRelationEnum);
if (gpsLocation==null && bsLocation==null) { if (bsLocation != null) {
gpsBsData.setBsLocation(DataLocationConvert.convertDataToGpsLocation(bsLocation));
}
DataGpsLocation wifiLocation = getDeviceLastWifiInfoBySn(sn);
if (wifiLocation != null) {
gpsBsData.setWifiLocation(DataLocationConvert.convertDataToGpsLocation(wifiLocation));
}
if (gpsLocation == null && bsLocation == null && wifiLocation == null) {
return null;
}
return gpsBsData; return gpsBsData;
} }
gpsBsData = new GpsBsData(); /**
gpsBsData.setSn(sn); * WiFi定位数据
gpsBsData.setGpsLocation(DataLocationConvert.convertDataToGpsLocation(gpsLocation)); * @param sn
gpsBsData.setBsLocation(DataLocationConvert.convertDataToGpsLocation(bsLocation)); * @return
return gpsBsData; */
public DataGpsLocation getDeviceLastWifiInfoBySn(String sn) {
// TODO 75开头的设备是沃达孚的无线设备,需要显示wifi定位
if (StringUtils.isBlank(sn) || !sn.startsWith("75")) {
return null;
}
DataGpsLocation wifiLocation = hdaoGpsComponent.getWifiLocation(sn);
return wifiLocation;
} }
@Override @Override
......
package cn.com.glsx.devicemonitor.modules.utils;
import cn.com.glsx.admin.common.util.DateUtils;
import cn.com.glsx.alarm.services.model.DeviceLoginDto;
import cn.com.glsx.devicemonitor.common.ConstantsDevice;
import cn.com.glsx.devicemonitor.modules.model.DeviceLocationBo;
import cn.com.glsx.devicemonitor.modules.model.DeviceStatusModel;
import java.util.Date;
public class DeviceUtil {
/**
* 解析设备离线状态
* @param deviceLogin
* @param source 有源:1 无源:0
* @param offlineTime 单位秒
* @return
*/
public static DeviceStatusModel parseDeviceStatus(DeviceLoginDto deviceLogin, int source, long offlineTime) {
DeviceStatusModel deviceStatus = new DeviceStatusModel();
deviceStatus.setSource(source);
if (deviceLogin == null) {
return deviceStatus;
}
Date lastGprsDate = deviceLogin.getLastgprstime();
Date lastRttrackDate = deviceLogin.getLastrttrack();
if (lastGprsDate == null && lastRttrackDate == null) {
deviceStatus.setStatus(ConstantsDevice.DEVICE_STATUS_OFFLINE);
return deviceStatus;
}
long gpsDateLong = lastRttrackDate != null ? lastRttrackDate.getTime() : 0;
long gprsDateLong = lastGprsDate != null ? lastGprsDate.getTime() : 0;
Integer speed = deviceLogin.getSpeed();
if (gpsDateLong == 0 && gprsDateLong == 0) {
deviceStatus.setStatus(ConstantsDevice.DEVICE_STATUS_OFFLINE);
return deviceStatus;
}
long trackTime = Math.max(gpsDateLong, gprsDateLong);
long now = System.currentTimeMillis();
if (trackTime > now) {
trackTime = now;
}
parseStatus(deviceStatus, speed, trackTime, offlineTime);
return deviceStatus;
}
/**
* @param deviceStatus
* @param speed
* @param trackTime
*/
private static void parseStatus(DeviceStatusModel deviceStatus, Integer speed, long trackTime, long offlineTime) {
long now = System.currentTimeMillis();
if (now - trackTime > offlineTime) {
deviceStatus.setStatus(ConstantsDevice.DEVICE_STATUS_OFFLINE);
deviceStatus.setStatusTime(DateUtils.formatTimeInSec((now - trackTime) / 1000));
return;
}
//无源设备 在线
if (deviceStatus.getSource() == ConstantsDevice.SOURCE_NO) {
deviceStatus.setStatus(ConstantsDevice.DEVICE_STATUS_ONLINE);
deviceStatus.setStatusTime(DateUtils.formatTimeInSec((now - trackTime) / 1000));
return;
}
//有源设备 有速度 判断是否行驶
parseSourceStatus(deviceStatus, speed, trackTime, offlineTime);
}
/**
* 解析有源设备的状态
*
* @param deviceStatus
* @param speed
* @param trackTime
*/
public static void parseSourceStatus(DeviceStatusModel deviceStatus, Integer speed, long trackTime, long offlineTime) {
long now = System.currentTimeMillis();
if (now - trackTime > offlineTime) {
//大于6分钟 有源在线
deviceStatus.setStatus(ConstantsDevice.DEVICE_STATUS_ONLINE);
deviceStatus.setStatusTime(DateUtils.formatTimeInSec((now - trackTime) / 1000));
return;
}
if (speed != null && speed > 0) {
//行驶状态
deviceStatus.setStatus(ConstantsDevice.DEVICE_STATUS_DRIVING);
return;
}
//无速度 静止
deviceStatus.setStatus(ConstantsDevice.DEVICE_STATUS_STATIC);
deviceStatus.setStatusTime(DateUtils.formatTimeInSec((now - trackTime) / 1000));
}
}
package cn.com.glsx.devicemonitor.modules.utils;
import cn.com.glsx.devicemonitor.modules.model.WifiMapInfoModel;
import com.alibaba.fastjson.JSONObject;
import com.glsx.plat.common.utils.HttpUtils;
import io.micrometer.core.instrument.util.JsonUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import java.util.HashMap;
import java.util.Map;
@Slf4j
public class MapUtil {
/**
* 根据wifi的mac地址,使用高德地图解析位置信息
* @param macs
* @return
*/
public static WifiMapInfoModel getWifiLoactionByMac(String macs) {
String url = "http://apilocate.amap.com/position";
Map<String, Object> map = new HashMap<>();
map.put("key", "d0059dce9808bf2c1344c9ffe09c118a");
map.put("imei", "00000000000000000000");
map.put("accesstype", "1");
map.put("macs", macs);
String result = "";
try {
result = HttpUtils.get(url, map);
if (StringUtils.isEmpty(result)) {
log.info("getWifiLoactionByMac fail。 Result is empty!!");
return null;
}
com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(result);
String status = jsonObject.getString("status");
if (!"1".equals(status)) {
log.info("解析mac地址获取wifi位置信息失败。info:" + jsonObject.getString("info"));
return null;
}
String resultData = jsonObject.getString("result");
WifiMapInfoModel infoModel = JSONObject.parseObject(resultData, WifiMapInfoModel.class);
return infoModel;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
...@@ -12,7 +12,7 @@ public class TestDeviceController { ...@@ -12,7 +12,7 @@ public class TestDeviceController {
private static String serverUrl = localUrl; private static String serverUrl = localUrl;
public static void main(String[] args) { public static void main(String[] args) {
testGetDeviceBySn(); testGetDeviceMonitorInfo();
} }
public static void testGetDeviceBySn() { public static void testGetDeviceBySn() {
...@@ -23,4 +23,15 @@ public class TestDeviceController { ...@@ -23,4 +23,15 @@ public class TestDeviceController {
String res = HttpUtil.get(url, paramMap, 20000); String res = HttpUtil.get(url, paramMap, 20000);
System.out.println(res); System.out.println(res);
} }
public static void testGetDeviceMonitorInfo() {
String url = serverUrl + "/device/getDeviceMonitorInfo";
String sn = "8130912152";
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("sn", sn);
paramMap.put("deviceCode", "gps");
String res = HttpUtil.get(url, paramMap, 20000);
System.out.println(res);
}
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!