From a4501b0013153ee105d65a8b9ae34f3998d60904 Mon Sep 17 00:00:00 2001
From: huawei <huawei@2214094776>
Date: 星期一, 01 十二月 2025 15:16:41 +0800
Subject: [PATCH] Merge branch 'master' of http://43.142.96.171:8080/r/~cnf/JH/JH_MesService

---
 WebApi/Gs.Sys/Services/FmController.cs |  106 +++++++++++++++++++++++---
 WebApi/Gs.Toolbox/UtilityHelper.cs     |    4 
 WebApi/Gs.Toolbox/InterfaceUtil.cs     |   70 +++++++++++++++--
 WebApi/Gs.HostIIS/appsettings.json     |    2 
 4 files changed, 159 insertions(+), 23 deletions(-)

diff --git a/WebApi/Gs.HostIIS/appsettings.json b/WebApi/Gs.HostIIS/appsettings.json
index 4674b65..7526a1b 100644
--- a/WebApi/Gs.HostIIS/appsettings.json
+++ b/WebApi/Gs.HostIIS/appsettings.json
@@ -6,7 +6,6 @@
     }
   },
   "AllowedHosts": "*",
-  /*"ConnectionStrings": "Data Source=192.168.1.146;Initial Catalog=TEST_MES;User ID=testUser;Password =qixi1qaz@WSXtest",*/
   "ConnectionStrings": "Data Source=192.168.8.8;Initial Catalog=YS_MES;User ID=sa;Password =JianHui@2025",
   "TestErpUrl": "http://60.204.140.168:8080//kingdee/billWriteIn",
   "TestErpUrl2": "http://60.204.140.168:8080//kingdee/transferDirect",
@@ -14,6 +13,7 @@
   "TestErpUrl4": "http://60.204.140.168:8080//kingdee/billReload",
   "TestErpUrl5": "http://60.204.140.168:8888//kingdee/billWriteIn",
   "TestErpUrl6": "http://60.204.140.168:8888//kingdee/transferDirect",
+  "TestErpUrl101": "http://60.204.140.168:8080//kingdee/deleteBill",
   "ProductionErpUrl": "http://192.168.1.149:8066/WebService1.asmx/mesToErpinfoFormal",
   "ServicesPath": "Services",
   "LogPath": "logs",
diff --git a/WebApi/Gs.Sys/Services/FmController.cs b/WebApi/Gs.Sys/Services/FmController.cs
index 88a8cc0..d0374b1 100644
--- a/WebApi/Gs.Sys/Services/FmController.cs
+++ b/WebApi/Gs.Sys/Services/FmController.cs
@@ -1,4 +1,4 @@
-锘縰sing Gs.Toolbox;
+锘匡豢锘匡豢锘匡豢锘縰sing Gs.Toolbox;
 using Gs.Toolbox.ApiCore.Abstract.Mvc;
 using Gs.Toolbox.ApiCore.Common.Mvc;
 using Gs.Toolbox.ApiCore.Group;
@@ -257,6 +257,14 @@
                 string keyGuid = model.keyGuid;
                 string keyNo = model.keyNo;
                 string idtype = model.idtype;//杩欎釜浠呬粎鏄洿鏂板伐鍗曠姸鎬佺殑鏃跺�欐湁
+                string keyMeth = model.keyMeth;
+
+                // 鐗规畩澶勭悊锛歞elete鎿嶄綔浣跨敤TestErpUrl101鎺ュ彛
+                if (keyMeth != null && keyMeth.Equals("delete", StringComparison.OrdinalIgnoreCase))
+                {
+                    (_rtnInt, _rtnStr) = InterfaceUtil.HttpPostErp(_erpJson, keyUserGuid, keyGuid, keyNo, 101);
+                }
+                else
                 if (string.IsNullOrEmpty(idtype))
                 {
                     (_rtnInt, _rtnStr) = InterfaceUtil.HttpPostErp(_erpJson, keyUserGuid, keyGuid, keyNo);
@@ -286,6 +294,7 @@
             {
                 Gs.Toolbox.LogHelper.Debug(this.ToString(), "Fm SendErp:" + ex.Message);
                 return "鍙戦�乪rp澶辫触:" + ex.Message;
+         
             }
             if (_rtnInt <= 0)
             {
@@ -309,17 +318,16 @@
             string keyMeth = model.keyMeth;
             string keyNo = model.keyNo;
             string idtype = model.idtype;//杩欎釜浠呬粎鏄洿鏂板伐鍗曠姸鎬佺殑鏃跺�欐湁
-            if (keyMeth.ToUpper() == "delete".ToUpper())
-                return "";
+ 
             try
             {
                 System.Data.DataSet dset = new System.Data.DataSet();
                 SqlParameter[] parameters =
                       {
-                       new("@inOrderGuid", keyGuid),
-                       new("@inEdtUserGuid", keyUserGuid),
-                       new("@keyMeth", keyMeth.ToLower()),
-                   };
+               new("@inOrderGuid", keyGuid),
+               new("@inEdtUserGuid", keyUserGuid),
+               new("@keyMeth", keyMeth.ToLower()),
+           };
                 dset = DbHelperSQL.RunProcedure(keyProduce, parameters, "0");
                 if (dset == null)
                     return "";
@@ -327,12 +335,82 @@
                     return "";
                 if (dset.Tables[0].Rows.Count <= 0)
                     return "";
-                //杩欐槸鏅�氱殑鎺ュ彛
+
+                // 杩欐槸鏅�氱殑鎺ュ彛
                 string _mesGuid = dset.Tables[0].Rows[0][0].ToString();
                 dynamic _datajson = new ExpandoObject();
-                if (dset.Tables.Count > 1)
+
+               // delete鏂规硶涓撳睘澶勭悊閫昏緫
+                 if (keyMeth.Equals("delete", StringComparison.OrdinalIgnoreCase))
+                 {
+                     try
+                     {
+                         _datajson = new ExpandoObject();
+                         List<string> deleteLst = new List<string>();
+                         
+                         // 鎻愬彇billType
+                         try
+                         {
+                             if (dset.Tables.Count > 0 && dset.Tables[0]?.Rows.Count > 0)
+                             {
+                                 string billType = dset.Tables[0].Rows[0][0]?.ToString() ?? "";
+                                 ((IDictionary<string, object>)_datajson)["billType"] = billType;
+                             }
+                         }
+                         catch (Exception ex)
+                         {
+                             Gs.Toolbox.LogHelper.Debug(this.ToString(), $"鎻愬彇billType寮傚父锛歿ex.Message}");
+                         }
+                         
+                         // 鎻愬彇BILLNO鍒楄〃
+                         if (dset.Tables.Count > 1 && dset.Tables[1]?.Rows.Count > 0)
+                         {
+                             DataTable table1 = dset.Tables[1];
+                             string targetColumn = "BILLNO";
+                             bool hasColumn = table1.Columns.Contains(targetColumn);
+
+                             foreach (DataRow row in table1.Rows)
+                             {
+                                 if (row == null) continue;
+                                 
+                                 string billNo = "";
+                                 try
+                                 {
+                                     if (hasColumn)
+                                     {
+                                         billNo = row[targetColumn]?.ToString()?.Trim() ?? "";
+                                     }
+                                     else if (table1.Columns.Count > 0)
+                                     {
+                                         billNo = row[table1.Columns[0].ColumnName]?.ToString()?.Trim() ?? "";
+                                     }
+                                 }
+                                 catch { }
+                                 
+                                 if (!string.IsNullOrEmpty(billNo))
+                                 {
+                                     deleteLst.Add(billNo);
+                                 }
+                             }
+                         }
+
+                         // 鎸傝浇鍒発eyChild鎴栭粯璁ら敭
+                         string targetKey = !string.IsNullOrEmpty(keyChild) ? keyChild : "billItems";
+                         ((IDictionary<string, object>)_datajson)[targetKey] = deleteLst;
+                         
+                       //  Gs.Toolbox.LogHelper.Debug(this.ToString(), $"delete鍒嗘敮锛氭彁鍙杮deleteLst.Count}鏉℃暟鎹�");
+                     }
+                     catch (Exception ex)
+                     {
+                         Gs.Toolbox.LogHelper.Debug(this.ToString(), $"delete鍒嗘敮寮傚父锛歿ex.Message}");
+                         _datajson = new ExpandoObject();
+                     }
+                 }
+ 
+                // 鍘熸湁閫昏緫锛氶潪delete鏂规硶锛屾墽琛屽巻鍙叉嫾鎺ラ�昏緫 
+                else if (dset.Tables.Count > 1)
                 {
-                    //杩欐槸杩欐槸鏅�氱殑鎺ュ彛閲岀殑缁撴锛岀粨鏋勫拰鍏跺畠涓嶄竴鏍�
+                    // 杩欐槸鏅�氱殑鎺ュ彛閲岀殑缁撴锛岀粨鏋勫拰鍏跺畠涓嶄竴鏍�
                     if (keyMeth.ToLower() == "toclose".ToLower() || keyMeth.ToLower() == "closure".ToLower() || keyMeth.ToLower() == "unfinish")
                     {
                         _datajson = dset.Tables[1].Rows[0].RowToDynamic();
@@ -344,8 +422,10 @@
                         ((IDictionary<string, object>)_datajson)[keyChild] = _lst;
                     }
                 }
-                return JsonConvert.SerializeObject(_datajson); 
-                //杩欐槸璁㈠崟鍥炰紶鏍囪瘑
+
+                return JsonConvert.SerializeObject(_datajson);
+
+                // 杩欐槸璁㈠崟鍥炰紶鏍囪瘑锛堝師鏈夋敞閲婁唬鐮佸畬鍏ㄤ繚鐣欙級
                 /*List<dynamic> _datajson22 = new List<dynamic>();
                 dynamic _ob = new ExpandoObject();
                 _ob.ENTRY = dset.Tables[0].TableToDynamicList();
@@ -357,6 +437,8 @@
                     datajson = JsonConvert.SerializeObject(_datajson22),
                 };
                 return JsonConvert.SerializeObject(_obj22);*/
+            
+            
             }
             catch (Exception ex)
             {
diff --git a/WebApi/Gs.Toolbox/InterfaceUtil.cs b/WebApi/Gs.Toolbox/InterfaceUtil.cs
index 006c27a..f928d30 100644
--- a/WebApi/Gs.Toolbox/InterfaceUtil.cs
+++ b/WebApi/Gs.Toolbox/InterfaceUtil.cs
@@ -1,4 +1,4 @@
-锘縰sing Newtonsoft.Json;
+锘匡豢锘縰sing Newtonsoft.Json;
 using System.Data.SqlClient;
 using System.Dynamic;
 using System.Net;
@@ -47,6 +47,10 @@
         {
             url = AppSettingsHelper.getValueByKey("TestErpUrl6");
         }
+        else if (urlType == 101)
+        {
+            url = AppSettingsHelper.getValueByKey("TestErpUrl101");
+        }
         HttpWebRequest request = null;
         StreamWriter requestStream = null;
         WebResponse response = null;
@@ -89,9 +93,36 @@
         //{"msg":"鎿嶄綔鎴愬姛","code":200,"data":{"number":"CGSL168397","code":"200","id":"268781"}}
         if (_rtn != -1)
         {
-            Result _result = JsonConvert.DeserializeObject<Result>(responseStr);
-            if ("200".Equals(_result.code))
-                _rtn = 1;
+            try
+            {
+                Result _result = JsonConvert.DeserializeObject<Result>(responseStr);
+                
+                // 銆愪紭鍏堝垽鏂�慸ata.code锛圗RP鐪熸鐨勫鐞嗙粨鏋滐級
+                if (_result?.data != null && "200".Equals(_result.data.code))
+                {
+                    _rtn = 1;
+                    LogHelper.Debug(url, $"ERP澶勭悊鎴愬姛锛宒ata.code=200, number={_result.data.number}, id={_result.data.id}");
+                }
+                // 銆愰檷绾у垽鏂�戝鏋渄ata涓虹┖锛屽垯鍒ゆ柇澶栧眰code锛堝吋瀹规棫鎺ュ彛锛�
+               /* else if (_result != null && "200".Equals(_result.code))
+                {
+                    _rtn = 1;
+                    LogHelper.Debug(url, $"ERP澶栧眰杩斿洖鎴愬姛锛宑ode=200锛堟棤data灞傦紝鍙兘鏄棫鎺ュ彛锛�");
+                }*/
+                else
+                {
+                    _rtn = -1;
+                    string errorMsg = _result?.data?.code != null 
+                        ? $"ERP澶勭悊澶辫触锛宒ata.code={_result.data.code}" 
+                        : $"ERP澶勭悊澶辫触锛屽灞俢ode={_result?.code}";
+                    LogHelper.Debug(url, errorMsg + $", msg={_result?.msg}, responseStr={responseStr}");
+                }
+            }
+            catch (Exception ex)
+            {
+                _rtn = -1;
+                LogHelper.Debug(url, $"ERP杩斿洖鏁版嵁瑙f瀽澶辫触锛歿ex.Message}, responseStr={responseStr}");
+            }
         }
         sbLog.Append("," + DateTime.Now.ToString() + "缁撴潫鍙戦��");
         if (_rtn > 0)
@@ -126,11 +157,34 @@
 public class Result
 {
     /// <summary>
-    /// 200鎴愬姛锛屽惁鍒欏け璐�
+    /// 200鎴愬姛锛屽惁鍒欏け璐ワ紙澶栧眰code锛�
     /// </summary>
-    /// 
-    
     public string? msg { get; set; }
     public string? code { get; set; }
-   // public string? data { get; set; }
+    
+    /// <summary>
+    /// data灞傦紝鍖呭惈鐪熸鐨凟RP澶勭悊缁撴灉
+    /// </summary>
+    public ErpData? data { get; set; }
+}
+
+/// <summary>
+/// ERP杩斿洖鐨刣ata灞傛暟鎹粨鏋�
+/// </summary>
+public class ErpData
+{
+    /// <summary>
+    /// ERP鍗曟嵁缂栧彿
+    /// </summary>
+    public string? number { get; set; }
+    
+    /// <summary>
+    /// ERP澶勭悊缁撴灉浠g爜锛�"200"鎴愬姛锛�
+    /// </summary>
+    public string? code { get; set; }
+    
+    /// <summary>
+    /// ERP鍗曟嵁ID
+    /// </summary>
+    public string? id { get; set; }
 }
\ No newline at end of file
diff --git a/WebApi/Gs.Toolbox/UtilityHelper.cs b/WebApi/Gs.Toolbox/UtilityHelper.cs
index 0b53232..35f3b58 100644
--- a/WebApi/Gs.Toolbox/UtilityHelper.cs
+++ b/WebApi/Gs.Toolbox/UtilityHelper.cs
@@ -1,4 +1,4 @@
-锘縰sing System.Data;
+using System.Data;
 using System.Dynamic;
 using System.Security.Cryptography;
 using System.Text;
@@ -120,7 +120,7 @@
         sb.Append(" exec prc_log_create '" + _userGuid + "','" + _abtGuid +
                   "','" + _table + "','" + _logTxt + "' ");
         return sb;
-    }
+    }  
      
     /// <summary>
     ///     鍒ゆ柇鏄笉鏄痝uid

--
Gitblit v1.9.3