فهرست منبع

`fix 站点播报`

wenhongquan 2 سال پیش
والد
کامیت
e5df5eaa28

+ 5 - 0
ruoyi-modules/ruoyi-khy/src/main/java/org/dromara/system/service/impl/TblCarScheduleServiceImpl.java

@@ -62,7 +62,12 @@ public class TblCarScheduleServiceImpl implements ITblCarScheduleService {
         Map<String, Object> params = bo.getParams();
         LambdaQueryWrapper<TblCarSchedule> lqw = Wrappers.lambdaQuery();
         lqw.eq(StringUtils.isNotBlank(bo.getPathInfo()), TblCarSchedule::getPathInfo, bo.getPathInfo());
+        lqw.eq(StringUtils.isNotBlank(bo.getCarNum()), TblCarSchedule::getCarNum, bo.getCarNum());
         lqw.eq(bo.getScheduleDate() != null, TblCarSchedule::getScheduleDate, bo.getScheduleDate());
+        if(bo.getParams()!=null && bo.getParams().keySet().size()>0){
+            lqw.gt(bo.getParams().get("scheduleDate")!=null, TblCarSchedule::getScheduleDate, bo.getParams().get("scheduleDate"));
+        }
+        lqw.orderBy(true,true,TblCarSchedule::getScheduleDate);
         return lqw;
     }
 

+ 85 - 9
ruoyi-modules/ruoyi-khy/src/main/java/org/dromara/util/CamelDataUtil.java

@@ -1,28 +1,37 @@
 package org.dromara.util;
 
 import cn.hutool.json.JSON;
+import cn.hutool.json.JSONArray;
 import cn.hutool.json.JSONUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
 import org.apache.camel.ProducerTemplate;
+import org.apache.commons.lang3.time.DateFormatUtils;
 import org.dromara.common.core.constant.Constants;
+import org.dromara.common.core.utils.DateUtils;
+import org.dromara.common.core.utils.SpringUtils;
 import org.dromara.common.core.utils.StringUtils;
 import org.dromara.common.redis.utils.RedisUtils;
 import org.dromara.sms4j.api.universal.RedisUtil;
 import org.dromara.system.domain.GpsData;
+import org.dromara.system.domain.SysDictData;
 import org.dromara.system.domain.TblCarInfo;
+import org.dromara.system.domain.bo.SysDictDataBo;
 import org.dromara.system.domain.bo.TblCarInfoBo;
+import org.dromara.system.domain.bo.TblCarScheduleBo;
+import org.dromara.system.domain.vo.SysDictDataVo;
 import org.dromara.system.domain.vo.TblCarInfoVo;
-import org.dromara.system.service.ISysDictDataService;
-import org.dromara.system.service.ITblCarInfoService;
-import org.dromara.system.service.ITblCarPathService;
-import org.dromara.system.service.ITblGpsDataService;
+import org.dromara.system.domain.vo.TblCarScheduleVo;
+import org.dromara.system.service.*;
 import org.springframework.beans.factory.annotation.Autowired;
+import cn.hutool.json.JSONObject;
 import org.springframework.stereotype.Component;
 
 import java.io.UnsupportedEncodingException;
 import java.time.Duration;
+import java.util.Calendar;
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
@@ -40,7 +49,7 @@ public class CamelDataUtil {
     ITblCarInfoService tblCarInfoService;
 
     @Autowired
-    ITblCarPathService tablCarPathService;
+    ITblCarScheduleService tblCarScheduleService;
 
     @Autowired
     ISysDictDataService sysDictDataService;
@@ -93,14 +102,81 @@ public class CamelDataUtil {
                             carInfoBo1.setCarNum(carInfoVo.getCarNum());
                             List<TblCarInfoVo> carInfoVos1 =  tblCarInfoService.queryList(carInfoBo1);
                             if(carInfoVos1.size()>0){
+                                // 查询车辆信息
                                 TblCarInfoVo carInfoVo1 = carInfoVos1.get(0);
+                                TblCarScheduleBo tblCarScheduleBo = new TblCarScheduleBo();
+                                tblCarScheduleBo.setCarNum(carInfoVo1.getCarNum());
+                                Map<String, Object> map = Map.of("scheduleDate", DateUtils.parseDate(DateUtils.getDate()+" 00:00:00") );
+                                tblCarScheduleBo.setParams(map);
+                                List<TblCarScheduleVo>  list =  tblCarScheduleService.queryList(tblCarScheduleBo);
+                                if(list.size()>0){
+                                    long t0 = 10;
+                                    TblCarScheduleVo scheduleVo = null;
+                                    for (TblCarScheduleVo vo : list) {
+                                        if(vo.getScheduleDate().getTime()-DateUtils.getNowDate().getTime()<0){
+                                            if(t0>0){
+                                                t0 = vo.getScheduleDate().getTime()-DateUtils.getNowDate().getTime();
+                                                scheduleVo = vo;
+                                            }
+                                            if(t0<vo.getScheduleDate().getTime()-DateUtils.getNowDate().getTime()){
+                                                t0 = vo.getScheduleDate().getTime()-DateUtils.getNowDate().getTime();
+                                                scheduleVo = vo;
+                                            }
+                                        }
+                                    }
+                                    //  查询路线信息
+                                    if(scheduleVo!=null){
+                                        try{
+                                            JSONArray lines = JSONUtil.parseObj(scheduleVo.getPathInfo()).getJSONArray("pathLine");
+                                            for (JSONObject jsonObject : lines.toList(JSONObject.class)) {
+                                               double distance =  DistanceCalculator.calculateDistance(jsonObject.getStr("location"),StringUtils.format("{},{}", gpsData.getLng(),gpsData.getLat()));
+                                               String configdistance = SpringUtils.getBean(ISysConfigService.class).selectConfigByKey("sys.car.distance");
+                                               if(Double.parseDouble(configdistance)>distance){
+                                                   //靠近站点
+                                                   String stationName =  RedisUtils.getCacheObject(StringUtils.format("car_{}_{}_tip",carInfoVo1.getCarNum(),DateFormatUtils.format( scheduleVo.getScheduleDate(),DateUtils.YYYYMMDDHHMMSS) ));
+                                                   if(stationName!=null && stationName.contains(jsonObject.getStr("stationName"))){
+                                                       //提报过的不再提报
+
+                                                   }else{
+                                                       stationName=stationName==null?"":stationName;
+                                                       RedisUtils.setCacheObject(StringUtils.format("car_{}_{}_tip",carInfoVo1.getCarNum(), DateFormatUtils.format( scheduleVo.getScheduleDate(),DateUtils.YYYYMMDDHHMMSS) ), stationName+","+jsonObject.getStr("stationName"),Duration.ofSeconds(3600*24));
+                                                       //开始播报
+                                                       //获取站点设备信息
+                                                       SysDictDataBo sysDictData =  new SysDictDataBo();
+                                                       sysDictData.setDictLabel(jsonObject.getStr("stationName"));
+                                                       sysDictData.setDictType("tbl_sites");
+                                                       List<SysDictDataVo> stations = sysDictDataService.selectDictDataList(sysDictData);
+                                                       if(stations.size()>0){
+                                                           //满足条件播报(led or 广播)
+                                                           String message = StringUtils.format("{}即将到达,请准备接车,请等待。。。", carInfoVo1.getCarNum());
+                                                           List<JSONObject> devicedatas = JSONUtil.parseArray( stations.get(0).getRemark()).toList(JSONObject.class);
+                                                           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);
+                                                               }
+                                                           }
+                                                       }
+
+
+                                                   }
+
+                                               }
+                                            }
+
+
+                                        }catch (Exception e){
+                                            log.error("---------------------");
+                                            log.error(e.getMessage());
+                                            log.error("---------------------");
+                                        }
+                                    }
+                                }
                             }
                         }
-
                     }
-
-                    // 查询车辆信息 查询路线信息 查询下个站点信息(包括站点设备) 计算经纬距离 满足条件播报(led or 广播)
-                    System.out.println("---------");
                 }
             });
         }

+ 39 - 0
ruoyi-modules/ruoyi-khy/src/main/java/org/dromara/util/DistanceCalculator.java

@@ -0,0 +1,39 @@
+package org.dromara.util;
+import java.lang.Math;
+
+public class DistanceCalculator {
+    private static final double EARTH_RADIUS = 6371000; // 地球平均半径(单位:米)
+
+    public static void main(String[] args) {
+        double lat1 = 40.7128; // 第一个点的纬度
+        double lon1 = -74.0060; // 第一个点的经度
+
+        double lat2 = 51.5074; // 第二个点的纬度
+        double lon2 = -0.1278; // 第二个点的经度
+
+        double distanceInMeters = calculateDistance(lat1, lon1, lat2, lon2);
+        System.out.println("两个点之间的距离为:" + distanceInMeters + " 米");
+    }
+
+    public static double calculateDistance(String location1, String location2) {
+        String[] loat1 = location1.split(",");
+        String[] loat2 = location1.split(",");
+        return calculateDistance(Double.parseDouble(loat1[1]), Double.parseDouble(loat1[0]), Double.parseDouble(loat2[1]), Double.parseDouble(loat2[0]));
+    }
+
+    public static double calculateDistance(double lat1, double lon1, double lat2, double lon2) {
+        double radLat1 = Math.toRadians(lat1);
+        double radLon1 = Math.toRadians(lon1);
+        double radLat2 = Math.toRadians(lat2);
+        double radLon2 = Math.toRadians(lon2);
+
+        double a = Math.sin((radLat2-radLat1)/2) * Math.sin((radLat2-radLat1)/2) +
+            Math.cos(radLat1) * Math.cos(radLat2) *
+                Math.sin((radLon2-radLon1)/2) * Math.sin((radLon2-radLon1)/2);
+
+        double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
+        double distance = EARTH_RADIUS * c;
+
+        return distance;
+    }
+}