啊鑫
2025-09-09 f2b71fe1d3c2b7651d525a5b5bbe66fad602ea06
WebApi/GS.QC/Service/FqcItemsManager.cs
@@ -1,19 +1,17 @@
using Gs.Toolbox;
using System.Data;
using System.Data.SqlClient;
using System.Dynamic;
using System.Text;
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 Newtonsoft.Json.Linq;
using System.Data;
using System.Data.SqlClient;
using System.Dynamic;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using static Gs.Toolbox.UtilityHelper;
namespace GS.QC.Service
{
namespace GS.QC.Service;
    [ApiGroup(ApiGroupNames.QC)]
    public class FqcItemsManager : IRomteService
    {
@@ -62,7 +60,8 @@
            };
            try
            {
                dset = DbHelperSQL.RunProcedure("prc_fqc_items_lst", parameters, "0");
            dset = DbHelperSQL.RunProcedure("prc_fqc_items_lst", parameters,
                "0");
                if (dset != null && dset.Tables.Count > 0 &&
                    dset.Tables[0].Rows.Count > 0) //有数据
                {
@@ -84,6 +83,7 @@
                return ReturnDto<PageList<dynamic>>.QuickReturn(_pglist,
              ReturnCode.Exception, ex.Message);
            }
            return ReturnDto<PageList<dynamic>>.QuickReturn(_pglist,
                ReturnCode.Success, "读取成功");
        }
@@ -104,16 +104,19 @@
            try
            {
                // 查询主表数据
                string sqlMain = $"SELECT A.*,B.Name as OrgName FROM MES_FQC_ITEMS A LEFT JOIN SYS_ORGANIZATION b ON A.OrgId = b.FID  WHERE a.GUID='{guid}'";
            var sqlMain =
                $"SELECT A.*,B.Name as OrgName FROM MES_FQC_ITEMS A LEFT JOIN SYS_ORGANIZATION b ON A.OrgId = b.FID  WHERE a.GUID='{guid}'";
                var dsMain = DbHelperSQL.Query(sqlMain);
                if (dsMain != null && dsMain.Tables.Count > 0 && dsMain.Tables[0].Rows.Count > 0)
            if (dsMain != null && dsMain.Tables.Count > 0 &&
                dsMain.Tables[0].Rows.Count > 0)
                {
                    var dr = dsMain.Tables[0].Rows[0];
                    m = dr.RowToDynamic();
                }
                // 查询子表1数据
                string sqlDetail1 = $"SELECT * FROM MES_FQC_ITEM_DETAIL1 WHERE PID='{guid}' ORDER BY Seq";
            var sqlDetail1 =
                $"SELECT * FROM MES_FQC_ITEM_DETAIL1 WHERE PID='{guid}' ORDER BY Seq";
                var dsDetail1 = DbHelperSQL.Query(sqlDetail1);
                if (dsDetail1 != null && dsDetail1.Tables.Count > 0)
                {
@@ -122,7 +125,8 @@
                }
                // 查询子表2数据
                string sqlDetail2 = $"SELECT * FROM MES_FQC_ITEM_DETAIL2 WHERE PID='{guid}' ORDER BY Seq";
            var sqlDetail2 =
                $"SELECT * FROM MES_FQC_ITEM_DETAIL2 WHERE PID='{guid}' ORDER BY Seq";
                var dsDetail2 = DbHelperSQL.Query(sqlDetail2);
                if (dsDetail2 != null && dsDetail2.Tables.Count > 0)
                {
@@ -136,7 +140,8 @@
            }
            
            if (m != null)
                return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Success, "读取成功!");
            return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Success,
                "读取成功!");
            return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Default, "读取失败!");
        }
@@ -157,13 +162,11 @@
            
            // 处理生产日期,允许为空
            DateTime? productionDate = null;
            if (model.productionDate != null && !string.IsNullOrEmpty(model.productionDate.ToString()))
            {
                if (DateTime.TryParse(model.productionDate.ToString(), out DateTime parsedDate))
                {
        if (model.productionDate != null &&
            !string.IsNullOrEmpty(model.productionDate.ToString()))
            if (DateTime.TryParse(model.productionDate.ToString(),
                    out DateTime parsedDate))
                    productionDate = parsedDate;
                }
            }
            
            string acRe_A = model.acRe_A; // AC/Re A类
            string acRe_B = model.acRe_B; // AC/Re B类
@@ -187,33 +190,27 @@
            
            // 处理检验日期,允许为空
            DateTime? jyDate = null;
            if (model.jyDate != null && !string.IsNullOrEmpty(model.jyDate.ToString()))
            {
                if (DateTime.TryParse(model.jyDate.ToString(), out DateTime parsedJyDate))
                {
        if (model.jyDate != null &&
            !string.IsNullOrEmpty(model.jyDate.ToString()))
            if (DateTime.TryParse(model.jyDate.ToString(),
                    out DateTime parsedJyDate))
                    jyDate = parsedJyDate;
                }
            }
            
            // 处理审核日期,允许为空
            DateTime? checkDate = null;
            if (model.checkDate != null && !string.IsNullOrEmpty(model.checkDate.ToString()))
            {
                if (DateTime.TryParse(model.checkDate.ToString(), out DateTime parsedCheckDate))
                {
        if (model.checkDate != null &&
            !string.IsNullOrEmpty(model.checkDate.ToString()))
            if (DateTime.TryParse(model.checkDate.ToString(),
                    out DateTime parsedCheckDate))
                    checkDate = parsedCheckDate;
                }
            }
            
            // 处理审批日期,允许为空
            DateTime? spDate = null;
            if (model.spDate != null && !string.IsNullOrEmpty(model.spDate.ToString()))
            {
                if (DateTime.TryParse(model.spDate.ToString(), out DateTime parsedSpDate))
                {
        if (model.spDate != null &&
            !string.IsNullOrEmpty(model.spDate.ToString()))
            if (DateTime.TryParse(model.spDate.ToString(),
                    out DateTime parsedSpDate))
                    spDate = parsedSpDate;
                }
            }
            // 构建子表1数据字符串
            var _sb1 = new StringBuilder();
@@ -240,7 +237,9 @@
                                + m.RPB018 + _split
                                + m.RPB019 + _split
                                + m.Remark + _split
                                + (CheckGuid(_guid) ? _guid : Guid.Empty.ToString());
                                 + (CheckGuid(_guid)
                                     ? _guid
                                     : Guid.Empty.ToString());
                if (_sb1.Length > 0)
                    _sb1.Append("~");
                _sb1.Append(_line);
@@ -258,7 +257,9 @@
                                + m.CClass + _split
                                + m.Point + _split
                                + m.Remark + _split
                                + (CheckGuid(_guid) ? _guid : Guid.Empty.ToString());
                              + (CheckGuid(_guid)
                                  ? _guid
                                  : Guid.Empty.ToString());
                if (_sb2.Length > 0)
                    _sb2.Append("~");
                _sb2.Append(_line);
@@ -284,13 +285,17 @@
                            new("@outSum", SqlDbType.Int),
                            new("@outGuid", SqlDbType.UniqueIdentifier),
                            new("@outNo", SqlDbType.NVarChar, 300),
                            new("@inOrderGuid", CheckGuid(guid) ? guid : DBNull.Value),
                        new("@inOrderGuid",
                            CheckGuid(guid) ? guid : DBNull.Value),
                            new("@inFQCNo", fqcNo),
                            new("@inWorkShop", workShop),
                            new("@inItemName", itemName),
                            new("@inItemModel", itemModel),
                            new("@inBrand", brand),
                            new("@inProductionDate", productionDate.HasValue ? (object)productionDate.Value : DBNull.Value),
                        new("@inProductionDate",
                            productionDate.HasValue
                                ? productionDate.Value
                                : DBNull.Value),
                            new("@inAcRe_A", acRe_A),
                            new("@inAcRe_B", acRe_B),
                            new("@inAcRe_C", acRe_C),
@@ -309,9 +314,14 @@
                            new("@inJyUser", jyUser),
                            new("@inCheckUser", checkUser),
                            new("@inSpUser", spUser),
                            new("@inJyDate", jyDate.HasValue ? (object)jyDate.Value : DBNull.Value),
                            new("@inCheckDate", checkDate.HasValue ? (object)checkDate.Value : DBNull.Value),
                            new("@inSpDate", spDate.HasValue ? (object)spDate.Value : DBNull.Value),
                        new("@inJyDate",
                            jyDate.HasValue ? jyDate.Value : DBNull.Value),
                        new("@inCheckDate",
                            checkDate.HasValue
                                ? checkDate.Value
                                : DBNull.Value),
                        new("@inSpDate",
                            spDate.HasValue ? spDate.Value : DBNull.Value),
                            new("@inEdtUserGuid", _userGuid),
                            new("@inDetail1List", _sb1.ToString()),
                            new("@inDetail2List", _sb2.ToString())
@@ -341,9 +351,12 @@
                    }
                }
            }
            if (mObj.outSum <= 0)
                return ReturnDto<dynamic>.QuickReturn(mObj, ReturnCode.Exception, mObj.outMsg);
            return ReturnDto<dynamic>.QuickReturn(mObj, ReturnCode.Success, mObj.outMsg);
            return ReturnDto<dynamic>.QuickReturn(mObj, ReturnCode.Exception,
                mObj.outMsg);
        return ReturnDto<dynamic>.QuickReturn(mObj, ReturnCode.Success,
            mObj.outMsg);
        }
        /// <summary>
@@ -362,7 +375,7 @@
            {
                if (CheckGuid(guid))
                {
                    string sql = $@"
                var sql = $@"
                        DELETE FROM MES_FQC_ITEM_DETAIL1 WHERE PID='{guid}';
                        DELETE FROM MES_FQC_ITEM_DETAIL2 WHERE PID='{guid}';
                        DELETE FROM MES_FQC_ITEMS WHERE GUID='{guid}';";
@@ -381,8 +394,10 @@
                _outMsg = ex.Message;
                _outSum = -1;
            }
            if (_outSum <= 0)
                return ReturnDto<int>.QuickReturn(rtnInt, ReturnCode.Exception, _outMsg);
            return ReturnDto<int>.QuickReturn(rtnInt, ReturnCode.Exception,
                _outMsg);
            return ReturnDto<int>.QuickReturn(rtnInt, ReturnCode.Success, _outMsg);
        }
@@ -405,7 +420,7 @@
            new("@inEveryPageSize", everyPageSize),
            new("@inSortName", sortName),
            new("@inSortOrder", ""),
            new("@inQueryWhere", keyWhere),
            new("@inQueryWhere", keyWhere)
        };
            var dset = new DataSet();
            var _pglist = new PageList<dynamic>
@@ -455,20 +470,21 @@
            };
            try
            {
                var dsMain = DbHelperSQL.RunProcedure("report_cprkjdDetail", parameters, "0");
                if (dsMain != null && dsMain.Tables.Count > 0 && dsMain.Tables[0].Rows.Count > 0)
                {
            var dsMain =
                DbHelperSQL.RunProcedure("report_cprkjdDetail", parameters,
                    "0");
            if (dsMain != null && dsMain.Tables.Count > 0 &&
                dsMain.Tables[0].Rows.Count > 0)
                    m.list = dsMain.Tables[0].TableToDynamicList();
                }
            }
            catch (Exception ex)
            {
                LogHelper.Debug(ToString(), ex.Message);
            }
            if (m != null)
                return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Success, "读取成功!");
            return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Success,
                "读取成功!");
            return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Default, "读取失败!");
        }
    }
}