kyy
2025-12-01 f0ac4ec65279aa31d568b933afeb8237bee73a72
WebApi/Gs.Sys/Services/FmController.cs
@@ -1,15 +1,16 @@
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.Dynamic;
using Gs.Toolbox;
using Gs.Toolbox;
using Gs.Toolbox.ApiCore.Abstract.Mvc;
using Gs.Toolbox.ApiCore.Common.Mvc;
using Gs.Toolbox.ApiCore.Group;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using NetTaste;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.Dynamic;
using static Gs.Toolbox.UtilityHelper;
namespace Gs.Sys.Services
@@ -24,8 +25,7 @@
        public FmController(IHttpContextAccessor httpContextAccessor)
        {
            _http = httpContextAccessor;
            (_userCode, _userGuid, _orgFids) =
                GetUserGuidAndOrgGuid(_http);
            (_userCode, _userGuid, _orgFids) = GetUserGuidAndOrgGuid(_http);
        }
        #region 版面
@@ -209,7 +209,6 @@
            return ReturnDto<string>.QuickReturn(strMsg, ReturnCode.Success, "读取成功!");
        }
        #endregion
        private int? chkAdmin()
@@ -244,26 +243,58 @@
            //string keyChild = model.keyChild;任务子节点名
            //string keyMeth = model.keyMeth;方法名
            //string keyNo = model.keyNo;单据编号
            //string idtype = model.idtype;推送类型
            int _rtnInt = 0;
            string _rtnStr = "";
            try
            {
                string _erpJson = GetErpParam(model);
                if (_erpJson.Length <= 0)
                {
                    return "-1读取erp参数失败!";
                }
                string keyUserGuid = model.keyUserGuid;
                string keyGuid = model.keyGuid;
                string keyNo = model.keyNo;
                string idtype = model.idtype;//这个仅仅是更新工单状态的时候有
                if (string.IsNullOrEmpty(idtype))
                    (_rtnInt, _rtnStr) = InterfaceUtil.HttpPostErp(_erpJson, keyUserGuid, keyGuid, keyNo);
                string keyMeth = model.keyMeth;
                // 特殊处理:delete操作使用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);
                }
                else if(idtype=="2")
                {
                    (_rtnInt, _rtnStr) = InterfaceUtil.HttpPostErp(_erpJson, keyUserGuid, keyGuid, keyNo, 2);
                }
                else if(idtype == "3")
                {
                    (_rtnInt, _rtnStr) = InterfaceUtil.HttpPostErp(_erpJson, keyUserGuid, keyGuid, keyNo, 3);
                }
                else if (idtype == "4")
                {
                    (_rtnInt, _rtnStr) = InterfaceUtil.HttpPostErp(_erpJson, keyUserGuid, keyGuid, keyNo, 4);
                }
                else if (idtype == "5")
                {
                    (_rtnInt, _rtnStr) = InterfaceUtil.HttpPostErp(_erpJson, keyUserGuid, keyGuid, keyNo, 5);
                }
                else if (idtype == "6")
                {
                    (_rtnInt, _rtnStr) = InterfaceUtil.HttpPostErp(_erpJson, keyUserGuid, keyGuid, keyNo, 6);
                }
            }
            catch (Exception ex)
            {
                Gs.Toolbox.LogHelper.Debug(this.ToString(), "Fm SendErp:" + ex.Message);
                return "发送erp失败:" + ex.Message;
            }
            if (_rtnInt <= 0)
            {
@@ -287,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 "";
@@ -305,36 +335,98 @@
                    return "";
                if (dset.Tables[0].Rows.Count <= 0)
                    return "";
                //这是普通的接口
                if (string.IsNullOrEmpty(idtype))
                // 这是普通的接口
                string _mesGuid = dset.Tables[0].Rows[0][0].ToString();
                dynamic _datajson = new ExpandoObject();
               // 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);
                                 }
                             }
                         }
                         // 挂载到keyChild或默认键
                         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)
                {
                    string _mesGuid = dset.Tables[0].Rows[0][0].ToString();
                    dynamic _datajson = new ExpandoObject();
                    if (dset.Tables.Count > 1)
                    // 这是普通的接口里的结案,结构和其它不一样
                    if (keyMeth.ToLower() == "toclose".ToLower() || keyMeth.ToLower() == "closure".ToLower() || keyMeth.ToLower() == "unfinish")
                    {
                        //这是这是普通的接口里的结案,结构和其它不一样
                        if (keyMeth.ToLower() == "toclose".ToLower() || keyMeth.ToLower() == "closure".ToLower() || keyMeth.ToLower() == "unfinish")
                        {
                            _datajson = dset.Tables[1].Rows[0].RowToDynamic();
                        }
                        else
                        {
                            _datajson = dset.Tables[0].Rows[0].RowToDynamic();
                            List<dynamic> _lst = dset.Tables[1].TableToDynamicList();
                            ((IDictionary<string, object>)_datajson)[keyChild] = _lst;
                        }
                        _datajson = dset.Tables[1].Rows[0].RowToDynamic();
                    }
                    var _obj = new
                    else
                    {
                        mesid = _mesGuid,
                        taskname = keyTaskName,
                        optype = keyMeth,
                        datajson = JsonConvert.SerializeObject(_datajson),
                    };
                    return JsonConvert.SerializeObject(_obj);
                        _datajson = dset.Tables[0].Rows[0].RowToDynamic();
                        List<dynamic> _lst = dset.Tables[1].TableToDynamicList();
                        ((IDictionary<string, object>)_datajson)[keyChild] = _lst;
                    }
                }
                //这是订单回传标识
                List<dynamic> _datajson22 = new List<dynamic>();
                return JsonConvert.SerializeObject(_datajson);
                // 这是订单回传标识(原有注释代码完全保留)
                /*List<dynamic> _datajson22 = new List<dynamic>();
                dynamic _ob = new ExpandoObject();
                _ob.ENTRY = dset.Tables[0].TableToDynamicList();
                _datajson22.Add(_ob);
@@ -344,7 +436,9 @@
                    idtype = idtype,
                    datajson = JsonConvert.SerializeObject(_datajson22),
                };
                return JsonConvert.SerializeObject(_obj22);
                return JsonConvert.SerializeObject(_obj22);*/
            }
            catch (Exception ex)
            {