Commit 111a7eb5 by 杨林龙

优化获取 vdId 业务逻辑

1 parent c479e810
...@@ -9,35 +9,35 @@ import lombok.Setter; ...@@ -9,35 +9,35 @@ import lombok.Setter;
*/ */
@Setter @Setter
@Getter @Getter
public class stdinterfaceException extends RuntimeException { public class StdinterfaceException extends RuntimeException {
private int errorCode; private int errorCode;
private String message; private String message;
public stdinterfaceException() { public StdinterfaceException() {
} }
public stdinterfaceException(String message) { public StdinterfaceException(String message) {
super(message); super(message);
} }
public stdinterfaceException(int errorCode, String message) { public StdinterfaceException(int errorCode, String message) {
super(message); super(message);
this.errorCode = errorCode; this.errorCode = errorCode;
this.message = message; this.message = message;
} }
public stdinterfaceException(ResultEnum resultEnum) { public StdinterfaceException(ResultEnum resultEnum) {
this.errorCode = resultEnum.getCode(); this.errorCode = resultEnum.getCode();
this.message = resultEnum.getMessage(); this.message = resultEnum.getMessage();
} }
public stdinterfaceException(Throwable cause) { public StdinterfaceException(Throwable cause) {
super(cause); super(cause);
} }
public stdinterfaceException(String message, Throwable cause) { public StdinterfaceException(String message, Throwable cause) {
super(message, cause); super(message, cause);
} }
} }
...@@ -18,8 +18,8 @@ import org.springframework.web.bind.annotation.RestControllerAdvice; ...@@ -18,8 +18,8 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
@RestControllerAdvice @RestControllerAdvice
public class StdinterfaceExceptionHandler extends GlobalExceptionHandler { public class StdinterfaceExceptionHandler extends GlobalExceptionHandler {
@ExceptionHandler(stdinterfaceException.class) @ExceptionHandler(StdinterfaceException.class)
public R handleAdminException(stdinterfaceException e) { public R handleAdminException(StdinterfaceException e) {
return R.error(e.getErrorCode(), e.getMessage()); return R.error(e.getErrorCode(), e.getMessage());
} }
......
...@@ -50,13 +50,4 @@ public class FenceDriverController { ...@@ -50,13 +50,4 @@ public class FenceDriverController {
fenceDriverService.insertFenceDrive(electricFenceDrive); fenceDriverService.insertFenceDrive(electricFenceDrive);
return R.ok(); return R.ok();
} }
@GetMapping(value = "/getvdidbysn")
@SysLog(module = MODULE, value = "通过设备号获取当前车辆和设备的绑定Id", action = OperateType.QUERY)
@ApiOperation(value = "通过设备号获取当前车辆和设备的绑定Id")
public R getVdIdbySn(@RequestParam String sn) {
log.info("查询车辆和设备绑定关系设备号为===sn:" + sn);
Long vdId = fenceDriverService.getVdIdbySn(sn);
return R.ok().data(vdId);
}
} }
...@@ -16,7 +16,7 @@ import java.util.List; ...@@ -16,7 +16,7 @@ import java.util.List;
@Mapper @Mapper
public interface VehicleDeviceMapper extends CommonBaseMapper<VehicleDevice> { public interface VehicleDeviceMapper extends CommonBaseMapper<VehicleDevice> {
Long getVdIdbySn(@Param("sn") String sn); VehicleDevice getVdIdbySn(@Param("sn") String sn);
List<VehicleDevice> selectAllBindingDevices(); List<VehicleDevice> selectAllBindingDevices();
......
package cn.com.glsx.stdinterface.modules.service; package cn.com.glsx.stdinterface.modules.service;
import cn.com.glsx.stdinterface.common.exception.StdinterfaceException;
import cn.com.glsx.stdinterface.dto.ElectricInStoreDto; import cn.com.glsx.stdinterface.dto.ElectricInStoreDto;
import cn.com.glsx.stdinterface.modules.mapper.ElectricInStoreMapper; import cn.com.glsx.stdinterface.modules.mapper.ElectricInStoreMapper;
import cn.com.glsx.stdinterface.modules.mapper.VehicleDeviceMapper; import cn.com.glsx.stdinterface.modules.mapper.VehicleDeviceMapper;
...@@ -39,7 +40,18 @@ public class ElectricInStoreService { ...@@ -39,7 +40,18 @@ public class ElectricInStoreService {
vehicleDevice.setDelFlag(0); vehicleDevice.setDelFlag(0);
VehicleDevice device = vehicleDeviceMapper.selectOne(vehicleDevice); VehicleDevice device = vehicleDeviceMapper.selectOne(vehicleDevice);
if (device != null) { if (device != null) {
electricInStoreDrive.setVdId(device.getId()); // 如果设备已经解绑
if (device.getId() != null) {
electricInStoreDrive.setVdId(device.getId());
} else {
//从解绑的集合中获取最近的一个
device = vehicleDeviceMapper.getVdIdbySn(electricInStoreDrive.getSn());
if (device != null) {
electricInStoreDrive.setVdId(device.getId());
} else {
throw new StdinterfaceException("vdId 不存在,属于无效数据,设备号为:" + electricInStoreDrive.getSn());
}
}
} }
electricInStoreMapper.insert(electricInStoreDrive); electricInStoreMapper.insert(electricInStoreDrive);
} }
......
package cn.com.glsx.stdinterface.modules.service; package cn.com.glsx.stdinterface.modules.service;
import cn.com.glsx.stdinterface.common.exception.StdinterfaceException;
import cn.com.glsx.stdinterface.dto.ElectricFenceDto; import cn.com.glsx.stdinterface.dto.ElectricFenceDto;
import cn.com.glsx.stdinterface.modules.mapper.ElectricFenceDriveMapper; import cn.com.glsx.stdinterface.modules.mapper.ElectricFenceDriveMapper;
import cn.com.glsx.stdinterface.modules.mapper.VehicleDeviceMapper; import cn.com.glsx.stdinterface.modules.mapper.VehicleDeviceMapper;
...@@ -38,12 +39,19 @@ public class FenceDriverService { ...@@ -38,12 +39,19 @@ public class FenceDriverService {
vehicleDevice.setDelFlag(0); vehicleDevice.setDelFlag(0);
VehicleDevice device = vehicleDeviceMapper.selectOne(vehicleDevice); VehicleDevice device = vehicleDeviceMapper.selectOne(vehicleDevice);
if (device != null) { if (device != null) {
fenceDrive.setVdId(device.getId()); // 如果设备已经解绑
if (device.getId() != null) {
fenceDrive.setVdId(device.getId());
} else {
//从解绑的集合中获取最近的一个
device = vehicleDeviceMapper.getVdIdbySn(fenceDrive.getSn());
if (device != null) {
fenceDrive.setVdId(device.getId());
} else {
throw new StdinterfaceException("vdId 不存在,属于无效数据,设备号为:" + fenceDrive.getSn());
}
}
} }
electricFenceDriveMapper.insert(fenceDrive); electricFenceDriveMapper.insert(fenceDrive);
} }
public Long getVdIdbySn(String sn) {
return vehicleDeviceMapper.getVdIdbySn(sn);
}
} }
package cn.com.glsx.stdinterface.modules.service; package cn.com.glsx.stdinterface.modules.service;
import cn.com.glsx.stdinterface.common.exception.StdinterfaceException;
import cn.com.glsx.stdinterface.dto.RouteOilMileageDto; import cn.com.glsx.stdinterface.dto.RouteOilMileageDto;
import cn.com.glsx.stdinterface.modules.mapper.RouteOilMileageMapper; import cn.com.glsx.stdinterface.modules.mapper.RouteOilMileageMapper;
import cn.com.glsx.stdinterface.modules.mapper.VehicleDeviceMapper; import cn.com.glsx.stdinterface.modules.mapper.VehicleDeviceMapper;
...@@ -64,7 +65,20 @@ public class RouteOilMileageService { ...@@ -64,7 +65,20 @@ public class RouteOilMileageService {
RouteOilMileage routeOilMileage = new RouteOilMileage(); RouteOilMileage routeOilMileage = new RouteOilMileage();
BeanUtils.copyProperties(romd, routeOilMileage); BeanUtils.copyProperties(romd, routeOilMileage);
routeOilMileage.setVdId(device != null ? device.getId() : null); if (device != null) {
// 如果设备已经解绑
if (device.getId() != null) {
routeOilMileage.setVdId(device.getId());
} else {
//从解绑的集合中获取最近的一个
device = vehicleDeviceMapper.getVdIdbySn(romd.getSn());
if (device != null) {
routeOilMileage.setVdId(device.getId());
} else {
throw new StdinterfaceException("vdId 不存在,属于无效数据,设备号为:" + romd.getSn());
}
}
}
list.add(routeOilMileage); list.add(routeOilMileage);
}); });
if (CollectionUtils.isNotEmpty(list)) { if (CollectionUtils.isNotEmpty(list)) {
......
...@@ -23,8 +23,11 @@ ...@@ -23,8 +23,11 @@
id, vehicle_id, sn, bind_status, del_flag, created_date, created_by, updated_date, id, vehicle_id, sn, bind_status, del_flag, created_date, created_by, updated_date,
updated_by updated_by
</sql> </sql>
<select id="getVdIdbySn" resultType="java.lang.Long">
select id from t_vehicle_device where sn = #{sn} and bind_status = 1 and del_flag = 0 <select id="getVdIdbySn" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_vehicle_device where sn = #{sn} and bind_status = 2 and his_type = 1 order by id desc limit 1
</select> </select>
<select id="selectAllBindingDevices" resultMap="BaseResultMap"> <select id="selectAllBindingDevices" resultMap="BaseResultMap">
......
...@@ -4,6 +4,7 @@ import cn.com.glsx.Application; ...@@ -4,6 +4,7 @@ import cn.com.glsx.Application;
import cn.com.glsx.stdinterface.dto.RouteOilMileageDto; import cn.com.glsx.stdinterface.dto.RouteOilMileageDto;
import cn.com.glsx.stdinterface.modules.mapper.VehicleDeviceMapper; import cn.com.glsx.stdinterface.modules.mapper.VehicleDeviceMapper;
import cn.com.glsx.stdinterface.modules.model.VehicleDevice; import cn.com.glsx.stdinterface.modules.model.VehicleDevice;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
...@@ -55,4 +56,11 @@ public class RouteOilMileageTest { ...@@ -55,4 +56,11 @@ public class RouteOilMileageTest {
routeOilMileageService.storeIgnoreExists(collection); routeOilMileageService.storeIgnoreExists(collection);
} }
@Test
public void test01() {
VehicleDevice device = vehicleDeviceMapper.getVdIdbySn("8701024611");
System.out.println("device = " + JSON.toJSONString(device));
}
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!