|
@@ -4,6 +4,7 @@ package com.management.platform.controller;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.google.gson.JsonObject;
|
|
import com.google.gson.JsonObject;
|
|
import com.management.platform.constant.Constant;
|
|
import com.management.platform.constant.Constant;
|
|
@@ -809,5 +810,151 @@ public class FeishuInfoController {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @RequestMapping("/getFeishuMembsFromPlatform")
|
|
|
|
+ public HttpRespMsg getFeishuMembsFromPlatform(HttpServletRequest request){
|
|
|
|
+ HttpRespMsg msg=new HttpRespMsg();
|
|
|
|
+ Integer companyId = userMapper.selectById(request.getHeader("token")).getCompanyId();
|
|
|
|
+ FeishuInfo feishuInfo = feishuInfoMapper.selectOne(new LambdaQueryWrapper<FeishuInfo>().eq(FeishuInfo::getCompanyId, companyId));
|
|
|
|
+ String corpId = feishuInfo.getCorpid();
|
|
|
|
+ if(feishuInfo==null){
|
|
|
|
+ msg.setData("飞书配置暂未完成,请联系服务商");
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+ //获取应用可用范围内的部门
|
|
|
|
+ Map<String, Object> availableRange = feishuInfoService.getAvailableRange(feishuInfo, null);
|
|
|
|
+ JSONArray deptArray = (JSONArray) availableRange.get("department_ids");
|
|
|
|
+ JSONArray departmentInfoArrays=new JSONArray();
|
|
|
|
+ for (int i = 0; i < deptArray.size(); i++) {
|
|
|
|
+ String dpId = deptArray.getString(i);
|
|
|
|
+ JSONArray departmentInfo = feishuInfoService.getDepartmentInfo(feishuInfo, dpId);
|
|
|
|
+ if(departmentInfo!=null&&departmentInfo.size()>0){
|
|
|
|
+ departmentInfoArrays.addAll(departmentInfo);
|
|
|
|
+ }
|
|
|
|
+ JSONArray subDepartmentList =getSubDepartmentList(feishuInfo,dpId);
|
|
|
|
+ if(subDepartmentList!=null&&subDepartmentList.size()>0){
|
|
|
|
+ departmentInfoArrays.addAll(subDepartmentList);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ for (int j = 0; j < departmentInfoArrays.size(); j++) {
|
|
|
|
+ JSONObject ob = departmentInfoArrays.getJSONObject(j);
|
|
|
|
+ String departmentName = String.valueOf(ob.get("name"));
|
|
|
|
+ System.out.println("synchronizationDP========="+departmentName);
|
|
|
|
+ String departmentId = String.valueOf(ob.getString("department_id"));
|
|
|
|
+ String openDepartmentId = String.valueOf(ob.getString("open_department_id"));
|
|
|
|
+ String departmentParentId =String.valueOf(ob.getString("parent_department_id"));
|
|
|
|
+ Integer cut = departmentFeishuMapper.selectCount(new QueryWrapper<DepartmentFeishu>().eq("corpid",corpId).eq("feishu_deptid",departmentId));
|
|
|
|
+ if(cut==0&&!departmentId.equals("0")){
|
|
|
|
+ System.out.println("join===========");
|
|
|
|
+ DepartmentFeishu departmentFeishu=new DepartmentFeishu();
|
|
|
|
+ departmentFeishu.setCorpid(corpId)
|
|
|
|
+ .setName(departmentName)
|
|
|
|
+ .setFeishuParentid(departmentParentId)
|
|
|
|
+ .setFeishuDeptid(departmentId)
|
|
|
|
+ .setFeishuOpenDeptid(openDepartmentId);
|
|
|
|
+ Department department = new Department();
|
|
|
|
+ department.setCompanyId(companyId);
|
|
|
|
+ department.setDepartmentName(departmentName);
|
|
|
|
+ department.setFeishuDeptid(openDepartmentId);
|
|
|
|
+ departmentMapper.insert(department);
|
|
|
|
+ departmentFeishu.setSysDeptid(department.getDepartmentId());
|
|
|
|
+ departmentFeishuMapper.insert(departmentFeishu);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ SysRole role = sysRoleMapper.selectOne(new QueryWrapper<SysRole>().eq("company_id", companyId).eq("rolename","普通员工"));
|
|
|
|
+ List<Department> departmentList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", companyId));
|
|
|
|
+ List<DepartmentFeishu> departmentFeishuList = departmentFeishuMapper.selectList(new QueryWrapper<DepartmentFeishu>().eq("corpid", corpId));
|
|
|
|
+ List<User> userList=new ArrayList<>();
|
|
|
|
+ for (DepartmentFeishu departmentFeishu : departmentFeishuList) {
|
|
|
|
+ Optional<Department> first = departmentList.stream().filter(dl -> dl.getDepartmentId().equals(departmentFeishu.getSysDeptid())).findFirst();
|
|
|
|
+ //获取到当前部门的上级部门
|
|
|
|
+ Optional<DepartmentFeishu> wx = departmentFeishuList.stream().filter(dl -> dl.getFeishuOpenDeptid().equals(departmentFeishu.getFeishuParentid())).findFirst();
|
|
|
|
+ if(first.isPresent()){
|
|
|
|
+ if(wx.isPresent()){
|
|
|
|
+ Optional<Department> dp = departmentList.stream().filter(dl -> dl.getDepartmentId().equals(wx.get().getSysDeptid())).findFirst();
|
|
|
|
+ if(dp.isPresent()){
|
|
|
|
+ first.get().setSuperiorId(dp.get().getDepartmentId());
|
|
|
|
+ departmentMapper.updateById(first.get());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //处理部门下的人员
|
|
|
|
+ JSONArray userInfoWithDepartment=feishuInfoService.getUserInfoWithDepartment(feishuInfo,departmentFeishu.getFeishuOpenDeptid(),null);
|
|
|
|
+ for (int m=0;m<userInfoWithDepartment.size(); m++) {
|
|
|
|
+ JSONObject userJson = userInfoWithDepartment.getJSONObject(m);
|
|
|
|
+ String curUserid = userJson.getString("user_id");
|
|
|
|
+ String openUserid = userJson.getString("open_id");
|
|
|
|
+ if(!userJson.getJSONObject("status").getBoolean("is_activated")){
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ List<String> departments = (List<String>) userJson.get("department_ids");
|
|
|
|
+ System.out.println("user info======:"+userJson.toString());
|
|
|
|
+ //不存在的人员, 进行插入
|
|
|
|
+ User user = new User();
|
|
|
|
+ //在当前部门下的员工
|
|
|
|
+ user.setId(SnowFlake.nextId()+"")
|
|
|
|
+ .setRoleId(role.getId())//默认普通员工
|
|
|
|
+ .setRoleName(role.getRolename())
|
|
|
|
+ .setCompanyId(companyId)
|
|
|
|
+ .setName(userJson.getString("name"))
|
|
|
|
+ .setFeishuUserid(openUserid)
|
|
|
|
+ .setColor(ColorUtil.randomColor())
|
|
|
|
+ .setJobNumber(curUserid)
|
|
|
|
+ .setPassword(MD5Util.getPassword("000000"))
|
|
|
|
+ .setFeishuDeptid(departmentFeishu.getFeishuDeptid());
|
|
|
|
+ String max = departments.get(0);
|
|
|
|
+ Optional<DepartmentFeishu> dpFs = departmentFeishuList.stream().filter(dl -> dl.getFeishuOpenDeptid().equals(max)).findFirst();
|
|
|
|
+ if(dpFs.isPresent()){
|
|
|
|
+ Optional<Department> dp = departmentList.stream().filter(dl -> dl.getDepartmentId().equals(dpFs.get().getSysDeptid())).findFirst();
|
|
|
|
+ if(dp.isPresent()){
|
|
|
|
+ user.setDepartmentName(dp.get().getDepartmentName());
|
|
|
|
+ user.setDepartmentId(dp.get().getDepartmentId());
|
|
|
|
+ user.setDepartmentCascade(convertDepartmentIdToCascade(dp.get().getDepartmentId(),departmentList));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ boolean b = userList.stream().anyMatch(ul ->ul.getFeishuUserid()!=null&&ul.getFeishuUserid().equals(user.getFeishuUserid()));
|
|
|
|
+ if(!b){
|
|
|
|
+ userList.add(user);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //获取应用可用范围内的人员
|
|
|
|
+ JSONArray userArray = (JSONArray) availableRange.get("user_ids");
|
|
|
|
+ for (int i = 0; i < userArray.size(); i++) {
|
|
|
|
+ String userId = userArray.getString(i);
|
|
|
|
+ JSONObject userInfo = feishuInfoService.getUserInfo(feishuInfo, userId);
|
|
|
|
+ List<String> departments = (List<String>) userInfo.get("department_ids");
|
|
|
|
+ //不存在的人员, 进行插入
|
|
|
|
+ User user = new User();
|
|
|
|
+ //在当前部门下的员工
|
|
|
|
+ String max = departments.get(0);
|
|
|
|
+ user.setId(SnowFlake.nextId()+"")
|
|
|
|
+ .setRoleId(role.getId())//默认普通员工
|
|
|
|
+ .setRoleName(role.getRolename())
|
|
|
|
+ .setCompanyId(companyId)
|
|
|
|
+ .setName(userInfo.getString("name"))
|
|
|
|
+ .setFeishuUserid(userInfo.getString("open_id"))
|
|
|
|
+ .setColor(ColorUtil.randomColor())
|
|
|
|
+ .setJobNumber(userInfo.getString("user_id"))
|
|
|
|
+ .setPassword(MD5Util.getPassword("000000"))
|
|
|
|
+ .setFeishuDeptid(max);
|
|
|
|
+ Optional<DepartmentFeishu> dpFs = departmentFeishuList.stream().filter(dl -> dl.getFeishuDeptid().equals(max)).findFirst();
|
|
|
|
+ if(dpFs.isPresent()){
|
|
|
|
+ Optional<Department> dp = departmentList.stream().filter(dl -> dl.getDepartmentId().equals(dpFs.get().getSysDeptid())).findFirst();
|
|
|
|
+ user.setDepartmentName(dp.get().getDepartmentName());
|
|
|
|
+ user.setDepartmentId(dp.get().getDepartmentId());
|
|
|
|
+ user.setDepartmentCascade(convertDepartmentIdToCascade(dp.get().getDepartmentId(),departmentList));
|
|
|
|
+ }
|
|
|
|
+ boolean b = userList.stream().anyMatch(ul ->ul.getFeishuUserid()!=null&&ul.getFeishuUserid().equals(user.getFeishuUserid()));
|
|
|
|
+ if(!b){
|
|
|
|
+ userList.add(user);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ System.out.println("resutlList========="+userList);
|
|
|
|
+ if (userList.size()>0) {
|
|
|
|
+ userService.saveBatch(userList);
|
|
|
|
+ }
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|