Procházet zdrojové kódy

判断是否是企业微信管理员

seyason před 2 roky
rodič
revize
dd576d9ea2

+ 2 - 2
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/WxCorpInfoService.java

@@ -30,8 +30,8 @@ public interface WxCorpInfoService extends IService<WxCorpInfo> {
 
     public String testDownloadFile();
 
-    //获取企业管理员列表
-    List<User> getAdminList(Integer companyId)throws Exception;
+    //获取企业管理员OpenUserId列表
+    List<String> getAdminOpenIdList(Integer companyId)throws Exception;
 
     public HttpRespMsg getUserCheckInDayData(int companyId, String userId, LocalDateTime startDateTime, LocalDateTime endDateTime, boolean showLog);
 

+ 5 - 6
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/UserServiceImpl.java

@@ -443,13 +443,12 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
     public HttpRespMsg isManager(HttpServletRequest request) throws Exception {
         HttpRespMsg msg=new HttpRespMsg();
         User user= userMapper.selectById(request.getHeader("token"));
-        List<User> adminList = wxCorpInfoService.getAdminList(user.getCompanyId());
-        /*boolean match = adminList.stream().anyMatch(al -> user.getCorpwxUserid() != null && al.getCorpwxUserid() != null && al.getCorpwxUserid().equals(user.getCorpwxUserid()));*/
-        if(adminList!=null){
-            boolean match = adminList.stream().anyMatch(al -> al.getId().equals(user.getId()));
-            msg.data=match;
+        if (user.getCorpwxUserid() != null) {
+            List<String> adminList = wxCorpInfoService.getAdminOpenIdList(user.getCompanyId());
+            msg.data = adminList.contains(user.getCorpwxUserid());
+        } else {
+            msg.data = false;
         }
-        msg.data=false;
         return msg;
     }
 

+ 6 - 6
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/WxCorpInfoServiceImpl.java

@@ -475,8 +475,8 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
 
     //获取企业管理员列表
     @Override
-    public List<User> getAdminList(Integer companyId)throws Exception{
-        List<User> userList=new ArrayList<>();
+    public List<String> getAdminOpenIdList(Integer companyId)throws Exception{
+        List<String> userOpenIdList=new ArrayList<>();
         WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", companyId));
         String url=GET_ADMIN_LIST.replaceAll("SUITE_ACCESS_TOKEN",getSuiteAccessToken());
         HttpHeaders headers = new HttpHeaders();
@@ -490,19 +490,19 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
         if (responseEntity.getStatusCode() == HttpStatus.OK) {
             String resp = responseEntity.getBody();
             JSONObject json = JSONObject.parseObject(resp);
+            System.out.println(json);
             if (json.getIntValue("errcode") == 0) {
                 JSONArray adminList = json.getJSONArray("admin");
                 for (int i = 0; i < adminList.size(); i++) {
                     JSONObject object = adminList.getJSONObject(i);
-                    String userid = String.valueOf(object.get("userid"));
-                    User user = userMapper.selectOne(new QueryWrapper<User>().eq("corpwx_userid", userid));
-                    userList.add(user);
+                    String openUserid = String.valueOf(object.get("open_userid"));
+                    userOpenIdList.add(openUserid);
                 }
             } else {
                 throw new Exception(json.toJSONString());
             }
         }
-        return userList;
+        return userOpenIdList;
     }
 
     //获取企业AccessToken