Commit ff60f483 authored by ma's avatar ma

撤销merge

parent 971d4435
# -------------------- 平台应用相关,以pms开头 --------------------
DROP TABLE IF EXISTS `pms_use_log`;
CREATE TABLE `pms_use_log`
(
`id` int(10) NOT NULL AUTO_INCREMENT,
`sn` varchar(30) DEFAULT NULL COMMENT '设备编号',
`status` int(1) DEFAULT '1' COMMENT '状态 1:成功,0:失败',
`error_code` varchar(10) DEFAULT NULL COMMENT '如果失败,则这是失败的代号',
`message` varchar(200) DEFAULT NULL COMMENT '如果失败,则这里是失败的信息',
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
`deleted` int(1) DEFAULT '0' COMMENT '逻辑删除标识 1:删除,0:未删除',
PRIMARY KEY (`id`)
) ENGINE = InnoDB
AUTO_INCREMENT = 0
DEFAULT CHARSET = utf8 COMMENT ='使用记录表';
ALTER TABLE `device`
ADD COLUMN `status` int(1) NULL DEFAULT NULL COMMENT '状态 0:未使用,1:已使用,2:失效' AFTER `app_id`;
ALTER TABLE `device`
ADD COLUMN `sn_bind` varchar(30) NULL DEFAULT NULL COMMENT '绑定的SN' AFTER `status`;
\ No newline at end of file
package iot.sixiang.license.controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import iot.sixiang.license.entity.PmsUseLog;
import iot.sixiang.license.entity.SysOperLog;
import iot.sixiang.license.log.BusinessType;
import iot.sixiang.license.log.MyLog;
import iot.sixiang.license.model.PageInfoModel;
import iot.sixiang.license.model.PageResult;
import iot.sixiang.license.model.vo.DeviceVo;
import iot.sixiang.license.service.PmsUseService;
import iot.sixiang.license.service.SysOperLogService;
import lombok.extern.slf4j.Slf4j;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
import java.util.List;
@Slf4j
@RestController
@RequestMapping("/iot_license/pms_use_log")
@Api(value = "使用记录模块", tags = {"使用记录模块"})
public class PmsUseLogController {
@Autowired
private PmsUseService pmsUseService;
/**
* 分页查询使用记录
*
* @param pageNo
* @param pageSize
* @return
*/
@ApiOperation(value = "获取使用记录列表接口", notes = "用于获取使用记录列表")
@GetMapping("list")
@MyLog(title = "获取使用记录列表", optParam = "#{pageNo},#{pageSize},#{sn},#{status}", businessType = BusinessType.SELECT)
@ApiImplicitParams({
@ApiImplicitParam(name = "pageNo", value = "当前在第几页", required = true, dataType = "int"),
@ApiImplicitParam(name = "pageSize", value = "每页显示多少条", required = true, dataType = "int"),
@ApiImplicitParam(name = "sn", value = "设备编号"),
@ApiImplicitParam(name = "status", value = "状态 1:成功,0:失败", dataType = "int")
})
public PageResult<PmsUseLog> getPmsUseLogList(@RequestParam(value = "pageNo", defaultValue = "0") int pageNo,
@RequestParam(value = "pageSize", defaultValue = "0") int pageSize,
@RequestParam(value = "sn", required = false) String sn,
@RequestParam(value = "status", required = false) Integer status) {
PageInfoModel<PmsUseLog> records = pmsUseService.getPmsUseLogList(pageNo, pageSize, sn, status);
int total = records.getTotal();
int pages = total / pageSize;//pages为总页数
int mod = total % pageSize;
if (mod != 0) {
pages = pages + 1;
}
List<PmsUseLog> result = records.getResult();
return new PageResult(200, "查找成功", pageNo, pages, total, result);
}
}
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.model.dto.TerminalDevieUnBindDTO;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("/iot_license/terminal_device")
@Api(value = "终端设备模块", tags = {"终端设备模块"})
public class TerminalDeviceController {
@Autowired
TerminalDeviceService terminalDeviceService;
@GetMapping("/get_token")
@ApiOperation(value = "终端设备获取token", notes = "终端设备获取token")
public ResResult getToken(GetTerminalDeviceTokenDTO getTerminalDeviceTokenDTO) {
return terminalDeviceService.getToken(getTerminalDeviceTokenDTO);
}
@PostMapping("/report_error_msg")
@ApiOperation(value = "终端设备上报错误信息", notes = "终端设备上报错误信息")
public BaseResult reportErrorMsg(@RequestBody List<ReportErrorMsgDTO> reportErrorMsgDTO) {
return terminalDeviceService.reportErrorMsg(reportErrorMsgDTO);
}
@PostMapping("/bind")
@ApiOperation(value = "终端设备绑定接口", notes = "终端设备绑定接口")
public BaseResult terminalDevieBind(@RequestBody TerminalDevieBindDTO terminalDevieBindDTO) {
return terminalDeviceService.terminalDeviceBind(terminalDevieBindDTO);
}
@PostMapping("/unbind")
@ApiOperation(value = "终端设备解绑接口", notes = "终端设备解绑接口")
public BaseResult terminalDevieunBind(@RequestBody TerminalDevieUnBindDTO terminalDevieUnBindDTO) {
return terminalDeviceService.terminalDeviceunBind(terminalDevieUnBindDTO);
}
@GetMapping("/get_bind_status")
@ApiOperation(value = "获取终端设备绑定状态接口", notes = "获取终端设备绑定状态接口")
public ResResult getBindStatus(TerminalDevieUnBindDTO terminalDevieUnBindDTO) {
return terminalDeviceService.getBindStatus(terminalDevieUnBindDTO);
}
}
package iot.sixiang.license.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* Created by M=54G
* Date 11/23/22 3:12 PM
* Description
*/
@Data
public class PmsUseLog {
@ApiModelProperty("记录标识")
@TableId(type = IdType.AUTO)
private Integer id;
@ApiModelProperty("设备编号")
private String sn;
@ApiModelProperty("状态 1:成功,0:失败")
private Integer status;
@ApiModelProperty("如果失败,则这是失败的代号")
private String errorCode;
@ApiModelProperty("如果失败,则这里是失败的信息")
private String message;
@ApiModelProperty("创建时间")
private Date createTime;
@ApiModelProperty("更新时间")
private Date updateTime;
@ApiModelProperty("逻辑删除标识 1:删除,0:未删除")
private Integer deleted;
}
package iot.sixiang.license.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import iot.sixiang.license.entity.PmsUseLog;
import iot.sixiang.license.model.vo.DeviceVo;
import java.util.List;
/**
* Created by M=54G
* Date 11/23/22 3:12 PM
* Description
*/
public interface PmsUseLogMapper extends BaseMapper<PmsUseLog> {
List<PmsUseLog> getPmsUseLogList(String sn, Integer status);
}
package iot.sixiang.license.model.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class GetTerminalDeviceTokenDTO {
@ApiModelProperty("应用id")
private String appId;
@ApiModelProperty("设备编号")
private String sn;
@ApiModelProperty("签名")
private String sign;
}
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;
}
package iot.sixiang.license.model.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class TerminalDevieUnBindDTO {
@ApiModelProperty("设备SN")
private String snBind;
}
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
* Date 11/23/22 3:09 PM
* Description
*/
public interface PmsUseService {
int createUseLog(String sn);
void createFailUseLog(String sn, String message);
void success(int useLogId);
PageInfoModel<PmsUseLog> getPmsUseLogList(int pageNo, int pageSize, String sn, Integer status);
boolean reportErrorMsg(ReportErrorMsgDTO reportErrorMsgDTO);
boolean deletePmsUseLogById(Integer id);
}
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 java.util.List;
public interface TerminalDeviceService {
ResResult getToken(GetTerminalDeviceTokenDTO getTerminalDeviceTokenDTO);
BaseResult reportErrorMsg(List<ReportErrorMsgDTO> reportErrorMsgDTO);
BaseResult terminalDeviceBind(TerminalDevieBindDTO terminalDevieBindDTO);
BaseResult terminalDeviceunBind(TerminalDevieUnBindDTO terminalDevieUnBindDTO);
ResResult getBindStatus(TerminalDevieUnBindDTO terminalDevieUnBindDTO);
}
package iot.sixiang.license.service.impl;
import iot.sixiang.license.consts.ResultCode;
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.dto.ReportErrorMsgDTO;
import iot.sixiang.license.service.PmsUseService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/**
* Created by M=54G
* Date 11/23/22 3:10 PM
* Description
*/
@Service
public class PmsUseServiceImpl implements PmsUseService {
@Resource
private PmsUseLogMapper pmsUseLogMapper;
@Override
public int createUseLog(String sn) {
PmsUseLog pmsUseLog = getPmsUseLog(sn);
pmsUseLogMapper.insert(pmsUseLog);
return pmsUseLog.getId();
}
@Override
public void createFailUseLog(String sn, String message) {
PmsUseLog pmsUseLog = getPmsUseLog(sn);
pmsUseLog.setStatus(0);
pmsUseLog.setMessage(message);
pmsUseLogMapper.insert(pmsUseLog);
}
@Override
public void success(int useLogId) {
PmsUseLog pmsUseLog = new PmsUseLog();
pmsUseLog.setId(useLogId);
pmsUseLog.setStatus(1);
pmsUseLogMapper.updateById(pmsUseLog);
}
@Override
public PageInfoModel<PmsUseLog> getPmsUseLogList(int pageNo, int pageSize, String sn, Integer status) {
if (pageNo == 0 || pageSize == 0) {
throw new IotLicenseException(ResultCode.VALIDATE_FAILED.getCode(), ResultCode.VALIDATE_FAILED.getMsg());
}
List<PmsUseLog> pmsUseLogs = pmsUseLogMapper.getPmsUseLogList(sn, status);
List<PmsUseLog> result = new ArrayList<>();
int begin = (pageNo - 1) * pageSize;
if (begin >= 0 && pmsUseLogs.size() > 0) {
result = pmsUseLogs.stream().skip(begin).limit(pageSize).collect(Collectors.toList());
}
PageInfoModel<PmsUseLog> pmsUseLogPageInfoModel = new PageInfoModel<>();
pmsUseLogPageInfoModel.setTotal(pmsUseLogs.size());
pmsUseLogPageInfoModel.setResult(result);
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);
return res > 0;
}
@Override
public boolean deletePmsUseLogById(Integer id) {
PmsUseLog pmsUseLog = new PmsUseLog();
pmsUseLog.setId(id);
pmsUseLog.setStatus(0);
pmsUseLog.setUpdateTime(new Date());
pmsUseLog.setDeleted(1);
int res = pmsUseLogMapper.updateById(pmsUseLog);
return res > 0;
}
private PmsUseLog getPmsUseLog(String sn) {
PmsUseLog pmsUseLog = new PmsUseLog();
Date date = new Date();
pmsUseLog.setCreateTime(date);
pmsUseLog.setUpdateTime(date);
pmsUseLog.setSn(sn);
return pmsUseLog;
}
}
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.model.dto.TerminalDevieUnBindDTO;
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;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Comparator;
import java.util.List;
@Slf4j
@Service
public class TerminalDeviceServiceImpl implements TerminalDeviceService {
@Autowired
private AuthManager authManager;
@Autowired
private DeviceService deviceService;
@Autowired
private PmsUseService pmsUseService;
@Resource
private DeviceManager deviceManager;
@Override
public ResResult getToken(GetTerminalDeviceTokenDTO getTerminalDeviceTokenDTO) {
String appId = getTerminalDeviceTokenDTO.getAppId();
String sn = getTerminalDeviceTokenDTO.getSn();
String sign = getTerminalDeviceTokenDTO.getSign();
if (StringUtils.isEmpty(appId)) {
throw new IotLicenseException(403, "应用id不能为空");
}
if (StringUtils.isEmpty(sn)) {
throw new IotLicenseException(403, "终端编号不能为空");
}
if (StringUtils.isEmpty(sign)) {
throw new IotLicenseException(403, "签名不能为空");
}
boolean authResult = authManager.authTerminalDevice(appId, sn, sign);
if (authResult) {
LoginUser user = new LoginUser();
user.setUserId(appId);
user.setUserName(sn);
String token = JwtUtil.createToken(user);
return ResResult.success().record(token);
} else {
return ResResult.validate_failed();
}
}
@Override
public BaseResult reportErrorMsg(List<ReportErrorMsgDTO> reportErrorMsgDTOs) {
if (reportErrorMsgDTOs == null || reportErrorMsgDTOs.size() == 0) {
return BaseResult.validate_failed();
}
reportErrorMsgDTOs.sort(Comparator.comparingInt(ReportErrorMsgDTO::getId));
for (int i = 0; i < reportErrorMsgDTOs.size() - 1; i++) {
ReportErrorMsgDTO reportErrorMsgDTO = reportErrorMsgDTOs.get(i);
Integer id = reportErrorMsgDTO.getId();
if (id == null || id == 0) {
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())) {
pmsUseService.success(reportErrorMsgDTO.getId());
return BaseResult.success();
} else {
boolean res = pmsUseService.reportErrorMsg(reportErrorMsgDTO);
if (res) {
return BaseResult.success();
} else {
return BaseResult.failed();
}
}
}
}
@Override
public BaseResult terminalDeviceBind(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) {
deviceManager.initDevices();
return BaseResult.success();
} else {
return BaseResult.failed();
}
}
@Override
public BaseResult terminalDeviceunBind(TerminalDevieUnBindDTO terminalDevieUnBindDTO) {
String snBind = terminalDevieUnBindDTO.getSnBind();
if (StringUtils.isEmpty(snBind)) {
return BaseResult.validate_failed();
}
Boolean res = deviceService.terminalDevieunBind(terminalDevieUnBindDTO);
if (res) {
deviceManager.initDevices();
return BaseResult.success();
} else {
return BaseResult.failed();
}
}
@Override
public ResResult getBindStatus(TerminalDevieUnBindDTO terminalDevieUnBindDTO) {
String snBind = terminalDevieUnBindDTO.getSnBind();
if (StringUtils.isEmpty(snBind)) {
return ResResult.validate_failed();
}
return deviceService.getBindStatus(terminalDevieUnBindDTO);
}
}
server:
port: 8868
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://8.134.112.146:3306/iot_license?serverTimezone=GMT%2B8
username: root
password: 1808030428mzh
main:
allow-bean-definition-overriding: true
mybatis-plus:
mapper-locations: classpath:/mapper/**.xml
type-aliases-package: iot.sixiang.license.entity
knife4j:
enable: true
logging:
level:
root: info
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="iot.sixiang.license.mapper.PmsUseLogMapper">
<select id="getPmsUseLogList" resultType="iot.sixiang.license.entity.PmsUseLog">
SELECT * FROM pms_use_log
where 1=1
<if test="null != sn and '' != sn">
and sn like concat('%',#{sn},'%')
</if>
<if test="null != status">
and status = #{status}
</if>
and deleted = 0
order by create_time desc
</select>
</mapper>
\ No newline at end of file
package iot.sixiang.license;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
/**
* Created by M=54G
* Date 9/14/22 3:08 PM
* Description
*/
@SpringBootTest
@ActiveProfiles({"test-acc"})
@Slf4j
public class BaseTest {
protected void log(Object object) {
log.info(JSON.toJSONString(object));
}
}
\ No newline at end of file
package iot.sixiang.license.service;
import iot.sixiang.license.BaseTest;
import org.junit.jupiter.api.Test;
import javax.annotation.Resource;
/**
* Created by M=54G
* Date 11/23/22 3:39 PM
* Description
*/
public class PmsUseServiceTest extends BaseTest {
@Resource
private PmsUseService pmsUseService;
@Test
void addLog() {
log(pmsUseService.createUseLog("abcd"));
}
@Test
void updateLog() {
pmsUseService.success(1);
}
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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