package com.ruzhoukj.sms.controller; import com.dingtalk.api.DefaultDingTalkClient; import com.dingtalk.api.DingTalkClient; import com.dingtalk.api.request.OapiV2DepartmentListsubidRequest; import com.dingtalk.api.response.OapiV2DepartmentListsubidResponse; import com.ruzhoukj.sms.ding.PermissionConfig; import com.taobao.api.ApiException; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import java.util.List; import java.util.Map; /** * @author : wujipeng * @date : 2025/2/28 10:00 * @Version: 1.0 * @Desc : 钉钉考勤管理 */ @Api(tags = "钉钉考勤管理") @RestController @RequestMapping("/ding/attendance") public class DingAttendanceController { @Resource private PermissionConfig permissionConfig; @ApiOperation(value = "获取子部门ID列表") @GetMapping("/child/{deptId}") public List getChildIdList(@PathVariable String deptId) { String accessToken = permissionConfig.getAccessToken(); try { DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/listsubid"); OapiV2DepartmentListsubidRequest req = new OapiV2DepartmentListsubidRequest(); OapiV2DepartmentListsubidResponse rsp = client.execute(req, ""); req.setDeptId(Long.valueOf(deptId)); Map textParams = req.getTextParams(); textParams.put("access_token", accessToken); OapiV2DepartmentListsubidResponse.DeptListSubIdResponse result = rsp.getResult(); return result.getDeptIdList(); } catch (ApiException e) { throw new RuntimeException(e); } } }