Commit a260218c authored by AfirSraftGarrier's avatar AfirSraftGarrier

Merge remote-tracking branch 'origin/master'

parents c108a349 57f7cc77
......@@ -4,10 +4,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import iot.sixiang.license.model.BaseResult;
import iot.sixiang.license.model.ResResult;
import iot.sixiang.license.model.dto.GetTerminalDeviceTokenDTO;
import iot.sixiang.license.model.dto.ReportErrorMsgDTO;
import iot.sixiang.license.model.dto.TerminalDevieBindDTO;
import iot.sixiang.license.model.dto.TerminalDevieUnBindDTO;
import iot.sixiang.license.model.dto.*;
import iot.sixiang.license.service.TerminalDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
......@@ -54,4 +51,10 @@ public class TerminalDeviceController {
public ResResult getBindStatus(TerminalDevieUnBindDTO terminalDevieUnBindDTO) {
return terminalDeviceService.getBindStatus(terminalDevieUnBindDTO);
}
@PostMapping("/v2/bind")
@ApiOperation(value = "平台绑定设备sn接口", notes = "平台绑定设备sn接口")
public BaseResult platFormBind(@RequestBody PlatFormBindDTO platFormBindDTO) {
return terminalDeviceService.platFormBind(platFormBindDTO);
}
}
package iot.sixiang.license.model.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* Created by m33
* Date 2022/12/8 10:34
* Description
*/
@Data
public class PlatFormBindDTO {
@ApiModelProperty("设备id")
private Integer deviceId;
@ApiModelProperty("设备编码")
private String sn;
@ApiModelProperty("绑定的SN")
private String snBind;
}
......@@ -2,8 +2,10 @@ package iot.sixiang.license.service;
import com.baomidou.mybatisplus.extension.service.IService;
import iot.sixiang.license.entity.Device;
import iot.sixiang.license.model.BaseResult;
import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.ResResult;
import iot.sixiang.license.model.dto.PlatFormBindDTO;
import iot.sixiang.license.model.dto.TerminalDevieBindDTO;
import iot.sixiang.license.model.dto.TerminalDevieUnBindDTO;
import iot.sixiang.license.model.vo.DeviceVo;
......@@ -24,4 +26,6 @@ public interface DeviceService extends IService<Device> {
Boolean terminalDevieunBind(TerminalDevieUnBindDTO terminalDevieUnBindDTO);
ResResult getBindStatus(TerminalDevieUnBindDTO terminalDevieUnBindDTO);
BaseResult platFormBind(PlatFormBindDTO platFormBindDTO);
}
......@@ -2,10 +2,7 @@ package iot.sixiang.license.service;
import iot.sixiang.license.model.BaseResult;
import iot.sixiang.license.model.ResResult;
import iot.sixiang.license.model.dto.GetTerminalDeviceTokenDTO;
import iot.sixiang.license.model.dto.ReportErrorMsgDTO;
import iot.sixiang.license.model.dto.TerminalDevieBindDTO;
import iot.sixiang.license.model.dto.TerminalDevieUnBindDTO;
import iot.sixiang.license.model.dto.*;
import java.util.List;
......@@ -19,4 +16,6 @@ public interface TerminalDeviceService {
BaseResult terminalDeviceunBind(TerminalDevieUnBindDTO terminalDevieUnBindDTO);
ResResult getBindStatus(TerminalDevieUnBindDTO terminalDevieUnBindDTO);
BaseResult platFormBind(PlatFormBindDTO platFormBindDTO);
}
......@@ -7,8 +7,10 @@ import iot.sixiang.license.device.DeviceManager;
import iot.sixiang.license.entity.Device;
import iot.sixiang.license.handler.IotLicenseException;
import iot.sixiang.license.mapper.DeviceMapper;
import iot.sixiang.license.model.BaseResult;
import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.ResResult;
import iot.sixiang.license.model.dto.PlatFormBindDTO;
import iot.sixiang.license.model.dto.TerminalDevieBindDTO;
import iot.sixiang.license.model.dto.TerminalDevieUnBindDTO;
import iot.sixiang.license.model.vo.DeviceVo;
......@@ -23,6 +25,7 @@ import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.stream.BaseStream;
import java.util.stream.Collectors;
/**
......@@ -137,4 +140,41 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
return new ResResult(405, "未绑定");
}
}
@Override
public BaseResult platFormBind(PlatFormBindDTO platFormBindDTO) {
Integer deviceId = platFormBindDTO.getDeviceId();
String sn = platFormBindDTO.getSn();
String snBind = platFormBindDTO.getSnBind();
LambdaQueryWrapper<Device> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Device::getSnBind, snBind).last("limit 1");
Device device = deviceMapper.selectOne(queryWrapper);
if (device != null) {
if (deviceId.equals(device.getDeviceId())) {
return BaseResult.success();
} else {
return BaseResult.failed().msg("设备sn已被绑定");
}
}
LambdaQueryWrapper<Device> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(Device::getDeviceId, deviceId).last("limit 1");
Device tempDevice = deviceMapper.selectOne(wrapper);
if (tempDevice != null) {
if (!StringUtils.isEmpty(tempDevice.getSnBind())) {
return BaseResult.failed().msg("设备已绑定sn");
}
} else {
return BaseResult.failed().msg("请输入正确的id");
}
tempDevice.setSn(sn);
tempDevice.setSnBind(snBind);
tempDevice.setStatus(1);
tempDevice.setUpdateTime(new Date());
int res = deviceMapper.updateById(tempDevice);
if (res > 0) {
return BaseResult.success();
} else {
return BaseResult.failed();
}
}
}
......@@ -7,10 +7,7 @@ import iot.sixiang.license.jwt.JwtUtil;
import iot.sixiang.license.jwt.LoginUser;
import iot.sixiang.license.model.BaseResult;
import iot.sixiang.license.model.ResResult;
import iot.sixiang.license.model.dto.GetTerminalDeviceTokenDTO;
import iot.sixiang.license.model.dto.ReportErrorMsgDTO;
import iot.sixiang.license.model.dto.TerminalDevieBindDTO;
import iot.sixiang.license.model.dto.TerminalDevieUnBindDTO;
import iot.sixiang.license.model.dto.*;
import iot.sixiang.license.service.DeviceService;
import iot.sixiang.license.service.PmsUseService;
import iot.sixiang.license.service.TerminalDeviceService;
......@@ -132,4 +129,15 @@ public class TerminalDeviceServiceImpl implements TerminalDeviceService {
}
return deviceService.getBindStatus(terminalDevieUnBindDTO);
}
@Override
public BaseResult platFormBind(PlatFormBindDTO platFormBindDTO) {
Integer deviceId = platFormBindDTO.getDeviceId();
String sn = platFormBindDTO.getSn();
String snBind = platFormBindDTO.getSnBind();
if (deviceId == null || deviceId <= 0 || StringUtils.isEmpty(sn) || StringUtils.isEmpty(snBind)) {
return BaseResult.validate_failed();
}
return deviceService.platFormBind(platFormBindDTO);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment