|
@@ -1,8 +1,14 @@
|
|
|
package org.dromara.util;
|
|
package org.dromara.util;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
|
|
+import cn.hutool.core.util.CharsetUtil;
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.json.JSON;
|
|
import cn.hutool.json.JSON;
|
|
|
import cn.hutool.json.JSONArray;
|
|
import cn.hutool.json.JSONArray;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
|
|
|
+import io.netty.buffer.ByteBuf;
|
|
|
|
|
+import io.netty.buffer.Unpooled;
|
|
|
|
|
+import io.netty.channel.ChannelHandlerContext;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.camel.CamelContext;
|
|
import org.apache.camel.CamelContext;
|
|
|
import org.apache.camel.Exchange;
|
|
import org.apache.camel.Exchange;
|
|
@@ -12,11 +18,15 @@ import org.dromara.common.core.constant.Constants;
|
|
|
import org.dromara.common.core.utils.DateUtils;
|
|
import org.dromara.common.core.utils.DateUtils;
|
|
|
import org.dromara.common.core.utils.SpringUtils;
|
|
import org.dromara.common.core.utils.SpringUtils;
|
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
|
|
|
+import org.dromara.common.json.utils.JsonUtils;
|
|
|
import org.dromara.common.redis.utils.RedisUtils;
|
|
import org.dromara.common.redis.utils.RedisUtils;
|
|
|
|
|
+import org.dromara.netty.pojo.NettyChannelHandlerContext;
|
|
|
import org.dromara.sms4j.api.universal.RedisUtil;
|
|
import org.dromara.sms4j.api.universal.RedisUtil;
|
|
|
|
|
+import org.dromara.system.domain.CountData;
|
|
|
import org.dromara.system.domain.GpsData;
|
|
import org.dromara.system.domain.GpsData;
|
|
|
import org.dromara.system.domain.SysDictData;
|
|
import org.dromara.system.domain.SysDictData;
|
|
|
import org.dromara.system.domain.TblCarInfo;
|
|
import org.dromara.system.domain.TblCarInfo;
|
|
|
|
|
+import org.dromara.system.domain.bo.CountDataBo;
|
|
|
import org.dromara.system.domain.bo.SysDictDataBo;
|
|
import org.dromara.system.domain.bo.SysDictDataBo;
|
|
|
import org.dromara.system.domain.bo.TblCarInfoBo;
|
|
import org.dromara.system.domain.bo.TblCarInfoBo;
|
|
|
import org.dromara.system.domain.bo.TblCarScheduleBo;
|
|
import org.dromara.system.domain.bo.TblCarScheduleBo;
|
|
@@ -33,6 +43,9 @@ import java.nio.charset.Charset;
|
|
|
import java.time.Duration;
|
|
import java.time.Duration;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
+import static org.dromara.netty.NettyChannelHandlerContextMapCache.ChannelMapCache;
|
|
|
|
|
+import static org.dromara.netty.NettyChannelHandlerContextMapCache.ChannelMapCache;
|
|
|
|
|
+
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
@Component("camelDataUtil")
|
|
@Component("camelDataUtil")
|
|
|
public class CamelDataUtil {
|
|
public class CamelDataUtil {
|
|
@@ -42,6 +55,9 @@ public class CamelDataUtil {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
ITblGpsDataService gpsDataService;
|
|
ITblGpsDataService gpsDataService;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ ITblCountDataService countDataService;
|
|
|
|
|
+
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
ITblCarInfoService tblCarInfoService;
|
|
ITblCarInfoService tblCarInfoService;
|
|
@@ -67,6 +83,7 @@ public class CamelDataUtil {
|
|
|
// exchange.getMessage().setBody(body);
|
|
// exchange.getMessage().setBody(body);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
public void processGpsData(GpsData gpsData){
|
|
public void processGpsData(GpsData gpsData){
|
|
|
|
|
|
|
|
log.info("body:{}",JSONUtil.toJsonStr(gpsData));
|
|
log.info("body:{}",JSONUtil.toJsonStr(gpsData));
|
|
@@ -129,7 +146,27 @@ public class CamelDataUtil {
|
|
|
//靠近站点 还得计算当前是否跨站点
|
|
//靠近站点 还得计算当前是否跨站点
|
|
|
String stationName = RedisUtils.getCacheObject(StringUtils.format("car_{}_{}_tip",carInfoVo1.getCarNum(),DateFormatUtils.format( scheduleVo.getScheduleDate(),DateUtils.YYYYMMDDHHMMSS) ));
|
|
String stationName = RedisUtils.getCacheObject(StringUtils.format("car_{}_{}_tip",carInfoVo1.getCarNum(),DateFormatUtils.format( scheduleVo.getScheduleDate(),DateUtils.YYYYMMDDHHMMSS) ));
|
|
|
if(stationName!=null && stationName.contains(jsonObject.getStr("stationName"))){
|
|
if(stationName!=null && stationName.contains(jsonObject.getStr("stationName"))){
|
|
|
- //提报过的不再提报
|
|
|
|
|
|
|
+ //提报过的不再提报 //离开站记录时间
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (scheduleVo.getExt1() != null) {
|
|
|
|
|
+ //进站点 记录时间
|
|
|
|
|
+ JSONObject datainout = new JSONObject();
|
|
|
|
|
+ datainout = JSONUtil.parseObj(scheduleVo.getExt1());
|
|
|
|
|
+ if (datainout.get(jsonObject.getStr("stationName")) != null) {
|
|
|
|
|
+ JSONObject inout = datainout.getJSONObject(jsonObject.getStr("stationName"));
|
|
|
|
|
+ if (inout.getStr("outtime") == null) {
|
|
|
|
|
+ inout.set("outtime", DateUtil.now());
|
|
|
|
|
+ }
|
|
|
|
|
+ datainout.set(jsonObject.getStr("stationName"), inout);
|
|
|
|
|
+ scheduleVo.setExt1(JSONUtil.toJsonStr(datainout));
|
|
|
|
|
+ TblCarScheduleBo scheduleVo1 = new TblCarScheduleBo();
|
|
|
|
|
+ scheduleVo1.setId(scheduleVo.getId());
|
|
|
|
|
+ scheduleVo1.setExt1(scheduleVo.getExt1());
|
|
|
|
|
+ tblCarScheduleService.updateByBo(scheduleVo1);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }catch (Exception e){}
|
|
|
}else{
|
|
}else{
|
|
|
lines1.add(jsonObject);
|
|
lines1.add(jsonObject);
|
|
|
}
|
|
}
|
|
@@ -155,6 +192,23 @@ public class CamelDataUtil {
|
|
|
sysDictData.setDictType("tbl_sites");
|
|
sysDictData.setDictType("tbl_sites");
|
|
|
List<SysDictDataVo> stations = sysDictDataService.selectDictDataList(sysDictData);
|
|
List<SysDictDataVo> stations = sysDictDataService.selectDictDataList(sysDictData);
|
|
|
if(stations.size()>0){
|
|
if(stations.size()>0){
|
|
|
|
|
+ try{
|
|
|
|
|
+ //进站点 记录时间
|
|
|
|
|
+ JSONObject datainout = new JSONObject();
|
|
|
|
|
+ if(scheduleVo.getExt1()!=null){
|
|
|
|
|
+ datainout = JSONUtil.parseObj(scheduleVo.getExt1());
|
|
|
|
|
+ }
|
|
|
|
|
+ JSONObject inout = new JSONObject();
|
|
|
|
|
+ inout.set("intime", DateUtil.now());
|
|
|
|
|
+ datainout.set(stations.get(0).getDictLabel(),inout);
|
|
|
|
|
+ scheduleVo.setExt1(JSONUtil.toJsonStr(datainout));
|
|
|
|
|
+ TblCarScheduleBo scheduleVo1 = new TblCarScheduleBo();
|
|
|
|
|
+ scheduleVo1.setId(scheduleVo.getId());
|
|
|
|
|
+ scheduleVo1.setExt1(scheduleVo.getExt1());
|
|
|
|
|
+ tblCarScheduleService.updateByBo(scheduleVo1);
|
|
|
|
|
+ }catch (Exception e){}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
//满足条件播报(led or 广播)
|
|
//满足条件播报(led or 广播)
|
|
|
String message = StringUtils.format("{}即将到达{},即将到达,请准备接货。", carInfoVo1.getCarNum(),stations.get(0).getDictLabel());
|
|
String message = StringUtils.format("{}即将到达{},即将到达,请准备接货。", carInfoVo1.getCarNum(),stations.get(0).getDictLabel());
|
|
|
if(StringUtils.isNotEmpty(stations.get(0).getRemark())){
|
|
if(StringUtils.isNotEmpty(stations.get(0).getRemark())){
|
|
@@ -210,6 +264,71 @@ public class CamelDataUtil {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ public void ReciveTcpData(String body, Exchange exchange) throws UnsupportedEncodingException {
|
|
|
|
|
+ StringBuilder countdatastr= new StringBuilder("");
|
|
|
|
|
+ JSONArray data= JSONUtil.parseArray(body);
|
|
|
|
|
+ for (int i = 0; i < data.size(); i++) {
|
|
|
|
|
+ if( data.get(i) instanceof Integer){
|
|
|
|
|
+ countdatastr.append((char)(((Integer) data.get(i)).byteValue()&0xff));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if(StrUtil.isNotEmpty(countdatastr.toString())){
|
|
|
|
|
+ log.info("body:{}",countdatastr);
|
|
|
|
|
+ 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;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ 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);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
// public static void main(String[] args) {
|
|
// public static void main(String[] args) {
|
|
|
// String ss = "{\"pathLine\": [{\"order\": 1, \"location\": \"119.807462,26.958413\", \"planInTime\": \"00:15:00\", \"planOutTime\": \"01:15:00\", \"stationName\": \"松罗乡\"}, {\"order\": 2, \"location\": \"119.723653,26.841206\", \"planInTime\": \"00:30:00\", \"planOutTime\": \"01:15:00\", \"stationName\": \"福安客运站\"}, {\"order\": 3, \"location\": \"119.852881,26.817088\", \"planInTime\": \"01:15:00\", \"planOutTime\": \"04:15:00\", \"stationName\": \"姚澳村\"}], \"driverInfo\": 2, \"attendantInfo\": \"1763485590079639554\"}";
|
|
// String ss = "{\"pathLine\": [{\"order\": 1, \"location\": \"119.807462,26.958413\", \"planInTime\": \"00:15:00\", \"planOutTime\": \"01:15:00\", \"stationName\": \"松罗乡\"}, {\"order\": 2, \"location\": \"119.723653,26.841206\", \"planInTime\": \"00:30:00\", \"planOutTime\": \"01:15:00\", \"stationName\": \"福安客运站\"}, {\"order\": 3, \"location\": \"119.852881,26.817088\", \"planInTime\": \"01:15:00\", \"planOutTime\": \"04:15:00\", \"stationName\": \"姚澳村\"}], \"driverInfo\": 2, \"attendantInfo\": \"1763485590079639554\"}";
|
|
|
// JSONArray lines = JSONUtil.parseObj(ss).getJSONArray("pathLine");
|
|
// JSONArray lines = JSONUtil.parseObj(ss).getJSONArray("pathLine");
|