Commit 27888877 authored by AfirSraftGarrier's avatar AfirSraftGarrier

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	license/src/main/java/iot/sixiang/license/service/TerminalDeviceService.java
parents 40d031dc 4c342fd9
......@@ -78,20 +78,22 @@ public class DeviceController {
*/
@ApiOperation(value = "获取设备列表接口", notes = "用于获取设备列表")
@GetMapping("list")
@MyLog(title = "获取设备列表", optParam = "#{pageNo},#{pageSize},#{appName},#{userName},#{status}", businessType = BusinessType.SELECT)
@MyLog(title = "获取设备列表", optParam = "#{pageNo},#{pageSize},#{appName},#{userName},#{sn},#{status}", businessType = BusinessType.SELECT)
@ApiImplicitParams({
@ApiImplicitParam(name = "pageNo", value = "当前在第几页", required = true, dataType = "int"),
@ApiImplicitParam(name = "pageSize", value = "每页显示多少页", required = true, dataType = "int"),
@ApiImplicitParam(name = "appName", value = "应用名"),
@ApiImplicitParam(name = "userName", value = "用户名"),
@ApiImplicitParam(name = "sn", value = "设备编码"),
@ApiImplicitParam(name = "status", value = "状态", dataType = "int")
})
public PageResult<DeviceVo> getDeviceList(@RequestParam(value = "pageNo", defaultValue = "0") int pageNo,
@RequestParam(value = "pageSize", defaultValue = "0") int pageSize,
@RequestParam(value = "appName", required = false) String appName,
@RequestParam(value = "userName", required = false) String userName,
@RequestParam(value = "sn", required = false) String sn,
@RequestParam(value = "status", required = false) Integer status) {
PageInfoModel<DeviceVo> records = deviceService.getDeviceList(pageNo, pageSize, appName, userName, status);
PageInfoModel<DeviceVo> records = deviceService.getDeviceList(pageNo, pageSize, appName, userName, sn, status);
int total = records.getTotal();
int pages = total / pageSize;//pages为总页数
int mod = total % pageSize;
......
......@@ -17,7 +17,7 @@ import javax.servlet.http.HttpServletResponse;
@RestController
@RequestMapping("/resource")
@RequestMapping("/iot_license/resource")
@Api(value = "资源模块", tags = {"资源模块"})
public class ResourceContrller {
......
......@@ -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);
}
}
......@@ -51,7 +51,7 @@ public class DeviceManager {
public void initDevices() {
allDevice = new HashMap<>();
PageInfoModel<DeviceVo> records = deviceService.getDeviceList(1, 10000, "", "", null);
PageInfoModel<DeviceVo> records = deviceService.getDeviceList(1, 10000, "", "", null, null);
List<DeviceVo> deviceList = records.getResult();
for (DeviceVo deviceVo : deviceList) {
......@@ -149,7 +149,7 @@ public class DeviceManager {
}
public PageInfoModel<DeviceDetailVo> getDeviceDetailList(int pageNo, int pageSize, String appName, String userName) {
PageInfoModel<DeviceVo> records = deviceService.getDeviceList(pageNo, pageSize, appName, userName, null);
PageInfoModel<DeviceVo> records = deviceService.getDeviceList(pageNo, pageSize, appName, userName, null, null);
List<DeviceVo> deviceVos = records.getResult();
PageInfoModel<DeviceDetailVo> detailVoPageInfoModel = new PageInfoModel<>();
List<DeviceDetailVo> detailVos = new ArrayList<>();
......
......@@ -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();
......
......@@ -13,7 +13,7 @@ import java.util.List;
* @since 2022-06-08
*/
public interface DeviceMapper extends BaseMapper<Device> {
List<DeviceVo> getDeviceList(String appName, String userName, Integer status);
List<DeviceVo> getDeviceList(String appName, String userName, String sn, Integer status);
boolean addDevice(String sn, String appId);
}
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;
/**
......@@ -12,7 +13,9 @@ import iot.sixiang.license.model.vo.DeviceVo;
* @since 2022-06-08
*/
public interface DeviceService extends IService<Device> {
PageInfoModel<DeviceVo> getDeviceList(int pageNo, int pageSize, String appName, String userName, Integer status);
PageInfoModel<DeviceVo> getDeviceList(int pageNo, int pageSize, String appName, String userName, String sn, 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.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;
......@@ -32,11 +35,11 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, Device> impleme
private DeviceMapper deviceMapper;
@Override
public PageInfoModel<DeviceVo> getDeviceList(int pageNo, int pageSize, String appName, String userName, Integer status) {
public PageInfoModel<DeviceVo> getDeviceList(int pageNo, int pageSize, String appName, String userName, String sn, Integer status) {
if (pageNo == 0 || pageSize == 0) {
throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(), ResultCode.VALIDATE_FAILED.getMsg());
}
List<DeviceVo> deviceTypes = deviceMapper.getDeviceList(appName, userName, status);
List<DeviceVo> deviceTypes = deviceMapper.getDeviceList(appName, userName, sn, status);
deviceTypes = deviceTypes.stream().sorted(Comparator.comparing(DeviceVo::getCreateTime, Comparator.reverseOrder())).collect(Collectors.toList());
List<DeviceVo> result = new ArrayList<>();
int begin = (pageNo - 1) * pageSize;
......@@ -65,4 +68,32 @@ 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) {
if (!StringUtils.isEmpty(device.getSnBind())) {
if (device.getSnBind().equals(snBind)) {
return true;
} else {
throw new IotLicenseException(403, "sn已被绑定");
}
}
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();
}
}
}
......@@ -14,6 +14,9 @@
<if test="null != userName and '' != userName">
and user_name like concat('%',#{userName},'%')
</if>
<if test="null != sn and '' != sn">
and sn like concat('%',#{sn},'%')
</if>
<if test="null != status">
and status = #{status}
</if>
......
......@@ -5,7 +5,7 @@
SELECT * FROM pms_use_log
where 1=1
<if test="null != sn and '' != sn">
and sn = #{sn}
and sn like concat('%',#{sn},'%')
</if>
<if test="null != status">
and status = #{status}
......
......@@ -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