Commit ede6dc08 authored by ma's avatar ma

Merge remote-tracking branch 'remotes/origin/master' into for-yx

# Conflicts:
#	license/pom.xml
#	license/src/main/java/iot/sixiang/license/device/DeviceServerHandler.java
#	license/src/main/java/iot/sixiang/license/util/CommonUtil.java
parents 5b4098c8 388cfef0
package iot.sixiang.license.consts; package iot.sixiang.license.consts;
public class Consts { public class Constant {
public static final int CMD_LICENSE = 1;// 授权消息的cmd,十进制 public static final int CMD_LICENSE = 1;// 授权消息的cmd,十进制
public static final int CMD_UPLOAD_ERROR = 2;// 错误消息上报
public static final int EXECUTOR_THREAD_NUM = 30; public static final int EXECUTOR_THREAD_NUM = 30;
public static final int FORWARD_THREAD_NUM = 30; public static final int FORWARD_THREAD_NUM = 30;
public static final int OPERATE_THREAD_NUM = 5; public static final int OPERATE_THREAD_NUM = 5;
......
...@@ -4,10 +4,7 @@ import io.swagger.annotations.Api; ...@@ -4,10 +4,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import iot.sixiang.license.model.BaseResult; import iot.sixiang.license.model.BaseResult;
import iot.sixiang.license.model.ResResult; import iot.sixiang.license.model.ResResult;
import iot.sixiang.license.model.dto.GetTerminalDeviceTokenDTO; import iot.sixiang.license.model.dto.*;
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.service.TerminalDeviceService; import iot.sixiang.license.service.TerminalDeviceService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
...@@ -25,23 +22,23 @@ public class TerminalDeviceController { ...@@ -25,23 +22,23 @@ public class TerminalDeviceController {
@Autowired @Autowired
TerminalDeviceService terminalDeviceService; TerminalDeviceService terminalDeviceService;
@GetMapping("/get_token") // @GetMapping("/get_token")
@ApiOperation(value = "终端设备获取token", notes = "终端设备获取token") // @ApiOperation(value = "终端设备获取token", notes = "终端设备获取token")
public ResResult getToken(GetTerminalDeviceTokenDTO getTerminalDeviceTokenDTO) { // public ResResult getToken(GetTerminalDeviceTokenDTO getTerminalDeviceTokenDTO) {
return terminalDeviceService.getToken(getTerminalDeviceTokenDTO); // return terminalDeviceService.getToken(getTerminalDeviceTokenDTO);
} // }
@PostMapping("/report_error_msg") // @PostMapping("/report_error_msg")
@ApiOperation(value = "终端设备上报错误信息", notes = "终端设备上报错误信息") // @ApiOperation(value = "终端设备上报错误信息", notes = "终端设备上报错误信息")
public BaseResult reportErrorMsg(@RequestBody List<ReportErrorMsgDTO> reportErrorMsgDTO) { // public BaseResult reportErrorMsg(@RequestBody List<ReportErrorMsgDTO> reportErrorMsgDTO) {
return terminalDeviceService.reportErrorMsg(reportErrorMsgDTO); // return terminalDeviceService.reportErrorMsg(reportErrorMsgDTO);
} // }
@PostMapping("/bind") // @PostMapping("/bind")
@ApiOperation(value = "终端设备绑定接口", notes = "终端设备绑定接口") // @ApiOperation(value = "终端设备绑定接口", notes = "终端设备绑定接口")
public BaseResult terminalDevieBind(@RequestBody TerminalDevieBindDTO terminalDevieBindDTO) { // public BaseResult terminalDevieBind(@RequestBody TerminalDevieBindDTO terminalDevieBindDTO) {
return terminalDeviceService.terminalDeviceBind(terminalDevieBindDTO); // return terminalDeviceService.terminalDeviceBind(terminalDevieBindDTO);
} // }
@PostMapping("/unbind") @PostMapping("/unbind")
@ApiOperation(value = "终端设备解绑接口", notes = "终端设备解绑接口") @ApiOperation(value = "终端设备解绑接口", notes = "终端设备解绑接口")
...@@ -49,9 +46,15 @@ public class TerminalDeviceController { ...@@ -49,9 +46,15 @@ public class TerminalDeviceController {
return terminalDeviceService.terminalDeviceunBind(terminalDevieUnBindDTO); return terminalDeviceService.terminalDeviceunBind(terminalDevieUnBindDTO);
} }
@GetMapping("/get_bind_status") // @GetMapping("/get_bind_status")
@ApiOperation(value = "获取终端设备绑定状态接口", notes = "获取终端设备绑定状态接口") // @ApiOperation(value = "获取终端设备绑定状态接口", notes = "获取终端设备绑定状态接口")
public ResResult getBindStatus(TerminalDevieUnBindDTO terminalDevieUnBindDTO) { // public ResResult getBindStatus(TerminalDevieUnBindDTO terminalDevieUnBindDTO) {
return terminalDeviceService.getBindStatus(terminalDevieUnBindDTO); // return terminalDeviceService.getBindStatus(terminalDevieUnBindDTO);
// }
@PostMapping("/v2/bind")
@ApiOperation(value = "平台绑定设备sn接口", notes = "平台绑定设备sn接口")
public BaseResult platFormBind(@RequestBody PlatFormBindDTO platFormBindDTO) {
return terminalDeviceService.platFormBind(platFormBindDTO);
} }
} }
...@@ -4,7 +4,7 @@ import io.netty.channel.socket.SocketChannel; ...@@ -4,7 +4,7 @@ import io.netty.channel.socket.SocketChannel;
import io.netty.handler.timeout.IdleStateHandler; import io.netty.handler.timeout.IdleStateHandler;
import io.netty.util.concurrent.DefaultEventExecutorGroup; import io.netty.util.concurrent.DefaultEventExecutorGroup;
import io.netty.util.concurrent.EventExecutorGroup; import io.netty.util.concurrent.EventExecutorGroup;
import iot.sixiang.license.consts.Consts; import iot.sixiang.license.consts.Constant;
import iot.sixiang.license.net.BaseChannelInitializer; import iot.sixiang.license.net.BaseChannelInitializer;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -14,7 +14,7 @@ import java.util.concurrent.TimeUnit; ...@@ -14,7 +14,7 @@ import java.util.concurrent.TimeUnit;
public class DeviceChannelInitializer extends BaseChannelInitializer { public class DeviceChannelInitializer extends BaseChannelInitializer {
private DeviceServerHandler handler; private DeviceServerHandler handler;
static final EventExecutorGroup workGroup = new DefaultEventExecutorGroup(Consts.EXECUTOR_THREAD_NUM); static final EventExecutorGroup workGroup = new DefaultEventExecutorGroup(Constant.EXECUTOR_THREAD_NUM);
public DeviceChannelInitializer(DeviceServerHandler handler) { public DeviceChannelInitializer(DeviceServerHandler handler) {
this.handler = handler; this.handler = handler;
......
package iot.sixiang.license.device; package iot.sixiang.license.device;
import iot.sixiang.license.consts.Consts; import iot.sixiang.license.consts.Constant;
import iot.sixiang.license.model.PageInfoModel; import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.SessionContext; import iot.sixiang.license.model.SessionContext;
import iot.sixiang.license.model.vo.DeviceDetailVo; import iot.sixiang.license.model.vo.DeviceDetailVo;
...@@ -142,7 +142,7 @@ public class DeviceManager { ...@@ -142,7 +142,7 @@ public class DeviceManager {
if (targetSession.getChannelId().equals(channelId)) { if (targetSession.getChannelId().equals(channelId)) {
targetSession.setAuthStatus(false); targetSession.setAuthStatus(false);
targetSession.setStatus(Consts.DEVICE_STATE_OFFLINE); targetSession.setStatus(Constant.DEVICE_STATE_OFFLINE);
targetSession.setOffline(CommonUtil.getSystemTime()); targetSession.setOffline(CommonUtil.getSystemTime());
return true; return true;
} }
......
package iot.sixiang.license.device; package iot.sixiang.license.device;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.SocketChannel;
import iot.sixiang.license.auth.AuthManager; import iot.sixiang.license.auth.AuthManager;
import iot.sixiang.license.consts.Consts; import iot.sixiang.license.consts.Constant;
import iot.sixiang.license.event.CreateForwardClientEvent; import iot.sixiang.license.event.CreateForwardClientEvent;
import iot.sixiang.license.event.DeviceClientInactiveEvent; import iot.sixiang.license.event.DeviceClientInactiveEvent;
import iot.sixiang.license.event.DeviceClientLicenseEvent;
import iot.sixiang.license.event.EventPublisher; import iot.sixiang.license.event.EventPublisher;
import iot.sixiang.license.event.ForwardClientRequestEvent; import iot.sixiang.license.event.ForwardClientRequestEvent;
import iot.sixiang.license.model.SessionContext; import iot.sixiang.license.model.SessionContext;
import iot.sixiang.license.model.dto.ReportErrorMsgDTO;
import iot.sixiang.license.service.PmsUseService; import iot.sixiang.license.service.PmsUseService;
import iot.sixiang.license.third_lib.LibHelper; import iot.sixiang.license.service.TerminalDeviceService;
import iot.sixiang.license.util.CommonUtil; import iot.sixiang.license.util.CommonUtil;
import iot.sixiang.license.util.HexUtil; import iot.sixiang.license.util.HexUtil;
import iot.sixiang.license.util.SpringUtil; import iot.sixiang.license.util.SpringUtil;
...@@ -24,15 +27,19 @@ import org.springframework.stereotype.Component; ...@@ -24,15 +27,19 @@ import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.List;
@Component @Component
@ChannelHandler.Sharable @ChannelHandler.Sharable
@Slf4j @Slf4j
public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> { public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
@Autowired @Autowired
EventPublisher eventPublisher; EventPublisher eventPublisher;
@Resource @Resource
private PmsUseService pmsUseService; private PmsUseService pmsUseService;
@Resource
TerminalDeviceService terminalDeviceService;
public DeviceServerHandler() { public DeviceServerHandler() {
super(); super();
...@@ -53,13 +60,18 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> { ...@@ -53,13 +60,18 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
int cmdInt = cmd & 0xFF; int cmdInt = cmd & 0xFF;
boolean auth = false; boolean auth = false;
if (cmdInt == Consts.CMD_LICENSE) { if (cmdInt == Constant.CMD_LICENSE) {
auth = handlerCheckAuth(channel, remoteIp, remotePort, protocol); auth = handleCheckAuth(channel, remoteIp, remotePort, protocol);
} else if (cmdInt == Constant.CMD_UPLOAD_ERROR) {
auth = handleCheckAuthStatus(channel, remoteIp, remotePort, protocol);
if (auth) {
handleUploadError(channel, remoteIp, remotePort, protocol);
}
} else { } else {
auth = handlerCheckAuthStatus(channel); auth = handleCheckAuthStatus(channel, remoteIp, remotePort, protocol);
if (auth) { if (auth) {
log.info("auth valid..."); log.info("auth valid...");
handlerForward(channel, protocol); handleForward(channel, remoteIp, remotePort, protocol);
} }
} }
...@@ -147,7 +159,7 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> { ...@@ -147,7 +159,7 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
session.setChannelId(channelId); session.setChannelId(channelId);
session.setClientChannel(channel); session.setClientChannel(channel);
session.setAuthStatus(true); session.setAuthStatus(true);
session.setStatus(Consts.DEVICE_STATE_ONLINE); session.setStatus(Constant.DEVICE_STATE_ONLINE);
session.setOnline(CommonUtil.getSystemTime()); session.setOnline(CommonUtil.getSystemTime());
DeviceManager deviceManager = SpringUtil.getBean(DeviceManager.class); DeviceManager deviceManager = SpringUtil.getBean(DeviceManager.class);
...@@ -163,17 +175,50 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> { ...@@ -163,17 +175,50 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
return license; return license;
} }
private boolean handlerCheckAuthStatus(SocketChannel channel) { private void handleUploadError(SocketChannel channel, String remoteIp, int remotePort, DeviceProtocol protocol) {
//byte[] bytes = safety.decodeExtendedPayload(protocol.getContent(), 0, protocol.getContent().length);
if (protocol.getContent() == null) {
return;
}
String decodeInfo = CommonUtil.bytesToStr(protocol.getContent());
log.info("upload error byte to string:" + decodeInfo);
if (decodeInfo == null) {
return;
}
List<ReportErrorMsgDTO> reportErrorMsgDTOS = JSONArray.parseArray(decodeInfo, ReportErrorMsgDTO.class);
terminalDeviceService.reportErrorMsg(reportErrorMsgDTOS);
short stx = 21930;
byte ack = 0x0;
int len = 3;
byte cmd = 0x2;
byte[] content = new byte[1];
content[0] = 0x7e;
byte end = 0x1;
DeviceProtocol theProtocol = new DeviceProtocol(stx, len, cmd, ack, content, end);
handleClient(channel, theProtocol);
}
private boolean handleCheckAuthStatus(SocketChannel channel, String remoteIp, int remotePort, DeviceProtocol protocol) {
String channelId = channel.id().asLongText(); String channelId = channel.id().asLongText();
DeviceManager deviceManager = SpringUtil.getBean(DeviceManager.class); DeviceManager deviceManager = SpringUtil.getBean(DeviceManager.class);
return deviceManager.getAuthStatusByChannelId(channelId); return deviceManager.getAuthStatusByChannelId(channelId);
} }
private void handlerForward(SocketChannel channel, DeviceProtocol protocol) { private void handleForward(SocketChannel channel, String remoteIp, int remotePort, DeviceProtocol protocol) {
String channelId = channel.id().asLongText(); String channelId = channel.id().asLongText();
ForwardClientRequestEvent forwardClientRequestEvent = new ForwardClientRequestEvent(); ForwardClientRequestEvent forwardClientRequestEvent = new ForwardClientRequestEvent();
forwardClientRequestEvent.setDeviceChannelId(channelId); forwardClientRequestEvent.setDeviceChannelId(channelId);
forwardClientRequestEvent.setProtocol(protocol); forwardClientRequestEvent.setProtocol(protocol);
eventPublisher.publishEvent(forwardClientRequestEvent); eventPublisher.publishEvent(forwardClientRequestEvent);
} }
private void handleClient(SocketChannel channel, DeviceProtocol protocol) {
String channelId = channel.id().asLongText();
DeviceClientLicenseEvent deviceClientLicenseEvent = new DeviceClientLicenseEvent();
deviceClientLicenseEvent.setDeviceChannelId(channelId);
deviceClientLicenseEvent.setProtocol(protocol);
eventPublisher.publishEvent(deviceClientLicenseEvent);
}
} }
...@@ -6,5 +6,6 @@ import lombok.Data; ...@@ -6,5 +6,6 @@ import lombok.Data;
@Data @Data
public class DeviceClientLicenseEvent extends BaseEvent { public class DeviceClientLicenseEvent extends BaseEvent {
private String sn; private String sn;
private String deviceChannelId;
private DeviceProtocol protocol; private DeviceProtocol protocol;
} }
...@@ -17,15 +17,19 @@ public class DeviceClientLicenseEventHandler { ...@@ -17,15 +17,19 @@ public class DeviceClientLicenseEventHandler {
EventPublisher eventPublisher; EventPublisher eventPublisher;
public DeviceClientLicenseEventHandler() { public DeviceClientLicenseEventHandler() {
} }
@EventListener @EventListener
public void handlerEvent(DeviceClientLicenseEvent event) { public void handlerEvent(DeviceClientLicenseEvent event) {
String appId = event.getSn(); String sn = event.getSn();
DeviceProtocol protocol = event.getProtocol(); DeviceProtocol protocol = event.getProtocol();
SessionContext session = null;
if (sn != null) {
session = deviceManager.getSessionContextBySN(sn);
} else if (event.getDeviceChannelId() != null) {
session = deviceManager.getSessionByChannelId(event.getDeviceChannelId());
}
SessionContext session = deviceManager.getSessionContextBySN(appId);
if (session == null) { if (session == null) {
log.debug("device client license undo ..."); log.debug("device client license undo ...");
return; return;
......
...@@ -22,8 +22,8 @@ public class ForwardMessageResponseEventHandler { ...@@ -22,8 +22,8 @@ public class ForwardMessageResponseEventHandler {
ForwardManager forwardManager; ForwardManager forwardManager;
@Autowired @Autowired
EventPublisher eventPublisher; EventPublisher eventPublisher;
@Resource //@Resource
private PmsUseService pmsUseService; //private PmsUseService pmsUseService;
public ForwardMessageResponseEventHandler() { public ForwardMessageResponseEventHandler() {
} }
...@@ -45,10 +45,9 @@ public class ForwardMessageResponseEventHandler { ...@@ -45,10 +45,9 @@ public class ForwardMessageResponseEventHandler {
} else { } else {
log.info("forward client response undo ..." + sn); log.info("forward client response undo ..." + sn);
} }
// 说明已经成功 // 说明已经成功
if (protocol.getCmd() == 0xF2) { //if (protocol.getCmd() == 0xF2) {
pmsUseService.success(deviceSessionContext.getUseLogId()); // pmsUseService.success(deviceSessionContext.getUseLogId());
} //}
} }
} }
...@@ -3,13 +3,13 @@ package iot.sixiang.license.forward; ...@@ -3,13 +3,13 @@ package iot.sixiang.license.forward;
import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.SocketChannel;
import io.netty.util.concurrent.DefaultEventExecutorGroup; import io.netty.util.concurrent.DefaultEventExecutorGroup;
import io.netty.util.concurrent.EventExecutorGroup; import io.netty.util.concurrent.EventExecutorGroup;
import iot.sixiang.license.consts.Consts; import iot.sixiang.license.consts.Constant;
import iot.sixiang.license.net.BaseChannelInitializer; import iot.sixiang.license.net.BaseChannelInitializer;
public class ForwardChannelInitializer extends BaseChannelInitializer { public class ForwardChannelInitializer extends BaseChannelInitializer {
private ForwardClientHandler handler; private ForwardClientHandler handler;
static final EventExecutorGroup workGroup = new DefaultEventExecutorGroup(Consts.FORWARD_THREAD_NUM); static final EventExecutorGroup workGroup = new DefaultEventExecutorGroup(Constant.FORWARD_THREAD_NUM);
public ForwardChannelInitializer(ForwardClientHandler handler) { public ForwardChannelInitializer(ForwardClientHandler handler) {
this.handler = handler; this.handler = handler;
......
package iot.sixiang.license.forward; package iot.sixiang.license.forward;
import iot.sixiang.license.consts.Consts; import iot.sixiang.license.consts.Constant;
import iot.sixiang.license.model.SessionContext; import iot.sixiang.license.model.SessionContext;
import iot.sixiang.license.model.vo.ServerStatusVo; import iot.sixiang.license.model.vo.ServerStatusVo;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -67,11 +67,11 @@ public class ForwardManager { ...@@ -67,11 +67,11 @@ public class ForwardManager {
public ServerStatusVo getServerStatus() { public ServerStatusVo getServerStatus() {
ServerStatusVo vo = new ServerStatusVo(); ServerStatusVo vo = new ServerStatusVo();
int size = sessionContexts.size(); int size = sessionContexts.size();
int statue = Consts.SERVICE_DX_STATUS_FLUENT; int statue = Constant.SERVICE_DX_STATUS_FLUENT;
if (size >= Consts.SERVICE_DX_THRESHOLD_NORMAL) { if (size >= Constant.SERVICE_DX_THRESHOLD_NORMAL) {
statue = Consts.SERVICE_DX_STATUS_NORMAL; statue = Constant.SERVICE_DX_STATUS_NORMAL;
} else if (size > Consts.SERVICE_DX_THRESHOLD_BUSY) { } else if (size > Constant.SERVICE_DX_THRESHOLD_BUSY) {
statue = Consts.SERVICE_DX_STATUS_BUSY; statue = Constant.SERVICE_DX_STATUS_BUSY;
} }
vo.setCount(size); vo.setCount(size);
vo.setStatus(statue); vo.setStatus(statue);
......
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;
}
...@@ -3,14 +3,14 @@ package iot.sixiang.license.operate; ...@@ -3,14 +3,14 @@ package iot.sixiang.license.operate;
import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.SocketChannel;
import io.netty.util.concurrent.DefaultEventExecutorGroup; import io.netty.util.concurrent.DefaultEventExecutorGroup;
import io.netty.util.concurrent.EventExecutorGroup; import io.netty.util.concurrent.EventExecutorGroup;
import iot.sixiang.license.consts.Consts; import iot.sixiang.license.consts.Constant;
import iot.sixiang.license.net.BaseChannelInitializer; import iot.sixiang.license.net.BaseChannelInitializer;
public class OperateChannelInitializer extends BaseChannelInitializer { public class OperateChannelInitializer extends BaseChannelInitializer {
private OperateClientHandler handler; private OperateClientHandler handler;
static final EventExecutorGroup workGroup = new DefaultEventExecutorGroup(Consts.OPERATE_THREAD_NUM); static final EventExecutorGroup workGroup = new DefaultEventExecutorGroup(Constant.OPERATE_THREAD_NUM);
public OperateChannelInitializer(OperateClientHandler handler) { public OperateChannelInitializer(OperateClientHandler handler) {
this.handler = handler; this.handler = handler;
......
...@@ -2,8 +2,10 @@ package iot.sixiang.license.service; ...@@ -2,8 +2,10 @@ package iot.sixiang.license.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import iot.sixiang.license.entity.Device; import iot.sixiang.license.entity.Device;
import iot.sixiang.license.model.BaseResult;
import iot.sixiang.license.model.PageInfoModel; import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.ResResult; 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.TerminalDevieBindDTO;
import iot.sixiang.license.model.dto.TerminalDevieUnBindDTO; import iot.sixiang.license.model.dto.TerminalDevieUnBindDTO;
import iot.sixiang.license.model.vo.DeviceVo; import iot.sixiang.license.model.vo.DeviceVo;
...@@ -24,4 +26,6 @@ public interface DeviceService extends IService<Device> { ...@@ -24,4 +26,6 @@ public interface DeviceService extends IService<Device> {
Boolean terminalDevieunBind(TerminalDevieUnBindDTO terminalDevieUnBindDTO); Boolean terminalDevieunBind(TerminalDevieUnBindDTO terminalDevieUnBindDTO);
ResResult getBindStatus(TerminalDevieUnBindDTO terminalDevieUnBindDTO); ResResult getBindStatus(TerminalDevieUnBindDTO terminalDevieUnBindDTO);
BaseResult platFormBind(PlatFormBindDTO platFormBindDTO);
} }
...@@ -2,10 +2,7 @@ package iot.sixiang.license.service; ...@@ -2,10 +2,7 @@ package iot.sixiang.license.service;
import iot.sixiang.license.model.BaseResult; import iot.sixiang.license.model.BaseResult;
import iot.sixiang.license.model.ResResult; import iot.sixiang.license.model.ResResult;
import iot.sixiang.license.model.dto.GetTerminalDeviceTokenDTO; import iot.sixiang.license.model.dto.*;
import iot.sixiang.license.model.dto.ReportErrorMsgDTO;
import iot.sixiang.license.model.dto.TerminalDevieBindDTO;
import iot.sixiang.license.model.dto.TerminalDevieUnBindDTO;
import java.util.List; import java.util.List;
...@@ -19,4 +16,6 @@ public interface TerminalDeviceService { ...@@ -19,4 +16,6 @@ public interface TerminalDeviceService {
BaseResult terminalDeviceunBind(TerminalDevieUnBindDTO terminalDevieUnBindDTO); BaseResult terminalDeviceunBind(TerminalDevieUnBindDTO terminalDevieUnBindDTO);
ResResult getBindStatus(TerminalDevieUnBindDTO terminalDevieUnBindDTO); ResResult getBindStatus(TerminalDevieUnBindDTO terminalDevieUnBindDTO);
BaseResult platFormBind(PlatFormBindDTO platFormBindDTO);
} }
...@@ -7,8 +7,10 @@ import iot.sixiang.license.device.DeviceManager; ...@@ -7,8 +7,10 @@ import iot.sixiang.license.device.DeviceManager;
import iot.sixiang.license.entity.Device; import iot.sixiang.license.entity.Device;
import iot.sixiang.license.handler.IotLicenseException; import iot.sixiang.license.handler.IotLicenseException;
import iot.sixiang.license.mapper.DeviceMapper; import iot.sixiang.license.mapper.DeviceMapper;
import iot.sixiang.license.model.BaseResult;
import iot.sixiang.license.model.PageInfoModel; import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.ResResult; 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.TerminalDevieBindDTO;
import iot.sixiang.license.model.dto.TerminalDevieUnBindDTO; import iot.sixiang.license.model.dto.TerminalDevieUnBindDTO;
import iot.sixiang.license.model.vo.DeviceVo; import iot.sixiang.license.model.vo.DeviceVo;
...@@ -23,6 +25,7 @@ import java.util.ArrayList; ...@@ -23,6 +25,7 @@ import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.stream.BaseStream;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
...@@ -137,4 +140,41 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme ...@@ -137,4 +140,41 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
return new ResResult(405, "未绑定"); 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; ...@@ -7,10 +7,7 @@ import iot.sixiang.license.jwt.JwtUtil;
import iot.sixiang.license.jwt.LoginUser; import iot.sixiang.license.jwt.LoginUser;
import iot.sixiang.license.model.BaseResult; import iot.sixiang.license.model.BaseResult;
import iot.sixiang.license.model.ResResult; import iot.sixiang.license.model.ResResult;
import iot.sixiang.license.model.dto.GetTerminalDeviceTokenDTO; import iot.sixiang.license.model.dto.*;
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.service.DeviceService; import iot.sixiang.license.service.DeviceService;
import iot.sixiang.license.service.PmsUseService; import iot.sixiang.license.service.PmsUseService;
import iot.sixiang.license.service.TerminalDeviceService; import iot.sixiang.license.service.TerminalDeviceService;
...@@ -66,31 +63,23 @@ public class TerminalDeviceServiceImpl implements TerminalDeviceService { ...@@ -66,31 +63,23 @@ public class TerminalDeviceServiceImpl implements TerminalDeviceService {
if (reportErrorMsgDTOs == null || reportErrorMsgDTOs.size() == 0) { if (reportErrorMsgDTOs == null || reportErrorMsgDTOs.size() == 0) {
return BaseResult.validate_failed(); return BaseResult.validate_failed();
} }
reportErrorMsgDTOs.sort(Comparator.comparingInt(ReportErrorMsgDTO::getId)); for (ReportErrorMsgDTO reportErrorMsgDTO : reportErrorMsgDTOs) {
for (int i = 0; i < reportErrorMsgDTOs.size() - 1; i++) {
ReportErrorMsgDTO reportErrorMsgDTO = reportErrorMsgDTOs.get(i);
Integer id = reportErrorMsgDTO.getId(); Integer id = reportErrorMsgDTO.getId();
if (id == null || id == 0) { if (id == null || id == 0 || reportErrorMsgDTO.getErrorCode() == null) {
return BaseResult.validate_failed(); return BaseResult.validate_failed();
} }
pmsUseService.deletePmsUseLogById(id);
}
ReportErrorMsgDTO reportErrorMsgDTO = reportErrorMsgDTOs.get(reportErrorMsgDTOs.size() - 1);
if (reportErrorMsgDTO.getId() == null || reportErrorMsgDTO.getId() == 0 || reportErrorMsgDTO.getErrorCode() == null) {
return BaseResult.validate_failed();
} else {
if ("0".equals(reportErrorMsgDTO.getErrorCode())) { if ("0".equals(reportErrorMsgDTO.getErrorCode())) {
pmsUseService.success(reportErrorMsgDTO.getId()); pmsUseService.success(reportErrorMsgDTO.getId());
return BaseResult.success(); } else if ("-1".equals(reportErrorMsgDTO.getErrorCode())) {
pmsUseService.deletePmsUseLogById(id);
} else { } else {
boolean res = pmsUseService.reportErrorMsg(reportErrorMsgDTO); boolean res = pmsUseService.reportErrorMsg(reportErrorMsgDTO);
if (res) { if (!res) {
return BaseResult.success();
} else {
return BaseResult.failed(); return BaseResult.failed();
} }
} }
} }
return BaseResult.success();
} }
@Override @Override
...@@ -132,4 +121,20 @@ public class TerminalDeviceServiceImpl implements TerminalDeviceService { ...@@ -132,4 +121,20 @@ public class TerminalDeviceServiceImpl implements TerminalDeviceService {
} }
return deviceService.getBindStatus(terminalDevieUnBindDTO); 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();
}
BaseResult result = deviceService.platFormBind(platFormBindDTO);
if (result.getCode() == 200) {
deviceManager.initDevices();
}
return result;
}
} }
package iot.sixiang.license.util; package iot.sixiang.license.util;
import iot.sixiang.license.consts.Consts; import iot.sixiang.license.consts.Constant;
import iot.sixiang.license.model.ResResult;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.http.util.TextUtils; import org.apache.http.util.TextUtils;
...@@ -234,7 +233,7 @@ public class CommonUtil { ...@@ -234,7 +233,7 @@ public class CommonUtil {
} }
public static String getServerParentDirectory() { public static String getServerParentDirectory() {
return new File(new ApplicationHome(Consts.class).getSource().getParentFile().getPath()).getParent() + File.separator + "lib"; return new File(new ApplicationHome(Constant.class).getSource().getParentFile().getPath()).getParent() + File.separator + "lib";
} }
/** /**
......
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