Forráskód Böngészése

内部应用企业微信通讯录同步

yurk 2 éve
szülő
commit
6e64ddc647

+ 21 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/DepartmentWxController.java

@@ -0,0 +1,21 @@
+package com.management.platform.controller;
+
+
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * <p>
+ *  前端控制器
+ * </p>
+ *
+ * @author Seyason
+ * @since 2022-11-28
+ */
+@RestController
+@RequestMapping("/department-wx")
+public class DepartmentWxController {
+
+}
+

+ 221 - 4
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/WeiXinCorpController.java

@@ -3,6 +3,10 @@ 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.dingtalk.api.DefaultDingTalkClient;
+import com.dingtalk.api.DingTalkClient;
+import com.dingtalk.api.request.OapiV2DepartmentListsubRequest;
+import com.dingtalk.api.response.OapiV2DepartmentListsubResponse;
 import com.google.gson.JsonObject;
 import com.management.platform.constant.Constant;
 import com.management.platform.entity.*;
@@ -16,6 +20,7 @@ import com.management.platform.service.impl.UserServiceImpl;
 import com.management.platform.util.*;
 import com.qq.weixin.mp.aes.AesException;
 import com.qq.weixin.mp.aes.WXBizMsgCrypt;
+import com.taobao.api.ApiException;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.ibatis.annotations.Select;
 import org.json.XML;
@@ -37,6 +42,9 @@ import java.sql.Timestamp;
 import java.time.*;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Function;
+import java.util.function.Predicate;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
@@ -82,12 +90,17 @@ public class WeiXinCorpController {
     public static final String GET_CORP_TOKEN = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=ID&corpsecret=SECRET";
 
     public static final String GET_REGISTER_CODE = "https://qyapi.weixin.qq.com/cgi-bin/service/get_register_code?provider_access_token=PROVIDER_ACCESS_TOKEN";
+
+    public static final String GET_APPLICATION_INFO = "https://qyapi.weixin.qq.com/cgi-bin/agent/get?access_token=ACCESS_TOKEN&agentid=AGENTID";
+
     @Value("${suitId}")
     private String suitId;
     @Value("${suitSecret}")
     private String suitSecret;
     @Value("${providerSecret}")
     private String providerSecret;
+    @Value("${configEnv.isPrivateDeploy}")
+    private boolean isPrivateDeploy;//企业内部应用,私有化部署的情况
 
     //自己公司的企业微信通讯录secret
     private String concactSecret="irf7s8fy16wLhWGb8IxvGL2Nkm0sTB6dludpe_3VP6k";
@@ -121,6 +134,8 @@ public class WeiXinCorpController {
     private SysRoleModuleService sysRoleModuleService;
     @Resource
     private SysRoleFunctionService sysRoleFunctionService;
+    @Resource
+    private UserService userService;
     @Autowired
     RestTemplate restTemplate;
     @Resource
@@ -143,6 +158,8 @@ public class WeiXinCorpController {
     private WxOrderMapper wxOrderMapper;
     @Resource
     private ContactSyncLogMapper contactSyncLogMapper;
+    @Resource
+    private DepartmentWxMapper departmentWxMapper;
 
     public static String SUITE_ACCESS_TOKEN = null;
     public static long suiteTokenExpireTime = 0L;
@@ -179,8 +196,6 @@ public class WeiXinCorpController {
     @Resource
     DepartmentService departmentService;
     @Resource
-    UserService userService;
-    @Resource
     CorpwxJobResultMapper corpwxJobResultMapper;
     @Resource
     private AuditWorkflowTimeSettingMapper auditWorkflowTimeSettingMapper;
@@ -3268,8 +3283,6 @@ public class WeiXinCorpController {
             }
             companyMapper.updateById(newCompany);
             System.out.println("已成功变更版本,版本号为:"+edition_id);
-            //开通模块和权限
-            rootRole(wxCorpInfo.getCompanyId());
         }else {
             System.out.println("++++++++++++++++++++++"+"版本变更失败!"+"++++++++++++++++++++++++");
         }
@@ -3289,6 +3302,210 @@ public class WeiXinCorpController {
         }
         return view;
     }
+    /**
+     * 初始化内部应用的系统数据
+     * @return
+     */
+    @RequestMapping("/initSystem")
+    public HttpRespMsg initSystem(String corpid) throws Exception{
+        try {
+            //初始化数据生成公司
+            System.out.println("========接收到initSystem请求===corpid="+corpid);
+            HttpRespMsg msg = new HttpRespMsg();
+            if (!isPrivateDeploy) {
+                //msg.setError("请配置isPrivateDeploy: true");
+                msg.setError(MessageUtils.message("config.isPrivateDeploy"));
+            } else {
+                //查找公司对应的记录是否已经添加
+                WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectById(corpid);
+                if (wxCorpInfo == null) {
+                    //msg.setError("请在company_dingding表中增加corpid:" + corpid);
+                    msg.setError(MessageUtils.message("config.ddCorpId"));
+                } else if (wxCorpInfo.getCompanyId() != null) {
+                    //msg.setError("companyId已存在,如需重新初始化请先重置company_dingding中该条数据的companyId为null");
+                    msg.setError(MessageUtils.message("config.companyIdExist"));
+                } else {
+                    Company company = new Company().setCompanyName(wxCorpInfo.getCorpName())
+                            .setExpirationDate(LocalDateTime.now().plusDays(15));
+                    company.setPackageWorktime(1);
+                    companyMapper.insert(company);
+                    wxCorpInfo.setCompanyId(company.getId());
+                    wxCorpInfoMapper.updateById(wxCorpInfo);
+                    //生成工作时长
+                    TimeType timeType = new TimeType();
+                    timeType.setCompanyId(company.getId());
+                    timeTypeMapper.insert(timeType);
+                    SysRole smanager = sysRoleService.generateDefaultRoles(company.getId());
+                    //生成项目的成本基线默认条目
+                    String[] array = Constant.DEFAULT_BASE_COST_ITEMS;
+                    for (String baseItem : array) {
+                        ProjectBasecostSetting setting = new ProjectBasecostSetting();
+                        setting.setName(baseItem);
+                        setting.setCompanyId(company.getId());
+                        projectBasecostSettingMapper.insert(setting);
+                    }
+                    String accessToken = getCorpConcactAccessToken(wxCorpInfo);
+                    //获取组织架构 同步部门
+                    String departmentInfoResp=wxCorpInfoService.getDepartmentInfoWithApplication(accessToken);
+                    System.out.println(departmentInfoResp);
+                    JSONObject departmentInfoOb = JSONObject.parseObject(departmentInfoResp);
+                    JSONArray departmentInfoArrays = departmentInfoOb.getJSONArray("department");
+                    for (int i = 0; i < departmentInfoArrays.size(); i++) {
+                        JSONObject ob = departmentInfoArrays.getJSONObject(i);
+                        String departmentName = String.valueOf(ob.get("name"));
+                        System.out.println("synchronizationDP========="+departmentName);
+                        Integer departmentId = ob.getInteger("id");
+                        Integer departmentParentId =ob.getInteger("parentid");
+                        Integer cut = departmentWxMapper.selectCount(new QueryWrapper<DepartmentWx>().eq("corpid",corpid).eq("wx_deptid",departmentId));
+                        if(cut==0&&departmentId!=1){
+                            System.out.println("join===========");
+                            DepartmentWx departmentWx=new DepartmentWx();
+                            departmentWx.setCorpid(corpid)
+                                    .setName(departmentName)
+                                    .setWxParentid(departmentParentId)
+                                    .setWxDeptid(departmentId);
+                            Department department = new Department();
+                            department.setCompanyId(company.getId());
+                            department.setDepartmentName(departmentName);
+                            department.setCorpwxDeptid(departmentId);
+                            departmentMapper.insert(department);
+                            departmentWx.setSysDeptid(department.getDepartmentId());
+                            departmentWxMapper.insert(departmentWx);
+                        }
+                    }
+                    SysRole role = sysRoleMapper.selectOne(new QueryWrapper<SysRole>().eq("company_id", company.getId()).eq("rolename","普通员工"));
+                    List<Department> departmentList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", company.getId()));
+                    List<DepartmentWx> departmentWxList = departmentWxMapper.selectList(new QueryWrapper<DepartmentWx>().eq("corpid", corpid));
+                    List<User> userList=new ArrayList<>();
+                    for (DepartmentWx departmentWx : departmentWxList) {
+                        Optional<Department> first = departmentList.stream().filter(dl -> dl.getDepartmentId().equals(departmentWx.getSysDeptid())).findFirst();
+                        //获取到当前部门的上级部门
+                        Optional<DepartmentWx> wx = departmentWxList.stream().filter(dl -> dl.getWxDeptid().equals(departmentWx.getWxParentid())).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());
+                                }
+                            }
+                        }
+                        //处理部门下的人员
+                        String resp=wxCorpInfoService.getUserInfoWithDepartment(accessToken,departmentWx.getWxDeptid());
+                        System.out.println("userList======"+resp);
+                        JSONObject userOb = JSONObject.parseObject(resp);
+                        JSONArray jsonArray = userOb.getJSONArray("userlist");
+                        for (int m=0;m<jsonArray.size(); m++) {
+                            JSONObject userJson = jsonArray.getJSONObject(m);
+                            String curUserid = userJson.getString("userid");
+                            String openUserid = userJson.getString("open_userid");
+                            List<Integer> departments = (List<Integer>) userJson.get("department");
+                            System.out.println("user info======:"+userJson.toString());
+                            //不存在的人员, 进行插入
+                            User user = new User();
+                            //在当前部门下的员工
+                            user.setId(SnowFlake.nextId()+"")
+                                    .setRoleId(role.getId())//默认普通员工
+                                    .setRoleName(role.getRolename())
+                                    .setCompanyId(company.getId())
+                                    .setName(userJson.getString("name"))
+                                    .setCorpwxUserid(openUserid)
+                                    .setCorpwxRealUserid(curUserid)
+                                    .setColor(ColorUtil.randomColor())
+                                    .setJobNumber(curUserid.equals(openUserid)?null:curUserid)
+                                    .setPassword(MD5Util.getPassword("000000"))
+                                    .setCorpwxDeptid(departmentWx.getWxDeptid());
+                            Integer max = Collections.max(departments);
+                            Optional<DepartmentWx> dpWx = departmentWxList.stream().filter(dl -> dl.getWxDeptid().equals(max)).findFirst();
+                            if(dpWx.isPresent()){
+                                Optional<Department> dp = departmentList.stream().filter(dl -> dl.getDepartmentId().equals(dpWx.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.getCorpwxUserid()!=null&&ul.getCorpwxUserid().equals(openUserid));
+                            if(!b){
+                                userList.add(user);
+                            }
+                        }
+                    }
+                    String url = GET_APPLICATION_INFO.replace("ACCESS_TOKEN",accessToken).replace("AGENTID",String.valueOf(wxCorpInfo.getAgentid()));
+                    HttpHeaders headers = new HttpHeaders();
+                    headers.setContentType(MediaType.APPLICATION_JSON);
+                    ResponseEntity<String> responseEntity = this.restTemplate.getForEntity(url,String.class);
+                    if (responseEntity.getStatusCode() == HttpStatus.OK) {
+                        String resp = responseEntity.getBody();
+                        JSONObject json = JSONObject.parseObject(resp);
+                        if (json.getIntValue("errcode") == 0) {
+                            System.out.println("this is agentinfo========"+resp);
+                            String allow_userinfos = json.getString("allow_userinfos");
+                            JSONObject jsonObject = JSONObject.parseObject(allow_userinfos);
+                            JSONArray userInfo = jsonObject.getJSONArray("user");
+                            for (int i = 0; i < userInfo.size(); i++) {
+                                JSONObject object = userInfo.getJSONObject(i);
+                                String corpWxuserid = object.getString("userid");
+                                String userInfoResp=wxCorpInfoService.getUserInfoWithApplication(accessToken,corpWxuserid);
+                                System.out.println("this is userinfo======="+userInfoResp);
+                                JSONObject userInfoOb = JSONObject.parseObject(userInfoResp);
+                                //跳过非激活状态的员工
+                                if (userInfoOb.getInteger("status") != 1) continue;
+                                String userName = String.valueOf(userInfoOb.get("name"));
+                                String phone = String.valueOf(userInfoOb.get("phone"));
+                                String openUserid = userInfoOb.getString("open_userid");
+                                List<Integer> departments = (List<Integer>) userInfoOb.get("department");
+                                Integer deptId = departments.get(0);
+                                User user=new User();
+                                user.setId(String.valueOf(SnowFlake.nextId()));
+                                user.setCompanyId(company.getId());
+                                System.out.println("now dept id is ==="+deptId);
+                                for (Integer department : departments) {
+                                    Optional<DepartmentWx> first = departmentWxList.stream().filter(dl -> dl.getWxDeptid().equals(department)).findFirst();
+                                    if(first.isPresent()){
+                                        if(department.equals(deptId)){
+                                            user.setDepartmentId(first.get().getSysDeptid());
+                                            user.setDepartmentName(first.get().getName());
+                                            user.setCorpwxDeptid(first.get().getWxDeptid());
+                                            user.setDepartmentCascade(convertDepartmentIdToCascade(first.get().getSysDeptid(), departmentList));
+                                        }
+                                    }
+                                }
+                                user.setCorpwxUserid(openUserid)
+                                    .setName(userName)
+                                    .setRoleName(role.getRolename())
+                                    .setRoleId(role.getId())
+                                    .setPhone(phone)
+                                    .setCorpwxRealUserid(corpWxuserid)
+                                    .setColor(ColorUtil.randomColor())
+                                    .setPassword(MD5Util.getPassword("000000"))
+                                    .setJobNumber(corpWxuserid.equals(openUserid)?null:corpWxuserid);
+                                boolean b = userList.stream().anyMatch(ul -> ul.getCorpwxUserid().equals(openUserid));
+                                if(!b){
+                                    userList.add(user);
+                                }
+                            }
+                        } else {
+                            throw new Exception(json.toJSONString());
+                        }
+                    }
+                    userService.saveBatch(userList);
+                }
+            }
+            return msg;
+        } catch (ApiException e) {
+            e.printStackTrace();
+            String errMsg = e.getErrMsg();
+            HttpRespMsg msg = new HttpRespMsg();
+            msg.setError(errMsg);
+            return msg;
+        }
+    }
+
+
+
+    @RequestMapping("/initSuperManager")
+    public HttpRespMsg initSuperManager(String corpid, String name) {
+        return wxCorpInfoService.initSuperManager(corpid, name);
+    }
 
     //为超级管理员角色赋予模块权限
     private void rootRole (Integer companyId){

+ 3 - 6
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/entity/Department.java

@@ -1,6 +1,5 @@
 package com.management.platform.entity;
 
-import com.baomidou.mybatisplus.annotation.FieldStrategy;
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.extension.activerecord.Model;
 import com.baomidou.mybatisplus.annotation.TableId;
@@ -16,7 +15,7 @@ import lombok.experimental.Accessors;
  * </p>
  *
  * @author Seyason
- * @since 2022-07-14
+ * @since 2022-11-28
  */
 @Data
 @EqualsAndHashCode(callSuper = false)
@@ -52,23 +51,21 @@ public class Department extends Model<Department> {
     /**
      * 部门负责人id
      */
-    @TableField(value = "manager_id", updateStrategy = FieldStrategy.IGNORED)
+    @TableField("manager_id")
     private String managerId;
 
     /**
      * 日报导入审核人
      */
-    @TableField(value = "report_audit_userid", updateStrategy = FieldStrategy.IGNORED)
+    @TableField("report_audit_userid")
     private String reportAuditUserid;
 
-
     /**
      * 企业微信的部门id
      */
     @TableField("corpwx_deptid")
     private Integer corpwxDeptid;
 
-
     /**
      * 企业微信部门的父部门id
      */

+ 57 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/entity/DepartmentWx.java

@@ -0,0 +1,57 @@
+package com.management.platform.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableField;
+import java.io.Serializable;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author Seyason
+ * @since 2022-11-28
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+public class DepartmentWx extends Model<DepartmentWx> {
+
+    private static final long serialVersionUID=1L;
+
+    @TableId(value = "id", type = IdType.AUTO)
+    private Integer id;
+
+    @TableField("wx_deptid")
+    private Integer wxDeptid;
+
+    @TableField("wx_parentid")
+    private Integer wxParentid;
+
+    /**
+     * 企业corpid
+     */
+    @TableField("corpid")
+    private String corpid;
+
+    @TableField("name")
+    private String name;
+
+    /**
+     * 内部部门id
+     */
+    @TableField("sys_deptid")
+    private Integer sysDeptid;
+
+
+    @Override
+    protected Serializable pkVal() {
+        return this.id;
+    }
+
+}

+ 16 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/mapper/DepartmentWxMapper.java

@@ -0,0 +1,16 @@
+package com.management.platform.mapper;
+
+import com.management.platform.entity.DepartmentWx;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author Seyason
+ * @since 2022-11-28
+ */
+public interface DepartmentWxMapper extends BaseMapper<DepartmentWx> {
+
+}

+ 16 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/DepartmentWxService.java

@@ -0,0 +1,16 @@
+package com.management.platform.service;
+
+import com.management.platform.entity.DepartmentWx;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author Seyason
+ * @since 2022-11-28
+ */
+public interface DepartmentWxService extends IService<DepartmentWx> {
+
+}

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

@@ -6,6 +6,7 @@ import com.management.platform.entity.LeaveSheet;
 import com.management.platform.entity.WxCorpInfo;
 import com.management.platform.util.HttpRespMsg;
 
+import javax.servlet.http.HttpServletRequest;
 import java.io.File;
 import java.time.LocalDateTime;
 import java.util.List;
@@ -43,4 +44,12 @@ public interface WxCorpInfoService extends IService<WxCorpInfo> {
     public String getSyncTranslationResult(String jobId) throws Exception;
 
     public HttpRespMsg getUserPunchRecord(int companyId, String userId, LocalDateTime startDateTime, LocalDateTime endDateTime, boolean showLog);
+
+    String getUserInfoWithApplication(String accessToken, String userid) throws Exception;
+
+    String getDepartmentInfoWithApplication(String accessToken);
+
+    HttpRespMsg initSuperManager(String corpid, String name);
+
+    String getUserInfoWithDepartment(String accessToken, Integer wxDeptid);
 }

+ 20 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/DepartmentWxServiceImpl.java

@@ -0,0 +1,20 @@
+package com.management.platform.service.impl;
+
+import com.management.platform.entity.DepartmentWx;
+import com.management.platform.mapper.DepartmentWxMapper;
+import com.management.platform.service.DepartmentWxService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+
+/**
+ * <p>
+ *  服务实现类
+ * </p>
+ *
+ * @author Seyason
+ * @since 2022-11-28
+ */
+@Service
+public class DepartmentWxServiceImpl extends ServiceImpl<DepartmentWxMapper, DepartmentWx> implements DepartmentWxService {
+
+}

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

@@ -5,13 +5,24 @@ import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.dingtalk.api.DefaultDingTalkClient;
+import com.dingtalk.api.DingTalkClient;
+import com.dingtalk.api.request.OapiAuthScopesRequest;
+import com.dingtalk.api.request.OapiV2DepartmentGetRequest;
+import com.dingtalk.api.request.OapiV2DepartmentListsubRequest;
+import com.dingtalk.api.response.OapiAuthScopesResponse;
+import com.dingtalk.api.response.OapiV2DepartmentGetResponse;
+import com.dingtalk.api.response.OapiV2DepartmentListsubResponse;
 import com.google.gson.JsonArray;
 import com.google.gson.JsonObject;
+import com.management.platform.constant.Constant;
 import com.management.platform.controller.WeiXinCorpController;
 import com.management.platform.entity.*;
 import com.management.platform.mapper.*;
+import com.management.platform.service.SysRoleService;
 import com.management.platform.service.WxCorpInfoService;
 import com.management.platform.util.*;
+import com.taobao.api.ApiException;
 import javafx.scene.effect.Light;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
@@ -65,6 +76,12 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
 
     public static final String GET_CHECKIN_OPTION = "https://qyapi.weixin.qq.com/cgi-bin/checkin/getcheckinoption?access_token=ACCESS_TOKEN";
 
+    public static final String GET_USER_INFO = "https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token=ACCESS_TOKEN&userid=USERID";
+
+    public static final String GET_DEPARTMENT_INFO = "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=ACCESS_TOKEN&id=ID";
+
+    public static final String GET_USER_INFO_WITHDP = "https://qyapi.weixin.qq.com/cgi-bin/user/list?access_token=ACCESS_TOKEN&department_id=DEPARTMENT_ID";
+
 
     @Value("${suitId}")
     private String suitId;
@@ -100,6 +117,8 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
     LeaveSheetMapper leaveSheetMapper;
     @Resource
     TimeTypeMapper timeTypeMapper;
+    @Resource
+    SysRoleMapper sysRoleMapper;
 
 
     //获取服务商provider_access_token
@@ -505,6 +524,62 @@ public class WxCorpInfoServiceImpl extends ServiceImpl<WxCorpInfoMapper, WxCorpI
         return msg;
     }
 
+    @Override
+    public String getUserInfoWithApplication(String accessToken, String userid) throws Exception {
+        String url = GET_USER_INFO.replace("ACCESS_TOKEN",accessToken).replace("USERID",userid);
+        ResponseEntity<String> responseEntity = this.restTemplate.getForEntity(url,String.class);
+        String result="";
+        if (responseEntity.getStatusCode() == HttpStatus.OK) {
+            String resp = responseEntity.getBody();
+            result+=resp;
+        }
+        return result;
+    }
+
+    @Override
+    public String getDepartmentInfoWithApplication(String accessToken) {
+        String url = GET_DEPARTMENT_INFO.replace("ACCESS_TOKEN",accessToken);
+        ResponseEntity<String> responseEntity = this.restTemplate.getForEntity(url,String.class);
+        String result="";
+        if (responseEntity.getStatusCode() == HttpStatus.OK) {
+            String resp = responseEntity.getBody();
+            result+=resp;
+        }
+        return result;
+    }
+
+    @Override
+    public HttpRespMsg initSuperManager(String corpid, String name) {
+        HttpRespMsg msg = new HttpRespMsg();
+        WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectById(corpid);
+        Integer companyId = wxCorpInfo.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;
+    }
+
+    @Override
+    public String getUserInfoWithDepartment(String accessToken, Integer wxDeptid) {
+        String url = GET_USER_INFO_WITHDP.replace("ACCESS_TOKEN",accessToken).replace("DEPARTMENT_ID",wxDeptid+"");
+        ResponseEntity<String> responseEntity = this.restTemplate.getForEntity(url,String.class);
+        String result="";
+        if (responseEntity.getStatusCode() == HttpStatus.OK) {
+            String resp = responseEntity.getBody();
+            result+=resp;
+        }
+        return result;
+    }
+
 
     public void reqPunchRecord(WxCorpInfo corpInfo, long startTime, long endTime, Object[] objects, boolean showLog,String userId,LocalDate date)throws Exception {
         DateTimeFormatter mdFormat = DateTimeFormatter.ofPattern("yyyy/M/d");

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

@@ -19,99 +19,4 @@
         department_id, department_name, superior_id, company_id, manager_id, report_audit_userid, corpwx_deptid, corpwx_deptpid
     </sql>
 
-    <!--根据部门获取成本-->
-    <select id="getCostByDepartment" resultType="java.util.Map">
-        SELECT SUM(b.working_time) AS time, SUM(b.cost) AS money
-        FROM report AS b
-        WHERE b.state = 1
-        <if test="departmentIds != null and departmentIds.size()>0">
-            AND b.dept_id IN
-            <foreach collection="departmentIds" item="departmentId" index="index" open="(" close=")" separator=",">
-                #{departmentId}
-            </foreach>
-        </if>
-        <if test="startDate != null and endDate != null">
-            AND b.create_date between #{startDate} and #{endDate}
-        </if>
-    </select>
-
-    <!--根据人员获取成本-->
-    <select id="getCostByUser" resultType="java.util.Map">
-        SELECT a.id as id, a.name AS user,a.corpwx_userid as corpwxUserId, a.job_number as jobNumber, c.project_name AS project, SUM(b.working_time) AS time, SUM(b.cost) AS
-        money
-        FROM user AS a
-        LEFT JOIN report AS b ON a.id = b.creator_id
-        LEFT JOIN project AS c ON b.project_id = c.id
-        WHERE b.state = 1
-        <if test="departmentIds != null and departmentIds.size()>0">
-            AND b.dept_id IN
-            <foreach collection="departmentIds" item="departmentId" index="index" open="(" close=")" separator=",">
-                #{departmentId}
-            </foreach>
-        </if>
-        <if test="userIds != null">
-            AND a.id IN
-            <foreach collection="userIds" item="userId" index="index" open="(" close=")" separator=",">
-                #{userId}
-            </foreach>
-        </if>
-        <if test="companyId != null">
-            AND a.company_id = #{companyId}
-        </if>
-        <if test="startDate != null and endDate != null">
-            AND b.create_date between #{startDate} and #{endDate}
-        </if>
-        GROUP BY b.project_id, a.id order by a.department_id
-    </select>
-
-    <!-- 根据人员获取自定义的日报数值 -->
-    <select id="getCustomDataByUser" resultType="java.util.Map">
-        SELECT a.id as id, a.name AS user,a.corpwx_userid as corpwxUserid, a.job_number as jobNumber,c.project_name AS project, IFNULL(SUM(b.custom_data),0) AS cost
-        FROM user AS a
-        LEFT JOIN report AS b ON a.id = b.creator_id
-        LEFT JOIN project AS c ON b.project_id = c.id
-        WHERE b.state = 1
-        <if test="departmentIds != null">
-            AND a.department_id IN
-            <foreach collection="departmentIds" item="departmentId" index="index" open="(" close=")" separator=",">
-                #{departmentId}
-            </foreach>
-        </if>
-        <if test="userIds != null">
-            AND a.id IN
-            <foreach collection="userIds" item="userId" index="index" open="(" close=")" separator=",">
-                #{userId}
-            </foreach>
-        </if>
-        <if test="companyId != null">
-            AND a.company_id = #{companyId}
-        </if>
-        <if test="startDate != null and endDate != null">
-            AND b.create_date between #{startDate} and #{endDate}
-        </if>
-        GROUP BY b.project_id, a.id
-        having IFNULL(SUM(b.custom_data),0) > 0
-    </select>
-    <!-- 根据部门获取自定义的日报数值 -->
-    <select id="getDeptCustomDataStatistic" resultType="java.util.Map">
-        SELECT a.department_id as id, a.department_name AS department, c.project_name AS project, IFNULL(SUM(b.custom_data),0) AS cost
-        FROM department AS a
-        LEFT JOIN report AS b ON a.department_id = b.dept_id
-        LEFT JOIN project AS c ON b.project_id = c.id
-        WHERE b.state = 1
-        <if test="companyId!=null">
-            AND a.company_id =#{companyId}
-        </if>
-        <if test="departmentIds != null">
-            AND a.department_id IN
-            <foreach collection="departmentIds" item="departmentId" index="index" open="(" close=")" separator=",">
-                #{departmentId}
-            </foreach>
-        </if>
-        <if test="startDate!=null and endDate!=null">
-            AND b.create_date between #{startDate} and #{endDate}
-        </if>
-        GROUP BY b.project_id, a.department_id
-        having IFNULL(SUM(b.custom_data),0) > 0
-    </select>
 </mapper>

+ 20 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/resources/mapper/DepartmentWxMapper.xml

@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.management.platform.mapper.DepartmentWxMapper">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap" type="com.management.platform.entity.DepartmentWx">
+        <id column="id" property="id" />
+        <result column="wx_deptid" property="wxDeptid" />
+        <result column="wx_parentid" property="wxParentid" />
+        <result column="corpid" property="corpid" />
+        <result column="name" property="name" />
+        <result column="sys_deptid" property="sysDeptid" />
+    </resultMap>
+
+    <!-- 通用查询结果列 -->
+    <sql id="Base_Column_List">
+        id, wx_deptid, wx_parentid, corpid, name, sys_deptid
+    </sql>
+
+</mapper>