wenhongquan 2 лет назад
Родитель
Сommit
b3bb6434f4

+ 3 - 0
ruoyi-modules/ruoyi-khy/src/main/java/org/dromara/system/domain/vo/TblCarScheduleVo.java

@@ -51,4 +51,7 @@ public class TblCarScheduleVo implements Serializable {
     @ExcelProperty(value = "车牌")
     private String carNum;
 
+
+    private String stationInfo;
+
 }

+ 13 - 2
ruoyi-modules/ruoyi-khy/src/main/java/org/dromara/system/service/impl/TblCarInfoServiceImpl.java

@@ -1,5 +1,7 @@
 package org.dromara.system.service.impl;
 
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
 import org.dromara.common.core.utils.MapstructUtils;
 import org.dromara.common.core.utils.StringUtils;
 import org.dromara.common.mybatis.core.page.TableDataInfo;
@@ -43,7 +45,11 @@ public class TblCarInfoServiceImpl implements ITblCarInfoService {
     @Override
     public TblCarInfoVo queryById(Long id){
         TblCarInfoVo carInfoVo = baseMapper.selectVoById(id);
-        carInfoVo.setLocation(RedisUtils.getCacheObject(StringUtils.format("gps_{}", id)));
+        JSONUtil.parseArray(carInfoVo.getDeviceInfos()).toList(JSONObject.class).forEach(deviceInfo -> {
+            if(deviceInfo.getStr("type").equals("gps")){
+                carInfoVo.setLocation(RedisUtils.getCacheObject(StringUtils.format("gps_{}", deviceInfo.getStr("code"))));
+            }
+        });
         return carInfoVo;
     }
 
@@ -55,7 +61,12 @@ public class TblCarInfoServiceImpl implements ITblCarInfoService {
         LambdaQueryWrapper<TblCarInfo> lqw = buildQueryWrapper(bo);
         Page<TblCarInfoVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
         result.getRecords().forEach(carInfoVo -> {
-            carInfoVo.setLocation(RedisUtils.getCacheObject(StringUtils.format("gps_{}", carInfoVo.getId())));
+            JSONUtil.parseArray(carInfoVo.getDeviceInfos()).toList(JSONObject.class).forEach(deviceInfo -> {
+                if(deviceInfo.getStr("type").equals("gps")){
+                    carInfoVo.setLocation(RedisUtils.getCacheObject(StringUtils.format("gps_{}", deviceInfo.getStr("code"))));
+                }
+            });
+
         });
         return TableDataInfo.build(result);
     }

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

@@ -1,5 +1,6 @@
 package org.dromara.system.service.impl;
 
+import org.apache.commons.lang3.time.DateFormatUtils;
 import org.dromara.common.core.utils.DateUtils;
 import org.dromara.common.core.utils.MapstructUtils;
 import org.dromara.common.core.utils.StringUtils;
@@ -9,6 +10,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import lombok.RequiredArgsConstructor;
+import org.dromara.common.redis.utils.RedisUtils;
 import org.springframework.stereotype.Service;
 import org.dromara.system.domain.bo.TblCarScheduleBo;
 import org.dromara.system.domain.vo.TblCarScheduleVo;
@@ -48,6 +50,14 @@ public class TblCarScheduleServiceImpl implements ITblCarScheduleService {
     public TableDataInfo<TblCarScheduleVo> queryPageList(TblCarScheduleBo bo, PageQuery pageQuery) {
         LambdaQueryWrapper<TblCarSchedule> lqw = buildQueryWrapper(bo);
         Page<TblCarScheduleVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
+
+        result.getRecords().forEach(e -> {
+            String stations = RedisUtils.getCacheObject(StringUtils.format("car_{}_{}_current_station",e.getCarNum(), DateFormatUtils.format( e.getScheduleDate(),DateUtils.YYYYMMDDHHMMSS)));
+            String stationName =  RedisUtils.getCacheObject(StringUtils.format("car_{}_{}_tip",e.getCarNum(),DateFormatUtils.format( e.getScheduleDate(),DateUtils.YYYYMMDDHHMMSS) ));
+//            String gpsinfo = RedisUtils.getCacheObject(StringUtils.format("gps_{}", id));
+            e.setStationInfo(StringUtils.format("{\"currentStation\":\"{}\",\"passStations\":\"{}\"}",stations,stationName));
+        });
+
         return TableDataInfo.build(result);
     }
 

+ 47 - 28
ruoyi-modules/ruoyi-khy/src/main/java/org/dromara/util/CamelDataUtil.java

@@ -31,10 +31,7 @@ import org.springframework.stereotype.Component;
 import java.io.UnsupportedEncodingException;
 import java.nio.charset.Charset;
 import java.time.Duration;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 @Slf4j
 @Component("camelDataUtil")
@@ -121,42 +118,55 @@ public class CamelDataUtil {
                                 if(scheduleVo!=null){
                                     try{
                                         JSONArray lines = JSONUtil.parseObj(scheduleVo.getPathInfo()).getJSONArray("pathLine");
+                                        List<JSONObject> lines1 = lines.toList(JSONObject.class);
                                         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 stations = RedisUtils.getCacheObject(StringUtils.format("car_{}_{}_current_station",carInfoVo1.getCarNum(),DateFormatUtils.format( scheduleVo.getScheduleDate(),DateUtils.YYYYMMDDHHMMSS)));
+                                                RedisUtils.setCacheObject(StringUtils.format("car_{}_{}_current_station",carInfoVo1.getCarNum(),DateFormatUtils.format( scheduleVo.getScheduleDate(),DateUtils.YYYYMMDDHHMMSS)),stations+","+jsonObject.getStr("stationName"));
+                                                //靠近站点 还得计算当前是否跨站点
                                                 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);
-                                                            }
-                                                        }
-                                                    }
+                                                   lines1.add(jsonObject);
+                                                }
+                                            }
+                                        }
 
+                                        if(lines1.size()>0){
+                                            //先判断是否跨站点
+                                            if(lines1.size()>1){
+                                                lines1.sort(Comparator.comparingInt((JSONObject o) -> o.getInt("order")));
+                                            }
 
+                                            JSONObject jsonObject = lines1.get(0);
+                                            String stationName =  RedisUtils.getCacheObject(StringUtils.format("car_{}_{}_tip",carInfoVo1.getCarNum(),DateFormatUtils.format( scheduleVo.getScheduleDate(),DateUtils.YYYYMMDDHHMMSS) ));
+                                            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);
+                                                    }
                                                 }
-
                                             }
+
+                                        }else{
+                                            RedisUtils.setCacheObject(StringUtils.format("car_{}_{}_current_station",carInfoVo1.getCarNum(),DateFormatUtils.format( scheduleVo.getScheduleDate(),DateUtils.YYYYMMDDHHMMSS)),"");
                                         }
 
 
@@ -191,4 +201,13 @@ public class CamelDataUtil {
 
         log.info("body:{}",body);
     }
+
+
+//    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\"}";
+//        JSONArray lines = JSONUtil.parseObj(ss).getJSONArray("pathLine");
+//        List<JSONObject> lines1 = lines.toList(JSONObject.class);
+//        lines1.sort(Comparator.comparingInt((JSONObject o) -> o.getInt("order")));
+//        System.out.println(lines1.get(0).toStringPretty());
+//    }
 }