Commit b2c3868f by 黄小葱

优化

1 parent e6f69583
......@@ -38,7 +38,9 @@ public enum ResultEnum {
* 车辆监控历史轨迹
*/
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 String message;
......
......@@ -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.exception.AdminException;
import cn.com.glsx.admin.modules.entity.VehicleDevice;
import cn.com.glsx.admin.modules.model.BaseImportInfo;
import cn.com.glsx.admin.modules.service.DeviceService;
import cn.com.glsx.admin.modules.service.VehicleService;
......@@ -164,8 +165,8 @@ public class TrialDriveVehicleImportListener extends AnalysisEventListener<Trial
reason.append("设备号不存在");
return reason.toString();
}
boolean snBind = deviceService.checkSnBind(sn);
if (snBind) {
VehicleDevice vehicleDevice = deviceService.checkSnBind(sn);
if (vehicleDevice != null) {
reason.append("该设备号已绑定车辆");
}
return reason.toString();
......
......@@ -41,17 +41,15 @@ public class DeviceService {
}
/**
* 检查设备号是否绑定 false 没有绑定
* 检查设备号是否绑定
* @param sn
*/
public boolean checkSnBind(String sn) {
VehicleDevice vehicleDeviceParam = new VehicleDevice();
vehicleDeviceParam.setSn(sn);
VehicleDevice vehicleDevice = vdMapper.getVehicleDeviceBySnStatus(vehicleDeviceParam);
if (vehicleDevice != null && vehicleDevice.getBindStatus() == ConstantsDevice.BIND_VEHICLE_STATUS) {
return true;
}
return false;
public VehicleDevice checkSnBind(String sn) {
VehicleDevice param = new VehicleDevice();
param.setSn(sn);
param.setBindStatus(ConstantsDevice.BIND_VEHICLE_STATUS);
VehicleDevice vehicleDevice = vdMapper.getVehicleDeviceBySnStatus(param);
return vehicleDevice;
}
}
......@@ -36,12 +36,14 @@ import com.google.gson.reflect.TypeToken;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
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.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;
/**
......@@ -54,8 +56,6 @@ import java.util.stream.Collectors;
@Service
public class VehicleMonitorSevice {
protected Log logger = LogFactory.getLog(getClass());
@Autowired
private GpsBsService gpsBsService;
......@@ -194,11 +194,11 @@ public class VehicleMonitorSevice {
DeviceLocationBo retLocation = new DeviceLocationBo();
R gpsBsDataR = gpsBsService.getLastGpsBsBySn(sn, DeviceTypeRelationEnum.GPS.getDeviceCode());
if (!gpsBsDataR.isSuccess()) {
logger.info("获取最后gps和基站数据失败");
log.info("获取最后gps和基站数据失败");
return retLocation;
}
if (gpsBsDataR.getData() == null) {
logger.info("获取最后gps和基站数据为空。");
log.info("获取最后gps和基站数据为空。");
return retLocation;
}
GpsBsData gpsBsData = (GpsBsData) gpsBsDataR.getData();
......@@ -216,7 +216,7 @@ public class VehicleMonitorSevice {
buildBaseInfo(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;
}
......@@ -247,12 +247,12 @@ public class VehicleMonitorSevice {
//查询拆除报警(断电和光感)
R<AlarmDto> searchR = alarmFeignClient.search(alarmBo);
if (searchR == null || !searchR.isSuccess()) {
logger.info("查找到拆除报警失败,sn:" + sn);
log.info("查找到拆除报警失败,sn:" + sn);
return;
}
List<AlarmDto> alarmDataList = JSON.parseArray(JSONArray.toJSONString(searchR.getData()), AlarmDto.class);
if (CollectionUtils.isEmpty(alarmDataList)) {
logger.info("未查找到拆除报警,sn:" + sn);
log.info("未查找到拆除报警,sn:" + sn);
return;
}
Set<Integer> alarmSet = new HashSet<>();
......@@ -318,7 +318,7 @@ public class VehicleMonitorSevice {
try {
speed = Integer.parseInt(speedStr);
} catch (NumberFormatException num) {
logger.info("解析设备的速度异常,sn:" + location.getSn() + ";speed:" + speedStr);
log.info("解析设备的速度异常,sn:" + location.getSn() + ";speed:" + speedStr);
}
parseStatus(location, speed, trackTime);
}
......
......@@ -30,8 +30,6 @@ import com.glsx.plat.core.web.R;
import com.google.gson.reflect.TypeToken;
import lombok.extern.slf4j.Slf4j;
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.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -51,7 +49,6 @@ import java.util.List;
@Service
public class VehicleService {
protected Log logger = LogFactory.getLog(getClass());
@Autowired
private VehicleMapper vehicleMapper;
......@@ -92,14 +89,17 @@ public class VehicleService {
if (StringUtils.isBlank(sn)) {
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();
param.setBindStatus(ConstantsDevice.BIND_VEHICLE_STATUS);
param.setSn(sn);
VehicleDevice bindVehicleDevice = vehicleDeviceMapper.getVehicleDeviceBySnStatus(param);
if (bindVehicleDevice != null) {
VehicleDevice vdBind = deviceService.checkSnBind(sn);
if (vdBind != null) {
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.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!