魏熙美 6 年之前
父節點
當前提交
716a0a924d
共有 18 個文件被更改,包括 1135 次插入2 次删除
  1. 38
    0
      CODE/foreign-service/src/main/java/com/community/huiju/dao/TaFaceMapper.java
  2. 20
    0
      CODE/foreign-service/src/main/java/com/community/huiju/dao/TaUserVerifyMapper.java
  3. 16
    0
      CODE/foreign-service/src/main/java/com/community/huiju/dao/TpEquipmentMapper.java
  4. 11
    0
      CODE/foreign-service/src/main/java/com/community/huiju/dao/TpEquipmentTreeMapper.java
  5. 3
    1
      CODE/foreign-service/src/main/java/com/community/huiju/enums/ResponseErrorsMessages.java
  6. 69
    0
      CODE/foreign-service/src/main/java/com/community/huiju/model/TaFace.java
  7. 45
    0
      CODE/foreign-service/src/main/java/com/community/huiju/service/FaceServiceI.java
  8. 32
    0
      CODE/foreign-service/src/main/java/com/community/huiju/service/IHKService.java
  9. 15
    0
      CODE/foreign-service/src/main/java/com/community/huiju/service/ImageServiceI.java
  10. 441
    0
      CODE/foreign-service/src/main/java/com/community/huiju/service/impl/FaceServicelimpl.java
  11. 365
    0
      CODE/foreign-service/src/main/java/com/community/huiju/service/impl/HKServiceImpl.java
  12. 46
    0
      CODE/foreign-service/src/main/java/com/community/huiju/service/impl/ImageServiceimpl.java
  13. 1
    0
      CODE/foreign-service/src/main/resources/application.yml
  14. 5
    0
      CODE/foreign-service/src/main/resources/mapper/TaFaceMapper.xml
  15. 5
    0
      CODE/foreign-service/src/main/resources/mapper/TaSysRoleMapper.xml
  16. 17
    0
      CODE/foreign-service/src/main/resources/mapper/TaUserVerifyMapper.xml
  17. 5
    0
      CODE/foreign-service/src/main/resources/mapper/TpBuildingMapper.xml
  18. 1
    1
      CODE/smart-community/app-api/src/main/resources/mapper/TpHotelMapper.xml

+ 38
- 0
CODE/foreign-service/src/main/java/com/community/huiju/dao/TaFaceMapper.java 查看文件

@@ -0,0 +1,38 @@
1
+package com.community.huiju.dao;
2
+
3
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.community.huiju.model.TaFace;
5
+import org.apache.ibatis.annotations.Param;
6
+
7
+/**
8
+ * <p>
9
+ * 人脸检测图片 Mapper 接口
10
+ * </p>
11
+ *
12
+ * @author jobob
13
+ * @since 2019-05-16
14
+ */
15
+public interface TaFaceMapper extends BaseMapper<TaFace> {
16
+
17
+
18
+    /**
19
+     * 查看当前用户信息
20
+     * @param userVerifyId
21
+     * @return
22
+     */
23
+    TaFace getByUserVerifyId(@Param("userVerifyId") Integer userVerifyId);
24
+
25
+    /**
26
+     * 查看当前信息
27
+     * @param id
28
+     * @return
29
+     */
30
+    TaFace getById(@Param("id")Integer id);
31
+
32
+    /**
33
+     * 根据审核ID删除人脸信息
34
+     * @param verifyId
35
+     */
36
+    void deleteFace(@Param("verifyId") Integer verifyId);
37
+
38
+}

+ 20
- 0
CODE/foreign-service/src/main/java/com/community/huiju/dao/TaUserVerifyMapper.java 查看文件

@@ -74,4 +74,24 @@ public interface TaUserVerifyMapper extends BaseMapper<TaUserVerify> {
74 74
             "where user_id = #{userId} " +
75 75
             "and id = #{userVerifyId} ")
76 76
     TaUserVerify selectByUserIdAndUserVerifyId(Integer userId, Integer userVerifyId);
77
+
78
+    /**
79
+     * 根据 用户id、小区id 、 期、栋、单元、楼层、户号、审核状态  进行条件查询
80
+     * @param communityId
81
+     * @param phaseId
82
+     * @param buildingId
83
+     * @param unitId
84
+     * @param levelId
85
+     * @param roomNoId
86
+     * @param verifyStatus
87
+     * @return
88
+     */
89
+    List<TaUserVerify> selectCommunityAndAddressAndVerifyStatus(@Param("userId") Integer userId,
90
+                                                                @Param("communityId") Integer communityId,
91
+                                                                @Param("phaseId") Integer phaseId,
92
+                                                                @Param("buildingId") Integer buildingId,
93
+                                                                @Param("unitId") Integer unitId,
94
+                                                                @Param("levelId") Integer levelId,
95
+                                                                @Param("roomNoId") Integer roomNoId,
96
+                                                                @Param("verifyStatus") Integer verifyStatus);
77 97
 }

+ 16
- 0
CODE/foreign-service/src/main/java/com/community/huiju/dao/TpEquipmentMapper.java 查看文件

@@ -8,6 +8,8 @@ import org.apache.ibatis.annotations.ResultMap;
8 8
 import org.apache.ibatis.annotations.ResultType;
9 9
 import org.apache.ibatis.annotations.Select;
10 10
 
11
+import java.util.List;
12
+
11 13
 /**
12 14
  * <p>
13 15
  * 设备表 Mapper 接口
@@ -34,4 +36,18 @@ public interface TpEquipmentMapper extends BaseMapper<TpEquipment> {
34 36
             "tp_equipment tm " +
35 37
             "where tm.community_id = #{communityId} and tm.equipment_type = 1")
36 38
     IPage<TpEquipment> selectMonitoringByCommunityId(IPage<TpEquipment> page, @Param("communityId") Integer communityId);
39
+
40
+    /**
41
+     * 根据小区 和 单元号 查询所有设备
42
+     * @param communityId
43
+     * @param unitId
44
+     * @return
45
+     */
46
+    @ResultType(TpEquipment.class)
47
+    @Select("select " +
48
+            "te.* " +
49
+            "from tp_unit_equipment trne left join tp_equipment te " +
50
+            "on trne.equipment_id = te.id " +
51
+            "where trne.community_id=#{communityId} and trne.unit_id=#{unitId} and te.equipment_type=#{equipmentType}")
52
+    List<TpEquipment> selectByCommunityIdAndUnitId(Integer communityId, Integer unitId, int i);
37 53
 }

+ 11
- 0
CODE/foreign-service/src/main/java/com/community/huiju/dao/TpEquipmentTreeMapper.java 查看文件

@@ -2,6 +2,9 @@ package com.community.huiju.dao;
2 2
 
3 3
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4 4
 import com.community.huiju.model.TpEquipmentTree;
5
+import org.apache.ibatis.annotations.Param;
6
+import org.apache.ibatis.annotations.ResultType;
7
+import org.apache.ibatis.annotations.Select;
5 8
 
6 9
 /**
7 10
  * <p>
@@ -13,4 +16,12 @@ import com.community.huiju.model.TpEquipmentTree;
13 16
  */
14 17
 public interface TpEquipmentTreeMapper extends BaseMapper<TpEquipmentTree> {
15 18
 
19
+    /**
20
+     * 根据小区id 查询
21
+     * @param communityId
22
+     * @return
23
+     */
24
+    @ResultType(TpEquipmentTree.class)
25
+    @Select("select * from tp_equipment_tree where community_id = #{communityId}")
26
+    TpEquipmentTree selectByCommunityId(@Param("communityId") Integer communityId);
16 27
 }

+ 3
- 1
CODE/foreign-service/src/main/java/com/community/huiju/enums/ResponseErrorsMessages.java 查看文件

@@ -22,7 +22,9 @@ public enum ResponseErrorsMessages {
22 22
     NO_UNIT(1010, "单元不存在!"),
23 23
     NO_LEVEL(1011, "楼层不存在!"),
24 24
     NO_ROOM_NO(1012, "户号不存在!"),
25
-    NOT_USER_VERIFY(1013, "无房产关联关系!")
25
+    NOT_USER_VERIFY(1013, "无房产关联关系!"),
26
+    NOT_USER_FACE(1014, "未录入人脸信息!"),
27
+    NOT_PUSH_FACE(1015, "人脸推送失敗!")
26 28
     ;
27 29
 
28 30
 

+ 69
- 0
CODE/foreign-service/src/main/java/com/community/huiju/model/TaFace.java 查看文件

@@ -0,0 +1,69 @@
1
+package com.community.huiju.model;
2
+
3
+import com.baomidou.mybatisplus.annotation.IdType;
4
+import com.baomidou.mybatisplus.annotation.TableId;
5
+import com.baomidou.mybatisplus.annotation.TableName;
6
+import lombok.Data;
7
+import lombok.EqualsAndHashCode;
8
+import lombok.experimental.Accessors;
9
+
10
+import java.io.Serializable;
11
+import java.time.LocalDateTime;
12
+import java.util.Date;
13
+
14
+/**
15
+ * <p>
16
+ * 人脸检测图片
17
+ * </p>
18
+ *
19
+ * @author jobob
20
+ * @since 2019-05-16
21
+ */
22
+@Data
23
+@EqualsAndHashCode(callSuper = false)
24
+@Accessors(chain = true)
25
+@TableName("ta_face")
26
+public class TaFace implements Serializable {
27
+
28
+    private static final long serialVersionUID = 1L;
29
+
30
+    @TableId(value = "id", type = IdType.AUTO)
31
+    private Integer faceId;
32
+
33
+    /**
34
+     * 小区id
35
+     */
36
+    private Integer communityId;
37
+
38
+    /**
39
+     * 用户审核表id
40
+     */
41
+    private Integer taUserVerifyId;
42
+
43
+    /**
44
+     * 上传的图片
45
+     */
46
+    private String faceImg;
47
+
48
+    /**
49
+     * 创建人
50
+     */
51
+    private Integer createUser;
52
+
53
+    /**
54
+     * 创建时间
55
+     */
56
+    private Date createDate;
57
+
58
+    /**
59
+     * 更新人
60
+     */
61
+    private Integer updateUser;
62
+
63
+    /**
64
+     * 更新时间
65
+     */
66
+    private Date updateDate;
67
+
68
+
69
+}

+ 45
- 0
CODE/foreign-service/src/main/java/com/community/huiju/service/FaceServiceI.java 查看文件

@@ -0,0 +1,45 @@
1
+package com.community.huiju.service;
2
+
3
+
4
+import com.baomidou.mybatisplus.extension.service.IService;
5
+import com.community.commom.session.UserElement;
6
+import com.community.huiju.common.base.ResponseBean;
7
+import com.community.huiju.model.TaFace;
8
+import com.community.huiju.model.TaUser;
9
+import org.springframework.web.multipart.MultipartFile;
10
+
11
+public interface FaceServiceI extends IService<TaFace> {
12
+    /**
13
+     * 添加人脸
14
+     * @param userId 用户Id
15
+     *  @param  uploadFile
16
+     *  @param userVerifyId 审核id
17
+     * @return
18
+     */
19
+    ResponseBean addFace(Integer userId, Integer userVerifyId, MultipartFile uploadFile);
20
+
21
+    /**
22
+     * 更新当前人脸
23
+     *  @param userId 用户Id
24
+     *  @param  uploadFile
25
+     *  @param userVerifyId 审核id
26
+     * @return
27
+     */
28
+    ResponseBean updateFace(Integer userId, Integer userVerifyId, MultipartFile uploadFile);
29
+
30
+    /**
31
+     * 当前登入人是否有人脸信息
32
+     * @param userElement
33
+     * @param otherUserId
34
+     * @return
35
+     */
36
+    ResponseBean getTaFaceByUserId(UserElement userElement, Integer otherUserId);
37
+
38
+    /**
39
+     * 删除人脸
40
+     * @param userElement
41
+     * @param otherUserId
42
+     * @return
43
+     */
44
+    ResponseBean deleteFace(UserElement userElement, Integer otherUserId, Integer verifyId);
45
+}

+ 32
- 0
CODE/foreign-service/src/main/java/com/community/huiju/service/IHKService.java 查看文件

@@ -0,0 +1,32 @@
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, Integer userVerifyId);
17
+
18
+    /**
19
+     * 下发门禁权限
20
+     * @return
21
+     */
22
+    ResponseBean downloadAuthorityByDeviceUuids();
23
+
24
+    /**
25
+     * 异步反控开门 (远程开门)
26
+     *
27
+     * @param userVerifyId 审核ID
28
+     * @return
29
+     */
30
+    ResponseBean syncControl(Integer userVerifyId);
31
+
32
+}

+ 15
- 0
CODE/foreign-service/src/main/java/com/community/huiju/service/ImageServiceI.java 查看文件

@@ -0,0 +1,15 @@
1
+package com.community.huiju.service;
2
+
3
+import org.springframework.web.multipart.MultipartFile;
4
+
5
+import java.io.IOException;
6
+
7
+/**
8
+ * @author admin
9
+ * @Title: ImageServiceI
10
+ * @Description: TODO
11
+ * @date 2018/11/5
12
+ */
13
+public interface ImageServiceI {
14
+    String getImageUrl(MultipartFile uploadFile) throws IOException;
15
+}

+ 441
- 0
CODE/foreign-service/src/main/java/com/community/huiju/service/impl/FaceServicelimpl.java 查看文件

@@ -0,0 +1,441 @@
1
+package com.community.huiju.service.impl;
2
+
3
+import com.alibaba.fastjson.JSONObject;
4
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
5
+import com.community.commom.ailiyun.AESDecode;
6
+import com.community.commom.constant.Constant;
7
+import com.community.commom.hk.HKOpenApi;
8
+import com.community.commom.session.UserElement;
9
+import com.community.huiju.common.base.ResponseBean;
10
+import com.community.huiju.dao.*;
11
+import com.community.huiju.enums.ResponseErrorsMessages;
12
+import com.community.huiju.exception.WisdomException;
13
+import com.community.huiju.model.*;
14
+import com.community.huiju.service.FaceServiceI;
15
+import com.community.huiju.service.IHKService;
16
+import com.community.huiju.service.ImageServiceI;
17
+import com.google.common.collect.Maps;
18
+import lombok.extern.slf4j.Slf4j;
19
+import org.springframework.beans.factory.annotation.Autowired;
20
+import org.springframework.http.HttpEntity;
21
+import org.springframework.http.HttpHeaders;
22
+import org.springframework.http.HttpMethod;
23
+import org.springframework.http.MediaType;
24
+import org.springframework.stereotype.Service;
25
+import org.springframework.transaction.annotation.Transactional;
26
+import org.springframework.web.client.RestTemplate;
27
+import org.springframework.web.multipart.MultipartFile;
28
+
29
+import java.io.IOException;
30
+import java.util.ArrayList;
31
+import java.util.Date;
32
+import java.util.List;
33
+import java.util.Map;
34
+import java.util.stream.Collectors;
35
+
36
+@Service("faceServicel")
37
+@Transactional
38
+@Slf4j
39
+public class FaceServicelimpl  extends ServiceImpl<TaFaceMapper, TaFace> implements FaceServiceI {
40
+
41
+
42
+    @Autowired
43
+    private TaFaceMapper taFaceMapper;
44
+
45
+    @Autowired
46
+    private TaUserMapper taUserMapper;
47
+
48
+    @Autowired
49
+    private TaSysRoleMapper taSysRoleMapper;
50
+
51
+    @Autowired
52
+    private ImageServiceI imageServiceI;
53
+
54
+    @Autowired
55
+    private TaUserVerifyMapper taUserVerifyMapper;
56
+
57
+    @Autowired
58
+    private IHKService ihkService;
59
+
60
+    @Autowired
61
+    private TpEquipmentMapper tpEquipmentMapper;
62
+
63
+    @Autowired
64
+    private TpConfigurationMapper tpConfigurationMapper;
65
+
66
+    @Autowired
67
+    private TpEquipmentTreeMapper tpEquipmentTreeMapper;
68
+
69
+    @Override
70
+    @Transactional(rollbackFor = Exception.class)
71
+    public ResponseBean addFace(Integer userId, Integer userVerifyId, MultipartFile uploadFile) {
72
+        ResponseBean responseBean = new ResponseBean();
73
+        // 判断房产是否存在关联关系
74
+        TaUserVerify userVerify = taUserVerifyMapper.selectByUserIdAndUserVerifyId(userId, userVerifyId);
75
+        if (null == userVerify) {
76
+            responseBean.addError(ResponseErrorsMessages.NOT_USER_VERIFY.getCode(), ResponseErrorsMessages.NOT_USER_VERIFY.getMsg());
77
+            return responseBean;
78
+        }
79
+
80
+        TpEquipmentTree tpEquipmentTree = tpEquipmentTreeMapper.selectByCommunityId(userVerify.getCommunityId());
81
+
82
+        // 当前人脸图片url
83
+        String faceImg = img(uploadFile);
84
+
85
+        /**
86
+         * 删除的时候,将所有的海康设备的关联关系删除了,需要重新下发一次
87
+         */
88
+        // 下发门禁
89
+        ihkService.pushPerson(userId + "", userVerifyId);
90
+
91
+        TaUser user = taUserMapper.selectById(userId);
92
+        TaFace taFace = new TaFace();
93
+        taFace.setFaceImg(faceImg);
94
+        taFace.setCommunityId(user.getCommunityId());
95
+        taFace.setTaUserVerifyId(userVerifyId);
96
+        taFace.setCreateUser(userId);
97
+        taFace.setUpdateUser(userId);
98
+        taFace.setCreateDate(new Date());
99
+        taFace.setUpdateDate(new Date());
100
+
101
+        /*验证身份*/
102
+        responseBean = addVerify(userId, userVerifyId, uploadFile, faceImg, taFace, tpEquipmentTree);
103
+        return responseBean;
104
+    }
105
+
106
+    /**
107
+     * 修改人脸信息
108
+     *
109
+     * @param userElement 登入人ID
110
+     * @param uploadFile
111
+     * @param otherUserId 关联家属或者租客ID
112
+     * @return
113
+     */
114
+    @Override
115
+    @Transactional(rollbackFor = Exception.class)
116
+    public ResponseBean updateFace(Integer userId, Integer userVerifyId, MultipartFile uploadFile) {
117
+        ResponseBean responseBean = new ResponseBean();
118
+        // 判断房产是否存在关联关系
119
+        TaUserVerify userVerify = taUserVerifyMapper.selectByUserIdAndUserVerifyId(userId, userVerifyId);
120
+        if (null == userVerify) {
121
+            responseBean.addError(ResponseErrorsMessages.NOT_USER_VERIFY.getCode(), ResponseErrorsMessages.NOT_USER_VERIFY.getMsg());
122
+            return responseBean;
123
+        }
124
+
125
+        TpEquipmentTree tpEquipmentTree = tpEquipmentTreeMapper.selectByCommunityId(userVerify.getCommunityId());
126
+        // 人脸图片地址url
127
+        String faceImg = img(uploadFile);
128
+
129
+        /**
130
+         * 删除的时候,将所有的海康设备的关联关系删除了,需要重新下发一次
131
+         */
132
+        // 下发门禁
133
+        ihkService.pushPerson(userId + "", userVerifyId);
134
+
135
+        //当前修改的id否存在
136
+        TaFace face = taFaceMapper.getByUserVerifyId(userVerifyId);
137
+        if (null == face) {
138
+            responseBean.addError(ResponseErrorsMessages.NOT_USER_FACE.getCode(), ResponseErrorsMessages.NOT_USER_FACE.getMsg());
139
+            return responseBean;
140
+        }
141
+
142
+        face.setTaUserVerifyId(userVerifyId);
143
+        face.setFaceImg(faceImg);
144
+        face.setUpdateUser(userId);
145
+        face.setUpdateDate(new Date());
146
+        ResponseBean resps = checKout(faceImg, face, false, uploadFile, userId, userVerify.getCommunityId(), userVerify.getRoomNoId(), userVerify.getUnitId(), tpEquipmentTree.getAppkey(), tpEquipmentTree.getSecret(), tpEquipmentTree.getHttpServer());
147
+        if (resps.getCode().equals("0")) {
148
+            resps.addSuccess((Object) faceImg);
149
+        } else {
150
+            resps.addError(resps.getMessage());
151
+        }
152
+        return resps;
153
+    }
154
+
155
+    /**
156
+     * 验证图片是否为人脸,推送海康
157
+     * @param faceImg
158
+     * @param taFace
159
+     * @param isA
160
+     * @param uploadFile
161
+     * @param userId
162
+     * @param communityId
163
+     * @param roomNoId
164
+     * @param unitId
165
+     * @param appkey
166
+     * @param secret
167
+     * @param openapi_ip_port_http 海康服务器地址
168
+     * @return
169
+     */
170
+    public ResponseBean checKout(String faceImg, TaFace taFace, boolean isA, MultipartFile uploadFile, Integer userId, Integer communityId, Integer roomNoId, Integer unitId, String  appkey, String secret, String openapi_ip_port_http) {
171
+        ResponseBean responseBean = new ResponseBean();
172
+        TaUser user = taUserMapper.selectById(userId);
173
+        if (user.getHkUserId() == null) {
174
+            log.error("本地库人员ID:{}  的海康人员ID不存在", userId);
175
+            throw new WisdomException(ResponseErrorsMessages.NOT_PUSH_FACE.getCode(), ResponseErrorsMessages.NOT_PUSH_FACE.getMsg());
176
+            return responseBean;
177
+        }
178
+        AESDecode aesd = new AESDecode();
179
+        String body = "{\"type\": \"0\", \"image_url\":\"" + faceImg + "\"}";
180
+        try {
181
+            com.community.commom.mode.ResponseBean send = aesd.send(body);
182
+            JSONObject jsonObject = JSONObject.parseObject(send.getMessage());
183
+            Integer type = (Integer) jsonObject.get("errno");
184
+            Integer faceNum = (Integer) jsonObject.get("face_num");
185
+
186
+            /*推送海康*/
187
+            String data = HKOpenApi.HKpersonGroupId(uploadFile, user.getHkUserId(), user.getHkPersonNo(), user.getUserName(), user.getHkCardNo(), appkey, secret, openapi_ip_port_http);
188
+            /*boolean isA为true进行添加,为false进行修改*/
189
+            if (0 == type && 1 == faceNum) {
190
+                if (null == data) {
191
+                    log.error("未得到,海康数据反馈!");
192
+                    throw new WisdomException(ResponseErrorsMessages.NOT_PUSH_FACE.getCode(), ResponseErrorsMessages.NOT_PUSH_FACE.getMsg());
193
+                }
194
+                if (isA) {
195
+                    taFaceMapper.insert(taFace);
196
+                } else {
197
+                    taFaceMapper.updateById(taFace);
198
+                }
199
+                responseBean.addSuccess("操作成功");
200
+
201
+                // 设备树
202
+                TpEquipmentTree tpEquipmentTree = tpEquipmentTreeMapper.selectByCommunityId(communityId);
203
+                // 所有设备
204
+                List<TpEquipment> tpEquipments = tpEquipmentMapper.selectByCommunityIdAndUnitId(communityId, unitId, 4);
205
+                List<Map<String, Object>> equipmentUUID = getEquipmentUUID(tpEquipments);
206
+                StringBuilder doorUuids = new StringBuilder();
207
+                StringBuilder deviceUuids = new StringBuilder();
208
+                equipmentUUID.forEach(e-> {
209
+                    doorUuids.append(e.get("doorUuid"));
210
+                    doorUuids.append(",");
211
+                    deviceUuids.append(e.get("deviceUuid"));
212
+                    deviceUuids.append(",");
213
+                });
214
+                Map<String,Object> map = Maps.newHashMap();
215
+                map.put("appkey", tpEquipmentTree.getAppkey());
216
+                map.put("opUserUuid", tpEquipmentTree.getOpUserUuid());
217
+                map.put("personIds", String.valueOf(user.getHkUserId()));
218
+                map.put("deviceUuids", deviceUuids.substring(0, deviceUuids.lastIndexOf(",")));
219
+                map.put("type", 1);
220
+                map.put("openapi_ip_port_http", tpEquipmentTree.getHttpServer());
221
+                HKOpenApi.downloadFaceAndFingerInfos(map);
222
+
223
+                //可视对讲时 指定人员人脸权限下载
224
+                List<Integer> userIdList = new ArrayList<>();
225
+                userIdList.add(user.getHkUserId());
226
+                //临时设备编号
227
+                // TODO 根据期楼栋号,来查询出门口机
228
+
229
+                // 单元门口机
230
+                List<TpEquipment> visualEquipments = tpEquipmentMapper.selectByCommunityIdAndUnitId(communityId, unitId, 3);
231
+                List<String> visualList = visualEquipments.stream()
232
+                        .map(e-> tpConfigurationMapper.selectById(e.getUuidId()).getConfigurationValue())
233
+                        .collect(Collectors.toList());
234
+//                List<String> visualList = new ArrayList<>();
235
+//                visualList.add("10010100000");
236
+                HKOpenApi.visualIntercom(tpEquipmentTree.getOpUserUuid(), 1, userIdList, visualList, tpEquipmentTree.getAppkey(), tpEquipmentTree.getSecret(), tpEquipmentTree.getHttpServer());
237
+            } else {
238
+                responseBean.addError("请录入正确图片");
239
+            }
240
+        } catch (Exception e) {
241
+            e.printStackTrace();
242
+            log.error("海康人脸推送失敗! {}", e);
243
+            throw new RuntimeException("海康人脸推送失敗!");
244
+        }
245
+        return responseBean;
246
+    }
247
+
248
+    /**
249
+     * 获取设备UUID
250
+     * @param equipmentList
251
+     * @return
252
+     */
253
+    private List<Map<String,Object>> getEquipmentUUID(List<TpEquipment> equipmentList) {
254
+        return equipmentList.stream().map(equipment -> {
255
+            TpConfiguration tpConfiguration = tpConfigurationMapper.selectById(equipment.getUuidId());
256
+            Map<String,Object> map = Maps.newHashMap();
257
+            map.put("doorUuid", tpConfiguration.getDoorUuid());
258
+            map.put("deviceUuid", tpConfiguration.getDeviceUuid());
259
+            return map;
260
+        }).collect(Collectors.toList());
261
+    }
262
+
263
+    /**
264
+     * 当前登入人是否有人脸信息
265
+     */
266
+    @Override
267
+    public ResponseBean getTaFaceByUserId(UserElement userElement, Integer otherUserId) {
268
+        ResponseBean responseBean = new ResponseBean();
269
+        Integer userVerifyId = userElement.getUserVerifyId();
270
+
271
+        /**当otherUserId不为空时判断它是否是业主下的租客或者家属*/
272
+        if (null != otherUserId) {
273
+            TaUserVerify userVerify = getTaFaceParentId(userElement, otherUserId);
274
+            userVerifyId = userVerify.getUserVerifyId();
275
+        }
276
+        TaFace face = taFaceMapper.getByUserVerifyId(userVerifyId);
277
+        if (null != face) {
278
+            responseBean.addSuccess(face);
279
+            return responseBean;
280
+        }
281
+        responseBean.addError("当前用户暂无人脸图片");
282
+        return responseBean;
283
+
284
+    }
285
+
286
+    /**
287
+     * 判断当前用户下的人员关系(家属,租客)
288
+     */
289
+    public TaUserVerify getTaFaceParentId(UserElement userElement, Integer otherUserId) {
290
+        // 根据 家属/租客 的id, 和 当前的房产信息进行查询是否有值,有值就说明是 家属/租客
291
+        List<TaUserVerify> todUserVerify = taUserVerifyMapper.selectCommunityAndAddressAndVerifyStatus(otherUserId, userElement.getCommunityId(), userElement.getPhaseId(), userElement.getBuildingId(), userElement.getUnitId(), userElement.getLevelId(), userElement.getRoomNoId(), 1);
292
+        // 判断 家属或者租客 属不属于这个业主的下面
293
+        if (null == todUserVerify || todUserVerify.size() == 0) {
294
+            throw new WisdomException("您输入的家属或租户ID有误或审核未通过!");
295
+        }
296
+//        if (!Constant.VERIFY_STATUS.equals(todUserVerify.get(0).getVerifyStatus())) {
297
+//            throw new WisdomException("用户房产审核未通过!");
298
+//        }
299
+
300
+        return todUserVerify.get(0);
301
+    }
302
+
303
+    /**
304
+     * 得到当前图片
305
+     */
306
+    private String img(MultipartFile uploadFile) {
307
+        String faceImg = null;
308
+        try {
309
+            faceImg = imageServiceI.getImageUrl(uploadFile);
310
+        } catch (IOException e) {
311
+            e.printStackTrace();
312
+        }
313
+        return faceImg;
314
+    }
315
+
316
+    /**
317
+     * 各种身份校验
318
+     */
319
+    public ResponseBean addVerify(Integer userid, Integer userVerifyId, MultipartFile uploadFile, String faceImg, TaFace taFace, TpEquipmentTree tpEquipmentTree) {
320
+        ResponseBean response = new ResponseBean();
321
+
322
+        TaUserVerify userVerify = taUserVerifyMapper.selectById(userVerifyId);
323
+        if (null == userVerify) {
324
+            response.addError("当前房产审核记录不存在!");
325
+            return response;
326
+        }
327
+        TaUser taUser = taUserMapper.selectById(userid);
328
+
329
+        //身份为家属租客,状态为已停用
330
+        if (null != taUser && !Constant.EFFECTIVE_STATUS.equals(taUser.getStatus())) {
331
+            response.addError("9996", "您的身份已停用,请联系物业");
332
+            return response;
333
+        }
334
+
335
+        //查询当前用户是否有人脸记录
336
+        TaFace face = taFaceMapper.getByUserVerifyId(userVerifyId);
337
+        if (null == face) {
338
+            boolean isA = true;
339
+            if (Constant.EFFECTIVE_STATUS.equals(taUser.getStatus())) {
340
+                ResponseBean responseBean = checKout(faceImg, taFace, isA, uploadFile, userid, userVerify.getCommunityId(), userVerify.getRoomNoId(), userVerify.getUnitId(),tpEquipmentTree.getAppkey(), tpEquipmentTree.getSecret(), tpEquipmentTree.getHttpServer());
341
+                if (responseBean.getCode().equals("0")) {
342
+                    responseBean.addSuccess("图片录入成功");
343
+                } else {
344
+                    responseBean.addError(responseBean.getMessage());
345
+                }
346
+                return responseBean;
347
+            }
348
+        }
349
+        response.addError("您的信息已存在");
350
+        return response;
351
+    }
352
+
353
+    @Override
354
+    public ResponseBean deleteFace(UserElement userElement, Integer otherUserId, Integer verifyId) {
355
+        ResponseBean responseBean= new ResponseBean();
356
+        TaUserVerify taUserVerify= infoExist(userElement.getUserVerifyId());
357
+        if (null ==taUserVerify) {
358
+            responseBean.addError("房产审核未通过");
359
+            return responseBean;
360
+        }
361
+            TaUser taUser = taUserMapper.selectById(taUserVerify.getUserId());
362
+
363
+        // 设备树
364
+        TpEquipmentTree tpEquipmentTree = tpEquipmentTreeMapper.selectByCommunityId(taUserVerify.getCommunityId());
365
+        // 所有设备
366
+        List<TpEquipment> tpEquipments = tpEquipmentMapper.selectByCommunityIdAndUnitId(taUserVerify.getCommunityId(), taUserVerify.getUnitId(), 4);
367
+        List<Map<String, Object>> equipmentUUID = getEquipmentUUID(tpEquipments);
368
+        StringBuilder doorUuids = new StringBuilder();
369
+        StringBuilder deviceUuids = new StringBuilder();
370
+        equipmentUUID.forEach(e-> {
371
+            doorUuids.append(e.get("doorUuid"));
372
+            doorUuids.append(",");
373
+            deviceUuids.append(e.get("deviceUuid"));
374
+            deviceUuids.append(",");
375
+        });
376
+
377
+
378
+        // TODO 删除人脸,是否删除海康
379
+        // 修改人脸(图片为null时。海康删除人脸)
380
+//        HKOpenApi.HKpersonGroupId(null, taUser.getHkUserId(), taUser.getHkPersonNo(), taUser.getUserName(), taUser.getHkCardNo(), tpEquipmentTree.getAppkey(), tpEquipmentTree.getSecret());
381
+        // 删除 权限
382
+        Map<String,Object> selectUserFaceMap = Maps.newHashMap();
383
+        selectUserFaceMap.put("personIds", taUser.getHkUserId()+"");
384
+        selectUserFaceMap.put("opUserUuid", tpEquipmentTree.getOpUserUuid());
385
+        selectUserFaceMap.put("appkey", tpEquipmentTree.getAppkey());
386
+        selectUserFaceMap.put("secret", tpEquipmentTree.getSecret());
387
+        selectUserFaceMap.put("openapi_ip_port_http", tpEquipmentTree.getHttpServer());
388
+        // 查询人脸信息
389
+        HKOpenApi.selectUserFace(selectUserFaceMap);
390
+
391
+        Map<String,Object> deleteUserMap = Maps.newHashMap();
392
+        deleteUserMap.put("personIds", taUser.getHkUserId()+"");
393
+        deleteUserMap.put("opUserUuid", tpEquipmentTree.getOpUserUuid());
394
+        deleteUserMap.put("doorUuids", doorUuids.substring(0, doorUuids.lastIndexOf(",")));
395
+        deleteUserMap.put("appkey", tpEquipmentTree.getAppkey());
396
+        deleteUserMap.put("secret", tpEquipmentTree.getSecret());
397
+        deleteUserMap.put("openapi_ip_port_http", tpEquipmentTree.getHttpServer());
398
+        // 删除当前人脸设备信息
399
+        String data= HKOpenApi.deleteUser(deleteUserMap);
400
+        JSONObject object= JSONObject.parseObject(data);
401
+
402
+        if (object.get("errorCode").equals(1)){
403
+            String errorMessage=  object.getString("errorMessage");
404
+            responseBean.addError(errorMessage);
405
+            return responseBean;
406
+        }
407
+        Integer activeUser = otherUserId == null ? userElement.getUserVerifyId() : otherUserId;
408
+        taFaceMapper.deleteFace(activeUser);
409
+        // 异动同步到设备
410
+        Map<String,Object> appointJurisdictionMap = Maps.newHashMap();
411
+        appointJurisdictionMap.put("appkey", tpEquipmentTree.getAppkey());
412
+        appointJurisdictionMap.put("secret", tpEquipmentTree.getSecret());
413
+        appointJurisdictionMap.put("opUserUuid", tpEquipmentTree.getOpUserUuid());
414
+        appointJurisdictionMap.put("personIds", taUser.getHkUserId()+"" );
415
+        appointJurisdictionMap.put("doorUuids", doorUuids.substring(0, doorUuids.lastIndexOf(",")));
416
+        appointJurisdictionMap.put("operateType",3);
417
+        appointJurisdictionMap.put("includeFinger",0);
418
+        appointJurisdictionMap.put("openapi_ip_port_http", tpEquipmentTree.getHttpServer());
419
+
420
+         HKOpenApi.appointJurisdiction(appointJurisdictionMap);
421
+        // HKOpenApi.selectUserSynchronization();
422
+        // ihkService.downloadAuthorityByDeviceUuids();
423
+        return responseBean;
424
+
425
+    }
426
+
427
+    /*校验房产是否审核通过*/
428
+    public TaUserVerify infoExist(Integer verifyID){
429
+        /*查询当前的房产ID*/
430
+        TaUserVerify taUserVerify = null;
431
+      if (!"".equals(verifyID)) {
432
+        taUserVerify = taUserVerifyMapper.selectById(verifyID);
433
+      }
434
+      if (null!= taUserVerify && taUserVerify.getVerifyStatus().equals("1")) {
435
+          return taUserVerify;
436
+      }
437
+      return  null;
438
+    }
439
+}
440
+
441
+

+ 365
- 0
CODE/foreign-service/src/main/java/com/community/huiju/service/impl/HKServiceImpl.java 查看文件

@@ -0,0 +1,365 @@
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.*;
10
+import com.community.huiju.exception.WisdomException;
11
+import com.community.huiju.model.*;
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.apache.commons.collections.CollectionUtils;
17
+import org.springframework.beans.factory.annotation.Autowired;
18
+import org.springframework.stereotype.Service;
19
+import org.springframework.transaction.annotation.Transactional;
20
+
21
+import java.text.ParseException;
22
+import java.text.SimpleDateFormat;
23
+import java.time.LocalDate;
24
+import java.util.Arrays;
25
+import java.util.HashMap;
26
+import java.util.List;
27
+import java.util.Map;
28
+import java.util.stream.Collectors;
29
+
30
+/**
31
+ * 海康 业务实现
32
+ * @author weiximei
33
+ */
34
+@Service
35
+@Slf4j
36
+public class HKServiceImpl implements IHKService {
37
+
38
+    @Autowired
39
+    private TaUserMapper taUserMapper;
40
+
41
+    private IdGen idGen = IdGen.get();
42
+
43
+    @Autowired
44
+    private TpEquipmentMapper tpEquipmentMapper;
45
+
46
+    @Autowired
47
+    private TpConfigurationMapper tpConfigurationMapper;
48
+
49
+    @Autowired
50
+    private TpEquipmentTreeMapper tpEquipmentTreeMapper;
51
+
52
+    @Autowired
53
+    private TaUserVerifyMapper taUserVerifyMapper;
54
+
55
+    /**
56
+     * 获取设备UUID
57
+     * @param equipmentList
58
+     * @return
59
+     */
60
+    private List<Map<String,Object>> getEquipmentUUID(List<TpEquipment> equipmentList) {
61
+        return equipmentList.stream().map(equipment -> {
62
+            TpConfiguration tpConfiguration = tpConfigurationMapper.selectById(equipment.getUuidId());
63
+            Map<String,Object> map = Maps.newHashMap();
64
+            map.put("doorUuid", tpConfiguration.getDoorUuid());
65
+            map.put("deviceUuid", tpConfiguration.getDeviceUuid());
66
+            return map;
67
+        }).collect(Collectors.toList());
68
+    }
69
+
70
+    @Override
71
+    @Transactional(rollbackFor = Exception.class)
72
+    public ResponseBean pushPerson(String appUserId, Integer userVerifyId) {
73
+        ResponseBean responseBean = new ResponseBean();
74
+        TaUser user = taUserMapper.selectById(Integer.parseInt(appUserId));
75
+
76
+        TaUserVerify userVerify = taUserVerifyMapper.selectById(userVerifyId);
77
+        if (null == userVerify) {
78
+            throw new WisdomException("审核数据不存在!");
79
+        }
80
+        TpEquipmentTree tpEquipmentTree = tpEquipmentTreeMapper.selectByCommunityId(userVerify.getCommunityId());
81
+
82
+        // 这两个值一般都是同时存在的
83
+        // 当这两个值不存在的时候,就添加海康人员
84
+        if (null == user.getHkUserId() && null == user.getHkPersonNo()) {
85
+            // 设置 海康id
86
+            user.setHkPersonNo(idGen.nextId());
87
+            /**
88
+             * 1.获取部门(比如 住户)
89
+             * 2.根据部门编号推送 海康
90
+             */
91
+            taUserMapper.updateById(user);
92
+            addUserAndOpenCard(responseBean, user, tpEquipmentTree);
93
+        }
94
+
95
+
96
+        // 推送海康
97
+
98
+        // 给用户添加 海康门禁权限
99
+
100
+        List<TpEquipment> tpEquipments = tpEquipmentMapper.selectByCommunityIdAndUnitId(userVerify.getCommunityId(), userVerify.getUnitId(), 4);
101
+        List<Map<String, Object>> equipmentUUID = getEquipmentUUID(tpEquipments);
102
+        StringBuilder doorUuids = new StringBuilder();
103
+        StringBuilder deviceUuids = new StringBuilder();
104
+        equipmentUUID.forEach(e-> {
105
+            doorUuids.append(e.get("doorUuid"));
106
+            doorUuids.append(",");
107
+            deviceUuids.append(e.get("deviceUuid"));
108
+            deviceUuids.append(",");
109
+        });
110
+
111
+        Map<String, Object> map = Maps.newHashMap();
112
+        map.put("personIds",String.valueOf(user.getHkUserId()));
113
+        map.put("doorUuids", doorUuids.substring(0, doorUuids.lastIndexOf(",")));
114
+        map.put("secret", tpEquipmentTree.getSecret());
115
+        map.put("appkey", tpEquipmentTree.getAppkey());
116
+        map.put("openapi_ip_port_http", tpEquipmentTree.getHttpServer());
117
+        HKOpenApi.addAuthoritiesByPersonIds(map);
118
+
119
+        // 下发门禁权限
120
+        Map<String, Object> downloadAuthorityByPersonIdsMap = Maps.newHashMap();
121
+        downloadAuthorityByPersonIdsMap.put("personIds",String.valueOf(user.getHkUserId()));
122
+        downloadAuthorityByPersonIdsMap.put("doorUuids", doorUuids.substring(0, doorUuids.lastIndexOf(",")));
123
+        downloadAuthorityByPersonIdsMap.put("operateType",1);
124
+        downloadAuthorityByPersonIdsMap.put("includeFinger",1);
125
+        downloadAuthorityByPersonIdsMap.put("secret", tpEquipmentTree.getSecret());
126
+        downloadAuthorityByPersonIdsMap.put("appkey", tpEquipmentTree.getAppkey());
127
+        downloadAuthorityByPersonIdsMap.put("openapi_ip_port_http", tpEquipmentTree.getHttpServer());
128
+        HKOpenApi.downloadAuthorityByPersonIds(downloadAuthorityByPersonIdsMap);
129
+
130
+        //--------- 可视对讲 ----------
131
+
132
+        Map<String,Object> addOutDoorAuthMap = Maps.newHashMap();
133
+        addOutDoorAuthMap.put("authName", "荟居");
134
+        addOutDoorAuthMap.put("personIds", Arrays.asList(user.getHkUserId()));
135
+        addOutDoorAuthMap.put("secret", tpEquipmentTree.getSecret());
136
+        addOutDoorAuthMap.put("appkey", tpEquipmentTree.getAppkey());
137
+
138
+        // 单元门口机
139
+        List<TpEquipment> visualEquipments = tpEquipmentMapper.selectByCommunityIdAndUnitId(userVerify.getCommunityId(), userVerify.getUnitId(), 3);
140
+        List<String> visualList = visualEquipments.stream()
141
+                .map(e-> tpConfigurationMapper.selectById(e.getUuidId()).getConfigurationValue())
142
+                .collect(Collectors.toList());
143
+//        List<String> visualList = new ArrayList<>();
144
+//        visualList.add("10010100000");
145
+        addOutDoorAuthMap.put("longNums", visualList);
146
+        // 可视对讲下发 权限
147
+        visualIntercomPermissions(addOutDoorAuthMap);
148
+        if ("0".equals(responseBean.getCode())) {
149
+            responseBean.addSuccess("操作成功!");
150
+            return responseBean;
151
+        }
152
+        throw new WisdomException("操作失败!");
153
+    }
154
+
155
+    @Override
156
+    @Deprecated
157
+    public ResponseBean downloadAuthorityByDeviceUuids() {
158
+        ResponseBean responseBean = new ResponseBean();
159
+        // 下发门禁权限
160
+        HKOpenApi.downloadAuthorityByDeviceUuids(Maps.newHashMap());
161
+        responseBean.addSuccess("操作成功!");
162
+        return responseBean;
163
+    }
164
+
165
+    /**
166
+     * 公共方法
167
+     * 添加人员, 开卡
168
+     *
169
+     * @param response
170
+     * @param user
171
+     */
172
+    private void addUserAndOpenCard(ResponseBean response, TaUser user, TpEquipmentTree tpEquipmentTree) {
173
+        Map<String, Object> parDept = Maps.newHashMap();
174
+        parDept.put("pageNo", 1);
175
+        parDept.put("pageSize", 100);
176
+        parDept.put("deptName", Constant.DEPT_RESIDENTS);
177
+        parDept.put("openapi_ip_port_http", tpEquipmentTree.getHttpServer());
178
+        // 部门UUID
179
+        String deptUuid = getDeptUUID(parDept);
180
+
181
+        // 添加人员
182
+        Map<String, Object> parUser = Maps.newHashMap();
183
+        parUser.put("personNo", user.getHkPersonNo());
184
+        parUser.put("personName", user.getUserName());
185
+        parUser.put("phoneNo", user.getLoginName());
186
+        parUser.put("deptUuid", deptUuid);
187
+        parUser.put("secret", tpEquipmentTree.getSecret());
188
+        parUser.put("appkey", tpEquipmentTree.getAppkey());
189
+        parUser.put("openapi_ip_port_http", tpEquipmentTree.getHttpServer());
190
+        Map<String, Object> resultMap = JSONObject.parseObject(HKOpenApi.addUser(parUser), HashMap.class);
191
+        int errorCode = (int) resultMap.get("errorCode");
192
+        if (errorCode == 0) {
193
+            Map<String, Object> resultDataMap = (Map<String, Object>) resultMap.get("data");
194
+            // 开卡 卡号
195
+            long cardNo = System.currentTimeMillis();
196
+            // 海康人员ID
197
+            Integer personId = (Integer) resultDataMap.get("personId");
198
+            TaUser tempUser = taUserMapper.selectById(user.getUserId());
199
+            tempUser.setHkUserId(personId);
200
+            tempUser.setHkCardNo(cardNo + "");
201
+
202
+            user.setHkUserId(personId);
203
+            // 存储海康人员ID
204
+            int row = taUserMapper.updateById(tempUser);
205
+            if (row > 0) {
206
+                response.addSuccess("操作成功!");
207
+            } else {
208
+                response.addError("操作失败");
209
+                throw new RuntimeException("数据库添加 家属/租客 人员失败!");
210
+            }
211
+
212
+            // 开卡
213
+            List<String> cardAndPersonList = Lists.newArrayList();
214
+            cardAndPersonList.add(cardNo + "," + personId);
215
+            response = openCard(cardAndPersonList, null, tpEquipmentTree);
216
+        } else {
217
+            String errorMessage = String.valueOf(resultMap.get("errorMessage"));
218
+            response.addError(errorMessage);
219
+            log.error("海康添加人员失败! {}", errorMessage);
220
+            throw new RuntimeException(errorMessage);
221
+        }
222
+    }
223
+
224
+    /**
225
+     * 批量开卡
226
+     *
227
+     * @param cardIdAndHKUserID list.add("卡号,人员ID")
228
+     * @param expirationTime    有效期为多少? 单位为 年
229
+     * @return
230
+     */
231
+    private ResponseBean openCard(List<String> cardIdAndHKUserID, Integer expirationTime, TpEquipmentTree tpEquipmentTree) {
232
+        ResponseBean response = new ResponseBean();
233
+
234
+        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
235
+        LocalDate today = LocalDate.now();
236
+        int year = today.getYear();
237
+        // 加上20, 表示加上20年,默认
238
+        if (null == expirationTime || expirationTime <= 0) {
239
+            year += 20;
240
+        } else {
241
+            year += expirationTime;
242
+        }
243
+        int month = today.getMonthValue();
244
+        int day = today.getDayOfMonth();
245
+
246
+        Long time = null;
247
+        try {
248
+            time = formatter.parse(year + "-" + month + "-" + day).getTime();
249
+        } catch (ParseException e) {
250
+            e.printStackTrace();
251
+        }
252
+
253
+        // 开卡
254
+        Map<String, Object> parOpenCard = Maps.newHashMap();
255
+        parOpenCard.put("cardAndPerson", cardIdAndHKUserID);
256
+        parOpenCard.put("startTime", System.currentTimeMillis());
257
+        parOpenCard.put("endTime", time);
258
+        parOpenCard.put("secret", tpEquipmentTree.getSecret());
259
+        parOpenCard.put("appkey", tpEquipmentTree.getAppkey());
260
+        parOpenCard.put("openapi_ip_port_http", tpEquipmentTree.getHttpServer());
261
+        JSONObject openCardJSON = JSONObject.parseObject(HKOpenApi.openCard(parOpenCard));
262
+        int code = (int) openCardJSON.get("errorCode");
263
+        if (code == 0) {
264
+            response.addSuccess("操作成功!");
265
+        } else {
266
+            String errorMessage = String.valueOf(openCardJSON.get("errorMessage"));
267
+            response.addError(errorMessage);
268
+            log.error("开卡失败! {}", errorMessage);
269
+            throw new RuntimeException(errorMessage);
270
+        }
271
+
272
+        return response;
273
+    }
274
+
275
+    /**
276
+     * 获取部门 uuid
277
+     * <p>
278
+     * 这里的部门相当于 小区
279
+     *
280
+     * @return
281
+     */
282
+    private String getDeptUUID(Map<String, Object> parDept) {
283
+        Map<String, Object> deptMap = JSONObject.parseObject(HKOpenApi.getDeptName(parDept), HashMap.class);
284
+        Map<String, Object> deptDataMap = (Map<String, Object>) deptMap.get("data");
285
+        JSONArray jsonArray = (JSONArray) deptDataMap.get("list");
286
+        Map<String, Object> deptListData = (Map<String, Object>) jsonArray.get(0);
287
+        // 部门UUID
288
+        String deptUuid = (String) deptListData.get("deptUuid");
289
+        return deptUuid;
290
+    }
291
+
292
+    /**
293
+     * 可视对讲下发 权限
294
+     *
295
+     * @param map
296
+     */
297
+    private void visualIntercomPermissions(Map<String,Object> map) {
298
+        // TODO 目前下发的 authName权限组是我们自定义的, 后面肯定是按照小区的 期楼栋号来设置的
299
+        // TODO longNums设备编号, 可视对讲的机器编号, 应该根据 期楼栋号 下面的机器编号来设置的
300
+
301
+        //--------- 可视对讲 ----------
302
+
303
+        // 可视对讲 根据人员 ID 集添加权限并下发
304
+        HKOpenApi.addOutDoorAuth(map);
305
+
306
+    }
307
+
308
+    /**
309
+     * 可视对讲 指定人员指纹权限下载
310
+     * @param map
311
+     */
312
+    private void visualIntercomFingerprint(Map<String,Object> map) {
313
+        // 可视对讲 指定人员指纹权限下载
314
+        Map<String, Object> downloadFingerMap = new HashMap<>();
315
+        // opType 操作类型 Integer 是 1 为下发权限;2 为删除权限
316
+        downloadFingerMap.put("opType", 1);
317
+        downloadFingerMap.put("personIds", map.get("personIds"));
318
+        downloadFingerMap.put("longNums", map.get("longNums"));
319
+        downloadFingerMap.put("openapi_ip_port_http", map.get("openapi_ip_port_http"));
320
+        // 可视对讲 指定人员指纹权限下载
321
+        HKOpenApi.downloadFinger(downloadFingerMap);
322
+    }
323
+
324
+    @Override
325
+    public ResponseBean syncControl(Integer userVerifyId) {
326
+        // TODO 暂时只支持开单元门
327
+
328
+        ResponseBean responseBean = new ResponseBean();
329
+
330
+        // 查询当前的房产
331
+        TaUserVerify userVerify = taUserVerifyMapper.selectById(userVerifyId);
332
+        TpEquipmentTree tpEquipmentTree = tpEquipmentTreeMapper.selectByCommunityId(userVerify.getCommunityId());
333
+        // 单元门口机
334
+        List<TpEquipment> tpEquipments = tpEquipmentMapper.selectByCommunityIdAndUnitId(userVerify.getCommunityId(), userVerify.getUnitId(), 3);
335
+
336
+         if (CollectionUtils.isEmpty(tpEquipments)) {
337
+             responseBean.addError("无设备信息!");
338
+             return responseBean;
339
+         }
340
+
341
+         String str = "";
342
+         for (TpEquipment e : tpEquipments) {
343
+             TpConfiguration tpConfiguration = tpConfigurationMapper.selectById(e.getUuidId());
344
+             str += tpConfiguration.getConfigurationValue();
345
+             str += ",";
346
+         }
347
+
348
+        // 查询设备编号
349
+
350
+        Map<String,Object> parMap = com.beust.jcommander.internal.Maps.newHashMap();
351
+        parMap.put("longNums", str);
352
+        parMap.put("openapi_ip_port_http", tpEquipmentTree.getHttpServer());
353
+        parMap.put("secret", tpEquipmentTree.getSecret());
354
+        parMap.put("appkey", tpEquipmentTree.getAppkey());
355
+        String data = HKOpenApi.syncControl(parMap);
356
+        JSONObject jsonObject = JSONObject.parseObject(data);
357
+        int errorCode = jsonObject.getInteger("errorCode");
358
+        if (errorCode == 0) {
359
+            responseBean.addSuccess("操作成功!");
360
+            return responseBean;
361
+        }
362
+        responseBean.addError("操作失败!");
363
+        return responseBean;
364
+    }
365
+}

+ 46
- 0
CODE/foreign-service/src/main/java/com/community/huiju/service/impl/ImageServiceimpl.java 查看文件

@@ -0,0 +1,46 @@
1
+package com.community.huiju.service.impl;
2
+
3
+import com.aliyun.oss.OSSClient;
4
+import com.community.huiju.service.ImageServiceI;
5
+import org.springframework.stereotype.Service;
6
+import org.springframework.web.multipart.MultipartFile;
7
+
8
+import java.io.ByteArrayInputStream;
9
+import java.io.IOException;
10
+import java.util.Date;
11
+
12
+/**
13
+ * @author weichaochao
14
+ * @Title: ImageServiceimpl
15
+ * @Description: 获取图片地址实现类
16
+ * @date 2018/11/5
17
+ */
18
+@Service("ImageService")
19
+public class ImageServiceimpl implements ImageServiceI {
20
+
21
+    private static String endpoint = "http://oss-cn-shanghai.aliyuncs.com";
22
+    private static String accessKeyId = "LTAIkc75dpkJw8Lb";
23
+    private static String accessKeySecret = "v4bvXCaix6vSDTCFfwSAdqV53iFEQw";
24
+    private static String bucketName = "jingcheng-h5temp";
25
+
26
+    @Override
27
+    public String getImageUrl(MultipartFile uploadFile) throws IOException {
28
+
29
+        String imgName = System.currentTimeMillis() + ".png";
30
+        // 创建OSSClient实例
31
+        OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
32
+        // 上传
33
+        long time = System.currentTimeMillis();
34
+
35
+        ossClient.putObject(bucketName, imgName, new ByteArrayInputStream(uploadFile.getBytes()));
36
+
37
+        // 关闭client
38
+        ossClient.shutdown();
39
+        Date expiration = new Date(time + 3600 * 1000 * 24 * 365 * 10);
40
+        String url = ossClient.generatePresignedUrl(bucketName, imgName, expiration).toString();
41
+
42
+        // 截取掉签名
43
+        url = url.substring(0, url.lastIndexOf("&Signature"));
44
+        return url;
45
+    }
46
+}

+ 1
- 0
CODE/foreign-service/src/main/resources/application.yml 查看文件

@@ -18,6 +18,7 @@ mybatis-plus:
18 18
   mapper-locations: classpath:mapper/*.xml
19 19
   configuration:
20 20
     call-setters-on-nulls: true
21
+    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl #打印sql语句,调试用
21 22
 
22 23
 # 打印sql
23 24
 logging:

+ 5
- 0
CODE/foreign-service/src/main/resources/mapper/TaFaceMapper.xml 查看文件

@@ -0,0 +1,5 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
+<mapper namespace="com.community.huiju.dao.TaFaceMapper">
4
+
5
+</mapper>

+ 5
- 0
CODE/foreign-service/src/main/resources/mapper/TaSysRoleMapper.xml 查看文件

@@ -0,0 +1,5 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
+<mapper namespace="com.community.huiju.dao.TaSysRoleMapper">
4
+
5
+</mapper>

+ 17
- 0
CODE/foreign-service/src/main/resources/mapper/TaUserVerifyMapper.xml 查看文件

@@ -2,4 +2,21 @@
2 2
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3 3
 <mapper namespace="com.community.huiju.dao.TaUserVerifyMapper">
4 4
 
5
+    <select id="selectCommunityAndAddressAndVerifyStatus" resultType="com.community.huiju.model.TaUserVerify">
6
+        select
7
+        <include refid="Base_Column_List"/>
8
+        from ta_user_verify
9
+        where community_id = #{communityId,jdbcType=INTEGER}
10
+        and user_id = #{userId,jdbcType=INTEGER}
11
+        and phase_id = #{phaseId,jdbcType=INTEGER}
12
+        and building_id = #{buildingId,jdbcType=INTEGER}
13
+        and unit_id = #{unitId,jdbcType=INTEGER}
14
+        and level_id = #{levelId,jdbcType=INTEGER}
15
+        and room_no_id = #{roomNoId,jdbcType=INTEGER}
16
+        <if test="verifyStatus != null and verifyStatus != ''">
17
+            and verify_status = #{verifyStatus}
18
+        </if>
19
+    </select>
20
+
21
+
5 22
 </mapper>

+ 5
- 0
CODE/foreign-service/src/main/resources/mapper/TpBuildingMapper.xml 查看文件

@@ -0,0 +1,5 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
+<mapper namespace="com.community.huiju.dao.TpBuildingMapper">
4
+
5
+</mapper>

+ 1
- 1
CODE/smart-community/app-api/src/main/resources/mapper/TpHotelMapper.xml 查看文件

@@ -192,7 +192,7 @@
192 192
   </select>
193 193
   
194 194
   <select id="hotelSetting" resultType="string">
195
-    select id from tp_hotel_setting where  community_id = #{communityId};
195
+    select id from tp_hotel_setting where  community_id = #{communityId}
196 196
   </select>
197 197
 
198 198
 </mapper>