|
|
@@ -21,6 +21,7 @@ import org.dromara.common.core.utils.StringUtils;
|
|
|
import org.dromara.common.json.utils.JsonUtils;
|
|
|
import org.dromara.common.redis.utils.CacheUtils;
|
|
|
import org.dromara.common.redis.utils.RedisUtils;
|
|
|
+import org.dromara.netty.NettyChannelHandlerContextMapCache;
|
|
|
import org.dromara.netty.pojo.NettyChannelHandlerContext;
|
|
|
import org.dromara.sms4j.api.universal.RedisUtil;
|
|
|
import org.dromara.system.domain.CountData;
|
|
|
@@ -380,61 +381,75 @@ public class CamelDataUtil {
|
|
|
if(StrUtil.isNotEmpty(countdatastr.toString())){
|
|
|
try{
|
|
|
this.SendData("direct:senddev", countdatastr.toString(), "devtype","-");
|
|
|
-
|
|
|
}catch (Exception e){
|
|
|
|
|
|
}
|
|
|
- JSONObject countdata = JsonUtils.parseObject(countdatastr.toString(), JSONObject.class);
|
|
|
-
|
|
|
- String sn = countdata.getStr("sn");
|
|
|
- String type = countdata.getStr("type");
|
|
|
- Long time = countdata.getLong("time");
|
|
|
- Integer in = 0;
|
|
|
- Integer out = 0;
|
|
|
- Long iCreatedTime = 0L;
|
|
|
- if(type.equals("count")){
|
|
|
- //获取数据in out
|
|
|
- JSONArray inoutarry = ((JSONObject)(countdata.getJSONArray("data").get(0))).getJSONArray("count");
|
|
|
- for (int i = 0; i < inoutarry.size(); i++) {
|
|
|
- if(((JSONObject)inoutarry.get(i)).getStr("name").equals("d1")){
|
|
|
- in = ((JSONObject)inoutarry.get(i)).getInt("in");
|
|
|
- out = ((JSONObject)inoutarry.get(i)).getInt("out");
|
|
|
- break;
|
|
|
+ try{
|
|
|
+ JSONObject countdata = JsonUtils.parseObject(countdatastr.toString(), JSONObject.class);
|
|
|
+
|
|
|
+ String sn = countdata.getStr("sn");
|
|
|
+ String type = countdata.getStr("type");
|
|
|
+ Long time = countdata.getLong("time");
|
|
|
+ try {
|
|
|
+ NettyChannelHandlerContext topic = NettyChannelHandlerContextMapCache.ChannelMapCache.get(((ChannelHandlerContext) (exchange.getIn().getHeader("CamelNettyChannelHandlerContext"))).channel().toString());
|
|
|
+ if (topic != null) {
|
|
|
+ topic.setTag(sn);
|
|
|
}
|
|
|
- }
|
|
|
- iCreatedTime = ((JSONObject)(countdata.getJSONArray("data").get(0))).getLong("iCreatedTime");
|
|
|
- if(iCreatedTime*1000>DateUtil.current()-24*3600*1000 && iCreatedTime*1000<DateUtil.current()+24*3600*1000){
|
|
|
- //正确的时间
|
|
|
- CountData countData = new CountData();
|
|
|
- countData.setIncount(in);
|
|
|
- countData.setOutcount(out);
|
|
|
- countData.setDevicecode(sn);
|
|
|
- countData.setTslong(iCreatedTime*1000);
|
|
|
- countDataService.insertData(countData);
|
|
|
- }else{
|
|
|
- log.error("{}:时间错误",iCreatedTime);
|
|
|
+ RedisUtils.setCacheObject(StringUtils.format("count_{}", sn), DateUtil.now());
|
|
|
+
|
|
|
+ }catch (Exception e){
|
|
|
|
|
|
}
|
|
|
- //存储数据
|
|
|
+ Integer in = 0;
|
|
|
+ Integer out = 0;
|
|
|
+ Long iCreatedTime = 0L;
|
|
|
+ if(type.equals("count")){
|
|
|
+ //获取数据in out
|
|
|
+ JSONArray inoutarry = ((JSONObject)(countdata.getJSONArray("data").get(0))).getJSONArray("count");
|
|
|
+ for (int i = 0; i < inoutarry.size(); i++) {
|
|
|
+ if(((JSONObject)inoutarry.get(i)).getStr("name").equals("d1")){
|
|
|
+ in = ((JSONObject)inoutarry.get(i)).getInt("in");
|
|
|
+ out = ((JSONObject)inoutarry.get(i)).getInt("out");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ iCreatedTime = ((JSONObject)(countdata.getJSONArray("data").get(0))).getLong("iCreatedTime");
|
|
|
+ if(iCreatedTime*1000>DateUtil.current()-24*3600*1000 && iCreatedTime*1000<DateUtil.current()+24*3600*1000){
|
|
|
+ //正确的时间
|
|
|
+ CountData countData = new CountData();
|
|
|
+ countData.setIncount(in);
|
|
|
+ countData.setOutcount(out);
|
|
|
+ countData.setDevicecode(sn);
|
|
|
+ countData.setTslong(iCreatedTime*1000);
|
|
|
+ countDataService.insertData(countData);
|
|
|
+ }else{
|
|
|
+ log.error("{}:时间错误",iCreatedTime);
|
|
|
+
|
|
|
+ }
|
|
|
+ //存储数据
|
|
|
// log.info("{},{},{},{},{}",sn,type,in,out,iCreatedTime);
|
|
|
- }
|
|
|
+ }
|
|
|
+ //组织返回数据
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+ result.put( "sn" , sn) ;
|
|
|
+ result.put("type", type) ;
|
|
|
+ if(type.equals("heart")){
|
|
|
+ JSONObject sub = new JSONObject() ;
|
|
|
+ sub.put("time", time) ;
|
|
|
+ result.put("data", sub ) ;
|
|
|
+ }else{
|
|
|
+ result.put("time", time ) ;
|
|
|
+ }
|
|
|
+
|
|
|
+ NettyChannelHandlerContext ctx = ChannelMapCache.get(((ChannelHandlerContext)exchange.getIn().getHeader("CamelNettyChannelHandlerContext")).channel().toString());
|
|
|
+ ByteBuf buf = Unpooled.copiedBuffer(JsonUtils.toJsonString(result).getBytes(CharsetUtil.UTF_8));
|
|
|
+ ctx.getChannelHandlerContext().writeAndFlush(buf);
|
|
|
+
|
|
|
+ }catch (Exception e){}
|
|
|
+
|
|
|
|
|
|
|
|
|
- //组织返回数据
|
|
|
- JSONObject result = new JSONObject();
|
|
|
- result.put( "sn" , sn) ;
|
|
|
- result.put("type", type) ;
|
|
|
- if(type.equals("heart")){
|
|
|
- JSONObject sub = new JSONObject() ;
|
|
|
- sub.put("time", time) ;
|
|
|
- result.put("data", sub ) ;
|
|
|
- }else{
|
|
|
- result.put("time", time ) ;
|
|
|
- }
|
|
|
|
|
|
- NettyChannelHandlerContext ctx = ChannelMapCache.get(((ChannelHandlerContext)exchange.getIn().getHeader("CamelNettyChannelHandlerContext")).channel().toString());
|
|
|
- ByteBuf buf = Unpooled.copiedBuffer(JsonUtils.toJsonString(result).getBytes(CharsetUtil.UTF_8));
|
|
|
- ctx.getChannelHandlerContext().writeAndFlush(buf);
|
|
|
}
|
|
|
|
|
|
|