From 44128b40c6dfdc1ccf9014807fa5ce856ea76aaf Mon Sep 17 00:00:00 2001 From: wanggeng <450292408@qq.com> Date: Sat, 7 Aug 2021 11:42:36 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=BA=86=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E6=96=87=E4=BB=B6=E4=B8=B4=E6=97=B6=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/cm/common/config/WebConfig.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/cloud-common/src/main/java/com/cm/common/config/WebConfig.java b/cloud-common/src/main/java/com/cm/common/config/WebConfig.java index 8136097..1bda5f4 100644 --- a/cloud-common/src/main/java/com/cm/common/config/WebConfig.java +++ b/cloud-common/src/main/java/com/cm/common/config/WebConfig.java @@ -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(); + } } From 497e295b8d660fa399996651e86553e56c0a20ce Mon Sep 17 00:00:00 2001 From: wanggeng <450292408@qq.com> Date: Wed, 11 Aug 2021 23:15:37 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=92=89=E9=92=89?= =?UTF-8?q?=E9=83=A8=E9=97=A8=E5=88=97=E8=A1=A8=E5=92=8C=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/api/DemoController.java | 5 - .../pojo/bos/DingDingDepartmentBO.java | 57 ++++++ .../dingding/pojo/bos/DingDingUserBO.java | 185 ++++++++++++++++++ .../IDingDingAppDepartmentService.java | 10 +- .../service/IDingDingAppUserService.java | 20 ++ .../DingDingAppDepartmentServiceImpl.java | 26 ++- .../impl/DingDingAppUserServiceImpl.java | 41 ++++ 7 files changed, 334 insertions(+), 10 deletions(-) create mode 100644 cloud-common-dingding/src/main/java/com/cm/common/dingding/pojo/bos/DingDingDepartmentBO.java create mode 100644 cloud-common-dingding/src/main/java/com/cm/common/dingding/pojo/bos/DingDingUserBO.java diff --git a/cloud-common-dingding/src/main/java/com/cm/common/dingding/controller/api/DemoController.java b/cloud-common-dingding/src/main/java/com/cm/common/dingding/controller/api/DemoController.java index d08c105..836c375 100644 --- a/cloud-common-dingding/src/main/java/com/cm/common/dingding/controller/api/DemoController.java +++ b/cloud-common-dingding/src/main/java/com/cm/common/dingding/controller/api/DemoController.java @@ -38,9 +38,4 @@ public class DemoController { return dingDingMessageService.send(phone, "测试"); } - @GetMapping("list") - public JSONObject list() throws ApiException { - return dingDingAppDepartmentService.list(); - } - } diff --git a/cloud-common-dingding/src/main/java/com/cm/common/dingding/pojo/bos/DingDingDepartmentBO.java b/cloud-common-dingding/src/main/java/com/cm/common/dingding/pojo/bos/DingDingDepartmentBO.java new file mode 100644 index 0000000..da356dd --- /dev/null +++ b/cloud-common-dingding/src/main/java/com/cm/common/dingding/pojo/bos/DingDingDepartmentBO.java @@ -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; + } +} diff --git a/cloud-common-dingding/src/main/java/com/cm/common/dingding/pojo/bos/DingDingUserBO.java b/cloud-common-dingding/src/main/java/com/cm/common/dingding/pojo/bos/DingDingUserBO.java new file mode 100644 index 0000000..59c6033 --- /dev/null +++ b/cloud-common-dingding/src/main/java/com/cm/common/dingding/pojo/bos/DingDingUserBO.java @@ -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; + } +} diff --git a/cloud-common-dingding/src/main/java/com/cm/common/dingding/service/IDingDingAppDepartmentService.java b/cloud-common-dingding/src/main/java/com/cm/common/dingding/service/IDingDingAppDepartmentService.java index c7700a2..ab7dbfe 100644 --- a/cloud-common-dingding/src/main/java/com/cm/common/dingding/service/IDingDingAppDepartmentService.java +++ b/cloud-common-dingding/src/main/java/com/cm/common/dingding/service/IDingDingAppDepartmentService.java @@ -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 listAll() throws ApiException; } diff --git a/cloud-common-dingding/src/main/java/com/cm/common/dingding/service/IDingDingAppUserService.java b/cloud-common-dingding/src/main/java/com/cm/common/dingding/service/IDingDingAppUserService.java index b1e6379..3ff9151 100644 --- a/cloud-common-dingding/src/main/java/com/cm/common/dingding/service/IDingDingAppUserService.java +++ b/cloud-common-dingding/src/main/java/com/cm/common/dingding/service/IDingDingAppUserService.java @@ -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 listByDeptId(Long deptId) throws ApiException; + + /** + * 部门用户列表 + * + * @param deptIds + * @return + */ + List listByDeptIds(List deptIds) throws ApiException; + } diff --git a/cloud-common-dingding/src/main/java/com/cm/common/dingding/service/impl/DingDingAppDepartmentServiceImpl.java b/cloud-common-dingding/src/main/java/com/cm/common/dingding/service/impl/DingDingAppDepartmentServiceImpl.java index 4247f81..6b3589b 100644 --- a/cloud-common-dingding/src/main/java/com/cm/common/dingding/service/impl/DingDingAppDepartmentServiceImpl.java +++ b/cloud-common-dingding/src/main/java/com/cm/common/dingding/service/impl/DingDingAppDepartmentServiceImpl.java @@ -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 listAll() throws ApiException { + List deptBaseResponses = new ArrayList<>(); + buildDeptList(1L, deptBaseResponses); + return deptBaseResponses; + } + + private void buildDeptList(Long parentDeptId, List 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 subDepts = rsp.getResult(); + if (!subDepts.isEmpty()) { + for (OapiV2DepartmentListsubResponse.DeptBaseResponse subDept : subDepts) { + deptBaseResponses.add(subDept); + buildDeptList(subDept.getDeptId(), deptBaseResponses); + } + } } + } diff --git a/cloud-common-dingding/src/main/java/com/cm/common/dingding/service/impl/DingDingAppUserServiceImpl.java b/cloud-common-dingding/src/main/java/com/cm/common/dingding/service/impl/DingDingAppUserServiceImpl.java index 77c8a35..b526d2c 100644 --- a/cloud-common-dingding/src/main/java/com/cm/common/dingding/service/impl/DingDingAppUserServiceImpl.java +++ b/cloud-common-dingding/src/main/java/com/cm/common/dingding/service/impl/DingDingAppUserServiceImpl.java @@ -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 listByDeptId(Long deptId) throws ApiException { + List userResponses = new ArrayList<>(); + buildUserList(deptId, 0L, userResponses); + return userResponses; + } + + private void buildUserList(Long deptId, Long cursor, List 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 listUserResponses = result.getList(); + if (result.getHasMore()) { + buildUserList(deptId, result.getNextCursor(), userResponses); + } + userResponses.addAll(listUserResponses); + } + + @Override + public List listByDeptIds(List deptIds) throws ApiException { + if (deptIds.isEmpty()) { + return new ArrayList<>(); + } + List userResponses = new ArrayList<>(); + for (Long deptId : deptIds) { + userResponses.addAll(listByDeptId(deptId)); + } + return userResponses; + } + } From 98d47e38ed6c47895e7c82e09643b4eed6bef28d Mon Sep 17 00:00:00 2001 From: wanggeng <450292408@qq.com> Date: Wed, 11 Aug 2021 23:16:20 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=BB=84=E3=80=81=E7=BB=84=E7=94=A8=E6=88=B7=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../oauth/service/group/IGroupService.java | 33 ++++++++++++ .../service/group/impl/GroupServiceImpl.java | 52 +++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/group/IGroupService.java create mode 100644 cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/group/impl/GroupServiceImpl.java diff --git a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/group/IGroupService.java b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/group/IGroupService.java new file mode 100644 index 0000000..d7b2112 --- /dev/null +++ b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/group/IGroupService.java @@ -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 list(String parentGroupId); + + /** + * 组用户列表 + * + * @param groupId + * @return + */ + List listUser(String groupId); + +} diff --git a/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/group/impl/GroupServiceImpl.java b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/group/impl/GroupServiceImpl.java new file mode 100644 index 0000000..9888c50 --- /dev/null +++ b/cloud-common-plugin-oauth/src/main/java/com/cm/common/plugin/oauth/service/group/impl/GroupServiceImpl.java @@ -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 list(String parentGroupId) { + Map 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 listUser(String groupId) { + Map 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); + } +}