|
@@ -4,6 +4,11 @@ import cn.hutool.http.HttpUtil;
|
|
|
import cn.hutool.json.JSONArray;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
+import com.alibaba.nacos.common.utils.UuidUtils;
|
|
|
+import com.alibaba.xxpt.gateway.shared.api.request.OapiMessageWorkNotificationRequest;
|
|
|
+import com.alibaba.xxpt.gateway.shared.api.response.OapiMessageWorkNotificationResponse;
|
|
|
+import com.alibaba.xxpt.gateway.shared.client.http.ExecutableClient;
|
|
|
+import com.alibaba.xxpt.gateway.shared.client.http.IntelligentGetClient;
|
|
|
import com.dingtalk.api.DefaultDingTalkClient;
|
|
|
import com.dingtalk.api.DingTalkClient;
|
|
|
import com.dingtalk.api.request.OapiGettokenRequest;
|
|
@@ -13,11 +18,13 @@ import com.dingtalk.api.response.OapiGettokenResponse;
|
|
|
import com.dingtalk.api.response.OapiMessageCorpconversationAsyncsendV2Response;
|
|
|
import com.dingtalk.api.response.OapiUserGetByMobileResponse;
|
|
|
import com.taobao.api.ApiException;
|
|
|
+import com.zjugis.framework.common.enums.UserTypeEnum;
|
|
|
import com.zjugis.framework.common.pojo.CommonResult;
|
|
|
import com.zjugis.module.infra.api.ding.dto.*;
|
|
|
import com.zjugis.module.infra.dal.dataobject.msg.MsgSendRecordDO;
|
|
|
import com.zjugis.module.infra.enums.msg.SendTypeEnum;
|
|
|
import com.zjugis.module.infra.service.msg.MsgSendRecordService;
|
|
|
+import com.zjugis.module.system.api.social.SocialUserApi;
|
|
|
import com.zjugis.module.system.api.user.AdminUserApi;
|
|
|
import com.zjugis.module.system.api.user.dto.AdminUserRespDTO;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -27,6 +34,7 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
@@ -58,6 +66,13 @@ public class DingServiceImpl implements DingService {
|
|
|
@Autowired
|
|
|
private AdminUserApi adminUserApi;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private SocialUserApi socialUserApi;
|
|
|
+ @Value("${zjugis.zzd.tenantId}")
|
|
|
+ private String zzdTenantId;
|
|
|
+ @Resource(name = "executableClient")
|
|
|
+ private ExecutableClient executableClient;
|
|
|
+
|
|
|
/**
|
|
|
* @param mobile
|
|
|
* @param
|
|
@@ -145,11 +160,6 @@ public class DingServiceImpl implements DingService {
|
|
|
throw new ApiException(errMsg);
|
|
|
}
|
|
|
String userId = map.get("userid").toString();
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
Map<String, Object> paramMap = new HashMap<>();
|
|
|
paramMap.put("access_token", accessToken);
|
|
|
paramMap.put("userid", userId);
|
|
@@ -161,6 +171,41 @@ public class DingServiceImpl implements DingService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public String sendZzdNotification(DingMessageDto dingMessageDto) {
|
|
|
+ String userId = dingMessageDto.getUserId();
|
|
|
+ CommonResult<String> user = socialUserApi.getUserAccountId(UserTypeEnum.MEMBER.getValue(), userId);
|
|
|
+ String userAccountId = user.getData();
|
|
|
+ OA oa = dingMessageDto.getOa();
|
|
|
+ String msg = JSONUtil.toJsonStr(oa);
|
|
|
+ IntelligentGetClient intelligentGetClient = executableClient.newIntelligentGetClient("/message/workNotification");
|
|
|
+ OapiMessageWorkNotificationRequest oapiMessageWorkNotificationRequest = new OapiMessageWorkNotificationRequest();
|
|
|
+ //接收人用户ID
|
|
|
+ oapiMessageWorkNotificationRequest.setReceiverIds(userAccountId);
|
|
|
+ //租户ID
|
|
|
+ oapiMessageWorkNotificationRequest.setTenantId(zzdTenantId);
|
|
|
+ //业务消息id
|
|
|
+ oapiMessageWorkNotificationRequest.setBizMsgId(UuidUtils.generateUuid());
|
|
|
+ //消息对象
|
|
|
+ oapiMessageWorkNotificationRequest.setMsg(msg);
|
|
|
+ //获取结果
|
|
|
+ OapiMessageWorkNotificationResponse apiResult = intelligentGetClient.get(oapiMessageWorkNotificationRequest);
|
|
|
+ MsgSendRecordDO record = new MsgSendRecordDO();
|
|
|
+ record.setSendPersonId(dingMessageDto.getUserId());
|
|
|
+ record.setSendContent(JSONUtil.toJsonStr(msg));
|
|
|
+ record.setSendType(SendTypeEnum.DING.getType());
|
|
|
+ record.setSendTime(LocalDateTime.now());
|
|
|
+ record.setMsgType(dingMessageDto.getMsgType().name());
|
|
|
+ if(apiResult.getSuccess()){
|
|
|
+ record.setSendState(1);
|
|
|
+ } else {
|
|
|
+ record.setSendState(0);
|
|
|
+ record.setSendResult("errcode: " + apiResult.getCode() +",errmsg: " + apiResult.getMessage());
|
|
|
+ }
|
|
|
+ msgSendRecordService.createMsgSendRecord(record);
|
|
|
+ return apiResult.toString();
|
|
|
+ }
|
|
|
+
|
|
|
private String getDeptList(String staffDeptName, String accessToken) throws ApiException {
|
|
|
|
|
|
Map<String, Object> paramMap = new HashMap<>();
|