use of com.jeecg.dingtalk.api.core.response.Response in project kms by mahonelau.
the class ThirdAppController method sendMessageTest.
/**
* 发送消息测试
*
* @return
*/
@PostMapping("/sendMessageTest")
public Result sendMessageTest(@RequestBody JSONObject params, HttpServletRequest request) {
/* 获取前台传递的参数 */
// 第三方app的类型
String app = params.getString("app");
// 是否发送给全部人
boolean sendAll = params.getBooleanValue("sendAll");
// 消息接收者,传sys_user表的username字段,多个用逗号分割
String receiver = params.getString("receiver");
// 消息内容
String content = params.getString("content");
String fromUser = JwtUtil.getUserNameByToken(request);
String title = "第三方APP消息测试";
MessageDTO message = new MessageDTO(fromUser, receiver, title, content);
message.setToAll(sendAll);
if (ThirdAppConfig.WECHAT_ENTERPRISE.equals(app)) {
if (thirdAppConfig.isWechatEnterpriseEnabled()) {
JSONObject response = wechatEnterpriseService.sendMessageResponse(message, false);
return Result.OK(response);
}
return Result.error("企业微信已被禁用");
} else if (ThirdAppConfig.DINGTALK.equals(app)) {
if (thirdAppConfig.isDingtalkEnabled()) {
Response<String> response = dingtalkService.sendMessageResponse(message, false);
return Result.OK(response);
}
return Result.error("钉钉已被禁用");
}
return Result.error("不识别的第三方APP");
}
use of com.jeecg.dingtalk.api.core.response.Response in project jeecg-boot by jeecgboot.
the class ThirdAppDingtalkServiceImpl method syncLocalDepartmentToThirdApp.
// update:2022-1-21,updateBy:sunjianlei; for 【JTC-704】【钉钉】部门同步成功,实际没成,后台提示ip白名单
@Override
public SyncInfoVo syncLocalDepartmentToThirdApp(String ids) {
SyncInfoVo syncInfo = new SyncInfoVo();
String accessToken = this.getAccessToken();
if (accessToken == null) {
syncInfo.addFailInfo("accessToken获取失败!");
return syncInfo;
}
// 获取【钉钉】所有的部门
List<Response<Department>> departments = JdtDepartmentAPI.listAllResponse(accessToken);
// 删除钉钉有但本地没有的部门(以本地部门数据为主)(钉钉不能创建同名部门,只能先删除)
List<SysDepart> sysDepartList = sysDepartService.list();
for1: for (Response<Department> departmentRes : departments) {
// 判断部门是否查询成功
if (!departmentRes.isSuccess()) {
syncInfo.addFailInfo(departmentRes.getErrmsg());
// 88 是 ip 不在白名单的错误码,如果遇到此错误码,后面的操作都可以不用进行了,因为肯定都是失败的
if (new Integer(88).equals(departmentRes.getErrcode())) {
return syncInfo;
}
continue;
}
Department department = departmentRes.getResult();
for (SysDepart depart : sysDepartList) {
// id相同,代表已存在,不删除
String sourceIdentifier = department.getSource_identifier();
if (sourceIdentifier != null && sourceIdentifier.equals(depart.getId())) {
continue for1;
}
}
// 循环到此说明本地没有,删除
int deptId = department.getDept_id();
// 钉钉不允许删除带有用户的部门,所以需要判断下,将有用户的部门的用户移动至根部门
Response<List<String>> userIdRes = JdtUserAPI.getUserListIdByDeptId(deptId, accessToken);
if (userIdRes.isSuccess() && userIdRes.getResult().size() > 0) {
for (String userId : userIdRes.getResult()) {
User updateUser = new User();
updateUser.setUserid(userId);
updateUser.setDept_id_list(1);
JdtUserAPI.update(updateUser, accessToken);
}
}
JdtDepartmentAPI.delete(deptId, accessToken);
}
// 获取本地所有部门树结构
List<SysDepartTreeModel> sysDepartsTree = sysDepartService.queryTreeList();
// -- 钉钉不能创建新的顶级部门,所以新的顶级部门的parentId就为1
Department parent = new Department();
parent.setDept_id(1);
// 递归同步部门
departments = JdtDepartmentAPI.listAllResponse(accessToken);
this.syncDepartmentRecursion(sysDepartsTree, departments, parent, accessToken, syncInfo);
return syncInfo;
}
use of com.jeecg.dingtalk.api.core.response.Response in project kykms by mahonelau.
the class ThirdAppController method sendMessageTest.
/**
* 发送消息测试
*
* @return
*/
@PostMapping("/sendMessageTest")
public Result sendMessageTest(@RequestBody JSONObject params, HttpServletRequest request) {
/* 获取前台传递的参数 */
// 第三方app的类型
String app = params.getString("app");
// 是否发送给全部人
boolean sendAll = params.getBooleanValue("sendAll");
// 消息接收者,传sys_user表的username字段,多个用逗号分割
String receiver = params.getString("receiver");
// 消息内容
String content = params.getString("content");
String fromUser = JwtUtil.getUserNameByToken(request);
String title = "第三方APP消息测试";
MessageDTO message = new MessageDTO(fromUser, receiver, title, content);
message.setToAll(sendAll);
if (ThirdAppConfig.WECHAT_ENTERPRISE.equals(app)) {
if (thirdAppConfig.isWechatEnterpriseEnabled()) {
JSONObject response = wechatEnterpriseService.sendMessageResponse(message, false);
return Result.OK(response);
}
return Result.error("企业微信已被禁用");
} else if (ThirdAppConfig.DINGTALK.equals(app)) {
if (thirdAppConfig.isDingtalkEnabled()) {
Response<String> response = dingtalkService.sendMessageResponse(message, false);
return Result.OK(response);
}
return Result.error("钉钉已被禁用");
}
return Result.error("不识别的第三方APP");
}
use of com.jeecg.dingtalk.api.core.response.Response in project kykms by mahonelau.
the class ThirdAppDingtalkServiceImpl method syncLocalDepartmentToThirdApp.
@Override
public boolean syncLocalDepartmentToThirdApp(String ids) {
String accessToken = this.getAccessToken();
if (accessToken == null) {
return false;
}
// 获取【钉钉】所有的部门
List<Department> departments = JdtDepartmentAPI.listAll(accessToken);
// 删除钉钉有但本地没有的部门(以本地部门数据为主)(钉钉不能创建同名部门,只能先删除)
List<SysDepart> sysDepartList = sysDepartService.list();
for1: for (Department department : departments) {
for (SysDepart depart : sysDepartList) {
// id相同,代表已存在,不删除
String sourceIdentifier = department.getSource_identifier();
if (sourceIdentifier != null && sourceIdentifier.equals(depart.getId())) {
continue for1;
}
}
// 循环到此说明本地没有,删除
int deptId = department.getDept_id();
// 钉钉不允许删除带有用户的部门,所以需要判断下,将有用户的部门的用户移动至根部门
Response<List<String>> userIdRes = JdtUserAPI.getUserListIdByDeptId(deptId, accessToken);
if (userIdRes.isSuccess() && userIdRes.getResult().size() > 0) {
for (String userId : userIdRes.getResult()) {
User updateUser = new User();
updateUser.setUserid(userId);
updateUser.setDept_id_list(1);
JdtUserAPI.update(updateUser, accessToken);
}
}
JdtDepartmentAPI.delete(deptId, accessToken);
}
// 获取本地所有部门树结构
List<SysDepartTreeModel> sysDepartsTree = sysDepartService.queryTreeList();
// -- 钉钉不能创建新的顶级部门,所以新的顶级部门的parentId就为1
Department parent = new Department();
parent.setDept_id(1);
// 递归同步部门
departments = JdtDepartmentAPI.listAll(accessToken);
this.syncDepartmentRecursion(sysDepartsTree, departments, parent, accessToken);
return true;
}
Aggregations