Commit b2c3868f by 黄小葱

优化

1 parent e6f69583
...@@ -38,7 +38,9 @@ public enum ResultEnum { ...@@ -38,7 +38,9 @@ public enum ResultEnum {
* 车辆监控历史轨迹 * 车辆监控历史轨迹
*/ */
TRACKHISTORY_HAS_EXCEED_LIMIT(12110004, "获取gps历史轨迹的数据条数已经超过最大限制"), TRACKHISTORY_HAS_EXCEED_LIMIT(12110004, "获取gps历史轨迹的数据条数已经超过最大限制"),
TRACKHISTORY_HAS_NO_DATA(12110005, "没有查询到历史轨迹数据"); TRACKHISTORY_HAS_NO_DATA(12110005, "没有查询到历史轨迹数据"),
DEVICE_NOT_EXIST(12110006, "%s 设备不存在!");
private final Integer code; private final Integer code;
private final String message; private final String message;
......
...@@ -2,6 +2,7 @@ package cn.com.glsx.admin.modules.model.imports; ...@@ -2,6 +2,7 @@ package cn.com.glsx.admin.modules.model.imports;
import cn.com.glsx.admin.common.enums.ResultEnum; import cn.com.glsx.admin.common.enums.ResultEnum;
import cn.com.glsx.admin.common.exception.AdminException; import cn.com.glsx.admin.common.exception.AdminException;
import cn.com.glsx.admin.modules.entity.VehicleDevice;
import cn.com.glsx.admin.modules.model.BaseImportInfo; import cn.com.glsx.admin.modules.model.BaseImportInfo;
import cn.com.glsx.admin.modules.service.DeviceService; import cn.com.glsx.admin.modules.service.DeviceService;
import cn.com.glsx.admin.modules.service.VehicleService; import cn.com.glsx.admin.modules.service.VehicleService;
...@@ -164,8 +165,8 @@ public class TrialDriveVehicleImportListener extends AnalysisEventListener<Trial ...@@ -164,8 +165,8 @@ public class TrialDriveVehicleImportListener extends AnalysisEventListener<Trial
reason.append("设备号不存在"); reason.append("设备号不存在");
return reason.toString(); return reason.toString();
} }
boolean snBind = deviceService.checkSnBind(sn); VehicleDevice vehicleDevice = deviceService.checkSnBind(sn);
if (snBind) { if (vehicleDevice != null) {
reason.append("该设备号已绑定车辆"); reason.append("该设备号已绑定车辆");
} }
return reason.toString(); return reason.toString();
......
...@@ -41,17 +41,15 @@ public class DeviceService { ...@@ -41,17 +41,15 @@ public class DeviceService {
} }
/** /**
* 检查设备号是否绑定 false 没有绑定 * 检查设备号是否绑定
* @param sn * @param sn
*/ */
public boolean checkSnBind(String sn) { public VehicleDevice checkSnBind(String sn) {
VehicleDevice vehicleDeviceParam = new VehicleDevice(); VehicleDevice param = new VehicleDevice();
vehicleDeviceParam.setSn(sn); param.setSn(sn);
VehicleDevice vehicleDevice = vdMapper.getVehicleDeviceBySnStatus(vehicleDeviceParam); param.setBindStatus(ConstantsDevice.BIND_VEHICLE_STATUS);
if (vehicleDevice != null && vehicleDevice.getBindStatus() == ConstantsDevice.BIND_VEHICLE_STATUS) { VehicleDevice vehicleDevice = vdMapper.getVehicleDeviceBySnStatus(param);
return true; return vehicleDevice;
}
return false;
} }
} }
...@@ -36,12 +36,14 @@ import com.google.gson.reflect.TypeToken; ...@@ -36,12 +36,14 @@ import com.google.gson.reflect.TypeToken;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
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.*; import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
...@@ -54,8 +56,6 @@ import java.util.stream.Collectors; ...@@ -54,8 +56,6 @@ import java.util.stream.Collectors;
@Service @Service
public class VehicleMonitorSevice { public class VehicleMonitorSevice {
protected Log logger = LogFactory.getLog(getClass());
@Autowired @Autowired
private GpsBsService gpsBsService; private GpsBsService gpsBsService;
...@@ -194,11 +194,11 @@ public class VehicleMonitorSevice { ...@@ -194,11 +194,11 @@ public class VehicleMonitorSevice {
DeviceLocationBo retLocation = new DeviceLocationBo(); DeviceLocationBo retLocation = new DeviceLocationBo();
R gpsBsDataR = gpsBsService.getLastGpsBsBySn(sn, DeviceTypeRelationEnum.GPS.getDeviceCode()); R gpsBsDataR = gpsBsService.getLastGpsBsBySn(sn, DeviceTypeRelationEnum.GPS.getDeviceCode());
if (!gpsBsDataR.isSuccess()) { if (!gpsBsDataR.isSuccess()) {
logger.info("获取最后gps和基站数据失败"); log.info("获取最后gps和基站数据失败");
return retLocation; return retLocation;
} }
if (gpsBsDataR.getData() == null) { if (gpsBsDataR.getData() == null) {
logger.info("获取最后gps和基站数据为空。"); log.info("获取最后gps和基站数据为空。");
return retLocation; return retLocation;
} }
GpsBsData gpsBsData = (GpsBsData) gpsBsDataR.getData(); GpsBsData gpsBsData = (GpsBsData) gpsBsDataR.getData();
...@@ -216,7 +216,7 @@ public class VehicleMonitorSevice { ...@@ -216,7 +216,7 @@ public class VehicleMonitorSevice {
buildBaseInfo(retLocation, sn); buildBaseInfo(retLocation, sn);
//构建报警数据 //构建报警数据
buildAlarmData(retLocation, sn); buildAlarmData(retLocation, sn);
logger.info("monitor track sn:" + sn + "status:" + retLocation.getStatus()); log.info("monitor track sn:" + sn + "status:" + retLocation.getStatus());
return retLocation; return retLocation;
} }
...@@ -247,12 +247,12 @@ public class VehicleMonitorSevice { ...@@ -247,12 +247,12 @@ public class VehicleMonitorSevice {
//查询拆除报警(断电和光感) //查询拆除报警(断电和光感)
R<AlarmDto> searchR = alarmFeignClient.search(alarmBo); R<AlarmDto> searchR = alarmFeignClient.search(alarmBo);
if (searchR == null || !searchR.isSuccess()) { if (searchR == null || !searchR.isSuccess()) {
logger.info("查找到拆除报警失败,sn:" + sn); log.info("查找到拆除报警失败,sn:" + sn);
return; return;
} }
List<AlarmDto> alarmDataList = JSON.parseArray(JSONArray.toJSONString(searchR.getData()), AlarmDto.class); List<AlarmDto> alarmDataList = JSON.parseArray(JSONArray.toJSONString(searchR.getData()), AlarmDto.class);
if (CollectionUtils.isEmpty(alarmDataList)) { if (CollectionUtils.isEmpty(alarmDataList)) {
logger.info("未查找到拆除报警,sn:" + sn); log.info("未查找到拆除报警,sn:" + sn);
return; return;
} }
Set<Integer> alarmSet = new HashSet<>(); Set<Integer> alarmSet = new HashSet<>();
...@@ -318,7 +318,7 @@ public class VehicleMonitorSevice { ...@@ -318,7 +318,7 @@ public class VehicleMonitorSevice {
try { try {
speed = Integer.parseInt(speedStr); speed = Integer.parseInt(speedStr);
} catch (NumberFormatException num) { } catch (NumberFormatException num) {
logger.info("解析设备的速度异常,sn:" + location.getSn() + ";speed:" + speedStr); log.info("解析设备的速度异常,sn:" + location.getSn() + ";speed:" + speedStr);
} }
parseStatus(location, speed, trackTime); parseStatus(location, speed, trackTime);
} }
......
...@@ -30,8 +30,6 @@ import com.glsx.plat.core.web.R; ...@@ -30,8 +30,6 @@ import com.glsx.plat.core.web.R;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
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;
...@@ -51,7 +49,6 @@ import java.util.List; ...@@ -51,7 +49,6 @@ import java.util.List;
@Service @Service
public class VehicleService { public class VehicleService {
protected Log logger = LogFactory.getLog(getClass());
@Autowired @Autowired
private VehicleMapper vehicleMapper; private VehicleMapper vehicleMapper;
...@@ -92,14 +89,17 @@ public class VehicleService { ...@@ -92,14 +89,17 @@ public class VehicleService {
if (StringUtils.isBlank(sn)) { if (StringUtils.isBlank(sn)) {
return; return;
} }
//查询该设备是否存在
boolean snExist = deviceService.checkSnExist(sn);
if (!snExist) {
throw new AdminException(ResultEnum.DEVICE_NOT_EXIST.getCode(),
String.format(ResultEnum.DEVICE_NOT_EXIST.getMessage(), sn));
}
//查询车辆是否绑定过 绑定过 抛出异常 //查询车辆是否绑定过 绑定过 抛出异常
VehicleDevice param = new VehicleDevice(); VehicleDevice vdBind = deviceService.checkSnBind(sn);
param.setBindStatus(ConstantsDevice.BIND_VEHICLE_STATUS); if (vdBind != null) {
param.setSn(sn);
VehicleDevice bindVehicleDevice = vehicleDeviceMapper.getVehicleDeviceBySnStatus(param);
if (bindVehicleDevice != null) {
throw new AdminException(ResultEnum.TRIAL_DRIVE_DEVICE_EXISTS.getCode(), throw new AdminException(ResultEnum.TRIAL_DRIVE_DEVICE_EXISTS.getCode(),
String.format(ResultEnum.TRIAL_DRIVE_DEVICE_EXISTS.getMessage(), bindVehicleDevice.getVehicleId())); String.format(ResultEnum.TRIAL_DRIVE_DEVICE_EXISTS.getMessage(), vdBind.getVehicleId()));
} }
VehicleDevice vehicleDevice = new VehicleDevice(); VehicleDevice vehicleDevice = new VehicleDevice();
vehicleDevice.setBindStatus(ConstantsDevice.BIND_VEHICLE_STATUS); vehicleDevice.setBindStatus(ConstantsDevice.BIND_VEHICLE_STATUS);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!