use of com.dingtalk.api.DefaultDingTalkClient in project dingtalk-app-server by nju-softeng.
the class OAApi method deleteAbsentOA.
public boolean deleteAbsentOA(String processInstanceId, User user) {
try {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/process/instance/terminate");
OapiProcessInstanceTerminateRequest req = new OapiProcessInstanceTerminateRequest();
OapiProcessInstanceTerminateRequest.TerminateProcessInstanceRequestV2 processInstanceRequestV2 = new OapiProcessInstanceTerminateRequest.TerminateProcessInstanceRequestV2();
processInstanceRequestV2.setProcessInstanceId(processInstanceId);
processInstanceRequestV2.setIsSystem(false);
processInstanceRequestV2.setRemark("取消请假");
processInstanceRequestV2.setOperatingUserid(user.getUserid());
req.setRequest(processInstanceRequestV2);
OapiProcessInstanceTerminateResponse rsp = client.execute(req, getAccessToken());
return rsp.getResult();
} catch (Exception e) {
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
}
}
use of com.dingtalk.api.DefaultDingTalkClient in project MaxKey by dromara.
the class DingtalkOrganizationService method requestDepartmentList.
public OapiV2DepartmentListsubResponse requestDepartmentList(String access_token, Long deptId) throws ApiException {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/listsub");
OapiV2DepartmentListsubRequest req = new OapiV2DepartmentListsubRequest();
req.setDeptId(deptId);
req.setLanguage("zh_CN");
OapiV2DepartmentListsubResponse rspDepts = client.execute(req, access_token);
_logger.trace("response : " + rspDepts.getBody());
return rspDepts;
}
use of com.dingtalk.api.DefaultDingTalkClient in project MaxKey by dromara.
the class DingtalkOrganizationService method requestDepartment.
public OapiV2DepartmentGetResponse requestDepartment(String access_token, Long deptId) throws ApiException {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/get");
OapiV2DepartmentGetRequest req = new OapiV2DepartmentGetRequest();
req.setDeptId(deptId);
req.setLanguage("zh_CN");
OapiV2DepartmentGetResponse rspDepts = client.execute(req, access_token);
_logger.trace("response : " + rspDepts.getBody());
return rspDepts;
}
use of com.dingtalk.api.DefaultDingTalkClient in project MaxKey by dromara.
the class DingtalkUsersService method sync.
public void sync() {
_logger.info("Sync Dingtalk Users...");
try {
List<SynchroRelated> synchroRelateds = synchroRelatedService.findOrgs(this.synchronizer);
for (SynchroRelated relatedOrg : synchroRelateds) {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/list");
OapiV2UserListRequest req = new OapiV2UserListRequest();
_logger.debug("DingTalk deptId : {}", relatedOrg.getOriginId());
req.setDeptId(Long.parseLong(relatedOrg.getOriginId()));
req.setCursor(0L);
req.setSize(100L);
req.setOrderField("modify_desc");
req.setContainAccessLimit(true);
req.setLanguage("zh_CN");
OapiV2UserListResponse rsp = client.execute(req, access_token);
_logger.trace("response : {}", rsp.getBody());
if (rsp.getErrcode() == 0) {
for (ListUserResponse user : rsp.getResult().getList()) {
_logger.debug("name : {} , {} , {}", user.getName(), user.getLoginId(), user.getUserid());
UserInfo userInfo = buildUserInfo(user, relatedOrg);
_logger.trace("userInfo {}", userInfo);
userInfo.setPassword(userInfo.getUsername() + UserInfo.DEFAULT_PASSWORD_SUFFIX);
userInfoService.saveOrUpdate(userInfo);
SynchroRelated synchroRelated = new SynchroRelated(userInfo.getId(), userInfo.getUsername(), userInfo.getDisplayName(), UserInfo.CLASS_TYPE, synchronizer.getId(), synchronizer.getName(), user.getUnionid(), user.getName(), user.getUserid(), "", synchronizer.getInstId());
synchroRelatedService.updateSynchroRelated(this.synchronizer, synchroRelated, UserInfo.CLASS_TYPE);
socialsAssociate(synchroRelated, "dingtalk");
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.dingtalk.api.DefaultDingTalkClient in project metersphere by metersphere.
the class DingNoticeSender method sendNailRobot.
public void sendNailRobot(MessageDetail messageDetail, NoticeModel noticeModel, String context) {
List<Receiver> receivers = noticeModel.getReceivers();
DingTalkClient client = new DefaultDingTalkClient(messageDetail.getWebhook());
OapiRobotSendRequest request = new OapiRobotSendRequest();
request.setMsgtype("text");
OapiRobotSendRequest.Text text = new OapiRobotSendRequest.Text();
text.setContent("消息通知: \n" + context);
request.setText(text);
if (CollectionUtils.isNotEmpty(receivers)) {
OapiRobotSendRequest.At at = new OapiRobotSendRequest.At();
List<String> userIds = receivers.stream().map(Receiver::getUserId).distinct().collect(Collectors.toList());
List<String> phoneList = super.getUserDetails(userIds).stream().map(UserDetail::getPhone).distinct().collect(Collectors.toList());
if (!CollectionUtils.isEmpty(phoneList)) {
LogUtil.info("钉钉收件人地址: {}", userIds);
at.setAtMobiles(phoneList);
request.setAt(at);
}
}
try {
client.execute(request);
} catch (ApiException e) {
LogUtil.error(e.getMessage(), e);
}
}
Aggregations