فهرست منبع

1、新增临时表插入Helper
2、修复复制已审核软床报价无法保存问题
3、修复选择部件配置后带出的明细有误问题

MY 23 ساعت پیش
والد
کامیت
f60c878ad2

+ 1 - 0
JLHHJSvr/Com/Model/u_configure_codemxbom.cs

@@ -34,6 +34,7 @@ namespace JLHHJSvr.Com.Model
         public decimal default_qty { get; set; }
         #region 辅助
         public string pzname { get; set; }
+        public string pznamemx { get; set; }
         public string mtrlname { get; set; }
         public string mtrlcode { get; set; }
         public string mtrlmode { get; set; }

+ 31 - 30
JLHHJSvr/Helper/SoftBedHelper.cs

@@ -216,13 +216,24 @@ namespace JLHHJSvr.Helper
         public List<u_softbed_mx> GetSoftBedMxBomList(List<u_configure_codemx> codeList)
 		{
 			var mxlist = new List<u_softbed_mx>();
-			foreach(var code in codeList)
-			{
-				var resultList = new List<u_configure_codemxbom>();
-				var outputFields = @"pzid,printid,pid,mtrlid,sonscale,sonscale_formula,mng_cost_rate,profit_rate,realqty,cost,sonloss,sonloss_formula,
+
+            #region 临时表
+            var dt = new DataTable();
+            dt.Columns.Add("pzid", typeof(int));
+            dt.Columns.Add("printid", typeof(int));
+            dt.Columns.Add("has_type", typeof(byte));
+            foreach(var code in codeList)
+            {
+                dt.Rows.Add(code.pzid, code.printid,code.has_type);
+            }
+            TempTableHelper.CreateAndBulkInsert(cmd, "#CodeMxBom",dt);
+            #endregion
+
+            var resultList = new List<u_configure_codemxbom>();
+            var outputFields = @"pzid,printid,pid,mtrlid,sonscale,sonscale_formula,mng_cost_rate,profit_rate,realqty,cost,sonloss,sonloss_formula,
 									sondecloss,sondecloss_formula,default_length,default_width,default_qty,mtrlcode,mtrlname,mtrlmode,unit,
-									mtrlsectype,zxmtrlmode,usermtrlmode,price,pzname";
-				var selectStr = @"SELECT u_configure_codemxbom.pzid
+									mtrlsectype,zxmtrlmode,usermtrlmode,price,pzname,pznamemx,has_type";
+            var selectStr = @"SELECT u_configure_codemxbom.pzid
 										,u_configure_codemxbom.printid
 										,u_configure_codemxbom.pid
 										,u_configure_codemxbom.mtrlid
@@ -247,22 +258,22 @@ namespace JLHHJSvr.Helper
 										,u_mtrldef.zxmtrlmode
 										,u_mtrldef.usermtrlmode
 										,u_erpmtrl_price.price
-										,u_configure_codemx.namemx AS pzname
+										,u_configure_codemx.namemx AS pznamemx
+										,u_configure_code.name AS pzname
+										,k.has_type
 									FROM u_configure_codemxbom
+                                    INNER JOIN #CodeMxBom k ON u_configure_codemxbom.pzid = k.pzid AND u_configure_codemxbom.printid = k.printid
 									INNER JOIN u_configure_codemx ON u_configure_codemxbom.pzid = u_configure_codemx.pzid
 										AND u_configure_codemxbom.printid = u_configure_codemx.printid
+                                    INNER JOIN u_configure_code ON u_configure_codemx.pzid = u_configure_code.pzid
 									INNER JOIN u_mtrldef ON u_configure_codemxbom.mtrlid = u_mtrldef.mtrlid
 									LEFT OUTER JOIN u_erpmtrl_price ON u_configure_codemxbom.mtrlid = u_erpmtrl_price.mtrlid";
-				DbSqlHelper.SelectJoin(cmd,selectStr, 
-					"u_configure_codemxbom.pzid = @pzid AND u_configure_codemxbom.printid = @printid",
-					new Dictionary<string, object>() { { "@pzid", code.pzid }, { "@printid",code.printid} }, 
-					"u_configure_codemxbom.pid", outputFields, 0,0,resultList);
+            DbSqlHelper.SelectJoin(cmd, selectStr,null,null,"u_configure_codemxbom.pid", outputFields, 0, 0, resultList);
 
-				foreach(var item in resultList)
-				{
-					mxlist.Add(InitSoftBedMxFromBom(item, code.has_type.Value));
-				}
-			}
+            foreach (var item in resultList)
+            {
+                mxlist.Add(InitSoftBedMxFromBom(item, item.has_type));
+            }
 			return mxlist;
         }
 		/// <summary>
@@ -295,8 +306,9 @@ namespace JLHHJSvr.Helper
 				loss_rate = bomItem.sonloss,
 				cost_price = 0,
 				cost_amt = 0,
-				pzname = bomItem.pzname
-			};
+				pzname = bomItem.pzname,
+				pznamemx = bomItem.pznamemx
+            };
 			return mx;
         }
 		/// <summary>
@@ -1441,18 +1453,15 @@ namespace JLHHJSvr.Helper
             }
 
             int nextPrintId = GetNextSoftBedTemplateCodeMxIdV2(pzid);
-            byte defaultFlag = HasSoftBedTemplateDefaultCodeMxV2(pzid) ? (byte)0 : (byte)1;
-
             var insertMx = new u_configure_codemx()
             {
                 pzid = pzid,
                 printid = nextPrintId,
                 pzcodemx = $"{pzcode}_{FormatCode(nextPrintId, 3)}",
                 namemx = codeMxName,
-                ifdft = defaultFlag,
                 ifuse = 1
             };
-            DbSqlHelper.Insert(cmd, "u_configure_codemx", null, insertMx, "pzid,printid,pzcodemx,namemx,ifdft,ifuse");
+            DbSqlHelper.Insert(cmd, "u_configure_codemx", null, insertMx, "pzid,printid,pzcodemx,namemx,ifuse");
             return nextPrintId;
         }
 
@@ -1611,14 +1620,6 @@ namespace JLHHJSvr.Helper
             return Convert.ToInt32(result) + 1;
         }
 
-        private bool HasSoftBedTemplateDefaultCodeMxV2(int pzid)
-        {
-            cmd.CommandText = @"SELECT COUNT(*) FROM u_configure_codemx WHERE pzid = @pzid AND ifdft = 1";
-            cmd.Parameters.Clear();
-            cmd.Parameters.AddWithValue("@pzid", pzid);
-            return Convert.ToInt32(cmd.ExecuteScalar()) > 0;
-        }
-
         private int GetNextSoftBedTemplateBomPidV2(int pzid, int printid)
         {
             cmd.CommandText = @"SELECT ISNULL(MAX(pid),0) FROM u_configure_codemxbom WHERE pzid = @pzid AND printid = @printid";

+ 2 - 1
JLHHJSvr/JLHHJSvr.csproj

@@ -651,6 +651,7 @@
     <Compile Include="TextLog\SyncLogger.cs" />
     <Compile Include="Tools\AutoInit.cs" />
     <Compile Include="Tools\CalculateFormula.cs" />
+    <Compile Include="Tools\TempTableHelper.cs" />
     <Compile Include="Tools\ListEx.cs" />
     <Compile Include="Tools\ObjectHelper.cs" />
     <Compile Include="Tools\IntervalScheduledTask.cs" />
@@ -707,4 +708,4 @@ if "$(ConfigurationName)" == "Release" Xcopy "$(ProjectDir)\DataStore\" "$(Proje
   <Target Name="AfterBuild">
   </Target>
   -->
-</Project>
+</Project>

+ 165 - 0
JLHHJSvr/Tools/TempTableHelper.cs

@@ -0,0 +1,165 @@
+using System;
+using System.Data;
+using System.Data.SqlClient;
+using System.Text.RegularExpressions;
+
+namespace JLHHJSvr.Tools
+{
+    public static class TempTableHelper
+    {
+        private static readonly Regex TempTableNameRegex = new Regex(@"^#{1,2}[A-Za-z_][A-Za-z0-9_]*$", RegexOptions.Compiled);
+
+        /// <summary>
+        /// Creates a SQL Server temp table from DataTable columns and writes rows by SqlBulkCopy.
+        /// </summary>
+        public static void CreateAndBulkInsert(SqlCommand cmd, string tempTableName, DataTable dataTable, bool recreate = true, int batchSize = 1000, int bulkCopyTimeout = 60)
+        {
+            CheckArguments(cmd, tempTableName, dataTable);
+
+            if (recreate)
+            {
+                DropIfExists(cmd, tempTableName);
+            }
+
+            CreateTempTable(cmd, tempTableName, dataTable);
+            BulkInsert(cmd, tempTableName, dataTable, batchSize, bulkCopyTimeout);
+        }
+
+        /// <summary>
+        /// Writes DataTable rows to an existing SQL Server temp table by SqlBulkCopy.
+        /// </summary>
+        public static void BulkInsert(SqlCommand cmd, string tempTableName, DataTable dataTable, int batchSize = 1000, int bulkCopyTimeout = 60)
+        {
+            CheckArguments(cmd, tempTableName, dataTable);
+
+            using (var sqlBC = cmd.Transaction == null
+                ? new SqlBulkCopy(cmd.Connection)
+                : new SqlBulkCopy(cmd.Connection, SqlBulkCopyOptions.Default, cmd.Transaction))
+            {
+                sqlBC.BatchSize = batchSize;
+                sqlBC.BulkCopyTimeout = bulkCopyTimeout;
+                sqlBC.DestinationTableName = tempTableName;
+
+                foreach (DataColumn column in dataTable.Columns)
+                {
+                    sqlBC.ColumnMappings.Add(column.ColumnName, column.ColumnName);
+                }
+
+                sqlBC.WriteToServer(dataTable);
+            }
+        }
+
+        /// <summary>
+        /// Drops a SQL Server temp table in the current connection when it exists.
+        /// </summary>
+        public static void DropIfExists(SqlCommand cmd, string tempTableName)
+        {
+            CheckCommand(cmd);
+            CheckTempTableName(tempTableName);
+
+            cmd.CommandType = CommandType.Text;
+            cmd.Parameters.Clear();
+            cmd.CommandText = string.Format(
+                "IF OBJECT_ID('tempdb..{0}') IS NOT NULL DROP TABLE {1}",
+                tempTableName.Replace("'", "''"),
+                QuoteName(tempTableName));
+            cmd.ExecuteNonQuery();
+        }
+
+        private static void CreateTempTable(SqlCommand cmd, string tempTableName, DataTable dataTable)
+        {
+            if (dataTable.Columns.Count == 0)
+            {
+                throw new ArgumentException("DataTable must contain at least one column.", "dataTable");
+            }
+
+            string columnSql = string.Empty;
+            foreach (DataColumn column in dataTable.Columns)
+            {
+                if (!string.IsNullOrEmpty(columnSql))
+                {
+                    columnSql += ",";
+                }
+
+                columnSql += string.Format("{0} {1} {2}",
+                    QuoteName(column.ColumnName),
+                    GetSqlType(column),
+                    column.AllowDBNull ? "NULL" : "NOT NULL");
+            }
+
+            cmd.CommandType = CommandType.Text;
+            cmd.Parameters.Clear();
+            cmd.CommandText = string.Format("CREATE TABLE {0} ({1})", QuoteName(tempTableName), columnSql);
+            cmd.ExecuteNonQuery();
+        }
+
+        private static string GetSqlType(DataColumn column)
+        {
+            if (column.ExtendedProperties.ContainsKey("SqlType"))
+            {
+                var sqlType = Convert.ToString(column.ExtendedProperties["SqlType"]);
+                if (!string.IsNullOrWhiteSpace(sqlType))
+                {
+                    return sqlType;
+                }
+            }
+
+            var type = Nullable.GetUnderlyingType(column.DataType) ?? column.DataType;
+            if (type == typeof(string))
+            {
+                return column.MaxLength > 0 && column.MaxLength <= 4000
+                    ? string.Format("NVARCHAR({0})", column.MaxLength)
+                    : "NVARCHAR(MAX)";
+            }
+            if (type == typeof(int)) return "INT";
+            if (type == typeof(long)) return "BIGINT";
+            if (type == typeof(short)) return "SMALLINT";
+            if (type == typeof(byte)) return "TINYINT";
+            if (type == typeof(bool)) return "BIT";
+            if (type == typeof(decimal)) return "DECIMAL(38, 10)";
+            if (type == typeof(double)) return "FLOAT";
+            if (type == typeof(float)) return "REAL";
+            if (type == typeof(DateTime)) return "DATETIME";
+            if (type == typeof(Guid)) return "UNIQUEIDENTIFIER";
+            if (type == typeof(byte[])) return "VARBINARY(MAX)";
+
+            throw new NotSupportedException(string.Format("Unsupported DataColumn type: {0}, column: {1}", column.DataType.FullName, column.ColumnName));
+        }
+
+        private static void CheckArguments(SqlCommand cmd, string tempTableName, DataTable dataTable)
+        {
+            CheckCommand(cmd);
+            CheckTempTableName(tempTableName);
+
+            if (dataTable == null)
+            {
+                throw new ArgumentNullException("dataTable");
+            }
+        }
+
+        private static void CheckCommand(SqlCommand cmd)
+        {
+            if (cmd == null)
+            {
+                throw new ArgumentNullException("cmd");
+            }
+            if (cmd.Connection == null)
+            {
+                throw new ArgumentException("SqlCommand must have a valid SqlConnection.", "cmd");
+            }
+        }
+
+        private static void CheckTempTableName(string tempTableName)
+        {
+            if (string.IsNullOrWhiteSpace(tempTableName) || !TempTableNameRegex.IsMatch(tempTableName))
+            {
+                throw new ArgumentException("Temp table name must start with # or ## and contain only letters, numbers, and underscores.", "tempTableName");
+            }
+        }
+
+        private static string QuoteName(string name)
+        {
+            return "[" + name.Replace("]", "]]") + "]";
+        }
+    }
+}

+ 2 - 1
JLHWEB/src/languages/modules/zh-cn/table.json

@@ -469,7 +469,8 @@
     "minqty": "库存下限",
     "iffp": "生产分配",
     "lmsaleprice": "设定售价",
-    "price_ifpz": "销售价格限价策略"
+    "price_ifpz": "销售价格限价策略",
+    "keyword": "物料编码/名称"
   },
   "u_mtrlware_mx": {
     "barcode": "条码",

+ 9 - 3
JLHWEB/src/views/baseinfo/erpmtrlprice/hooks/index.tsx

@@ -52,13 +52,19 @@ export const useHooks = (t?: any) => {
       title: "物料编码",
       field: "mtrlcode",
       table: "u_mtrldef",
-      type: "html"
+      search: {
+        el: "input",
+        key: "keyword",
+        props: {
+          placeholder: "物料编码/名称"
+        },
+        order: 1
+      }
     },
     {
       title: "物料名称",
       field: "mtrlname",
-      table: "u_mtrldef",
-      type: "html"
+      table: "u_mtrldef"
     },
     {
       title: "英文名称",

+ 1 - 0
JLHWEB/src/views/baseinfo/erpmtrlprice/index.vue

@@ -8,6 +8,7 @@
           title="物料分类"
           label="mtrltype"
           :expand-on-click-node="true"
+          :default-expand-all="false"
           :request-api="getMtrlType"
           @change="changeTreeFilter"
         />

+ 27 - 11
JLHWEB/src/views/quote/softbedQuote/hooks/index.tsx

@@ -1488,6 +1488,14 @@ export const useHooks = (t?: any) => {
       result.softbed.copy_id = result.softbed.softbed_id;
       result.softbed.softbed_id = 0;
       result.softbed.softbed_code = "";
+      result.softbed.flag = 0;
+      result.softbed.create_date = "";
+      result.softbed.create_emp = "";
+      result.softbed.update_date = "";
+      result.softbed.update_emp = "";
+      result.softbed.audit_date = "";
+      result.softbed.audit_emp = "";
+      result.softbed.version = 0;
     }
     //
     state.softBed = [result.softbed];
@@ -1507,15 +1515,18 @@ export const useHooks = (t?: any) => {
     state.nightstandConfigOptions = [];
     state.bedframeConfigOptions = [];
     state.headboardConfigOptions = [];
+    state.partsConfig.headboard = [];
+    state.partsConfig.nightstand = [];
+    state.partsConfig.bedframe = [];
 
     if (result.typeList?.length > 0) {
       for (const item of result.typeList) {
         if (item.contfigtypename.includes("床头柜")) {
-          handleConfigItem(item, state.nightstandConfigOptions, state.partsConfig.nightstand);
+          handleConfigItem(item, state.nightstandConfigOptions, state.partsConfig.nightstand, state.nightStandMx);
         } else if (item.contfigtypename.includes("床架")) {
-          handleConfigItem(item, state.bedframeConfigOptions, state.partsConfig.bedframe);
+          handleConfigItem(item, state.bedframeConfigOptions, state.partsConfig.bedframe, state.bedFrameMx);
         } else if (item.contfigtypename.includes("床头")) {
-          handleConfigItem(item, state.headboardConfigOptions, state.partsConfig.headboard);
+          handleConfigItem(item, state.headboardConfigOptions, state.partsConfig.headboard, state.headBoardMx);
         }
       }
     }
@@ -1607,7 +1618,7 @@ export const useHooks = (t?: any) => {
    * @param targetOption
    * @param targetConfig
    */
-  const handleConfigItem = (item: any, targetOption: any[], targetConfig: any[]) => {
+  const handleConfigItem = (item: any, targetOption: any[], targetConfig: any[], mxList: any[] = []) => {
     if (item.codeList?.length > 0) {
       for (const code of item.codeList) {
         targetOption.push({ pzid: code.pzid, pzname: code.name });
@@ -1618,13 +1629,18 @@ export const useHooks = (t?: any) => {
 
             // 自动添加标准选配值
             if (targetConfig.findIndex(t => t.pzid === code.pzid) === -1) {
-              targetConfig.push(
-                ...code.codeMxList
-                  .filter(t => t.ifdft === 1)
-                  .map(t => {
-                    return { pzid: t.pzid, selectedId: t.printid, selectedValue: t.namemx };
-                  })
-              );
+              const mx = mxList.find(t => Number(t.pzid) > 0 && Number(t.pzmxid) > 0 && Number(t.pzid) === Number(code.pzid));
+              const matched = mx
+                ? code.codeMxList.find(t => Number(t.pzid) === Number(mx.pzid) && Number(t.printid) === Number(mx.pzmxid))
+                : null;
+
+              if (matched) {
+                targetConfig.push({
+                  pzid: matched.pzid,
+                  selectedId: matched.printid,
+                  selectedValue: matched.namemx
+                });
+              }
             }
           }
         }