傅行帆 6 yıl önce
ebeveyn
işleme
ae68646811

+ 4
- 0
CODE/smart-community/app-api/src/main/java/com/community/huiju/dao/TaUserVerifyMapper.java Dosyayı Görüntüle

@@ -98,4 +98,8 @@ public interface TaUserVerifyMapper {
98 98
                                            @Param("levelId") Integer levelId,
99 99
                                            @Param("roomNoId") Integer roomNoId);
100 100
 
101
+    @ResultMap("BaseResultMap")
102
+    @Select("select * from ta_user_verify where community_id=#{communityId}" +
103
+            " and verify_status =  1 and id = 1262 ")
104
+    List<TaUserVerify> selectByCommunityId(@Param("communityId") Integer communityId);
101 105
 }

+ 283
- 0
CODE/smart-community/app-api/src/main/java/com/community/huiju/service/impl/userDataHKsiteImpl.java Dosyayı Görüntüle

@@ -0,0 +1,283 @@
1
+package com.community.huiju.service.impl;
2
+
3
+import com.alibaba.fastjson.JSONObject;
4
+import com.beust.jcommander.internal.Maps;
5
+import com.community.commom.hk.HKOpenApi;
6
+import com.community.commom.mode.ResponseBean;
7
+import com.community.commom.uuid.IdGen;
8
+import com.community.huiju.dao.*;
9
+import com.community.huiju.exception.WisdomException;
10
+import com.community.huiju.model.*;
11
+import com.community.huiju.service.userDataHKsiteI;
12
+import lombok.extern.slf4j.Slf4j;
13
+import org.springframework.beans.factory.annotation.Autowired;
14
+import org.springframework.stereotype.Service;
15
+import org.springframework.transaction.annotation.Transactional;
16
+import sun.misc.BASE64Encoder;
17
+
18
+import java.io.ByteArrayOutputStream;
19
+import java.io.IOException;
20
+import java.io.InputStream;
21
+import java.net.HttpURLConnection;
22
+import java.net.URL;
23
+import java.text.ParseException;
24
+import java.text.SimpleDateFormat;
25
+import java.time.LocalDate;
26
+import java.util.*;
27
+import java.util.stream.Collectors;
28
+
29
+
30
+@Service
31
+@Slf4j
32
+@Transactional
33
+public class userDataHKsiteImpl  implements userDataHKsiteI {
34
+
35
+    @Autowired
36
+    private TaUserVerifyMapper taUserVerifyMapper;
37
+
38
+    @Autowired
39
+    private TaUserMapper taUserMapper;
40
+
41
+    @Autowired
42
+    private TpUnitHkSettingMapper tpUnitHkSettingMapper;
43
+
44
+
45
+    @Autowired
46
+    private TpEquipmentTreeMapper tpEquipmentTreeMapper;
47
+
48
+    private IdGen idGen = IdGen.get();
49
+
50
+    @Autowired
51
+    private TaUserHkMapper taUserHkMapper;
52
+
53
+    @Autowired
54
+    private TpEquipmentMapper tpEquipmentMapper;
55
+
56
+
57
+    @Autowired
58
+    private TpConfigurationMapper tpConfigurationMapper;
59
+
60
+    @Autowired
61
+    private TaFaceMapper taFaceMapper;
62
+
63
+    @Override
64
+    public ResponseBean cleanHKdata(Integer communityId) {
65
+        //根据小区id查询审核数据
66
+        List<TaUserVerify> userVerifyList = taUserVerifyMapper.selectByCommunityId(communityId);
67
+
68
+        for (TaUserVerify taUserVerify : userVerifyList){
69
+            //重新构建海康和我们的关系
70
+            buildHKData(taUserVerify);
71
+        }
72
+
73
+        return null;
74
+    }
75
+
76
+    private void buildHKData(TaUserVerify taUserVerify) {
77
+        //查询人脸信息
78
+        TaFace taFace = taFaceMapper.getByUserVerifyId(taUserVerify.getId());
79
+
80
+        TaUserHk taUserHk = new TaUserHk();
81
+        taUserHk.setHkPersonNo(idGen.nextId());
82
+
83
+
84
+        TaUser taUser = taUserMapper.selectByPrimaryKey(taUserVerify.getUserId());
85
+
86
+        // 海康权限信息
87
+        TpUnitHkSetting unitHkSetting = getUnitHkSetting(taUserVerify.getCommunityId(), taUserVerify.getUnitId());
88
+        TpEquipmentTree tpEquipmentTree = tpEquipmentTreeMapper.selectByCommunityId(taUserVerify.getCommunityId());
89
+        // 开卡 卡号
90
+        long cardNo = System.currentTimeMillis();
91
+        // 添加卡片
92
+        Map<String,Object> addCardsMap = new HashMap<>();
93
+        addCardsMap.put("secret", tpEquipmentTree.getSecret());
94
+        addCardsMap.put("appkey", tpEquipmentTree.getAppkey());
95
+        addCardsMap.put("openapi_ip_port_http", tpEquipmentTree.getHttpServer());
96
+        addCardsMap.put("startCardNo", cardNo);
97
+        addCardsMap.put("endCardNo", cardNo);
98
+        addCardsMap.put("opUserUuid", tpEquipmentTree.getOpUserUuid());
99
+        String addCardsJSON = HKOpenApi.addCards(addCardsMap);
100
+        JSONObject addCardsJsonObject = JSONObject.parseObject(addCardsJSON);
101
+        Integer addCardsResultCode = addCardsJsonObject.getInteger("errorCode");
102
+        if (0 != addCardsResultCode) {
103
+            throw new RuntimeException(addCardsJsonObject.getString("errorMessage"));
104
+        }
105
+
106
+
107
+
108
+        // =================== 添加人员 ===========================
109
+        Map<String, Object> parUser = Maps.newHashMap();
110
+        parUser.put("personNo", taUserHk.getHkPersonNo());
111
+        parUser.put("personName", taUser.getUserName());
112
+        // parUser.put("phoneNo", user.getLoginName());
113
+        parUser.put("remark", taUser.getLoginName());
114
+        parUser.put("deptUuid", unitHkSetting.getDepartmentId());
115
+        parUser.put("secret", tpEquipmentTree.getSecret());
116
+        parUser.put("appkey", tpEquipmentTree.getAppkey());
117
+        parUser.put("openapi_ip_port_http", tpEquipmentTree.getHttpServer());
118
+        parUser.put("opUserUuid", tpEquipmentTree.getOpUserUuid());
119
+        if (null != taFace){
120
+            try {
121
+                parUser.put("facePhoto", encodeImageToBase64(new URL(taFace.getFaceImg())));
122
+            } catch (Exception e) {
123
+                log.info("解析图片出错");
124
+                e.printStackTrace();
125
+            }
126
+            parUser.put("cardNo", cardNo + "");
127
+        }
128
+
129
+        Map<String, Object> resultMap = JSONObject.parseObject(HKOpenApi.addUser(parUser), HashMap.class);
130
+
131
+
132
+        Integer errorCode = (Integer) resultMap.get("errorCode");
133
+        if (errorCode != 0) {
134
+            throw new RuntimeException(String.valueOf(resultMap.get("errorMessage")));
135
+        }
136
+        Map<String, Object> resultDataMap = (Map<String, Object>) resultMap.get("data");
137
+        // 海康人员ID
138
+        Integer personId = (Integer) resultDataMap.get("personId");
139
+        taUserHk.setHkUserId(personId);
140
+
141
+        // =================== 添加卡片 =====================
142
+
143
+
144
+
145
+        taUserHk.setHkCardNo(cardNo + "");
146
+
147
+        taUserHk.setCommunityId(taUserVerify.getCommunityId());
148
+        taUserHk.setTaUserId(taUserVerify.getId());
149
+        taUserHk.setCreateDate(new Date());
150
+        taUserHk.setCreateUser(1);
151
+        taUserHkMapper.insertSelective(taUserHk);
152
+        // ============== 人员绑定卡片 ======================
153
+
154
+        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
155
+        LocalDate today = LocalDate.now();
156
+        int year = today.getYear();
157
+        // 加上20, 表示加上20年,默认
158
+        year += 20;
159
+
160
+        int month = today.getMonthValue();
161
+        int day = today.getDayOfMonth();
162
+
163
+        Long time = null;
164
+        try {
165
+            time = formatter.parse(year + "-" + month + "-" + day).getTime();
166
+        } catch (ParseException e) {
167
+            e.printStackTrace();
168
+        }
169
+
170
+        // 开卡
171
+        Map<String, Object> parOpenCard = Maps.newHashMap();
172
+        parOpenCard.put("personId", taUserHk.getHkUserId());
173
+        parOpenCard.put("cardNo", Long.valueOf(cardNo));
174
+        parOpenCard.put("startTime", System.currentTimeMillis());
175
+        parOpenCard.put("endTime", time);
176
+        parOpenCard.put("secret", tpEquipmentTree.getSecret());
177
+        parOpenCard.put("appkey", tpEquipmentTree.getAppkey());
178
+        parOpenCard.put("openapi_ip_port_http", tpEquipmentTree.getHttpServer());
179
+        parOpenCard.put("opUserUuid", tpEquipmentTree.getOpUserUuid());
180
+        JSONObject openCardJSON = JSONObject.parseObject(HKOpenApi.openCard(parOpenCard));
181
+        int code = (int) openCardJSON.get("errorCode");
182
+        if (code != 0) {
183
+            String errorMessage = String.valueOf(openCardJSON.get("errorMessage"));
184
+            log.error("人员绑定开卡失败! {}", errorMessage);
185
+            throw new RuntimeException(errorMessage);
186
+        }
187
+
188
+        //=================== 下发可是对讲卡权限 =====================
189
+
190
+        //--------- 可视对讲 ----------
191
+
192
+        Map<String,Object> addOutDoorAuthMap = Maps.newHashMap();
193
+        // app用户权限勿动 unitHkSetting.getPermissionId()
194
+        addOutDoorAuthMap.put("authName", taUser.getUserName()+taUserVerify.getId());
195
+        addOutDoorAuthMap.put("personIds", Arrays.asList(taUserHk.getHkUserId()));
196
+        addOutDoorAuthMap.put("secret", tpEquipmentTree.getSecret());
197
+        addOutDoorAuthMap.put("appkey", tpEquipmentTree.getAppkey());
198
+        addOutDoorAuthMap.put("openapi_ip_port_http", tpEquipmentTree.getHttpServer());
199
+        addOutDoorAuthMap.put("opUserUuid", tpEquipmentTree.getOpUserUuid());
200
+
201
+        // 单元门口机
202
+        List<TpEquipment> visualEquipments = tpEquipmentMapper.selectByCommunityIdAndUnitId(taUserVerify.getCommunityId(), taUserVerify.getUnitId(), 3);
203
+        // 可是对讲设备号
204
+        List<String> visualList = visualEquipments.stream()
205
+                .map(e-> tpConfigurationMapper.selectByPrimaryKey(e.getUuidId()).getConfigurationValue())
206
+                .collect(Collectors.toList());
207
+
208
+        addOutDoorAuthMap.put("longNums", visualList); // visualList
209
+        // 可视对讲下发 权限
210
+         String addOutDoorAuthJSONString = HKOpenApi.addOutDoorAuth(addOutDoorAuthMap);
211
+        JSONObject addOutDoorAuthJSON = JSONObject.parseObject(addOutDoorAuthJSONString);
212
+        int addOutDoorAuthJSONCode = (int) addOutDoorAuthJSON.get("errorCode");
213
+        if (addOutDoorAuthJSONCode != 0 ) {
214
+            String errorMessage = String.valueOf(addOutDoorAuthJSON.get("errorMessage"));
215
+            log.error("可视对讲下发 权限失败! {}", errorMessage);
216
+            throw new RuntimeException(errorMessage);
217
+        }
218
+
219
+        try {
220
+            Thread.sleep(2000);
221
+        } catch (InterruptedException e) {
222
+            e.printStackTrace();
223
+        }
224
+
225
+         //================ 可是对讲人脸权限下发 ==============
226
+
227
+        // 可视对讲时 指定人员人脸权限下载
228
+        List<Integer> userIdList = new ArrayList<>();
229
+        userIdList.add(taUserHk.getHkUserId());
230
+
231
+        HKOpenApi.visualIntercom(tpEquipmentTree.getOpUserUuid(), 1, userIdList, visualList, tpEquipmentTree.getAppkey(), tpEquipmentTree.getSecret(), tpEquipmentTree.getHttpServer());
232
+    }
233
+
234
+    /**
235
+     * 海康权限组
236
+     * @return
237
+     */
238
+    private TpUnitHkSetting getUnitHkSetting(Integer communityId, Integer unitId) {
239
+        TpUnitHkSetting tpUnitHkSetting = tpUnitHkSettingMapper.selectByCommunityIdAndUnitId(communityId, unitId);
240
+        if (null == tpUnitHkSetting) {
241
+            throw new WisdomException("权限组未配置");
242
+        }
243
+        return tpUnitHkSetting;
244
+    }
245
+
246
+    public String encodeImageToBase64(URL url) throws Exception {
247
+        //将图片文件转化为字节数组字符串,并对其进行Base64编码处理
248
+        System.out.println("图片的路径为:" + url.toString());
249
+        //打开链接
250
+        HttpURLConnection conn = null;
251
+        try {
252
+            conn = (HttpURLConnection) url.openConnection();
253
+        //设置请求方式为"GET"
254
+            conn.setRequestMethod("GET");
255
+        //超时响应时间为5秒
256
+            conn.setConnectTimeout(5 * 1000);
257
+        //通过输入流获取图片数据
258
+            InputStream inStream = conn.getInputStream();
259
+        //得到图片的二进制数据,以二进制封装得到数据,具有通用性
260
+            ByteArrayOutputStream outStream = new ByteArrayOutputStream();
261
+        //创建一个Buffer字符串
262
+            byte[] buffer = new byte[1024];
263
+        //每次读取的字符串长度,如果为-1,代表全部读取完毕
264
+            int len = 0;
265
+        //使用一个输入流从buffer里把数据读取出来
266
+            while ((len = inStream.read(buffer)) != -1) {
267
+        //用输出流往buffer里写入数据,中间参数代表从哪个位置开始读,len代表读取的长度
268
+                outStream.write(buffer, 0, len);
269
+            }
270
+        //关闭输入流
271
+            inStream.close();
272
+            byte[] data = outStream.toByteArray();
273
+        //对字节数组Base64编码
274
+            BASE64Encoder encoder = new BASE64Encoder();
275
+            String base64 = encoder.encode(data);
276
+            System.out.println("网络文件[{}]编码成base64字符串:[{}]"+url.toString()+base64);
277
+            return base64;//返回Base64编码过的字节数组字符串
278
+        } catch (IOException e) {
279
+            e.printStackTrace();
280
+            throw new Exception("图片上传失败,请联系客服!");
281
+        }
282
+    }
283
+}

+ 7
- 0
CODE/smart-community/app-api/src/main/java/com/community/huiju/service/userDataHKsiteI.java Dosyayı Görüntüle

@@ -0,0 +1,7 @@
1
+package com.community.huiju.service;
2
+
3
+import com.community.commom.mode.ResponseBean;
4
+
5
+public interface userDataHKsiteI {
6
+    ResponseBean cleanHKdata(Integer communityId);
7
+}

+ 41
- 0
CODE/smart-community/app-api/src/main/java/com/community/huiju/siteutil/userDataHKsite.java Dosyayı Görüntüle

@@ -0,0 +1,41 @@
1
+package com.community.huiju.siteutil;
2
+
3
+import com.community.commom.constant.Constant;
4
+import com.community.commom.mode.ResponseBean;
5
+import com.community.commom.session.UserElement;
6
+import com.community.huiju.service.ISenCartId;
7
+import com.community.huiju.service.userDataHKsiteI;
8
+import io.swagger.annotations.Api;
9
+import io.swagger.annotations.ApiImplicitParam;
10
+import io.swagger.annotations.ApiImplicitParams;
11
+import io.swagger.annotations.ApiOperation;
12
+import lombok.extern.slf4j.Slf4j;
13
+import org.springframework.beans.factory.annotation.Autowired;
14
+import org.springframework.cloud.context.config.annotation.RefreshScope;
15
+import org.springframework.web.bind.annotation.*;
16
+
17
+import javax.servlet.http.HttpSession;
18
+
19
+@RestController
20
+@RefreshScope
21
+@RequestMapping("/")
22
+@Api(value = "现场调试工具", description = "现场调试工具")
23
+@Slf4j
24
+public class userDataHKsite {
25
+
26
+
27
+    @Autowired
28
+    private userDataHKsiteI userDataHKsite;
29
+
30
+    @ApiOperation(value = "清洗海康人员录入人脸信息", notes = "清洗海康人员录入人脸信息")
31
+    @ApiImplicitParams({
32
+            @ApiImplicitParam(paramType = "path", dataType = "Integer", name = "communityId", value = "小区ID") })
33
+    @RequestMapping(value = "/site/{communityId}",method = RequestMethod.GET)
34
+    public ResponseBean sitePersionData(@PathVariable("communityId") Integer communityId){
35
+        ResponseBean responseBean = new ResponseBean();
36
+        //查询出审核表中的数据并建人脸
37
+        responseBean = userDataHKsite.cleanHKdata(communityId);
38
+        responseBean.addSuccess("ok");
39
+        return responseBean;
40
+    }
41
+}