Skip to content

Commit

Permalink
添加对应消息Bean
Browse files Browse the repository at this point in the history
  • Loading branch information
朱培杰 committed Dec 19, 2018
1 parent 1f9245e commit bdb97f3
Show file tree
Hide file tree
Showing 20 changed files with 635 additions and 130 deletions.
480 changes: 480 additions & 0 deletions firestorm.log

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/main/java/com/github/unclecatmyself/Application.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.github.unclecatmyself;

import com.github.unclecatmyself.auto.InitServer;
import com.github.unclecatmyself.common.properties.InitNetty;
import com.github.unclecatmyself.common.bean.InitNetty;

/**
* Created by MySelf on 2018/12/18.
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/github/unclecatmyself/auto/InitServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import com.github.unclecatmyself.bootstrap.BootstrapServer;
import com.github.unclecatmyself.bootstrap.NettyBootstrapServer;
import com.github.unclecatmyself.common.properties.InitNetty;
import com.github.unclecatmyself.common.bean.InitNetty;

/**
* Create by UncleCatMySelf in 2018/12/06
Expand All @@ -26,7 +26,6 @@ public void open(){
}
}


public void close(){
if(bootstrapServer!=null){
bootstrapServer.shutdown();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.unclecatmyself.auto;

import com.github.unclecatmyself.common.properties.InitNetty;
import com.github.unclecatmyself.common.bean.InitNetty;
import org.apache.commons.lang3.ObjectUtils;


Expand All @@ -24,17 +24,6 @@ public ServerAutoConfigure(){

}

// @Bean
// @ConditionalOnMissingBean(name = "sacnScheduled")
// public ScanRunnable initRunable(@Autowired InitNetty serverBean){
// long time =(serverBean==null || serverBean.getPeriod()<5)?10:serverBean.getPeriod();
// ScanRunnable sacnScheduled = new SacnScheduled(time);
// Thread scanRunnable = new Thread(sacnScheduled);
// scanRunnable.setDaemon(true);
// scanRunnable.start();
// return sacnScheduled;
// }

public InitServer initServer(InitNetty serverBean){
if(!ObjectUtils.allNotNull(serverBean.getWebport(),serverBean.getServerName())){
throw new NullPointerException("not set port");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import com.github.unclecatmyself.bootstrap.channel.WebSocketHandlerService;
import com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler;
import com.github.unclecatmyself.common.properties.InitNetty;
import com.github.unclecatmyself.common.bean.InitNetty;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.unclecatmyself.bootstrap;

import com.github.unclecatmyself.common.properties.InitNetty;
import com.github.unclecatmyself.common.bean.InitNetty;

/**
* Create by UncleCatMySelf in 2018/12/06
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.github.unclecatmyself.bootstrap;

import com.github.unclecatmyself.common.ip.IpUtils;
import com.github.unclecatmyself.common.properties.InitNetty;
import com.github.unclecatmyself.common.bean.InitNetty;
import com.github.unclecatmyself.common.utils.RemotingUtil;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.PooledByteBufAllocator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
*/
public class WebSocketHandlerService extends ServerWebSocketHandlerService {


private final InChatVerifyService inChatVerifyService = new InChatVerifyServiceImpl();

private final InChatBackMapService inChatBackMapService = new InChatBackMapServiceImpl();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.github.unclecatmyself.bootstrap.data;

import com.github.unclecatmyself.common.bean.InChatMessage;

import java.util.Map;

/**
* Created by MySelf on 2018/12/3.
*/
public interface InChatToDataBaseService {

Boolean writeMapToDB(Map<String,Object> maps);
Boolean writeMapToDB(InChatMessage message);

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.alibaba.fastjson.JSON;
import com.github.unclecatmyself.common.exception.NoFindHandlerException;
import com.github.unclecatmyself.common.utils.TimeUtil;
import com.github.unclecatmyself.common.websockets.ServerWebSocketHandlerService;
import com.github.unclecatmyself.common.websockets.WebSocketHandler;
import com.github.unclecatmyself.common.utils.ConstansUtil;
Expand All @@ -15,6 +14,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;
import java.util.Map;

/**
Expand Down Expand Up @@ -47,23 +47,27 @@ protected void textdoMessage(ChannelHandlerContext ctx, TextWebSocketFrame msg)
throw new NoFindHandlerException("Server Handler 不匹配");
}
Map<String,Object> maps = (Map) JSON.parse(msg.text());
maps.put("time", TimeUtil.getTime());
maps.put("time", new Date());
switch ((String)maps.get(ConstansUtil.TYPE)){
case ConstansUtil.LOGIN:
log.info("[DefaultWebSocketHandler.textdoMessage.LOGIN]");
serverWebSocketHandlerService.login(channel,maps);
break;
//针对个人,发送给自己
case ConstansUtil.SENDME:
log.info("[DefaultWebSocketHandler.textdoMessage.SENDME]");
serverWebSocketHandlerService.verify(channel,maps);
serverWebSocketHandlerService.sendMeText(channel,maps);
break;
//针对个人,发送给某人
case ConstansUtil.SENDTO:
log.info("[DefaultWebSocketHandler.textdoMessage.SENDTO]");
serverWebSocketHandlerService.verify(channel,maps);
serverWebSocketHandlerService.sendToText(channel,maps);
break;
//发送给群组
case ConstansUtil.SENDGROUP:
log.info("[DefaultWebSocketHandler.textdoMessage.SENDGROUP]");
serverWebSocketHandlerService.verify(channel,maps);
serverWebSocketHandlerService.sendGroupText(channel,maps);
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package com.github.unclecatmyself.common.bean;

import java.util.Date;

/**
* Created by MySelf on 2018/12/19.
*/
public class InChatMessage {

private Date time;

private String type;

private String value;

private String token;

private String groudId;

private String online;

private String one;

public Date getTime() {
return time;
}

public void setTime(Date time) {
this.time = time;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}

public String getToken() {
return token;
}

public void setToken(String token) {
this.token = token;
}

public String getGroudId() {
return groudId;
}

public void setGroudId(String groudId) {
this.groudId = groudId;
}

public String getOnline() {
return online;
}

public void setOnline(String online) {
this.online = online;
}

public String getOne() {
return one;
}

public void setOne(String one) {
this.one = one;
}

@Override
public String toString() {
return "InChatMessage{" +
"time=" + time +
", type='" + type + '\'' +
", value='" + value + '\'' +
", token='" + token + '\'' +
", groudId='" + groudId + '\'' +
", online='" + online + '\'' +
", one='" + one + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.unclecatmyself.common.properties;
package com.github.unclecatmyself.common.bean;

import com.github.unclecatmyself.bootstrap.handler.DefaultWebSocketHandler;

Expand Down
13 changes: 0 additions & 13 deletions src/main/java/com/github/unclecatmyself/common/pool/Scheduled.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ public class ConstansUtil {
public static final String FROM = "from";

public static final String SENDGROUP = "sendGroup";

public static final String TIME = "time";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.github.unclecatmyself.common.utils;

import com.github.unclecatmyself.common.bean.InChatMessage;

import java.util.Date;
import java.util.Map;

/**
* Created by MySelf on 2018/12/19.
*/
public class MessageChangeUtil {

public static InChatMessage Change(Map<String,Object> maps){
InChatMessage message = new InChatMessage();
if (maps.containsKey(ConstansUtil.TOKEN)){
message.setToken((String) maps.get(ConstansUtil.TOKEN));
}
if (maps.containsKey(ConstansUtil.TIME)){
message.setTime((Date) maps.get(ConstansUtil.TIME));
}
if (maps.containsKey(ConstansUtil.VALUE)){
message.setValue((String)maps.get(ConstansUtil.VALUE));
}
if (maps.containsKey(ConstansUtil.TYPE)){
message.setType((String)maps.get(ConstansUtil.TYPE));
}
if (maps.containsKey(ConstansUtil.ONE)){
message.setOne((String)maps.get(ConstansUtil.ONE));
}
if (maps.containsKey(ConstansUtil.GROUPID)){
message.setGroudId((String)maps.get(ConstansUtil.GROUPID));
}
if (maps.containsKey(ConstansUtil.ON_ONLINE)){
message.setOnline((String)maps.get(ConstansUtil.ON_ONLINE));
}
return message;
}

}

This file was deleted.

19 changes: 0 additions & 19 deletions src/main/java/com/github/unclecatmyself/common/utils/TimeUtil.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.github.unclecatmyself.task;

import com.github.unclecatmyself.bootstrap.data.InChatToDataBaseService;
import com.github.unclecatmyself.common.bean.InChatMessage;
import com.github.unclecatmyself.common.utils.MessageChangeUtil;
import com.github.unclecatmyself.user.DataBaseServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -18,11 +20,10 @@ public class DataAsynchronousTask {

public void writeData(Map<String,Object> maps) throws Exception {
log.info("【异步写入数据】");
// return new AsyncResult<>(inChatToDataBaseService.writeMapToDB(maps));
new Thread(new Runnable() {
@Override
public void run() {
inChatToDataBaseService.writeMapToDB(maps);
inChatToDataBaseService.writeMapToDB(MessageChangeUtil.Change(maps));
}
}).start();
}
Expand Down
Loading

0 comments on commit bdb97f3

Please sign in to comment.