diff --git a/AMESCoreStudio.WebApi/Controllers/BAS/RulesController.cs b/AMESCoreStudio.WebApi/Controllers/BAS/RulesController.cs
index ac1e3746..a985ad84 100644
--- a/AMESCoreStudio.WebApi/Controllers/BAS/RulesController.cs
+++ b/AMESCoreStudio.WebApi/Controllers/BAS/RulesController.cs
@@ -139,6 +139,29 @@ namespace AMESCoreStudio.WebApi.Controllers.BAS
return rules;
}
+ ///
+ /// 根據下一站別IDD查詢
+ ///
+ ///
+ ///
+ // GET: api/Rules/5
+ [HttpGet("ByNextStation/{id}")]
+ public async Task>> GetRulesByNextStation(int id)
+ {
+ IQueryable q = _context.Ruleses;
+
+ q = q.Where(p => p.NextStationID.Equals(id));
+
+ var rules = await q.ToListAsync();
+
+ if (rules == null)
+ {
+ return NotFound();
+ }
+
+ return rules;
+ }
+
///
/// 更新流程規則資料
///
diff --git a/AMESCoreStudio.WebApi/Controllers/BLL/BarCodeCheckController.cs b/AMESCoreStudio.WebApi/Controllers/BLL/BarCodeCheckController.cs
index 23779270..b87300e5 100644
--- a/AMESCoreStudio.WebApi/Controllers/BLL/BarCodeCheckController.cs
+++ b/AMESCoreStudio.WebApi/Controllers/BLL/BarCodeCheckController.cs
@@ -560,7 +560,6 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES
// 找該筆工單號碼的生產單位代號
var q1 = q.Value.Where(w => w.UnitNO == unitno).FirstOrDefault();
-
// 取工單號碼開立的 WipID、生產單位
var wipinfo = q.Value.Select(s => new { s.WipID, s.UnitNO }).ToList();
@@ -650,7 +649,7 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES
// 該作業站 RuleStationID
int? RuleStationID = ruleStations.Value.Where(w => w.StationID == station).Select(s => s.RuleStationID).FirstOrDefault();
- if (RuleStationID == null)
+ if (RuleStationID == null || RuleStationID == 0)
{
resultModel.Msg = "該工單號碼【" + wipno + "】的流程未設定此作業站";
return resultModel;
@@ -667,15 +666,9 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES
return resultModel;
}
- int LastStopRuleStationID = await GetBarCodeLastStopRuleStationID(wipno, station);
- if (LastStopRuleStationID != 0 && LastStopRuleStationID != 1000)
- {
- if (!BarCodeStationByWipID.Where(w => w.RuleStationID == LastStopRuleStationID).Any())
- {
- resultModel.Msg = "內部序號【" + barcode + "】找不到上一個作業站過站紀錄,請確認";
- return resultModel;
- }
- }
+ resultModel = (ResultModel)await GetBarCodeLastStopRuleStationID(wipID, station, BarCodeStationByWipID);
+ if (!resultModel.Success)
+ return resultModel;
#endregion
resultModel.Success = true;
@@ -1087,79 +1080,55 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES
///
/// 取得上一個作業站RuleStationID
///
- /// 工單號碼
- /// 作業站ID
- /// 0:沒有上一站
- private async Task GetBarCodeLastStopRuleStationID(string wipno, int stationID)
+ /// 工單ID
+ /// 目前作業站ID
+ /// 該工單號碼過站資料
+ /// true:false
+ private async Task GetBarCodeLastStopRuleStationID(int wipID, int stationID, List barCodeStations)
{
+ ResultModel resultModel = new ResultModel { Success = false };
WipInfosController wipInfosController = new WipInfosController(_context);
- var q = wipInfosController.GetWipInfoByWipNo(wipno);
-
- if (q.Result.Value.Count() == 0)
- return 0;
+ var q = wipInfosController.GetWipInfo(wipID);
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)
+ //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的流程ID
+ int WipFlowRule = q1.FirstOrDefault().FlowRuleID;
+
+ // 用作業站抓 有設定下一站為該站的資料
+ RulesController rulesController = new RulesController(_context);
+ var rules = await rulesController.GetRulesByNextStation(stationID);
+
+ //排除第一站
+ if (rules.Value.Count() != 0)
{
- if (i == 0)
- continue;
-
- var ruleStations = await ruleStationsController.GetRuleStationByFlow(i, 0);
- if (ruleStations.Value.Count() != 0)
+ // 反查上一站是否有資料
+ var ruleSationID = rules.Value.Select(s => s.RuleStationID).ToList();
+ if (!barCodeStations.Where(w => ruleSationID.Contains(w.RuleStationID)).Any())
{
- foreach (var item in ruleStations.Value.OrderBy(o => o.Sequence))
- {
- var x = new
- {
- index,
- item.StationID,
- item.RuleStationID,
- item.Sequence,
- item.StationType
- };
- dy.Add(x);
- index++;
- }
+ resultModel.Msg = "找不到上一個作業站過站紀錄,請確認";
+ return resultModel;
}
}
- if (dy.Where(w => w.StationID == stationID).Select(s => s.index).FirstOrDefault() == null)
- return 0;
-
- int NowIndex = dy.Where(w => w.StationID == stationID).Select(s => s.index).FirstOrDefault();
-
- if (dy.Where(w => w.index == (NowIndex - 1)).Select(s => s.StationID).FirstOrDefault() == null)
- return 0;
-
- return dy.Where(w => w.index == (NowIndex - 1)).Select(s => s.RuleStationID).FirstOrDefault();
+ resultModel.Success = true;
+ return resultModel;
}
///