魏熙美 6 年之前
父節點
當前提交
a7b127d211

+ 14
- 6
CODE/smart-community/app-api/src/main/java/com/community/huiju/controller/HkController.java 查看文件

@@ -5,16 +5,14 @@ import com.community.commom.mode.HkResponseBean;
5 5
 import com.community.commom.mode.ResponseBean;
6 6
 import com.community.commom.session.UserElement;
7 7
 import com.community.huiju.model.HkVisitorBill;
8
+import com.community.huiju.service.IHKService;
8 9
 import io.swagger.annotations.Api;
9 10
 import io.swagger.annotations.ApiImplicitParam;
10 11
 import io.swagger.annotations.ApiImplicitParams;
11 12
 import io.swagger.annotations.ApiOperation;
13
+import org.springframework.beans.factory.annotation.Autowired;
12 14
 import org.springframework.cloud.context.config.annotation.RefreshScope;
13
-import org.springframework.web.bind.annotation.PathVariable;
14
-import org.springframework.web.bind.annotation.RequestBody;
15
-import org.springframework.web.bind.annotation.RequestMapping;
16
-import org.springframework.web.bind.annotation.RequestMethod;
17
-import org.springframework.web.bind.annotation.RestController;
15
+import org.springframework.web.bind.annotation.*;
18 16
 
19 17
 import javax.servlet.http.HttpSession;
20 18
 
@@ -27,7 +25,10 @@ import javax.servlet.http.HttpSession;
27 25
 @RequestMapping("/")
28 26
 @Api(value = "海康相关的API",description = "海康相关的API")
29 27
 public class HkController {
30
-	
28
+
29
+	@Autowired
30
+	private IHKService ihkService;
31
+
31 32
 	@ApiOperation(value = "发送访客账单", notes = "发送访客账单")
32 33
 	@ApiImplicitParams({ @ApiImplicitParam(paramType = "body", name = "hkVisitorBill", dataType = "String",value = "billNum: 账单号,reservationNum:预约单号,plateNum:出场车牌号,leaveTime:出场时间,billFee:账单金额")})
33 34
 	@RequestMapping(value = "/sendVisitorBill",method = RequestMethod.POST)
@@ -41,4 +42,11 @@ public class HkController {
41 42
 		hkResponseBean.addSuccess("账单发送成功","");
42 43
 		return hkResponseBean;
43 44
 	}
45
+
46
+	@RequestMapping(value = "推送HK人员", method = RequestMethod.POST)
47
+	public ResponseBean pushHKPerson(@RequestParam("appUserId") String appUserId) {
48
+		ResponseBean responseBean = new ResponseBean();
49
+		responseBean = ihkService.pushPerson(appUserId);
50
+		return responseBean;
51
+	}
44 52
 }

+ 2
- 2
CODE/smart-community/app-api/src/main/java/com/community/huiju/controller/WxLoginController.java 查看文件

@@ -71,9 +71,9 @@ public class WxLoginController extends BaseController {
71 71
 			@ApiImplicitParam(paramType = "body",dataType = "String",name = "parameter",value = "userName用户姓名;idCard身份证;gender性别(1:男  2:女);loginName手机号;code验证码;openid微信标识;nickname微信用户名称")
72 72
 	})
73 73
 	@RequestMapping(value = "/wx/register",method = RequestMethod.POST)
74
-	public ResponseBean register(@RequestBody String parameter, HttpSession session) {
74
+	public ResponseBean register(@RequestBody String parameter, HttpServletRequest request ,HttpSession session) {
75 75
 		ResponseBean responseBean = new ResponseBean();
76
-		responseBean = wxLoginService.register(parameter);
76
+		responseBean = wxLoginService.register(parameter, request);
77 77
 		TaUserVO userVO = (TaUserVO) responseBean.getData();
78 78
 		if (null != userVO) {
79 79
 			setUserElement(userVO, session);

+ 1
- 0
CODE/smart-community/app-api/src/main/java/com/community/huiju/model/TaVisitor.java 查看文件

@@ -163,4 +163,5 @@ public class TaVisitor {
163 163
     public void setCarLicense(List<String> carLicense) {
164 164
         this.carLicense = carLicense;
165 165
     }
166
+
166 167
 }

+ 18
- 0
CODE/smart-community/app-api/src/main/java/com/community/huiju/service/IHKService.java 查看文件

@@ -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
+}

+ 3
- 1
CODE/smart-community/app-api/src/main/java/com/community/huiju/service/WxLoginServiceI.java 查看文件

@@ -2,6 +2,8 @@ package com.community.huiju.service;
2 2
 
3 3
 import com.community.commom.mode.ResponseBean;
4 4
 
5
+import javax.servlet.http.HttpServletRequest;
6
+
5 7
 public interface WxLoginServiceI {
6 8
 
7 9
 	/**
@@ -23,5 +25,5 @@ public interface WxLoginServiceI {
23 25
 	 * @param parameter
24 26
 	 * @return
25 27
 	 */
26
-	ResponseBean register(String parameter);
28
+	ResponseBean register(String parameter, HttpServletRequest request);
27 29
 }

+ 221
- 0
CODE/smart-community/app-api/src/main/java/com/community/huiju/service/impl/HKServiceImpl.java 查看文件

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

+ 120
- 154
CODE/smart-community/app-api/src/main/java/com/community/huiju/service/impl/TaUserServiceImpl.java 查看文件

@@ -20,6 +20,7 @@ import com.community.huiju.dao.*;
20 20
 import com.community.huiju.enums.UserVerifyEnum;
21 21
 import com.community.huiju.exception.WisdomException;
22 22
 import com.community.huiju.model.*;
23
+import com.community.huiju.service.IHKService;
23 24
 import com.community.huiju.service.ITaUserService;
24 25
 import com.community.huiju.service.ImageServiceI;
25 26
 import com.community.huiju.vo.TaUserVO;
@@ -71,9 +72,6 @@ public class TaUserServiceImpl implements ITaUserService {
71 72
     @Autowired
72 73
     private TaUserMapper taUserMapper;
73 74
 
74
-    @Autowired
75
-    private TpBuildingOwnerInfoMapper tpBuildingOwnerInfoMapper;
76
-
77 75
     @Autowired
78 76
     private TaSysRoleMapper taSysRoleMapper;
79 77
 
@@ -105,6 +103,45 @@ public class TaUserServiceImpl implements ITaUserService {
105 103
     @Autowired
106 104
     private LoginCodePerproties loginCodePerproties;
107 105
 
106
+    @Autowired
107
+    private IHKService ihkService;
108
+
109
+    /**
110
+     * 期
111
+     */
112
+    @Autowired
113
+    private TpPhaseMapper tpPhaseMapper;
114
+
115
+    /**
116
+     * 单元
117
+     */
118
+    @Autowired
119
+    private TpUnitMapper tpUnitMapper;
120
+
121
+    /**
122
+     * 楼层
123
+     */
124
+    @Autowired
125
+    private TpLevelMapper tpLevelMapper;
126
+
127
+    /**
128
+     * 栋
129
+     */
130
+    @Autowired
131
+    private TpBuildingMapper tpBuildingMapper;
132
+
133
+    /**
134
+     * 楼栋资料库
135
+     */
136
+    @Autowired
137
+    private TpBuildingOwnerInfoMapper tpBuildingOwnerInfoMapper;
138
+
139
+    /**
140
+     * 户号
141
+     */
142
+    @Autowired
143
+    private TpRoomNoMapper tpRoomNoMapper;
144
+
108 145
     @Override
109 146
     @Transactional(rollbackFor = Exception.class)
110 147
     public ResponseBean login(String loginName, String code, HttpSession session) {
@@ -192,6 +229,10 @@ public class TaUserServiceImpl implements ITaUserService {
192 229
 
193 230
         // 校验房产
194 231
         List<TaUserVerify> taUserVerifies = taUserVerifyMapper.selectByUserId(currentUser.getId());
232
+        taUserVerifies.forEach(e->{
233
+            e.setVerifyUrl(loginCodePerproties.getLoginCode().get("-1") + e.getId());
234
+        });
235
+        taUserVO.setUserVerifyList(taUserVerifies);
195 236
         // 无关联房产
196 237
         if (null == taUserVerifies || taUserVerifies.size() == 0) {
197 238
             String token = null;
@@ -213,10 +254,6 @@ public class TaUserServiceImpl implements ITaUserService {
213 254
 
214 255
             return checkHouse(response, taUserVO, userVerify);
215 256
         } else if (taUserVerifies.size() >= 2) {
216
-            taUserVerifies.forEach(e->{
217
-                e.setVerifyUrl(loginCodePerproties.getLoginCode().get("-1") + e.getId());
218
-            });
219
-            taUserVO.setUserVerifyList(taUserVerifies);
220 257
             response.addSuccess(UserVerifyEnum.A_MULTIPLE_REAL_ESTATE.getMsg(), taUserVO, loginCodePerproties.getLoginCode().get(UserVerifyEnum.A_MULTIPLE_REAL_ESTATE.getCode()));
221 258
             return response;
222 259
         }
@@ -247,35 +284,6 @@ public class TaUserServiceImpl implements ITaUserService {
247 284
         userVO.setCommunityName(toCommunities.getCommunityName());
248 285
     }
249 286
 
250
-    /**
251
-     * 可视对讲下发
252
-     *
253
-     * @param user
254
-     */
255
-    private void visualIntercom(TaUser user) {
256
-        // TODO 目前下发的 authName权限组是我们自定义的, 后面肯定是按照小区的 期楼栋号来设置的
257
-        // TODO longNums设备编号, 可视对讲的机器编号, 应该根据 期楼栋号 下面的机器编号来设置的
258
-
259
-        //--------- 可视对讲 ----------
260
-
261
-        // 可视对讲 根据人员 ID 集添加权限并下发
262
-        Map<String, Object> addOutDoorAuthMap = new HashMap<>();
263
-        addOutDoorAuthMap.put("authName", "荟居");
264
-        addOutDoorAuthMap.put("personIds", Arrays.asList(user.getHkUserId()));
265
-        addOutDoorAuthMap.put("longNums", Arrays.asList("10010100000"));
266
-        // 可视对讲 根据人员 ID 集添加权限并下发
267
-        HKOpenApi.addOutDoorAuth(addOutDoorAuthMap);
268
-
269
-        // 可视对讲 指定人员指纹权限下载
270
-//        Map<String, Object> downloadFingerMap = new HashMap<>();
271
-//        // opType 操作类型 Integer 是 1 为下发权限;2 为删除权限
272
-//        downloadFingerMap.put("opType", 1);
273
-//        downloadFingerMap.put("personIds", Arrays.asList(user.getHkUserId()));
274
-//        downloadFingerMap.put("longNums", Arrays.asList("10010100000"));
275
-//        // 可视对讲 指定人员指纹权限下载
276
-//        HKOpenApi.downloadFinger(downloadFingerMap);
277
-
278
-    }
279 287
 
280 288
     @Transactional(rollbackFor = Exception.class)
281 289
     @Override
@@ -475,7 +483,9 @@ public class TaUserServiceImpl implements ITaUserService {
475 483
         // 返回值 code 为 1,表示已经注册
476 484
         if ("1".equals(response.getCode())) {
477 485
             // 用户数据查询出来
478
-            user = taUserMapper.selectByPrimaryKey(user.getId());
486
+            Map<String, Object> map = Maps.newHashMap();
487
+            map.put("loginName", user.getLoginName());
488
+            user = taUserMapper.selectByLoginName(map);
479 489
         } else {
480 490
             user = (TaUser) response.getData();
481 491
         }
@@ -505,31 +515,86 @@ public class TaUserServiceImpl implements ITaUserService {
505 515
 
506 516
         taUserVerifyMapper.insertSelective(userVerify);
507 517
 
508
-        // 设置 海康id
509
-        user.setHkPersonNo(idGen.nextId());
510
-
518
+        // 插入楼栋资料库
519
+        TpBuildingOwnerInfo buildingInfo = getBuildingInfo(userElement, user.getLoginName());
520
+        if (null == buildingInfo) {
521
+            insertTpBuildingOwnerInfo(userElement, user, null);
522
+        }
511 523
 
512 524
         // 推送海康
513
-        /**
514
-         * 1.获取部门(比如 住户)
515
-         * 2.根据部门编号推送 海康
516
-         */
517
-        addUserAndOpenCard(response, user);
525
+        response = ihkService.pushPerson(user.getId()+"");
526
+        if ("1".equals(response.getCode())) {
527
+            throw new WisdomException("推送HK失败!");
528
+        }
518 529
 
519
-        // 给用户添加 海康门禁权限
520
-        HKOpenApi.addAuthoritiesByPersonIds(String.valueOf(user.getHkUserId()));
530
+        response.addSuccess(user);
531
+        return response;
532
+    }
521 533
 
522
-        // 下发门禁权限
523
-        HKOpenApi.downloadAuthorityByDeviceUuids();
534
+    /**
535
+     * 查询 楼栋信息
536
+     *      根据小区Id, 栋,单元,楼层,房号, 手机号
537
+     * @param userElement
538
+     * @param phone
539
+     * @return
540
+     */
541
+    private TpBuildingOwnerInfo getBuildingInfo(UserElement userElement, String phone) {
524 542
 
525
-        //--------- 可视对讲 ----------
526
-        visualIntercom(user);
543
+        TpBuildingOwnerInfo selectBuild = tpBuildingOwnerInfoMapper.selectCommunityAndAddressAndPhone(userElement.getCommunityId(),
544
+                userElement.getPhaseId(), userElement.getBuildingId(), userElement.getUnitId(), userElement.getLevelId(),
545
+                userElement.getRoomNoId(), phone);
527 546
 
528
-        if ("0".equals(response.getCode())) {
529
-            response.addSuccess(user);
530
-        }
547
+        return selectBuild;
548
+    }
531 549
 
532
-        return response;
550
+    /**
551
+     * 插入 楼栋资料库
552
+     *
553
+     * @param userElement
554
+     * @param user
555
+     * @param userId 创建人
556
+     */
557
+    private TpBuildingOwnerInfo insertTpBuildingOwnerInfo (UserElement userElement, TaUser user, Integer userId) {
558
+        TpBuildingOwnerInfo tpBuildingOwnerInfo = new TpBuildingOwnerInfo();
559
+        // 查询 期/楼栋/单元/层/户号
560
+        TpPhase phase = tpPhaseMapper.selectByPrimaryKey(userElement.getPhaseId());
561
+        TpBuilding building = tpBuildingMapper.selectByPrimaryKey(userElement.getBuildingId());
562
+        TpUnit unit = tpUnitMapper.selectByPrimaryKey(userElement.getUnitId());
563
+        TpLevel level = tpLevelMapper.selectByPrimaryKey(userElement.getLevelId());
564
+        TpRoomNo roomNo = tpRoomNoMapper.selectByPrimaryKey(userElement.getRoomNoId());
565
+
566
+
567
+        // 主键是自增的, 所以设置为 null
568
+        tpBuildingOwnerInfo.setId(null);
569
+        tpBuildingOwnerInfo.setPhaseId(phase.getId());
570
+        tpBuildingOwnerInfo.setPhaseName(phase.getName());
571
+        tpBuildingOwnerInfo.setBuildingId(building.getId());
572
+        tpBuildingOwnerInfo.setBuildingName(building.getName());
573
+        tpBuildingOwnerInfo.setUnitId(unit.getId());
574
+        tpBuildingOwnerInfo.setUnitName(unit.getName());
575
+        tpBuildingOwnerInfo.setLevelId(level.getId());
576
+        tpBuildingOwnerInfo.setLevelName(level.getName());
577
+        tpBuildingOwnerInfo.setRoomNoId(roomNo.getId());
578
+        tpBuildingOwnerInfo.setRoomNoName(roomNo.getName());
579
+        tpBuildingOwnerInfo.setOwnerName(user.getUserName());
580
+        tpBuildingOwnerInfo.setOwnerTel(user.getLoginName());
581
+        tpBuildingOwnerInfo.setGender(user.getGender());
582
+        // tpBuildingOwnerInfo.setUpdateUser(userId);
583
+        tpBuildingOwnerInfo.setUpdateDate(new Date());
584
+        tpBuildingOwnerInfo.setCreateDate(new Date());
585
+        // tpBuildingOwnerInfo.setCreateUser(userId);
586
+        tpBuildingOwnerInfo.setVerifyStatus("1");
587
+        tpBuildingOwnerInfo.setPairStatus("1");
588
+
589
+        // 添加的时候, 默认是当前操作的小区
590
+        tpBuildingOwnerInfo.setCommunityId(userElement.getCommunityId());
591
+
592
+        int row = tpBuildingOwnerInfoMapper.insertSelective(tpBuildingOwnerInfo);
593
+        if (row <= 0) {
594
+            log.error("添加操作! 楼栋业主信息表 失败!");
595
+            throw new WisdomException("操作失败!");
596
+        }
597
+        return tpBuildingOwnerInfo;
533 598
     }
534 599
 
535 600
     @Override
@@ -595,60 +660,7 @@ public class TaUserServiceImpl implements ITaUserService {
595 660
         return response;
596 661
     }
597 662
 
598
-    /**
599
-     * 公共方法
600
-     * 添加人员, 开卡
601
-     *
602
-     * @param response
603
-     * @param user
604
-     */
605
-    private void addUserAndOpenCard(ResponseBean response, TaUser user) {
606
-        Map<String, Object> parDept = Maps.newHashMap();
607
-        parDept.put("pageNo", 1);
608
-        parDept.put("pageSize", 100);
609
-        parDept.put("deptName", Constant.DEPT_RESIDENTS);
610
-        // 部门UUID
611
-        String deptUuid = getDeptUUID(parDept);
612 663
 
613
-        // 添加人员
614
-        Map<String, Object> parUser = Maps.newHashMap();
615
-        parUser.put("personNo", user.getHkPersonNo());
616
-        parUser.put("personName", user.getUserName());
617
-        parUser.put("phoneNo", user.getLoginName());
618
-        parUser.put("deptUuid", deptUuid);
619
-        Map<String, Object> resultMap = JSONObject.parseObject(HKOpenApi.addUser(parUser), HashMap.class);
620
-        int errorCode = (int) resultMap.get("errorCode");
621
-        if (errorCode == 0) {
622
-            Map<String, Object> resultDataMap = (Map<String, Object>) resultMap.get("data");
623
-            // 开卡 卡号
624
-            long cardNo = System.currentTimeMillis();
625
-            // 海康人员ID
626
-            Integer personId = (Integer) resultDataMap.get("personId");
627
-            TaUser tempUser = taUserMapper.selectByPrimaryKey(user.getId());
628
-            tempUser.setHkUserId(personId);
629
-            tempUser.setHkCardNo(cardNo + "");
630
-
631
-            user.setHkUserId(personId);
632
-            // 存储海康人员ID
633
-            int row = taUserMapper.updateByPrimaryKeySelective(tempUser);
634
-            if (row > 0) {
635
-                response.addSuccess("操作成功!");
636
-            } else {
637
-                response.addError("操作失败");
638
-                throw new RuntimeException("数据库添加 家属/租客 人员失败!");
639
-            }
640
-
641
-            // 开卡
642
-            List<String> cardAndPersonList = Lists.newArrayList();
643
-            cardAndPersonList.add(cardNo + "," + personId);
644
-            response = openCard(cardAndPersonList, null);
645
-        } else {
646
-            String errorMessage = String.valueOf(resultMap.get("errorMessage"));
647
-            response.addError(errorMessage);
648
-            log.error("海康添加人员失败! {}", errorMessage);
649
-            throw new RuntimeException(errorMessage);
650
-        }
651
-    }
652 664
 
653 665
     /**
654 666
      * 公共方法
@@ -701,53 +713,7 @@ public class TaUserServiceImpl implements ITaUserService {
701 713
         return deptUuid;
702 714
     }
703 715
 
704
-    /**
705
-     * 批量开卡
706
-     *
707
-     * @param cardIdAndHKUserID list.add("卡号,人员ID")
708
-     * @param expirationTime    有效期为多少? 单位为 年
709
-     * @return
710
-     */
711
-    private ResponseBean openCard(List<String> cardIdAndHKUserID, Integer expirationTime) {
712
-        ResponseBean response = new ResponseBean();
713
-
714
-        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
715
-        LocalDate today = LocalDate.now();
716
-        int year = today.getYear();
717
-        // 加上20, 表示加上20年,默认
718
-        if (null == expirationTime || expirationTime <= 0) {
719
-            year += 20;
720
-        } else {
721
-            year += expirationTime;
722
-        }
723
-        int month = today.getMonthValue();
724
-        int day = today.getDayOfMonth();
725 716
 
726
-        Long time = null;
727
-        try {
728
-            time = formatter.parse(year + "-" + month + "-" + day).getTime();
729
-        } catch (ParseException e) {
730
-            e.printStackTrace();
731
-        }
732
-
733
-        // 开卡
734
-        Map<String, Object> parOpenCard = Maps.newHashMap();
735
-        parOpenCard.put("cardAndPerson", cardIdAndHKUserID);
736
-        parOpenCard.put("startTime", System.currentTimeMillis());
737
-        parOpenCard.put("endTime", time);
738
-        JSONObject openCardJSON = JSONObject.parseObject(HKOpenApi.openCard(parOpenCard));
739
-        int code = (int) openCardJSON.get("errorCode");
740
-        if (code == 0) {
741
-            response.addSuccess("操作成功!");
742
-        } else {
743
-            String errorMessage = String.valueOf(openCardJSON.get("errorMessage"));
744
-            response.addError(errorMessage);
745
-            log.error("开卡失败! {}", errorMessage);
746
-            throw new RuntimeException(errorMessage);
747
-        }
748
-
749
-        return response;
750
-    }
751 717
 
752 718
     /**
753 719
      * 公共方法,添加或者修改 角色.

+ 17
- 1
CODE/smart-community/app-api/src/main/java/com/community/huiju/service/impl/TaUserVerifyServicelmpl.java 查看文件

@@ -2,11 +2,13 @@ package com.community.huiju.service.impl;
2 2
 
3 3
 
4 4
 import com.alibaba.fastjson.JSONObject;
5
+import com.community.commom.constant.Constant;
5 6
 import com.community.commom.mode.ResponseBean;
6 7
 import com.community.commom.session.UserElement;
7 8
 import com.community.huiju.dao.*;
8 9
 import com.community.huiju.exception.WisdomException;
9 10
 import com.community.huiju.model.*;
11
+import com.community.huiju.service.IHKService;
10 12
 import com.community.huiju.service.TaUserVerifyServicel;
11 13
 import com.community.huiju.vo.TaUserVO;
12 14
 import lombok.extern.slf4j.Slf4j;
@@ -80,6 +82,9 @@ public class TaUserVerifyServicelmpl implements TaUserVerifyServicel {
80 82
     @Autowired
81 83
     private TpRoomNoMapper tpRoomNoMapper;
82 84
 
85
+    @Autowired
86
+    private IHKService ihkService;
87
+
83 88
     @Override
84 89
     public ResponseBean getToAuditNotApproved(Integer userVerifyId) {
85 90
         ResponseBean responseBean = new ResponseBean();
@@ -228,7 +233,7 @@ public class TaUserVerifyServicelmpl implements TaUserVerifyServicel {
228 233
             responseBean.addError("该审核不存在!");
229 234
             return responseBean;
230 235
         }
231
-        if (!"0".equals(userVerify.getVerifyStatus())) {
236
+        if (!Constant.TO_AUDIT.equals(userVerify.getVerifyStatus())) {
232 237
             responseBean.addError("只能审核待审状态!");
233 238
             return responseBean;
234 239
         }
@@ -238,6 +243,11 @@ public class TaUserVerifyServicelmpl implements TaUserVerifyServicel {
238 243
             userVerify.setVerifyStatus(userVerifyStatus);
239 244
             userVerify.setRemark(remark);
240 245
             taUserVerifyMapper.updateByPrimaryKeySelective(userVerify);
246
+            // 如果业主审核 租客/家属 不是审核通过的状态, 就不在往下执行
247
+            if (!Constant.APPROVED.equals(userVerifyStatus)) {
248
+                responseBean.addError("操作成功!");
249
+                return responseBean;
250
+            }
241 251
 
242 252
             // 获取这个被审核的用户
243 253
             TaUser user = taUserMapper.selectByPrimaryKey(userVerify.getUserId());
@@ -283,6 +293,12 @@ public class TaUserVerifyServicelmpl implements TaUserVerifyServicel {
283 293
                 message.setCreateDate(new Date());
284 294
                 tpMessageMapper.insert(message);
285 295
             }
296
+            // 推送海康
297
+            responseBean = ihkService.pushPerson(user.getId()+"");
298
+            if ("1".equals(responseBean.getCode())) {
299
+                throw new WisdomException("推送HK失败!");
300
+            }
301
+
286 302
             responseBean.addSuccess("操作成功!");
287 303
             return responseBean;
288 304
         }

+ 31
- 9
CODE/smart-community/app-api/src/main/java/com/community/huiju/service/impl/WxLoginServiceImpl.java 查看文件

@@ -7,6 +7,7 @@ import com.community.huiju.common.code.ICode;
7 7
 import com.community.huiju.common.perproties.LoginCodePerproties;
8 8
 import com.community.huiju.dao.TaUserMapper;
9 9
 import com.community.huiju.enums.UserVerifyEnum;
10
+import com.community.huiju.exception.WisdomException;
10 11
 import com.community.huiju.model.TaUser;
11 12
 import com.community.huiju.service.ITaUserService;
12 13
 import com.community.huiju.service.WxLoginServiceI;
@@ -26,6 +27,8 @@ import org.springframework.stereotype.Service;
26 27
 import org.springframework.transaction.annotation.Transactional;
27 28
 import org.springframework.web.client.RestTemplate;
28 29
 
30
+import javax.servlet.http.HttpServletRequest;
31
+import javax.servlet.http.HttpSession;
29 32
 import java.net.URLDecoder;
30 33
 import java.net.URLEncoder;
31 34
 import java.util.Date;
@@ -77,8 +80,8 @@ public class WxLoginServiceImpl implements WxLoginServiceI {
77 80
 			result.put("openid", openId);
78 81
 
79 82
 			JSONObject userInfoJSON = JSONObject.parseObject(userInfo);
80
-			String wxPar = "&openid=" + openId + "&nickname=" + userInfoJSON.getString("nickname");
81
-			responseBean.addError(UserVerifyEnum.NO_ACCOUNT.getMsg(), result, loginCodePerproties.getLoginCode().get(UserVerifyEnum.NO_ACCOUNT.getCode()) + URLEncoder.encode(wxPar));
83
+			String wxPar = "&openid=" + URLEncoder.encode(openId) + "&nickname=" + URLEncoder.encode(userInfoJSON.getString("nickname"));
84
+			responseBean.addError(UserVerifyEnum.NO_ACCOUNT.getMsg(), result, loginCodePerproties.getLoginCode().get(UserVerifyEnum.NO_ACCOUNT.getCode()) + wxPar);
82 85
 			return responseBean;
83 86
 		}
84 87
 
@@ -135,11 +138,11 @@ public class WxLoginServiceImpl implements WxLoginServiceI {
135 138
 		}
136 139
 
137 140
 		JSONObject jsonObject = JSONObject.parseObject(parameter);
141
+		logger.info("绑定的微信数据是:{}", parameter);
138 142
 
139 143
 		String openid = jsonObject.getString("openid");
140
-		if (StringUtils.isNotBlank(openid)) {
141
-			responseBean.addError("openid 参数缺失!");
142
-			return responseBean;
144
+		if (StringUtils.isBlank(openid)) {
145
+			throw new WisdomException("openid 参数缺失!");
143 146
 		}
144 147
 
145 148
 		user.setOpenid(openid);
@@ -157,11 +160,13 @@ public class WxLoginServiceImpl implements WxLoginServiceI {
157 160
 
158 161
 	@Transactional(rollbackFor = Exception.class)
159 162
 	@Override
160
-	public ResponseBean register(String parameter) {
161
-		ResponseBean<TaUser> response = new ResponseBean();
163
+	public ResponseBean register(String parameter, HttpServletRequest request) {
164
+		ResponseBean response = new ResponseBean();
162 165
 
163 166
 		JSONObject jsonObject = JSONObject.parseObject(parameter);
167
+		String userName = jsonObject.getString("userName");
164 168
 		TaUser user = jsonObject.toJavaObject(TaUser.class);
169
+		user.setUserName(userName);
165 170
 
166 171
 		Map<String,Object> map = Maps.newHashMap();
167 172
 		map.put("loginName",user.getLoginName());
@@ -190,11 +195,28 @@ public class WxLoginServiceImpl implements WxLoginServiceI {
190 195
 		user.setCreateUser(user.getId());
191 196
 		user.setUpdateUser(user.getId());
192 197
 
198
+		// 这里设置为null,因为在上面的 jsonObject.toJavaObject 装换的时候,自动的吧openid设置到这个user对象了
199
+		// 下面的校验微信绑定时候,会把openid设置上去的
200
+		user.setOpenid(null);
201
+
193 202
 		// 更新
194 203
 		taUserMapper.updateByPrimaryKeySelective(user);
195 204
 
196
-		// 检验微信绑定
197
-		response = checkWX(response, user, parameter);
205
+		// 如果是 普通注册 就把用户数据返回出去
206
+		TaUserVO userVO = new TaUserVO();
207
+		BeanTools.copyProperties(user, userVO);
208
+		// 刚注册的用户,跳转到绑定房产页面
209
+		response.addError(UserVerifyEnum.NO_AUDIT_REAL_ESTATE.getMsg(), userVO, loginCodePerproties.getLoginCode().get(UserVerifyEnum.NO_AUDIT_REAL_ESTATE.getCode()) + "&token=" + request.getSession().getId());
210
+
211
+		/**
212
+		 * 这里是因为 手机号注册 和 社交登录的手机号注册,公用的一个接口,所以有 openid 的时候,表示是微信那边的社交登录
213
+		 * 否则就是普通的 手机号注册
214
+		 */
215
+		String openid = jsonObject.getString("openid");
216
+		if (StringUtils.isNotBlank(openid)) {
217
+			// 检验微信绑定
218
+			response = checkWX(response, user, parameter);
219
+		}
198 220
 
199 221
 		return response;
200 222
 	}