|
@@ -1305,72 +1305,6 @@ public class WeiXinCorpController {
|
|
|
return userlist;
|
|
|
}
|
|
|
|
|
|
- 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);
|
|
|
- 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);
|
|
|
- log.info("部门列表:"+result);
|
|
|
- JSONObject obj = JSONObject.parseObject(result);
|
|
|
-
|
|
|
- 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);
|
|
@@ -1437,54 +1371,6 @@ public class WeiXinCorpController {
|
|
|
return SUITE_ACCESS_TOKEN;
|
|
|
}
|
|
|
|
|
|
- @RequestMapping(value = "/bindCorpWeiXin")
|
|
|
- public ModelAndView bindCorpWeiXin(String code, String userId, Integer state) {
|
|
|
- Map<String,Object> reqParam = new HashMap<String,Object>(16);
|
|
|
- String userAgent = request.getHeader("User-Agent");
|
|
|
- //获取设备类型
|
|
|
- String deviceType = UserAgentUtils.getDeviceType(userAgent);
|
|
|
- boolean isMobile = "MOBILE".equals(deviceType);
|
|
|
- String redirecUrl = null;
|
|
|
- if (isMobile) {
|
|
|
- redirecUrl = "http://mobworktime.ttkuaiban.com";
|
|
|
- } else {
|
|
|
- redirecUrl = "http://worktime.ttkuaiban.com";
|
|
|
- }
|
|
|
- User curUser = userMapper.selectById(userId);
|
|
|
- //https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?access_token=ACCESS_TOKEN&code=CODE
|
|
|
- if (curUser == null) {
|
|
|
- //msg.setError("该用户不存在,请退出重新登录");
|
|
|
- System.out.println("该用户不存在,请退出重新登录");
|
|
|
- reqParam.put("errorMsg",MessageUtils.message("user.notExists"));
|
|
|
- } else {
|
|
|
- String url = null;
|
|
|
- try {
|
|
|
- url = GET_CORP_USERINFO_URL.replace("SUITE_ACCESS_TOKEN", getSuiteAccessToken()).replace("CODE", code);
|
|
|
- String forObject = this.restTemplate.getForObject(url, String.class);
|
|
|
- JSONObject obj = JSONObject.parseObject(forObject);
|
|
|
- System.out.println("获取授权的用户身份信息:"+obj.toString());
|
|
|
- String wxUserId = obj.getString("open_userid");
|
|
|
- String realUserId = obj.getString("UserId");
|
|
|
- if (userId == null) {
|
|
|
- //msg.setError("该用户企业未授权");
|
|
|
- System.out.println("该用户企业未授权");
|
|
|
- reqParam.put("errorMsg",MessageUtils.message("access.grant"));
|
|
|
- } else {
|
|
|
- curUser.setCorpwxRealUserid(realUserId);
|
|
|
- curUser.setCorpwxUserid(wxUserId);
|
|
|
- userMapper.updateById(curUser);
|
|
|
- }
|
|
|
- } catch (Exception exception) {
|
|
|
- exception.printStackTrace();
|
|
|
- reqParam.put("errorMsg",exception.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- ModelAndView modelAndView = new ModelAndView(
|
|
|
- new RedirectView(redirecUrl), reqParam);
|
|
|
-
|
|
|
- return modelAndView;
|
|
|
- }
|
|
|
|
|
|
//企业微信用户登录
|
|
|
@RequestMapping(value = "/corpWeiXinLogin", method = RequestMethod.GET)
|
|
@@ -1706,141 +1592,6 @@ public class WeiXinCorpController {
|
|
|
return msg;
|
|
|
}
|
|
|
|
|
|
- @RequestMapping("/syncMembByCardTime")
|
|
|
- public HttpRespMsg syncMembByCardTime(Integer companyId) {
|
|
|
- WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", companyId));
|
|
|
- Company company = companyMapper.selectOne(new QueryWrapper<Company>().eq("id", companyId));
|
|
|
- Integer employeeCnt = userMapper.selectCount(new QueryWrapper<User>().eq("company_id", companyId).eq("is_active",1));
|
|
|
- if (employeeCnt > company.getStaffCountMax()){
|
|
|
- HttpRespMsg msg = new HttpRespMsg();
|
|
|
- //公司人员已达上限,请联系客服提高人数上限。
|
|
|
- msg.setError(MessageUtils.message("wx.employeeFull"));
|
|
|
- return msg;
|
|
|
- }
|
|
|
- if (wxCorpInfo == null) {
|
|
|
- HttpRespMsg msg = new HttpRespMsg();
|
|
|
- //msg.setError("仅企业微信用户支持该操作");
|
|
|
- msg.setError(MessageUtils.message("wx.noWXUser"));
|
|
|
- return msg;
|
|
|
- }
|
|
|
- String curCorpAccessToken = null;
|
|
|
- try {
|
|
|
- curCorpAccessToken = getCorpAccessToken(wxCorpInfo);
|
|
|
- } catch (Exception exception) {
|
|
|
- exception.printStackTrace();
|
|
|
- }
|
|
|
- if (wxCorpInfo.getAuthMode() == 0) {
|
|
|
- //修正: 获取企业的人员授权范围
|
|
|
- JSONArray allowUserList = null;
|
|
|
- JSONArray allowPartyList = null;
|
|
|
- try {
|
|
|
- String url = GET_AUTH_INFO.replaceAll("SUITE_ACCESS_TOKEN", getSuiteAccessToken());
|
|
|
- JSONObject map = new JSONObject();
|
|
|
- map.put("auth_corpid",wxCorpInfo.getCorpid());
|
|
|
- map.put("permanent_code",wxCorpInfo.getPermanentCode());
|
|
|
- HttpHeaders headers = new HttpHeaders();
|
|
|
- headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
- HttpEntity<JSONObject> detailEntity = new HttpEntity<>(map, headers);
|
|
|
- ResponseEntity<String> detailResponseEntity = restTemplate.postForEntity(url, detailEntity, String.class);
|
|
|
- JSONObject json = JSONObject.parseObject(detailResponseEntity.getBody());
|
|
|
- System.out.println("获取企业授权返回:"+json.toJSONString());
|
|
|
- if (json.containsKey("auth_corp_info")){
|
|
|
- JSONArray jsonArray = json.getJSONObject("auth_info").getJSONArray("agent");
|
|
|
- for (int i=0;i<jsonArray.size(); i++) {
|
|
|
- JSONObject jsonObject = jsonArray.getJSONObject(i);
|
|
|
-// if (jsonObject.getString("name").equals("工时管家")) {
|
|
|
-// System.out.println(jsonObject);
|
|
|
- JSONObject privilege = jsonObject.getJSONObject("privilege");
|
|
|
- allowUserList = privilege.getJSONArray("allow_user");
|
|
|
- allowPartyList = privilege.getJSONArray("allow_party");
|
|
|
-// break;
|
|
|
-// }
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception exception) {
|
|
|
- exception.printStackTrace();
|
|
|
- }
|
|
|
- //管理员授权模式下,获取部门人员
|
|
|
- SysRole defaultRole = sysRoleMapper.selectOne(
|
|
|
- new QueryWrapper<SysRole>().eq("company_id", companyId).eq("is_default", 1));
|
|
|
- //单独授权的人员,获取人员详情进行处理
|
|
|
- for (int i=0;i<allowUserList.size(); i++) {
|
|
|
- String allowUserId = allowUserList.getString(i);
|
|
|
- JSONObject userJson = getUserInfo(curCorpAccessToken, allowUserId);
|
|
|
- String curUserid = userJson.getString("userid");
|
|
|
- String openUserid = userJson.getString("open_userid");
|
|
|
- //跳过非激活状态的员工
|
|
|
- if (userJson.getInteger("status") != 1) continue;
|
|
|
- //不存在的人员, 进行插入
|
|
|
- User user = new User();
|
|
|
- JSONArray userDeptArray = userJson.getJSONArray("department");
|
|
|
- //取最末级的,也就是最大的deptId
|
|
|
- int maxDeptId = 1;
|
|
|
- for (int m=0;m<userDeptArray.size(); m++) {
|
|
|
- int curId = userDeptArray.getInteger(m);
|
|
|
- if (curId > maxDeptId) maxDeptId = curId;
|
|
|
- }
|
|
|
- System.out.println("userid="+curUserid+", name=" + userJson.getString("name")+", mobile="+userJson.getString("mobile"));
|
|
|
- //不存在的人员, 进行插入
|
|
|
- user.setId(SnowFlake.nextId()+"")
|
|
|
- .setRoleId(defaultRole.getId())//默认组员
|
|
|
- .setRoleName(defaultRole.getRolename())
|
|
|
- .setCompanyId(companyId)
|
|
|
- .setName(userJson.getString("name"))
|
|
|
- .setCorpwxUserid(curUserid)
|
|
|
- .setColor(ColorUtil.randomColor())
|
|
|
- .setInductionDate(LocalDate.now());
|
|
|
- //检查用户是否已经存在
|
|
|
- if (userMapper.selectCount(new QueryWrapper<User>().eq("corpwx_userid", curUserid)) == 0) {
|
|
|
- userMapper.insert(user);
|
|
|
- System.out.println("新用户==="+user.getName());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //获取部门
|
|
|
- JSONObject deptObj = getAllDepartments(curCorpAccessToken);
|
|
|
- JSONArray deptObjJSONArray = deptObj.getJSONArray("department");
|
|
|
- for (int i=0;i<deptObjJSONArray.size(); i++) {
|
|
|
- int deptId = deptObjJSONArray.getJSONObject(i).getIntValue("id");
|
|
|
-
|
|
|
- JSONArray userList = getDeptUserSimple(curCorpAccessToken, deptId);
|
|
|
- System.out.println("该部门下用户数量:"+userList.size());
|
|
|
- for (int m=0;m<userList.size(); m++) {
|
|
|
- JSONObject userJson = userList.getJSONObject(m);
|
|
|
- String curUserid = userJson.getString("userid");
|
|
|
- System.out.println("userid="+curUserid+", name=" + userJson.getString("name")+", mobile="+userJson.getString("mobile"));
|
|
|
- //不存在的人员, 进行插入
|
|
|
- User user = new User();
|
|
|
-
|
|
|
- user.setId(SnowFlake.nextId()+"")
|
|
|
- .setRoleId(defaultRole.getId())//默认组员
|
|
|
- .setRoleName(defaultRole.getRolename())
|
|
|
- .setCompanyId(companyId)
|
|
|
- .setDepartmentId(0)
|
|
|
- .setName(userJson.getString("name"))
|
|
|
- .setCorpwxUserid(curUserid)
|
|
|
- .setColor(ColorUtil.randomColor());
|
|
|
-
|
|
|
- //检查用户是否已经存在
|
|
|
- if (userMapper.selectCount(new QueryWrapper<User>().eq("corpwx_userid", curUserid).eq("company_id", companyId)) == 0) {
|
|
|
- userMapper.insert(user);
|
|
|
- } else {
|
|
|
- User curUser = userMapper.selectOne(new QueryWrapper<User>().eq("corpwx_userid", curUserid).eq("company_id", companyId));
|
|
|
- System.out.println("找到用户:"+curUser.getName());
|
|
|
- if (curUser.getDepartmentId() != null) {
|
|
|
- Department dept = departmentMapper.selectById(curUser.getDepartmentId());
|
|
|
- if (dept != null) {
|
|
|
- System.out.println("部门:"+dept.getDepartmentName());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return wxCorpInfoService.syncMembByCardTime(wxCorpInfo);
|
|
|
- }
|
|
|
-
|
|
|
//改造老版的接口,从平台获取客户通讯录
|
|
|
@RequestMapping("/getCorpMembsFromPlatform")
|
|
|
public HttpRespMsg getCorpMembsFromPlatform(Integer companyId) {
|
|
@@ -2346,6 +2097,213 @@ public class WeiXinCorpController {
|
|
|
}
|
|
|
return view;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 同步企业内部应用的通讯录组织架构
|
|
|
+ * @param companyId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping("/syncInsideCorpMembs")
|
|
|
+ public HttpRespMsg syncInsideCorpMembs(Integer companyId) {
|
|
|
+ Company company = companyMapper.selectById(companyId);
|
|
|
+ WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", companyId));
|
|
|
+ String corpid = wxCorpInfo.getCorpid();
|
|
|
+ if (wxCorpInfo != null) {
|
|
|
+ Integer employeeCnt = userMapper.selectCount(new QueryWrapper<User>().eq("company_id", companyId).eq("is_active",1));
|
|
|
+ if (employeeCnt > company.getStaffCountMax()){
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ //公司人员已达上限,请联系客服提高人数上限。
|
|
|
+ msg.setError(MessageUtils.message("wx.employeeFull"));
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ if (wxCorpInfo == null) {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ //msg.setError("仅企业微信用户支持该操作");
|
|
|
+ msg.setError(MessageUtils.message("wx.noWXUser"));
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ String accessToken = null;
|
|
|
+ try {
|
|
|
+ accessToken = wxCorpInfoService.getCorpAgentAccessToken(wxCorpInfo);
|
|
|
+ //获取组织架构 同步部门
|
|
|
+ String departmentInfoResp = wxCorpInfoService.getDepartmentInfoWithApplication(accessToken);
|
|
|
+ JSONObject departmentInfoOb = JSONObject.parseObject(departmentInfoResp);
|
|
|
+ JSONArray departmentInfoArrays = departmentInfoOb.getJSONArray("department");
|
|
|
+ System.out.println(departmentInfoOb.toJSONString());
|
|
|
+ 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");
|
|
|
+ int status = userJson.getIntValue("status");
|
|
|
+ if(status!=1){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ 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)
|
|
|
+ .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();
|
|
|
+ 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.getCorpwxUserid()!=null&&ul.getCorpwxUserid().equals(user.getCorpwxUserid()));
|
|
|
+ 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");
|
|
|
+ int status = object.getIntValue("status");
|
|
|
+ if(status!=1){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ 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(corpWxuserid)
|
|
|
+ .setName(userName)
|
|
|
+ .setRoleName(role.getRolename())
|
|
|
+ .setRoleId(role.getId())
|
|
|
+// .setPhone(phone)
|
|
|
+ .setCorpwxRealUserid(corpWxuserid)
|
|
|
+ .setColor(ColorUtil.randomColor())
|
|
|
+ .setPassword(MD5Util.getPassword("000000"))
|
|
|
+ .setJobNumber(corpWxuserid);
|
|
|
+ boolean b = userList.stream().anyMatch(ul -> ul.getCorpwxUserid().equals(user.getCorpwxUserid()));
|
|
|
+ if(!b){
|
|
|
+ userList.add(user);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new Exception(json.toJSONString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ System.out.println("resutlList========="+userList);
|
|
|
+ userService.saveBatch(userList);
|
|
|
+ employeeCnt = userMapper.selectCount(new QueryWrapper<User>().eq("company_id", companyId).eq("is_active",1));
|
|
|
+ ContactSyncLog contactSyncLog = new ContactSyncLog();
|
|
|
+ contactSyncLog.setCompanyId(companyId);
|
|
|
+ if (employeeCnt > company.getStaffCountMax()){
|
|
|
+ contactSyncLog.setResult(0);
|
|
|
+ //contactSyncLog.setMsg("公司人员已达上限,请联系客服提高人数上限。");
|
|
|
+ contactSyncLog.setMsg(MessageUtils.message("wx.employeeFull"));
|
|
|
+ contactSyncLogMapper.insert(contactSyncLog);
|
|
|
+ }else {
|
|
|
+ contactSyncLog.setResult(1);
|
|
|
+ //contactSyncLog.setMsg("同步成功");
|
|
|
+ contactSyncLog.setMsg(MessageUtils.message("wx.synSuccess"));
|
|
|
+ contactSyncLogMapper.insert(contactSyncLog);
|
|
|
+ }
|
|
|
+ } catch (Exception exception) {
|
|
|
+ exception.printStackTrace();
|
|
|
+ }
|
|
|
+ return new HttpRespMsg();
|
|
|
+ } else {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ msg.setError("该企业不存在");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 初始化内部应用的系统数据
|
|
|
* @return
|
|
@@ -2393,7 +2351,7 @@ public class WeiXinCorpController {
|
|
|
// String accessToken = getCorpConcactAccessToken(wxCorpInfo);
|
|
|
String accessToken = wxCorpInfoService.getCorpAgentAccessToken(wxCorpInfo);
|
|
|
//获取组织架构 同步部门
|
|
|
- String departmentInfoResp=wxCorpInfoService.getDepartmentInfoWithApplication(accessToken);
|
|
|
+ String departmentInfoResp = wxCorpInfoService.getDepartmentInfoWithApplication(accessToken);
|
|
|
JSONObject departmentInfoOb = JSONObject.parseObject(departmentInfoResp);
|
|
|
JSONArray departmentInfoArrays = departmentInfoOb.getJSONArray("department");
|
|
|
System.out.println(departmentInfoOb.toJSONString());
|