Bladeren bron

更新,给皖事通提供剩余车位数接口

Administrator 2 jaren geleden
bovenliggende
commit
f2f1fb6349

+ 7 - 0
ruoyi-admin/pom.xml

@@ -61,6 +61,13 @@
             <artifactId>ruoyi-generator</artifactId>
         </dependency>
 
+        <!-- 海康威视停车场数据jar包-->
+        <dependency>
+            <groupId>com.hikvision.ga</groupId>
+            <artifactId>artemis-http-client</artifactId>
+            <version>1.1.3</version>
+        </dependency>
+
     </dependencies>
 
     <build>

+ 82 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/parkLot/GetCameraPreviewURL.java

@@ -0,0 +1,82 @@
+package com.ruoyi.web.controller.parkLot;
+
+
+import com.alibaba.fastjson2.JSONObject;
+import com.hikvision.artemis.sdk.ArtemisHttpUtil;
+import com.hikvision.artemis.sdk.config.ArtemisConfig;
+
+import java.util.HashMap;
+import java.util.Map;
+/**
+ * @Author: tjf
+ * @Date: 2023/1/3 15:01
+ * @Describe:
+ */
+public class GetCameraPreviewURL {
+
+
+    /**
+     * 提供给皖事通剩余地面车位数量
+     * @return
+     */
+    public static String GetCameraPreviewURL() {
+        /**
+         * STEP1:设置平台参数,根据实际情况,设置host appkey appsecret 三个参数.
+         */
+        ArtemisConfig.host = "114.99.51.58:442"; // 平台的ip端口
+        ArtemisConfig.appKey = "26665995";  // 密钥appkey
+        ArtemisConfig.appSecret = "P9y9211M5ftH8P1Xrcef";// 密钥appSecret
+
+        /**
+         * STEP2:设置OpenAPI接口的上下文
+         */
+        final String ARTEMIS_PATH = "/artemis";
+        /**
+         * STEP3:设置接口的URI地址
+         */
+        final String previewURLsApi = ARTEMIS_PATH + "/api/pms/v1/park/remainSpaceNum";
+        Map<String, String> path = new HashMap<String, String>(2) {
+            {
+                put("https://", previewURLsApi);//根据现场环境部署确认是http还是https
+            }
+        };
+
+        /**
+         * STEP4:设置参数提交方式
+         */
+        String contentType = "application/json";
+
+        /**
+         * STEP5:组装请求参数
+         */
+        JSONObject jsonBody = new JSONObject();
+        jsonBody.put("parkSyscode", "v45gh45gergf34g34g354g35ger");
+        String body = jsonBody.toJSONString();
+        /**
+         * STEP6:调用接口
+         */
+        String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType , null);// post请求application/json类型参数
+        System.out.println(result);
+        /**
+         * {
+         *     "code": "0",
+         *     "msg": "success",
+         *     "data": [
+         *         {
+         *             "parkSyscode": "h45h3gh3g34g324g345",
+         *             "parkName": "停车库1",
+         *             "parentParkSyscode": "g354g45g345g35g2345gh5",
+         *             "totalPlace": 5000,
+         *             "totalPermPlace": 5000,
+         *             "totalReservePlace": 0,
+         *             "leftPlace": 0,
+         *             "leftPermPlace": 0,
+         *             "leftReservePlace": 0
+         *         }
+         *     ]
+         * }
+         */
+        return result;
+    }
+}
+

+ 51 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/parkLot/ParkLotController.java

@@ -0,0 +1,51 @@
+package com.ruoyi.web.controller.parkLot;
+
+import com.alibaba.fastjson2.JSONArray;
+import com.alibaba.fastjson2.JSONObject;
+import com.ruoyi.common.core.controller.BaseController;
+import com.ruoyi.common.core.redis.RedisCache;
+import com.ruoyi.common.utils.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.concurrent.TimeUnit;
+
+import static com.ruoyi.common.constant.CacheConstants.LEFT_PLACE;
+
+/**
+ * 参数配置 信息操作处理
+ *
+ * @author ruoyi
+ */
+@RestController
+@RequestMapping("/parkLot")
+public class ParkLotController extends BaseController {
+    @Autowired
+    private RedisCache redisCache;
+
+    /**
+     * 提供给皖事通剩余地面车位数量
+     */
+    @PostMapping("/parkLotNum")
+    public String parkLotNum() {
+        //先去查redis
+        String leftPlaceRedis = redisCache.getCacheObject(LEFT_PLACE);
+        if (StringUtils.isEmpty(leftPlaceRedis)){
+            leftPlaceRedis = "0";
+            String result = GetCameraPreviewURL.GetCameraPreviewURL();
+            JSONObject jsonObject = JSONObject.parseObject(result);
+            String code = jsonObject.getString("code");
+            if ("0".equals(code)) {
+                JSONArray data = jsonObject.getJSONArray("data");
+                leftPlaceRedis = data.getJSONObject(0).getString("leftPlace");
+                System.out.println(leftPlaceRedis);
+            }else {
+                System.out.println(jsonObject.getString("msg"));
+            }
+            redisCache.setCacheObject(LEFT_PLACE,leftPlaceRedis,5, TimeUnit.SECONDS);
+        }
+        return leftPlaceRedis;
+    }
+
+}

+ 4 - 0
ruoyi-common/src/main/java/com/ruoyi/common/constant/CacheConstants.java

@@ -16,6 +16,10 @@ public class CacheConstants
      * 验证码 redis key
      */
     public static final String CAPTCHA_CODE_KEY = "captcha_codes:";
+    /**
+     * 皖事通剩余车位数
+     */
+    public static final String LEFT_PLACE = "left_place:";
 
     /**
      * 参数管理 cache key