提交 | 用户 | 时间
|
149dd0
|
1 |
package com.iailab.module.data.video.dahua; |
H |
2 |
|
08b6a5
|
3 |
import com.iailab.framework.tenant.core.context.TenantContextHolder; |
149dd0
|
4 |
import com.iailab.module.data.video.dto.LogDTO; |
H |
5 |
import com.iailab.module.data.video.dto.NvrDTO; |
|
6 |
import com.iailab.module.data.video.enums.CameraStatusEnum; |
|
7 |
import com.iailab.module.data.video.service.LogService; |
|
8 |
import com.iailab.module.data.video.service.NvrService; |
|
9 |
import org.springframework.beans.factory.annotation.Autowired; |
|
10 |
import org.springframework.stereotype.Component; |
|
11 |
|
|
12 |
import java.util.Date; |
|
13 |
import java.util.Map; |
|
14 |
import java.util.concurrent.ConcurrentHashMap; |
|
15 |
|
|
16 |
/** |
|
17 |
* @author PanZhibao |
|
18 |
* @Description |
|
19 |
* @createTime 2024年04月08日 |
|
20 |
*/ |
|
21 |
@Component |
|
22 |
public class DHClientFactory { |
|
23 |
|
|
24 |
@Autowired |
|
25 |
private NvrService nvrService; |
|
26 |
|
|
27 |
@Autowired |
|
28 |
private LogService logService; |
|
29 |
|
|
30 |
private Map<String, DHCapturePictureClient> clientMap = new ConcurrentHashMap<>(); |
|
31 |
|
|
32 |
public synchronized DHCapturePictureClient getClient(String nvrId) { |
|
33 |
if (clientMap.containsKey(nvrId)) { |
|
34 |
return clientMap.get(nvrId); |
|
35 |
} |
|
36 |
|
|
37 |
DHCapturePictureClient client = new DHCapturePictureClient(); |
|
38 |
if (!DHCapturePictureClient.isInit()) { |
|
39 |
boolean bInit = client.initSDK(); |
|
40 |
LogDTO dto = new LogDTO(); |
|
41 |
dto.setCreateDate(new Date()); |
|
42 |
dto.setEvent("初始化SDK"); |
|
43 |
dto.setDevId("SDK"); |
|
44 |
dto.setContent(bInit ? "初始化SDK成功" : "初始化SDK失败"); |
|
45 |
logService.save(dto); |
|
46 |
} |
|
47 |
NvrDTO nvrDTO = nvrService.get(nvrId); |
|
48 |
if (!client.isLogin()) { |
|
49 |
boolean bLogin = client.login(nvrDTO.getIp(), nvrDTO.getPort(), nvrDTO.getUsername(), nvrDTO.getPassword()); |
|
50 |
|
|
51 |
LogDTO dto = new LogDTO(); |
|
52 |
dto.setCreateDate(new Date()); |
|
53 |
dto.setEvent("登录设备"); |
|
54 |
dto.setDevId(nvrDTO.getIp()); |
|
55 |
dto.setContent(bLogin ? "登录成功" : "登录失败"); |
|
56 |
if (bLogin) { |
|
57 |
nvrService.setStatus(nvrDTO.getIp(), CameraStatusEnum.ONLIEN.getCode()); |
|
58 |
} else { |
|
59 |
nvrService.setStatus(nvrDTO.getIp(), CameraStatusEnum.OFFLINE.getCode()); |
|
60 |
} |
|
61 |
logService.save(dto); |
|
62 |
} |
|
63 |
clientMap.put(nvrId, client); |
|
64 |
return client; |
|
65 |
} |
|
66 |
|
|
67 |
public void reLogin(DHCapturePictureClient client, String nvrId) { |
|
68 |
NvrDTO nvrDTO = nvrService.get(nvrId); |
|
69 |
boolean bLogin = client.login(nvrDTO.getIp(), nvrDTO.getPort(), nvrDTO.getUsername(), nvrDTO.getPassword()); |
|
70 |
LogDTO dto = new LogDTO(); |
|
71 |
dto.setCreateDate(new Date()); |
|
72 |
dto.setEvent("登录设备"); |
|
73 |
dto.setDevId(nvrDTO.getIp()); |
|
74 |
dto.setContent(bLogin ? "登录成功" : "登录失败"); |
|
75 |
if (bLogin) { |
|
76 |
nvrService.setStatus(nvrDTO.getIp(), CameraStatusEnum.ONLIEN.getCode()); |
|
77 |
} else { |
|
78 |
nvrService.setStatus(nvrDTO.getIp(), CameraStatusEnum.OFFLINE.getCode()); |
|
79 |
} |
|
80 |
logService.save(dto); |
|
81 |
} |
|
82 |
|
|
83 |
// public void getNvrOnlineStatus(List<DevNvrEntity> nvrs) { |
|
84 |
// nvrs.stream().forEach(nvr -> { |
|
85 |
// DHCapturePictureClient client = getClient(nvr.getId().toString()); |
|
86 |
// if(!client.isLogin()) { |
|
87 |
// reLogin(client, nvr.getId().toString()); |
|
88 |
// } |
|
89 |
// boolean bLogin = client.login(nvr.getIp(), nvr.getPort(), nvr.getUsername(), nvr.getPassword()); |
|
90 |
// DevLogDTO dto = new DevLogDTO(); |
|
91 |
// dto.setCreateDate(new Date()); |
|
92 |
// dto.setEvent("登录设备"); |
|
93 |
// dto.setDevId(nvr.getIp()); |
|
94 |
// dto.setContent(bLogin ? "登录成功" : "登录失败"); |
|
95 |
// if (bLogin) { |
|
96 |
// nvr.setStatus(CameraStatusEnum.ONLIEN.getCode()); |
|
97 |
// devNvrService.setStatus(nvr.getIp(), CameraStatusEnum.ONLIEN.getCode()); |
|
98 |
// } else { |
|
99 |
// nvr.setStatus(CameraStatusEnum.OFFLINE.getCode()); |
|
100 |
// devNvrService.setStatus(nvr.getIp(), CameraStatusEnum.OFFLINE.getCode()); |
|
101 |
// } |
|
102 |
// devLogService.save(dto); |
|
103 |
// }); |
|
104 |
// } |
|
105 |
} |