package com.secusoft.server.service.impl;
import com.google.common.collect.Lists;
import com.secusoft.common.bean.DeviceViewBaseParam;
import com.secusoft.common.bean.PlatformStatus;
import com.secusoft.common.bean.enums.SubscriptionStatus;
import com.secusoft.common.bean.requenst.APEsRequest;
import com.secusoft.common.bean.requenst.SubscribeRequest;
import com.secusoft.common.bean.response.QueryDeviceResponseObject;
import com.secusoft.common.bean.response.ResponseListStatusObject;
import com.secusoft.common.bean.response.ResponseStatus;
import com.secusoft.common.bean.response.ResponseStatusListModeObject;
import com.secusoft.common.bean.response.ResponseStatusObject;
import com.secusoft.common.bean.subscribes.SubscribeBase;
import com.secusoft.common.bean.subscribes.SubscribeListObject;
import com.secusoft.common.bean.subscribes.SubscribeObjects;
import com.secusoft.common.exceptions.CustomResponseListModeException;
import com.secusoft.common.http.HttpResponseBean;
import com.secusoft.common.http.RESTClient;
import com.secusoft.common.system.DomainConstant;
import com.secusoft.common.task.ScheduleTask;
import com.secusoft.common.task.ScheduleUtil;
import com.secusoft.common.task.TaskService;
import com.secusoft.common.utils.CommonUtlis;
import com.secusoft.common.utils.DateUtil;
import com.secusoft.common.utils.GsonUtil;
import com.secusoft.common.utils.URLParameter;
import com.secusoft.server.entity.ViewLibraryDomainChannel;
import com.secusoft.server.entity.ViewLibraryDomainDevice;
import com.secusoft.server.entity.ViewLibraryDomainSubscribe;
import com.secusoft.server.service.IViewLibraryDomainChannelService;
import com.secusoft.server.service.IViewLibraryDomainDeviceService;
import com.secusoft.server.service.IViewLibraryDomainSubscribeService;
import com.secusoft.server.service.PlatformService;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import static com.secusoft.common.bean.enums.StatusCodeEnum.PLATFORM_PARAMETER_FAIL;
/**
* @author :dzp
* @date :Created in 2024/6/25 15:43
* @description:
*/
@Service
@Log4j2
public class PlatformServiceImpl implements PlatformService, TaskService {
@Resource
private IViewLibraryDomainDeviceService viewLibraryDomainDeviceService;
@Resource
private IViewLibraryDomainChannelService viewLibraryDomainChannelService;
@Resource
private IViewLibraryDomainSubscribeService viewLibraryDomainSubscribeService;
@Resource
private IViewLibraryDomainSubscribeService domainSubscribeService;
/**
* 心跳key
*/
public static final String TASK_CASCADE_KEEP_KEY = "platform_keep_alive";
/**
* 默认心跳周期
*/
public static final Integer DEFAULT_HEARTBEAT_CYCLE = 3;
/**
* 默认最大心跳超时时间
*/
public static final Integer DEFAULT_MAX_HEARTBEAT_TIMEOUT_NUM = 60;
@Override
public ResponseStatusObject register(DeviceViewBaseParam param, String url) {
int heartbeatCycle = DEFAULT_HEARTBEAT_CYCLE;
int maxHeartbeatTimeoutNum = DEFAULT_MAX_HEARTBEAT_TIMEOUT_NUM;
// 保存到domain_platform 中 设备id,状态(注册默认在线,保活时间取最新时间)
ViewLibraryDomainDevice domainPlatform = viewLibraryDomainDeviceService.selectByDomainDeviceId(param.getDeviceId());
if (domainPlatform == null) {
viewLibraryDomainDeviceService.save(new ViewLibraryDomainDevice(param.getDeviceId(), PlatformStatus.ONLINE.getValue(), LocalDateTime.now(), DEFAULT_HEARTBEAT_CYCLE, DEFAULT_MAX_HEARTBEAT_TIMEOUT_NUM));
} else {
viewLibraryDomainDeviceService.updateRegisterStatus(param.getDeviceId(), PlatformStatus.ONLINE.getValue());
heartbeatCycle = domainPlatform.getHeartbeatCycle();
maxHeartbeatTimeoutNum = domainPlatform.getMaxHeartbeatTimeoutNum();
}
ScheduleUtil.start(
new ScheduleTask(TASK_CASCADE_KEEP_KEY + param.getDeviceId(), this, ""),
new Date(System.currentTimeMillis() + heartbeatCycle * maxHeartbeatTimeoutNum * 1000 * 1000)
);
return ResponseStatusObject.initSuccess(url, param, "注册成功");
}
@Override
public ResponseStatusObject unregister(DeviceViewBaseParam param, String url) {
// 保存到domain_platform 中 设备id,状态(注销状态)
viewLibraryDomainDeviceService.updateRegisterStatus(param.getDeviceId(), PlatformStatus.LOGGED_OUT.getValue());
ScheduleUtil.cancel(
TASK_CASCADE_KEEP_KEY + param.getDeviceId()
);
return ResponseStatusObject.initSuccess(url, param, "注销成功");
}
@Override
public ResponseStatusObject keepalive(DeviceViewBaseParam param, String url) {
// 根据设备id修改 保活时间取最新时间
viewLibraryDomainDeviceService.updateRegisterStatus(param.getDeviceId(), PlatformStatus.ONLINE.getValue());
ScheduleUtil.start(
new ScheduleTask(TASK_CASCADE_KEEP_KEY + param.getDeviceId(), this, "心跳未保活"),
new Date(System.currentTimeMillis()+DEFAULT_HEARTBEAT_CYCLE*DEFAULT_MAX_HEARTBEAT_TIMEOUT_NUM * 1000)
);
return ResponseStatusObject.initSuccess(url, param, "保活成功");
}
@Override
public ResponseStatusObject time(DeviceViewBaseParam param, String url) {
return null;
}
@Override
public void work(String id, String keyword) {
String platformId = id.replace(TASK_CASCADE_KEEP_KEY, "");
ViewLibraryDomainDevice viewLibraryDomainPlatform = viewLibraryDomainDeviceService.selectByDomainDeviceId(platformId);
if (viewLibraryDomainPlatform != null) {
LocalDateTime latestKeepAliveTime = viewLibraryDomainPlatform.getLatestKeepAliveTime();
if (latestKeepAliveTime == null) {
viewLibraryDomainDeviceService.updateRegisterStatus(viewLibraryDomainPlatform.getDeviceId(), PlatformStatus.LOGGED_OUT.getValue());
return;
}
if (DateUtil.isAfterAddingSeconds(LocalDateTime.now(), latestKeepAliveTime, viewLibraryDomainPlatform.getMaxHeartbeatTimeoutNum() * viewLibraryDomainPlatform.getHeartbeatCycle())) {
viewLibraryDomainDeviceService.updateRegisterStatus(viewLibraryDomainPlatform.getDeviceId(), PlatformStatus.LOGGED_OUT.getValue());
}
}
}
@Override
public <E> void queryDeviceList(DeviceViewBaseParam param, APEsRequest apEsRequest, List<E> list) {
ViewLibraryDomainDevice viewLibraryDomainDevice = viewLibraryDomainDeviceService.selectByDomainDeviceId(param.getDeviceId());
if (viewLibraryDomainDevice == null || StringUtils.isEmpty(viewLibraryDomainDevice.getRegisterHost())) {
log.warn("viewLibraryDomainPlatform or registerHost is null======>>{}", param.getDeviceId());
return;
}
// 通过设备id 查询host
String responseStr = RESTClient.getClientConnectionPool()
.fetchByGetMethod(viewLibraryDomainDevice.getRegisterHost() + DomainConstant.REQUEST_VIID_APES + "?" + URLParameter.toUrlParams(apEsRequest),param);
if (StringUtils.isEmpty(responseStr)) {
return;
}
//mock
// String responseStr = "{\"APEListObject\":{\"PageRecordNum\":5000,\"StartNum\":0,\"TotalNum\":1,\"APEObject\":[{\"ApeID\":\"868834683e1d4b76bf9ec3c837ea55ab\",\"Name\":\"Camera
没有合适的资源?快使用搜索试试~ 我知道了~
视图库开发示例,拿来即用
共531个文件
class:154个
java:147个
xml:131个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 3 下载量 121 浏览量
2024-09-29
11:17:39
上传
评论
收藏 32.72MB RAR 举报
温馨提示
使用java开发,支持1400接入和级联 支持功能如下: 注册、心跳、注销、订阅、回调、人脸、机动车、非机动车、人员、图像等功能。 也支持二次推送,可自行选择推送给第三方,或写进指定的存储中,只需要实现ViewLibProducedDataService中的sendMessage方法既可。 如需支持高并发,需自行进行更改和调优。
资源推荐
资源详情
资源评论
收起资源包目录
视图库开发示例,拿来即用 (531个子文件)
02b5d026be7b49742912207049fb661c1ffd2142 215B
041f522da4f7523dfafc230a092f5af2a53c5e8e 0B
0565ba3dde24e400b7368fb1fb658b073f329cd1 0B
08a8b343eb3d041b4e874e74bf19e4275b4be110 0B
094e2a9356781479366eb6b2424ace81a2e9e9a3 0B
0b2921580113fb32efe85029aaa1af4e9c82a833 260B
12d28df3c730cbe6d8432f861bb50dcd1f6e8d57 90B
20b8fb42742a12c85860e15cdfbf4f648445ac64 0B
22a3f4c4d2d68683d22316b4923748f16bd15182 593B
252fcd68cbae0882d21d2d73435f8d8fdd390956 351B
2b2074e8b08f4860d0df2af3e3be13559ffa9a76 0B
30684d1edb3f081d851d0829a7d4ab17b6afcf7b 363B
30b31104403cf65ce046976e904a44df362e2ea3 113B
3277abe1758ded024ee4375150da930c68e8ee64 0B
3347d0e7d0692fc596aed458706abb792406e3ac 0B
335da1eca31d1afaf0a869cfd1823d1f336cf56d 0B
4810ae949d683e456eb1ceb40febcae1dfe99055 2KB
488bdbea7e8b73c44bd2a54e63f6012f10969196 0B
48f0a1e61657850adc988baec25653eb504b097c 211B
49cc34abc0cd6da3fce3f38d49ef198107147645 104B
4f47b3e712d5e489c5c2af9199a26778425b81b8 217B
5136c69be114df3ab045d5514a9a5e54f7a8198a 245B
5573049e2dc763f8357f4fc29ef1a3379775c233 832B
582c33e18d7c9ccb03af44b9515995e5450aed07 90B
5859a1394db4fb3b137935209940add95540f364 0B
63b5db53f3928404b682e5c938726442de0c1743 0B
672dd75256e5316a5b0bd184a925037f92748c71 0B
6eb2e9b5b6f91943302906ad88c44513e55db50e 0B
6f93696a3e1af2fa663d9aa2d045a443207d7e8e 111B
73defd12a31646535f69460d2dcd923decd9a154 104B
7608525e1044cc944de9c6ebfe578da28ff1cc5a 313B
7b6c1462cc3f2b78a4e9592d35c94a6c39266bb3 0B
8028fabdecdaca39b167a5056ea942e24344b4ea 0B
8e72d7bce72526531fab190a3d6cb3f4002785b8 91B
8ec9a00bfd09b3190ac6b22251dbb1aa95a0579d 0B
8fea62787228c31e593e7f52698593757f1cd412 90B
97de6d72e7952337859345302d42acd01ff1b596 113B
9e89e584df2a66f1484ccc2872e7299ef47ddf80 0B
9f69281f98edb507527925ff11fcb77b70a866bd 0B
a2bae7e255566c5f12896f37c8468eeb5e195c17 0B
a95cd33997b9c48680e8676d44946ac64aa2ebea 0B
ad20217a43d1a2d14dbe52392be31c5736cef454 118B
af72c365f99cb6302b9a963e7c54d69d0f664c9e 104B
b0943d9006dc3f49b84a125134f84e9d8d29bc22 255B
b0a2768a9bf3fd0a7a2c69cfbe1132ecb39a0236 0B
b6bad16f6361f36da5d8b2c4ce226b65792ee095 0B
b9a1117b3a12ef8dc627bb648f903d797684f93b 0B
bc4f2fe787b1b2b9ec0151f8432bfff380b74eff 813B
c010c61f82a6bbe5e425fbbdc6dd9dd0db302c45 116B
c29437166a2b7e7de0518be85ad86d82381a3128 58B
c348a39dadbf3ac6a9458abdfd47c318ad38fd04 285B
c794e6af9acb0f13138ad311169f6c5dca09e16f 0B
PlatformServiceImpl.class 18KB
ViewLibAcceptDataServiceImpl.class 16KB
RESTClient.class 16KB
CascadePlatformRequestServiceImpl.class 15KB
ViewLibraryCascadeSubscribe.class 14KB
ViewLibraryCascadeDeviceServiceImpl.class 12KB
CascadePlatformServiceImpl.class 12KB
ViewLibraryCascadeSubscribe.class 11KB
ViewLibraryDomainSubscribe.class 11KB
ImageInfoObjectBean.class 10KB
ViewLibraryDomainChannel.class 10KB
ViewLibraryCascadeChannel.class 8KB
CascadeSubscribeController.class 8KB
MotorVehicleObject.class 8KB
ToolUtil.class 8KB
DigestAuthenticator.class 7KB
ViewLibraryCascadeSubscribeController.class 7KB
SubscribeController.class 6KB
ViewLibraryCustomSubscribeController.class 6KB
SubscribeBase.class 6KB
ViewLibSubscribeRequestService.class 6KB
SubscribeNotificationsRequest.class 6KB
ViewLibraryDomainChannelServiceImpl.class 6KB
SubscribeNotificationObject.class 6KB
DateUtil.class 6KB
ViewLibraryCascadeChannelServiceImpl.class 5KB
PlatformController.class 5KB
ViewLibraryCascadeSubscribeServiceImpl.class 5KB
FaceObject.class 5KB
FastAutoGeneratorTest.class 5KB
ViewLibraryCascadeDevice.class 5KB
ViewLibraryCascadeDevice.class 5KB
ViewLibraryDomainDevice.class 5KB
ViewLibraryCascadeChannel.class 4KB
ViewLibraryCascadeSubscribeServiceImpl.class 4KB
ViewLibraryDomainSubscribeServiceImpl.class 4KB
ResponseStatusListModeObject.class 4KB
AcceptController.class 4KB
RequestLogAspect.class 4KB
GsonUtil.class 4KB
ViewLibraryDomainDeviceServiceImpl.class 4KB
APEObject.class 4KB
ResponseStatus.class 3KB
ResponseStatusObject.class 3KB
QueryDeviceResponseObject.class 3KB
CommonUtlis.class 3KB
SubImageInfoObject.class 3KB
URLParameter.class 3KB
共 531 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论
- weixin_525465162024-11-16资源很受用,资源主总结的很全面,内容与描述一致,解决了我当下的问题。
- weixin_512740642024-11-20资源不错,内容挺好的,有一定的使用价值,值得借鉴,感谢分享。
- qq_357161062024-11-15发现一个宝藏资源,赶紧冲冲冲!支持大佬~
一枚开发小咸鱼
- 粉丝: 1930
- 资源: 53
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 日志文件:日志概念、LogBack日志技术的概述、使用、logback.xml配置文件详解
- 基于python使用Drl来解决多智能体卸载问题+源码(期末作业&课程设计&项目开发)
- 科学计算领域中的Fortran语言基础知识与应用
- 4.健身房预约课程-微信小程序.zip
- 小乌龟键盘控制源码111111
- 电赛2023年本科组电子电路设计比赛指南与任务解析
- Delphi 12 控件之dspack For Delphi 10.2 - 视频播放组件包e963a-main.zip
- delphi 12 控件之FB4D – The OpenSource Cross-Platform Library for FirebaseFB4D-master.zip
- Rust语言入门与进阶教程
- delphi 12 控件之Delphi开发的微信电脑版登录工具ec617-main.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功