wenhongquan vor 10 Monaten
Ursprung
Commit
3d0fb17b00

+ 3 - 3
ruoyi-admin/src/main/resources/application-dev.yml

@@ -43,15 +43,15 @@ spring:
           driverClassName: com.mysql.cj.jdbc.Driver
           # jdbc 所有参数配置参考 https://lionli.blog.csdn.net/article/details/122018562
           # rewriteBatchedStatements=true 批处理优化 大幅提升批量插入更新删除性能(对数据库有性能损耗 使用批量操作应考虑性能问题)
-          url: jdbc:mysql://localhost:3306/khyznh?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true
+          url: jdbc:mysql://127.0.0.1:8535/khyznh?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true
           username: root
-          password: root
+          password: 123456
         # 从库数据源
         slave:
           lazy: false
           type: ${spring.datasource.type}
           driverClassName: com.taosdata.jdbc.rs.RestfulDriver
-          url: jdbc:TAOS-RS://127.0.0.1:6041/khyznh?charset=utf8&timezone=GMT%2B8
+          url: jdbc:TAOS-RS://127.0.0.1:8536/khyznh?charset=utf8&timezone=GMT%2B8
           username: root
           password: taosdata
 #        oracle:

+ 0 - 1
ruoyi-admin/src/main/resources/application.yml

@@ -301,4 +301,3 @@ wx:
 
 
 
-

+ 49 - 6
ruoyi-modules/ruoyi-dzbc/src/main/java/org/dromara/system/controller/TblDzbcPathSchedulingController.java

@@ -8,6 +8,7 @@ import cn.hutool.core.date.DateField;
 import cn.hutool.core.date.DatePattern;
 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 lombok.RequiredArgsConstructor;
@@ -294,13 +295,55 @@ public class TblDzbcPathSchedulingController extends BaseController {
                 double distanceArea = DistanceCalculator.calculateDistance(startArea.getLocation(),toArea.getLocation());
                 double distanceSite = DistanceCalculator.calculateDistance(startSite.getLocation(),endSite.getLocation());
 
-                Integer price1 = dataObject.getInt("price");
-                if(price1==null) return R.fail("路线价格未设置");
-                //单价 根据区域-区域 单价及站点-站点 计算价格
-                double price = price1*(distanceSite/distanceArea);
-                //计算加价
-                tblDzbcPathSchedulingVo.setPrice((int)Math.round(price+tblDzbcPathSchedulingVo.getPprice()));
+                try{
+                    TblDzbcPathVo pathVo = tblDzbcPathService.queryById(tblDzbcPathSchedulingVo.getPathId());
+                    JSONObject ext1 = dataObject.getJSONObject("ext1");
+                    if(pathVo!=null && pathVo.getExt1()!=null){
+                        ext1 = JSONUtil.parseObj(pathVo.getExt1()) ;
+                    }
+                    if(ext1!=null){
+                        //获取区域价格
+                        JSONArray prices = ext1.getJSONArray("jgqj");
+                        //获取距离
+                        Double distance = ext1.getDouble("jl");
+                        //获取价格系数
+                        Double jgxs = ext1.getDouble("jgxs");
+
+                        if(jgxs==null) jgxs = 0.0;
+                        if(distance==null) distance = distanceArea;
+                        double distanceSite1 = distanceSite*distanceArea/distance;
+                        if(prices!=null && prices.size()>0){
+                            for (int i = 0; i < prices.size(); i++) {
+                                JSONObject price = prices.getJSONObject(i);
+                                Double min = price.getDouble("min");
+                                Double max = price.getDouble("max");
+                                Double p = price.getDouble("price");
+                                if(min==null) min = 0.0;
+                                if(max==null) max = Double.MAX_VALUE;
+                                if(distanceSite1>=min && distanceSite1<=max){
+                                    double jg = (p*100)+(distanceSite1)*jgxs;
+                                    tblDzbcPathSchedulingVo.setPrice((int)Math.round(jg));
+                                    break;
+                                }
+                            }
+
+                        }
+
 
+
+                    }
+
+                }catch (Exception e){
+                    return R.fail("路线价格错误");
+                }
+                if(tblDzbcPathSchedulingVo.getPrice()==null){
+                    Integer price1 = dataObject.getInt("price");
+                    if(price1==null) return R.fail("路线价格未设置");
+                    //单价 根据区域-区域 单价及站点-站点 计算价格
+                    double price = price1*(distanceSite/distanceArea);
+                    //计算加价
+                    tblDzbcPathSchedulingVo.setPrice((int)Math.round(price+tblDzbcPathSchedulingVo.getPprice()));
+                }
             } catch (Exception e) {
                 return  R.fail("站点信息错误");
             }

+ 55 - 5
ruoyi-modules/ruoyi-dzbc/src/main/java/org/dromara/system/service/impl/TblDzbcOrderServiceImpl.java

@@ -7,6 +7,7 @@ import cn.hutool.core.thread.ThreadUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.cron.timingwheel.SystemTimer;
 import cn.hutool.cron.timingwheel.TimerTask;
+import cn.hutool.json.JSONArray;
 import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -14,6 +15,7 @@ import com.github.binarywang.wxpay.bean.request.BaseWxPayRequest;
 import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
 import com.github.binarywang.wxpay.service.WxPayService;
 import jakarta.annotation.PostConstruct;
+import org.dromara.common.core.domain.R;
 import org.dromara.common.core.utils.MapstructUtils;
 import org.dromara.common.core.utils.SpringUtils;
 import org.dromara.common.core.utils.StringUtils;
@@ -181,11 +183,59 @@ public class TblDzbcOrderServiceImpl implements ITblDzbcOrderService {
         Assert.isTrue(StrUtil.isNotEmpty(areas.get(1).getLocation()),areas.get(1).getName()+"区域未设置经纬度");
         double distanceArea = DistanceCalculator.calculateDistance(areas.get(0).getLocation(),areas.get(1).getLocation());
         double distanceSite = DistanceCalculator.calculateDistance(startSite.getLocation(),endSite.getLocation());
-        Assert.isTrue(pathVo.getPrice()!=null,"路线价格未设置");
-        //单价 根据区域-区域 单价及站点-站点 计算价格
-        double price = pathVo.getPrice()*(distanceSite/distanceArea);
-        //计算加价
-        add.setPrice((int)Math.round(price+scheduling.getPprice()));
+
+
+        try{
+
+
+            if(pathVo.getExt1()!=null && JSONUtil.parseObj(pathVo.getExt1().toString())!=null) {
+                JSONObject ext1 = JSONUtil.parseObj(pathVo.getExt1().toString());
+
+
+                //获取区域价格
+                JSONArray prices = ext1.getJSONArray("jgqj");
+                //获取距离
+                Double distance = ext1.getDouble("jl");
+                //获取价格系数
+                Double jgxs = ext1.getDouble("jgxs");
+
+                if (jgxs == null) jgxs = 1.0;
+                if (distance == null) distance = distanceArea;
+                double distanceSite1 = distanceSite * distanceArea / distance;
+
+                if(prices!=null||prices.size()>0) {
+
+                    for (int i = 0; i < prices.size(); i++) {
+                        JSONObject price = prices.getJSONObject(i);
+                        Double min = price.getDouble("min");
+                        Double max = price.getDouble("max");
+                        Double p = price.getDouble("price");
+                        if (min == null) min = 0.0;
+                        if (max == null) max = Double.MAX_VALUE;
+                        if (distanceSite1 >= min && distanceSite1 <= max) {
+                            double jg = (p * 100) + (distanceSite1) * jgxs;
+                            add.setPrice((int) Math.round(jg));
+                            break;
+                        }
+                    }
+                }
+            }
+        }catch (Exception e){
+            throw new RuntimeException("路线价格错误");
+        }
+        if(add.getPrice()==null){
+            Integer price1 = pathVo.getPrice();
+            if(price1==null) throw new RuntimeException("路线价格错误");
+            //单价 根据区域-区域 单价及站点-站点 计算价格
+            double price = price1*(distanceSite/distanceArea);
+            //计算加价
+            add.setPrice((int)Math.round(price+scheduling.getPprice()));
+        }
+//
+//        //单价 根据区域-区域 单价及站点-站点 计算价格
+//        double price = pathVo.getPrice()*(distanceSite/distanceArea);
+//        //计算加价
+//        add.setPrice((int)Math.round(price+scheduling.getPprice()));
 
         add.setStartInfo(JSONUtil.toJsonStr(Map.of("areaInfo", areas.get(0), "siteInfo", startSite)));
         add.setEndInfo(JSONUtil.toJsonStr(Map.of("areaInfo", areas.get(1), "siteInfo", endSite)));

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

@@ -37,6 +37,7 @@ import java.io.UnsupportedEncodingException;
 import java.security.Key;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
+import java.time.format.DateTimeFormatter;
 import java.util.*;
 
 @Component
@@ -286,6 +287,89 @@ public class CabinetUtil {
     }
 
 
+    @Scheduled(fixedRate = 2*60*60*1000)
+    public void getExpressHistory() throws UnsupportedEncodingException {
+        //获取所有快递柜的快递信息
+        Map<String, JSONObject> cabinetMap = 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->{
+                        if(((JSONObject)item2).getStr("type").equals("cabinet")){
+                            ((JSONObject) item2).put("location",item.getDictValue());
+                            cabinetMap.put( item.getDictLabel(),(JSONObject)item2);
+                        }
+                    });
+                }
+            });
+        }catch (Exception e){
+
+        }
+        if(cabinetMap!=null && cabinetMap.size()>0) {
+            try {
+
+                List<JSONObject> cabinetList = new ArrayList<>();
+                cabinetMap.keySet().forEach(i->{
+                    JSONObject c = cabinetMap.get(i);
+                    if(c.getStr("location")!=null&&c.getStr("wdcode")!=null){
+                        c.put("deviceId", c.getStr("code"));
+                        c.put("stationId", c.getStr("wdcode"));
+                        c.put("deviceType", "cabinet");
+                        cabinetList.add(c);
+                    }
+                } );
+
+                SPlatUtils.SysDevice(cabinetList);
+            }catch (Exception e){
+
+            }
+
+        }
+        //获取历史
+        try {
+            Map<String,String> map = new HashMap<>();
+            map.put("start_ctime ", DateUtil.format( DateUtil.offsetHour(DateUtil.date(),-2), "yyyy-MM-dd HH:mm:ss"));
+            map.put("end_ctime ", DateUtil.format( DateUtil.date(), "yyyy-MM-dd HH:mm:ss"));
+            map.put("page_size", "10000");
+            String data = CabinetUtil.getExpressHistory(map);
+            List<JSONObject> jsonObjectList = new ArrayList<>();
+            JSONArray jsonArray = JSONUtil.parseObj(data).getJSONObject("data").getJSONArray("list");
+            for (JSONObject jsonObject1 : jsonArray.toList(JSONObject.class)) {
+                JSONObject json = new JSONObject();
+                json.put("deviceId",jsonObject1.getStr("device_number"));
+                json.put("cpCode",jsonObject1.getStr("product_type"));
+
+                json.put("waybillNo",jsonObject1.getStr("order_number"));
+
+                if(jsonObject1.getInt("used_status")==3||jsonObject1.getInt("used_status")==4){
+                    if(jsonObject1.getInt("used_status")==3){
+                        json.put("scTime",jsonObject1.getStr("save_end_time"));
+                        json.put("scType",1);
+                    }
+                    if(jsonObject1.getInt("used_status")==4){
+                        json.put("scType",2);
+                        json.put("scTime",jsonObject1.getStr("get_end_time"));
+                    }
+                }
+                jsonObjectList.add(json);
+            }
+            SPlatUtils.pushExpressInfo(jsonObjectList);
+
+        }catch (Exception e){
+
+        }
+
+
+
+
+
+
+    }
+
     @Scheduled(fixedRate = 5*60*1000)
     private void resetStationLed() throws UnsupportedEncodingException {
         //获取所有站点led
@@ -481,6 +565,16 @@ public class CabinetUtil {
 
     }
 
+    //获取快递历史信息
+    public static String getExpressHistory(Map<String,String> body) throws Exception{
+        int times = (int) (DateUtil.date().getTime()/1000);
+        String str_sign = appid + "=" + times + "=" + appid;
+        str_sign = encrypt(str_sign);
+        String result3= HttpRequest.post(hosts + "/kd/api/v2/search/record_query/").body(JSON.toJSONString(body))
+            .addHeaders(Map.of("timestamp",times+"","Content-Type","application/json","appid",appid,"sign",str_sign)).execute().body();
+        return result3;
+    }
+
 
 
 

+ 94 - 0
ruoyi-modules/ruoyi-khy/src/main/java/org/dromara/util/SPlatUtils.java

@@ -0,0 +1,94 @@
+package org.dromara.util;
+
+import cn.hutool.crypto.SecureUtil;
+import cn.hutool.crypto.digest.MD5;
+import cn.hutool.http.HttpResponse;
+import cn.hutool.http.HttpUtil;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class SPlatUtils {
+    public final static String SPLAT_URL = "http://116.63.183.174:5050";
+
+    public static String gettoken() {
+        String url = SPLAT_URL+"/outerService/login";
+        String param = "?username=khy_baiwei&password="+ SecureUtil.md5("123456");
+        HttpResponse response = HttpUtil.createGet(url+param)
+            .execute();
+        for (String cookie : response.headers().get("Set-Cookie")){
+            Map<String, String> cookieMap = parseCookie( cookie);
+            if(cookieMap.containsKey("satoken"))
+                return cookieMap.get("satoken");
+        }
+        return "";
+    }
+
+    public static void SysDevice(List<JSONObject> devices) {
+       String token =  gettoken();
+
+        for (JSONObject i :devices) {
+            String url = SPLAT_URL+"/outerService/deviceInfo";
+            Map<String, String> params = new HashMap<>();
+            params.put("deviceId",i.getStr("deviceId"));
+            params.put("stationId",i.getStr("stationId"));
+            params.put("vid","baiwei");
+            params.put("coordinateName","WGS-84");
+            params.put("deviceLongitude",i.getStr("location").split(",")[0]);
+            params.put("deviceLatitude",i.getStr("location").split(",")[1]);
+            HttpResponse response = HttpUtil.createPost(url).header("satoken",token).body(JSONUtil.toJsonStr( params))
+                .execute();
+        }
+
+    }
+
+   /**
+     * 推送快件信息接口
+    *
+    *
+    */
+   public static void pushExpressInfo(List<JSONObject> jsonObjectList){
+       String token =  gettoken();
+       String url = SPLAT_URL+"/outerService/deviceExpressRegist";
+       for (JSONObject jsonObject : jsonObjectList) {
+           Map<String,Object> params = new HashMap<>();
+           params.put("deviceId",jsonObject.get("deviceId"));
+           params.put("vid","baiwei");
+           params.put("cpCode",jsonObject.get("cpCode"));
+           params.put("scType",jsonObject.get("scType"));
+           params.put("scTime",jsonObject.get("scTime"));
+           params.put("waybillNo",jsonObject.get("waybillNo"));
+           HttpResponse response = HttpUtil.createPost(url).header("satoken",token).body(JSONUtil.toJsonStr( params))
+               .execute();
+       }
+
+   }
+
+
+    /**
+     * 解析 Set-Cookie 字符串为键值对
+     *
+     * @param setCookie Set-Cookie 字符串
+     * @return 包含键值对的 Map
+     */
+    public static Map<String, String> parseCookie(String setCookie) {
+        Map<String, String> cookieMap = new HashMap<>();
+        // 按 ";" 将 Cookie 拆分成多个部分
+        String[] attributes = setCookie.split(";");
+        for (String attribute : attributes) {
+            // 按 "=" 分离键和值(注意去掉多余空格)
+            String[] keyValue = attribute.trim().split("=", 2); // 限制最多分割成两个部分
+            if (keyValue.length == 2) {
+                // 如果有键和值,存入 Map
+                cookieMap.put(keyValue[0], keyValue[1]);
+            } else {
+                // 如果只有键(例如 HttpOnly、Secure 没有值),存入 Map,值为 null
+                cookieMap.put(keyValue[0], null);
+            }
+        }
+        return cookieMap;
+    }
+}