Kaynağa Gözat

1、添加发送浙政钉消息功能

fuwb 3 ay önce
ebeveyn
işleme
b572121a34

+ 4 - 0
zjugis-module-infra/zjugis-module-infra-api/src/main/java/com/zjugis/module/infra/api/ding/DingApi.java

@@ -24,6 +24,10 @@ public interface DingApi {
     @Operation(summary = "发送钉钉消息")
     CommonResult<String> sendMessage(@Valid @RequestBody DingMessageDto dingMessageDto);
 
+    @PostMapping(PREFIX + "/send-zzd-message")
+    @Operation(summary = "发送浙政钉消息")
+    CommonResult<String> sendZzdMessage(@Valid @RequestBody DingMessageDto dingMessageDto);
+
     @PostMapping(PREFIX + "/entry")
     @Operation(summary = "员工入职")
     CommonResult<String> entry(@Valid @RequestBody StaffDTO dto);

+ 15 - 3
zjugis-module-infra/zjugis-module-infra-biz/pom.xml

@@ -14,8 +14,8 @@
     <name>${project.artifactId}</name>
     <description>
         infra 模块,主要提供两块能力:
-            1. 我们放基础设施的运维与管理,支撑上层的通用与核心业务。 例如说:定时任务的管理、服务器的信息等等
-            2. 研发工具,提升研发效率与质量。 例如说:代码生成器、接口文档等等
+        1. 我们放基础设施的运维与管理,支撑上层的通用与核心业务。 例如说:定时任务的管理、服务器的信息等等
+        2. 研发工具,提升研发效率与质量。 例如说:代码生成器、接口文档等等
     </description>
 
     <dependencies>
@@ -153,7 +153,19 @@
             <scope>system</scope>
             <systemPath>${project.basedir}/src/lib/ding/taobao-sdk-java-auto-1479188381469-20200507.jar</systemPath>
         </dependency>
-
+        <!--  浙政钉SDK      -->
+        <dependency>
+            <groupId>com.alibaba.openplatform.shared</groupId>
+            <artifactId>sdk.client</artifactId>
+            <version>2.9.0-SNAPSHOT</version>
+            <scope>system</scope>
+            <systemPath>${project.basedir}/src/main/resources/lib/zwdd-sdk-java-1.2.0.jar</systemPath>
+        </dependency>
+        <dependency>
+            <groupId>joda-time</groupId>
+            <artifactId>joda-time</artifactId>
+            <version>2.12.4</version>
+        </dependency>
     </dependencies>
     <build>
         <!-- 设置构建的 jar 包名 -->

+ 12 - 0
zjugis-module-infra/zjugis-module-infra-biz/src/main/java/com/zjugis/module/infra/api/ding/DingApiImpl.java

@@ -50,6 +50,18 @@ public class DingApiImpl implements DingApi {
         }
     }
 
+    /**
+     * 浙政钉发送发消息
+     *
+     * @param dingMessageDto
+     * @return
+     */
+    @Override
+    public CommonResult<String> sendZzdMessage(@RequestBody DingMessageDto dingMessageDto) {
+        String s = dingService.sendZzdNotification(dingMessageDto);
+        return CommonResult.success(s);
+    }
+
     @Override
     public CommonResult<String> entry(@RequestBody StaffDTO dto) {
         try {

+ 2 - 1
zjugis-module-infra/zjugis-module-infra-biz/src/main/java/com/zjugis/module/infra/framework/rpc/config/RpcConfiguration.java

@@ -1,10 +1,11 @@
 package com.zjugis.module.infra.framework.rpc.config;
 
+import com.zjugis.module.system.api.social.SocialUserApi;
 import com.zjugis.module.system.api.user.AdminUserApi;
 import org.springframework.cloud.openfeign.EnableFeignClients;
 import org.springframework.context.annotation.Configuration;
 
 @Configuration(proxyBeanMethods = false)
-@EnableFeignClients(clients = AdminUserApi.class)
+@EnableFeignClients(clients = {AdminUserApi.class, SocialUserApi.class})
 public class RpcConfiguration {
 }

+ 1 - 0
zjugis-module-infra/zjugis-module-infra-biz/src/main/java/com/zjugis/module/infra/service/ding/DingService.java

@@ -16,4 +16,5 @@ public interface DingService {
 
     void deleteStaff(String mobile) throws ApiException;
 
+    String sendZzdNotification(DingMessageDto dingMessageDto);
 }

+ 50 - 5
zjugis-module-infra/zjugis-module-infra-biz/src/main/java/com/zjugis/module/infra/service/ding/DingServiceImpl.java

@@ -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<>();

+ 6 - 0
zjugis-module-infra/zjugis-module-infra-biz/src/main/resources/application-dev.yaml

@@ -169,3 +169,9 @@ zjugis:
     agentid: 2755233050
     appkey: dingk0ggukejc4xacgku
     appsecret: 1Irqm3obWLCWTokhrCgbrcMIX7klSI3s_ljiBZrAzMfnpttJTUJHIBCi8C-2rD2O
+  zzd:
+    appkey: razg_oa-1r4wzTHFbdhjTB9zM363Mz
+    appsecret: TP7rfEsJp53gI5YOJnzpuvD2J2bkflLjxLgPkn49
+    domain: openplatform-pro.ding.zj.gov.cn
+    tenantId: 196729
+