|
@@ -1,26 +1,17 @@
|
|
package com.jeeplus.test.dingding.controller;
|
|
package com.jeeplus.test.dingding.controller;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
import com.dingtalk.api.DefaultDingTalkClient;
|
|
import com.dingtalk.api.DefaultDingTalkClient;
|
|
import com.dingtalk.api.DingTalkClient;
|
|
import com.dingtalk.api.DingTalkClient;
|
|
-import com.dingtalk.api.request.OapiGettokenRequest;
|
|
|
|
-import com.dingtalk.api.request.OapiV2DepartmentListsubRequest;
|
|
|
|
-import com.dingtalk.api.request.OapiV2UserListRequest;
|
|
|
|
-import com.dingtalk.api.response.OapiGettokenResponse;
|
|
|
|
-import com.dingtalk.api.response.OapiV2DepartmentListsubResponse;
|
|
|
|
-import com.dingtalk.api.response.OapiV2UserListResponse;
|
|
|
|
|
|
+import com.dingtalk.api.request.*;
|
|
|
|
+import com.dingtalk.api.response.*;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.jeeplus.logging.annotation.ApiLog;
|
|
import com.jeeplus.logging.annotation.ApiLog;
|
|
-import com.jeeplus.test.grid.service.dto.TestContinentDTO;
|
|
|
|
|
|
+import com.jeeplus.test.dingding.dto.DeptDTO;
|
|
import com.taobao.api.ApiException;
|
|
import com.taobao.api.ApiException;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.http.ResponseEntity;
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
|
-
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
@RestController
|
|
@RestController
|
|
@RequestMapping(value = "/test/addressBook")
|
|
@RequestMapping(value = "/test/addressBook")
|
|
@@ -86,16 +77,44 @@ public class DingdingAddressBookController {
|
|
@ApiLog("获取部门列表")
|
|
@ApiLog("获取部门列表")
|
|
@ApiOperation(value = "获取部门列表")
|
|
@ApiOperation(value = "获取部门列表")
|
|
@GetMapping("deptList")
|
|
@GetMapping("deptList")
|
|
- public ResponseEntity deptList() {
|
|
|
|
|
|
+ public ResponseEntity deptList(Long deptId) {
|
|
try {
|
|
try {
|
|
String token = getToken();
|
|
String token = getToken();
|
|
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/listsub");
|
|
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/listsub");
|
|
OapiV2DepartmentListsubRequest req = new OapiV2DepartmentListsubRequest();
|
|
OapiV2DepartmentListsubRequest req = new OapiV2DepartmentListsubRequest();
|
|
|
|
+ // 检查 deptId 是否为空
|
|
|
|
+ if (deptId != null) {
|
|
|
|
+ req.setDeptId(deptId);
|
|
|
|
+ }
|
|
OapiV2DepartmentListsubResponse rsp = client.execute(req, token);
|
|
OapiV2DepartmentListsubResponse rsp = client.execute(req, token);
|
|
// 返回 JSON 响应
|
|
// 返回 JSON 响应
|
|
return ResponseEntity.ok(rsp);
|
|
return ResponseEntity.ok(rsp);
|
|
} catch (ApiException e) {
|
|
} catch (ApiException e) {
|
|
e.printStackTrace(); // 打印错误日志(开发调试用)
|
|
e.printStackTrace(); // 打印错误日志(开发调试用)
|
|
|
|
+ return ResponseEntity.badRequest().body("接口异常,请重试!");
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace(); // 打印错误日志(开发调试用)
|
|
|
|
+ return ResponseEntity.badRequest().body("接口异常,请重试!");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 删除部门
|
|
|
|
+ */
|
|
|
|
+ @ApiLog("删除部门")
|
|
|
|
+ @ApiOperation(value = "删除部门")
|
|
|
|
+ @PostMapping("delDept")
|
|
|
|
+ public ResponseEntity delDept(@RequestBody DeptDTO deptDTO) {
|
|
|
|
+ try {
|
|
|
|
+ String token = getToken();
|
|
|
|
+ DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/delete");
|
|
|
|
+ OapiV2DepartmentDeleteRequest req = new OapiV2DepartmentDeleteRequest();
|
|
|
|
+ req.setDeptId(deptDTO.getDeptId());
|
|
|
|
+ OapiV2DepartmentDeleteResponse rsp = client.execute(req, token);
|
|
|
|
+ return ResponseEntity.ok(rsp);
|
|
|
|
+ } catch (ApiException e) {
|
|
|
|
+ e.printStackTrace(); // 打印错误日志(开发调试用)
|
|
return ResponseEntity.badRequest ( ).body ( "接口异常,请重试!" );
|
|
return ResponseEntity.badRequest ( ).body ( "接口异常,请重试!" );
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace(); // 打印错误日志(开发调试用)
|
|
e.printStackTrace(); // 打印错误日志(开发调试用)
|
|
@@ -104,6 +123,34 @@ public class DingdingAddressBookController {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 创建部门
|
|
|
|
+ */
|
|
|
|
+ @ApiLog("创建部门")
|
|
|
|
+ @ApiOperation(value = "创建部门")
|
|
|
|
+ @PostMapping("addDept")
|
|
|
|
+ public ResponseEntity addDept(@RequestBody DeptDTO deptDTO) {
|
|
|
|
+ try {
|
|
|
|
+ String token = getToken();
|
|
|
|
+ DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/create");
|
|
|
|
+ OapiV2DepartmentCreateRequest req = new OapiV2DepartmentCreateRequest();
|
|
|
|
+ req.setParentId(deptDTO.getParentId());
|
|
|
|
+ req.setName(deptDTO.getName());
|
|
|
|
+ OapiV2DepartmentCreateResponse rsp = client.execute(req, token);
|
|
|
|
+ System.out.println(rsp.getBody());
|
|
|
|
+ return ResponseEntity.ok(rsp);
|
|
|
|
+ } catch (ApiException e) {
|
|
|
|
+ e.printStackTrace(); // 打印错误日志(开发调试用)
|
|
|
|
+ return ResponseEntity.badRequest ( ).body ( "接口异常,请重试!" );
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace(); // 打印错误日志(开发调试用)
|
|
|
|
+ return ResponseEntity.badRequest ( ).body ( "接口异常,请重试!" );
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
public <T> T jsonToObject(String json, Class<T> clazz) {
|
|
public <T> T jsonToObject(String json, Class<T> clazz) {
|
|
try {
|
|
try {
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
ObjectMapper objectMapper = new ObjectMapper();
|