Merge branch 'noPermission' of e.coding.net:tsteam/cm-cloud/cm-cloud into noPermission
This commit is contained in:
commit
469d237bd3
@ -38,9 +38,4 @@ public class DemoController {
|
||||
return dingDingMessageService.send(phone, "测试");
|
||||
}
|
||||
|
||||
@GetMapping("list")
|
||||
public JSONObject list() throws ApiException {
|
||||
return dingDingAppDepartmentService.list();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,57 @@
|
||||
package com.cm.common.dingding.pojo.bos;
|
||||
|
||||
/**
|
||||
* @ClassName: DingDingDepartmentBO
|
||||
* @Description: 钉钉部门
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/8/4 10:31 下午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class DingDingDepartmentBO {
|
||||
|
||||
private Long deptId;
|
||||
private String name;
|
||||
private String parentId;
|
||||
private String createDeptGroup;
|
||||
private String autoAddUser;
|
||||
|
||||
public Long getDeptId() {
|
||||
return deptId == null ? 0 : deptId;
|
||||
}
|
||||
|
||||
public void setDeptId(Long deptId) {
|
||||
this.deptId = deptId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name == null ? "" : name.trim();
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getParentId() {
|
||||
return parentId == null ? "" : parentId.trim();
|
||||
}
|
||||
|
||||
public void setParentId(String parentId) {
|
||||
this.parentId = parentId;
|
||||
}
|
||||
|
||||
public String getCreateDeptGroup() {
|
||||
return createDeptGroup == null ? "" : createDeptGroup.trim();
|
||||
}
|
||||
|
||||
public void setCreateDeptGroup(String createDeptGroup) {
|
||||
this.createDeptGroup = createDeptGroup;
|
||||
}
|
||||
|
||||
public String getAutoAddUser() {
|
||||
return autoAddUser == null ? "" : autoAddUser.trim();
|
||||
}
|
||||
|
||||
public void setAutoAddUser(String autoAddUser) {
|
||||
this.autoAddUser = autoAddUser;
|
||||
}
|
||||
}
|
@ -0,0 +1,185 @@
|
||||
package com.cm.common.dingding.pojo.bos;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @ClassName: DingDingUserBO
|
||||
* @Description: 钉钉用户
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/8/5 10:27 上午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class DingDingUserBO {
|
||||
|
||||
private String userid;
|
||||
private Long order;
|
||||
private String unionid;
|
||||
private String mobile;
|
||||
private String tel;
|
||||
private String workPlace;
|
||||
private String remark;
|
||||
private Boolean isAdmin;
|
||||
private Boolean isBoss;
|
||||
private Boolean isHide;
|
||||
private Boolean isLeader;
|
||||
private String name;
|
||||
private Boolean isActive;
|
||||
private Long[] department;
|
||||
private String position;
|
||||
private String email;
|
||||
private String avatar;
|
||||
private String jobnumber;
|
||||
private Date hiredDate;
|
||||
|
||||
public String getUserid() {
|
||||
return userid == null ? "" : userid.trim();
|
||||
}
|
||||
|
||||
public void setUserid(String userid) {
|
||||
this.userid = userid;
|
||||
}
|
||||
|
||||
public Long getOrder() {
|
||||
return order == null ? 0 : order;
|
||||
}
|
||||
|
||||
public void setOrder(Long order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public String getUnionid() {
|
||||
return unionid == null ? "" : unionid.trim();
|
||||
}
|
||||
|
||||
public void setUnionid(String unionid) {
|
||||
this.unionid = unionid;
|
||||
}
|
||||
|
||||
public String getMobile() {
|
||||
return mobile == null ? "" : mobile.trim();
|
||||
}
|
||||
|
||||
public void setMobile(String mobile) {
|
||||
this.mobile = mobile;
|
||||
}
|
||||
|
||||
public String getTel() {
|
||||
return tel == null ? "" : tel.trim();
|
||||
}
|
||||
|
||||
public void setTel(String tel) {
|
||||
this.tel = tel;
|
||||
}
|
||||
|
||||
public String getWorkPlace() {
|
||||
return workPlace == null ? "" : workPlace.trim();
|
||||
}
|
||||
|
||||
public void setWorkPlace(String workPlace) {
|
||||
this.workPlace = workPlace;
|
||||
}
|
||||
|
||||
public String getRemark() {
|
||||
return remark == null ? "" : remark.trim();
|
||||
}
|
||||
|
||||
public void setRemark(String remark) {
|
||||
this.remark = remark;
|
||||
}
|
||||
|
||||
public Boolean getAdmin() {
|
||||
return isAdmin;
|
||||
}
|
||||
|
||||
public void setAdmin(Boolean admin) {
|
||||
isAdmin = admin;
|
||||
}
|
||||
|
||||
public Boolean getBoss() {
|
||||
return isBoss;
|
||||
}
|
||||
|
||||
public void setBoss(Boolean boss) {
|
||||
isBoss = boss;
|
||||
}
|
||||
|
||||
public Boolean getHide() {
|
||||
return isHide;
|
||||
}
|
||||
|
||||
public void setHide(Boolean hide) {
|
||||
isHide = hide;
|
||||
}
|
||||
|
||||
public Boolean getLeader() {
|
||||
return isLeader;
|
||||
}
|
||||
|
||||
public void setLeader(Boolean leader) {
|
||||
isLeader = leader;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name == null ? "" : name.trim();
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Boolean getActive() {
|
||||
return isActive;
|
||||
}
|
||||
|
||||
public void setActive(Boolean active) {
|
||||
isActive = active;
|
||||
}
|
||||
|
||||
public Long[] getDepartment() {
|
||||
return department;
|
||||
}
|
||||
|
||||
public void setDepartment(Long[] department) {
|
||||
this.department = department;
|
||||
}
|
||||
|
||||
public String getPosition() {
|
||||
return position == null ? "" : position.trim();
|
||||
}
|
||||
|
||||
public void setPosition(String position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email == null ? "" : email.trim();
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getAvatar() {
|
||||
return avatar == null ? "" : avatar.trim();
|
||||
}
|
||||
|
||||
public void setAvatar(String avatar) {
|
||||
this.avatar = avatar;
|
||||
}
|
||||
|
||||
public String getJobnumber() {
|
||||
return jobnumber == null ? "" : jobnumber.trim();
|
||||
}
|
||||
|
||||
public void setJobnumber(String jobnumber) {
|
||||
this.jobnumber = jobnumber;
|
||||
}
|
||||
|
||||
public Date getHiredDate() {
|
||||
return hiredDate;
|
||||
}
|
||||
|
||||
public void setHiredDate(Date hiredDate) {
|
||||
this.hiredDate = hiredDate;
|
||||
}
|
||||
}
|
@ -1,8 +1,11 @@
|
||||
package com.cm.common.dingding.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.dingtalk.api.response.OapiV2DepartmentListsubResponse;
|
||||
import com.taobao.api.ApiException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName: IDingDingAppDepartmentService
|
||||
* @Description: 钉钉部门
|
||||
@ -12,6 +15,11 @@ import com.taobao.api.ApiException;
|
||||
*/
|
||||
public interface IDingDingAppDepartmentService {
|
||||
|
||||
JSONObject list() throws ApiException;
|
||||
/**
|
||||
* 部门全部列表,无层级
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
List<OapiV2DepartmentListsubResponse.DeptBaseResponse> listAll() throws ApiException;
|
||||
|
||||
}
|
||||
|
@ -2,6 +2,10 @@ package com.cm.common.dingding.service;
|
||||
|
||||
import com.cm.common.exception.SearchException;
|
||||
import com.dingtalk.api.response.OapiUserGetResponse;
|
||||
import com.dingtalk.api.response.OapiV2UserListResponse;
|
||||
import com.taobao.api.ApiException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
@ -41,4 +45,20 @@ public interface IDingDingAppUserService {
|
||||
*/
|
||||
String getUserIdByPhone(String phone);
|
||||
|
||||
/**
|
||||
* 部门用户列表
|
||||
*
|
||||
* @param deptId
|
||||
* @return
|
||||
*/
|
||||
List<OapiV2UserListResponse.ListUserResponse> listByDeptId(Long deptId) throws ApiException;
|
||||
|
||||
/**
|
||||
* 部门用户列表
|
||||
*
|
||||
* @param deptIds
|
||||
* @return
|
||||
*/
|
||||
List<OapiV2UserListResponse.ListUserResponse> listByDeptIds(List<Long> deptIds) throws ApiException;
|
||||
|
||||
}
|
||||
|
@ -7,11 +7,16 @@ import com.cm.common.dingding.manager.app.DingDingAppManager;
|
||||
import com.cm.common.dingding.service.IDingDingAppDepartmentService;
|
||||
import com.dingtalk.api.DefaultDingTalkClient;
|
||||
import com.dingtalk.api.DingTalkClient;
|
||||
import com.dingtalk.api.request.OapiUserSimplelistRequest;
|
||||
import com.dingtalk.api.request.OapiV2DepartmentListsubRequest;
|
||||
import com.dingtalk.api.response.OapiUserSimplelistResponse;
|
||||
import com.dingtalk.api.response.OapiV2DepartmentListsubResponse;
|
||||
import com.taobao.api.ApiException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName: DingDingAppDepartmentServiceImpl
|
||||
* @Description: 钉钉部门管理,需要开放钉钉应用:权限管理 -> 通讯录管理 -> 通讯录部门信息读权限
|
||||
@ -21,14 +26,27 @@ import org.springframework.stereotype.Service;
|
||||
*/
|
||||
@Service
|
||||
public class DingDingAppDepartmentServiceImpl extends AbstractService implements IDingDingAppDepartmentService {
|
||||
|
||||
@Override
|
||||
public JSONObject list() throws ApiException {
|
||||
public List<OapiV2DepartmentListsubResponse.DeptBaseResponse> listAll() throws ApiException {
|
||||
List<OapiV2DepartmentListsubResponse.DeptBaseResponse> deptBaseResponses = new ArrayList<>();
|
||||
buildDeptList(1L, deptBaseResponses);
|
||||
return deptBaseResponses;
|
||||
}
|
||||
|
||||
private void buildDeptList(Long parentDeptId, List<OapiV2DepartmentListsubResponse.DeptBaseResponse> deptBaseResponses) throws ApiException {
|
||||
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/listsub");
|
||||
OapiV2DepartmentListsubRequest oapiV2DepartmentListsubRequest = new OapiV2DepartmentListsubRequest();
|
||||
oapiV2DepartmentListsubRequest.setDeptId(1L);
|
||||
oapiV2DepartmentListsubRequest.setDeptId(parentDeptId);
|
||||
oapiV2DepartmentListsubRequest.setLanguage("zh_CN");
|
||||
OapiV2DepartmentListsubResponse rsp = client.execute(oapiV2DepartmentListsubRequest, DingDingAppManager.getInstance().getAccessToken());
|
||||
System.out.println(rsp.getBody());
|
||||
return JSON.parseObject(rsp.getBody());
|
||||
List<OapiV2DepartmentListsubResponse.DeptBaseResponse> subDepts = rsp.getResult();
|
||||
if (!subDepts.isEmpty()) {
|
||||
for (OapiV2DepartmentListsubResponse.DeptBaseResponse subDept : subDepts) {
|
||||
deptBaseResponses.add(subDept);
|
||||
buildDeptList(subDept.getDeptId(), deptBaseResponses);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,13 +10,18 @@ import com.dingtalk.api.DingTalkClient;
|
||||
import com.dingtalk.api.request.OapiUserGetByMobileRequest;
|
||||
import com.dingtalk.api.request.OapiUserGetRequest;
|
||||
import com.dingtalk.api.request.OapiUserGetUseridByUnionidRequest;
|
||||
import com.dingtalk.api.request.OapiV2UserListRequest;
|
||||
import com.dingtalk.api.response.OapiUserGetByMobileResponse;
|
||||
import com.dingtalk.api.response.OapiUserGetResponse;
|
||||
import com.dingtalk.api.response.OapiUserGetUseridByUnionidResponse;
|
||||
import com.dingtalk.api.response.OapiV2UserListResponse;
|
||||
import com.taobao.api.ApiException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* When you feel like quitting. Think about why you started
|
||||
* 当你想要放弃的时候,想想当初你为何开始
|
||||
@ -86,4 +91,40 @@ public class DingDingAppUserServiceImpl extends AbstractService implements IDing
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OapiV2UserListResponse.ListUserResponse> listByDeptId(Long deptId) throws ApiException {
|
||||
List<OapiV2UserListResponse.ListUserResponse> userResponses = new ArrayList<>();
|
||||
buildUserList(deptId, 0L, userResponses);
|
||||
return userResponses;
|
||||
}
|
||||
|
||||
private void buildUserList(Long deptId, Long cursor, List<OapiV2UserListResponse.ListUserResponse> userResponses) throws ApiException {
|
||||
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/list");
|
||||
OapiV2UserListRequest req = new OapiV2UserListRequest();
|
||||
req.setDeptId(deptId);
|
||||
req.setCursor(cursor);
|
||||
req.setSize(1000L);
|
||||
req.setContainAccessLimit(true);
|
||||
req.setLanguage("zh_CN");
|
||||
OapiV2UserListResponse oapiV2UserListResponse = client.execute(req, DingDingAppManager.getInstance().getAccessToken());
|
||||
OapiV2UserListResponse.PageResult result = oapiV2UserListResponse.getResult();
|
||||
List<OapiV2UserListResponse.ListUserResponse> listUserResponses = result.getList();
|
||||
if (result.getHasMore()) {
|
||||
buildUserList(deptId, result.getNextCursor(), userResponses);
|
||||
}
|
||||
userResponses.addAll(listUserResponses);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OapiV2UserListResponse.ListUserResponse> listByDeptIds(List<Long> deptIds) throws ApiException {
|
||||
if (deptIds.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<OapiV2UserListResponse.ListUserResponse> userResponses = new ArrayList<>();
|
||||
for (Long deptId : deptIds) {
|
||||
userResponses.addAll(listByDeptId(deptId));
|
||||
}
|
||||
return userResponses;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,33 @@
|
||||
package com.cm.common.plugin.oauth.service.group;
|
||||
|
||||
import com.cm.common.plugin.pojo.bos.UserResourceBO;
|
||||
import com.cm.common.pojo.bos.GroupBO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName: IGroupService
|
||||
* @Description: 用户组
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/8/11 2:55 下午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public interface IGroupService {
|
||||
|
||||
/**
|
||||
* 组列表
|
||||
*
|
||||
* @param parentGroupId 上级ID
|
||||
* @return
|
||||
*/
|
||||
List<GroupBO> list(String parentGroupId);
|
||||
|
||||
/**
|
||||
* 组用户列表
|
||||
*
|
||||
* @param groupId
|
||||
* @return
|
||||
*/
|
||||
List<UserResourceBO> listUser(String groupId);
|
||||
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package com.cm.common.plugin.oauth.service.group.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.cm.common.base.AbstractService;
|
||||
import com.cm.common.config.properties.ApiPathProperties;
|
||||
import com.cm.common.plugin.IApiConsts;
|
||||
import com.cm.common.plugin.oauth.service.group.IGroupService;
|
||||
import com.cm.common.plugin.oauth.token.ClientTokenManager;
|
||||
import com.cm.common.plugin.pojo.bos.UserResourceBO;
|
||||
import com.cm.common.plugin.utils.RestTemplateUtil;
|
||||
import com.cm.common.pojo.bos.GroupBO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @ClassName: GroupServiceImpl
|
||||
* @Description: 用户组
|
||||
* @Author: wanggeng
|
||||
* @Date: 2021/8/11 2:55 下午
|
||||
* @Version: 1.0
|
||||
*/
|
||||
@Service
|
||||
public class GroupServiceImpl extends AbstractService implements IGroupService {
|
||||
|
||||
@Autowired
|
||||
private RestTemplateUtil restTemplateUtil;
|
||||
@Autowired
|
||||
private ApiPathProperties apiPathProperties;
|
||||
|
||||
|
||||
@Override
|
||||
public List<GroupBO> list(String parentGroupId) {
|
||||
Map<String, Object> params = new HashMap<>(2);
|
||||
params.put(IApiConsts.ACCESS_TOKEN, ClientTokenManager.getInstance().getClientToken().getAccessToken());
|
||||
String result = restTemplateUtil.doGetFormNormal(String.format("%s/resource/group/list/%s", apiPathProperties.getUserCenter(), parentGroupId), params);
|
||||
searchResourceResult(result, "获取组列表失败");
|
||||
return JSONArray.parseArray(result, GroupBO.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserResourceBO> listUser(String groupId) {
|
||||
Map<String, Object> params = new HashMap<>(2);
|
||||
params.put(IApiConsts.ACCESS_TOKEN, ClientTokenManager.getInstance().getClientToken().getAccessToken());
|
||||
String result = restTemplateUtil.doGetFormNormal(String.format("%s/resource/group/list-user/%s", apiPathProperties.getUserCenter(), groupId), params);
|
||||
searchResourceResult(result, "获取组列表失败");
|
||||
return JSONArray.parseArray(result, UserResourceBO.class);
|
||||
}
|
||||
}
|
@ -2,11 +2,16 @@ package com.cm.common.config;
|
||||
|
||||
import com.cm.common.config.properties.FileProperties;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.web.servlet.MultipartConfigFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import javax.servlet.MultipartConfigElement;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @ClassName: WebConfig
|
||||
* @Description: Web配置
|
||||
@ -30,4 +35,16 @@ public class WebConfig implements WebMvcConfigurer {
|
||||
registry.addResourceHandler("/files/**").addResourceLocations("file:" + fileProperties.getUploadPath());
|
||||
registry.addResourceHandler("/assets/**").addResourceLocations("classpath:/static/assets/").setCachePeriod(7 * 24 * 3600);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MultipartConfigElement multipartConfigElement(){
|
||||
MultipartConfigFactory multipartConfigFactory = new MultipartConfigFactory();
|
||||
String location = System.getProperty("user.dir") + "/data/tmp";
|
||||
File file = new File(location);
|
||||
if(!file.exists()){
|
||||
file.mkdirs();
|
||||
}
|
||||
multipartConfigFactory.setLocation(location);
|
||||
return multipartConfigFactory.createMultipartConfig();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user