Ver código fonte

飞书集成 子部门递归修改 进度 回调人员处理 子部门数据处理

Min 2 anos atrás
pai
commit
5dc5440db0

+ 144 - 2
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/FeishuInfoController.java

@@ -4,22 +4,27 @@ package com.management.platform.controller;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.google.gson.JsonObject;
 import com.management.platform.constant.Constant;
 import com.management.platform.entity.*;
 import com.management.platform.entity.vo.UserVO;
 import com.management.platform.mapper.*;
+import com.management.platform.service.DepartmentOtherManagerService;
 import com.management.platform.service.FeishuInfoService;
 import com.management.platform.service.SysRoleService;
 import com.management.platform.service.UserService;
 import com.management.platform.service.impl.FeishuInfoServiceImpl;
 import com.management.platform.util.*;
 import com.taobao.api.ApiException;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.http.*;
 import org.springframework.util.StringUtils;
 import org.springframework.web.bind.annotation.RequestMapping;
 
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.client.RestTemplate;
 
@@ -39,6 +44,7 @@ import java.util.stream.Collectors;
  */
 @RestController
 @RequestMapping("/feishu-info")
+@Slf4j
 public class FeishuInfoController {
 
     @Resource
@@ -79,6 +85,8 @@ public class FeishuInfoController {
     private TaskGroupMapper taskGroupMapper;
     @Resource
     private ProjectAuditorMapper projectAuditorMapper;
+    @Resource
+    DepartmentOtherManagerService departmentOtherManagerService;
 
 
     /**
@@ -144,7 +152,7 @@ public class FeishuInfoController {
                 if(departmentInfo!=null&&departmentInfo.size()>0){
                     departmentInfoArrays.addAll(departmentInfo);
                 }
-                JSONArray subDepartmentList = feishuInfoService.getSubDepartmentList(feishuInfo, dpId, null);
+                JSONArray subDepartmentList =getSubDepartmentList(feishuInfo,dpId);
                 if(subDepartmentList!=null&&subDepartmentList.size()>0){
                     departmentInfoArrays.addAll(subDepartmentList);
                 }
@@ -181,7 +189,7 @@ public class FeishuInfoController {
             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.getFeishuDeptid().equals(departmentFeishu.getFeishuParentid())).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();
@@ -267,6 +275,22 @@ public class FeishuInfoController {
         return msg;
     }
 
+    private JSONArray getSubDepartmentList(FeishuInfo feishuInfo, String dpId) {
+        JSONArray result=new JSONArray();
+        JSONArray subDepartmentList = feishuInfoService.getSubDepartmentList(feishuInfo, dpId, null);
+        result.addAll(subDepartmentList);
+        if(subDepartmentList!=null&&subDepartmentList.size()>0){
+            for (int i = 0; i < subDepartmentList.size(); i++) {
+                JSONObject ob = subDepartmentList.getJSONObject(i);
+                if(ob.getString("open_department_id")!=null){
+                    JSONArray array = getSubDepartmentList(feishuInfo, ob.getString("open_department_id"));
+                    result.addAll(array);
+                }
+            }
+        }
+        return  result;
+    }
+
     //将部门id转换为部门层级
     private String convertDepartmentIdToCascade(Integer id, List<Department> allDeptList) {
         StringBuilder cascade = new StringBuilder();
@@ -559,5 +583,123 @@ public class FeishuInfoController {
         }
     }
 
+
+    @RequestMapping("/initSuperManager")
+    public HttpRespMsg initSuperManager(String corpid, String name) {
+        return feishuInfoService.initSuperManager(corpid, name);
+    }
+
+    //"企业微信数据回调"
+    @RequestMapping(value = "/dataCallback", method = RequestMethod.POST)
+    @ResponseBody
+    public String dataCallback(String schema,String header,String event){
+        JSONObject headerOb = JSONObject.parseObject(header);
+        JSONObject eventOb = JSONObject.parseObject(event);
+        log.info("========schema========="+schema);
+        String appId = headerOb.getString("app_id");
+        log.info("========app_id========"+appId);
+        String tenantKey = headerOb.getString("tenant_key");
+        log.info("========tenant_key========"+tenantKey);
+        String createTime = headerOb.getString("create_time");
+        log.info("========create_time========"+createTime);
+        List<FeishuInfo> feishuInfoList = feishuInfoMapper.selectList(new QueryWrapper<FeishuInfo>().eq("app_id", appId));
+        if(feishuInfoList.size()>0){
+            FeishuInfo feishuInfo = feishuInfoList.get(0);
+            List<User> allUserList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", feishuInfo.getCompanyId()));
+            SysRole role = sysRoleMapper.selectOne(new QueryWrapper<SysRole>().eq("company_id",feishuInfo.getCompanyId()).eq("rolename","普通员工"));
+            //通讯录权限范围变更
+            //todo:新增的
+            if(eventOb.getJSONObject("added")!=null){
+                JSONObject addedOb = eventOb.getJSONObject("added");
+                //todo:处理部门
+                JSONArray departmentArray = addedOb.getJSONArray("departments");
+                for (int j = 0; j < departmentArray.size(); j++) {
+                    JSONObject ob = departmentArray.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"));
+                    JSONArray leaders = ob.getJSONArray("leaders");
+                    Integer cut = departmentFeishuMapper.selectCount(new QueryWrapper<DepartmentFeishu>().eq("corpid",feishuInfo.getCorpid()).eq("feishu_deptid",departmentId));
+                    if(cut==0&&!departmentId.equals("0")){
+                        System.out.println("join===========");
+                        DepartmentFeishu departmentFeishu=new DepartmentFeishu();
+                        departmentFeishu.setCorpid(feishuInfo.getCorpid())
+                                .setName(departmentName)
+                                .setFeishuParentid(departmentParentId)
+                                .setFeishuDeptid(departmentId)
+                                .setFeishuOpenDeptid(openDepartmentId);
+                        Department department = new Department();
+                        department.setCompanyId(feishuInfo.getCompanyId());
+                        department.setDepartmentName(departmentName);
+                        department.setFeishuDeptid(openDepartmentId);
+                        departmentMapper.insert(department);
+                        List<DepartmentOtherManager> odList=new ArrayList<>();
+                        if(leaders.size()>0){
+                            //todo:处理主要负责人
+                            Optional<Object> first = leaders.stream().filter(l -> ((JSONObject) l).getIntValue("leaderType") == 1).findFirst();
+                            if(first.isPresent()){
+                                JSONObject firstOb = (JSONObject) first.get();
+                                Optional<User> leaderID = allUserList.stream().filter(ul -> ul.getFeishuUserid().equals(firstOb.getString("leaderID"))).findFirst();
+                                if(leaderID.isPresent()){
+                                    department.setManagerId(leaderID.get().getId());
+                                }
+                            }
+                            //todo:处理次要负责人
+                            List<Object> othObs = leaders.stream().filter(l -> ((JSONObject) l).getIntValue("leaderType") == 2).collect(Collectors.toList());
+                            for (Object othOb : othObs) {
+                                JSONObject oth = (JSONObject) othOb;
+                                Optional<User> leaderID = allUserList.stream().filter(ul -> ul.getFeishuUserid().equals(oth.getString("leaderID"))).findFirst();
+                                if(leaderID.isPresent()){
+                                    DepartmentOtherManager departmentOtherManager=new DepartmentOtherManager();
+                                    departmentOtherManager.setCompanyId(feishuInfo.getCompanyId());
+                                    departmentOtherManager.setDepartmentId(department.getDepartmentId());
+                                    departmentOtherManager.setOtherManagerId(leaderID.get().getId());
+                                    odList.add(departmentOtherManager);
+                                }
+                            }
+                        }
+                        departmentMapper.updateById(department);
+                        departmentFeishu.setSysDeptid(department.getDepartmentId());
+                        departmentFeishuMapper.insert(departmentFeishu);
+                        departmentOtherManagerService.saveBatch(odList);
+                    }
+                }
+                List<Department> departmentList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id",feishuInfo.getCompanyId()));
+                List<DepartmentFeishu> departmentFeishuList = departmentFeishuMapper.selectList(new QueryWrapper<DepartmentFeishu>().eq("corpid", feishuInfo.getCorpid()));
+                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.getFeishuDeptid().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());
+                            }
+                        }
+                    }
+                }
+                //todo:处理人员
+                JSONArray userArrays = addedOb.getJSONArray("users");
+                List<User> newUserList=new ArrayList<>();
+                for (int i = 0; i < userArrays.size(); i++) {
+                    JSONObject userOb = userArrays.getJSONObject(i);
+                    boolean b = allUserList.stream().anyMatch(al -> al.getFeishuUserid() != null && al.getFeishuUserid().equals(userOb.getString("open_id")));
+                    if(!b){
+                        User user=new User();
+                    }
+                }
+            }
+            //todo:移除的
+            if(eventOb.getJSONObject("removed")!=null){
+
+            }
+        }
+        return null;
+    }
+
 }
 

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

@@ -37,4 +37,6 @@ public interface FeishuInfoService extends IService<FeishuInfo> {
     void batchSendCardTemplateMessage(FeishuInfo feishuInfo, List<String> userIds, String sendTypeName, List<String> templateVariableDetail) throws Exception;
 
     void batchSendCardMessage(FeishuInfo feishuInfo, List<String> userIds, String sendTypeName, Map<String, String> templateVariableDetail, String pushUrl) throws Exception;
+
+    HttpRespMsg initSuperManager(String corpid, String name);
 }

+ 29 - 3
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/FeishuInfoServiceImpl.java

@@ -6,14 +6,16 @@ import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.google.gson.JsonObject;
 import com.management.platform.constant.Constant;
-import com.management.platform.entity.FeishuInfo;
-import com.management.platform.entity.FeishuSend;
-import com.management.platform.entity.User;
+import com.management.platform.entity.*;
 import com.management.platform.mapper.FeishuInfoMapper;
 import com.management.platform.mapper.FeishuSendMapper;
+import com.management.platform.mapper.SysRoleMapper;
+import com.management.platform.mapper.UserMapper;
+import com.management.platform.service.DepartmentOtherManagerService;
 import com.management.platform.service.FeishuInfoService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.management.platform.util.HttpRespMsg;
+import com.management.platform.util.MD5Util;
 import com.management.platform.util.MessageUtils;
 import com.management.platform.util.UserAgentUtils;
 import org.apache.http.client.methods.HttpGet;
@@ -67,6 +69,10 @@ public class FeishuInfoServiceImpl extends ServiceImpl<FeishuInfoMapper, FeishuI
         FeishuInfoMapper feishuInfoMapper;
         @Resource
         FeishuSendMapper feishuSendMapper;
+        @Resource
+        UserMapper userMapper;
+        @Resource
+        SysRoleMapper sysRoleMapper;
 
         @Override
         public String getAppAccessToken(FeishuInfo feishuInfo) {
@@ -463,4 +469,24 @@ public class FeishuInfoServiceImpl extends ServiceImpl<FeishuInfoMapper, FeishuI
                 }
         }
 
+        @Override
+        public HttpRespMsg initSuperManager(String corpid, String name) {
+                HttpRespMsg msg = new HttpRespMsg();
+                FeishuInfo feishuInfo = feishuInfoMapper.selectById(corpid);
+                Integer companyId = feishuInfo.getCompanyId();
+                User user = userMapper.selectOne(new QueryWrapper<User>().eq("name", name).eq("company_id", companyId));
+                if (user == null) {
+                        //msg.setError("该用户不存在: " + name);
+                        msg.setError(MessageUtils.message("user.notExistsByParam",name));
+                } else {
+                        SysRole role = sysRoleMapper.selectOne(new QueryWrapper<SysRole>().eq("company_id", companyId).eq("rolename", "超级管理员"));
+                        user.setPhone(user.getName());
+                        user.setPassword(MD5Util.getPassword("000000"));
+                        user.setRoleId(role.getId());
+                        user.setRoleName(role.getRolename());
+                        userMapper.updateById(user);
+                }
+                return msg;
+        }
+
 }

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

@@ -706,16 +706,18 @@
     </select>
     <select id="getProWaitingApproveCnt" resultType="java.util.HashMap">
         select count(1) as num, user.dingding_userid as auditorDDId ,user.corpwx_userid as corpwxUserid from report
-         left join user on user.id = project_auditor_id
+         left join `user` on `user`.id = project_auditor_id
          where state = 0 and project_audit_state = 0 and is_dept_audit = 0
         and report.company_id = #{companyId}
+        and `user`.is_active=1
         group by project_auditor_id
     </select>
     <select id="getDeptWaitingApproveCnt" resultType="java.util.HashMap">
         select COUNT(1) as num, user.dingding_userid as auditorDDId ,user.corpwx_userid as corpwxUserid from report
-         left join user on user.id = audit_dept_managerid
+         left join `user` on `user`.id = audit_dept_managerid
          where state = 0 and department_audit_state = 0 and is_dept_audit = 1
         and report.company_id =#{companyId}
+        and `user`.is_active=1
         group by audit_dept_managerid
     </select>
     <select id="getProjectCost" resultType="java.util.HashMap">