From 1858d33ed2b1f5013eb2153b32070e0ae6b547f8 Mon Sep 17 00:00:00 2001
From: Cloud Zhang <941187371@qq.com>
Date: 星期四, 16 五月 2024 14:18:25 +0800
Subject: [PATCH] 料站表相关接口

---
 Tiger.IBusiness/MES/SMT/ISmtTool.cs             |    2 
 Tiger.Business/MES/SMT/Biz.SmtTool.cs           |  134 +++++++++++++++++++++++++++++++++
 Tiger.Api/Controllers/MES/SMTController.Tool.cs |   41 ++++++++++
 Tiger.Model.Net/Entitys/MES/SMT_WO_TABLE.cs     |   52 +++++++++---
 4 files changed, 216 insertions(+), 13 deletions(-)

diff --git a/Tiger.Api/Controllers/MES/SMTController.Tool.cs b/Tiger.Api/Controllers/MES/SMTController.Tool.cs
index 7f6bcc9..0e14ad0 100644
--- a/Tiger.Api/Controllers/MES/SMTController.Tool.cs
+++ b/Tiger.Api/Controllers/MES/SMTController.Tool.cs
@@ -1,5 +1,6 @@
 锘縰sing Microsoft.AspNetCore.Mvc;
 using Rhea.Common;
+using System.Collections.Generic;
 using System.Threading.Tasks;
 using Tiger.IBusiness;
 using Tiger.Model;
@@ -28,5 +29,45 @@
             }
             return Ok(response);
         }
+        /// <summary>
+        /// 瀵煎叆宸ュ崟鏂欑珯琛�
+        /// </summary>
+        /// <param name="action"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [Route("api/[controller]/[action]")]
+        public async Task<IActionResult> ValidateTableImport([FromBody]List<smtWoTableIn> action)
+        {
+            ApiAction response = new();
+            try
+            {
+                response = response.GetResponse(await DI.Resolve<ISmtTool>().ValidateTableImport(action));
+            }
+            catch (System.Exception ex)
+            {
+                response = response.GetResponse().CatchExceptionWithLog(ex);
+            }
+            return Ok(response);
+        }
+        /// <summary>
+        /// 淇濆瓨瀵煎叆宸ュ崟鏂欑珯琛�
+        /// </summary>
+        /// <param name="action"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [Route("api/[controller]/[action]")]
+        public async Task<IActionResult> SaveValidateTableImport([FromBody] List<smtWoTableIn> action)
+        {
+            ApiAction response = new();
+            try
+            {
+                response = response.GetResponse(await DI.Resolve<ISmtTool>().SaveValidateTableImport(action));
+            }
+            catch (System.Exception ex)
+            {
+                response = response.GetResponse().CatchExceptionWithLog(ex);
+            }
+            return Ok(response);
+        }
     }
 }
diff --git a/Tiger.Business/MES/SMT/Biz.SmtTool.cs b/Tiger.Business/MES/SMT/Biz.SmtTool.cs
index a9cccb2..d1f1110 100644
--- a/Tiger.Business/MES/SMT/Biz.SmtTool.cs
+++ b/Tiger.Business/MES/SMT/Biz.SmtTool.cs
@@ -13,6 +13,8 @@
 using static Tiger.Business.Biz;
 using Microsoft.AspNetCore.Http;
 using System.Collections;
+using System.Data;
+using Sundial;
 
 namespace Tiger.Business
 {
@@ -55,6 +57,138 @@
                 res.Data = sList;
                 return await Task.FromResult(res);
             }
+            /// <summary>
+            /// 瀵煎叆宸ュ崟鏂欑珯琛�
+            /// </summary>
+            /// <param name="paras"></param>
+            /// <returns></returns>
+            public async Task<ApiAction<List<smtWoTableIn>>> ValidateTableImport(List<smtWoTableIn> paras)
+            {
+                var result = new ApiAction<List<smtWoTableIn>>();
+                try
+                {
+
+                    //DataTable dt = JsonConvert.DeserializeObject<DataTable>(paras.ToString());
+                    List<smtWoTableIn> currentList = new List<smtWoTableIn>();
+                    if (paras.Count > 0)
+                    {
+                        var duplicateWo = paras.GroupBy(p => p.鍏宠仈宸ュ崟鍙�)
+                                         .Where(g => g.Count() > 1)
+                                         .Select(g => g.Key)
+                                         .ToList();
+                        if (duplicateWo.Count() > 0)//瀛樺湪閲嶅鏁版嵁  
+                        {
+                            string WORK_ORDER = string.Empty;
+                            foreach (var item in duplicateWo)
+                            {
+                                WORK_ORDER += item;
+                            }
+                            WORK_ORDER = WORK_ORDER.TrimEnd(';');
+                            result.IsSuccessed = false;
+                            result.Message = $"瀵煎叆鐨勭墿鏂欎腑鏈夐噸澶嶆暟鎹細鍏宠仈宸ュ崟锛歿WORK_ORDER}";
+                        }
+                        else
+                        {
+                            foreach (var item in paras)
+                            {
+                                item.澶勭悊鏂瑰紡 = "鏂板";
+                                item.鍘熷洜 = null;
+                                if (item.鍏宠仈宸ュ崟鍙� == null)
+                                {
+                                    item.澶勭悊鏂瑰紡 = "鏁版嵁寮傚父";
+                                    item.鍘熷洜 += "宸ュ崟鍙风┖鎴栦笉瀛樺湪锛�";
+                                }
+                                if (item.浜у搧缂栫爜 == null)
+                                {
+                                    item.澶勭悊鏂瑰紡 = "鏁版嵁寮傚父";
+                                    item.鍘熷洜 += $"浜у搧缂栫爜涓虹┖锛�";
+                                }
+                                currentList.Add(item);
+                                if (await Db.Queryable<SMT_WO_TABLE>().AnyAsync(x => x.WORK_ORDER == item.鍏宠仈宸ュ崟鍙�))
+                                {
+                                    item.澶勭悊鏂瑰紡 = "淇敼";
+                                    item.鍘熷洜 += $"宸ュ崟{item.鍏宠仈宸ュ崟鍙穧涓庢暟鎹簱閲嶅锛�";
+                                }
+                            }
+                            //for (int i = 0; i < item..Count; i++)
+                            {
+                            }
+
+                        }
+                    }
+                    result.Data = currentList;
+
+                }
+                catch (Exception ex)
+                {
+                    result.CatchException(ex, $"楠岃瘉瀵煎叆鍙戞枡璁″垝鎺掔▼寮傚父");
+                }
+                return result;
+            }
+            /// <summary>
+            /// 瀵煎叆宸ュ崟鏂欑珯琛�
+            /// </summary>
+            /// <param name="paras"></param>
+            /// <returns></returns>
+            public async Task<ApiAction> SaveValidateTableImport(List<smtWoTableIn> paras)
+            {
+                var result = new ApiAction();
+                try
+                {
+
+                    //DataTable dt = JsonConvert.DeserializeObject<DataTable>(paras.ToString());
+                    List<SMT_WO_TABLE> currentList = new List<SMT_WO_TABLE>();
+                    if (paras.Count > 0)
+                    {
+                        var db = Biz.Db;
+                        foreach (var item in paras)
+                        {
+                            var workorder = item.鍏宠仈宸ュ崟鍙�.ToString();
+                            var id = db.Queryable<SMT_WO_TABLE>().Where(s => s.WORK_ORDER == workorder).Select(q => q.ID).First();
+                            SMT_WO_TABLE table = new SMT_WO_TABLE();
+                            table.ID= item.澶勭悊鏂瑰紡?.ToString()=="鏂板"?Guid.NewGuid().ToString():id;
+                            table.CREATE_TIME = DateTime.Now;
+                            table.UPDATE_TIME = DateTime.Now;
+                            table.WORK_ORDER = item.鍏宠仈宸ュ崟鍙�.ToString();
+                            table.PROD_CODE = item.浜у搧缂栫爜?.ToString();
+                            table.ITEM_CODE = item.鐗╂枡缂栫爜?.ToString();
+                            table.SUBITEM_CODE = item.鏇夸唬鏂�?.ToString();
+                            table.UNIT = item.鍗曚綅?.ToString();
+                            table.UNIT_QTY = item.鍗曚綅鐢ㄩ噺.ToInt32();
+                            table.LINE_CODE = item.浜х嚎缂栫爜?.ToString();
+                            table.SMT_CODE = item.璐寸墖鏈虹紪鐮�?.ToString();
+                            table.SMT_STENCIL = item.閽㈢綉缂栫爜?.ToString();
+                            table.SLOT_NO = item.绔欎綅鍙�?.ToString();
+                            table.LOCATION = item.璐寸墖浣嶇疆?.ToString();
+                            table.FEEDER_CODE = item.椋炶揪缂栫爜?.ToString();
+                            table.FEEDER_TYPE = item.椋炶揪绫诲瀷?.ToString();
+                            table.PCB_SURFACE = item.鍔犲伐闈�?.ToString();
+                            table.LOAD_SEQ = item.涓婃枡椤哄簭.ToInt32();
+                            table.REMARK = item.澶囨敞?.ToString();
+                            table.VALIDATION_TYPE = item.澶勭悊鏂瑰紡?.ToString();
+                            table.VALIDATION_RESULT = item.鍘熷洜?.ToString();
+                            currentList.Add(table);
+                        }
+                        var add = currentList.Where(q => q.VALIDATION_TYPE == "鏂板").ToList();
+                        var upd = currentList.Where(q => q.VALIDATION_TYPE == "淇敼").ToList();
+                        if(add.Count > 0)
+                        {
+                            Biz.Db.Insertable(add).ExecuteCommand();
+                        }
+                        if (upd.Count > 0)
+                        {
+                            Biz.Db.Updateable(upd).ExecuteCommand();
+                        }
+
+                    }
+
+                }
+                catch (Exception ex)
+                {
+                    result.CatchException(ex, $"楠岃瘉瀵煎叆宸ュ崟鏂欑珯琛ㄥ紓甯�");
+                }
+                return result;
+            }
         }
     }
 }
diff --git a/Tiger.IBusiness/MES/SMT/ISmtTool.cs b/Tiger.IBusiness/MES/SMT/ISmtTool.cs
index 863ac75..070730d 100644
--- a/Tiger.IBusiness/MES/SMT/ISmtTool.cs
+++ b/Tiger.IBusiness/MES/SMT/ISmtTool.cs
@@ -12,5 +12,7 @@
     public interface ISmtTool
     {
         public Task<ApiAction<List<SMT_WO_TABLE>>> GetNotLoadingMaterial(smtWoTableParams paras);
+        public Task<ApiAction<List<smtWoTableIn>>> ValidateTableImport(List<smtWoTableIn> paras);
+        public Task<ApiAction> SaveValidateTableImport(List<smtWoTableIn> paras);
     }
 }
diff --git a/Tiger.Model.Net/Entitys/MES/SMT_WO_TABLE.cs b/Tiger.Model.Net/Entitys/MES/SMT_WO_TABLE.cs
index 76360ad..67eeac4 100644
--- a/Tiger.Model.Net/Entitys/MES/SMT_WO_TABLE.cs
+++ b/Tiger.Model.Net/Entitys/MES/SMT_WO_TABLE.cs
@@ -86,17 +86,21 @@
 		/// 备注
 		/// </summary>
 		public string REMARK { get; set; }
-		#endregion
+        #endregion
 
-		#region 虚拟属性
-		/*例子
+        #region 虚拟属性
+        /*例子
 		[SugarColumn(IsIgnore = true)]
 		public string FieldName { get; set; }
 		*/
-		#endregion
+        [SugarColumn(IsIgnore = true)]
+        public string VALIDATION_TYPE { get; set; }
+        [SugarColumn(IsIgnore = true)]
+        public string VALIDATION_RESULT { get; set; }
+        #endregion
 
-		#region 外键属性
-		/*例子
+        #region 外键属性
+        /*例子
 		//一对一外键导航
 		[Navigate(NavigateType.OneToOne, nameof(ClassAId))]//一对一 ClassAId是SMT_WO_TABLE类里面的外键ID字段
 		public ClassA ClassA { get; set; } //注意禁止手动赋值,只能是null
@@ -107,10 +111,10 @@
 		[Navigate(typeof(MappingClass), nameof(MappingClass.SMT_WO_TABLEId), nameof(MappingClass.ClassAId))]//注意顺序
 		public List<ClassA> ClassAList { get; set; } //注意禁止手动赋值,只能是null
 		*/
-		#endregion
+        #endregion
 
-		#region 枚举变量
-		/*例子
+        #region 枚举变量
+        /*例子
 		public enum FieldNames
 		{
 			[Description("枚举描述0")]
@@ -119,13 +123,13 @@
 			Enum1,
 		}
 		*/
-		#endregion
+        #endregion
 
-		#region 公共方法
+        #region 公共方法
 
-		#endregion
+        #endregion
 
-	}//endClass
+    }//endClass
 
 	public class smtWoTableParams { 
 		public string prodCode { get; set; }
@@ -134,4 +138,26 @@
         public string moCode { get; set; }
         public string machineCode { get; set; }
     }
+	//导入对象
+    public class smtWoTableIn
+    {
+        public string 关联工单号 { get; set; }
+        public string 产品编码 { get; set; }
+        public string 物料编码 { get; set; }
+        public string 替代料 { get; set; }
+        public string 单位 { get; set; }
+        public int 单位用量 { get; set; }
+        public string 产线编码 { get; set; }
+        public string 贴片机编码 { get; set; }
+        public string 钢网编码 { get; set; }
+        public string 站位号 { get; set; }
+        public string 贴片位置 { get; set; }
+        public string 飞达编码 { get; set; }
+        public string 飞达类型 { get; set; }
+        public string 加工面 { get; set; }
+        public int 上料顺序 { get; set; }
+        public string 备注 { get; set; }
+        public string 处理方式 { get; set; }
+        public string 原因 { get; set; }
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.3