dingxin 6 lat temu
rodzic
commit
04f9d3100a

+ 5
- 0
CODE/smart-community/community-common/src/main/java/com/community/commom/hk/HKConstant.java Wyświetl plik

@@ -124,6 +124,11 @@ public class HKConstant {
124 124
      */
125 125
     public static final String ITF_SELECT_USER ="/openapi/service/acs/auth/getAuthoritiesByPersonIds";
126 126
 
127
+    /**
128
+     * 人员异动
129
+     */
130
+    public static final String ITF_SELECT_USER_SDH="/openapi/service/acs/auth/downloadAuthorityByDeviceUuids";
131
+
127 132
     /**
128 133
      * 删除人员设备
129 134
      */

+ 33
- 6
CODE/smart-community/community-common/src/main/java/com/community/commom/hk/HKOpenApi.java Wyświetl plik

@@ -979,7 +979,7 @@ public class HKOpenApi {
979 979
         //设置时间参数
980 980
         parMap.put("time", System.currentTimeMillis());
981 981
         parMap.put("opUserUuid",HKConstant.OP_USER_UUID);
982
-        parMap.put("personIds",2301+"");
982
+        parMap.put("personIds",opUserUuid+"");
983 983
         parMap.put("doorUuids","91b8ce635b634d468cde925af6e4274c,d40b23e316364bb5a276b99bb6327181,7f866e918ab8452f9eb1d8a25e481530,8b8256fc605d428c9dc797451e3dc432,84d619c5e84942f68047f0bca93fc041");
984 984
         String params =  JSON.toJSONString(parMap);
985 985
         log.info("删除人脸 请求参数:{}", params);
@@ -989,12 +989,12 @@ public class HKOpenApi {
989 989
             log.info("删除人脸 请求返回结果:{}",data);
990 990
         } catch (Exception e) {
991 991
             e.printStackTrace();
992
-            log.error("删除人脸失败!",e);
993
-            throw new RuntimeException("删除人脸失败!");
992
+            log.error("删除人脸失败!",e);
993
+            throw new RuntimeException("删除人脸失败!");
994 994
         }
995 995
         return data;
996 996
     }
997
-        // 查询当前人脸设备信息---(没通)
997
+        // 查询当前人脸设备信息
998 998
     public static String selectUserFace(Integer opUserUuid) {
999 999
         String url = HKConstant.OPENAPI_IP_PORT_HTTP + HKConstant.ITF_SELECT_USER;
1000 1000
         Map<String, Object> parMap = new HashMap<String, Object>();
@@ -1002,8 +1002,8 @@ public class HKOpenApi {
1002 1002
         parMap.put("appkey", HKConstant.APPKEY);
1003 1003
         //设置时间参数
1004 1004
         parMap.put("time", System.currentTimeMillis());
1005
-        parMap.put("pageNo","1");
1006
-        parMap.put("pageSize","100");
1005
+        parMap.put("pageNo",1);
1006
+        parMap.put("pageSize",100);
1007 1007
         parMap.put("opUserUuid",HKConstant.OP_USER_UUID);
1008 1008
         parMap.put("personIds",opUserUuid+"");
1009 1009
         String params =  JSON.toJSONString(parMap);
@@ -1020,4 +1020,31 @@ public class HKOpenApi {
1020 1020
         return data;
1021 1021
     }
1022 1022
 
1023
+    /**
1024
+     * 人员异动(同步硬件)
1025
+     * @return
1026
+     */
1027
+    public static String selectUserSynchronization() {
1028
+        String url = HKConstant.OPENAPI_IP_PORT_HTTP + HKConstant.ITF_SELECT_USER_SDH;
1029
+        Map<String, Object> parMap = new HashMap<String, Object>();
1030
+        //设置APPKEY
1031
+        parMap.put("appkey", HKConstant.APPKEY);
1032
+        //设置时间参数
1033
+        parMap.put("time", System.currentTimeMillis());
1034
+        parMap.put("opUserUuid",HKConstant.OP_USER_UUID);
1035
+        parMap.put("deviceUuids","91b8ce635b634d468cde925af6e4274c,d40b23e316364bb5a276b99bb6327181,7f866e918ab8452f9eb1d8a25e481530,8b8256fc605d428c9dc797451e3dc432,84d619c5e84942f68047f0bca93fc041");
1036
+        String params =  JSON.toJSONString(parMap);
1037
+        log.info("人员异动 请求参数:{}", params);
1038
+        String data = null;
1039
+        try {
1040
+            data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, params, HKConstant.SECRET), params);
1041
+            log.info("人员异动 请求返回结果:{}",data);
1042
+        } catch (Exception e) {
1043
+            e.printStackTrace();
1044
+            log.error("人员异动失败!",e);
1045
+            throw new RuntimeException("人员异动失败!");
1046
+        }
1047
+        return data;
1048
+    }
1049
+
1023 1050
 }

+ 4
- 4
CODE/smart-community/property-api/src/main/java/com/community/huiju/controller/BuildingTreeController.java Wyświetl plik

@@ -49,7 +49,8 @@ public class BuildingTreeController extends BaseController {
49 49
 	@GetMapping(value = "/trees")
50 50
 	@ApiImplicitParams({
51 51
 			@ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "Token"),
52
-			@ApiImplicitParam(paramType = "body", dataTypeClass = String.class, name = "id", value = "当前节点id(查期时ID为空)")
52
+			@ApiImplicitParam(paramType = "body", dataTypeClass = String.class, name = "id", value = "当前节点id(查期时ID为空)"),
53
+			@ApiImplicitParam(paramType = "body", dataTypeClass = String.class, name = "treeType", value = "phase:(期),building:(栋),unit:(单元),level:(楼层),roomNo:(房间号)")
53 54
 	})
54 55
 	public ResponseBean getTreeList(@RequestParam(value = "id", required = false) Integer id,@RequestParam("treeType") String treeType,HttpSession session){
55 56
 		ResponseBean responseBean = new ResponseBean();UserElement userElement = getUserElement(session);
@@ -61,7 +62,7 @@ public class BuildingTreeController extends BaseController {
61 62
 	@ApiOperation(value = "添加当前节点", notes = "添加当前节点")
62 63
 	@ApiImplicitParams({
63 64
 			@ApiImplicitParam(paramType = "body", dataTypeClass = String.class, name = "parameter", value = "id:当前节点;" +
64
-					"name:节点名称;type:类型,nodeNumber:输入的节点")
65
+					"name:节点名称;type:(phase:(期),building:(栋),unit:(单元),level:(楼层),roomNo:(房间号)), roomNonodeNumber:输入的节点")
65 66
 	})
66 67
 	@RequestMapping(value = "/addnode",method = RequestMethod.POST)
67 68
 	public ResponseBean addNode(@RequestBody String parameter, HttpSession session){
@@ -72,8 +73,7 @@ public class BuildingTreeController extends BaseController {
72 73
 
73 74
 	@ApiOperation(value = "删除当前节点", notes = "删除当前节点")
74 75
 	@ApiImplicitParams({
75
-			@ApiImplicitParam(paramType = "body", dataTypeClass = String.class, name = "parameter", value = "id:当前节点;" +
76
-					"name:节点名称;type:类型,nodeNumber:输入的节点")
76
+			@ApiImplicitParam(paramType = "body", dataTypeClass = String.class, name = "parameter", value = "id:当前节点;type:(end:(房间),roomNo:(楼层),level:(单元),unit:(楼栋),building:(期))")
77 77
 	})
78 78
 	@RequestMapping(value = "/deletenode",method = RequestMethod.POST)
79 79
 	public ResponseBean deletenode(@RequestBody String parameter, HttpSession session){

+ 18
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/service/IHKService.java Wyświetl plik

@@ -0,0 +1,18 @@
1
+package com.community.huiju.service;
2
+
3
+import com.community.commom.mode.ResponseBean;
4
+
5
+/**
6
+ * 海康 业务
7
+ * @author weiximei
8
+ */
9
+public interface IHKService {
10
+
11
+    /**
12
+     * 推送海康人员
13
+     * @param appUserId
14
+     * @return
15
+     */
16
+    ResponseBean pushPerson(String appUserId);
17
+
18
+}

+ 0
- 3
CODE/smart-community/property-api/src/main/java/com/community/huiju/service/impl/BuildingTreeServiceImpl.java Wyświetl plik

@@ -294,7 +294,6 @@ public class BuildingTreeServiceImpl implements BuildingTreeServiceI {
294 294
 		 //当前输入的节点内容
295 295
 		 String nodeNumber= object.getString("nodeNumber");
296 296
 
297
-		//楼栋
298 297
 		/*查询出期*/
299 298
 		if(type.equals("phase")) {
300 299
 			//是否存在同样的名字
@@ -333,7 +332,6 @@ public class BuildingTreeServiceImpl implements BuildingTreeServiceI {
333 332
 						 .setCreateDate(LocalDateTime.now());
334 333
 			tpBuildingMapper.insert(tpBuilding);
335 334
 		}
336
-		//单元
337 335
 		//查询栋,维护单元
338 336
 		 TpBuilding selectTpBuilding= tpBuildingMapper.selectById(id);
339 337
 		if (type.equals("unit")){
@@ -359,7 +357,6 @@ public class BuildingTreeServiceImpl implements BuildingTreeServiceI {
359 357
 		 	 tpUnitMapper.insert(tpUnit);
360 358
 		 }
361 359
 
362
-		//楼层
363 360
 		//查询单元,维护楼层
364 361
 		 TpUnit selectTpUnit= tpUnitMapper.selectById(id);
365 362
 		if(type.equals("level")){

+ 18
- 3
CODE/smart-community/property-api/src/main/java/com/community/huiju/service/impl/FaceServicelimpl.java Wyświetl plik

@@ -17,6 +17,7 @@ import com.community.huiju.model.TaFace;
17 17
 import com.community.huiju.model.TaUser;
18 18
 import com.community.huiju.model.TaUserVerify;
19 19
 import com.community.huiju.service.FaceServiceI;
20
+import com.community.huiju.service.IHKService;
20 21
 import com.community.huiju.service.ImageServiceI;
21 22
 import lombok.extern.slf4j.Slf4j;
22 23
 import org.springframework.beans.factory.annotation.Autowired;
@@ -59,6 +60,9 @@ public class FaceServicelimpl implements FaceServiceI {
59 60
     @Autowired
60 61
     private TaUserVerifyMapper taUserVerifyMapper;
61 62
 
63
+    @Autowired
64
+    private IHKService ihkService;
65
+
62 66
     @Override
63 67
     @Transactional(rollbackFor = Exception.class)
64 68
     public ResponseBean addFace(UserElement userElement, MultipartFile uploadFile, Integer otherUserId,String phaseName,String buildingName,String unitName,String levelName,String roomNoName) {
@@ -201,12 +205,22 @@ public class FaceServicelimpl implements FaceServiceI {
201 205
 
202 206
     @Override
203 207
     public ResponseBean deleteFace(Integer otherUserId, String phaseName, String buildingName, String unitName, String levelName, String roomNoName) {
208
+        ResponseBean responseBean= new ResponseBean();
204 209
         TaUserVerify taUserVerify= infoExist(phaseName,buildingName,unitName,levelName, roomNoName,otherUserId);
205 210
         TaUser taUser= taUserMapper.selectById(taUserVerify.getUserId());
211
+
206 212
         // TODO 删除人脸,是否删除海康
207
-//        HKOpenApi.selectUser(taUser.getHkUserId());
208
-        HKOpenApi.deleteUser(taUser.getHkUserId());
209
-        return null;
213
+        HKOpenApi.selectUserFace(taUser.getHkUserId());
214
+        String data= HKOpenApi.deleteUser(taUser.getHkUserId());
215
+        JSONObject object= JSONObject.parseObject(data);
216
+        if (object.get("errorCode").equals(1)){
217
+            String errorMessage=  object.getString("errorMessage");
218
+            responseBean.addError(errorMessage);
219
+            return responseBean;
220
+        }
221
+           HKOpenApi.selectUserSynchronization();
222
+//        ihkService.pushPerson(taUserVerify.getUserId() + "");
223
+        return responseBean;
210 224
     }
211 225
 
212 226
     /**
@@ -246,6 +260,7 @@ public class FaceServicelimpl implements FaceServiceI {
246 260
         TaUserVerify taUserVerify= taUserVerifyMapper.selectOne(queryTaUserVerify);
247 261
         return taUserVerify;
248 262
     }
263
+
249 264
 }
250 265
 
251 266
 

+ 227
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/service/impl/HKServiceImpl.java Wyświetl plik

@@ -0,0 +1,227 @@
1
+package com.community.huiju.service.impl;
2
+
3
+import com.alibaba.fastjson.JSONArray;
4
+import com.alibaba.fastjson.JSONObject;
5
+import com.community.commom.constant.Constant;
6
+import com.community.commom.hk.HKOpenApi;
7
+import com.community.commom.mode.ResponseBean;
8
+import com.community.commom.uuid.IdGen;
9
+import com.community.huiju.dao.TaUserMapper;
10
+import com.community.huiju.exception.WisdomException;
11
+import com.community.huiju.model.TaUser;
12
+import com.community.huiju.service.IHKService;
13
+import com.google.common.collect.Lists;
14
+import com.google.common.collect.Maps;
15
+import lombok.extern.slf4j.Slf4j;
16
+import org.springframework.beans.factory.annotation.Autowired;
17
+import org.springframework.stereotype.Service;
18
+import org.springframework.transaction.annotation.Transactional;
19
+
20
+import java.text.ParseException;
21
+import java.text.SimpleDateFormat;
22
+import java.time.LocalDate;
23
+import java.util.Arrays;
24
+import java.util.HashMap;
25
+import java.util.List;
26
+import java.util.Map;
27
+
28
+/**
29
+ * 海康 业务实现
30
+ * @author weiximei
31
+ */
32
+@Service
33
+@Slf4j
34
+public class HKServiceImpl implements IHKService {
35
+
36
+    @Autowired
37
+    private TaUserMapper taUserMapper;
38
+
39
+    private IdGen idGen = IdGen.get();
40
+
41
+    @Override
42
+    @Transactional(rollbackFor = Exception.class)
43
+    public ResponseBean pushPerson(String appUserId) {
44
+        ResponseBean responseBean = new ResponseBean();
45
+        TaUser user = taUserMapper.selectById(Integer.parseInt(appUserId));
46
+        // 这两个值一般都是同时存在的
47
+        // 当这两个值不存在的时候,就添加海康人员
48
+        if (null == user.getHkUserId() && null == user.getHkPersonNo()) {
49
+            // 设置 海康id
50
+            user.setHkPersonNo(idGen.nextId());
51
+            /**
52
+             * 1.获取部门(比如 住户)
53
+             * 2.根据部门编号推送 海康
54
+             */
55
+            taUserMapper.updateById(user);
56
+            addUserAndOpenCard(responseBean, user);
57
+        }
58
+
59
+
60
+
61
+        // 推送海康
62
+
63
+        // 给用户添加 海康门禁权限
64
+        HKOpenApi.addAuthoritiesByPersonIds(String.valueOf(user.getHkUserId()));
65
+
66
+        // 下发门禁权限
67
+        HKOpenApi.downloadAuthorityByDeviceUuids();
68
+
69
+        //--------- 可视对讲 ----------
70
+        visualIntercom(user);
71
+        if ("0".equals(responseBean.getCode())) {
72
+            responseBean.addSuccess("操作成功!");
73
+            return responseBean;
74
+        }
75
+        throw new WisdomException("操作失败!");
76
+    }
77
+
78
+    /**
79
+     * 公共方法
80
+     * 添加人员, 开卡
81
+     *
82
+     * @param response
83
+     * @param user
84
+     */
85
+    private void addUserAndOpenCard(ResponseBean response, TaUser user) {
86
+        Map<String, Object> parDept = Maps.newHashMap();
87
+        parDept.put("pageNo", 1);
88
+        parDept.put("pageSize", 100);
89
+        parDept.put("deptName", Constant.DEPT_RESIDENTS);
90
+        // 部门UUID
91
+        String deptUuid = getDeptUUID(parDept);
92
+
93
+        // 添加人员
94
+        Map<String, Object> parUser = Maps.newHashMap();
95
+        parUser.put("personNo", user.getHkPersonNo());
96
+        parUser.put("personName", user.getUserName());
97
+        parUser.put("phoneNo", user.getLoginName());
98
+        parUser.put("deptUuid", deptUuid);
99
+        Map<String, Object> resultMap = JSONObject.parseObject(HKOpenApi.addUser(parUser), HashMap.class);
100
+        int errorCode = (int) resultMap.get("errorCode");
101
+        if (errorCode == 0) {
102
+            Map<String, Object> resultDataMap = (Map<String, Object>) resultMap.get("data");
103
+            // 开卡 卡号
104
+            long cardNo = System.currentTimeMillis();
105
+            // 海康人员ID
106
+            Integer personId = (Integer) resultDataMap.get("personId");
107
+            TaUser tempUser = taUserMapper.selectById(user.getId());
108
+            tempUser.setHkUserId(personId);
109
+            tempUser.setHkCardNo(cardNo + "");
110
+
111
+            user.setHkUserId(personId);
112
+            // 存储海康人员ID
113
+            int row = taUserMapper.updateById(tempUser);
114
+            if (row > 0) {
115
+                response.addSuccess("操作成功!");
116
+            } else {
117
+                response.addError("操作失败");
118
+                throw new RuntimeException("数据库添加 家属/租客 人员失败!");
119
+            }
120
+
121
+            // 开卡
122
+            List<String> cardAndPersonList = Lists.newArrayList();
123
+            cardAndPersonList.add(cardNo + "," + personId);
124
+            response = openCard(cardAndPersonList, null);
125
+        } else {
126
+            String errorMessage = String.valueOf(resultMap.get("errorMessage"));
127
+            response.addError(errorMessage);
128
+            log.error("海康添加人员失败! {}", errorMessage);
129
+            throw new RuntimeException(errorMessage);
130
+        }
131
+    }
132
+
133
+    /**
134
+     * 批量开卡
135
+     *
136
+     * @param cardIdAndHKUserID list.add("卡号,人员ID")
137
+     * @param expirationTime    有效期为多少? 单位为 年
138
+     * @return
139
+     */
140
+    private ResponseBean openCard(List<String> cardIdAndHKUserID, Integer expirationTime) {
141
+        ResponseBean response = new ResponseBean();
142
+
143
+        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
144
+        LocalDate today = LocalDate.now();
145
+        int year = today.getYear();
146
+        // 加上20, 表示加上20年,默认
147
+        if (null == expirationTime || expirationTime <= 0) {
148
+            year += 20;
149
+        } else {
150
+            year += expirationTime;
151
+        }
152
+        int month = today.getMonthValue();
153
+        int day = today.getDayOfMonth();
154
+
155
+        Long time = null;
156
+        try {
157
+            time = formatter.parse(year + "-" + month + "-" + day).getTime();
158
+        } catch (ParseException e) {
159
+            e.printStackTrace();
160
+        }
161
+
162
+        // 开卡
163
+        Map<String, Object> parOpenCard = Maps.newHashMap();
164
+        parOpenCard.put("cardAndPerson", cardIdAndHKUserID);
165
+        parOpenCard.put("startTime", System.currentTimeMillis());
166
+        parOpenCard.put("endTime", time);
167
+        JSONObject openCardJSON = JSONObject.parseObject(HKOpenApi.openCard(parOpenCard));
168
+        int code = (int) openCardJSON.get("errorCode");
169
+        if (code == 0) {
170
+            response.addSuccess("操作成功!");
171
+        } else {
172
+            String errorMessage = String.valueOf(openCardJSON.get("errorMessage"));
173
+            response.addError(errorMessage);
174
+            log.error("开卡失败! {}", errorMessage);
175
+            throw new RuntimeException(errorMessage);
176
+        }
177
+
178
+        return response;
179
+    }
180
+
181
+    /**
182
+     * 获取部门 uuid
183
+     * <p>
184
+     * 这里的部门相当于 小区
185
+     *
186
+     * @return
187
+     */
188
+    private String getDeptUUID(Map<String, Object> parDept) {
189
+        Map<String, Object> deptMap = JSONObject.parseObject(HKOpenApi.getDeptName(parDept), HashMap.class);
190
+        Map<String, Object> deptDataMap = (Map<String, Object>) deptMap.get("data");
191
+        JSONArray jsonArray = (JSONArray) deptDataMap.get("list");
192
+        Map<String, Object> deptListData = (Map<String, Object>) jsonArray.get(0);
193
+        // 部门UUID
194
+        String deptUuid = (String) deptListData.get("deptUuid");
195
+        return deptUuid;
196
+    }
197
+
198
+    /**
199
+     * 可视对讲下发
200
+     *
201
+     * @param user
202
+     */
203
+    private void visualIntercom(TaUser user) {
204
+        // TODO 目前下发的 authName权限组是我们自定义的, 后面肯定是按照小区的 期楼栋号来设置的
205
+        // TODO longNums设备编号, 可视对讲的机器编号, 应该根据 期楼栋号 下面的机器编号来设置的
206
+
207
+        //--------- 可视对讲 ----------
208
+
209
+        // 可视对讲 根据人员 ID 集添加权限并下发
210
+        Map<String, Object> addOutDoorAuthMap = new HashMap<>();
211
+        addOutDoorAuthMap.put("authName", "荟居");
212
+        addOutDoorAuthMap.put("personIds", Arrays.asList(user.getHkUserId()));
213
+        addOutDoorAuthMap.put("longNums", Arrays.asList("10010100000"));
214
+        // 可视对讲 根据人员 ID 集添加权限并下发
215
+        HKOpenApi.addOutDoorAuth(addOutDoorAuthMap);
216
+
217
+        // 可视对讲 指定人员指纹权限下载
218
+//        Map<String, Object> downloadFingerMap = new HashMap<>();
219
+//        // opType 操作类型 Integer 是 1 为下发权限;2 为删除权限
220
+//        downloadFingerMap.put("opType", 1);
221
+//        downloadFingerMap.put("personIds", Arrays.asList(user.getHkUserId()));
222
+//        downloadFingerMap.put("longNums", Arrays.asList("10010100000"));
223
+//        // 可视对讲 指定人员指纹权限下载
224
+//        HKOpenApi.downloadFinger(downloadFingerMap);
225
+
226
+    }
227
+}