ソースを参照

部门增加企业微信部门id

seyason 2 年 前
コミット
4f21d18f67

+ 405 - 9
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/WeiXinCorpController.java

@@ -32,6 +32,12 @@ import java.util.stream.Collectors;
 @RequestMapping("/wxcorp")
 @Slf4j
 public class WeiXinCorpController {
+    //中转的服务器获取部门详情
+    public static final String TRANSMIT_SERVER_GET_DEPTDETAIL = "http://47.101.180.183:10010/wxcorp/getCorpDeptDetail?accessToken=ACCESS_TOKEN&deptId=DEPTID";
+    public static final String TRANSMIT_SERVER_GET_DEPTMEMBDETAIL = "http://47.101.180.183:10010/wxcorp/getDeptUserDetail?accessToken=ACCESS_TOKEN&deptId=DEPTID";
+
+    public static final String POST_CONVERT_USERID = "https://qyapi.weixin.qq.com/cgi-bin/batch/userid_to_openuserid?access_token=ACCESS_TOKEN";
+
     public static final String GET_SUITE_ACCESS_TOKEN_URL = "https://qyapi.weixin.qq.com/cgi-bin/service/get_suite_token";
     public static final String GET_PREAUTH_CODE_URL = "https://qyapi.weixin.qq.com/cgi-bin/service/get_pre_auth_code?suite_access_token=SUITE_ACCESS_TOKEN";
     //获取企业永久授权码
@@ -43,6 +49,7 @@ public class WeiXinCorpController {
     //获取部门列表
     public static final String GET_ALL_DEPARTMENT_URL = "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=ACCESS_TOKEN";
     public static final String GET_DEPARTMENT_URL = "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=ACCESS_TOKEN&id=1";//获取某个部门下的子部门
+    public static final String GET_DEPARTMENT_DETAIL_URL = "https://qyapi.weixin.qq.com/cgi-bin/department/get?access_token=ACCESS_TOKEN&id=ID";//获取部门详情
     //获取部门成员详情
     public static final String GET_DEPARTMENT_USER_DETAIL_URL = "https://qyapi.weixin.qq.com/cgi-bin/user/list?access_token=ACCESS_TOKEN&department_id=DEPARTMENT_ID&fetch_child=0";
     public static final String GET_DEPARTMENT_USER_SIMPLE_URL = "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token=ACCESS_TOKEN&department_id=DEPARTMENT_ID&fetch_child=0";
@@ -387,7 +394,14 @@ public class WeiXinCorpController {
     @ResponseBody
     public HttpRespMsg getAuthPage() {
         HttpRespMsg msg = new HttpRespMsg();
-        String preAuthCode = getAuthCode();
+        String preAuthCode = null;
+        try {
+            preAuthCode = getAuthCode();
+        } catch (Exception exception) {
+            exception.printStackTrace();
+            msg.setError(exception.getMessage());
+            return msg;
+        }
 
         String url = "https://open.work.weixin.qq.com/3rdapp/install?suite_id=SUITE_ID&pre_auth_code=PRE_AUTH_CODE&redirect_uri=REDIRECT_URI&state=STATE";
         url = url.replace("SUITE_ID", suitId).replace("PRE_AUTH_CODE", preAuthCode)
@@ -409,7 +423,7 @@ public class WeiXinCorpController {
 
 
 
-    private void handleCorpAuth(String authCode) {
+    private void handleCorpAuth(String authCode) throws Exception {
         String suitAccessToken = getSuiteAccessToken();
         String url = GET_CORP_PERMANENT_CODE_URL.replace("SUITE_ACCESS_TOKEN", suitAccessToken);
         //失效了,需要重新获取
@@ -691,13 +705,49 @@ public class WeiXinCorpController {
     private JSONArray getDeptUserInfo(String accessToken, int deptId) {
         String url = GET_DEPARTMENT_USER_DETAIL_URL.replace("ACCESS_TOKEN", accessToken).replace("DEPARTMENT_ID", ""+deptId);
         String result = restTemplate.getForObject(url, String.class);
-        System.out.println("部门人员详情:"+result);
+        System.out.println("第三方应用获取部门人员详情:"+result);
+        JSONObject obj = JSONObject.parseObject(result);
+        JSONArray userlist = obj.getJSONArray("userlist");
+        return userlist;
+    }
+
+    private JSONArray getTransDeptUserInfo(String accessToken, int deptId) {
+        String url = GET_DEPARTMENT_USER_DETAIL_URL.replace("ACCESS_TOKEN", accessToken).replace("DEPARTMENT_ID", ""+deptId);
+        String result = restTemplate.getForObject(url, String.class);
+        System.out.println("中转服务获取部门人员详情:"+result);
         JSONObject obj = JSONObject.parseObject(result);
         JSONArray userlist = obj.getJSONArray("userlist");
 
         return userlist;
     }
 
+    //企业通讯录获取到的userid转化为open_userid
+    private JSONArray convertUserIdToOpenUserId(String accessToken, List<String> userIdList) throws Exception {
+        HttpHeaders headers = new HttpHeaders();
+        headers.setContentType(MediaType.APPLICATION_JSON);
+        JSONObject reqParam = new JSONObject();
+        reqParam.put("userid_list",  userIdList);
+
+        HttpEntity<String> requestEntity = new HttpEntity<String>(reqParam.toJSONString(), headers);
+        String url = POST_CONVERT_USERID.replaceAll("ACCESS_TOKEN", accessToken);
+        ResponseEntity<String> responseEntity = this.restTemplate.exchange(url,
+                HttpMethod.POST, requestEntity, String.class);
+        if (responseEntity.getStatusCode() == HttpStatus.OK) {
+            String resp = responseEntity.getBody();
+            System.out.println(resp);
+
+            JSONObject obj = JSONObject.parseObject(resp);
+            if (obj.getIntValue("errcode") == 0) {
+                JSONArray openUseridList = obj.getJSONArray("open_userid_list");
+                return openUseridList;
+            } else {
+                //抛出异常
+                throw new Exception(obj.getString("errmsg"));
+            }
+        }
+        return null;
+    }
+
     private JSONObject getDepartments(String accessToken) {
         String url = GET_DEPARTMENT_URL.replace("ACCESS_TOKEN", accessToken);
         String result = restTemplate.getForObject(url, String.class);
@@ -707,6 +757,17 @@ public class WeiXinCorpController {
         return obj;
     }
 
+    //获取部门详情
+    private JSONObject getDeptDetail(String accessToken, int deptId) {
+        String url = GET_DEPARTMENT_DETAIL_URL.replace("ACCESS_TOKEN", accessToken).replace("ID", ""+deptId);
+        String result = restTemplate.getForObject(url, String.class);
+        log.info("部门详情:"+result);
+        JSONObject obj = JSONObject.parseObject(result);
+        return obj;
+    }
+
+
+
     private JSONObject getAllDepartments(String accessToken) {
         String url = GET_ALL_DEPARTMENT_URL.replace("ACCESS_TOKEN", accessToken);
         String result = restTemplate.getForObject(url, String.class);
@@ -725,7 +786,7 @@ public class WeiXinCorpController {
 
 
     //获取预授权码
-    private String getAuthCode() {
+    private String getAuthCode() throws Exception {
         if (PRE_AUTH_CODE == null || expireTime < System.currentTimeMillis()) {
             //失效了,需要重新获取
             String resp = restTemplate.getForObject(GET_PREAUTH_CODE_URL.replaceAll("SUITE_ACCESS_TOKEN", getSuiteAccessToken()), String.class);
@@ -740,7 +801,7 @@ public class WeiXinCorpController {
     }
 
     //获取第三方应用临时凭证
-    private String getSuiteAccessToken() {
+    private String getSuiteAccessToken() throws Exception {
         if (SUITE_ACCESS_TOKEN == null || suiteTokenExpireTime < System.currentTimeMillis()) {
             //失效了,需要重新获取
             HttpHeaders headers = new HttpHeaders();
@@ -759,10 +820,14 @@ public class WeiXinCorpController {
             if (responseEntity.getStatusCode() == HttpStatus.OK) {
                 String resp = responseEntity.getBody();
                 log.info(resp);
+
                 JSONObject obj = JSONObject.parseObject(resp);
                 if (obj.getIntValue("errcode") == 0) {
                     SUITE_ACCESS_TOKEN = obj.getString("suite_access_token");
                     suiteTokenExpireTime = System.currentTimeMillis() + obj.getIntValue("expires_in")*1000;
+                } else {
+                    //抛出异常
+                    throw new Exception(obj.getString("errmsg"));
                 }
             }
         }
@@ -778,7 +843,14 @@ public class WeiXinCorpController {
             msg.setError("该用户不存在,请退出重新登录");
             return msg;
         }
-        String url = GET_CORP_USERINFO_URL.replace("SUITE_ACCESS_TOKEN", getSuiteAccessToken()).replace("CODE", code);
+        String url = null;
+        try {
+            url = GET_CORP_USERINFO_URL.replace("SUITE_ACCESS_TOKEN", getSuiteAccessToken()).replace("CODE", code);
+        } catch (Exception exception) {
+            exception.printStackTrace();
+            msg.setError(exception.getMessage());
+            return msg;
+        }
         String forObject = this.restTemplate.getForObject(url, String.class);
         JSONObject obj = JSONObject.parseObject(forObject);
         String wxUserId = obj.getString("UserId");
@@ -819,7 +891,14 @@ public class WeiXinCorpController {
     public HttpRespMsg corpWeiXinLogin(String code) {
         HttpRespMsg msg = new HttpRespMsg();
 
-        String url = GET_CORP_USERINFO_URL.replace("SUITE_ACCESS_TOKEN", getSuiteAccessToken()).replace("CODE", code);
+        String url = null;
+        try {
+            url = GET_CORP_USERINFO_URL.replace("SUITE_ACCESS_TOKEN", getSuiteAccessToken()).replace("CODE", code);
+        } catch (Exception exception) {
+            exception.printStackTrace();
+            msg.setError(exception.getMessage());
+            return msg;
+        }
         String forObject = this.restTemplate.getForObject(url, String.class);
         JSONObject obj = JSONObject.parseObject(forObject);
         String wxUserId = obj.getString("UserId");
@@ -1051,9 +1130,299 @@ public class WeiXinCorpController {
         return new HttpRespMsg();
     }
 
-    //新版本
+    //新版本, 由于是第三方服务商,需要先获取授权范围内的组织架构(没有部门和人员的名称),再从中转服务器去获取名称
     @RequestMapping("/getCorpMembs")
     public HttpRespMsg getCorpMembs(String corpId) {
+        System.out.println("============新版getCorpMembs=========");
+        WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectById(corpId);
+        HttpRespMsg msg = new HttpRespMsg();
+        if (wxCorpInfo.getContactSecret() == null) {
+            msg.setError("请先设置企业通讯录同步Secret");
+            return msg;
+        }
+        Company company = companyMapper.selectById(wxCorpInfo.getCompanyId());
+        String corpContactAccessToken = null;
+        try {
+            corpContactAccessToken = getCorpConcactAccessToken(wxCorpInfo);
+        } catch (Exception exception) {
+            exception.printStackTrace();
+            msg.setError("同步失败:"+exception.getMessage());
+            return msg;
+        }
+
+        String curCorpAccessToken = null;
+        try {
+            curCorpAccessToken = getCorpAccessToken(wxCorpInfo);
+        } catch (Exception exception) {
+            exception.printStackTrace();
+            msg.setError("同步失败:"+exception.getMessage());
+            return msg;
+        }
+        int companyId = company.getId();
+        //获取公司根部门人员,也就是没有分配部门的人员
+        int companyRootDeptId = 1;
+        JSONArray unAssignedUserList = getDeptUserInfo(curCorpAccessToken, companyRootDeptId);
+        //获取远程的带姓名的详情,通过企业通讯录的token获取
+        JSONArray remoteUnAUserList = null;
+        if (unAssignedUserList.size() > 0) {
+            remoteUnAUserList = remoteGetDeptUserDetail(corpContactAccessToken, companyRootDeptId);
+            //做id转化
+            List<String> userIds = new ArrayList<>();
+            for (int i=0;i<remoteUnAUserList.size(); i++) {
+                userIds.add(remoteUnAUserList.getJSONObject(i).getString("userid"));
+            }
+            try {
+                JSONArray array = convertUserIdToOpenUserId(curCorpAccessToken, userIds);
+                for (int i=0;i<array.size(); i++) {
+                    JSONObject jsonObject = array.getJSONObject(i);
+                    String userid = jsonObject.getString("userid");
+                    String openUserid = jsonObject.getString("open_userid");
+                    //替换userid
+                    for (int m=0;m<remoteUnAUserList.size(); m++) {
+                        JSONObject remoteUser = remoteUnAUserList.getJSONObject(m);
+                        if (remoteUser.getString("userid").equals(userid)) {
+                            remoteUser.put("userid", openUserid);
+                            break;
+                        }
+                    }
+                }
+            } catch (Exception exception) {
+                exception.printStackTrace();
+                msg.setError("同步失败:"+exception.getMessage());
+                return msg;
+            }
+        }
+
+        SysRole defaultRole = sysRoleMapper.selectOne(
+                new QueryWrapper<SysRole>().eq("company_id", companyId).eq("is_default", 1));
+        List<JSONObject> hasDirectLdMembs = new ArrayList<>();
+        for (int m=0;m<unAssignedUserList.size(); m++) {
+            JSONObject userJson = unAssignedUserList.getJSONObject(m);
+            String curUserid = userJson.getString("userid");
+            //跳过非激活状态的员工
+            if (userJson.getInteger("status") != 1) continue;
+            System.out.println("userid="+curUserid+", name=" + userJson.getString("name")+", department="+userJson.getJSONArray("department"));
+            if (userJson.getJSONArray("direct_leader").size() > 0) {
+                hasDirectLdMembs.add(userJson);
+            }
+            //不存在的人员, 进行插入
+            User user = new User();
+
+            user.setId(SnowFlake.nextId()+"")
+                    .setRoleId(defaultRole.getId())//默认普通员工
+                    .setRoleName(defaultRole.getRolename())
+                    .setCompanyId(companyId)
+                    .setName(userJson.getString("name"))
+                    .setPhone(userJson.getString("mobile"))
+                    .setCorpwxUserid(curUserid)
+                    .setColor(ColorUtil.randomColor());
+            //获取姓名
+            if (remoteUnAUserList != null) {
+                for (int i=0;i<remoteUnAUserList.size(); i++) {
+                    JSONObject remoteUserJson = remoteUnAUserList.getJSONObject(i);
+                    if (remoteUserJson.getString("userid").equals(curUserid)) {
+                        user.setName(remoteUserJson.getString("name"));
+                        break;
+                    }
+                }
+            }
+            //检查用户是否已经存在
+            User oldUser = userMapper.selectOne(new QueryWrapper<User>().select("id, name").eq("corpwx_userid", curUserid).eq("company_id", companyId));
+            if (oldUser == null) {
+                userMapper.insert(user);
+            } else if (!oldUser.getName().equals(user.getName())){
+                //姓名不一致,需要更新
+                System.out.println("===更新姓名==="+user.getName());
+                user.setId(oldUser.getId());
+                oldUser.setName(user.getName());
+                userMapper.updateById(oldUser);
+            }
+        }
+
+        //获取公司全部部门,不需要递归
+        JSONObject deptObj = getAllDepartments(curCorpAccessToken);
+        JSONArray deptObjJSONArray = deptObj.getJSONArray("department");
+
+        List<Department> sysDeptList = new ArrayList<>();
+        for (int i=0;i<deptObjJSONArray.size(); i++) {
+            int deptId = deptObjJSONArray.getJSONObject(i).getIntValue("id");
+            Department department = new Department();
+//            department.setDepartmentName(deptObjJSONArray.getJSONObject(i).getString("name"));
+            department.setCompanyId(companyId);
+            //设置企业微信的部门id
+            department.setCorpwxDeptid(deptObjJSONArray.getJSONObject(i).getInteger("id"));
+            System.out.println("开始远程获取部门详情=====");
+            String url = TRANSMIT_SERVER_GET_DEPTDETAIL.replace("ACCESS_TOKEN", corpContactAccessToken).replace("DEPTID", ""+deptId);
+            String result = restTemplate.getForObject(url, String.class);
+            System.out.println("部门返回数据:"+result);
+            JSONObject resultObj = JSONObject.parseObject(JSONObject.parseObject(result).getString("data"));
+            if (resultObj.getInteger("errcode") == 0) {
+                JSONObject serverDept = resultObj.getJSONObject("department");
+                String name = serverDept.getString("name");
+                department.setDepartmentName(name);
+            } else {
+                System.err.println("同步获取部门详情报错:"+resultObj.toString());
+            }
+
+            //检查是否已经有了
+            Department oldDept = departmentMapper.selectOne(new QueryWrapper<Department>().eq("company_id", companyId).eq("corpwx_deptid", department.getCorpwxDeptid()).last("limit 1"));
+            if (oldDept == null) {
+                if (deptId != 1) {
+                    //忽略根,根是公司名称
+                    //按名称比对
+                    oldDept = departmentMapper.selectOne(new QueryWrapper<Department>().eq("company_id", companyId).eq("department_name", department.getDepartmentName()).last("limit 1"));
+                    if (oldDept == null) {
+                        departmentMapper.insert(department);
+                    } else {
+                        //按照企业微信部门id进行更新
+                        oldDept.setCorpwxDeptid(department.getCorpwxDeptid());
+                        departmentMapper.updateById(oldDept);
+                    }
+                }
+            } else {
+                department = oldDept;
+            }
+
+            sysDeptList.add(department);
+            deptObjJSONArray.getJSONObject(i).put("sys_dept_id", department.getDepartmentId());
+            Integer departmentId = department.getDepartmentId();
+            JSONArray userList = getDeptUserInfo(curCorpAccessToken, deptId);
+            JSONArray remoteDeptUserList = null;
+            if (userList.size() > 0) {
+                remoteDeptUserList = remoteGetDeptUserDetail(corpContactAccessToken, deptId);
+                //做id转化
+                List<String> userIds = new ArrayList<>();
+                for (int p=0;p<remoteDeptUserList.size(); p++) {
+                    userIds.add(remoteDeptUserList.getJSONObject(p).getString("userid"));
+                }
+                try {
+                    JSONArray array = convertUserIdToOpenUserId(curCorpAccessToken, userIds);
+                    for (int w=0;w<array.size(); w++) {
+                        JSONObject jsonObject = array.getJSONObject(w);
+                        String userid = jsonObject.getString("userid");
+                        String openUserid = jsonObject.getString("open_userid");
+                        //替换userid
+                        for (int m=0;m<remoteDeptUserList.size(); m++) {
+                            JSONObject remoteUser = remoteDeptUserList.getJSONObject(m);
+                            if (remoteUser.getString("userid").equals(userid)) {
+                                remoteUser.put("userid", openUserid);
+                                break;
+                            }
+                        }
+                    }
+                } catch (Exception exception) {
+                    exception.printStackTrace();
+                    msg.setError("同步失败:"+exception.getMessage());
+                    return msg;
+                }
+            }
+
+            for (int m=0;m<userList.size(); m++) {
+                JSONObject userJson = userList.getJSONObject(m);
+                String curUserid = userJson.getString("userid");
+                if (userJson.getInteger("status") != 1) continue;
+                log.info("userid="+curUserid+", name=" + userJson.getString("name")+", mobile="+userJson.getString("mobile"));
+                if (userJson.getJSONArray("direct_leader").size() > 0) {
+                    hasDirectLdMembs.add(userJson);
+                }
+                //不存在的人员, 进行插入
+                User user = new User();
+
+                user.setId(SnowFlake.nextId()+"")
+                        .setRoleId(defaultRole.getId())
+                        .setRoleName(defaultRole.getRolename())
+                        .setCompanyId(companyId)
+                        .setDepartmentId(departmentId)
+                        .setPhone(userJson.getString("mobile"))
+                        .setName(userJson.getString("name"))
+                        .setCorpwxUserid(curUserid)
+                        .setColor(ColorUtil.randomColor());
+                //获取姓名
+                if (remoteDeptUserList != null) {
+                    for (int t=0;t<remoteDeptUserList.size(); t++) {
+                        JSONObject remoteUserJson = remoteDeptUserList.getJSONObject(t);
+                        if (remoteUserJson.getString("userid").equals(curUserid)) {
+                            //匹配到了。设置姓名
+                            System.out.println("远程的用户匹配到了:"+remoteUserJson.getString("name"));
+                            user.setName(remoteUserJson.getString("name"));
+                            break;
+                        }
+                    }
+                }
+                //检查用户是否已经存在
+                if (userMapper.selectCount(new QueryWrapper<User>().eq("corpwx_userid", curUserid).eq("company_id", companyId)) == 0) {
+                    userMapper.insert(user);
+                }
+            }
+        }
+
+        //再来更新部门的层级关系
+        List<Department> needUpdateDepts = new ArrayList<>();
+        for (int i=0;i<deptObjJSONArray.size(); i++) {
+            JSONObject deptJson = deptObjJSONArray.getJSONObject(i);
+            int pid = deptJson.getInteger("parentid");
+            if (pid != 1) {
+                //根部门Id = 1
+                Integer sysDeptId = deptJson.getInteger("sys_dept_id");
+                if (sysDeptId != null) {
+                    Department department = sysDeptList.stream().filter(d -> d.getDepartmentId() != null && d.getDepartmentId().equals(sysDeptId)).findFirst().get();
+                    //从deptjson数组中寻找parent item
+                    for (int m=0;m<deptObjJSONArray.size(); m++) {
+                        JSONObject item = deptObjJSONArray.getJSONObject(m);
+                        if (item.getInteger("id").equals(pid)) {
+                            department.setSuperiorId(item.getInteger("sys_dept_id"));
+                            break;
+                        }
+                    }
+                    needUpdateDepts.add(department);
+                }
+            }
+        }
+        if (needUpdateDepts.size() > 0) {
+            departmentService.updateBatchById(needUpdateDepts);
+        }
+        //更新人员的直属上级
+        if (hasDirectLdMembs.size() > 0) {
+            List<String> corpwxUids = new ArrayList<>();
+            for (JSONObject userJson : hasDirectLdMembs) {
+                String curUserid = userJson.getString("userid");
+                //取第一个leaderId
+                JSONArray directLeader = userJson.getJSONArray("direct_leader");
+                String string = directLeader.getString(0);
+                corpwxUids.add(curUserid);
+                if (!corpwxUids.contains(string)) {
+                    corpwxUids.add(string);
+                }
+            }
+            List<User> userList = userMapper.selectList(new QueryWrapper<User>().select("id, corpwx_userid, superior_id").in("corpwx_userid", corpwxUids));
+            List<User> updateUserList = new ArrayList<>();
+            for (JSONObject userJson : hasDirectLdMembs) {
+                String curUserid = userJson.getString("userid");
+                User user = userList.stream().filter(u -> u.getCorpwxUserid().equals(curUserid)).findFirst().get();
+                JSONArray directLeader = userJson.getJSONArray("direct_leader");
+                String leaderCorpWxuid = directLeader.getString(0);
+                //查找leader
+                User leader = userList.stream().filter(u -> u.getCorpwxUserid().equals(leaderCorpWxuid)).findFirst().get();
+                if (!leader.getId().equals(user.getSuperiorId())) {
+                    user.setSuperiorId(leader.getId());
+                    updateUserList.add(user);
+                }
+            }
+            if (updateUserList.size() > 0) {
+                //批量更新上级领导
+                userService.updateBatchById(updateUserList);
+            }
+        }
+
+
+        return new HttpRespMsg();
+    }
+
+
+
+    //直接通过企业的通讯录secret获取到组织架构,但是如果调用的服务器是第三方服务商会被腾讯识别并拦截
+    @RequestMapping("/getCorpMembsWithContactSEC")
+    public HttpRespMsg getCorpMembsWithContactSEC(String corpId) {
         WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectById(corpId);
         HttpRespMsg msg = new HttpRespMsg();
         if (wxCorpInfo.getContactSecret() == null) {
@@ -1167,7 +1536,8 @@ public class WeiXinCorpController {
                 User user = new User();
 
                 user.setId(SnowFlake.nextId()+"")
-                        .setRole(0)//默认普通员工
+                        .setRoleId(defaultRole.getId())
+                        .setRoleName(defaultRole.getRolename())
                         .setCompanyId(companyId)
                         .setDepartmentId(departmentId)
                         .setPhone(userJson.getString("mobile"))
@@ -1265,10 +1635,36 @@ public class WeiXinCorpController {
                 //批量更新上级领导
                 userService.updateBatchById(updateUserList);
             }
+
         }
         return new HttpRespMsg();
     }
 
+    private JSONArray remoteGetDeptUserDetail(String accessToken, int deptId) {
+        String url = TRANSMIT_SERVER_GET_DEPTMEMBDETAIL.replace("ACCESS_TOKEN", accessToken).replace("DEPTID", ""+deptId);
+        String result = restTemplate.getForObject(url, String.class);
+        System.out.println("远程部门人员详情:"+result);
+        JSONArray obj = JSONObject.parseArray(JSONObject.parseObject(result).getString("data"));
+        return obj;
+    }
+
+    //用于从中转服务器获取企业通讯录的部门详情数据
+    @RequestMapping("/getCorpDeptDetail")
+    public HttpRespMsg getCorpDeptDetail(String accessToken, int deptId) {
+        JSONObject deptDetail = getDeptDetail(accessToken, deptId);
+        HttpRespMsg msg = new HttpRespMsg();
+        msg.data = deptDetail.toString();
+        return msg;
+    }
+
+    //用于从中转服务器获取企业通讯录的部门人员详情
+    @RequestMapping("/getDeptUserDetail")
+    public HttpRespMsg getDeptUserDetail(String accessToken, int deptId) {
+        JSONArray userList = getTransDeptUserInfo(accessToken, deptId);
+        HttpRespMsg msg = new HttpRespMsg();
+        msg.data = userList.toString();
+        return msg;
+    }
 
     private boolean judgeIsLeader(String userId) {
         int cnt = projectAuditorMapper.selectCount(new QueryWrapper<ProjectAuditor>().eq("auditor_id", userId));

+ 8 - 1
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/entity/Department.java

@@ -16,7 +16,7 @@ import lombok.experimental.Accessors;
  * </p>
  *
  * @author Seyason
- * @since 2022-01-05
+ * @since 2022-07-05
  */
 @Data
 @EqualsAndHashCode(callSuper = false)
@@ -62,6 +62,13 @@ public class Department extends Model<Department> {
     private String reportAuditUserid;
 
 
+    /**
+     * 企业微信的部门id
+     */
+    @TableField("corpwx_deptid")
+    private Integer corpwxDeptid;
+
+
     @Override
     protected Serializable pkVal() {
         return this.departmentId;

+ 105 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/resources/application-dev2.yml

@@ -0,0 +1,105 @@
+server:
+  port: 10010
+  tomcat:
+    uri-encoding: utf-8
+    max-http-form-post-size: -1
+    connection-timeout: 18000000s
+spring:
+  servlet:
+    multipart:
+      # 配置上传文件的大小设置
+      # Single file max size  即单个文件大小
+      max-file-size: 100MB
+      max-request-size: 100MB
+  datasource:
+    driver-class-name: com.mysql.cj.jdbc.Driver
+    url: jdbc:mysql://127.0.0.1:3306/man_hour_manager?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&rewriteBatchedStatements=true&&useSSL=false
+    username: root
+    password: HuoshiDB@2022
+    hikari:
+      maximum-pool-size: 10
+      minimum-idle: 3
+      max-lifetime: 30000
+      connection-test-query: SELECT 1
+    #######redis配置######
+    # redis
+    redis:
+      host: 127.0.0.1
+      port: 6479
+      timeout: 3
+      # password:
+      pool:
+        minIdle: 1
+        maxIdle: 10
+        maxWait: 3
+        maxActive: 8
+    ####全局配置时间返回格式#####
+  jackson:
+    #参数意义:
+    #JsonInclude.Include.ALWAYS       默认
+    #JsonInclude.Include.NON_DEFAULT   属性为默认值不序列化
+    #JsonInclude.Include.NON_EMPTY     属性为 空(””) 或者为 NULL 都不序列化
+    #JsonInclude.Include.NON_NULL      属性为NULL  不序列化
+    default-property-inclusion: ALWAYS
+    time-zone: GMT+8
+    date-format: yyyy-MM-dd HH:mm:ss
+
+##########日志配置
+logging:
+  level:
+    root: info
+    org.mybatis: error
+    java.sql: error
+    org.springframework.web: error
+    #打印sql语句
+    com.management.platform.mapper: error
+  path: /log/
+  file: worktime.log
+##########
+mybatis-plus:
+  #  mapper-locations: classpath:mapper/*/*.xml
+  #  #实体扫描,多个package用逗号或者分号分隔
+  #  typeAliasesPackage: com.hssx.cloudmodel
+  global-config:
+    #主键类型  0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID";
+    id-type: 0
+    #字段策略 0:"忽略判断",1:"非 NULL 判断"),2:"非空判断"
+    field-strategy: 2
+    db-column-underline: true
+    refresh-mapper:
+    #################插入和更新非null判断
+    db-config:
+      insert-strategy: not_null
+      update-strategy: not_null
+  configuration:
+    map-underscore-to-camel-case: true
+    cache-enabled: false
+######mybstis配置#######
+mybatis:
+  type-aliases-package: com.management.platform.entity
+  mapper-locations: mappers/*Mapper.xml
+#####配置图片上传路径####
+upload:
+  path: /www/staticproject/timesheet/upload/
+
+
+
+
+
+##actuator健康检查配置
+management:
+  security:
+    enabled:false:
+  server:
+    port: 10011
+  #  endpoints:
+  #    web:
+  #      exposure:
+  #        include: "*"
+
+  health:
+    redis:
+      enabled: false
+
+configEnv:
+  isDev: true

+ 2 - 2
fhKeeper/formulahousekeeper/management-platform/src/main/resources/mapper/DepartmentMapper.xml

@@ -10,14 +10,14 @@
         <result column="company_id" property="companyId" />
         <result column="manager_id" property="managerId" />
         <result column="report_audit_userid" property="reportAuditUserid" />
+        <result column="corpwx_deptid" property="corpwxDeptid" />
     </resultMap>
 
     <!-- 通用查询结果列 -->
     <sql id="Base_Column_List">
-        department_id, department_name, superior_id, company_id, manager_id, report_audit_userid
+        department_id, department_name, superior_id, company_id, manager_id, report_audit_userid, corpwx_deptid
     </sql>
 
-
     <!--根据部门获取成本-->
     <select id="getCostByDepartment" resultType="java.util.Map">
         SELECT SUM(b.working_time) AS time, SUM(b.cost) AS money