Commit e79929a9 authored by 马33's avatar 马33

新增终端设备模块

parent 74c76e21
......@@ -2,13 +2,14 @@ package iot.sixiang.license.controller;
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.service.TerminalDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/iot_license/terminal_device")
......@@ -22,4 +23,16 @@ public class TerminalDeviceController {
public ResResult getToken(GetTerminalDeviceTokenDTO getTerminalDeviceTokenDTO) {
return terminalDeviceService.getToken(getTerminalDeviceTokenDTO);
}
@PostMapping("/report_error_msg")
@ApiOperation(value = "终端设备上报错误信息", notes = "终端设备上报错误信息")
public BaseResult reportErrorMsg(@RequestBody ReportErrorMsgDTO reportErrorMsgDTO) {
return terminalDeviceService.reportErrorMsg(reportErrorMsgDTO);
}
@PostMapping("/bind")
@ApiOperation(value = "终端设备绑定接口", notes = "终端设备绑定接口")
public BaseResult terminalDevieBind(@RequestBody TerminalDevieBindDTO terminalDevieBindDTO) {
return terminalDeviceService.terminalDevieBind(terminalDevieBindDTO);
}
}
......@@ -34,10 +34,13 @@ public class Device implements Serializable {
@ApiModelProperty("设备编号")
private String sn;
@ApiModelProperty("绑定的SN")
private String snBind;
@ApiModelProperty("应用Id")
private String appId;
@ApiModelProperty("应用Id")
@ApiModelProperty("状态 0:未使用,1:已使用,2:失效")
private Integer status;
@ApiModelProperty("创建时间")
......
......@@ -27,7 +27,9 @@ public class JwtFilter implements Filter {
private static final String url7 = "/swagger-resources";
private static final String url8 = "/webjars/";
private static final String url9 = "/log/get";
private static final String url10 = "/terminal_device/get_token";
private static final String url11 = "/get_token";
private static final String url12 = "/report_error_msg";
private static final String url13 = "/bind";
@Override
public void init(FilterConfig filterConfig) {
......@@ -49,7 +51,7 @@ public class JwtFilter implements Filter {
boolean check = true;
String uri = request.getRequestURI();
if (uri.contains(url1) || uri.contains(url2) || uri.contains(url3) || uri.contains(url4) || uri.contains(url7) || uri.contains(url8) || uri.contains(url9) || uri.contains(url10)) {
if (uri.contains(url1) || uri.contains(url2) || uri.contains(url3) || uri.contains(url4) || uri.contains(url7) || uri.contains(url8) || uri.contains(url9) || uri.contains(url11)) {
if (uri.contains(url1) || uri.contains(url2)) {
UserUtils.setUri(uri);
}
......@@ -77,6 +79,11 @@ public class JwtFilter implements Filter {
request.getRequestDispatcher("/fail").forward(request, response);
return;
}
// 终端设备放行
if (uri.contains(url12) || uri.contains(url13)) {
filterChain.doFilter(request, response);
return;
}
String userId = userData.get("userId").asString();
String userName = userData.get("userName").asString();
String password = userData.get("password").asString();
......
package iot.sixiang.license.model.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class ReportErrorMsgDTO {
@ApiModelProperty("错误标识id")
private Integer id;
@ApiModelProperty("错误码")
private String errorCode;
@ApiModelProperty("错误信息")
private String errorMsg;
}
package iot.sixiang.license.model.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class TerminalDevieBindDTO {
@ApiModelProperty("设备编码")
private String sn;
@ApiModelProperty("绑定的SN")
private String snBind;
}
......@@ -3,6 +3,7 @@ package iot.sixiang.license.service;
import com.baomidou.mybatisplus.extension.service.IService;
import iot.sixiang.license.entity.Device;
import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.dto.TerminalDevieBindDTO;
import iot.sixiang.license.model.vo.DeviceVo;
/**
......@@ -15,4 +16,6 @@ public interface DeviceService extends IService<Device> {
PageInfoModel<DeviceVo> getDeviceList(int pageNo, int pageSize, String appName, String userName, Integer status);
boolean addDevice(String appId, int count);
Boolean terminalDevieBind(TerminalDevieBindDTO terminalDevieBindDTO);
}
......@@ -2,6 +2,7 @@ package iot.sixiang.license.service;
import iot.sixiang.license.entity.PmsUseLog;
import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.dto.ReportErrorMsgDTO;
/**
* Created by M=54G
......@@ -16,4 +17,6 @@ public interface PmsUseService {
void success(int useLogId);
PageInfoModel<PmsUseLog> getPmsUseLogList(int pageNo, int pageSize, String sn, Integer status);
boolean reportErrorMsg(ReportErrorMsgDTO reportErrorMsgDTO);
}
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.vo.GetTerminalDeviceTokenVO;
import iot.sixiang.license.model.dto.ReportErrorMsgDTO;
import iot.sixiang.license.model.dto.TerminalDevieBindDTO;
public interface TerminalDeviceService {
ResResult getToken(GetTerminalDeviceTokenDTO getTerminalDeviceTokenDTO);
BaseResult reportErrorMsg(ReportErrorMsgDTO reportErrorMsgDTO);
BaseResult terminalDevieBind(TerminalDevieBindDTO terminalDevieBindDTO);
}
package iot.sixiang.license.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import iot.sixiang.license.consts.ResultCode;
import iot.sixiang.license.device.DeviceManager;
......@@ -7,6 +8,7 @@ import iot.sixiang.license.entity.Device;
import iot.sixiang.license.handler.IotLicenseException;
import iot.sixiang.license.mapper.DeviceMapper;
import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.dto.TerminalDevieBindDTO;
import iot.sixiang.license.model.vo.DeviceVo;
import iot.sixiang.license.service.DeviceService;
import iot.sixiang.license.util.CommonUtil;
......@@ -17,6 +19,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
......@@ -65,4 +68,25 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
deviceManager.initDevices();
return true;
}
@Override
public Boolean terminalDevieBind(TerminalDevieBindDTO terminalDevieBindDTO) {
String sn = terminalDevieBindDTO.getSn();
String snBind = terminalDevieBindDTO.getSnBind();
LambdaQueryWrapper<Device> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(Device::getSn, sn).last("limit 1");
Device device = deviceMapper.selectOne(queryWrapper);
if (device != null) {
device.setSnBind(snBind);
device.setStatus(1);
device.setUpdateTime(new Date());
int res = deviceMapper.updateById(device);
if (res >= 0) {
return true;
} else {
return false;
}
}
return false;
}
}
......@@ -5,13 +5,12 @@ import iot.sixiang.license.entity.PmsUseLog;
import iot.sixiang.license.handler.IotLicenseException;
import iot.sixiang.license.mapper.PmsUseLogMapper;
import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.vo.DeviceVo;
import iot.sixiang.license.model.dto.ReportErrorMsgDTO;
import iot.sixiang.license.service.PmsUseService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
......@@ -65,6 +64,25 @@ public class PmsUseServiceImpl implements PmsUseService {
return pmsUseLogPageInfoModel;
}
@Override
public boolean reportErrorMsg(ReportErrorMsgDTO reportErrorMsgDTO) {
Integer id = reportErrorMsgDTO.getId();
String errorCode = reportErrorMsgDTO.getErrorCode();
String errorMsg = reportErrorMsgDTO.getErrorMsg();
PmsUseLog pmsUseLog = new PmsUseLog();
pmsUseLog.setId(id);
pmsUseLog.setStatus(0);
pmsUseLog.setErrorCode(errorCode);
pmsUseLog.setMessage(errorMsg);
pmsUseLog.setUpdateTime(new Date());
int res = pmsUseLogMapper.updateById(pmsUseLog);
if (res >= 0) {
return true;
} else {
return false;
}
}
private PmsUseLog getPmsUseLog(String sn) {
PmsUseLog pmsUseLog = new PmsUseLog();
Date date = new Date();
......
package iot.sixiang.license.service.impl;
import iot.sixiang.license.auth.AuthManager;
import iot.sixiang.license.device.DeviceManager;
import iot.sixiang.license.handler.IotLicenseException;
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.service.DeviceService;
import iot.sixiang.license.service.PmsUseService;
import iot.sixiang.license.service.TerminalDeviceService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
......@@ -19,7 +23,9 @@ public class TerminalDeviceServiceImpl implements TerminalDeviceService {
@Autowired
private AuthManager authManager;
@Autowired
private DeviceManager deviceManager;
private DeviceService deviceService;
@Autowired
private PmsUseService pmsUseService;
@Override
public ResResult getToken(GetTerminalDeviceTokenDTO getTerminalDeviceTokenDTO) {
......@@ -46,4 +52,33 @@ public class TerminalDeviceServiceImpl implements TerminalDeviceService {
return ResResult.validate_failed();
}
}
@Override
public BaseResult reportErrorMsg(ReportErrorMsgDTO reportErrorMsgDTO) {
Integer id = reportErrorMsgDTO.getId();
if (id == null || id == 0) {
return BaseResult.validate_failed();
}
boolean res = pmsUseService.reportErrorMsg(reportErrorMsgDTO);
if (res) {
return BaseResult.success();
} else {
return BaseResult.failed();
}
}
@Override
public BaseResult terminalDevieBind(TerminalDevieBindDTO terminalDevieBindDTO) {
String sn = terminalDevieBindDTO.getSn();
String snBind = terminalDevieBindDTO.getSnBind();
if (StringUtils.isEmpty(sn) || StringUtils.isEmpty(snBind)) {
return BaseResult.validate_failed();
}
Boolean res = deviceService.terminalDevieBind(terminalDevieBindDTO);
if (res) {
return BaseResult.success();
} else {
return BaseResult.failed();
}
}
}
......@@ -22,6 +22,23 @@ import java.util.Random;
*/
public class DeviceControllerTest {
@Test
void terminalDeviceSign() {
String appId = "7j26zr7en9fiyoyvjz";
String sn = "8HOE8JH4EFSEV28534";
// String snBind = "snabcd";
String appKey = "2";
String string = "app_id=" + appId + "&sn=" + sn;
String sign = HmacUtil.encrypt(string, appKey, HmacUtil.HMAC_SHA1);
System.out.println("token appId:" + appId);
System.out.println("token sn:" + sn);
System.out.println("token sign:" + sign);
}
@Test
void tokenSign() {
String appId = "ebsh71dp5t1ck948l5";
......
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