From 6738bfc4d55d8948e87cd78a2341cf4f988431f8 Mon Sep 17 00:00:00 2001
From: Ben Lin <maobin001@msn.com>
Date: 星期一, 20 五月 2024 15:13:14 +0800
Subject: [PATCH] Smt上料一些更新

---
 Tiger.Business/MES/SMT/Biz.SmtTool.cs |  169 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 161 insertions(+), 8 deletions(-)

diff --git a/Tiger.Business/MES/SMT/Biz.SmtTool.cs b/Tiger.Business/MES/SMT/Biz.SmtTool.cs
index 0827d74..2fc34f6 100644
--- a/Tiger.Business/MES/SMT/Biz.SmtTool.cs
+++ b/Tiger.Business/MES/SMT/Biz.SmtTool.cs
@@ -12,6 +12,9 @@
 using Tiger.IBusiness;
 using static Tiger.Business.Biz;
 using Microsoft.AspNetCore.Http;
+using System.Collections;
+using System.Data;
+using Sundial;
 
 namespace Tiger.Business
 {
@@ -25,16 +28,166 @@
             /// <summary>
             /// 鑾峰彇鏈笂鏂欏垪琛�
             /// </summary>
-            /// <param name="itemCode"></param>
-            /// <param name="lineCode"></param>
-            /// <param name="pcbSurface"></param>
-            /// <param name="moCode"></param>
-            /// <param name="machineCode"></param>
+            /// <param name="paras"></param>
             /// <returns></returns>
-            /// <exception cref="NotImplementedException"></exception>
-            public Task<ApiAction<SMT_PROD_TABLE>> GetNotLoadingMaterial(string itemCode, string lineCode, string pcbSurface, string moCode, string machineCode = null)
+            public async Task<ApiAction<List<SMT_WO_TABLE>>> GetNotLoadingMaterial(SmtLoadingInput paras)
             {
-                throw new NotImplementedException();
+                var res = new ApiAction<List<SMT_WO_TABLE>>();
+                List<SMT_WO_TABLE> sList = new List<SMT_WO_TABLE>();
+                try
+                {
+                    sList = Db.Queryable<SMT_WO_TABLE, SMT_LOADING>((t, l) =>
+                                            new JoinQueryInfos(
+                                                JoinType.Left,
+                                                t.WORK_ORDER == l.WORK_ORDER
+                                                && t.PROD_CODE == l.PROD_CODE
+                                                && t.PCB_SURFACE == l.PCB_SURFACE
+                                                && t.LINE_CODE == l.LINE_CODE
+                                                && t.SLOT_NO == l.SLOT_NO
+                                            ))
+                                 .Where((t, l) => SqlFunc.IsNullOrEmpty(l.WORK_ORDER) && t.WORK_ORDER == paras.moCode && t.PROD_CODE == paras.prodCode && t.LINE_CODE == paras.lineCode && t.PCB_SURFACE == paras.pcbSurface)
+                                 .WhereIF(SqlFunc.IsNullOrEmpty(paras.machineCode), (t, l) => t.SMT_CODE == paras.machineCode)
+                                 .Select((t, l) => t)
+                                 .ToList();
+                }
+                catch (Exception ex)
+                {
+                    res.CatchExceptionWithLog(ex, "鏌ヨ寮傚父");
+                }
+                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;
             }
         }
     }

--
Gitblit v1.9.3