From a4df8a1bf65f4d6734aa754b1c33fdcb08f2e8eb Mon Sep 17 00:00:00 2001 From: ray Date: Wed, 5 Jan 2022 03:41:14 +0800 Subject: [PATCH] 1. PCS021 --- .../Controllers/PCSController.cs | 42 ++-- AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs | 11 + AMESCoreStudio.Web/Views/PCS/PCS021.cshtml | 13 +- .../Controllers/BLL/BarCodeCheckController.cs | 190 ++++++++++++++++-- 4 files changed, 216 insertions(+), 40 deletions(-) diff --git a/AMESCoreStudio.Web/Controllers/PCSController.cs b/AMESCoreStudio.Web/Controllers/PCSController.cs index 13193702..c8ac5747 100644 --- a/AMESCoreStudio.Web/Controllers/PCSController.cs +++ b/AMESCoreStudio.Web/Controllers/PCSController.cs @@ -2174,28 +2174,30 @@ namespace AMESCoreStudio.Web.Controllers } // 判斷作業站與製程順序是否正確 - + var BarCodeFlow = await _pcsApi.CheckBarCodeFlow(model.WipNO, model.Input, model.UnitNO, model.Station); + if (!BarCodeFlow.Success) + return Json(new Result() { success = BarCodeFlow.Success, msg = BarCodeFlow.Msg, data = Data }); // 下一個作業站是完工站時再判斷是否都有刷組件 // 判斷組件是否都有輸入 - if (Kp.Count() != model.MaterialKps.Count()) - { - Msg += "請確認組件序號是否有多刷或漏刷
"; - } - else - { - for (int i = 0; i < model.MaterialKps.Count; i++) - { - if (Kp[i].Length != model.MaterialKps[i].Length) - Msg += "組件序號【" + Kp[i] + "】 與組件名稱【" + model.MaterialKps[i].KpName + "】長度不符合
"; - - if (!string.IsNullOrWhiteSpace(model.MaterialKps[i].Title)) - { - if (!Kp[i].ToUpper().StartsWith(model.MaterialKps[i].Title.ToUpper())) - Msg += "組件序號【" + Kp[i] + "】 與組件名稱【" + model.MaterialKps[i].Title + "】前置碼不符合
"; - } - } - } + //if (Kp.Count() != model.MaterialKps.Count()) + //{ + // Msg += "請確認組件序號是否有多刷或漏刷
"; + //} + //else + //{ + // for (int i = 0; i < model.MaterialKps.Count; i++) + // { + // if (Kp[i].Length != model.MaterialKps[i].Length) + // Msg += "組件序號【" + Kp[i] + "】 與組件名稱【" + model.MaterialKps[i].KpName + "】長度不符合
"; + + // if (!string.IsNullOrWhiteSpace(model.MaterialKps[i].Title)) + // { + // if (!Kp[i].ToUpper().StartsWith(model.MaterialKps[i].Title.ToUpper())) + // Msg += "組件序號【" + Kp[i] + "】 與組件名稱【" + model.MaterialKps[i].Title + "】前置碼不符合
"; + // } + // } + //} } else @@ -2317,7 +2319,9 @@ namespace AMESCoreStudio.Web.Controllers await _pcsApi.PostNgInfo(JsonConvert.SerializeObject(ngInfo)); } + Msg = "內部序號【" + Data + "】 過站完成!"; Data = string.Empty; + } return Json(new Result() { success = Success, msg = Msg, data = Data }); diff --git a/AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs b/AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs index 47f4b486..f3a924fa 100644 --- a/AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs +++ b/AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs @@ -619,6 +619,17 @@ namespace AMESCoreStudio.Web /// Success:true or false [WebApiClient.Attributes.HttpGet("api/BarCodeCheck/BarCodeScrapped")] ITask> CheckBarCodeScrapped(string barcode); + + /// + /// 確認內部條碼流動 + /// + /// 工單號碼 + /// 內部序號 + /// 生產單位ID + /// 作業站ID + /// Success:true or false + [WebApiClient.Attributes.HttpGet("api/BarCodeCheck/BarCodeFlow")] + ITask> CheckBarCodeFlow(string wipno, string barcode, string unitno, int station); #endregion diff --git a/AMESCoreStudio.Web/Views/PCS/PCS021.cshtml b/AMESCoreStudio.Web/Views/PCS/PCS021.cshtml index bf2a9c6c..99f3f1af 100644 --- a/AMESCoreStudio.Web/Views/PCS/PCS021.cshtml +++ b/AMESCoreStudio.Web/Views/PCS/PCS021.cshtml @@ -125,6 +125,7 @@ + @*@Html.ValidationMessage("error")*@
@@ -138,6 +139,7 @@ *@ +
@@ -168,7 +170,7 @@ @index.StationsItemNo - + i++; @@ -214,16 +216,16 @@ - + - + - + - + @index.StationType @@ -373,6 +375,7 @@ parent.hg.msg(result.msg); } else { + parent.hg.msg(result.msg); if (result.data.length != 0) { TableAddRow(result.data); } diff --git a/AMESCoreStudio.WebApi/Controllers/BLL/BarCodeCheckController.cs b/AMESCoreStudio.WebApi/Controllers/BLL/BarCodeCheckController.cs index 0d2d7375..6c1e03de 100644 --- a/AMESCoreStudio.WebApi/Controllers/BLL/BarCodeCheckController.cs +++ b/AMESCoreStudio.WebApi/Controllers/BLL/BarCodeCheckController.cs @@ -207,7 +207,8 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES if (BarCodeID == 0) { - resultModel.Msg = "找不到內部序號【" + barcode + "】 對應BarCodeID"; + //resultModel.Msg = "找不到內部序號【" + barcode + "】 對應BarCodeID"; + resultModel.Success = true; return Ok(resultModel); } @@ -242,6 +243,7 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES var q = await barcodeInfoesController.GetBarcodeInfoesByNo(barcode); if (q.Value.Count() == 0) { + resultModel.Success = true; resultModel.Msg = "找不到內部序號【" + barcode + "】 對應BarCodeID"; return Ok(resultModel); } @@ -306,7 +308,7 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES if (unitno == "D") { int? WipID = wipinfo.Where(w => w.UnitNO == "S").Select(s => s.WipID).FirstOrDefault(); - if (WipID == 0) + if (WipID == null) { resultModel.Msg = "該工單號碼【" + wipno + "】的前製程生產單位尚未建立工單基本資料"; return Ok(resultModel); @@ -322,7 +324,7 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES else if (unitno == "T") { int? WipID = wipinfo.Where(w => w.UnitNO == "B").Select(s => s.WipID).FirstOrDefault(); - if (WipID == 0) + if (WipID == null) { resultModel.Msg = "該工單號碼【" + wipno + "】的前製程生產單位尚未建立工單基本資料"; return Ok(resultModel); @@ -337,7 +339,7 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES else if (unitno == "P") { int? WipID = wipinfo.Where(w => w.UnitNO == "T").Select(s => s.WipID).FirstOrDefault(); - if (WipID == 0) + if (WipID == null) { resultModel.Msg = "該工單號碼【" + wipno + "】的前製程生產單位尚未建立工單基本資料"; return Ok(resultModel); @@ -373,9 +375,7 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES // 該作業站 RuleStationID int? RuleStationID = ruleStations.Value.Where(w => w.StationID == station).Select(s => s.RuleStationID).FirstOrDefault(); - // 該作業站順序 - int? Sequence = ruleStations.Value.Where(w => w.StationID == station).Select(s => s.Sequence).FirstOrDefault(); - if (RuleStationID == 0) + if (RuleStationID == null) { resultModel.Msg = "該工單號碼【" + wipno + "】的流程未設定此作業站"; return Ok(resultModel); @@ -383,22 +383,28 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES // 取目前工單ID int wipID = q1.WipID; + // 該筆工單ID過站紀錄 var BarCodeStationByWipID = BarCodeStations.Value.Where(w => w.WipID == wipID).ToList(); - foreach (var item in ruleStations.Value.OrderBy(o => o.Sequence)) + if (BarCodeStationByWipID.Where(w => w.RuleStationID == RuleStationID && w.RuleStatus == "P").Any()) { - + resultModel.Msg = "內部序號【" + barcode + "】該作業站已有過站紀錄,請確認"; + return Ok(resultModel); } + int LastStopRuleStationID = await GetBarCodeLastStopRuleStationID(wipno, station); + if (LastStopRuleStationID != 0) + { + if (!BarCodeStationByWipID.Where(w => w.RuleStationID == LastStopRuleStationID && w.RuleStatus == "P").Any()) + { + resultModel.Msg = "內部序號【" + barcode + "】找不到上一個作業站過站紀錄,請確認"; + return Ok(resultModel); + } + } #endregion - return Ok(ruleStations); - //if (q.Value.Any(w => w.RuleStatus == "S")) - //{ - // resultModel.Msg = "內部序號【" + barcode + "】已報廢或轉賣, 不可繼續過站!"; - // return Ok(resultModel); - - //} + resultModel.Success = true; + return Ok(resultModel); } /// @@ -480,5 +486,157 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES return q.Value.FirstOrDefault().BarcodeID; } + + + /// + /// 取得上一個作業站RuleStationID + /// + /// 工單號碼 + /// 作業站ID + /// 0:沒有上一站 + private async Task GetBarCodeLastStopRuleStationID(string wipno, int stationID) + { + WipInfosController wipInfosController = new WipInfosController(_context); + var q = wipInfosController.GetWipInfoByWipNo(wipno); + + if (q.Result.Value.Count() == 0) + return 0; + + var q1 = q.Result.Value.ToList(); + List FlowRuleID = new List(); + List Unit = new List(); + // 取生產單位順序 + if (q1.Where(w => w.UnitNO == "S" || w.UnitNO == "D").Any()) + { + // SMT DIP + Unit.Add("S"); + Unit.Add("D"); + } + else if (q1.Where(w => w.UnitNO == "B" || w.UnitNO == "T").Any()) + { + // 組裝 測試 包裝 + Unit.Add("B"); + Unit.Add("T"); + Unit.Add("P"); + } + + // 抓各生產單位的流程ID + foreach (string str in Unit) + { + int WipFlowRule = q1.Where(w => w.UnitNO == str).Select(s => s.FlowRuleID).FirstOrDefault(); + FlowRuleID.Add(WipFlowRule); + } + + // 將工單-生產單位 流程ID取rulestation的作業站排順序 + RuleStationsController ruleStationsController = new RuleStationsController(_context); + List dy = new List(); + int index = 1; + foreach (int i in FlowRuleID) + { + if (i == 0) + continue; + + var ruleStations = await ruleStationsController.GetRuleStationByFlow(i, 0); + if (ruleStations.Value.Count() != 0) + { + foreach (var item in ruleStations.Value.Where(w => w.StationType == "M").OrderBy(o => o.Sequence)) + { + var x = new + { + index, + item.RuleStationID + }; + dy.Add(x); + index++; + } + } + } + + if (dy.Where(w => w.RuleStationID == stationID).Select(s => s.index).FirstOrDefault() == null) + return 0; + + int NowIndex = dy.Where(w => w.RuleStationID == stationID).Select(s => s.index).FirstOrDefault(); + + if (dy.Where(w => w.index == (NowIndex - 1)).Select(s => s.RuleStationID).FirstOrDefault() == null) + return 0; + + return dy.Where(w => w.index == (NowIndex - 1)).Select(s => s.RuleStationID).FirstOrDefault(); + int NextStopStationID = dy.Where(w => w.index == (NowIndex + 1)).Select(s => s.RuleStationID).FirstOrDefault(); + } + + /// + /// 取得下一個作業站RuleStationID + /// + /// 工單號碼 + /// 作業站ID + /// 0:沒有下一站 + private async Task GetBarCodeNextStopRuleStationID(string wipno, int stationID) + { + WipInfosController wipInfosController = new WipInfosController(_context); + var q = wipInfosController.GetWipInfoByWipNo(wipno); + + if (q.Result.Value.Count() == 0) + return 0; + + var q1 = q.Result.Value.ToList(); + List FlowRuleID = new List(); + List Unit = new List(); + // 取生產單位順序 + if (q1.Where(w => w.UnitNO == "S" || w.UnitNO == "D").Any()) + { + // SMT DIP + Unit.Add("S"); + Unit.Add("D"); + } + else if (q1.Where(w => w.UnitNO == "B" || w.UnitNO == "T").Any()) + { + // 組裝 測試 包裝 + Unit.Add("B"); + Unit.Add("T"); + Unit.Add("P"); + } + + // 抓各生產單位的流程ID + foreach (string str in Unit) + { + int WipFlowRule = q1.Where(w => w.UnitNO == str).Select(s => s.FlowRuleID).FirstOrDefault(); + FlowRuleID.Add(WipFlowRule); + } + + // 將工單-生產單位 流程ID取rulestation的作業站排順序 + RuleStationsController ruleStationsController = new RuleStationsController(_context); + List dy = new List(); + int index = 1; + foreach (int i in FlowRuleID) + { + if (i == 0) + continue; + + var ruleStations = await ruleStationsController.GetRuleStationByFlow(i, 0); + if (ruleStations.Value.Count() != 0) + { + foreach (var item in ruleStations.Value.Where(w => w.StationType == "M").OrderBy(o => o.Sequence)) + { + var x = new + { + index, + item.RuleStationID + }; + dy.Add(x); + index++; + } + } + } + + if (dy.Where(w => w.RuleStationID == stationID).Select(s => s.index).FirstOrDefault() == null) + return 0; + + int NowIndex = dy.Where(w => w.RuleStationID == stationID).Select(s => s.index).FirstOrDefault(); + + if (dy.Where(w => w.index == (NowIndex + 1)).Select(s => s.RuleStationID).FirstOrDefault() == null) + return 0; + + return dy.Where(w => w.index == (NowIndex + 1)).Select(s => s.RuleStationID).FirstOrDefault(); + } } }