|
@@ -0,0 +1,168 @@
|
|
1
|
+package com.community.huiju.controller;
|
|
2
|
+
|
|
3
|
+import com.alibaba.fastjson.JSONArray;
|
|
4
|
+import com.alibaba.fastjson.JSONObject;
|
|
5
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
6
|
+import com.community.commom.hk.HKConstant;
|
|
7
|
+import com.community.commom.hk.HKOpenApi;
|
|
8
|
+import com.community.commom.mode.ResponseBean;
|
|
9
|
+import com.community.commom.session.UserElement;
|
|
10
|
+import com.community.huiju.model.TpConfiguration;
|
|
11
|
+import com.community.huiju.model.TpEquipment;
|
|
12
|
+import com.community.huiju.model.TpEquipmentTree;
|
|
13
|
+import com.community.huiju.service.ITpConfigurationService;
|
|
14
|
+import com.community.huiju.service.ITpEquipmentService;
|
|
15
|
+import com.community.huiju.service.ITpEquipmentTreeService;
|
|
16
|
+import io.swagger.annotations.Api;
|
|
17
|
+import io.swagger.annotations.ApiImplicitParam;
|
|
18
|
+import io.swagger.annotations.ApiImplicitParams;
|
|
19
|
+import io.swagger.annotations.ApiOperation;
|
|
20
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
21
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
22
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
23
|
+import org.springframework.web.bind.annotation.RequestMethod;
|
|
24
|
+import org.springframework.web.bind.annotation.RestController;
|
|
25
|
+
|
|
26
|
+import javax.servlet.http.HttpSession;
|
|
27
|
+import java.time.LocalDateTime;
|
|
28
|
+import java.util.HashMap;
|
|
29
|
+import java.util.List;
|
|
30
|
+import java.util.Map;
|
|
31
|
+
|
|
32
|
+@RestController
|
|
33
|
+@RequestMapping("/")
|
|
34
|
+@Api(value = "自动配置门禁设备", description = "自动配置门禁设备")
|
|
35
|
+public class HkDoorsController {
|
|
36
|
+
|
|
37
|
+ @Autowired
|
|
38
|
+ private ITpConfigurationService tpConfigurationService;
|
|
39
|
+
|
|
40
|
+ @Autowired
|
|
41
|
+ private ITpEquipmentTreeService tpEquipmentTreeService;
|
|
42
|
+
|
|
43
|
+ @Autowired
|
|
44
|
+ private ITpEquipmentService tpEquipmentService;
|
|
45
|
+
|
|
46
|
+ @ApiOperation(value = "自动按小区配置门禁设备", notes = "自动按小区配置门禁设备")
|
|
47
|
+ @ApiImplicitParams({
|
|
48
|
+ @ApiImplicitParam(paramType = "path", dataTypeClass = String.class, name = "communityId", value = "小区ID")
|
|
49
|
+ })
|
|
50
|
+ @RequestMapping(value = "/auto/door/{communityId}",method = RequestMethod.GET)
|
|
51
|
+ public ResponseBean autoDoors(@PathVariable Integer communityId) {
|
|
52
|
+ ResponseBean responseBean = new ResponseBean();
|
|
53
|
+ //根小区获取设备树的详细信息
|
|
54
|
+ QueryWrapper<TpEquipmentTree> queryWrapper = new QueryWrapper<>();
|
|
55
|
+ queryWrapper.eq("community_id",communityId);
|
|
56
|
+ TpEquipmentTree tpEquipmentTree = tpEquipmentTreeService.getOne(queryWrapper);
|
|
57
|
+ //获取此小区的全部门禁点
|
|
58
|
+ Map<String,Object> parMap = new HashMap<>();
|
|
59
|
+ parMap.put("appkey",tpEquipmentTree.getAppkey());
|
|
60
|
+ parMap.put("pageNo",1);
|
|
61
|
+ parMap.put("pageSize",100);
|
|
62
|
+ parMap.put("opUserUuid", tpEquipmentTree.getOpUserUuid());
|
|
63
|
+ parMap.put("secret", tpEquipmentTree.getSecret());
|
|
64
|
+ parMap.put("openapi_ip_port_http", tpEquipmentTree.getHttpServer());
|
|
65
|
+ JSONObject jsonObject = JSONObject.parseObject(HKOpenApi.getDoorDevices(parMap));
|
|
66
|
+ if (jsonObject.getIntValue("errorCode") != 0){
|
|
67
|
+ responseBean.addError(jsonObject.getString("errorMessage"));
|
|
68
|
+ return responseBean;
|
|
69
|
+ }
|
|
70
|
+ JSONArray jsonArray = jsonObject.getJSONObject("data").getJSONArray("list");
|
|
71
|
+ for (Object doorsJson : jsonArray){
|
|
72
|
+ addDoorsData(communityId,tpEquipmentTree.getId(),doorsJson);
|
|
73
|
+ }
|
|
74
|
+ responseBean.addSuccess("插入成功");
|
|
75
|
+ return responseBean;
|
|
76
|
+ }
|
|
77
|
+
|
|
78
|
+ /**
|
|
79
|
+ * 添加新的设备
|
|
80
|
+ * @param communityId
|
|
81
|
+ * @param equipmentTreeId
|
|
82
|
+ * @param doorsJson
|
|
83
|
+ */
|
|
84
|
+ private void addDoorsData(Integer communityId, Integer equipmentTreeId, Object doorsJson) {
|
|
85
|
+ JSONObject doorJson = (JSONObject) doorsJson;
|
|
86
|
+ boolean state = getSaveDoorState(communityId,equipmentTreeId,doorJson);
|
|
87
|
+ if (state){
|
|
88
|
+ //插入配置表config
|
|
89
|
+ TpConfiguration tpConfiguration = new TpConfiguration();
|
|
90
|
+ tpConfiguration.setKey("");
|
|
91
|
+ tpConfiguration.setConfigurationName(doorJson.getString("deviceName"));
|
|
92
|
+ tpConfiguration.setConfigurationType(1);
|
|
93
|
+ tpConfiguration.setConfigurationValue(doorJson.getString("longNumber"));
|
|
94
|
+ tpConfiguration.setCreateTiem(LocalDateTime.now());
|
|
95
|
+ tpConfiguration.setCreateUser(1);
|
|
96
|
+ tpConfiguration.setUpdateTime(LocalDateTime.now());
|
|
97
|
+ tpConfiguration.setUpdateUser(1);
|
|
98
|
+ tpConfiguration.setCommunityId(communityId);
|
|
99
|
+ tpConfiguration.setDoorUuid(null);
|
|
100
|
+ tpConfiguration.setDeviceUuid(doorJson.getString("deviceUuid"));
|
|
101
|
+ tpConfiguration.setDeviceType(1);
|
|
102
|
+ tpConfigurationService.save(tpConfiguration);
|
|
103
|
+
|
|
104
|
+ //插入设备
|
|
105
|
+ TpEquipment tpEquipment = new TpEquipment();
|
|
106
|
+ tpEquipment.setCommunityId(communityId);
|
|
107
|
+ tpEquipment.setCreateTime(LocalDateTime.now());
|
|
108
|
+ tpEquipment.setCreateUser(1);
|
|
109
|
+ tpEquipment.setUpdateTime(LocalDateTime.now());
|
|
110
|
+ tpEquipment.setUpdateUser(1);
|
|
111
|
+ tpEquipment.setUuidId(tpConfiguration.getId());
|
|
112
|
+ tpEquipment.setEquipmentType("3");
|
|
113
|
+ tpEquipment.setEquipmentTreeId(equipmentTreeId);
|
|
114
|
+ tpEquipmentService.save(tpEquipment);
|
|
115
|
+
|
|
116
|
+ //插入配置表config
|
|
117
|
+ TpConfiguration videoConfiguration = new TpConfiguration();
|
|
118
|
+ videoConfiguration.setKey("高清地址");
|
|
119
|
+ videoConfiguration.setConfigurationName(doorJson.getString("deviceName")+"_视频流");
|
|
120
|
+ videoConfiguration.setConfigurationType(1);
|
|
121
|
+ videoConfiguration.setConfigurationValue("标清地址");
|
|
122
|
+ videoConfiguration.setCreateTiem(LocalDateTime.now());
|
|
123
|
+ videoConfiguration.setCreateUser(1);
|
|
124
|
+ videoConfiguration.setUpdateTime(LocalDateTime.now());
|
|
125
|
+ videoConfiguration.setUpdateUser(1);
|
|
126
|
+ videoConfiguration.setCommunityId(communityId);
|
|
127
|
+ videoConfiguration.setDoorUuid(null);
|
|
128
|
+ videoConfiguration.setDeviceUuid(doorJson.getString("deviceUuid"));
|
|
129
|
+// videoConfiguration.setDeviceType(1);
|
|
130
|
+ tpConfigurationService.save(videoConfiguration);
|
|
131
|
+
|
|
132
|
+ //插入设备
|
|
133
|
+ TpEquipment videoEquipment = new TpEquipment();
|
|
134
|
+ videoEquipment.setCommunityId(communityId);
|
|
135
|
+ videoEquipment.setCreateTime(LocalDateTime.now());
|
|
136
|
+ videoEquipment.setCreateUser(1);
|
|
137
|
+ videoEquipment.setUpdateTime(LocalDateTime.now());
|
|
138
|
+ videoEquipment.setUpdateUser(1);
|
|
139
|
+ videoEquipment.setEquipmentType("5");
|
|
140
|
+ videoEquipment.setUuidId(videoConfiguration.getId());
|
|
141
|
+ videoEquipment.setEquipmentTreeId(equipmentTreeId);
|
|
142
|
+ videoEquipment.setAppkey("dbeb0f364e9149c19b06a858c5bb7c29");
|
|
143
|
+ videoEquipment.setSecret("0b1933480ffbf01e9e5e5f4447033d12");
|
|
144
|
+ tpEquipmentService.save(videoEquipment);
|
|
145
|
+ }
|
|
146
|
+
|
|
147
|
+ }
|
|
148
|
+
|
|
149
|
+ /**
|
|
150
|
+ * 判断是否插入字段
|
|
151
|
+ * @param communityId
|
|
152
|
+ * @param equipmentTreeId
|
|
153
|
+ * @param doorJson
|
|
154
|
+ * @return
|
|
155
|
+ */
|
|
156
|
+ private boolean getSaveDoorState(Integer communityId, Integer equipmentTreeId, JSONObject doorJson) {
|
|
157
|
+ QueryWrapper<TpConfiguration> tpConfigurationQueryWrapper = new QueryWrapper<>();
|
|
158
|
+ tpConfigurationQueryWrapper.eq("community_id",communityId);
|
|
159
|
+ tpConfigurationQueryWrapper.isNotNull("deviceUuid");
|
|
160
|
+ List<TpConfiguration> configurationList = tpConfigurationService.list(tpConfigurationQueryWrapper);
|
|
161
|
+ for (TpConfiguration tpConfiguration : configurationList){
|
|
162
|
+ if (tpConfiguration.getDeviceUuid().equals(doorJson.getString("deviceUuid"))){
|
|
163
|
+ return false;
|
|
164
|
+ }
|
|
165
|
+ }
|
|
166
|
+ return true;
|
|
167
|
+ }
|
|
168
|
+}
|