Эх сурвалжийг харах

fix 大华增加token的接口
fix 大屏端资源列表接口增加数量返回

459242451@qq.com 3 жил өмнө
parent
commit
a1dde03115

+ 2 - 0
ruoyi-admin/nacos/yjzh-sq-prod.yaml

@@ -161,3 +161,5 @@ third:
     incidentDetailUrl: http://sqmb.xt.wenhq.top:8083/#/status/3/detail?id=#incidentId # 事件详情页面
     resourceUrl: http://sqmb.xt.wenhq.top:8083/#/warehouse/list?taskid=#taskId # 移动端资源跳转链接
     chemicalUrl: http://sqmb.xt.wenhq.top:8083/#/chemical/detail?id= # 危化品详情页面
+    dhVideoUserName: huashe2
+    dhPCUserName: huashe3

+ 2 - 0
ruoyi-admin/nacos/yjzh-sq-test.yaml

@@ -161,3 +161,5 @@ third:
     incidentDetailUrl: http://sqmb.xt.wenhq.top:8083/#/status/3/detail?id=#incidentId # 事件详情页面
     resourceUrl: http://sqmb.xt.wenhq.top:8083/#/warehouse/list?taskid=#taskId # 移动端资源跳转链接
     chemicalUrl: http://sqmb.xt.wenhq.top:8083/#/chemical/detail?id= # 危化品详情页面
+    dhVideoUserName: huashe4
+    dhPCUserName: huashe5

+ 24 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhdd/DhController.java

@@ -13,9 +13,12 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.RequiredArgsConstructor;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 @Validated
@@ -26,10 +29,31 @@ import org.springframework.web.bind.annotation.RestController;
 public class DhController {
 
     private final IDhService dhService;
+    @Value("${third.dhPCUserName}")
+    private String dhAccount;
 
     @ApiOperation("查询设备列表")
     @GetMapping("/deviceList")
     public AjaxResult list() {
         return AjaxResult.success(dhService.getDeviceTree());
     }
+
+    @ApiOperation("获取大华token")
+    @GetMapping("/getVideoToken")
+    public AjaxResult getToken(@RequestParam(required = false) String account) {
+        return AjaxResult.success(dhService.getVideoToken(account));
+    }
+
+    @ApiOperation("获取大华tokenV2.用于PC端业务")
+    @GetMapping("/v2/getVideoToken")
+    public AjaxResult getTokenV2() {
+        return AjaxResult.success(dhService.getVideoToken(dhAccount));
+    }
+
+    @ApiOperation("video的token下线")
+    @PostMapping("/offlineVideoToken")
+    public AjaxResult offlineVideoToken() {
+        dhService.offlineVideoToken();
+        return AjaxResult.success();
+    }
 }

+ 17 - 4
ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhdd/ResourceController.java

@@ -22,6 +22,7 @@ import com.ruoyi.common.utils.poi.ExcelUtil;
 import com.ruoyi.zhdd.domain.Resource;
 import com.ruoyi.zhdd.domain.ResourceDetail;
 import com.ruoyi.zhdd.domain.bo.ResourceBo;
+import com.ruoyi.zhdd.domain.vo.ResourceDetailStatic;
 import com.ruoyi.zhdd.domain.vo.ResourceVo;
 import com.ruoyi.zhdd.service.IResourceDetailService;
 import com.ruoyi.zhdd.service.IResourceService;
@@ -232,11 +233,23 @@ public class ResourceController extends BaseController {
     @GetMapping("/location")
     public AjaxResult<Map<String, List<ResourceVo>>> queryResourceLocation(ResourceBo bo) {
         List<ResourceVo> list = iResourceService.queryList(bo);
-        Map<Integer, List<ResourceVo>> collect = list.stream().collect(Collectors.groupingBy(ResourceVo::getResourceType, Collectors.mapping(a -> a, Collectors.toList())));
+        // 查询物资数量
+        List<ResourceDetailStatic> resourceDetailStatics = iResourceDetailService.queryResourceTotalNum();
+        Map<String, Integer> collect = resourceDetailStatics.stream().collect(Collectors.toMap(ResourceDetailStatic::getResourceId, ResourceDetailStatic::getNum));
+        for (ResourceVo resourceVo : list) {
+            if (resourceVo.getResourceType() == 1 || resourceVo.getResourceType() == 2) {
+                Integer integer = collect.get(resourceVo.getId());
+                resourceVo.setNum(integer == null ? 0 : integer);
+            } else if (resourceVo.getResourceType() == 3) {
+                resourceVo.setNum(collect.get(resourceVo.getId() + "车辆") == null ? 0 : collect.get(resourceVo.getId() + "车辆"));
+                resourceVo.setShipNum(collect.get(resourceVo.getId() + "船舶") == null ? 0 : collect.get(resourceVo.getId() + "船舶"));
+            }
+        }
+        Map<Integer, List<ResourceVo>> collect2 = list.stream().collect(Collectors.groupingBy(ResourceVo::getResourceType, Collectors.mapping(a -> a, Collectors.toList())));
         Map<String, List<ResourceVo>> result = new HashMap<>();
-        result.put("应急仓库", CollUtil.defaultIfEmpty(collect.get(1), new ArrayList<>()));
-        result.put("应急队伍", CollUtil.defaultIfEmpty(collect.get(2), new ArrayList<>()));
-        result.put("应急车队", CollUtil.defaultIfEmpty(collect.get(3), new ArrayList<>()));
+        result.put("应急仓库", CollUtil.defaultIfEmpty(collect2.get(1), new ArrayList<>()));
+        result.put("应急队伍", CollUtil.defaultIfEmpty(collect2.get(2), new ArrayList<>()));
+        result.put("应急车队", CollUtil.defaultIfEmpty(collect2.get(3), new ArrayList<>()));
         return AjaxResult.success(result);
     }
 

+ 1 - 0
ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java

@@ -159,6 +159,7 @@ public class Constants {
      * 大华tokon缓存
      */
     public static final String CACHE_DH_TOKEN = "dh:token";
+    public static final String CACHE_DH_VIDEO_TOKEN = "dh:videotoken";
     /**
      * 大华tokon缓存=用于刷新
      */

+ 13 - 0
ruoyi-zhdd/src/main/java/com/ruoyi/zhdd/service/IDhService.java

@@ -2,6 +2,8 @@ package com.ruoyi.zhdd.service;
 
 import cn.hutool.json.JSONArray;
 
+import java.util.Map;
+
 /**
  * @Description: TODO
  * @Author: huangcheng
@@ -24,4 +26,15 @@ public interface IDhService {
     Object getDeviceTree();
 
     JSONArray querySingleStat();
+
+    /**
+     * 提供给前端大华视频的token接口
+     *
+     * @param account
+     * @return
+     */
+    Map<String, Object> getVideoToken(String account);
+
+    void offlineVideoToken();
+
 }

+ 76 - 0
ruoyi-zhdd/src/main/java/com/ruoyi/zhdd/service/impl/DhServiceImpl.java

@@ -2,6 +2,7 @@ package com.ruoyi.zhdd.service.impl;
 
 import cn.hutool.core.convert.Convert;
 import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
 import cn.hutool.crypto.SecureUtil;
 import cn.hutool.http.HttpRequest;
 import cn.hutool.http.HttpUtil;
@@ -38,6 +39,8 @@ public class DhServiceImpl implements IDhService {
     private String keepaliveUrl;
     @Value("${third.dhDeviceTree}")
     private String dhDeviceTreeUrl;
+    @Value("${third.dhVideoUserName}")
+    private String dhVideoUserName;
     @Autowired
     private ISysConfigService sysConfigService;
 
@@ -186,6 +189,79 @@ public class DhServiceImpl implements IDhService {
         return getJson.getJSONArray("results");
     }
 
+    @Override
+    public Map<String, Object> getVideoToken(String account) {
+        Map<String, Object> token = RedisUtils.getCacheMap(Constants.CACHE_DH_VIDEO_TOKEN);
+        if (token.isEmpty()) {
+            token = new HashMap<>();
+            // 从大华接口获取token
+            if (StrUtil.isBlank(account)) {
+                account = dhVideoUserName;
+            }
+            JSONObject jsonOne = new JSONObject();
+            jsonOne.set("userName", account);
+            jsonOne.set("clientType", "winpc");
+            String postOne = "";
+            try {
+                postOne = HttpUtil.post(dhAuthorizeUrl, jsonOne.toString());
+            } catch (Exception e) {
+                log.error("【视频】大华接口请求异常,账号:{}:{}", account, e.getMessage());
+                throw new ServiceException("【视频】大华融合通信平台无法连接,请联系大华融合通信平台维护人员检查!");
+            }
+            JSONObject postOneJson = JSONUtil.parseObj(postOne);
+            log.info("【视频】大华创建会话,,账号:{}的返回结果:{}", account, postOneJson);
+            if (postOneJson.containsKey("realm")) {
+                String randomKey = postOneJson.getStr("randomKey");
+                String realm = postOneJson.getStr("realm");
+                String encryptType = postOneJson.getStr("encryptType");
+                // 第二次交互
+                String password = "huashe123";
+                String signature = SecureUtil.md5(
+                    SecureUtil.md5(account + ":" + realm + ":" +
+                        SecureUtil.md5(
+                            SecureUtil.md5(
+                                account +
+                                    SecureUtil.md5(password)))) + ":" + randomKey);
+                jsonOne.set("signature", signature);
+                jsonOne.set("randomKey", randomKey);
+                jsonOne.set("encryptType", encryptType);
+                jsonOne.set("pid", 2548);
+                jsonOne.set("expiredTime", 86400);
+                String postTwo = HttpUtil.post(dhAuthorizeUrl, jsonOne.toString());
+                JSONObject postTwoJson = JSONUtil.parseObj(postTwo);
+                if (postTwoJson.containsKey("token")) {
+                    String tokenStr = postTwoJson.getStr("token");
+                    int duration = postTwoJson.getInt("duration");
+                    String userId = postTwoJson.getStr("userId");
+                    token.put("userId", userId);
+                    token.put("token", tokenStr);
+                    token.put("userName", postTwoJson.getStr("userName"));
+                    log.info("【视频】大华创建会话,账号:{}的过期时间:{}", account, duration);
+                    log.info("【视频】大华创建会话,账号:{}的Token:{}", account, token);
+                    if (ObjectUtil.isEmpty(duration)) {
+                        duration = 120;
+                    }
+                    // 存入redis缓存
+                    RedisUtils.setCacheMap(Constants.CACHE_DH_VIDEO_TOKEN, token);
+                    RedisUtils.expire(Constants.CACHE_DH_VIDEO_TOKEN, Convert.toInt(duration), TimeUnit.SECONDS);
+                } else {
+                    log.error("【视频】大华,账号:{}第二次创建会话失败:{}", account, postTwoJson);
+                    if ("user is repeated landing".equals(postTwoJson.getStr("message"))) {
+                        // 说明已经登录过,那么退出,重新获取
+                    }
+                }
+            } else {
+                log.error("【视频】大华,账号:{}第一次创建会话失败:{}", account, postOneJson);
+            }
+        }
+        return token;
+    }
+
+    @Override
+    public void offlineVideoToken() {
+        RedisUtils.deleteObject(Constants.CACHE_DH_VIDEO_TOKEN);
+    }
+
     private JSONArray getList(Map<String, Object> param) {
         param.put("nodeType", 1);
         param.put("typeCode", "01;0;ALL;ALL");