diff --git a/AMESCoreStudio.Web/Controllers/QRSController.cs b/AMESCoreStudio.Web/Controllers/QRSController.cs index d31293cb..4d427608 100644 --- a/AMESCoreStudio.Web/Controllers/QRSController.cs +++ b/AMESCoreStudio.Web/Controllers/QRSController.cs @@ -472,31 +472,15 @@ namespace AMESCoreStudio.Web.Controllers var query = new QRS010ViewModel(); - int failQty = 0; foreach (var data in result.Data) { JObject jo = JObject.Parse(data.ToString()); - if (jo["ruleStatus"].ToString() == "P") - { - int pass_cnt = 0; - foreach (var item in result.Data) - { - JObject joItem = JObject.Parse(item.ToString()); - - if (jo["ruleStationID"].ToString() == joItem["ruleStationID"].ToString() && joItem["ruleStatus"].ToString() == "F") - { - pass_cnt = int.Parse(jo["firstCnt"].ToString()) + int.Parse(joItem["firstCnt"].ToString()); - failQty = failQty + 1; - break; - } - - } + var passData = await _pcsApi.GetPassData4QRS010(jo["lineDesc"].ToString(), jo["stationID"].ToString(),jo["wipNO"].ToString()); - if (pass_cnt == 0) - { - pass_cnt = int.Parse(jo["passCnt"].ToString()); - } + foreach (var pass in passData.Data) + { + JObject joPass = JObject.Parse(pass.ToString()); query.YieldDatas.Add(new YieldData { @@ -509,16 +493,16 @@ namespace AMESCoreStudio.Web.Controllers ItemNO = jo["itemNO"].ToString(), LineDesc = jo["lineDesc"].ToString(), ModelNO = jo["modelNO"].ToString(), - FirstCnt = int.Parse(jo["firstCnt"].ToString()), - PassCnt = pass_cnt, - Yield = int.Parse(jo["firstCnt"].ToString()) * 1.0 / pass_cnt * 100.0 + FirstCnt = int.Parse(joPass["firstCnt"].ToString()), + PassCnt = int.Parse(jo["passCnt"].ToString()), + Yield = int.Parse(joPass["firstCnt"].ToString()) * 1.0 / int.Parse(jo["passCnt"].ToString()) * 100.0 }); } } if (result.DataTotal > 0) { - return Json(new Table() { code = 0, msg = "", data = query.YieldDatas, count = result.DataTotal - failQty }); + return Json(new Table() { code = 0, msg = "", data = query.YieldDatas, count = result.DataTotal }); } return Json(new Table() { count = 0, data = null }); @@ -539,31 +523,15 @@ namespace AMESCoreStudio.Web.Controllers var query = new QRS010ViewModel(); - int failQty = 0; foreach (var data in result.Data) { JObject jo = JObject.Parse(data.ToString()); - if (jo["ruleStatus"].ToString() == "P") - { - int pass_cnt = 0; - foreach (var item in result.Data) - { - JObject joItem = JObject.Parse(item.ToString()); - - if (jo["ruleStationID"].ToString() == joItem["ruleStationID"].ToString() && joItem["ruleStatus"].ToString() == "F") - { - pass_cnt = int.Parse(jo["firstCnt"].ToString()) + int.Parse(joItem["firstCnt"].ToString()); - failQty = failQty + 1; - break; - } + var passData = await _pcsApi.GetPassData4QRS010(jo["lineDesc"].ToString(), jo["stationID"].ToString(), jo["wipNO"].ToString()); - } - - if (pass_cnt == 0) - { - pass_cnt = int.Parse(jo["passCnt"].ToString()); - } + foreach (var pass in passData.Data) + { + JObject joPass = JObject.Parse(pass.ToString()); query.YieldDatas.Add(new YieldData { @@ -576,9 +544,9 @@ namespace AMESCoreStudio.Web.Controllers ItemNO = jo["itemNO"].ToString(), LineDesc = jo["lineDesc"].ToString(), ModelNO = jo["modelNO"].ToString(), - FirstCnt = int.Parse(jo["firstCnt"].ToString()), - PassCnt = pass_cnt, - Yield = int.Parse(jo["firstCnt"].ToString()) * 1.0 / pass_cnt * 100.0 + FirstCnt = int.Parse(joPass["firstCnt"].ToString()), + PassCnt = int.Parse(jo["passCnt"].ToString()), + Yield = int.Parse(joPass["firstCnt"].ToString()) * 1.0 / int.Parse(jo["passCnt"].ToString()) * 100.0 }); } } diff --git a/AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs b/AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs index 4dd72a4a..20c70381 100644 --- a/AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs +++ b/AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs @@ -829,6 +829,13 @@ namespace AMESCoreStudio.Web [WebApiClient.Attributes.HttpGet("api/WipClass/GetYieldData4QRS010")] ITask> GetYieldData4QRS010(string unitNo, string lineID, string stationID, string mfgTypeNo, string wipNo, string itemNo, string dateStart, string dateEnd, int page, int limit); + /// + /// 良率查詢QRS010 + /// + /// + [WebApiClient.Attributes.HttpGet("api/WipClass/GetPassData4QRS010")] + ITask> GetPassData4QRS010(string lineDesc, string stationID, string wipNo); + #endregion #region WipKp 工單KP資訊資料檔 diff --git a/AMESCoreStudio.WebApi/Controllers/AMES/WipClassController.cs b/AMESCoreStudio.WebApi/Controllers/AMES/WipClassController.cs index bce5e22c..2dee2416 100644 --- a/AMESCoreStudio.WebApi/Controllers/AMES/WipClassController.cs +++ b/AMESCoreStudio.WebApi/Controllers/AMES/WipClassController.cs @@ -160,7 +160,7 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES public async Task> GetYieldData4QRS010(string unitNo, string lineID, string stationID, string mfgTypeNo, string wipNo, string itemNo, string dateStart, string dateEnd, int page = 0, int limit = 10) { ResultModel result = new ResultModel(); - var q = from a in _context.WipClass + var q = from a in _context.WipStations join b in _context.RuleStations on a.RuleStationID equals b.RuleStationID join c in _context.WipInfos on a.WipID equals c.WipID join d in _context.WipAtts on c.WipNO equals d.WipNO @@ -232,7 +232,7 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES } } - q = q.OrderBy(w => w.RuleStationID); + q = q.OrderBy(w => w.WipID + w.RuleStationID); var g = q.GroupBy(x => new { x.WipID, x.WipNO, x.PlanQTY, x.RuleStationID, x.StationID, x.StationDesc, x.RuleStatus, x.ItemNO, x.LineDesc, x.ModelNO }).Select(y => new { @@ -250,16 +250,130 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES PassCnt = y.Sum(x => x.PassCnt), Yield = (y.Sum(x => x.FirstCnt) / y.Sum(x => x.PassCnt) * 100) }); - + + var g1 = g.GroupBy(x => new { x.WipID, x.WipNO, x.PlanQTY, x.RuleStationID, x.StationID, x.StationDesc, x.ItemNO, x.LineDesc, x.ModelNO }).Select(y => new + { + WipID = y.Key.WipID, + WipNO = y.Key.WipNO, + PlanQTY = y.Key.PlanQTY, + RuleStationID = y.Key.RuleStationID, + StationID = y.Key.StationID, + StationDesc = y.Key.StationDesc, + ItemNO = y.Key.ItemNO, + LineDesc = y.Key.LineDesc, + ModelNO = y.Key.ModelNO, + FirstCnt = 0, + PassCnt = y.Sum(x => x.FirstCnt), + Yield = (y.Sum(x => x.FirstCnt) / y.Sum(x => x.PassCnt) * 100) + }) ; + //紀錄筆數 - result.DataTotal = g.Count(); + result.DataTotal = g1.Count(); //Table 頁數 if (page > 0) { - g = g.Skip((page - 1) * limit).Take(limit); + g1 = g1.Skip((page - 1) * limit).Take(limit); } + result.Data = await g1.ToListAsync(); + + if (result == null) + { + result.Msg = "查無資料"; + result.Success = false; + return result; + } + + result.Success = true; + result.Msg = "OK"; + return result; + } + + /// + /// 良率查詢 + /// + /// + /// + /// + /// + [Route("[action]")] + [HttpGet] + public async Task> GetPassData4QRS010(string lineDesc, string stationID, string wipNo) + { + ResultModel result = new ResultModel(); + var q = from a in _context.WipStations + join b in _context.RuleStations on a.RuleStationID equals b.RuleStationID + join c in _context.WipInfos on a.WipID equals c.WipID + join d in _context.WipAtts on c.WipNO equals d.WipNO + join e in _context.LineInfoes on c.LineID equals e.LineID + select new + { + a.WipID, + c.WipNO, + d.ItemNO, + c.PlanQTY, + d.ModelNO, + e.LineDesc, + a.RuleStationID, + b.StationID, + b.StationDesc, + a.RuleStatus, + a.FirstCnt, + a.PassCnt, + c.UnitNO, + c.LineID, + a.CreateDate + }; + + q = q.Where(w => w.RuleStatus.Equals("P")); + + if (lineDesc != null) + { + if (lineDesc != "*") + { + q = q.Where(w => w.LineDesc == lineDesc); + } + } + + if (stationID != null) + { + if (stationID != "0") + { + q = q.Where(w => w.StationID == int.Parse(stationID)); + } + } + + if (wipNo != null) + { + if (wipNo != "") + { + q = q.Where(w => w.WipNO == wipNo); + } + } + + q = q.OrderBy(w => w.WipID + w.RuleStationID); + + var g = q.GroupBy(x => new { x.WipID, x.WipNO, x.PlanQTY, x.RuleStationID, x.StationID, x.StationDesc, x.RuleStatus, x.ItemNO, x.LineDesc, x.ModelNO }).Select(y => new + { + WipID = y.Key.WipID, + WipNO = y.Key.WipNO, + PlanQTY = y.Key.PlanQTY, + RuleStationID = y.Key.RuleStationID, + StationID = y.Key.StationID, + StationDesc = y.Key.StationDesc, + RuleStatus = y.Key.RuleStatus, + ItemNO = y.Key.ItemNO, + LineDesc = y.Key.LineDesc, + ModelNO = y.Key.ModelNO, + FirstCnt = y.Sum(x => x.FirstCnt), + PassCnt = y.Sum(x => x.PassCnt), + Yield = (y.Sum(x => x.FirstCnt) / y.Sum(x => x.PassCnt) * 100) + }); + + //紀錄筆數 + result.DataTotal = g.Count(); + result.Data = await g.ToListAsync(); if (result == null)