wenhongquan hai 1 ano
pai
achega
5863dedb8d

+ 2 - 0
ruoyi-admin/src/main/java/org/dromara/DromaraApplication.java

@@ -6,6 +6,7 @@ import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup;
 import org.springframework.context.annotation.ComponentScan;
+import org.springframework.scheduling.annotation.EnableScheduling;
 
 /**
  * 启动程序
@@ -14,6 +15,7 @@ import org.springframework.context.annotation.ComponentScan;
  */
 
 @SpringBootApplication
+@EnableScheduling
 public class DromaraApplication {
 
     public static void main(String[] args) {

+ 95 - 2
ruoyi-modules/ruoyi-khy/src/main/java/org/dromara/system/controller/CommonController.java

@@ -1,6 +1,10 @@
 package org.dromara.system.controller;
 
 import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
 import com.dtflys.forest.backend.okhttp3.OkHttp3;
 import jakarta.annotation.Resource;
 import lombok.RequiredArgsConstructor;
@@ -8,12 +12,17 @@ import lombok.extern.slf4j.Slf4j;
 import okhttp3.OkHttpClient;
 import okhttp3.Request;
 import org.dromara.common.core.domain.R;
+import org.dromara.common.core.utils.SpringUtils;
 import org.dromara.common.mybatis.core.page.PageQuery;
 import org.dromara.common.mybatis.core.page.TableDataInfo;
+import org.dromara.common.redis.utils.CacheUtils;
 import org.dromara.common.redis.utils.RedisUtils;
 import org.dromara.common.web.core.BaseController;
+import org.dromara.system.domain.bo.SysDictDataBo;
 import org.dromara.system.domain.bo.TblCarInfoBo;
+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.ITblCarDriveWarningService;
 import org.dromara.util.CabinetUtil;
 import org.dromara.util.MessageUtils;
@@ -28,6 +37,9 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import static org.dromara.util.CabinetUtil.CABINET_BOXS;
+import static org.dromara.util.CabinetUtil.CABINET_INFO;
+
 @Validated
 @RequiredArgsConstructor
 @RestController
@@ -117,6 +129,87 @@ public class CommonController extends BaseController {
 
     }
 
+    @PostMapping("/playlist/static")
+    public Object playlistInfo() throws Exception {
+
+        List<Map<String,String>> data = new ArrayList<>();
+        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()<10) return data;
+        return data.subList(0,10);
+    }
+
+
+
+    /**
+     * 获取柜子统计信息
+     * @return
+     * @throws Exception
+     */
+    @PostMapping("/cabinet/boxstatic")
+    public Object cabinetInfo() throws Exception {
+        Map<String,Object> data = new HashMap<>();
+        CacheUtils.keys(CABINET_INFO).forEach(item->{
+            if(item.toString().contains("box")){
+                data.put(item.toString(),CacheUtils.get(CABINET_INFO,item));
+            }
+        });
+
+        return data;
+    }
+
+    @PostMapping("/devicemsg")
+    public Object devicemsg() throws Exception {
+        Map<String,Object> data = new HashMap<>();
+        CacheUtils.keys("offline").forEach(item->{
+            Map<String,Object> c = new HashMap<>();
+            if(CacheUtils.get("offline",item) instanceof  String){
+                CacheUtils.put("offline",item,new HashMap<>());
+            }else{
+                c = CacheUtils.get("offline",item);
+                if(c.keySet().size()>0){
+                    data.put(item.toString(),c);
+                }
+            }
+        });
+        return data;
+    }
+
+
+
+    @PostMapping("/station/devs")
+    public Object stationDevs() throws Exception {
+        Map<String,Map<String,String>> devMap = new HashMap<>();
+        SysDictDataBo bo =new SysDictDataBo();
+        bo.setDictType("tbl_sites");
+        List<SysDictDataVo> list = SpringUtils.getBean(ISysDictDataService.class).selectDictDataList(bo);
+        try {
+            list.forEach(item->{
+                if(StrUtil.isNotEmpty(item.getRemark())){
+                    JSONArray jsonArray = JSONUtil.parseArray(item.getRemark());
+                    jsonArray.forEach(item2->{
+                        Map<String,String> c =new HashMap<>();
+                        c.put("name",((JSONObject)item2).getStr("name"));
+                        c.put("offline","0");
+                        if(((JSONObject)item2).getStr("type").equals("cabinet")){
+                           Map offline = CacheUtils.get("offline",((JSONObject)item2).getStr("code"));
+                           if(offline.keySet().size()>0){
+                               c.put("offline","1");
+                           }
+                        }
+                        devMap.put(((JSONObject)item2).getStr("type")+((JSONObject)item2).getStr("code"),c);
+                    });
+                }
+            });
+        }catch (Exception e){
+
+        }
+        return devMap;
+    }
 
     /**
      * 通过POST请求获取指定柜子的信息。
@@ -130,7 +223,7 @@ public class CommonController extends BaseController {
      */
     @PostMapping("/cabinet/{code}/info")
     public Object cabinetInfo(@PathVariable String code) throws Exception {
-        return  CabinetUtil.getCabinetInfo(code);
+        return CacheUtils.get(CABINET_INFO,code);
     }
 
     /**
@@ -145,7 +238,7 @@ public class CommonController extends BaseController {
      */
     @PostMapping("/cabinet/{code}/allbox/info")
     public Object cabinetBoxInfo(@PathVariable String code) throws Exception {
-        return  CabinetUtil.getCabinetBoxs(code);
+        return CacheUtils.get(CABINET_BOXS,code);
     }
 
     /**

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

@@ -111,21 +111,25 @@ public class TblCarInfoServiceImpl implements ITblCarInfoService {
         Map<String,List<CountDataVo>> countDataMap = new HashMap<>();
         //查流量
         if(codes.size()>0){
-            CountDataBo q = new CountDataBo();
-            q.setParams(bo.getParams());
-            q.getParams().put("deviceCodes",codes);
-           List<CountDataVo> countDataList = countDataMapper.queryList(q);
-            if(countDataList.size()>0){
-                countDataList.forEach(countData -> {
-                    if(countDataMap.get(countData.getDevicecode())==null){
-                        List<CountDataVo> countDataList1 = new ArrayList<>();
-                        countDataList1.add(countData);
-                        countDataMap.put(countData.getDevicecode(),countDataList1);
-                    }else{
-                        countDataMap.get(countData.getDevicecode()).add(countData);
-                    }
-                });
-            }
+            codes.forEach(code->{
+                CountDataBo q = new CountDataBo();
+                q.setParams(bo.getParams());
+                q.getParams().put("deviceCodes",code);
+                List<CountDataVo> countDataList = countDataMapper.queryList(q);
+                if(countDataList.size()>0){
+                    countDataList.forEach(countData -> {
+                        if(countDataMap.get(countData.getDevicecode())==null){
+                            List<CountDataVo> countDataList1 = new ArrayList<>();
+                            countDataList1.add(countData);
+                            countDataMap.put(countData.getDevicecode(),countDataList1);
+                        }else{
+                            countDataMap.get(countData.getDevicecode()).add(countData);
+                        }
+                    });
+                }
+
+            });
+
         }
         try {
 

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

@@ -76,7 +76,11 @@ public class TblCountDataServiceImpl implements ITblCountDataService {
                 lqw.lt(bo.getParams().get("endtime") != null, CountData::getTs, bo.getParams().get("endtime"));
             }
             if(bo.getParams().get("deviceCodes")!=null){
-                lqw.in(CountData::getDevicecode, String.join(",",(List) bo.getParams().get("deviceCodes")));
+                if(bo.getParams().get("deviceCodes") instanceof List){
+                    lqw.in(CountData::getDevicecode, String.join(",",(List) bo.getParams().get("deviceCodes")));
+                }else{
+                    lqw.eq(CountData::getDevicecode, bo.getParams().get("deviceCodes"));
+                }
             }
         }
 

+ 142 - 0
ruoyi-modules/ruoyi-khy/src/main/java/org/dromara/util/CabinetUtil.java

@@ -1,13 +1,39 @@
 package org.dromara.util;
 
+import cn.hutool.core.date.DatePattern;
 import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.StrUtil;
 import cn.hutool.http.HttpRequest;
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
 import com.alibaba.fastjson.JSON;
+import org.apache.xmlbeans.impl.xb.xsdschema.Public;
+import org.dromara.common.core.utils.SpringUtils;
+import org.dromara.common.core.utils.StringUtils;
+import org.dromara.common.redis.utils.CacheUtils;
+import org.dromara.common.redis.utils.RedisUtils;
+import org.dromara.system.domain.GpsData;
+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.vo.SysDictDataVo;
+import org.dromara.system.domain.vo.TblCarInfoVo;
+import org.dromara.system.service.ISysDictDataService;
+import org.dromara.system.service.impl.TblCarInfoServiceImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
 
 import javax.crypto.Cipher;
 import java.security.Key;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
+@Component
 public class CabinetUtil {
 
     private  final static String appid = "bw_open_express_A8C848769E5C04E0";
@@ -15,6 +41,9 @@ public class CabinetUtil {
 
     private  final static String hosts = "https://open.bestwond.com";
 
+    public final static String CABINET_INFO = "cabinet_info";
+    public final static String CABINET_BOXS = "cabinet_boxs";
+    private static final Logger log = LoggerFactory.getLogger(CabinetUtil.class);
 
     private static String byteArr2HexStr(byte[] arrB) throws Exception {
         int iLen = arrB.length;
@@ -62,6 +91,119 @@ public class CabinetUtil {
 //        String text = SpringUtils.getBean(ISysConfigService.class).selectConfigByKey("sys.cabinet.account");
 //
 //    }
+     @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())){
+                 JSONUtil.parseArray(car.getDeviceInfos()).forEach(item->{
+                     JSONObject c = (JSONObject)item;
+                     if(c.getStr("type").equals("gps")){
+                        GpsData gpsData = RedisUtils.getCacheObject(StringUtils.format("gps_{}", c.getStr("code")));
+                        //1小时就离线
+                         Map<String,Object> map=new HashMap<>();
+                         if(gpsData.getTs()==null){
+                             gpsData.setTs(DateUtil.date());
+                         }
+
+                        if(DateUtil.current() - gpsData.getTs().getTime()> 1000*60*60){
+                            map.put("code",c.getStr("code"));
+                            map.put("time", DatePattern.NORM_DATETIME_FORMAT.format(gpsData.getTs()));
+                            map.put("station",car.getCarNum());
+                            CacheUtils.put("offline",c.getStr("code"),map);
+                        }else{
+                            CacheUtils.put("offline",c.getStr("code"),map);
+                        }
+                     }
+
+                 });
+             }
+         }
+
+     }
+
+
+
+    @Scheduled(fixedRate = 5*60*1000)
+    private void getList(){
+        //获取所有gps 判断是否离线
+        List<List<String>> cabinetList = new ArrayList<>();
+        SysDictDataBo bo =new SysDictDataBo();
+        bo.setDictType("tbl_sites");
+        List<SysDictDataVo> list = SpringUtils.getBean(ISysDictDataService.class).selectDictDataList(bo);
+        try {
+            list.forEach(item->{
+                if(StrUtil.isNotEmpty(item.getRemark())){
+                    JSONArray jsonArray = JSONUtil.parseArray(item.getRemark());
+                    jsonArray.forEach(item2->{
+                        if(((JSONObject)item2).getStr("type").equals("cabinet")){
+                            cabinetList.add( List.of(item.getDictLabel(),((JSONObject)item2).getStr("code")));
+                        }
+                    });
+                }
+            });
+        }catch (Exception e){
+
+        }
+
+
+        if(cabinetList.size()>0){
+            cabinetList.forEach(item->{
+                try {
+                    Thread.sleep(1000);
+                   String details= CabinetUtil.getCabinetInfo(item.get(1));
+                   CacheUtils.put(CABINET_INFO,item.get(1),details);
+                   log.info(StrUtil.format("获取到柜子信息:{},{}",item.get(1),details));
+                    Thread.sleep(1000);
+                   //获取柜子状态
+                    String boxs= CabinetUtil.getCabinetBoxs(item.get(1));
+                    CacheUtils.put(CABINET_BOXS,item.get(1),boxs);
+                    log.info(StrUtil.format("获取到柜子箱子信息:{},{}",item.get(1),boxs));
+
+
+                    try{
+                        Integer obline = JSONUtil.parseObj(details).getJSONObject("data").getInt("device_line");
+                        Map<String,Object> map=new HashMap<>();
+                        if(obline==0){
+                            map.put("code",item.get(1));
+                            map.put("time",DateUtil.now());
+                            map.put("station",item.get(0));
+                            //离线告警
+                            CacheUtils.put("offline",item.get(1),map);
+                        }else{
+                            CacheUtils.put("offline",item.get(1),map);
+                        }
+                    }catch(Exception e){
+                       log.error("快递柜信息解析错误");
+                    }
+
+                    try{
+                        Map<String,Integer> map=new HashMap<>();
+                        map.put("total",JSONUtil.parseObj(boxs).getJSONObject("data").getJSONObject("page").getInt("total_count"));
+                        JSONUtil.parseObj(boxs).getJSONObject("data").getJSONArray("list").forEach(item2->{
+                            if(((JSONObject)item2).getInt("box_use_status")==1){
+                                map.put("used",map.get("used")==null?1:map.get("used")+1);
+                            }else{
+                                map.put("unuse",map.get("unuse")==null?1:map.get("unuse")+1);
+                            }
+                        });
+                        if(map.get("used")==null) map.put("used",0);
+                        if(map.get("unuse")==null) map.put("unuse",0);
+                        CacheUtils.put(CABINET_INFO,item.get(1)+"_box",map);
+                    }catch(Exception e){
+                        log.error("快递柜box解析错误");
+                    }
+                } catch (Exception e) {
+                    throw new RuntimeException(e);
+                }
+            });
+        }
+
+    }
+
+
+
+
 
     // 获取柜子信息
     public static  String getCabinetInfo(String cabinetCode) throws Exception {

+ 37 - 3
ruoyi-modules/ruoyi-khy/src/main/java/org/dromara/util/CamelDataUtil.java

@@ -19,6 +19,7 @@ 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.json.utils.JsonUtils;
+import org.dromara.common.redis.utils.CacheUtils;
 import org.dromara.common.redis.utils.RedisUtils;
 import org.dromara.netty.pojo.NettyChannelHandlerContext;
 import org.dromara.sms4j.api.universal.RedisUtil;
@@ -83,12 +84,26 @@ public class CamelDataUtil {
 //        exchange.getMessage().setBody(body);
     }
 
+    public static void setPlayList(String carNum,Object data)
+    {
+        try{
+            CacheUtils.put("playlist",carNum,data);
+        }catch (Exception e){}
+
+    }
+
 
     public void processGpsData(GpsData gpsData){
 
-        log.info("body:{}",JSONUtil.toJsonStr(gpsData));
+        try{
+            this.SendData("direct:senddev", JSONUtil.toJsonStr(gpsData), "devtype","-");
+
+        }catch (Exception e){
+
+        }
         gpsDataService.insertData(gpsData);
 
+        gpsData.setTs(DateUtils.getNowDate());
         //缓存最新数据到redis
         RedisUtils.setCacheObject(StringUtils.format("gps_{}", gpsData.getDevicecode()), gpsData);
 
@@ -215,6 +230,13 @@ public class CamelDataUtil {
                                                 String message = StringUtils.format(text, carInfoVo1.getCarNum(),stations.get(0).getDictLabel());
                                                 if(StringUtils.isNotEmpty(stations.get(0).getRemark())){
                                                     List<JSONObject> devicedatas = JSONUtil.parseArray( stations.get(0).getRemark()).toList(JSONObject.class);
+                                                    Map<String,String> o = new HashMap<>();
+                                                    o.put("station",stations.get(0).getDictLabel());
+                                                    o.put("time",DateUtil.now());
+                                                    o.put("type",carInfoVo1.getCarType());
+                                                    o.put("carNum",carInfoVo1.getCarNum());
+                                                    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);
@@ -289,6 +311,13 @@ public class CamelDataUtil {
                                                     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);
@@ -335,7 +364,6 @@ public class CamelDataUtil {
             }
         }
 
-
         log.info("body:{}",body);
     }
 
@@ -350,8 +378,14 @@ public class CamelDataUtil {
             }
         }
         if(StrUtil.isNotEmpty(countdatastr.toString())){
-            log.info("body:{}",countdatastr);
+            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");