Commit ed179d55 by 杨林龙

车辆档案列表修改绑定的设备只能绑定未激活的设备 并且同步修改设备为激活 设置激活时间和激活状态

1 parent e5542e5d
......@@ -343,6 +343,12 @@ public class VehicleController {
return R.error(1001, sn + "该设备已经绑定").data(false);
}
// 校验设备号是否已经绑定
boolean activeSn = deviceService.checkActiveSn(sn);
if (!activeSn) {
return R.error(1001, sn + "该设备已经激活").data(false);
}
return R.ok(sn + "设备验证通过").data(true);
}
......
......@@ -3,6 +3,7 @@ package cn.com.glsx.admin.modules.mapper;
import cn.com.glsx.admin.modules.entity.Device;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@Mapper
public interface DeviceMapper extends CommonBaseMapper<Device> {
......@@ -10,9 +11,16 @@ public interface DeviceMapper extends CommonBaseMapper<Device> {
/**
* 根据设备号查找设备信息
*
* @param sn
* @param sn 设备号
* @return
*/
Device selectBySn(String sn);
Device selectBySn(@Param("sn") String sn);
/**
* 根据sn 获取未激活的设备
*
* @param sn 设备号
* @return
*/
Device selectUnActiveDeviceBySn(@Param("sn") String sn);
}
\ No newline at end of file
......@@ -64,6 +64,15 @@ public class DeviceService {
}
/**
* 根据sn 获取没有激活单的设备
*
* @param sn 设备号
*/
public Device getUnActiveDeviceBySn(String sn) {
return deviceMapper.selectUnActiveDeviceBySn(sn);
}
/**
* 检查设备号是否存在(入库) false 不存在
*
* @param sn
......@@ -174,4 +183,26 @@ public class DeviceService {
}
return false;
}
/**
* 校验设备时候已经激活
*
* @param sn 设备号
* @return
*/
public boolean checkActiveSn(String sn) {
if (StringUtils.isEmpty(sn)) {
return false;
}
Device param = new Device();
param.setSn(sn);
// 激活状态:0 未激活,1 激活
param.setActivateStatus(1);
param.setDelFlag(ConstantsDevice.NOT_DEL_FLAG);
Device device = deviceMapper.selectOne(param);
if (device == null) {
return true;
}
return false;
}
}
......@@ -1264,6 +1264,12 @@ public class VehicleService {
List<DeviceInfoDto> deviceInfoDtos = vehicleInfoVo.getDeviceInfoDtos();
for (DeviceInfoDto deviceInfoDto : deviceInfoDtos) {
vehicleDeviceService.saveSnToVehicleId(deviceInfoDto.getSn(), vehicle.getId());
// 修改设备为激活状态
Device unActiveDeviceBySn = deviceService.getUnActiveDeviceBySn(deviceInfoDto.getSn());
// 激活状态:0未激活,1激活
unActiveDeviceBySn.setActivateStatus(1);
unActiveDeviceBySn.setActivateTime(new Date());
deviceService.updateDevice(unActiveDeviceBySn);
}
}
......@@ -1309,6 +1315,12 @@ public class VehicleService {
if (vehicleDevice == null) {
log.info("车辆" + vehicle.getId() + "新绑定的设备号===" + deviceInfoDto.getSn());
vehicleDeviceService.saveSnToVehicleId(deviceInfoDto.getSn(), vehicle.getId());
// 修改设备为激活状态
Device unActiveDeviceBySn = deviceService.getUnActiveDeviceBySn(deviceInfoDto.getSn());
// 激活状态:0未激活,1激活
unActiveDeviceBySn.setActivateStatus(1);
unActiveDeviceBySn.setActivateTime(new Date());
deviceService.updateDevice(unActiveDeviceBySn);
}
}
}
......
......@@ -44,4 +44,13 @@
where del_flag = 0
and sn = #{sn}
</select>
<select id="selectUnActiveDeviceBySn" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_device
where del_flag = 0
and sn = #{sn}
and activate_status = 0
</select>
</mapper>
\ No newline at end of file
......@@ -2123,7 +2123,7 @@ public class VehicleServiceTest {
@Test
public void test12() {
R<DeviceStatusModel> deviceStatusBySn = deviceFeignService.getDeviceStatusBySn("75108160001", 0L);
R<DeviceStatusModel> deviceStatusBySn = deviceFeignService.getDeviceStatusBySn("8700922797", 0L);
System.out.println("deviceStatusBySn = " + deviceStatusBySn);
if (deviceStatusBySn != null) {
// 状态(0 行驶中 1 静止 2离线 3 在线)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!