package com.thhy.materials.modules.biz.helmet.smoke;
|
import com.alibaba.fastjson.JSONObject;
|
import com.thhy.materials.modules.biz.helmet.entity.TDataSmock;
|
import com.thhy.materials.modules.biz.helmet.service.HelmetService;
|
import com.thhy.materials.modules.biz.utils.ApplicationContextUtil;
|
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.Unpooled;
|
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.SimpleChannelInboundHandler;
|
import io.netty.util.CharsetUtil;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.context.ApplicationContext;
|
import org.springframework.stereotype.Component;
|
|
@Component
|
public class SmokeMessage extends SimpleChannelInboundHandler<ByteBuf>{
|
|
@Autowired
|
public HelmetService helmetService;
|
|
private static String[] alphabets = {"A", "B", "C", "D", "E", "F", "G", "H", "I",
|
"J", "K", "L", "M", "N", "O", "P"};
|
|
@Override
|
public void channelActive(ChannelHandlerContext ctx) {
|
for(int i=0; i<10; i++) {
|
StringBuilder builder = new StringBuilder();
|
builder.append("这是第");
|
builder.append(i);
|
builder.append("条消息, 内容是:");
|
for(int j=0; j<100; j++) {
|
builder.append(alphabets[i]);
|
}
|
builder.append("......");
|
builder.append("#");
|
|
|
System.out.println(builder.toString().getBytes().length);
|
|
ctx.writeAndFlush(Unpooled.copiedBuffer(builder.toString(),
|
CharsetUtil.UTF_8));
|
}
|
}
|
|
@Override
|
public void channelRead0(ChannelHandlerContext ctx, ByteBuf in) {
|
System.out.println("客户端接收到消息: " + in.toString(CharsetUtil.UTF_8));
|
JSONObject jsonObject11 = JSONObject.parseObject(in.toString(CharsetUtil.UTF_8));
|
System.out.println("客户端接收到消息: " + jsonObject11);
|
Object time = jsonObject11.get("time");
|
String parems = jsonObject11.get("params").toString();
|
JSONObject jsonObject = JSONObject.parseObject(parems);
|
System.out.println(time+"-------------"+jsonObject);
|
TDataSmock tDataSmock = new TDataSmock();
|
tDataSmock.setTime(time.toString());
|
tDataSmock.setI00(jsonObject.get("I00").toString().equals("true")?"开启":"关闭");
|
tDataSmock.setI01(jsonObject.get("I01").toString().equals("true")?"开启":"关闭");
|
tDataSmock.setI02(jsonObject.get("I02").toString().equals("true")?"开启":"关闭");
|
tDataSmock.setI03(jsonObject.get("I03").toString().equals("true")?"开启":"关闭");
|
tDataSmock.setI04(jsonObject.get("I04").toString().equals("true")?"开启":"关闭");
|
tDataSmock.setI05(jsonObject.get("I05").toString().equals("true")?"开启":"关闭");
|
tDataSmock.setI06(jsonObject.get("I06").toString().equals("true")?"开启":"关闭");
|
tDataSmock.setI07(jsonObject.get("I07").toString().equals("true")?"开启":"关闭");
|
tDataSmock.setI10(jsonObject.get("I10").toString().equals("true")?"开启":"关闭");
|
tDataSmock.setI11(jsonObject.get("I11").toString().equals("true")?"开启":"关闭");
|
tDataSmock.setQ00(jsonObject.get("Q00").toString().equals("true")?"运行中":"停止状态");
|
tDataSmock.setQ01(jsonObject.get("Q01").toString().equals("true")?"运行中":"停止状态");
|
tDataSmock.setQ02(jsonObject.get("Q02").toString().equals("true")?"运行中":"停止状态");
|
tDataSmock.setQ03(jsonObject.get("Q03").toString().equals("true")?"运行中":"停止状态");
|
tDataSmock.setQ04(jsonObject.get("Q04").toString().equals("true")?"运行中":"停止状态");
|
tDataSmock.setQ05(jsonObject.get("Q05").toString().equals("true")?"运行中":"停止状态");
|
tDataSmock.setVb0(jsonObject.get("VB0").toString());
|
tDataSmock.setVb10(jsonObject.get("VB10").toString());
|
tDataSmock.setVb11(jsonObject.get("VB11").toString());
|
tDataSmock.setVb12(jsonObject.get("VB12").toString());
|
|
// TDataSmock tDataSmock = new TDataSmock();
|
// tDataSmock.setGatewayCyc(jsonObject11.get("gateway_cyc").toString());
|
// tDataSmock.setFans(jsonObject11.get("FanS").toString());
|
// tDataSmock.setV1run(jsonObject11.get("V1Run").toString());
|
// tDataSmock.setUv1run(jsonObject11.get("UV1Run").toString());
|
// tDataSmock.setFanrun(jsonObject11.get("FanRun").toString());
|
// tDataSmock.setUv2run(jsonObject11.get("UV2Run").toString());
|
// tDataSmock.setSsvrun(jsonObject11.get("SSVRun").toString());
|
// tDataSmock.setDp(jsonObject11.get("DP").toString());
|
// tDataSmock.setT(jsonObject11.get("T").toString());
|
// tDataSmock.setOc(jsonObject11.get("OC").toString());
|
// tDataSmock.setGatew(jsonObject11.get("gatew").toString());
|
// tDataSmock.setNxrun(jsonObject11.get("NXRun").toString());
|
// tDataSmock.setTimes(jsonObject11.get("time").toString());
|
// tDataSmock.setRtcVolt(jsonObject11.get("RTC_VOLT").toString());
|
// tDataSmock.setV2run(jsonObject11.get("V2Run").toString());
|
// tDataSmock.setDxqvrun(jsonObject11.get("DXQVRun").toString());
|
// tDataSmock.setPress(jsonObject11.get("Press").toString());
|
// tDataSmock.setDc(jsonObject11.get("Dc").toString());
|
// System.out.println("-------"+tDataSmock);
|
getUserService().smockIn(tDataSmock);
|
}
|
@Override
|
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
|
cause.printStackTrace();
|
ctx.close();
|
}
|
|
|
public static HelmetService getUserService(){
|
ApplicationContext ac = ApplicationContextUtil.getApplicationContext();
|
HelmetService userService = (HelmetService) ac.getBean("helmetServiceImpl");
|
return userService;
|
}
|
|
}
|