Commit 2a9f05b3 authored by AfirSraftGarrier's avatar AfirSraftGarrier

增加设备使用记录

parent 8c4d1044
...@@ -13,7 +13,11 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -13,7 +13,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import java.util.*; import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@Component @Component
...@@ -71,12 +75,12 @@ public class DeviceManager { ...@@ -71,12 +75,12 @@ public class DeviceManager {
return allDevice; return allDevice;
} }
public synchronized void putSession(String appId, SessionContext session) { public synchronized void putSession(String sn, SessionContext session) {
sessionContexts.put(appId, session); sessionContexts.put(sn, session);
} }
public SessionContext getSessionContextByAppId(String appId) { public SessionContext getSessionContextBySN(String sn) {
return sessionContexts.get(appId); return sessionContexts.get(sn);
} }
public SessionContext getSessionByChannelId(String channelId) { public SessionContext getSessionByChannelId(String channelId) {
......
...@@ -151,12 +151,14 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> { ...@@ -151,12 +151,14 @@ public class DeviceServerHandler extends SimpleChannelInboundHandler<Object> {
session.setOnline(CommonUtil.getSystemTime()); session.setOnline(CommonUtil.getSystemTime());
DeviceManager deviceManager = SpringUtil.getBean(DeviceManager.class); DeviceManager deviceManager = SpringUtil.getBean(DeviceManager.class);
deviceManager.putSession(appId, session); deviceManager.putSession(sn, session);
// 创建透传的客户端 // 创建透传的客户端
CreateForwardClientEvent event = new CreateForwardClientEvent(); CreateForwardClientEvent event = new CreateForwardClientEvent();
event.setAppId(appId); event.setSn(sn);
eventPublisher.publishEvent(event); eventPublisher.publishEvent(event);
} else {
pmsUseService.createFailUseLog(sn, "鉴权失败");
} }
return license; return license;
} }
......
...@@ -5,5 +5,5 @@ import lombok.Data; ...@@ -5,5 +5,5 @@ import lombok.Data;
@Data @Data
public class CreateForwardClientEvent extends BaseEvent { public class CreateForwardClientEvent extends BaseEvent {
private String appId; private String sn;
} }
...@@ -24,14 +24,14 @@ public class CreateForwardClientEventHandler { ...@@ -24,14 +24,14 @@ public class CreateForwardClientEventHandler {
@EventListener @EventListener
public void handlerEvent(CreateForwardClientEvent event) { public void handlerEvent(CreateForwardClientEvent event) {
String appId = event.getAppId(); String sn = event.getSn();
Server balanceServer = balanceManager.getBalanceServer(); Server balanceServer = balanceManager.getBalanceServer();
if (balanceServer != null) { if (balanceServer != null) {
String serverIp = balanceServer.getServerIp(); String serverIp = balanceServer.getServerIp();
Integer port = balanceServer.getPort(); Integer port = balanceServer.getPort();
forwardManager.startTcpClient(serverIp, port, appId); forwardManager.startTcpClient(serverIp, port, sn);
} else { } else {
log.error("balanceServer is null"); log.error("balanceServer is null...");
} }
} }
} }
...@@ -4,7 +4,6 @@ import lombok.Data; ...@@ -4,7 +4,6 @@ import lombok.Data;
@Data @Data
public class DeviceClientBeForcedOfflineEvent extends BaseEvent { public class DeviceClientBeForcedOfflineEvent extends BaseEvent {
private String appId; private String sn;
} }
...@@ -20,17 +20,17 @@ public class DeviceClientBeForcedOfflineEventHandler { ...@@ -20,17 +20,17 @@ public class DeviceClientBeForcedOfflineEventHandler {
@EventListener @EventListener
public void handlerEvent(DeviceClientBeForcedOfflineEvent event) { public void handlerEvent(DeviceClientBeForcedOfflineEvent event) {
String appId = event.getAppId(); String sn = event.getSn();
SessionContext deviceSessionContext = deviceManager.getSessionContextByAppId(appId); SessionContext deviceSessionContext = deviceManager.getSessionContextBySN(sn);
if (deviceSessionContext != null) { if (deviceSessionContext != null) {
SocketChannel deviceClientChannel = deviceSessionContext.getClientChannel(); SocketChannel deviceClientChannel = deviceSessionContext.getClientChannel();
if (deviceClientChannel != null) { if (deviceClientChannel != null) {
deviceClientChannel.close(); deviceClientChannel.close();
log.debug("device client be forced offline success ..." + appId); log.debug("device client be forced offline success ..." + sn);
} }
} else { } else {
log.debug("device client be forced offline undo ..." + appId); log.debug("device client be forced offline undo ..." + sn);
} }
} }
......
...@@ -34,7 +34,7 @@ public class DeviceClientInactiveEventHandler { ...@@ -34,7 +34,7 @@ public class DeviceClientInactiveEventHandler {
if (result) { if (result) {
// TODO device client 离线需要强制中断该设备对应的forward client // TODO device client 离线需要强制中断该设备对应的forward client
ForwardClientBeForcedOfflineEvent forwardClientBeForcedOfflineEvent = new ForwardClientBeForcedOfflineEvent(); ForwardClientBeForcedOfflineEvent forwardClientBeForcedOfflineEvent = new ForwardClientBeForcedOfflineEvent();
forwardClientBeForcedOfflineEvent.setAppId(appId); forwardClientBeForcedOfflineEvent.setSn(appId);
eventPublisher.publishEvent(forwardClientBeForcedOfflineEvent); eventPublisher.publishEvent(forwardClientBeForcedOfflineEvent);
log.debug("device client inactive success ..."); log.debug("device client inactive success ...");
} }
......
...@@ -5,6 +5,6 @@ import lombok.Data; ...@@ -5,6 +5,6 @@ import lombok.Data;
@Data @Data
public class DeviceClientLicenseEvent extends BaseEvent { public class DeviceClientLicenseEvent extends BaseEvent {
private String appId; private String sn;
private DeviceProtocol protocol; private DeviceProtocol protocol;
} }
...@@ -22,10 +22,10 @@ public class DeviceClientLicenseEventHandler { ...@@ -22,10 +22,10 @@ public class DeviceClientLicenseEventHandler {
@EventListener @EventListener
public void handlerEvent(DeviceClientLicenseEvent event) { public void handlerEvent(DeviceClientLicenseEvent event) {
String appId = event.getAppId(); String appId = event.getSn();
DeviceProtocol protocol = event.getProtocol(); DeviceProtocol protocol = event.getProtocol();
SessionContext session = deviceManager.getSessionContextByAppId(appId); 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;
......
...@@ -4,6 +4,6 @@ import lombok.Data; ...@@ -4,6 +4,6 @@ import lombok.Data;
@Data @Data
public class ForwardClientBeForcedOfflineEvent extends BaseEvent { public class ForwardClientBeForcedOfflineEvent extends BaseEvent {
private String appId; private String sn;
} }
...@@ -11,7 +11,6 @@ import org.springframework.stereotype.Component; ...@@ -11,7 +11,6 @@ import org.springframework.stereotype.Component;
@Component @Component
@Slf4j @Slf4j
public class ForwardClientBeForcedOfflineEventHandler { public class ForwardClientBeForcedOfflineEventHandler {
@Autowired @Autowired
ForwardManager forwardManager; ForwardManager forwardManager;
...@@ -22,18 +21,16 @@ public class ForwardClientBeForcedOfflineEventHandler { ...@@ -22,18 +21,16 @@ public class ForwardClientBeForcedOfflineEventHandler {
@EventListener @EventListener
public void handlerEvent(ForwardClientBeForcedOfflineEvent event) { public void handlerEvent(ForwardClientBeForcedOfflineEvent event) {
String appId = event.getAppId(); String sn = event.getSn();
SessionContext forwardSessionContext = forwardManager.getSessionContextByAppId(appId); SessionContext forwardSessionContext = forwardManager.getSessionContextBySN(sn);
if (forwardSessionContext != null) { if (forwardSessionContext != null) {
SocketChannel forwardClientChannel = forwardSessionContext.getClientChannel(); SocketChannel forwardClientChannel = forwardSessionContext.getClientChannel();
if (forwardClientChannel != null) { if (forwardClientChannel != null) {
forwardClientChannel.close(); forwardClientChannel.close();
log.debug("forward client be forced offline success ..." + appId); log.debug("forward client be forced offline success ..." + sn);
} }
} else { } else {
log.debug("forward client be forced offline undo ..." + appId); log.debug("forward client be forced offline undo ..." + sn);
} }
} }
} }
...@@ -5,9 +5,8 @@ import lombok.Data; ...@@ -5,9 +5,8 @@ import lombok.Data;
@Data @Data
public class ForwardClientConnectEvent extends BaseEvent { public class ForwardClientConnectEvent extends BaseEvent {
private String appId; private String sn;
private String channelId; private String channelId;
private SocketChannel channel; private SocketChannel channel;
} }
...@@ -16,25 +16,22 @@ public class ForwardClientConnectEventHandler { ...@@ -16,25 +16,22 @@ public class ForwardClientConnectEventHandler {
@Autowired @Autowired
EventPublisher eventPublisher; EventPublisher eventPublisher;
public ForwardClientConnectEventHandler() { public ForwardClientConnectEventHandler() {
} }
@EventListener @EventListener
public void handlerEvent(ForwardClientConnectEvent event) { public void handlerEvent(ForwardClientConnectEvent event) {
String appId = event.getSn();
String appId = event.getAppId();
String channelId = event.getChannelId(); String channelId = event.getChannelId();
SocketChannel channel = event.getChannel(); SocketChannel channel = event.getChannel();
SessionContext session = new SessionContext(); SessionContext session = new SessionContext();
// session.setRemoteIp(remoteIp); // session.setRemoteIp(remoteIp);
// session.setRemotePort(remotePort); // session.setRemotePort(remotePort);
session.setAppId(appId); session.setAppId(appId);
// session.setAppKey(appKey); // session.setAppKey(appKey);
// session.setToken(token); // session.setToken(token);
session.setChannelId(channelId); session.setChannelId(channelId);
session.setClientChannel(channel); session.setClientChannel(channel);
...@@ -42,9 +39,5 @@ public class ForwardClientConnectEventHandler { ...@@ -42,9 +39,5 @@ public class ForwardClientConnectEventHandler {
forwardManager.putSession(appId, session); forwardManager.putSession(appId, session);
log.debug("forward client connect:" + event); log.debug("forward client connect:" + event);
} }
} }
...@@ -30,12 +30,12 @@ public class ForwardClientInactiveEventHandler { ...@@ -30,12 +30,12 @@ public class ForwardClientInactiveEventHandler {
log.debug("forward client inactive undo ..."); log.debug("forward client inactive undo ...");
return; return;
} else { } else {
String appId = session.getAppId(); String sn = session.getSn();
boolean result = forwardManager.removeSessionByChannelId(channelId); boolean result = forwardManager.removeSessionByChannelId(channelId);
if (result) { if (result) {
// forward client 离线需要强制中断该设备对应的 device client // forward client 离线需要强制中断该设备对应的 device client
DeviceClientBeForcedOfflineEvent deviceClientBeForcedOfflineEvent = new DeviceClientBeForcedOfflineEvent(); DeviceClientBeForcedOfflineEvent deviceClientBeForcedOfflineEvent = new DeviceClientBeForcedOfflineEvent();
deviceClientBeForcedOfflineEvent.setAppId(appId); deviceClientBeForcedOfflineEvent.setSn(sn);
eventPublisher.publishEvent(deviceClientBeForcedOfflineEvent); eventPublisher.publishEvent(deviceClientBeForcedOfflineEvent);
log.debug("forward client inactive success ..."); log.debug("forward client inactive success ...");
} }
......
...@@ -33,7 +33,7 @@ public class ForwardClientRequestEventHandler { ...@@ -33,7 +33,7 @@ public class ForwardClientRequestEventHandler {
SessionContext deviceSessionContext = deviceManager.getSessionByChannelId(deviceChannelId); SessionContext deviceSessionContext = deviceManager.getSessionByChannelId(deviceChannelId);
String appId = deviceSessionContext.getAppId(); String appId = deviceSessionContext.getAppId();
SessionContext forwardSessionContext = forwardManager.getSessionContextByAppId(appId); SessionContext forwardSessionContext = forwardManager.getSessionContextBySN(appId);
log.debug("forward client request:" + appId + "," + forwardSessionContext); log.debug("forward client request:" + appId + "," + forwardSessionContext);
SocketChannel clientChannel = forwardSessionContext.getClientChannel(); SocketChannel clientChannel = forwardSessionContext.getClientChannel();
clientChannel.writeAndFlush(protocol); clientChannel.writeAndFlush(protocol);
......
...@@ -22,29 +22,24 @@ public class ForwardMessageResponseEventHandler { ...@@ -22,29 +22,24 @@ public class ForwardMessageResponseEventHandler {
public ForwardMessageResponseEventHandler() { public ForwardMessageResponseEventHandler() {
} }
@EventListener @EventListener
public void handlerEvent(ForwardMessageResponseEvent event) { public void handlerEvent(ForwardMessageResponseEvent event) {
String channelId = event.getChannelId(); String channelId = event.getChannelId();
SocketChannel channel = event.getChannel(); //SocketChannel channel = event.getChannel();
DeviceProtocol protocol = event.getProtocol(); DeviceProtocol protocol = event.getProtocol();
SessionContext forwardSessionContext = forwardManager.getSessionByChannelId(channelId); SessionContext forwardSessionContext = forwardManager.getSessionByChannelId(channelId);
String appId = forwardSessionContext.getAppId(); String appId = forwardSessionContext.getAppId();
SessionContext deviceSessionContext = deviceManager.getSessionContextByAppId(appId); SessionContext deviceSessionContext = deviceManager.getSessionContextBySN(appId);
if (deviceSessionContext != null) { if (deviceSessionContext != null) {
SocketChannel deviceClientChannel = deviceSessionContext.getClientChannel(); SocketChannel deviceClientChannel = deviceSessionContext.getClientChannel();
log.debug("forward client response..." + appId + ",forward session:" + deviceSessionContext); log.info("forward client response..." + appId + ",forward session:" + deviceSessionContext);
deviceClientChannel.writeAndFlush(protocol); deviceClientChannel.writeAndFlush(protocol);
} else { } else {
log.debug("forward client response undo ..." + appId); log.info("forward client response undo ..." + appId);
} }
} }
} }
package iot.sixiang.license.forward; package iot.sixiang.license.forward;
import iot.sixiang.license.device.DeviceManager;
import iot.sixiang.license.net.TcpClient; import iot.sixiang.license.net.TcpClient;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@Component @Component
@Slf4j @Slf4j
public class ForwardClient { public class ForwardClient {
...@@ -13,16 +16,19 @@ public class ForwardClient { ...@@ -13,16 +16,19 @@ public class ForwardClient {
@Autowired @Autowired
ForwardClientHandler handler; ForwardClientHandler handler;
@Resource
private DeviceManager deviceManager;
public ForwardClient() { public ForwardClient() {
} }
public void startTcp(String host, int port, String appId) { public void startTcp(String host, int port, String sn) {
log.debug("桥接客户端,开始连接桥接服务:{},{},{}", host, port, appId); log.debug("桥接客户端,开始连接桥接服务:{},{},{}", host, port, sn);
ForwardConnectionListener listener = new ForwardConnectionListener(); ForwardConnectionListener listener = new ForwardConnectionListener();
listener.setAppId(appId); listener.setSn(sn);
listener.setHost(host); listener.setHost(host);
listener.setPort(port); listener.setPort(port);
listener.setDeviceManager(this.deviceManager);
channelInitializer = new ForwardChannelInitializer(handler); channelInitializer = new ForwardChannelInitializer(handler);
client = new TcpClient(host, port, channelInitializer, listener); client = new TcpClient(host, port, channelInitializer, listener);
......
...@@ -2,11 +2,13 @@ package iot.sixiang.license.forward; ...@@ -2,11 +2,13 @@ package iot.sixiang.license.forward;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.SocketChannel;
import iot.sixiang.license.device.DeviceManager;
import iot.sixiang.license.device.DeviceProtocol; import iot.sixiang.license.device.DeviceProtocol;
import iot.sixiang.license.event.DeviceClientBeForcedOfflineEvent; import iot.sixiang.license.event.DeviceClientBeForcedOfflineEvent;
import iot.sixiang.license.event.DeviceClientLicenseEvent; import iot.sixiang.license.event.DeviceClientLicenseEvent;
import iot.sixiang.license.event.EventPublisher; import iot.sixiang.license.event.EventPublisher;
import iot.sixiang.license.event.ForwardClientConnectEvent; import iot.sixiang.license.event.ForwardClientConnectEvent;
import iot.sixiang.license.model.SessionContext;
import iot.sixiang.license.net.BaseConnectionListener; import iot.sixiang.license.net.BaseConnectionListener;
import iot.sixiang.license.operate.OperateManager; import iot.sixiang.license.operate.OperateManager;
import iot.sixiang.license.service.AlarmService; import iot.sixiang.license.service.AlarmService;
...@@ -15,13 +17,18 @@ import lombok.extern.slf4j.Slf4j; ...@@ -15,13 +17,18 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
public class ForwardConnectionListener extends BaseConnectionListener { public class ForwardConnectionListener extends BaseConnectionListener {
private DeviceManager deviceManager;
public void setDeviceManager(DeviceManager deviceManager) {
this.deviceManager = deviceManager;
}
@Override @Override
public void operationComplete(ChannelFuture channelFuture) { public void operationComplete(ChannelFuture channelFuture) {
AlarmService alarmService = SpringUtil.getBean(AlarmService.class); AlarmService alarmService = SpringUtil.getBean(AlarmService.class);
if (!channelFuture.isSuccess()) { if (!channelFuture.isSuccess()) {
// 失败进行告警 // 失败进行告警
log.debug("桥接客户端,连接服务器失败:{},{},{}", this.host, this.port, this.appId); log.debug("桥接客户端,连接服务器失败:{},{},{}", this.host, this.port, this.sn);
int typeId = 1; int typeId = 1;
String title = "连接服器失败"; String title = "连接服器失败";
...@@ -30,37 +37,43 @@ public class ForwardConnectionListener extends BaseConnectionListener { ...@@ -30,37 +37,43 @@ public class ForwardConnectionListener extends BaseConnectionListener {
// forward client连接失败,则强制踢掉设备客户端 // forward client连接失败,则强制踢掉设备客户端
DeviceClientBeForcedOfflineEvent deviceClientBeForcedOfflineEvent = new DeviceClientBeForcedOfflineEvent(); DeviceClientBeForcedOfflineEvent deviceClientBeForcedOfflineEvent = new DeviceClientBeForcedOfflineEvent();
deviceClientBeForcedOfflineEvent.setAppId(this.appId); deviceClientBeForcedOfflineEvent.setSn(this.sn);
EventPublisher eventPublisher = SpringUtil.getBean(EventPublisher.class); EventPublisher eventPublisher = SpringUtil.getBean(EventPublisher.class);
eventPublisher.publishEvent(deviceClientBeForcedOfflineEvent); eventPublisher.publishEvent(deviceClientBeForcedOfflineEvent);
} else { } else {
log.debug("桥接客户端,连接服务器成功:{},{},{}", this.host, this.port, this.appId); log.debug("桥接客户端,连接服务器成功:{},{},{}", this.host, this.port, this.sn);
OperateManager operateManager = SpringUtil.getBean(OperateManager.class); OperateManager operateManager = SpringUtil.getBean(OperateManager.class);
operateManager.autoIncrement(); operateManager.autoIncrement();
SocketChannel channel = (SocketChannel) channelFuture.channel(); SocketChannel channel = (SocketChannel) channelFuture.channel();
String channelId = channel.id().asLongText(); String channelId = channel.id().asLongText();
ForwardClientConnectEvent forwardClientConnectEvent = new ForwardClientConnectEvent(); ForwardClientConnectEvent forwardClientConnectEvent = new ForwardClientConnectEvent();
forwardClientConnectEvent.setAppId(this.appId); forwardClientConnectEvent.setSn(this.sn);
forwardClientConnectEvent.setChannelId(channelId); forwardClientConnectEvent.setChannelId(channelId);
forwardClientConnectEvent.setChannel(channel); forwardClientConnectEvent.setChannel(channel);
EventPublisher eventPublisher = SpringUtil.getBean(EventPublisher.class); EventPublisher eventPublisher = SpringUtil.getBean(EventPublisher.class);
eventPublisher.publishEvent(forwardClientConnectEvent); eventPublisher.publishEvent(forwardClientConnectEvent);
SessionContext deviceSessionContext = deviceManager.getSessionContextBySN(this.sn);
int useLogId = deviceSessionContext.getUseLogId();
short stx = 21930; short stx = 21930;
byte ack = 0x0; byte ack = 0x0;
int len = 3; int len = 3;
byte cmd = 0x1; byte cmd = 0x1;
byte[] content = new byte[1]; byte[] content = new byte[4];
content[0] = 0x7e; content[0] = 0x7e;
content[1] = (byte) useLogId;
content[2] = (byte) (useLogId >> 8);
content[3] = (byte) (useLogId >> 16);
byte end = 0x1; byte end = 0x1;
DeviceProtocol protocol = new DeviceProtocol(stx, len, cmd, ack, content, end); DeviceProtocol protocol = new DeviceProtocol(stx, len, cmd, ack, content, end);
DeviceClientLicenseEvent deviceClientLicenseEvent = new DeviceClientLicenseEvent(); DeviceClientLicenseEvent deviceClientLicenseEvent = new DeviceClientLicenseEvent();
deviceClientLicenseEvent.setAppId(appId); deviceClientLicenseEvent.setSn(sn);
deviceClientLicenseEvent.setProtocol(protocol); deviceClientLicenseEvent.setProtocol(protocol);
eventPublisher.publishEvent(deviceClientLicenseEvent); eventPublisher.publishEvent(deviceClientLicenseEvent);
......
...@@ -22,20 +22,19 @@ public class ForwardManager { ...@@ -22,20 +22,19 @@ public class ForwardManager {
public ForwardManager() { public ForwardManager() {
sessionContexts = new HashMap<String, SessionContext>(); sessionContexts = new HashMap<>();
} }
public void startTcpClient(String serviceIP,int port,String appId) { public void startTcpClient(String serviceIP, int port, String sn) {
client.startTcp(serviceIP, port,appId); client.startTcp(serviceIP, port, sn);
} }
public synchronized void putSession(String appId, SessionContext session) { public synchronized void putSession(String sn, SessionContext session) {
sessionContexts.put(appId, session); sessionContexts.put(sn, session);
} }
public SessionContext getSessionContextByAppId(String appId) { public SessionContext getSessionContextBySN(String sn) {
return sessionContexts.get(appId); return sessionContexts.get(sn);
} }
public SessionContext getSessionByChannelId(String channelId) { public SessionContext getSessionByChannelId(String channelId) {
......
...@@ -8,7 +8,7 @@ import lombok.extern.slf4j.Slf4j; ...@@ -8,7 +8,7 @@ import lombok.extern.slf4j.Slf4j;
@Data @Data
@Slf4j @Slf4j
public class BaseConnectionListener implements ChannelFutureListener { public class BaseConnectionListener implements ChannelFutureListener {
public String appId; public String sn;
public String host; public String host;
public int port; public int port;
......
...@@ -7,4 +7,6 @@ package iot.sixiang.license.service; ...@@ -7,4 +7,6 @@ package iot.sixiang.license.service;
*/ */
public interface PmsUseService { public interface PmsUseService {
int createUseLog(String sn); int createUseLog(String sn);
void createFailUseLog(String sn, String message);
} }
...@@ -20,11 +20,23 @@ public class PmsUseServiceImpl implements PmsUseService { ...@@ -20,11 +20,23 @@ public class PmsUseServiceImpl implements PmsUseService {
@Override @Override
public int createUseLog(String sn) { public int createUseLog(String sn) {
PmsUseLog pmsUseLog = getPmsUseLog(sn);
return pmsUseLogMapper.insert(pmsUseLog);
}
@Override
public void createFailUseLog(String sn, String message) {
PmsUseLog pmsUseLog = getPmsUseLog(sn);
pmsUseLog.setMessage(message);
pmsUseLogMapper.insert(pmsUseLog);
}
private PmsUseLog getPmsUseLog(String sn) {
PmsUseLog pmsUseLog = new PmsUseLog(); PmsUseLog pmsUseLog = new PmsUseLog();
Date date = new Date(); Date date = new Date();
pmsUseLog.setCreateTime(date); pmsUseLog.setCreateTime(date);
pmsUseLog.setUpdateTime(date); pmsUseLog.setUpdateTime(date);
pmsUseLog.setSn(sn); pmsUseLog.setSn(sn);
return pmsUseLogMapper.insert(pmsUseLog); return pmsUseLog;
} }
} }
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