Kaynağa Gözat

Merge branch 'master' of http://192.168.1.43:3000/v2/zd-parents

linfutong 3 yıl önce
ebeveyn
işleme
5fd1772304

+ 24 - 38
zd-modules/zd-algorithm/src/main/java/com/zd/alg/smartlock/utils/SmartlockUtil.java

@@ -48,7 +48,7 @@ public class SmartlockUtil {
     /**
      * 智能锁返回成功字符描述
      */
-    public final static String resultMsg = "ok";
+    public final String RESULT_MSG = "ok";
 
     /**
      * //授权时长(小时)
@@ -86,7 +86,7 @@ public class SmartlockUtil {
             logger.info(response.body());
             String resultMsg = JSON.parseObject(response.body()).get("resultMsg").toString();
             //请求是否成功
-            if (SmartlockUtil.resultMsg.equals(resultMsg)) {
+            if (RESULT_MSG.equals(resultMsg)) {
                 token = JSON.parseObject(JSON.parseObject(response.body()).get("result").toString()).get("token").toString();
             } else {
                 logger.info("智能锁获取token失败:" + resultMsg);
@@ -109,7 +109,7 @@ public class SmartlockUtil {
             HttpResponse response = request.execute();
             // System.out.println(response.body());
             String resultMsg = JSON.parseObject(response.body().toString()).get("resultMsg").toString();
-            if (SmartlockUtil.resultMsg.equals(resultMsg)) {
+            if (RESULT_MSG.equals(resultMsg)) {
                 List<SlBuild> list = JSON.parseArray(JSON.parseObject(response.body().toString()).get("result").toString(), SlBuild.class);
                 slBuild = list.get(0);
             }
@@ -138,7 +138,7 @@ public class SmartlockUtil {
             String str = responseLc.body();
             //查询失败直接返回
             String resultMsg = JSON.parseObject(str).get("resultMsg").toString();
-            if (!SmartlockUtil.resultMsg.equals(resultMsg)) {
+            if (!RESULT_MSG.equals(resultMsg)) {
                 logger.error("获取楼层建筑id失败:" + resultMsg);
                 return listRoom;
             }
@@ -179,7 +179,7 @@ public class SmartlockUtil {
             HttpResponse response = request.execute();
             //查询失败直接返回
             String resultMsg = JSON.parseObject(response.body().toString()).get("resultMsg").toString();
-            if (!SmartlockUtil.resultMsg.equals(resultMsg)) {
+            if (!RESULT_MSG.equals(resultMsg)) {
                 logger.error("查询用户集合失败1:" + resultMsg);
                 return list;
             }
@@ -212,7 +212,7 @@ public class SmartlockUtil {
             HttpResponse response = request.execute();
             //查询失败直接返回
             String resultMsg = JSON.parseObject(response.body()).get("resultMsg").toString();
-            if (!SmartlockUtil.resultMsg.equals(resultMsg)) {
+            if (!RESULT_MSG.equals(resultMsg)) {
                 logger.error("获取房间详情失败1:" + resultMsg);
                 return lockOnline;
             }
@@ -242,7 +242,7 @@ public class SmartlockUtil {
             String token = getToken();
 
             if (StringUtils.isEmpty(openDoorSearch.getRoomid())) {
-                logger.error("查询开门记录集合失败,roomid为空" + resultMsg);
+                logger.error("查询开门记录集合失败,roomid为空");
                 return list;
             }
             if (StringUtils.isEmpty(openDoorSearch.getRecordtype())) {
@@ -261,7 +261,7 @@ public class SmartlockUtil {
             // System.out.println(response.body());
             //查询失败直接返回
             String resultMsg = JSON.parseObject(response.body()).get("resultMsg").toString();
-            if (!SmartlockUtil.resultMsg.equals(resultMsg)) {
+            if (!RESULT_MSG.equals(resultMsg)) {
                 logger.error("查询开门记录集合失败1:" + resultMsg);
                 return list;
             }
@@ -289,7 +289,7 @@ public class SmartlockUtil {
             HttpResponse response = request.execute();
             //查询失败直接返回
             String resultMsg = JSON.parseObject(response.body()).get("resultMsg").toString();
-            if (!SmartlockUtil.resultMsg.equals(resultMsg)) {
+            if (!RESULT_MSG.equals(resultMsg)) {
                 logger.error("查询开门记录集合失败1:" + resultMsg);
                 return list;
             }
@@ -313,6 +313,7 @@ public class SmartlockUtil {
             //获取组织id
             String pgid = listgroup.get(0).getPgid();
             String token = getToken();
+            String resultMsg;
 
             /*roomId="109";
             user.setPersoncode("C016");//学号、工号
@@ -330,11 +331,10 @@ public class SmartlockUtil {
                         "&personmobile=" + user.getPersonmobile() + "&persontype=" + user.getPersontype() + "&pgid=" + pgid + "&token=" + token;
                 HttpRequest request = SmartlockUtil.httpSendPost(url, "");
                 HttpResponse response = request.execute();
-                // System.out.println(response.body());
+
                 //查询失败直接返回
-                String resultMsg = JSON.parseObject(response.body().toString()).get("resultMsg").toString();
-                // System.out.println(resultMsg);
-                if (!SmartlockUtil.resultMsg.equals(resultMsg)) {
+                resultMsg = JSON.parseObject(response.body().toString()).get("resultMsg").toString();
+                if (!RESULT_MSG.equals(resultMsg)) {
                     logger.error("人员添加失败1:" + resultMsg);
                     map.put("resultMsg", resultMsg);
                     return map;
@@ -342,15 +342,18 @@ public class SmartlockUtil {
 
                 //添加授权
                 map = addUserAuths(token, user.getPersoncode(), roomId);
+                resultMsg = map.get("resultMsg").toString();
             } else {
                 //查询用户是否存在授权
                 String authis = checkUserAuthExis(user.getPersoncode(), token);
                 if (StringUtils.isNotEmpty(authis)) {
                     //修改授权
                     map = updateAuths(token, roomId, Integer.valueOf(authis));
+                    resultMsg= map.get("resultMsg").toString();
                 } else {
                     //添加授权
                     map = addUserAuths(token, user.getPersoncode(), roomId);
+                    resultMsg= map.get("resultMsg").toString();
                 }
             }
             //操作结果
@@ -387,14 +390,12 @@ public class SmartlockUtil {
             HttpResponse response2 = request2.execute();
             String resultMsg = JSON.parseObject(response2.body()).get("resultMsg").toString();
             logger.info("用户申请修改:"+response2.body());
-            // System.out.println(response2.body());
-            logger.info("用户密码:"+pw);
-            // System.out.println(pw);
+
             map.put("password", pw);
+            logger.info("用户密码:"+pw);
             map.put("resultMsg", resultMsg);
         } catch (Exception e) {
             logger.error("修改用户授权失败" + e);
-            // System.out.println("修改用户授权失败:" + resultMsg);
         }
         return map;
     }
@@ -434,7 +435,8 @@ public class SmartlockUtil {
             HttpResponse response2 = request2.execute();
             //System.out.println(response2.body());
             //查询失败直接返回
-            if (!SmartlockUtil.resultMsg.equals(resultMsg)) {
+            String resultMsg = JSON.parseObject(response2.body().toString()).get("resultMsg").toString();
+            if (!RESULT_MSG.equals(resultMsg)) {
                 logger.error("人员添加后办理入住失败1:" + resultMsg);
                 map.put("resultMsg", resultMsg);
                 return map;
@@ -480,7 +482,7 @@ public class SmartlockUtil {
             //查询失败直接返回
             String resultMsg = JSON.parseObject(response.body().toString()).get("resultMsg").toString();
             //System.out.println(resultMsg);
-            if (!SmartlockUtil.resultMsg.equals(resultMsg)) {
+            if (!RESULT_MSG.equals(resultMsg)) {
                 logger.error("人员添加失败1:" + resultMsg);
                 map.put("resultMsg", resultMsg);
             }
@@ -503,13 +505,13 @@ public class SmartlockUtil {
         postlist.add(postUser);
 
         //将对象转为json
-        //JSONObject jsonStr = JSON.parseObject(JSONObject.toJSONString( postlist ));
         String url2 = SERVICE_URL + "/lockauth/operate/9/batchauths?token=" + token;
         HttpRequest request2 = SmartlockUtil.httpSendPost(url2, JSONObject.toJSONString(postlist));
         HttpResponse response2 = request2.execute();
-        //System.out.println(response2.body());
+        String resultMsg = JSON.parseObject(response2.body().toString()).get("resultMsg").toString();
+
         //查询失败直接返回
-        if (!SmartlockUtil.resultMsg.equals(resultMsg)) {
+        if (!RESULT_MSG.equals(resultMsg)) {
             logger.error("人员添加后办理入住失败1:" + resultMsg);
             map.put("resultMsg", resultMsg);
         }
@@ -638,22 +640,6 @@ public class SmartlockUtil {
 
         //System.out.println(getRandom(6));
 
-        String token = null;
-        String url = "http://192.168.1.66/login/1/gettoken?userlogin=admin&password=admin123";
-        JSONObject json = new JSONObject();
-
-            HttpRequest request = HttpRequest.post(url)
-                    .header("Content-Type", "application/json")
-                    .body(json.toString());
-            HttpResponse response = request.execute();
-            logger.info(response.body());
-            String resultMsg = JSON.parseObject(response.body()).get("resultMsg").toString();
-            //请求是否成功
-            if (SmartlockUtil.resultMsg.equals(resultMsg)) {
-                token = JSON.parseObject(JSON.parseObject(response.body()).get("result").toString()).get("token").toString();
-            } else {
-                logger.info("智能锁获取token失败:" + resultMsg);
-            }
 
     }
 }