|
@@ -1,22 +1,28 @@
|
|
|
package com.ruoyi.basicData.service.impl;
|
|
|
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
-import com.ruoyi.basicData.domain.TCustomerContact;
|
|
|
-import com.ruoyi.basicData.mapper.TCustomerContactMapper;
|
|
|
+import cn.hutool.http.HttpRequest;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.ruoyi.basicData.domain.TWarehouseWebcam;
|
|
|
+import com.ruoyi.basicData.mapper.TWarehouseWebcamMapper;
|
|
|
+import com.ruoyi.basicData.service.ITWarehouseWebcamService;
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
import com.ruoyi.common.core.domain.entity.SysUser;
|
|
|
+import com.ruoyi.common.exception.BaseException;
|
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
+import com.ruoyi.system.domain.SysConfig;
|
|
|
+import com.ruoyi.system.mapper.SysConfigMapper;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import com.ruoyi.basicData.mapper.TWarehouseWebcamMapper;
|
|
|
-import com.ruoyi.basicData.domain.TWarehouseWebcam;
|
|
|
-import com.ruoyi.basicData.service.ITWarehouseWebcamService;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
/**
|
|
|
* 仓库摄像头Service业务层处理
|
|
|
*
|
|
@@ -29,7 +35,7 @@ public class TWarehouseWebcamServiceImpl implements ITWarehouseWebcamService {
|
|
|
private TWarehouseWebcamMapper tWarehouseWebcamMapper;
|
|
|
|
|
|
@Autowired
|
|
|
- private TCustomerContactMapper customerContactMapper;
|
|
|
+ private SysConfigMapper sysConfigMapper;
|
|
|
|
|
|
/**
|
|
|
* 查询仓库摄像头
|
|
@@ -76,18 +82,13 @@ public class TWarehouseWebcamServiceImpl implements ITWarehouseWebcamService {
|
|
|
return tWarehouseWebcamMapper.selectAppTWarehouseWebcamList(tWarehouseWebcam.getfWarehouseId(), null);
|
|
|
}
|
|
|
|
|
|
- TCustomerContact customerContact = new TCustomerContact();
|
|
|
+ String external = null;
|
|
|
SysUser user = SecurityUtils.getLoginUser().getUser();
|
|
|
- Long corpId = null;
|
|
|
if ("外部用户".equals(user.getDept().getDeptName())) {
|
|
|
- customerContact.setfTel(SecurityUtils.getLoginUser().getUser().getUserName());
|
|
|
- List<TCustomerContact> tCustomerContacts = customerContactMapper.selectTCustomerContactList(customerContact);
|
|
|
- if (CollectionUtils.isNotEmpty(tCustomerContacts)) {
|
|
|
- corpId = tCustomerContacts.get(0).getfPid();
|
|
|
- }
|
|
|
+ external = user.getUserName();
|
|
|
}
|
|
|
|
|
|
- return tWarehouseWebcamMapper.selectAppTWarehouseWebcamList(null, corpId);
|
|
|
+ return tWarehouseWebcamMapper.selectAppTWarehouseWebcamList(null, external);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -153,4 +154,90 @@ public class TWarehouseWebcamServiceImpl implements ITWarehouseWebcamService {
|
|
|
public int deleteTWarehouseWebcamById(Long fId) {
|
|
|
return tWarehouseWebcamMapper.deleteTWarehouseWebcamById(fId);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取摄像头流地址
|
|
|
+ *
|
|
|
+ * @param warehouseId 仓库ID
|
|
|
+ * @return 摄像头流地址集合
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<Map<String, Object>> getWebcamUrlList(Long fWarehouseId) {
|
|
|
+ String external = null;
|
|
|
+ SysUser user = SecurityUtils.getLoginUser().getUser();
|
|
|
+ if ("外部用户".equals(user.getDept().getDeptName())) {
|
|
|
+ external = user.getUserName();
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Map<String, Object>> data = new ArrayList<>();
|
|
|
+ Map<String, Object> temp;
|
|
|
+
|
|
|
+ List<TWarehouseWebcam> tWarehouseWebcams = tWarehouseWebcamMapper.selectAppTWarehouseWebcamList(fWarehouseId, external);
|
|
|
+ if (tWarehouseWebcams.size() > 0) {
|
|
|
+ // 获取摄像头token
|
|
|
+ String token = getToken();
|
|
|
+ for (TWarehouseWebcam tWarehouseWebcam : tWarehouseWebcams) {
|
|
|
+ String projectId = tWarehouseWebcam.getProjectId();
|
|
|
+ String deviceSerial = tWarehouseWebcam.getDeviceSerial();
|
|
|
+ String streamUrl = getWebcamUrl(token, projectId, deviceSerial);
|
|
|
+ temp = new HashMap<>();
|
|
|
+ temp.put("warehouseName", tWarehouseWebcam.getfWarehouseName());
|
|
|
+ temp.put("deviceName", tWarehouseWebcam.getDeviceName());
|
|
|
+ temp.put("streamUrl", streamUrl);
|
|
|
+ data.add(temp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getConfigValue(String key) {
|
|
|
+ SysConfig sysConfig = sysConfigMapper.checkConfigKeyUnique(key);
|
|
|
+ if (StringUtils.isNull(sysConfig)) {
|
|
|
+ throw new BaseException("系统参数异常,未找到" + key + "参数");
|
|
|
+ }
|
|
|
+ return sysConfig.getConfigValue();
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getToken() {
|
|
|
+ // 从参数里获取请求地址、参数
|
|
|
+ String tokenUrl = getConfigValue("warehouse.webcam.tokenUrl");
|
|
|
+
|
|
|
+ JSONObject values = new JSONObject();
|
|
|
+ values.put("accessKey", getConfigValue("warehouse.webcam.accessKey"));
|
|
|
+ values.put("secretKey", getConfigValue("warehouse.webcam.secretKey"));
|
|
|
+ values.put("productCode", getConfigValue("warehouse.webcam.productCode"));
|
|
|
+
|
|
|
+ String response = HttpRequest.post(tokenUrl)
|
|
|
+ .body(values.toString())
|
|
|
+ .execute().body();
|
|
|
+ JSONObject json = JSON.parseObject(response);
|
|
|
+ if ("200".equals(json.getString("code"))) {
|
|
|
+ throw new BaseException(json.getString("msg"));
|
|
|
+ }
|
|
|
+ JSONObject data = JSON.parseObject(json.getString("data"));
|
|
|
+ return data.getString("access_token");
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getWebcamUrl(String token, String projectId, String deviceSerial) {
|
|
|
+ // 从参数里获取请求地址、参数
|
|
|
+ String streamUrl = getConfigValue("warehouse.webcam.streamUrl");
|
|
|
+
|
|
|
+ JSONObject values = new JSONObject();
|
|
|
+ values.put("projectId", projectId);
|
|
|
+ values.put("deviceSerial", deviceSerial);
|
|
|
+ values.put("protocol", 3);
|
|
|
+ values.put("supportH265", 1);
|
|
|
+
|
|
|
+ String response = HttpRequest.post(streamUrl)
|
|
|
+ .header("access_token", token)
|
|
|
+ .body(values.toString())
|
|
|
+ .execute().body();
|
|
|
+ JSONObject json = JSON.parseObject(response);
|
|
|
+ if ("200".equals(json.getString("code"))) {
|
|
|
+ throw new BaseException(json.getString("msg"));
|
|
|
+ }
|
|
|
+ JSONObject data = JSON.parseObject(json.getString("data"));
|
|
|
+ return data.getString("url");
|
|
|
+ }
|
|
|
+
|
|
|
}
|