wenhongquan 1 年之前
父節點
當前提交
a6ed6c956d

+ 2 - 0
ruoyi-modules/ruoyi-khy/src/main/java/org/dromara/netty/Decode.java

@@ -47,7 +47,9 @@ public class Decode extends MessageToMessageDecoder {
     @Override
     public void channelInactive(ChannelHandlerContext ctx) throws Exception {
         super.channelInactive(ctx);
+
         NettyChannelHandlerContextMapCache.ChannelMapCache.remove(ctx.channel().toString());
+        ctx.channel().close();
     }
 
 }

+ 13 - 3
ruoyi-modules/ruoyi-khy/src/main/java/org/dromara/system/controller/CommonController.java

@@ -136,9 +136,19 @@ public class CommonController extends BaseController {
         for (Object key :   CacheUtils.keys("playlist")) {
             data.add((Map<String,String>) CacheUtils.get("playlist",key));
         }
-        data.sort((o1, o2) -> {
-            return Math.toIntExact(DateUtil.parseDateTime(o2.get("time")).getTime() - DateUtil.parseDateTime(o1.get("time")).getTime());
-        });
+        if(data.size()<1) return data;
+        try {
+            data.sort((o1, o2) -> {
+                try {
+                    return Math.toIntExact(DateUtil.parseDateTime(o2.get("time")).getTime() - DateUtil.parseDateTime(o1.get("time")).getTime());
+                } catch (Exception e) {
+                    log.error(e.getMessage());
+                    log.error(o1.get("time"));
+                    log.error(o2.get("time"));
+                    return -1;
+                }
+            });
+        }catch (Exception e){}
         if(data.size()<10) return data;
         return data.subList(0,10);
     }

+ 32 - 7
ruoyi-modules/ruoyi-khy/src/main/java/org/dromara/util/CabinetUtil.java

@@ -27,10 +27,12 @@ import org.dromara.system.service.impl.TblCarInfoServiceImpl;
 import org.dromara.system.service.impl.TblCarScheduleServiceImpl;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
 import javax.crypto.Cipher;
+import java.io.UnsupportedEncodingException;
 import java.security.Key;
 import java.text.DateFormat;
 import java.util.ArrayList;
@@ -41,6 +43,9 @@ import java.util.Map;
 @Component
 public class CabinetUtil {
 
+    @Autowired
+    ISysDictDataService sysDictDataService;
+
     private  final static String appid = "bw_open_express_A8C848769E5C04E0";
     private  final static String appkey = "5AFC6E07CFCF4A359B775D1416A9799A";
 
@@ -133,8 +138,8 @@ public class CabinetUtil {
         }
 
     }
-     @Scheduled(fixedRate = 5*60*1000)
-     private void getGpsList(){
+    @Scheduled(fixedRate = 5*60*1000)
+    private void getGpsList(){
          List<TblCarInfoVo> carInfoVos = SpringUtils.getBean(TblCarInfoServiceImpl.class).queryList(new TblCarInfoBo());
          for (TblCarInfoVo car : carInfoVos) {
              if(StrUtil.isNotEmpty(car.getDeviceInfos())){
@@ -163,9 +168,6 @@ public class CabinetUtil {
          }
 
      }
-
-
-
     @Scheduled(fixedRate = 5*60*1000)
     private void getList(){
         //获取所有gps 判断是否离线
@@ -244,8 +246,31 @@ public class CabinetUtil {
     }
 
 
-
-
+    @Scheduled(fixedRate = 5*60*1000)
+    private void resetStationLed() throws UnsupportedEncodingException {
+        //获取所有站点led
+        SysDictDataBo bo =new SysDictDataBo();
+        bo.setDictType("tbl_sites");
+        List<SysDictDataVo> allstations = sysDictDataService.selectDictDataList(bo);
+        for (SysDictDataVo station:allstations) {
+            //获取led
+            if(StringUtils.isNotEmpty(station.getRemark())) {
+                List<JSONObject> devicedatas = JSONUtil.parseArray(station.getRemark()).toList(JSONObject.class);
+                for (JSONObject i :devicedatas) {
+                    if(i.getStr("type").equals("led")){
+                        //查询缓存是否播放过
+                        Object time = RedisUtils.getCacheMapValue("station_led",station.getDictLabel());
+                        try {
+                            if (time != null && DateUtil.current() - Long.parseLong(time.toString()) < 1000 *60* 5) {
+                                continue;
+                            }
+                        }catch (Exception e){}
+                        MessageUtils.sendLed(i.getStr("code"),StringUtils.isNotEmpty( station.getCssClass())? station.getCssClass(): StringUtils.format("{}快梯柜",station.getDictLabel()));
+                    }
+                }
+            }
+        }
+    }
 
     // 获取柜子信息
     public static  String getCabinetInfo(String cabinetCode) throws Exception {

+ 78 - 70
ruoyi-modules/ruoyi-khy/src/main/java/org/dromara/util/CamelDataUtil.java

@@ -1,6 +1,7 @@
 package org.dromara.util;
 
 import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.thread.ThreadUtil;
 import cn.hutool.core.util.CharsetUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.json.JSON;
@@ -109,7 +110,7 @@ public class CamelDataUtil {
         RedisUtils.setCacheObject(StringUtils.format("gps_{}", gpsData.getDevicecode()), gpsData);
 
 
-        threadPoolExecutor.execute(new Runnable() {
+        ThreadUtil.execAsync(new Runnable() {
             @Override
             public void run() {
 
@@ -240,6 +241,7 @@ public class CamelDataUtil {
                                                     CamelDataUtil.setPlayList(carInfoVo1.getCarNum(),o);
                                                     for (JSONObject i :devicedatas) {
                                                         if(i.getStr("type").equals("led")){
+                                                            RedisUtils.setCacheMapValue("station_led",stations.get(0).getDictLabel(),  DateUtil.current());
                                                             MessageUtils.sendLed(i.getStr("code"), message);
                                                         }
                                                         if(i.getStr("type").equals("tts")){
@@ -264,83 +266,86 @@ public class CamelDataUtil {
                                 }
                             }else{
                                 //无路线无排班车辆
-
-                                String configdistance = SpringUtils.getBean(ISysConfigService.class).selectConfigByKey("sys.car5.distance");
-                                String configtime = SpringUtils.getBean(ISysConfigService.class).selectConfigByKey("sys.car5.time");
-                                String text = SpringUtils.getBean(ISysConfigService.class).selectConfigByKey("sys.car5.text");
-                                if(StrUtil.isEmptyIfStr(configdistance)) configdistance="500";
-                                if(StrUtil.isEmptyIfStr(configtime)) configtime="180000";
-                                //查询所有站点经纬
-                                SysDictDataBo bo =new SysDictDataBo();
-                                bo.setDictType("tbl_sites");
-                                List<SysDictDataVo> allstations = sysDictDataService.selectDictDataList(bo);
-                                //循环计算站点与车的距离
-                                for (SysDictDataVo station : allstations){
-                                    if(station.getDictValue()!=null && StrUtil.isNotEmpty(station.getDictValue()) && station.getDictValue().contains(",")){
-                                        try{
-                                            if(DistanceCalculator.calculateDistance(station.getDictValue(),StringUtils.format("{},{}", gpsData.getLng(),gpsData.getLat()))<Integer.parseInt(configdistance)){
-                                                //在范围内
-                                                //查看是否在单位时间内播报过
-                                                Long time = RedisUtils.getCacheObject(StringUtils.format("car_{}_{}_station",carInfoVo1.getCarNum(),station.getDictCode()));
-                                                boolean canbobao = false;
-                                                if(time==null){
-                                                    //未报过
-                                                    canbobao = true;
-                                                }else{
-                                                    if(System.currentTimeMillis()-time<Integer.parseInt(configtime)){
-                                                        //在单位时间内播报过
-                                                        continue;
-                                                    }else{
-                                                        //在单位时间内未播报过
+                                if(carInfoVo1.getCarType().equals("1")){
+                                    //五座车报站
+                                    String configdistance = SpringUtils.getBean(ISysConfigService.class).selectConfigByKey("sys.car5.distance");
+                                    String configtime = SpringUtils.getBean(ISysConfigService.class).selectConfigByKey("sys.car5.time");
+                                    String text = SpringUtils.getBean(ISysConfigService.class).selectConfigByKey("sys.car5.text");
+                                    if(StrUtil.isEmptyIfStr(configdistance)) configdistance="500";
+                                    if(StrUtil.isEmptyIfStr(configtime)) configtime="180000";
+                                    //查询所有站点经纬
+                                    SysDictDataBo bo =new SysDictDataBo();
+                                    bo.setDictType("tbl_sites");
+                                    List<SysDictDataVo> allstations = sysDictDataService.selectDictDataList(bo);
+                                    //循环计算站点与车的距离
+                                    for (SysDictDataVo station : allstations){
+                                        if(station.getDictValue()!=null && StrUtil.isNotEmpty(station.getDictValue()) && station.getDictValue().contains(",")){
+                                            try{
+                                                if(DistanceCalculator.calculateDistance(station.getDictValue(),StringUtils.format("{},{}", gpsData.getLng(),gpsData.getLat()))<Integer.parseInt(configdistance)){
+                                                    //在范围内
+                                                    //查看是否在单位时间内播报过
+                                                    Long time = RedisUtils.getCacheObject(StringUtils.format("car_{}_{}_station",carInfoVo1.getCarNum(),station.getDictCode()));
+                                                    boolean canbobao = false;
+                                                    if(time==null){
+                                                        //未报过
                                                         canbobao = true;
+                                                    }else{
+                                                        if(System.currentTimeMillis()-time<Integer.parseInt(configtime)){
+                                                            //在单位时间内播报过
+                                                            continue;
+                                                        }else{
+                                                            //在单位时间内未播报过
+                                                            canbobao = true;
+                                                        }
                                                     }
-                                                }
-                                                if(canbobao){
-                                                   String lastStationCode =  RedisUtils.getCacheObject(StringUtils.format("car_{}_last_bb_station",carInfoVo1.getCarNum()));
-                                                   if(lastStationCode!=null && lastStationCode.equals(station.getDictCode().toString())){
-                                                       canbobao = false;
-                                                   }
-                                                }
-                                                if(canbobao){
-
-                                                    //设置播报站播报时间
-                                                    RedisUtils.setCacheObject(StringUtils.format("car_{}_{}_station",carInfoVo1.getCarNum(),station.getDictCode()),DateUtil.current());
-                                                    //设置播报站
-                                                    RedisUtils.setCacheObject(StringUtils.format("car_{}_last_bb_station",carInfoVo1.getCarNum()),station.getDictCode().toString());
-
-                                                    //满足条件播报(led or 广播)
-                                                    String message = StringUtils.format(text, carInfoVo1.getCarNum(),station.getDictLabel());
-                                                    if(StringUtils.isNotEmpty(station.getRemark())){
-                                                        List<JSONObject> devicedatas = JSONUtil.parseArray( station.getRemark()).toList(JSONObject.class);
-                                                        Map<String,String> o = new HashMap<>();
-                                                        o.put("station",station.getDictLabel());
-                                                        o.put("time",DateUtil.now());
-                                                        o.put("carNum",carInfoVo1.getCarNum());
-                                                        o.put("type",carInfoVo1.getCarType());
-                                                        o.put("msg",message);
-                                                        CamelDataUtil.setPlayList(carInfoVo1.getCarNum(),o);
-                                                        for (JSONObject i :devicedatas) {
-                                                            if(i.getStr("type").equals("led")){
-                                                                MessageUtils.sendLed(i.getStr("code"), message);
-                                                            }
-                                                            if(i.getStr("type").equals("tts")){
-                                                                MessageUtils.sendTTs(i.getStr("code"), message);
+                                                    if(canbobao){
+                                                        String lastStationCode =  RedisUtils.getCacheObject(StringUtils.format("car_{}_last_bb_station",carInfoVo1.getCarNum()));
+                                                        if(lastStationCode!=null && lastStationCode.equals(station.getDictCode().toString())){
+                                                            canbobao = false;
+                                                        }
+                                                    }
+                                                    if(canbobao){
+
+                                                        //设置播报站播报时间
+                                                        RedisUtils.setCacheObject(StringUtils.format("car_{}_{}_station",carInfoVo1.getCarNum(),station.getDictCode()),DateUtil.current());
+                                                        //设置播报站
+                                                        RedisUtils.setCacheObject(StringUtils.format("car_{}_last_bb_station",carInfoVo1.getCarNum()),station.getDictCode().toString());
+
+                                                        //满足条件播报(led or 广播)
+                                                        String message = StringUtils.format(text, carInfoVo1.getCarNum(),station.getDictLabel());
+                                                        if(StringUtils.isNotEmpty(station.getRemark())){
+                                                            List<JSONObject> devicedatas = JSONUtil.parseArray( station.getRemark()).toList(JSONObject.class);
+                                                            Map<String,String> o = new HashMap<>();
+                                                            o.put("station",station.getDictLabel());
+                                                            o.put("time",DateUtil.now());
+                                                            o.put("carNum",carInfoVo1.getCarNum());
+                                                            o.put("type",carInfoVo1.getCarType());
+                                                            o.put("msg",message);
+                                                            CamelDataUtil.setPlayList(carInfoVo1.getCarNum(),o);
+                                                            for (JSONObject i :devicedatas) {
+                                                                if(i.getStr("type").equals("led")){
+                                                                    RedisUtils.setCacheMapValue("station_led",station.getDictLabel(), DateUtil.current());
+                                                                    MessageUtils.sendLed(i.getStr("code"), message);
+                                                                }
+                                                                if(i.getStr("type").equals("tts")){
+                                                                    MessageUtils.sendTTs(i.getStr("code"), message);
+                                                                }
                                                             }
                                                         }
                                                     }
+
+                                                }else{
+                                                    continue;
                                                 }
 
-                                            }else{
-                                                continue;
+                                            }catch (Exception e){
+                                                log.error("--------5座车计算经纬错误-------------");
+                                                log.error(e.getMessage());
+                                                log.error("-------5座车计算经纬错误--------------");
                                             }
-
-                                        }catch (Exception e){
-                                            log.error("--------5座车计算经纬错误-------------");
-                                            log.error(e.getMessage());
-                                            log.error("-------5座车计算经纬错误--------------");
                                         }
-                                    }
 
+                                    }
                                 }
 
                             }
@@ -423,8 +428,11 @@ public class CamelDataUtil {
                         countData.setTslong(iCreatedTime*1000);
                         countDataService.insertData(countData);
                     }else{
-                        log.error("{}:时间错误",iCreatedTime);
-
+                        log.error("{}--{}:时间错误",sn,iCreatedTime);
+                        //断开
+//                        NettyChannelHandlerContext ctx = ChannelMapCache.get(((ChannelHandlerContext)exchange.getIn().getHeader("CamelNettyChannelHandlerContext")).channel().toString());
+//                        ctx.getChannelHandlerContext().close();
+//                        return;
                     }
                     //存储数据
 //                log.info("{},{},{},{},{}",sn,type,in,out,iCreatedTime);