Commit 96299015 by levphon

设备监控-设备有效位置校验

1 parent 3e0454a1
...@@ -31,7 +31,7 @@ public class DeviceServiceImpl implements DeviceService { ...@@ -31,7 +31,7 @@ public class DeviceServiceImpl implements DeviceService {
private AlarmCenterApiImpl alarmCenterApi; private AlarmCenterApiImpl alarmCenterApi;
@Autowired @Autowired
private RemoteDeviceService remoteDeviceService; private EShieldService eShieldService;
@Autowired @Autowired
private DaoGpsServicePrx gpsPrxInstance; private DaoGpsServicePrx gpsPrxInstance;
...@@ -120,7 +120,7 @@ public class DeviceServiceImpl implements DeviceService { ...@@ -120,7 +120,7 @@ public class DeviceServiceImpl implements DeviceService {
} }
public Device getRemoteDevice(String sn) { public Device getRemoteDevice(String sn) {
TrackInfoDTO trackInfoDTO = remoteDeviceService.getDeviceBySn(sn); TrackInfoDTO trackInfoDTO = eShieldService.getDeviceBySn(sn);
return convertDevice(trackInfoDTO, 0L); return convertDevice(trackInfoDTO, 0L);
} }
......
...@@ -37,7 +37,7 @@ public class EShieldService { ...@@ -37,7 +37,7 @@ public class EShieldService {
log.info("getInfoBySn result {}", result); log.info("getInfoBySn result {}", result);
GetEShieldTrackInfoResp resp = JSONObject.parseObject(result, GetEShieldTrackInfoResp.class); GetEShieldTrackInfoResp resp = JSONObject.parseObject(result, GetEShieldTrackInfoResp.class);
if (!"0".equals(resp.getReturnCode())) { if (!"0".equals(resp.getReturnCode())) {
log.info("remote getInfoBysn fail! returnCode:" + resp.getReturnCode() + "; message:" + resp.getMessage()); log.info("remote getInfoBySn fail! returnCode:" + resp.getReturnCode() + "; message:" + resp.getMessage());
return null; return null;
} }
return resp.getData(); return resp.getData();
...@@ -61,7 +61,7 @@ public class EShieldService { ...@@ -61,7 +61,7 @@ public class EShieldService {
GetDeviceClassifyNameResp resp = JSONObject.parseObject(result, GetDeviceClassifyNameResp.class); GetDeviceClassifyNameResp resp = JSONObject.parseObject(result, GetDeviceClassifyNameResp.class);
if (!"0".equals(resp.getReturnCode())) { if (!"0".equals(resp.getReturnCode())) {
log.info("remote getInfoBysn fail! returnCode:" + resp.getReturnCode() + "; message:" + resp.getMessage()); log.info("remote getDeviceClassifyNameBySn fail! returnCode:" + resp.getReturnCode() + "; message:" + resp.getMessage());
return null; return null;
} }
return resp.getData(); return resp.getData();
......
...@@ -3,13 +3,13 @@ package cn.com.glsx.devicemonitor.modules.service.impl; ...@@ -3,13 +3,13 @@ package cn.com.glsx.devicemonitor.modules.service.impl;
import cn.com.glsx.devicemonitor.api.dto.request.DeviceLocationItem; import cn.com.glsx.devicemonitor.api.dto.request.DeviceLocationItem;
import cn.com.glsx.devicemonitor.api.dto.request.DeviceLocationRequest; import cn.com.glsx.devicemonitor.api.dto.request.DeviceLocationRequest;
import cn.com.glsx.devicemonitor.api.dto.request.GpsBsLastBatchRequest; import cn.com.glsx.devicemonitor.api.dto.request.GpsBsLastBatchRequest;
import cn.com.glsx.devicemonitor.api.dto.response.DeviceDTO;
import cn.com.glsx.devicemonitor.api.dto.response.GpsBsData; import cn.com.glsx.devicemonitor.api.dto.response.GpsBsData;
import cn.com.glsx.devicemonitor.api.dto.response.GpsLocation; import cn.com.glsx.devicemonitor.api.dto.response.GpsLocation;
import cn.com.glsx.devicemonitor.api.enums.DeviceTypeRelationEnum; import cn.com.glsx.devicemonitor.api.enums.DeviceTypeRelationEnum;
import cn.com.glsx.devicemonitor.api.enums.GeoLocationEnum; import cn.com.glsx.devicemonitor.api.enums.GeoLocationEnum;
import cn.com.glsx.devicemonitor.modules.components.HdaoGpsComponent; import cn.com.glsx.devicemonitor.modules.components.HdaoGpsComponent;
import cn.com.glsx.devicemonitor.modules.converter.DataLocationConvert; import cn.com.glsx.devicemonitor.modules.converter.DataLocationConvert;
import cn.com.glsx.devicemonitor.modules.entity.Device;
import cn.com.glsx.devicemonitor.modules.entity.DeviceLocation; import cn.com.glsx.devicemonitor.modules.entity.DeviceLocation;
import cn.com.glsx.devicemonitor.modules.entity.inner.DataGpsLocation; import cn.com.glsx.devicemonitor.modules.entity.inner.DataGpsLocation;
import cn.com.glsx.devicemonitor.modules.mapper.DeviceLocationMapper; import cn.com.glsx.devicemonitor.modules.mapper.DeviceLocationMapper;
...@@ -17,7 +17,7 @@ import cn.com.glsx.devicemonitor.modules.mapper.DeviceMapper; ...@@ -17,7 +17,7 @@ import cn.com.glsx.devicemonitor.modules.mapper.DeviceMapper;
import cn.com.glsx.devicemonitor.modules.model.BaseStationModel; import cn.com.glsx.devicemonitor.modules.model.BaseStationModel;
import cn.com.glsx.devicemonitor.modules.model.BsInfoModel; import cn.com.glsx.devicemonitor.modules.model.BsInfoModel;
import cn.com.glsx.devicemonitor.modules.model.MobileBaseModel; import cn.com.glsx.devicemonitor.modules.model.MobileBaseModel;
import cn.com.glsx.devicemonitor.modules.model.TrackInfoDTO; import cn.com.glsx.devicemonitor.modules.service.DeviceService;
import cn.com.glsx.devicemonitor.modules.service.GpsBsLocationService; import cn.com.glsx.devicemonitor.modules.service.GpsBsLocationService;
import com.glsx.plat.common.utils.DateUtils; import com.glsx.plat.common.utils.DateUtils;
import com.glsx.plat.common.utils.HttpUtils; import com.glsx.plat.common.utils.HttpUtils;
...@@ -57,9 +57,9 @@ public class GpsBsLocationServiceImpl implements GpsBsLocationService { ...@@ -57,9 +57,9 @@ public class GpsBsLocationServiceImpl implements GpsBsLocationService {
private HdaoGpsComponent hdaoGpsComponent; private HdaoGpsComponent hdaoGpsComponent;
@Autowired @Autowired
private EShieldService eShieldService; private DeviceService deviceService;
@Autowired @Resource
private DeviceMapper deviceMapper; private DeviceMapper deviceMapper;
@Override @Override
...@@ -137,15 +137,6 @@ public class GpsBsLocationServiceImpl implements GpsBsLocationService { ...@@ -137,15 +137,6 @@ public class GpsBsLocationServiceImpl implements GpsBsLocationService {
for (DeviceLocationItem item : locationRequest.getDevices()) { for (DeviceLocationItem item : locationRequest.getDevices()) {
String sn = item.getSn(); String sn = item.getSn();
TrackInfoDTO trackInfoDTO = eShieldService.getDeviceBySn(sn);
if (trackInfoDTO == null) {
throw BusinessException.create(String.format("设备%s不存在", sn));
}
if (trackInfoDTO.getIsActive() == 1) {
throw BusinessException.create(String.format("设备%s已激活", sn));
}
GpsBsData gpsBsData = gpsBsDataMap.get(sn); GpsBsData gpsBsData = gpsBsDataMap.get(sn);
if (gpsBsData == null) { if (gpsBsData == null) {
gpsBsData = new GpsBsData(); gpsBsData = new GpsBsData();
...@@ -203,11 +194,25 @@ public class GpsBsLocationServiceImpl implements GpsBsLocationService { ...@@ -203,11 +194,25 @@ public class GpsBsLocationServiceImpl implements GpsBsLocationService {
if (CollectionUtils.isEmpty(devices)) { if (CollectionUtils.isEmpty(devices)) {
throw BusinessException.create("传入的设备信息为空"); throw BusinessException.create("传入的设备信息为空");
} }
devices.forEach(dli -> { devices.forEach(dli -> {
Device device = deviceMapper.selectBySn(dli.getSn()); DeviceDTO deviceDTO = deviceService.getDeviceDTOBySn(dli.getSn(), true);
if (Objects.equals(device.getSource(), dli.getWireType())) { if (deviceDTO == null) {
throw BusinessException.create(String.format("设备 %s 未入库,请更换其他设备", dli.getSn()));
}
if (deviceDTO.getActivateStatus() == 1) {
throw BusinessException.create(String.format("设备%s已激活", dli.getSn()));
}
if (Objects.equals(deviceDTO.getSource(), dli.getWireType())) {
throw BusinessException.create("设备有线无线类型校验有误"); throw BusinessException.create("设备有线无线类型校验有误");
} }
if (StringUtils.isNotEmpty(dli.getCheckCode())) {//如果设备参数带了设备验证码就校验验证码正确性
if (!dli.getCheckCode().equals(deviceDTO.getCheckCode())) {
throw BusinessException.create(String.format("设备 %s 验证码不匹配,检测输入", dli.getSn()));
}
}
}); });
} }
......
package cn.com.glsx.devicemonitor.modules.service.impl;
import cn.com.glsx.devicemonitor.modules.model.TrackInfoDTO;
import cn.com.glsx.devicemonitor.modules.utils.GopUtil;
import com.alibaba.fastjson.JSONObject;
import com.glsx.plat.common.utils.HttpUtils;
import com.glsx.plat.context.utils.PropertiesUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import java.util.TreeMap;
@Slf4j
@Service
public class RemoteDeviceService {
/**
* 调用e盾标准接口获取设备信息
* @param sn
*/
public TrackInfoDTO getDeviceBySn(String sn) {
String url = PropertiesUtils.getProperty("edun.otsi.url") + "/api/device/getInfoBySn";
String appKet = PropertiesUtils.getProperty("edun.otsi.appKet");
String appSecret = PropertiesUtils.getProperty("edun.otsi.appSecret");
TreeMap<String, Object> tparams = new TreeMap<>();
tparams.put("appKey", appKet);
tparams.put("sn", sn);
//加密得到sign
String sign = GopUtil.sign(tparams, appSecret);
tparams.put("sign", sign);
try {
String result = HttpUtils.get(url, tparams);
JSONObject resultObj = JSONObject.parseObject(result);
if (resultObj == null) {
log.info("remote getInfoBysn result is null");
return null;
}
String returnCode = resultObj.getString("returnCode");
String message = resultObj.getString("message");
if (StringUtils.isBlank(returnCode) || !"0".equals(returnCode)) {
log.info("remote getInfoBysn fail! returnCode:" + returnCode + "; message:" + message);
return null;
}
String data = resultObj.getString("data");
if (StringUtils.isBlank(data)) {
return null;
}
TrackInfoDTO trackInfoDTO = JSONObject.parseObject(data, TrackInfoDTO.class);
return trackInfoDTO;
} catch (Exception e) {
log.info("调用虎哥E盾标准接口查询设备信息异常:{}", e.getMessage());
}
return null;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!