From cbd223ee2185f2cc39267e37a72edaadf6a3aa19 Mon Sep 17 00:00:00 2001
From: sinake <sinake1@qq.com>
Date: 星期三, 18 三月 2026 08:57:12 +0800
Subject: [PATCH] 死亡判定相关接口新增死亡判定说明、扩展 器官分配相关接口新增记录状态、附件、扩展 器官获取相关接口新增附件、扩展 新开发去态查询API接口

---
 ruoyi-project/src/main/java/com/ruoyi/project/service/impl/DingTalkServiceImpl.java |  147 +++++++++++++++++++++++++++++++-----------------
 1 files changed, 95 insertions(+), 52 deletions(-)

diff --git a/ruoyi-project/src/main/java/com/ruoyi/project/service/impl/DingTalkServiceImpl.java b/ruoyi-project/src/main/java/com/ruoyi/project/service/impl/DingTalkServiceImpl.java
index 9974eb6..4e6e151 100644
--- a/ruoyi-project/src/main/java/com/ruoyi/project/service/impl/DingTalkServiceImpl.java
+++ b/ruoyi-project/src/main/java/com/ruoyi/project/service/impl/DingTalkServiceImpl.java
@@ -3,7 +3,18 @@
 import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
+import com.dingtalk.api.DefaultDingTalkClient;
+import com.dingtalk.api.DingTalkClient;
+import com.dingtalk.api.request.OapiGettokenRequest;
+import com.dingtalk.api.request.OapiMessageCorpconversationAsyncsendV2Request;
+import com.dingtalk.api.request.OapiUserListidRequest;
+import com.dingtalk.api.request.OapiV2UserGetbymobileRequest;
+import com.dingtalk.api.response.OapiGettokenResponse;
+import com.dingtalk.api.response.OapiMessageCorpconversationAsyncsendV2Response;
+import com.dingtalk.api.response.OapiUserListidResponse;
+import com.dingtalk.api.response.OapiV2UserGetbymobileResponse;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.exception.base.BaseException;
 import com.ruoyi.common.utils.StringUtils;
@@ -18,6 +29,7 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
+import org.springframework.web.bind.annotation.RequestParam;
 
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
@@ -62,32 +74,37 @@
 
         String accessToken = null;
         try {
-            accessToken = dingTalkProxyClient.getAccessToken();
+            accessToken = getAccessToken();
         } catch (ApiException e) {
             e.printStackTrace();
         }
         if (StringUtils.isNotEmpty(dingTalkReqVo.getNumber())) {
-            // 浣跨敤浠g悊瀹㈡埛绔皟鐢ㄨ幏鍙栫敤鎴稩D鎺ュ彛
-            Map<String, String> params = new HashMap<>();
-            params.put("access_token", accessToken);
-            params.put("mobile", dingTalkReqVo.getNumber());
+            DingTalkClient clientT = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/getbymobile");
+            OapiV2UserGetbymobileRequest req = new OapiV2UserGetbymobileRequest();
+            req.setMobile(dingTalkReqVo.getNumber());
+            OapiV2UserGetbymobileResponse rsp = null;
             try {
-                body = dingTalkProxyClient.executeGet("/topapi/v2/user/getbymobile", params);
+                rsp = clientT.execute(req, accessToken);
+                body = rsp.getBody();
                 String jsonObject = JSONObject.parseObject(body).getJSONObject("result").get("userid").toString();
                 userIdlist.add(jsonObject);
+
             } catch (ApiException e) {
                 e.printStackTrace();
             }
         } else {
-            // 浣跨敤浠g悊瀹㈡埛绔皟鐢ㄨ幏鍙栭儴闂ㄧ敤鎴稩D鍒楄〃鎺ュ彛
-            Map<String, String> params = new HashMap<>();
-            params.put("access_token", accessToken);
-            params.put("dept_id", String.valueOf(dingTalkReqVo.getDeptId()));
+            DingTalkClient client3 = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/user/listid");
+
+            OapiUserListidRequest request2 = new OapiUserListidRequest();
+            request2.setDeptId(dingTalkReqVo.getDeptId()); // 璁剧疆瑕佽幏鍙栫殑閮ㄩ棬 ID锛岃繖閲屼互鏍归儴闂ㄤ负渚�675909059L
+            // 璁剧疆閮ㄩ棬 ID锛屽鏋滆幏鍙栨墍鏈夊憳宸ユ墜鏈哄彿锛屽彲浠ヨ缃负鏍归儴闂ㄧ殑 ID
+            OapiUserListidResponse response2 = null;
             try {
-                body = dingTalkProxyClient.executeGet("/topapi/user/listid", params);
+                response2 = client3.execute(request2, accessToken);
             } catch (ApiException e) {
                 e.printStackTrace();
             }
+            body = response2.getBody();
             // 瑙f瀽涓篔SONObject
             JSONObject jsonObject = JSONObject.parseObject(body);
             if (jsonObject != null) {
@@ -102,62 +119,60 @@
 
         //userid鏁扮粍
         for (String urid : userIdlist) {
-            // 鏋勫缓鍙戦�佹秷鎭殑瀹屾暣JSON瀵硅薄锛岀鍚堥拤閽堿PI鏍煎紡
-            Map<String, Object> messageData = new HashMap<>();
-            messageData.put("userid_list", urid);
-            messageData.put("agent_id", agentId);
-            messageData.put("to_all_user", false);
+            DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2");
+            OapiMessageCorpconversationAsyncsendV2Request request = new OapiMessageCorpconversationAsyncsendV2Request();
+            request.setUseridList(urid);
+            request.setAgentId(agentId);
+            request.setToAllUser(false);
 
             //鍙戦�佸唴瀹瑰鐞�
             List<ConcurrentHashMap<String, Object>> contents = dingTalkReqVo.getContents();
-            List<Map<String, Object>> objects = new ArrayList<>();
+            ArrayList<OapiMessageCorpconversationAsyncsendV2Request.Form> objects = new ArrayList<>();
             for (int i = 0; i < contents.size(); i++) {
                 ConcurrentHashMap<String, Object> map = contents.get(i);
                 for (Map.Entry<String, Object> entry : map.entrySet()) {
-                    Map<String, Object> formItem = new HashMap<>();
-                    formItem.put("key", entry.getKey());
+                    OapiMessageCorpconversationAsyncsendV2Request.Form formSeverityDesc = new OapiMessageCorpconversationAsyncsendV2Request.Form();
+                    formSeverityDesc.setKey(entry.getKey());
                     if (entry.getKey().contains("瀹℃壒鏃堕棿")) {
                         Date date = (Date) entry.getValue();
                         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
                         String format = simpleDateFormat.format(date);
-                        formItem.put("value", format);
+                        formSeverityDesc.setValue(format);
                     } else {
                         if (entry.getValue() != null) {
-                            formItem.put("value", entry.getValue().toString());
-                        } else {
-                            formItem.put("value", "");
+                            formSeverityDesc.setValue(entry.getValue().toString());
                         }
                     }
-                    objects.add(formItem);
+                    objects.add(formSeverityDesc);
                 }
             }
 
-            Map<String, Object> msg = new HashMap<>();
-            Map<String, Object> oa = new HashMap<>();
-            oa.put("message_url", dingTalkReqVo.getUrl());
-            oa.put("pc_message_url", dingTalkReqVo.getUrl());
-            Map<String, Object> head = new HashMap<>();
-            head.put("bgcolor", "00409eff");
-            oa.put("head", head);
-            Map<String, Object> bodyContent = new HashMap<>();
-            bodyContent.put("title", dingTalkReqVo.getTitle());
-            bodyContent.put("form", objects);
-            oa.put("body", bodyContent);
-            msg.put("oa", oa);
-            msg.put("msgtype", "oa");
-            messageData.put("msg", msg);
+            OapiMessageCorpconversationAsyncsendV2Request.Msg msg = new OapiMessageCorpconversationAsyncsendV2Request.Msg();
+            msg.setOa(new OapiMessageCorpconversationAsyncsendV2Request.OA());
+            msg.getOa().setMessageUrl(dingTalkReqVo.getUrl());
+            msg.getOa().setPcMessageUrl(dingTalkReqVo.getUrl());
+            msg.getOa().setHead(new OapiMessageCorpconversationAsyncsendV2Request.Head());
+            //   msg.getOa().getHead().setText("浣犲湪璇村暐鍛㈢粧椤舵浛鑻涘ず闃挎柉钂傝姮闃挎柉钂傝姮");
+            msg.getOa().getHead().setBgcolor("00409eff");
+            msg.getOa().setBody(new OapiMessageCorpconversationAsyncsendV2Request.Body());
+            msg.getOa().getBody().setTitle(dingTalkReqVo.getTitle());
+            // msg.getOa().getBody().setContent("寰呭鐞�:" + "123" + "鏉�");
 
-            // 灏哸ccess_token浣滀负URL鍙傛暟浼犻��
-            String messageJson = JSONObject.toJSONString(messageData);
+            msg.getOa().getBody().setForm(objects);
+            msg.setMsgtype("oa");
+            request.setMsg(msg);
+            //  log.info("鑾峰彇鍙戦�侀�氱煡娑堟伅浣撳拰鑾峰彇鍙戦�侀�氱煡浜哄畬鎴�");
+            OapiMessageCorpconversationAsyncsendV2Response response = null;
             try {
-                // 浣跨敤浠g悊瀹㈡埛绔彂閫丳OST璇锋眰
-                body = dingTalkProxyClient.executePost("/topapi/message/corpconversation/asyncsend_v2?access_token=" + accessToken, messageJson);
-                JSONObject response = JSONObject.parseObject(body);
-                result = response.getInteger("errcode") == 0;
+                response = client.execute(request, accessToken);
             } catch (ApiException e) {
-                log.error("鍙戦�侀拤閽夋秷鎭け璐�: " + e.getErrMsg());
+                e.getErrMsg();
             }
 
+            //  log.info("娑堟伅浠诲姟ID"+response.getTaskId());
+            System.out.println(response.getTaskId());
+
+            result = response.isSuccess();
         }
         return result;
     }
@@ -170,16 +185,36 @@
      */
     public Map<String, Object> noLogin(String authCode) {
         try {
-            String params = "access_token=" + dingTalkProxyClient.getAccessToken() + "&code=" + authCode;
+            // 澶嶇敤鍚屼竴涓� accessToken锛岄伩鍏嶉噸澶嶈姹�
+            String accessToken = dingTalkProxyClient.getAccessToken();
+
+            // 绗竴姝ワ細authCode 鎹� userid
+            String params = "access_token=" + accessToken + "&code=" + authCode;
             String result = HttpUtils.sendPost("https://oapi.dingtalk.com/topapi/v2/user/getuserinfo", params);
             ObjectMapper objectMapper = new ObjectMapper();
             Map<String, Object> map = objectMapper.readValue(result, Map.class);
-            return map;
+            if (!Integer.valueOf(0).equals(map.get("errcode"))) {
+                throw new BaseException("閽夐拤鐧诲綍澶辫触锛�" + map.get("errmsg"));
+            }
+            Map<String, Object> resultMap = (Map<String, Object>) map.get("result");
+            String userid = (String) resultMap.get("userid");
+
+            // 绗簩姝ワ細userid 鎹㈢敤鎴疯鎯咃紙鍚墜鏈哄彿锛�
+            String params2 = "access_token=" + accessToken + "&userid=" + userid + "&language=zh_CN";
+            String result2 = HttpUtils.sendPost("https://oapi.dingtalk.com/topapi/v2/user/get", params2);
+            Map<String, Object> map2 = objectMapper.readValue(result2, Map.class);
+            if (!Integer.valueOf(0).equals(map2.get("errcode"))) {
+                throw new BaseException("鑾峰彇鐢ㄦ埛璇︽儏澶辫触锛�" + map2.get("errmsg"));
+            }
+            Map<String, Object> userDetail = (Map<String, Object>) map2.get("result");
+
+            return userDetail;
+        } catch (BaseException e) {
+            throw e;
         } catch (Exception e) {
-            log.error(e.getMessage());
-            new BaseException("鐧诲綍鍑哄紓甯镐簡锛岃鑱旂郴绠$悊鍛樺鐞�");
+            log.error("noLogin 寮傚父锛歿}", e);
+            throw new BaseException("鐧诲綍鍑哄紓甯镐簡锛岃鑱旂郴绠$悊鍛樺鐞�");
         }
-        return null;
     }
 
     @Override
@@ -245,7 +280,15 @@
      * 鑾峰彇 access_token
      */
     private String getAccessToken() throws ApiException {
-        return dingTalkProxyClient.getAccessToken();
+        DefaultDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
+        OapiGettokenRequest request = new OapiGettokenRequest();
+        //Appkey
+        request.setAppkey(dingAppid);
+        //Appsecret
+        request.setAppsecret(dingAppSecret);
+        /*璇锋眰鏂瑰紡*/
+        request.setHttpMethod("GET");
+        OapiGettokenResponse response = client.execute(request);
+        return response.getAccessToken();
     }
-
 }

--
Gitblit v1.9.3