From 543a8e4f314534401d39d48b6778ec5f8b6956f4 Mon Sep 17 00:00:00 2001
From: hao <1836460075@qq.com>
Date: 星期三, 30 四月 2025 10:08:10 +0800
Subject: [PATCH] Merge branch 'master' of http://43.142.96.171:8080/r/~yhj/HM_JK

---
 StandardInterface/MESApplication/Controllers/QcIssueResult/QcIssueResultController.cs |   20 ++--
 StandardInterface/MES.Service/Modes/QcIssueResult/DingNameCode.cs                     |   14 ++-
 StandardInterface/MES.Service/service/QcIssueResult/QcIssueResultManager.cs           |  184 ++++++++++++++++++++++++++++++++++++++-------
 StandardInterface/MES.Service/resources/TopSdk.dll                                    |    0 
 StandardInterface/MES.Service/MES.Service.csproj                                      |    3 
 5 files changed, 175 insertions(+), 46 deletions(-)

diff --git a/StandardInterface/MES.Service/MES.Service.csproj b/StandardInterface/MES.Service/MES.Service.csproj
index 5f0ecb4..fb62dfb 100644
--- a/StandardInterface/MES.Service/MES.Service.csproj
+++ b/StandardInterface/MES.Service/MES.Service.csproj
@@ -27,6 +27,9 @@
       <Reference Include="Kingdee.CDP.WebApi.SDK">
         <HintPath>resources\Kingdee.CDP.WebApi.SDK.dll</HintPath>
       </Reference>
+      <Reference Include="TopSdk">
+        <HintPath>resources\TopSdk.dll</HintPath>
+      </Reference>
     </ItemGroup>
 
 </Project>
diff --git a/StandardInterface/MES.Service/Modes/QcIssueResult/DingNameCode.cs b/StandardInterface/MES.Service/Modes/QcIssueResult/DingNameCode.cs
index a2b7663..659ff2f 100644
--- a/StandardInterface/MES.Service/Modes/QcIssueResult/DingNameCode.cs
+++ b/StandardInterface/MES.Service/Modes/QcIssueResult/DingNameCode.cs
@@ -8,14 +8,18 @@
 namespace MES.Service.Modes.QcIssueResult;
 
 //閽夐拤鐢ㄦ埛鍐呯爜瀵瑰簲琛�
-[SugarTable("MES_DINGDING_NAME_CODE")]
+[SugarTable("MES_STAFF")]
 internal class DingNameCode
 {
+
+    [SugarColumn(ColumnName = "STAFF_NO")]
+    public string? STAFF_NO { get; set; }
+
     //閽夐拤鐢ㄦ埛鍐呯爜
-    [SugarColumn(ColumnName = "DINGDINGCODE")]
-    public string? DingDingCode { get; set; }
+    [SugarColumn(ColumnName = "STAFF_NAME")]
+    public string? STAFF_NAME { get; set; }
 
     //閽夐拤鐢ㄦ埛鍚嶇О
-    [SugarColumn(ColumnName = "DINGDINGNAME")]
-    public string? DingDingName { get; set; }
+    [SugarColumn(ColumnName = "PHONE_NUMBER")]
+    public string? PHONE_NUMBER { get; set; }
 }
diff --git a/StandardInterface/MES.Service/resources/TopSdk.dll b/StandardInterface/MES.Service/resources/TopSdk.dll
new file mode 100644
index 0000000..43cbaea
--- /dev/null
+++ b/StandardInterface/MES.Service/resources/TopSdk.dll
Binary files differ
diff --git a/StandardInterface/MES.Service/service/QcIssueResult/QcIssueResultManager.cs b/StandardInterface/MES.Service/service/QcIssueResult/QcIssueResultManager.cs
index e92cf28..8700d85 100644
--- a/StandardInterface/MES.Service/service/QcIssueResult/QcIssueResultManager.cs
+++ b/StandardInterface/MES.Service/service/QcIssueResult/QcIssueResultManager.cs
@@ -19,6 +19,10 @@
 using Newtonsoft.Json;
 using Oracle.ManagedDataAccess.Client;
 using System.Data;
+using System.Reflection;
+using System.Text;
+using DingTalk.Api;
+using System.Net.Http;
 
 namespace MES.Service.service.QcIssueResult;
 
@@ -56,8 +60,8 @@
         AlibabaCloud.SDK.Dingtalkoauth2_1_0.Client client = CreateClient1();
         AlibabaCloud.SDK.Dingtalkoauth2_1_0.Models.GetAccessTokenRequest getAccessTokenRequest = new AlibabaCloud.SDK.Dingtalkoauth2_1_0.Models.GetAccessTokenRequest
         {
-            AppKey = "dingyzos0r1bizj7g6lr",
-            AppSecret = "-HP4RvK2OUbqhG3iBUpd_TPe5MZRj8cfLc0b8Skt8rhC3I38kVLY9SS8P3kLWFcH",
+            AppKey = "ding8nmegrbi29a78ze0",
+            AppSecret = "CwWeKXzItBJktsVhGoZi73Ts79bP8qp3FuLmS5PtJgNmMxrWFaqdQQTY0RqCRQSC",
         };
 
         try
@@ -124,6 +128,85 @@
         }
     }
 
+    /**
+    * 鑾峰彇userid
+    * @return string 杩斿洖鍚姩缁撴灉
+    */
+   public  HttpClient _httpClient;
+    public string DingTalkService()
+    {
+        _httpClient = new HttpClient();
+        _httpClient.Timeout = TimeSpan.FromSeconds(30);
+        return "1";
+    }
+
+    public async Task<string> GetUserId(string phone)
+    {
+        // 鍙傛暟楠岃瘉
+        if (string.IsNullOrWhiteSpace(phone))
+            throw new ArgumentException("鎵嬫満鍙蜂笉鑳戒负绌�", nameof(phone));
+
+        // 鑾峰彇璁块棶浠ょ墝
+        string accessToken = GetToken();
+
+        // 璋冪敤鐜版湁鏂规硶
+        return await GetUserIdByMobile(accessToken, phone);
+    }
+
+  
+
+    public async Task<string> GetUserIdByMobile(string accessToken, string mobile)
+    {
+        // 鍙傛暟楠岃瘉
+        if (string.IsNullOrWhiteSpace(accessToken))
+            throw new ArgumentException("Access token cannot be empty", nameof(accessToken));
+
+        if (string.IsNullOrWhiteSpace(mobile) || !IsValidMobile(mobile))
+            throw new ArgumentException("Invalid mobile number", nameof(mobile));
+
+        try
+        {
+            // 鏋勯�犺姹俇RL
+            var url = $"https://oapi.dingtalk.com/topapi/v2/user/getbymobile?access_token={accessToken}";
+
+            string m = DingTalkService();
+
+            // 鏋勯�犺姹備綋
+            var requestBody = new { mobile };
+            var jsonContent = JsonConvert.SerializeObject(requestBody);
+            var content = new StringContent(jsonContent, Encoding.UTF8, "application/json");
+
+            // 鍙戦�佽姹�
+            var response = await _httpClient.PostAsync(url, content);
+
+            // 澶勭悊鍝嶅簲
+            response.EnsureSuccessStatusCode();
+
+            var responseBody = await response.Content.ReadAsStringAsync();
+            var result = JsonConvert.DeserializeObject<DingTalkResponse>(responseBody);
+
+            // 澶勭悊涓氬姟閫昏緫閿欒
+            if (result?.Errcode != 0)
+                throw new DingTalkApiException(result?.Errcode ?? -1, result?.Errmsg ?? "Unknown error");
+
+            return result?.Result?.UserId ?? throw new InvalidOperationException("User ID not found in response");
+        }
+        catch (HttpRequestException ex)
+        {
+            throw new DingTalkApiException(500, $"HTTP request failed: {ex.Message}", ex);
+        }
+        catch (JsonException ex)
+        {
+            throw new DingTalkApiException(500, $"JSON parsing failed: {ex.Message}", ex);
+        }
+    }
+
+    private bool IsValidMobile(string mobile)
+    {
+        // 绠�鍗曠殑鎵嬫満鍙锋牸寮忛獙璇�
+        return !string.IsNullOrEmpty(mobile) && mobile.Length == 11 && mobile.StartsWith("1");
+    }
+
 
     /**
      * 鍚姩閽夐拤宸ヤ綔娴佸疄渚�
@@ -132,19 +215,21 @@
 
     public string GetProcessNo(GetQcIssueResultDetail getQcIssueResultDetail)
     {
-
         var db = SqlSugarHelper.GetInstance();
-        var mapping = db.Queryable<DingNameCode>()
-            .Where(t => t.DingDingName == getQcIssueResultDetail.Fname)
+
+        var stafflist = db.Queryable<DingNameCode>()
+            .Where(t => t.STAFF_NO == getQcIssueResultDetail.Fname)
             .Select(t => new DingNameCode
             {
-               DingDingCode=t.DingDingCode,
+                STAFF_NAME = t.STAFF_NAME,
+                PHONE_NUMBER = t.PHONE_NUMBER
             })
             .ToList();
-        if (mapping.Any())
-        {
-            string UserId = mapping.FirstOrDefault().DingDingCode;
 
+        if (stafflist.Any())
+        {
+            Task<string> task = GetUserId(stafflist[0].PHONE_NUMBER);
+            string UserId = task.Result;
 
             // 浣跨敤 JSON 搴忓垪鍖栬緭鍑哄璞$殑璇︾粏鍐呭
             string getQcIssueResultDetailJson = JsonConvert.SerializeObject(getQcIssueResultDetail, Formatting.Indented);
@@ -199,7 +284,7 @@
             AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues formComponentValues8 = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues
             {
                 Name = "SignatureField_SKF9Q82DZUO0",
-                Value = getQcIssueResultDetail.Fname,
+                Value = stafflist[0].STAFF_NAME,
             };
             AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues formComponentValues9 = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues
             {
@@ -245,17 +330,17 @@
             {
                 ActionerKey = "null",
                 ActionerUserIds = new List<string>
-            {
-               UserId
-            },
+                {
+                   UserId
+                },
             };
             AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestApprovers approvers0 = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestApprovers
             {
                 ActionType = "OR",
                 UserIds = new List<string>
-            {
-                UserId
-            },
+                {
+                    UserId
+                },
             };
 
 
@@ -265,22 +350,22 @@
                 ProcessCode = "PROC-BBA5632D-DC7C-4267-A3E2-757E2B7023BC",
                 DeptId = 1,
                 FormComponentValues = new List<AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues>
-            {
-                 formComponentValues1,formComponentValues2,formComponentValues3, formComponentValues4, formComponentValues5, formComponentValues6, formComponentValues7, formComponentValues8,
-                 formComponentValues9,formComponentValues10, formComponentValues11, formComponentValues12, formComponentValues13, formComponentValues14
-            },
+                {
+                     formComponentValues1,formComponentValues2,formComponentValues3, formComponentValues4, formComponentValues5, formComponentValues6, formComponentValues7, formComponentValues8,
+                     formComponentValues9,formComponentValues10, formComponentValues11, formComponentValues12, formComponentValues13, formComponentValues14
+                },
                 TargetSelectActioners = new List<AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestTargetSelectActioners>
-            {
-                targetSelectActioners0
-            },
+                {
+                    targetSelectActioners0
+                },
                 Approvers = new List<AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestApprovers>
-            {
-                approvers0
-            },
+                {
+                    approvers0
+                },
                 CcList = new List<string>
-            {
-               UserId
-            },
+                {
+                   UserId
+                },
                 CcPosition = "START",
 
             };
@@ -307,8 +392,9 @@
                 return $"Exception: {_err.Message}";
             }
         }
-        else {
-            return "鎮ㄤ笉鏄叕鍙告垚鍛樻垨杩樻湭琚姞鍏ュ埌鏁版嵁搴撲腑鎴栧悕瀛楀~鍐欓敊璇紝鎬讳箣鏈壘鍒板尮閰嶇殑鐢ㄦ埛淇℃伅";
+        else
+        {
+            return "鏌ヤ笉鍒版偍鐨勬墜鏈哄彿";
         }
     }
 
@@ -513,4 +599,40 @@
     }
 
    
+}
+
+// 鍝嶅簲妯″瀷
+public class DingTalkResponse
+{
+    [JsonProperty("errcode")]
+    public int Errcode { get; set; }
+
+    [JsonProperty("errmsg")]
+    public string Errmsg { get; set; }
+
+    [JsonProperty("result")]
+    public UserResult Result { get; set; }
+}
+
+public class UserResult
+{
+    [JsonProperty("userid")]
+    public string UserId { get; set; }
+}
+
+// 鑷畾涔夊紓甯�
+public class DingTalkApiException : Exception
+{
+    public int ErrorCode { get; }
+
+    public DingTalkApiException(int errorCode, string message) : base(message)
+    {
+        ErrorCode = errorCode;
+    }
+
+    public DingTalkApiException(int errorCode, string message, Exception innerException)
+        : base(message, innerException)
+    {
+        ErrorCode = errorCode;
+    }
 }
\ No newline at end of file
diff --git a/StandardInterface/MESApplication/Controllers/QcIssueResult/QcIssueResultController.cs b/StandardInterface/MESApplication/Controllers/QcIssueResult/QcIssueResultController.cs
index 070e9d6..d44123c 100644
--- a/StandardInterface/MESApplication/Controllers/QcIssueResult/QcIssueResultController.cs
+++ b/StandardInterface/MESApplication/Controllers/QcIssueResult/QcIssueResultController.cs
@@ -44,18 +44,18 @@
             // 璋冪敤 QcIssueResultManager 涓殑 GetProcessNo 鏂规硶鏉ュ惎鍔ㄩ拤閽夊伐浣滄祦瀹炰緥
             string result = m.GetProcessNo(getQcIssueResultDetail);
 
-            string getLaboratoryDetailsJson = JsonConvert.SerializeObject(getQcIssueResultDetail, Formatting.Indented);
-            Debug.WriteLine("getQcIssueResultDetail: " + getLaboratoryDetailsJson);
+            //string getLaboratoryDetailsJson = JsonConvert.SerializeObject(getQcIssueResultDetail, Formatting.Indented);
+            //Debug.WriteLine("getQcIssueResultDetail: " + getLaboratoryDetailsJson);
 
-            string jsonPart = result.Substring(result.IndexOf("{"));
-            JObject jsonObject = JObject.Parse(jsonPart);
-            // 鎻愬彇instanceId鐨勫��
-            string instanceId = jsonObject["InstanceId"].ToString();
+            //string jsonPart = result.Substring(result.IndexOf("{"));
+            //JObject jsonObject = JObject.Parse(jsonPart);
+            //// 鎻愬彇instanceId鐨勫��
+            //string instanceId = jsonObject["InstanceId"].ToString();
 
-            dynamic resultInfos = new ExpandoObject();
-            string ProcessNo = instanceId;
-            var save = m.SaveProcessNo(getQcIssueResultDetail.ReleaseNo, instanceId);
-            resultInfos.tbBillList = save;
+            //dynamic resultInfos = new ExpandoObject();
+            //string ProcessNo = instanceId;
+            //var save = m.SaveProcessNo(getQcIssueResultDetail.ReleaseNo, instanceId);
+            //resultInfos.tbBillList = save;
 
             return Ok(result);
         }

--
Gitblit v1.9.3