|
@@ -3,6 +3,10 @@ package com.management.platform.controller;
|
|
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.QueryWrapper;
|
|
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.google.gson.JsonObject;
|
|
import com.management.platform.constant.Constant;
|
|
import com.management.platform.constant.Constant;
|
|
import com.management.platform.entity.*;
|
|
import com.management.platform.entity.*;
|
|
@@ -16,6 +20,7 @@ import com.management.platform.service.impl.UserServiceImpl;
|
|
import com.management.platform.util.*;
|
|
import com.management.platform.util.*;
|
|
import com.qq.weixin.mp.aes.AesException;
|
|
import com.qq.weixin.mp.aes.AesException;
|
|
import com.qq.weixin.mp.aes.WXBizMsgCrypt;
|
|
import com.qq.weixin.mp.aes.WXBizMsgCrypt;
|
|
|
|
+import com.taobao.api.ApiException;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.ibatis.annotations.Select;
|
|
import org.apache.ibatis.annotations.Select;
|
|
import org.json.XML;
|
|
import org.json.XML;
|
|
@@ -37,6 +42,9 @@ import java.sql.Timestamp;
|
|
import java.time.*;
|
|
import java.time.*;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.util.*;
|
|
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.Collectors;
|
|
import java.util.stream.Stream;
|
|
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_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_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}")
|
|
@Value("${suitId}")
|
|
private String suitId;
|
|
private String suitId;
|
|
@Value("${suitSecret}")
|
|
@Value("${suitSecret}")
|
|
private String suitSecret;
|
|
private String suitSecret;
|
|
@Value("${providerSecret}")
|
|
@Value("${providerSecret}")
|
|
private String providerSecret;
|
|
private String providerSecret;
|
|
|
|
+ @Value("${configEnv.isPrivateDeploy}")
|
|
|
|
+ private boolean isPrivateDeploy;//企业内部应用,私有化部署的情况
|
|
|
|
|
|
//自己公司的企业微信通讯录secret
|
|
//自己公司的企业微信通讯录secret
|
|
private String concactSecret="irf7s8fy16wLhWGb8IxvGL2Nkm0sTB6dludpe_3VP6k";
|
|
private String concactSecret="irf7s8fy16wLhWGb8IxvGL2Nkm0sTB6dludpe_3VP6k";
|
|
@@ -121,6 +134,8 @@ public class WeiXinCorpController {
|
|
private SysRoleModuleService sysRoleModuleService;
|
|
private SysRoleModuleService sysRoleModuleService;
|
|
@Resource
|
|
@Resource
|
|
private SysRoleFunctionService sysRoleFunctionService;
|
|
private SysRoleFunctionService sysRoleFunctionService;
|
|
|
|
+ @Resource
|
|
|
|
+ private UserService userService;
|
|
@Autowired
|
|
@Autowired
|
|
RestTemplate restTemplate;
|
|
RestTemplate restTemplate;
|
|
@Resource
|
|
@Resource
|
|
@@ -143,6 +158,8 @@ public class WeiXinCorpController {
|
|
private WxOrderMapper wxOrderMapper;
|
|
private WxOrderMapper wxOrderMapper;
|
|
@Resource
|
|
@Resource
|
|
private ContactSyncLogMapper contactSyncLogMapper;
|
|
private ContactSyncLogMapper contactSyncLogMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private DepartmentWxMapper departmentWxMapper;
|
|
|
|
|
|
public static String SUITE_ACCESS_TOKEN = null;
|
|
public static String SUITE_ACCESS_TOKEN = null;
|
|
public static long suiteTokenExpireTime = 0L;
|
|
public static long suiteTokenExpireTime = 0L;
|
|
@@ -179,8 +196,6 @@ public class WeiXinCorpController {
|
|
@Resource
|
|
@Resource
|
|
DepartmentService departmentService;
|
|
DepartmentService departmentService;
|
|
@Resource
|
|
@Resource
|
|
- UserService userService;
|
|
|
|
- @Resource
|
|
|
|
CorpwxJobResultMapper corpwxJobResultMapper;
|
|
CorpwxJobResultMapper corpwxJobResultMapper;
|
|
@Resource
|
|
@Resource
|
|
private AuditWorkflowTimeSettingMapper auditWorkflowTimeSettingMapper;
|
|
private AuditWorkflowTimeSettingMapper auditWorkflowTimeSettingMapper;
|
|
@@ -3268,8 +3283,6 @@ public class WeiXinCorpController {
|
|
}
|
|
}
|
|
companyMapper.updateById(newCompany);
|
|
companyMapper.updateById(newCompany);
|
|
System.out.println("已成功变更版本,版本号为:"+edition_id);
|
|
System.out.println("已成功变更版本,版本号为:"+edition_id);
|
|
- //开通模块和权限
|
|
|
|
- rootRole(wxCorpInfo.getCompanyId());
|
|
|
|
}else {
|
|
}else {
|
|
System.out.println("++++++++++++++++++++++"+"版本变更失败!"+"++++++++++++++++++++++++");
|
|
System.out.println("++++++++++++++++++++++"+"版本变更失败!"+"++++++++++++++++++++++++");
|
|
}
|
|
}
|
|
@@ -3289,6 +3302,210 @@ public class WeiXinCorpController {
|
|
}
|
|
}
|
|
return view;
|
|
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){
|
|
private void rootRole (Integer companyId){
|