|
@@ -6,10 +6,8 @@ import cn.hutool.json.JSONUtil;
|
|
|
import com.ebei.screen.common.response.ResponseBean;
|
|
|
import com.ebei.screen.common.util.CommonUtil;
|
|
|
import com.ebei.screen.modules.po.CameraDevice;
|
|
|
-import com.ebei.screen.modules.po.Project;
|
|
|
import com.ebei.screen.modules.po.YsAccessToken;
|
|
|
import com.ebei.screen.service.CameraDeviceService;
|
|
|
-import com.fasterxml.jackson.annotation.JsonUnwrapped;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -61,31 +59,31 @@ public class CameraDeviceServiceImpl implements CameraDeviceService {
|
|
|
criteria.where("_id").is(_id);
|
|
|
query.addCriteria(criteria);
|
|
|
YsAccessToken ysAccessToken = mongoTemplate.findById(_id, YsAccessToken.class, "YsAccessToken");
|
|
|
- if(CommonUtil.isEmpty(ysAccessToken) || ysAccessToken.getCreateTime().plusDays(6).isBefore(now)) {
|
|
|
+ if (CommonUtil.isEmpty(ysAccessToken) || ysAccessToken.getCreateTime().plusDays(6).isBefore(now)) {
|
|
|
ysAccessToken = new YsAccessToken();
|
|
|
//没有缓存过或者缓存的已经过期需要重新获取
|
|
|
//请求萤石接口
|
|
|
- Map<String,Object> paramMap = new HashMap<>();
|
|
|
- paramMap.put("appKey",appKey);
|
|
|
- paramMap.put("appSecret",appSecret);
|
|
|
+ Map<String, Object> paramMap = new HashMap<>();
|
|
|
+ paramMap.put("appKey", appKey);
|
|
|
+ paramMap.put("appSecret", appSecret);
|
|
|
String result = HttpUtil.post(ysGetTokenUrl, paramMap);
|
|
|
JSONObject jsonObject = JSONUtil.parseObj(result);
|
|
|
- if("200".equals(jsonObject.get("code"))) {
|
|
|
+ if ("200".equals(jsonObject.get("code"))) {
|
|
|
Object temp = jsonObject.get("data");
|
|
|
JSONObject data = JSONUtil.parseObj(temp);
|
|
|
String accessToken = data.get("accessToken").toString();
|
|
|
ysAccessToken.setToken(accessToken);
|
|
|
} else {
|
|
|
- log.error("获取萤石accesstoken失败:"+jsonObject.get("msg"));
|
|
|
- throw new Exception("获取萤石accesstoken失败:"+jsonObject.get("msg"));
|
|
|
+ log.error("获取萤石accesstoken失败:" + jsonObject.get("msg"));
|
|
|
+ throw new Exception("获取萤石accesstoken失败:" + jsonObject.get("msg"));
|
|
|
}
|
|
|
//保存到mongodb
|
|
|
Query tempQuery = new Query();
|
|
|
tempQuery.addCriteria(Criteria.where("_is").is(_id));
|
|
|
Update update = new Update();
|
|
|
- update.set("token",ysAccessToken.getToken());
|
|
|
- update.set("createTime",now);
|
|
|
- mongoTemplate.upsert(query,update,YsAccessToken.class,"YsAccessToken");
|
|
|
+ update.set("token", ysAccessToken.getToken());
|
|
|
+ update.set("createTime", now);
|
|
|
+ mongoTemplate.upsert(query, update, YsAccessToken.class, "YsAccessToken");
|
|
|
}
|
|
|
return ysAccessToken.getToken();
|
|
|
}
|
|
@@ -95,7 +93,7 @@ public class CameraDeviceServiceImpl implements CameraDeviceService {
|
|
|
public void syncAllYsDevice() throws Exception {
|
|
|
log.info("----------------开始同步萤石监控设备----------------------");
|
|
|
List<CameraDevice> ysDeviceList = getYsDeviceList();
|
|
|
- if(CommonUtil.isEmpty(ysDeviceList)) {
|
|
|
+ if (CommonUtil.isEmpty(ysDeviceList)) {
|
|
|
return;
|
|
|
}
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
@@ -103,30 +101,30 @@ public class CameraDeviceServiceImpl implements CameraDeviceService {
|
|
|
List<CameraDevice> cameraDevice = mongoTemplate.findAll(CameraDevice.class, "CameraDevice");
|
|
|
Map<String, CameraDevice> deviceMap = cameraDevice.stream().collect(Collectors.toMap(CameraDevice::getDeviceSerial, i -> i));
|
|
|
//处理直播地址
|
|
|
- if(CommonUtil.isNotEmpty(ysDeviceList)) {
|
|
|
+ if (CommonUtil.isNotEmpty(ysDeviceList)) {
|
|
|
//查询直播地址
|
|
|
- ysDeviceList.forEach( i -> {
|
|
|
+ ysDeviceList.forEach(i -> {
|
|
|
CameraDevice temp = deviceMap.get(i.getDeviceSerial());
|
|
|
- if(CommonUtil.isEmpty(temp)) {
|
|
|
+ if (CommonUtil.isEmpty(temp)) {
|
|
|
//不存在的需要生成id
|
|
|
i.setId(CommonUtil.getSnowId().toString());
|
|
|
i.setCreateTime(now);
|
|
|
} else {
|
|
|
i.setId(temp.getId());
|
|
|
}
|
|
|
- if(i.getStatus().equals(1)) {
|
|
|
+ if (i.getStatus().equals(1)) {
|
|
|
//设备在线的查询直播地址
|
|
|
- Map<String,Object> map = new HashMap<>();
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
try {
|
|
|
- map.put("accessToken",this.getYsAccessToken());
|
|
|
+ map.put("accessToken", this.getYsAccessToken());
|
|
|
} catch (Exception e) {
|
|
|
- log.error("获取萤石accessToken失败!",e);
|
|
|
+ log.error("获取萤石accessToken失败!", e);
|
|
|
}
|
|
|
- map.put("deviceSerial",i.getDeviceSerial());
|
|
|
- map.put("code",code);
|
|
|
+ map.put("deviceSerial", i.getDeviceSerial());
|
|
|
+ map.put("code", code);
|
|
|
String result = HttpUtil.post(ysGetLiveAddress, map);
|
|
|
JSONObject jsonObject = JSONUtil.parseObj(result);
|
|
|
- if("200".equals(jsonObject.get("code"))) {
|
|
|
+ if ("200".equals(jsonObject.get("code"))) {
|
|
|
i.setUrl(JSONUtil.parseObj(jsonObject.get("data")).get("url").toString());
|
|
|
}
|
|
|
}
|
|
@@ -134,15 +132,15 @@ public class CameraDeviceServiceImpl implements CameraDeviceService {
|
|
|
Query query = new Query();
|
|
|
query.addCriteria(Criteria.where("_id").is(i.getId()));
|
|
|
Update update = new Update();
|
|
|
- update.set("status",i.getStatus());
|
|
|
- update.set("deviceName",i.getDeviceName());
|
|
|
- update.set("deviceSerial",i.getDeviceSerial());
|
|
|
- update.set("deviceType",i.getDeviceType());
|
|
|
- update.set("isDelete",0);
|
|
|
- update.set("url",i.getUrl());
|
|
|
- update.set("createTime",i.getCreateTime());
|
|
|
- update.set("updateTime",i.getUpdateTime());
|
|
|
- mongoTemplate.upsert(query,update,CameraDevice.class,"CameraDevice");
|
|
|
+ update.set("status", i.getStatus());
|
|
|
+ update.set("deviceName", i.getDeviceName());
|
|
|
+ update.set("deviceSerial", i.getDeviceSerial());
|
|
|
+ update.set("deviceType", i.getDeviceType());
|
|
|
+ update.set("isDelete", 0);
|
|
|
+ update.set("url", i.getUrl());
|
|
|
+ update.set("createTime", i.getCreateTime());
|
|
|
+ update.set("updateTime", i.getUpdateTime());
|
|
|
+ mongoTemplate.upsert(query, update, CameraDevice.class, "CameraDevice");
|
|
|
});
|
|
|
|
|
|
}
|
|
@@ -152,19 +150,19 @@ public class CameraDeviceServiceImpl implements CameraDeviceService {
|
|
|
@Override
|
|
|
public ResponseBean queryProjectPage(Integer page, Integer pageSize, String name, String deviceSerial, Integer status) {
|
|
|
Query query = new Query();
|
|
|
- if(CommonUtil.isNotEmpty(name)) {
|
|
|
+ if (CommonUtil.isNotEmpty(name)) {
|
|
|
Criteria criteria = new Criteria();
|
|
|
- Pattern pattern=Pattern.compile("^.*"+name+".*$", Pattern.CASE_INSENSITIVE);
|
|
|
+ Pattern pattern = Pattern.compile("^.*" + name + ".*$", Pattern.CASE_INSENSITIVE);
|
|
|
criteria.where("deviceName").regex(pattern);
|
|
|
query.addCriteria(criteria);
|
|
|
}
|
|
|
- if(CommonUtil.isNotEmpty(deviceSerial)) {
|
|
|
+ if (CommonUtil.isNotEmpty(deviceSerial)) {
|
|
|
Criteria criteria = new Criteria();
|
|
|
- Pattern pattern=Pattern.compile("^.*"+deviceSerial+".*$", Pattern.CASE_INSENSITIVE);
|
|
|
+ Pattern pattern = Pattern.compile("^.*" + deviceSerial + ".*$", Pattern.CASE_INSENSITIVE);
|
|
|
criteria.where("deviceSerial").regex(pattern);
|
|
|
query.addCriteria(criteria);
|
|
|
}
|
|
|
- if(CommonUtil.isNotEmpty(status)) {
|
|
|
+ if (CommonUtil.isNotEmpty(status)) {
|
|
|
query.addCriteria(Criteria.where("status").is(status));
|
|
|
}
|
|
|
//计算总数
|
|
@@ -183,11 +181,11 @@ public class CameraDeviceServiceImpl implements CameraDeviceService {
|
|
|
//请求萤石接口获取全部设备
|
|
|
Integer pageStart = 0;
|
|
|
Integer pageSize = 50;
|
|
|
- Map<String,Object> paramMap = new HashMap<>();
|
|
|
+ Map<String, Object> paramMap = new HashMap<>();
|
|
|
try {
|
|
|
- paramMap.put("accessToken",this.getYsAccessToken());
|
|
|
+ paramMap.put("accessToken", this.getYsAccessToken());
|
|
|
} catch (Exception e) {
|
|
|
- log.error("同步设备失败:获取萤石accessToken失败",e);
|
|
|
+ log.error("同步设备失败:获取萤石accessToken失败", e);
|
|
|
throw new Exception("同步设备失败:获取萤石accessToken失败");
|
|
|
}
|
|
|
paramMap.put("pageStart", pageStart);
|
|
@@ -200,10 +198,10 @@ public class CameraDeviceServiceImpl implements CameraDeviceService {
|
|
|
List<CameraDevice> cameraDevices = JSONUtil.toList(JSONUtil.parseArray(data), CameraDevice.class);
|
|
|
List<CameraDevice> totalDevice = new ArrayList<>();
|
|
|
totalDevice.addAll(cameraDevices);
|
|
|
- while(totalDevice.size() < Integer.valueOf(page.get("total").toString())) {
|
|
|
+ while (totalDevice.size() < Integer.valueOf(page.get("total").toString())) {
|
|
|
//继续获取并存入totalDevice
|
|
|
pageStart++;
|
|
|
- paramMap.put("pageStart",pageStart);
|
|
|
+ paramMap.put("pageStart", pageStart);
|
|
|
String resultTemp = HttpUtil.post(ysGetDeviceWithPage, paramMap);
|
|
|
JSONObject jsonObjectTemp = JSONUtil.parseObj(resultTemp);
|
|
|
Object tempPage = jsonObjectTemp.get("page");
|