Commit 0f54fe57 authored by AfirSraftGarrier's avatar AfirSraftGarrier

增加设备使用记录

parent 4c6a24a7
......@@ -3,7 +3,7 @@ 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 '业务流程唯一标识',
`sn` varchar(30) DEFAULT NULL COMMENT '设备编号',
`status` int(1) DEFAULT '0' COMMENT '状态 1:成功,0:失败',
`error_code` varchar(10) DEFAULT NULL COMMENT '如果失败,则这是失败的代号',
`message` varchar(200) DEFAULT NULL COMMENT '如果失败,则这里是失败的信息',
......@@ -15,6 +15,8 @@ CREATE TABLE `pms_use_log`
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 `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
ALTER TABLE `device`
ADD COLUMN `sn_bind` varchar(30) NULL DEFAULT NULL COMMENT '绑定的SN' AFTER `status`;
\ No newline at end of file
......@@ -128,6 +128,9 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
log.info("设备鉴权信息和结果,{},{},{},{} ", appId, sn, sign, license);
String channelId = channel.id().asLongText();
if (license) {
// 创建一条使用记录
SessionContext session = new SessionContext();
session.setRemoteIp(remoteIp);
session.setRemotePort(remotePort);
......
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.time.LocalDate;
import java.util.Date;
/**
* Created by M=54G
* Date 11/23/22 3:12 PM
* Description
*/
@Data
public class PmsUseLog {
@ApiModelProperty("记录标识")
@TableId(value = "id", 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.Monitor;
import iot.sixiang.license.entity.PmsUseLog;
/**
* Created by M=54G
* Date 11/23/22 3:12 PM
* Description
*/
public interface PmsUseLogMapper extends BaseMapper<PmsUseLog> {
}
package iot.sixiang.license.service;
/**
* Created by M=54G
* Date 11/23/22 3:09 PM
* Description
*/
public interface PmsUseService {
int createUseLog(String sn);
}
package iot.sixiang.license.service.impl;
import iot.sixiang.license.entity.PmsUseLog;
import iot.sixiang.license.mapper.PmsUseLogMapper;
import iot.sixiang.license.service.PmsUseService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Date;
/**
* 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 = new PmsUseLog();
Date date = new Date();
pmsUseLog.setCreateTime(date);
pmsUseLog.setUpdateTime(date);
pmsUseLog.setSn(sn);
return pmsUseLogMapper.insert(pmsUseLog);
}
}
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"));
}
}
\ No newline at end of file
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