netty-确定互联完成
This commit is contained in:
@@ -18,7 +18,6 @@ import io.netty.util.internal.PlatformDependent;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.client.RestTemplate;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
@@ -46,27 +45,24 @@ public class AppMessageHandlerAdapter implements MessageService {
|
|||||||
*/
|
*/
|
||||||
private ConcurrentMap<String, Channel> links = PlatformDependent.newConcurrentHashMap();
|
private ConcurrentMap<String, Channel> links = PlatformDependent.newConcurrentHashMap();
|
||||||
|
|
||||||
// @Resource
|
@Resource
|
||||||
private MemberService memberService;
|
private MemberService memberService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private VenueService venueService;
|
private VenueService venueService;
|
||||||
|
|
||||||
// @Resource
|
@Resource
|
||||||
private DeviceService deviceService;
|
private DeviceService deviceService;
|
||||||
|
|
||||||
// @Resource
|
@Resource
|
||||||
private ConfigService configService;
|
private ConfigService configService;
|
||||||
|
|
||||||
// @Resource(name = "scheduledExecutorService")
|
@Resource(name = "scheduledExecutorService")
|
||||||
private ScheduledExecutorService scheduledExecutorService;
|
private ScheduledExecutorService scheduledExecutorService;
|
||||||
|
|
||||||
// @Resource
|
@Resource
|
||||||
private MemberEnterVenueLogService memberEnterVenueLogService;
|
private MemberEnterVenueLogService memberEnterVenueLogService;
|
||||||
|
|
||||||
// @Resource
|
|
||||||
private RestTemplate restTemplate;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理心跳信息,存储心跳信息
|
* 处理心跳信息,存储心跳信息
|
||||||
* @param clientId
|
* @param clientId
|
||||||
@@ -84,9 +80,9 @@ public class AppMessageHandlerAdapter implements MessageService {
|
|||||||
logger.error("this client choose venue Error! venueId == " + heartBeat.getVenueId());
|
logger.error("this client choose venue Error! venueId == " + heartBeat.getVenueId());
|
||||||
} else {
|
} else {
|
||||||
deviceService.online(heartBeat.getDeviceName(),heartBeat.getVenueId(),thisVenue.getType(),clientId);
|
deviceService.online(heartBeat.getDeviceName(),heartBeat.getVenueId(),thisVenue.getType(),clientId);
|
||||||
putChannelType(heartBeat.getDeviceName(),heartBeat.getVenueId(),channel);
|
addLinks(heartBeat.getDeviceName(),heartBeat.getVenueId(),channel);
|
||||||
VenueMessage VenueMessage = new VenueMessage(MessageType.LINK,"欢迎扫码进场!");
|
VenueMessage venueMessage = new VenueMessage(MessageType.LINK,"欢迎扫码进场!");
|
||||||
channel.writeAndFlush(VenueMessage);
|
ServerMessageUtils.INSTANCE.sendMsg(channel,venueMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -129,7 +125,7 @@ public class AppMessageHandlerAdapter implements MessageService {
|
|||||||
@Override
|
@Override
|
||||||
public void testLoad(String deviceName, Integer venueId) {
|
public void testLoad(String deviceName, Integer venueId) {
|
||||||
Channel currentChannel = getCurrentChannel(deviceName, venueId);
|
Channel currentChannel = getCurrentChannel(deviceName, venueId);
|
||||||
currentChannel.writeAndFlush("Test Links" + deviceName + venueId);
|
ServerMessageUtils.INSTANCE.sendMsg(currentChannel,new VenueMessage(MessageType.LINK,"测试链接"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -160,7 +156,7 @@ public class AppMessageHandlerAdapter implements MessageService {
|
|||||||
// VenueMessage.setCmdId(Cmd.OPEN_DOOR.id);
|
// VenueMessage.setCmdId(Cmd.OPEN_DOOR.id);
|
||||||
// VenueMessage.setDoor(2);
|
// VenueMessage.setDoor(2);
|
||||||
// sendOpenMessage(VenueMessage, device.getId());
|
// sendOpenMessage(VenueMessage, device.getId());
|
||||||
// 校验玩就可以出场了
|
// 校验完就可以出场了
|
||||||
// sendMessage(memberMessageDto, device.getId());
|
// sendMessage(memberMessageDto, device.getId());
|
||||||
// venueService.addNumber(venue.getId(), -1, member.getId());
|
// venueService.addNumber(venue.getId(), -1, member.getId());
|
||||||
// venue = venueService.findById(venue.getId());
|
// venue = venueService.findById(venue.getId());
|
||||||
@@ -245,7 +241,7 @@ public class AppMessageHandlerAdapter implements MessageService {
|
|||||||
/**
|
/**
|
||||||
* 缓存通道
|
* 缓存通道
|
||||||
*/
|
*/
|
||||||
public void putChannelType(String deviceName, Integer venueId, Channel channel) {
|
public void addLinks(String deviceName, Integer venueId, Channel channel) {
|
||||||
String clientId = deviceName + NettyConstant.SPIT_WORD + venueId;
|
String clientId = deviceName + NettyConstant.SPIT_WORD + venueId;
|
||||||
links.put(clientId, channel);
|
links.put(clientId, channel);
|
||||||
}
|
}
|
||||||
@@ -254,7 +250,7 @@ public class AppMessageHandlerAdapter implements MessageService {
|
|||||||
* 获取当前通道
|
* 获取当前通道
|
||||||
*/
|
*/
|
||||||
public Channel getCurrentChannel(String deviceName, Integer venueId){
|
public Channel getCurrentChannel(String deviceName, Integer venueId){
|
||||||
String clientId = deviceName + NettyConstant.SPIT_WORD + venueId + NettyConstant.SPIT_WORD;
|
String clientId = deviceName + NettyConstant.SPIT_WORD + venueId;
|
||||||
return links.get(clientId);
|
return links.get(clientId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ public class ClientHandler extends SimpleChannelInboundHandler<String> {
|
|||||||
private HeartBeat getHbMessage() {
|
private HeartBeat getHbMessage() {
|
||||||
HeartBeat hb = new HeartBeat();
|
HeartBeat hb = new HeartBeat();
|
||||||
hb.setDeviceName("dsadasdasd");
|
hb.setDeviceName("dsadasdasd");
|
||||||
hb.setVenueId(123);
|
hb.setVenueId(32);
|
||||||
return hb;
|
return hb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import io.netty.handler.timeout.IdleStateHandler;
|
|||||||
|
|
||||||
public class ClientInitializer extends ChannelInitializer<SocketChannel> {
|
public class ClientInitializer extends ChannelInitializer<SocketChannel> {
|
||||||
|
|
||||||
private final static int TIME_HEART_BEAT = 5;
|
private final static int TIME_HEART_BEAT = 60;
|
||||||
|
|
||||||
public ClientThread.ReConnectHandler reConnectHandler;
|
public ClientThread.ReConnectHandler reConnectHandler;
|
||||||
public ClientHandler dmClientHandler;
|
public ClientHandler dmClientHandler;
|
||||||
|
|||||||
@@ -23,6 +23,10 @@
|
|||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
<version>1.7.33</version>
|
<version>1.7.33</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>ch.qos.logback</groupId>
|
||||||
|
<artifactId>logback-classic</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>jackson-core</artifactId>
|
<artifactId>jackson-core</artifactId>
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ public interface NettyConstant {
|
|||||||
/**
|
/**
|
||||||
* session中存储终端发送的额外参数
|
* session中存储终端发送的额外参数
|
||||||
*/
|
*/
|
||||||
public static AttributeKey<ChannelParam> CHANNEL_PARAM = AttributeKey.newInstance("CHANNEL_PARAM");
|
AttributeKey<ChannelParam> CHANNEL_PARAM = AttributeKey.newInstance("CHANNEL_PARAM");
|
||||||
|
|
||||||
public final static String SPIT_WORD = "#";
|
String SPIT_WORD = "#";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,9 +7,12 @@ public class VenueMessage implements Serializable {
|
|||||||
private MessageType messageType;
|
private MessageType messageType;
|
||||||
private String message;
|
private String message;
|
||||||
|
|
||||||
public VenueMessage(MessageType type, String msg) {
|
public VenueMessage() {
|
||||||
this.messageType = type;
|
}
|
||||||
this.message = msg;
|
|
||||||
|
public VenueMessage(MessageType messageType, String message) {
|
||||||
|
this.messageType = messageType;
|
||||||
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageType getMessageType() {
|
public MessageType getMessageType() {
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ public enum ServerMessageUtils {
|
|||||||
INSTANCE;
|
INSTANCE;
|
||||||
|
|
||||||
public void sendMsg(Channel channel, VenueMessage message) {
|
public void sendMsg(Channel channel, VenueMessage message) {
|
||||||
channel.writeAndFlush(EncodeMsg.INSTANCE.encode(message));
|
if (channel != null) {
|
||||||
|
channel.writeAndFlush(EncodeMsg.INSTANCE.encode(message));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
<result column="stream" property="stream"/>
|
<result column="stream" property="stream"/>
|
||||||
<result column="venue_id" property="venueId"/>
|
<result column="venue_id" property="venueId"/>
|
||||||
<result column="venue_type" property="venueType"/>
|
<result column="venue_type" property="venueType"/>
|
||||||
<result column="device_type" property="deviceType"/>
|
|
||||||
<result column="bind_member" property="bindMember"/>
|
<result column="bind_member" property="bindMember"/>
|
||||||
<result column="bind_time" property="bindTime"/>
|
<result column="bind_time" property="bindTime"/>
|
||||||
<result column="status" property="status"/>
|
<result column="status" property="status"/>
|
||||||
@@ -53,7 +52,6 @@
|
|||||||
#{stream, jdbcType=VARCHAR},
|
#{stream, jdbcType=VARCHAR},
|
||||||
#{venue_id, jdbcType=INTEGER},
|
#{venue_id, jdbcType=INTEGER},
|
||||||
#{venue_type, jdbcType=INTEGER},
|
#{venue_type, jdbcType=INTEGER},
|
||||||
#{device_type, jdbcType=VARCHAR},
|
|
||||||
#{bind_member, jdbcType=INTEGER},
|
#{bind_member, jdbcType=INTEGER},
|
||||||
#{bind_time, jdbcType=TIMESTAMP},
|
#{bind_time, jdbcType=TIMESTAMP},
|
||||||
#{createdId, jdbcType=INTEGER},
|
#{createdId, jdbcType=INTEGER},
|
||||||
@@ -94,9 +92,6 @@
|
|||||||
<if test="venueType != null">
|
<if test="venueType != null">
|
||||||
venue_type,
|
venue_type,
|
||||||
</if>
|
</if>
|
||||||
<if test="deviceType != null">
|
|
||||||
device_type,
|
|
||||||
</if>
|
|
||||||
<if test="bindMember != null">
|
<if test="bindMember != null">
|
||||||
bind_member,
|
bind_member,
|
||||||
</if>
|
</if>
|
||||||
@@ -138,9 +133,6 @@
|
|||||||
<if test="venueType != null">
|
<if test="venueType != null">
|
||||||
#{venueType},
|
#{venueType},
|
||||||
</if>
|
</if>
|
||||||
<if test="deviceType != null">
|
|
||||||
#{deviceType},
|
|
||||||
</if>
|
|
||||||
<if test="bindMember != null">
|
<if test="bindMember != null">
|
||||||
#{bindMember},
|
#{bindMember},
|
||||||
</if>
|
</if>
|
||||||
@@ -211,9 +203,6 @@
|
|||||||
<if test="venueType != null">
|
<if test="venueType != null">
|
||||||
venue_type = #{venueType},
|
venue_type = #{venueType},
|
||||||
</if>
|
</if>
|
||||||
<if test="deviceType != null">
|
|
||||||
device_type = #{deviceType},
|
|
||||||
</if>
|
|
||||||
<if test="bindMember != null">
|
<if test="bindMember != null">
|
||||||
bind_member = #{bindMember},
|
bind_member = #{bindMember},
|
||||||
</if>
|
</if>
|
||||||
@@ -271,49 +260,31 @@
|
|||||||
<update id="offline">
|
<update id="offline">
|
||||||
UPDATE sv_device set status = 0,modified_time = now()
|
UPDATE sv_device set status = 0,modified_time = now()
|
||||||
WHERE name = #{deviceName} and venue_id=#{venueId}
|
WHERE name = #{deviceName} and venue_id=#{venueId}
|
||||||
<if test="deviceType != null">
|
|
||||||
and device_type = #{deviceType}
|
|
||||||
</if>
|
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
<update id="online">
|
<update id="online">
|
||||||
UPDATE sv_device set status = 2,modified_time = now()
|
UPDATE sv_device set status = 2,modified_time = now()
|
||||||
WHERE name = #{deviceName} and venue_id=#{venueId}
|
WHERE name = #{deviceName} and venue_id=#{venueId}
|
||||||
<if test="deviceType != null">
|
|
||||||
and device_type = #{deviceType}
|
|
||||||
</if>
|
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
<select id="checkDevice" resultType="java.lang.Integer">
|
<select id="checkDevice" resultType="java.lang.Integer">
|
||||||
SELECT count(1) FROM sv_device
|
SELECT count(1) FROM sv_device
|
||||||
WHERE 1=1 AND name = #{deviceName} and venue_id=#{venueId} and deleted = 0
|
WHERE 1=1 AND name = #{deviceName} and venue_id=#{venueId} and deleted = 0
|
||||||
<if test="deviceType != null">
|
|
||||||
and device_type = #{deviceType}
|
|
||||||
</if>
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="findByDevice" resultType="com.sv.entity.Device">
|
<select id="findByDevice" resultType="com.sv.entity.Device">
|
||||||
SELECT
|
SELECT
|
||||||
<include refid="Field"></include> FROM sv_device
|
<include refid="Field"></include> FROM sv_device
|
||||||
WHERE 1=1 AND name = #{deviceName} and venue_id=#{venueId} and deleted = 0
|
WHERE 1=1 AND name = #{deviceName} and venue_id=#{venueId} and deleted = 0
|
||||||
<if test="deviceType != null">
|
|
||||||
and device_type = #{deviceType}
|
|
||||||
</if>
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<update id="bindMember">
|
<update id="bindMember">
|
||||||
UPDATE sv_device set bind_member = #{bindMember},bind_time = now()
|
UPDATE sv_device set bind_member = #{bindMember},bind_time = now()
|
||||||
WHERE name = #{deviceName} and venue_id=#{venueId}
|
WHERE name = #{deviceName} and venue_id=#{venueId}
|
||||||
<if test="deviceType != null">
|
|
||||||
and device_type = #{deviceType}
|
|
||||||
</if>
|
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
<update id="unBindMember">
|
<update id="unBindMember">
|
||||||
UPDATE sv_device set bind_member = null,bind_time = null
|
UPDATE sv_device set bind_member = null,bind_time = null
|
||||||
WHERE name = #{deviceName} and venue_id=#{venueId}
|
WHERE name = #{deviceName} and venue_id=#{venueId}
|
||||||
<if test="deviceType != null">
|
|
||||||
and device_type = #{deviceType}
|
|
||||||
</if>
|
|
||||||
</update>
|
</update>
|
||||||
</mapper>
|
</mapper>
|
||||||
Reference in New Issue
Block a user