|
@@ -1,15 +1,19 @@
|
1
|
1
|
package com.community.huiju.service.impl;
|
2
|
2
|
|
|
3
|
+import com.alibaba.fastjson.JSONArray;
|
3
|
4
|
import com.alibaba.fastjson.JSONObject;
|
4
|
5
|
import com.community.commom.constant.Constant;
|
5
|
6
|
import com.community.commom.mode.ResponseBean;
|
6
|
7
|
import com.community.commom.utils.AccountValidatorUtil;
|
7
|
8
|
import com.community.commom.utils.MD5Utils;
|
8
|
9
|
import com.community.huiju.common.code.cache.AppkeyCache;
|
|
10
|
+import com.community.huiju.common.hk.HKConstant;
|
|
11
|
+import com.community.huiju.common.hk.HKOpenApi;
|
9
|
12
|
import com.community.huiju.dao.*;
|
10
|
13
|
import com.community.huiju.model.*;
|
11
|
14
|
import com.community.huiju.service.ITaUserService;
|
12
|
15
|
import com.community.huiju.vo.TaUserVO;
|
|
16
|
+import com.google.common.collect.Lists;
|
13
|
17
|
import com.google.common.collect.Maps;
|
14
|
18
|
import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ;
|
15
|
19
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -20,9 +24,16 @@ import org.springframework.beans.factory.annotation.Autowired;
|
20
|
24
|
import org.springframework.stereotype.Service;
|
21
|
25
|
import org.springframework.transaction.annotation.Transactional;
|
22
|
26
|
|
|
27
|
+import java.text.ParseException;
|
|
28
|
+import java.text.SimpleDateFormat;
|
|
29
|
+import java.time.LocalDate;
|
|
30
|
+import java.time.LocalDateTime;
|
|
31
|
+import java.time.format.DateTimeFormatter;
|
23
|
32
|
import java.util.Date;
|
|
33
|
+import java.util.HashMap;
|
24
|
34
|
import java.util.List;
|
25
|
35
|
import java.util.Map;
|
|
36
|
+import java.util.logging.SimpleFormatter;
|
26
|
37
|
|
27
|
38
|
/**
|
28
|
39
|
* 用户业务 实现
|
|
@@ -50,7 +61,7 @@ public class TaUserServiceImpl implements ITaUserService {
|
50
|
61
|
@Autowired
|
51
|
62
|
private SysNationMapper sysNationMapper;
|
52
|
63
|
|
53
|
|
- @Transactional
|
|
64
|
+ @Transactional(rollbackFor = Exception.class)
|
54
|
65
|
@Override
|
55
|
66
|
public ResponseBean login(TaUser user) {
|
56
|
67
|
ResponseBean response = new ResponseBean();
|
|
@@ -145,7 +156,7 @@ public class TaUserServiceImpl implements ITaUserService {
|
145
|
156
|
return response;
|
146
|
157
|
}
|
147
|
158
|
|
148
|
|
- @Transactional
|
|
159
|
+ @Transactional(rollbackFor = Exception.class)
|
149
|
160
|
@Override
|
150
|
161
|
public ResponseBean register(TaUser user) {
|
151
|
162
|
|
|
@@ -188,7 +199,8 @@ public class TaUserServiceImpl implements ITaUserService {
|
188
|
199
|
response.addSuccess(taUserVO);
|
189
|
200
|
return response;
|
190
|
201
|
}
|
191
|
|
- @Transactional
|
|
202
|
+
|
|
203
|
+ @Transactional(rollbackFor = Exception.class)
|
192
|
204
|
@Override
|
193
|
205
|
public ResponseBean upDateloginName(Integer id, String paramets) {
|
194
|
206
|
ResponseBean response = new ResponseBean();
|
|
@@ -224,7 +236,7 @@ public class TaUserServiceImpl implements ITaUserService {
|
224
|
236
|
return taUserMapper.selectUserListByParentId(parentId);
|
225
|
237
|
}
|
226
|
238
|
|
227
|
|
- @Transactional
|
|
239
|
+ @Transactional(rollbackFor = Exception.class)
|
228
|
240
|
@Override
|
229
|
241
|
public ResponseBean modifyUser(TaUser user) {
|
230
|
242
|
|
|
@@ -244,7 +256,7 @@ public class TaUserServiceImpl implements ITaUserService {
|
244
|
256
|
return response;
|
245
|
257
|
}
|
246
|
258
|
|
247
|
|
- @Transactional
|
|
259
|
+ @Transactional(rollbackFor = Exception.class)
|
248
|
260
|
@Override
|
249
|
261
|
public ResponseBean startOrEndUsingUser(Integer currentUserId, Integer userId, Integer type) {
|
250
|
262
|
ResponseBean response = null;
|
|
@@ -305,7 +317,7 @@ public class TaUserServiceImpl implements ITaUserService {
|
305
|
317
|
return response;
|
306
|
318
|
}
|
307
|
319
|
|
308
|
|
- @Transactional
|
|
320
|
+ @Transactional(rollbackFor = Exception.class)
|
309
|
321
|
@Override
|
310
|
322
|
public ResponseBean addTenantsOrDependents(String userName, String phone, String gender, Integer currentUserId, Integer type) {
|
311
|
323
|
ResponseBean response = new ResponseBean();
|
|
@@ -351,8 +363,116 @@ public class TaUserServiceImpl implements ITaUserService {
|
351
|
363
|
return response;
|
352
|
364
|
}
|
353
|
365
|
|
|
366
|
+ // 用户添加到本地库
|
354
|
367
|
addUserRole(type,response,user);
|
355
|
368
|
|
|
369
|
+ // 推送海康
|
|
370
|
+ /**
|
|
371
|
+ * 1.获取部门(比如 住户)
|
|
372
|
+ * 2.根据部门编号推送 海康
|
|
373
|
+ */
|
|
374
|
+ addUserAndOpenCard(response,user);
|
|
375
|
+
|
|
376
|
+ return response;
|
|
377
|
+ }
|
|
378
|
+
|
|
379
|
+ /**
|
|
380
|
+ * 公共方法
|
|
381
|
+ * 添加人员, 开卡
|
|
382
|
+ * @param response
|
|
383
|
+ * @param user
|
|
384
|
+ */
|
|
385
|
+ private void addUserAndOpenCard(ResponseBean response,TaUser user){
|
|
386
|
+ Map<String,Object> parDept = Maps.newHashMap();
|
|
387
|
+ parDept.put("pageNo",1);
|
|
388
|
+ parDept.put("pageSize",100);
|
|
389
|
+ parDept.put("deptName",Constant.DEPT_RESIDENTS);
|
|
390
|
+ Map<String,Object> deptMap = JSONObject.parseObject(HKOpenApi.getDeptName(parDept), HashMap.class);
|
|
391
|
+ Map<String,Object> deptDataMap = (Map<String, Object>) deptMap.get("data");
|
|
392
|
+ JSONArray jsonArray = (JSONArray) deptDataMap.get("list");
|
|
393
|
+ Map<String,Object> deptListData = (Map<String, Object>) jsonArray.get(0);
|
|
394
|
+ // 部门UUID
|
|
395
|
+ String deptUuid = (String) deptListData.get("deptUuid");
|
|
396
|
+
|
|
397
|
+ // 添加人员
|
|
398
|
+ Map<String,Object> parUser = Maps.newHashMap();
|
|
399
|
+ parUser.put("personNo",user.getId());
|
|
400
|
+ parUser.put("personName",user.getUserName());
|
|
401
|
+ parUser.put("phoneNo",user.getLoginName());
|
|
402
|
+ parUser.put("deptUuid",deptUuid);
|
|
403
|
+ Map<String,Object> resultMap = JSONObject.parseObject(HKOpenApi.addUser(parUser),HashMap.class);
|
|
404
|
+ int errorCode = (int) resultMap.get("errorCode");
|
|
405
|
+ if (errorCode == 0) {
|
|
406
|
+ Map<String,Object> resultDataMap = (Map<String, Object>) resultMap.get("data");
|
|
407
|
+ // 海康人员ID
|
|
408
|
+ Integer personId = (Integer) resultDataMap.get("personId");
|
|
409
|
+ TaUser tempUser = taUserMapper.selectByPrimaryKey(user.getId());
|
|
410
|
+ tempUser.setHkUserId(personId);
|
|
411
|
+ // 存储海康人员ID
|
|
412
|
+ int row = taUserMapper.updateByPrimaryKeySelective(tempUser);
|
|
413
|
+ if (row > 0) {
|
|
414
|
+ response.addSuccess("操作成功!");
|
|
415
|
+ }else {
|
|
416
|
+ response.addError("操作失败");
|
|
417
|
+ throw new RuntimeException("数据库添加 家属/租客 人员失败!");
|
|
418
|
+ }
|
|
419
|
+
|
|
420
|
+ // 开卡
|
|
421
|
+ List<String> cardAndPersonList = Lists.newArrayList();
|
|
422
|
+ cardAndPersonList.add(System.currentTimeMillis() + "," + personId);
|
|
423
|
+ response = openCard(cardAndPersonList,null);
|
|
424
|
+ }else {
|
|
425
|
+ String errorMessage = String.valueOf(resultMap.get("errorMessage"));
|
|
426
|
+ response.addError(errorMessage);
|
|
427
|
+ log.error("海康添加人员失败! {}",errorMessage);
|
|
428
|
+ throw new RuntimeException(errorMessage);
|
|
429
|
+ }
|
|
430
|
+ }
|
|
431
|
+
|
|
432
|
+ /**
|
|
433
|
+ * 批量开卡
|
|
434
|
+ * @param cardIdAndHKUserID list.add("卡号,人员ID")
|
|
435
|
+ * @param expirationTime 有效期为多少? 单位为 年
|
|
436
|
+ * @return
|
|
437
|
+ */
|
|
438
|
+ private ResponseBean openCard(List<String> cardIdAndHKUserID, Integer expirationTime){
|
|
439
|
+ ResponseBean response = new ResponseBean();
|
|
440
|
+
|
|
441
|
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
|
442
|
+ LocalDate today = LocalDate.now();
|
|
443
|
+ int year = today.getYear();
|
|
444
|
+ // 加上20, 表示加上20年,默认
|
|
445
|
+ if (null == expirationTime || expirationTime <= 0) {
|
|
446
|
+ year += 20;
|
|
447
|
+ } else {
|
|
448
|
+ year += expirationTime;
|
|
449
|
+ }
|
|
450
|
+ int month = today.getMonthValue();
|
|
451
|
+ int day = today.getDayOfMonth();
|
|
452
|
+
|
|
453
|
+ Long time = null;
|
|
454
|
+ try {
|
|
455
|
+ time = formatter.parse(year + "-" + month + "-" + day).getTime();
|
|
456
|
+ } catch (ParseException e) {
|
|
457
|
+ e.printStackTrace();
|
|
458
|
+ }
|
|
459
|
+
|
|
460
|
+ // 开卡
|
|
461
|
+ Map<String,Object> parOpenCard = Maps.newHashMap();
|
|
462
|
+ parOpenCard.put("cardAndPerson",cardIdAndHKUserID);
|
|
463
|
+ parOpenCard.put("startTime",System.currentTimeMillis());
|
|
464
|
+ parOpenCard.put("endTime",time);
|
|
465
|
+ JSONObject openCardJSON = JSONObject.parseObject(HKOpenApi.openCard(parOpenCard));
|
|
466
|
+ int code = (int) openCardJSON.get("errorCode");
|
|
467
|
+ if (code == 0) {
|
|
468
|
+ response.addSuccess("操作成功!");
|
|
469
|
+ }else {
|
|
470
|
+ String errorMessage = String.valueOf(openCardJSON.get("errorMessage"));
|
|
471
|
+ response.addError(errorMessage);
|
|
472
|
+ log.error("开卡失败! {}",errorMessage);
|
|
473
|
+ throw new RuntimeException(errorMessage);
|
|
474
|
+ }
|
|
475
|
+
|
356
|
476
|
return response;
|
357
|
477
|
}
|
358
|
478
|
|