From b65e59de30848659a8e30396114163575b1caa10 Mon Sep 17 00:00:00 2001 From: Marvin Date: Tue, 13 Dec 2022 16:31:56 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=96=B0=E5=A2=9EFQC=E5=A0=B1=E8=A1=A8?= =?UTF-8?q?=E6=9F=A5=E8=A9=A2QRS016?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/QRSController.cs | 154 ++++++++++++++++++ AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs | 29 ++++ .../ViewModels/QRS/QRS016ViewModel.cs | 45 +++++ AMESCoreStudio.Web/Views/QRS/QRS015.cshtml | 99 +++++++++++ AMESCoreStudio.Web/Views/QRS/QRS015A.cshtml | 36 ++++ AMESCoreStudio.Web/Views/QRS/QRS016.cshtml | 99 +++++++++++ AMESCoreStudio.Web/Views/QRS/QRS016A.cshtml | 91 +++++++++++ AMESCoreStudio.Web/Views/QRS/QRS016B.cshtml | 79 +++++++++ .../AMES/FqcResultMasterController.cs | 138 ++++++++++++++++ .../AMES/InspectionResultMastersController.cs | 64 ++++++++ AMESCoreStudio.WebApi/Models/AMESContext.cs | 31 ++++ 11 files changed, 865 insertions(+) create mode 100644 AMESCoreStudio.Web/ViewModels/QRS/QRS016ViewModel.cs create mode 100644 AMESCoreStudio.Web/Views/QRS/QRS015.cshtml create mode 100644 AMESCoreStudio.Web/Views/QRS/QRS015A.cshtml create mode 100644 AMESCoreStudio.Web/Views/QRS/QRS016.cshtml create mode 100644 AMESCoreStudio.Web/Views/QRS/QRS016A.cshtml create mode 100644 AMESCoreStudio.Web/Views/QRS/QRS016B.cshtml diff --git a/AMESCoreStudio.Web/Controllers/QRSController.cs b/AMESCoreStudio.Web/Controllers/QRSController.cs index 96a52f05..a1d7f75d 100644 --- a/AMESCoreStudio.Web/Controllers/QRSController.cs +++ b/AMESCoreStudio.Web/Controllers/QRSController.cs @@ -1052,5 +1052,159 @@ namespace AMESCoreStudio.Web.Controllers ViewData["RateDataList"] = rateDataList; return View(); } + + public async Task QRS015() + { + await GetUnitList(); + + ViewBag.StartDate = System.DateTime.Now.AddDays(-7).ToString("yyyy/MM/dd"); + ViewBag.EndDate = System.DateTime.Now.ToString("yyyy/MM/dd"); + + return View(); + } + + public async Task QRS015AAsync(string modelNO, string itemNO, string wipNO, string dateStart, string dateEnd) + { + ViewData["ParamList"] = modelNO + "_" + itemNO + "_" + wipNO + "_" + dateStart + "_" + dateEnd; + + ViewData["Title"] = "查詢條件 - 工單號碼 : " + wipNO + "; 料號 : " + itemNO + "; 機種 : " + modelNO + "; 檢驗日期 : " + dateStart + " ~ " + dateEnd; + + string ipqcDataList = ""; + + IResultModel result = await _pcsApi.GetIPQCHeaderData4QRS015(wipNO, itemNO, modelNO, dateStart, dateEnd); + + if (result.DataTotal > 0) + { + ipqcDataList = ipqcDataList + ""; + foreach (var item in result.Data) + { + JObject jo = JObject.Parse(item.ToString()); + string ipqc_week = jo["ipqcWeek"].ToString(); + string ipqc_cnt = jo["ipqcCnt"].ToString(); + ipqcDataList = ipqcDataList + ""; + + } + ipqcDataList = ipqcDataList + "
周次抽驗總筆數通過筆數不良筆數通過率
" + ipqc_week + "" + ipqc_cnt + "" + ipqc_cnt + "0100%
"; + } + + ipqcDataList = ipqcDataList + "
"; + ViewData["IPQCDataList"] = ipqcDataList; + return View(); + } + + public async Task QRS016() + { + await GetUnitList(); + + ViewBag.StartDate = System.DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd"); + ViewBag.EndDate = System.DateTime.Now.ToString("yyyy-MM-dd"); + + return View(); + } + + public IActionResult QRS016B(string id) + { + string[] param = id.Split("_"); + ViewBag.WIP_NO = param[0]; + ViewBag.ITEM_NO = param[1]; + ViewBag.MODEL_NO = param[2]; + ViewBag.START_DATE = param[3]; + ViewBag.END_DATE = param[4]; + ViewBag.WEEK = param[5]; + + return View(); + } + + [HttpPost] + public async Task GetFQCData4QRS016Async(string id) + { + string[] param = id.Split('_'); + string wip_no = param[0]; + string item_no = param[1]; + string model_no = param[2]; + string start_date = param[3]; + string end_date = param[4]; + + var result = await _pcsApi.GetFQCHeaderData4QRS016(wip_no, item_no, model_no, start_date, end_date); + + var query = new QRS016ViewModel(); + + foreach (var data in result.Data) + { + JObject jo = JObject.Parse(data.ToString()); + + query.FqcDatas.Add(new FqcData + { + WeekCode = jo["fqcWeek"].ToString(), + FqcCnt = int.Parse(jo["fqcCnt"].ToString()), + PassCnt = int.Parse(jo["passCnt"].ToString()), + FailCnt = int.Parse(jo["failCnt"].ToString()), + Rate = int.Parse(jo["passCnt"].ToString()) * 1.0 / int.Parse(jo["fqcCnt"].ToString()) * 100.0 + }); + } + + return Json(query.FqcDatas); + } + + public async Task QRS016AAsync(string modelNO, string itemNO, string wipNO, string dateStart, string dateEnd) + { + ViewData["ParamList"] = modelNO + "_" + itemNO + "_" + wipNO + "_" + dateStart + "_" + dateEnd; + + ViewData["Title"] = "查詢條件 - 工單號碼 : " + wipNO + "; 料號 : " + itemNO + "; 機種 : " + modelNO + "; 檢驗日期 : " + dateStart + " ~ " + dateEnd; + + string fqcDataList = ""; + + IResultModel result = await _pcsApi.GetFQCHeaderData4QRS016(wipNO, itemNO, modelNO, dateStart, dateEnd); + + if (result.DataTotal > 0) + { + fqcDataList = fqcDataList + ""; + int sumFqcCnt = 0, sumPassCnt = 0, sumFailCnt = 0; + foreach (var item in result.Data) + { + JObject jo = JObject.Parse(item.ToString()); + string fqc_week = jo["fqcWeek"].ToString(); + int fqc_cnt = int.Parse(jo["fqcCnt"].ToString()); + int pass_cnt = int.Parse(jo["passCnt"].ToString()); + int fail_cnt = int.Parse(jo["failCnt"].ToString()); + double fqc_rate = pass_cnt * 100.0 / fqc_cnt; + + fqcDataList = fqcDataList + ""; + + sumFqcCnt = sumFqcCnt + fqc_cnt; + sumPassCnt = sumPassCnt + pass_cnt; + sumFailCnt = sumFailCnt + fail_cnt; + } + double sum_fqc_rate = sumPassCnt * 100.0 / sumFqcCnt; + fqcDataList = fqcDataList + ""; + fqcDataList = fqcDataList + "
周次抽驗總筆數通過筆數不良筆數通過率
" + fqc_week + "" + "  " + fqc_cnt + "" + "  " + pass_cnt + "" + "  " + fail_cnt + "" + "  " + fqc_rate.ToString("0.00") + "%
" + " " + "Total" + "" + "  " + sumFqcCnt + "" + "  " + sumPassCnt + "" + "  " + sumFailCnt + "" + "  " + sum_fqc_rate.ToString("0.00") + "%
"; + } + + fqcDataList = fqcDataList + "
"; + ViewData["FQCDataList"] = fqcDataList; + return View(); + } + + [ResponseCache(Duration = 0)] + [HttpGet] + public async Task GetFQCDetailData(string id, int page = 0, int limit = 10) + { + string[] param = id.Split("_"); + string wip_no = param[0]; + string item_no = param[1]; + string model_no = param[2]; + string start_date = param[3]; + string end_date = param[4]; + string week = param[5]; + + var result = await _pcsApi.GetFQCDetailData(wip_no, item_no, model_no, start_date, end_date, week, page, limit); + + if (result.DataTotal > 0) + { + return Json(new Table() { code = 0, msg = "", data = result.Data, count = result.DataTotal }); + } + + return Json(new Table() { count = 0, data = null }); + } } } diff --git a/AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs b/AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs index ada26b1c..42d5602a 100644 --- a/AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs +++ b/AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs @@ -1068,6 +1068,35 @@ namespace AMESCoreStudio.Web #endregion + #region QRS015 IPQC查詢報表 + + /// + /// IPQC查詢報表 + /// + /// + [WebApiClient.Attributes.HttpGet("api/InspectionResultMasters/GetIPQCHeaderData4QRS015")] + ITask> GetIPQCHeaderData4QRS015(string wipNO, string itemNO, string modelNO, string dateStart, string dateEnd); + + #endregion + + #region QRS016 FQC查詢報表 + + /// + /// FQC查詢報表 + /// + /// + [WebApiClient.Attributes.HttpGet("api/FqcResultMaster/GetFQCHeaderData4QRS016")] + ITask> GetFQCHeaderData4QRS016(string wipNO, string itemNO, string modelNO, string dateStart, string dateEnd); + + /// + /// 查詢FQC明細資料 + /// + /// + [WebApiClient.Attributes.HttpGet("api/FqcResultMaster/GetFQCDetailData")] + ITask> GetFQCDetailData(string wipNO, string itemNO, string modelNO, string dateStart, string dateEnd, string weekCode, int page, int limit); + + #endregion + #region PDS003 查詢工單基本資料 /// diff --git a/AMESCoreStudio.Web/ViewModels/QRS/QRS016ViewModel.cs b/AMESCoreStudio.Web/ViewModels/QRS/QRS016ViewModel.cs new file mode 100644 index 00000000..d7c11b53 --- /dev/null +++ b/AMESCoreStudio.Web/ViewModels/QRS/QRS016ViewModel.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace AMESCoreStudio.Web.ViewModels.QRS +{ + public class QRS016ViewModel + { + public QRS016ViewModel() + { + FqcDatas = new List(); + } + + public List FqcDatas { get; set; } + } + + public class FqcData + { + /// + /// 周次 + /// + public string WeekCode { get; set; } + + /// + /// 抽檢總筆數 + /// + public int FqcCnt { get; set; } + + /// + /// 通過筆數 + /// + public int PassCnt { get; set; } + + /// + /// 不良筆數 + /// + public int FailCnt { get; set; } + + /// + /// 通過率 + /// + public double Rate { get; set; } + } +} diff --git a/AMESCoreStudio.Web/Views/QRS/QRS015.cshtml b/AMESCoreStudio.Web/Views/QRS/QRS015.cshtml new file mode 100644 index 00000000..bf3905f5 --- /dev/null +++ b/AMESCoreStudio.Web/Views/QRS/QRS015.cshtml @@ -0,0 +1,99 @@ +@{ + ViewData["Title"] = "IPQC查詢報表"; + Layout = "~/Views/Shared/_AMESLayout.cshtml"; +} + +
+
+
+
+
@ViewBag.Title
+
+ +
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+ +
+
+
+
+
+ +
+
+
+
+
+
+@section Scripts{ + @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); + await Html.RenderPartialAsync("_FileinputScriptsPartial"); } + +} \ No newline at end of file diff --git a/AMESCoreStudio.Web/Views/QRS/QRS015A.cshtml b/AMESCoreStudio.Web/Views/QRS/QRS015A.cshtml new file mode 100644 index 00000000..aef3e29f --- /dev/null +++ b/AMESCoreStudio.Web/Views/QRS/QRS015A.cshtml @@ -0,0 +1,36 @@ +@{ + Layout = "~/Views/Shared/_AMESLayout.cshtml"; +} + + + + + +
+
+
+
+
@ViewBag.Title
+
+ +
+
+
+ + @Html.Raw(ViewData["IPQCDataList"]) +
+
+ +@section Scripts { + @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); + await Html.RenderPartialAsync("_FileinputScriptsPartial"); } + + + + +} \ No newline at end of file diff --git a/AMESCoreStudio.Web/Views/QRS/QRS016.cshtml b/AMESCoreStudio.Web/Views/QRS/QRS016.cshtml new file mode 100644 index 00000000..4b323e8b --- /dev/null +++ b/AMESCoreStudio.Web/Views/QRS/QRS016.cshtml @@ -0,0 +1,99 @@ +@{ + ViewData["Title"] = "FQC查詢報表"; + Layout = "~/Views/Shared/_AMESLayout.cshtml"; +} + +
+
+
+
+
@ViewBag.Title
+
+ +
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+ +
+
+
+
+
+ +
+
+
+
+
+
+@section Scripts{ + @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); + await Html.RenderPartialAsync("_FileinputScriptsPartial"); } + +} \ No newline at end of file diff --git a/AMESCoreStudio.Web/Views/QRS/QRS016A.cshtml b/AMESCoreStudio.Web/Views/QRS/QRS016A.cshtml new file mode 100644 index 00000000..00c22249 --- /dev/null +++ b/AMESCoreStudio.Web/Views/QRS/QRS016A.cshtml @@ -0,0 +1,91 @@ +@{ + Layout = "~/Views/Shared/_AMESLayout.cshtml"; +} + + + + + +
+
+
+
+
@ViewBag.Title
+
+ +
+
+
+ +
+ @Html.Raw(ViewData["FQCDataList"]) +
+
+ +@section Scripts { + @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); + await Html.RenderPartialAsync("_FileinputScriptsPartial"); } + + + + +} \ No newline at end of file diff --git a/AMESCoreStudio.Web/Views/QRS/QRS016B.cshtml b/AMESCoreStudio.Web/Views/QRS/QRS016B.cshtml new file mode 100644 index 00000000..b422ea15 --- /dev/null +++ b/AMESCoreStudio.Web/Views/QRS/QRS016B.cshtml @@ -0,0 +1,79 @@ +@{ + ViewData["Title"] = "FQC查詢報表 - FQC明細資料"; + Layout = "~/Views/Shared/_AMESLayout.cshtml"; +} + +
+
+ + + + + + +
+
+
+ +@section Scripts{ + +} \ No newline at end of file diff --git a/AMESCoreStudio.WebApi/Controllers/AMES/FqcResultMasterController.cs b/AMESCoreStudio.WebApi/Controllers/AMES/FqcResultMasterController.cs index f75fb875..28a46f12 100644 --- a/AMESCoreStudio.WebApi/Controllers/AMES/FqcResultMasterController.cs +++ b/AMESCoreStudio.WebApi/Controllers/AMES/FqcResultMasterController.cs @@ -61,6 +61,144 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES return fqcResultMaster; } + /// + /// FQC查詢報表QRS016 + /// + /// + [Route("[action]")] + [HttpGet] + public async Task> GetFQCHeaderData4QRS016(string wipNO, string itemNO, string modelNO, string dateStart, string dateEnd) + { + ResultModel result = new ResultModel(); + var q = from q1 in _context.FqcResultMasters + join q2 in _context.CalendarTables on q1.CreateDate.Date equals q2.TimeID + select new + { + q1.FqcID, + q1.CreateDate, + q1.WipNo, + q1.ItemNo, + q1.ModelNo, + q1.QaQty, + q1.PassQty, + q1.FailQty, + q2.WeekOfYear + }; + + if (wipNO != null && wipNO != "") + { + q = q.Where(w => w.WipNo == wipNO); + } + if (itemNO != null && itemNO != "") + { + q = q.Where(w => w.ItemNo == itemNO); + } + if (modelNO != null && modelNO != "") + { + q = q.Where(w => w.ModelNo == modelNO); + } + if (dateStart != null && dateStart != "" && dateEnd != null && dateEnd != "") + { + q = q.Where(w => w.CreateDate >= DateTime.Parse(dateStart) && w.CreateDate <= DateTime.Parse(dateEnd)); + } + + q = q.OrderBy(w => w.CreateDate); + + //EF.Functions + var g = q.GroupBy(x => new { x.WeekOfYear }).Select(x => new + { + FQCWeek = x.Key.WeekOfYear, + //FQCCnt = x.Count(), + FQCCnt = x.Sum(i => i.QaQty), + PassCnt = x.Sum(i => i.PassQty), + FailCnt = x.Sum(i => i.FailQty) + }); + + //紀錄筆數 + result.DataTotal = g.Count(); + + result.Data = await g.ToListAsync(); + + if (result == null) + { + result.Msg = "查無資料"; + result.Success = false; + return result; + } + + result.Success = true; + result.Msg = "OK"; + return result; + } + + /// + /// 查詢FQC明細資料 + /// + /// + [Route("[action]")] + [HttpGet] + public async Task> GetFQCDetailData(string wipNO, string itemNO, string modelNO, string dateStart, string dateEnd, string weekCode, int page = 0, int limit = 10) + { + ResultModel result = new ResultModel(); + var q = from q1 in _context.FqcResultMasters + join q2 in _context.CalendarTables on q1.CreateDate.Date equals q2.TimeID + select new + { + q1.InhouseNo, + q1.WipNo, + q1.ModelNo, + q1.ItemNo, + q1.LotQty, + q1.QaResult, + q1.SpecialPo, + q1.CreateDate, + q2.WeekOfYear + }; + + if (wipNO != null && wipNO != "") + { + q = q.Where(w => w.WipNo == wipNO); + } + if (itemNO != null && itemNO != "") + { + q = q.Where(w => w.ItemNo == itemNO); + } + if (modelNO != null && modelNO != "") + { + q = q.Where(w => w.ModelNo == modelNO); + } + if (dateStart != null && dateStart != "" && dateEnd != null && dateEnd != "") + { + q = q.Where(w => w.CreateDate >= DateTime.Parse(dateStart) && w.CreateDate <= DateTime.Parse(dateEnd)); + } + if (weekCode != null && weekCode != "") + { + q = q.Where(w => w.WeekOfYear == int.Parse(weekCode)); + } + + //紀錄筆數 + result.DataTotal = q.Count(); + + //Table 頁數 + if (page > 0) + { + q = q.Skip((page - 1) * limit).Take(limit); + } + + result.Data = await q.ToListAsync(); + + if (result == null) + { + result.Msg = "查無資料"; + result.Success = false; + return result; + } + + result.Success = true; + result.Msg = "OK"; + return result; + } + /// /// 更新FQC檢驗單結果 /// diff --git a/AMESCoreStudio.WebApi/Controllers/AMES/InspectionResultMastersController.cs b/AMESCoreStudio.WebApi/Controllers/AMES/InspectionResultMastersController.cs index e6ca68df..f58e9ab5 100644 --- a/AMESCoreStudio.WebApi/Controllers/AMES/InspectionResultMastersController.cs +++ b/AMESCoreStudio.WebApi/Controllers/AMES/InspectionResultMastersController.cs @@ -128,6 +128,70 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES return InspectionResultMaster; } + /// + /// IPQC查詢報表QRS015 + /// + /// + [Route("[action]")] + [HttpGet] + public async Task> GetIPQCHeaderData4QRS015(string wipNO, string itemNO, string modelNO, string dateStart, string dateEnd) + { + ResultModel result = new ResultModel(); + var q = from q1 in _context.InspectionResultMasters + join q2 in _context.WipAtts on q1.WipNo equals q2.WipNO + select new + { + q1.InspectionFormID, + q1.CreateDate, + q1.WipNo, + q2.ItemNO, + q2.ModelNO, + IPQCWeek = _context.DatePart("week", q1.CreateDate) + }; + + if (wipNO != null && wipNO != "") + { + q = q.Where(w => w.WipNo == wipNO); + } + if (itemNO != null && itemNO != "") + { + q = q.Where(w => w.ItemNO == itemNO); + } + if (modelNO != "*") + { + q = q.Where(w => w.ModelNO == modelNO); + } + if (dateStart != null && dateStart != "" && dateEnd != null && dateEnd != "") + { + q = q.Where(w => w.CreateDate >= DateTime.Parse(dateStart) && w.CreateDate <= DateTime.Parse(dateEnd)); + } + + q = q.OrderBy(w => w.CreateDate); + + //EF.Functions + var g = q.GroupBy(x => new { x.IPQCWeek }).Select(x => new + { + IPQCWeek = x.Key.IPQCWeek, + IPQCCnt = x.Count() + }); + + //紀錄筆數 + result.DataTotal = g.Count(); + + result.Data = await g.ToListAsync(); + + if (result == null) + { + result.Msg = "查無資料"; + result.Success = false; + return result; + } + + result.Success = true; + result.Msg = "OK"; + return result; + } + /// /// 用FormID获取该巡檢結果资料 /// diff --git a/AMESCoreStudio.WebApi/Models/AMESContext.cs b/AMESCoreStudio.WebApi/Models/AMESContext.cs index ab3c6e3d..87479a7b 100644 --- a/AMESCoreStudio.WebApi/Models/AMESContext.cs +++ b/AMESCoreStudio.WebApi/Models/AMESContext.cs @@ -7,6 +7,9 @@ using AMESCoreStudio.WebApi; using AMESCoreStudio.WebApi.Models.SYS; using AMESCoreStudio.WebApi.Models.AMES; using AMESCoreStudio.WebApi.Models.BAS; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Query.SqlExpressions; +using System.Reflection; namespace AMESCoreStudio.WebApi { @@ -25,12 +28,40 @@ namespace AMESCoreStudio.WebApi //Configuration.ProxyCreationEnabled = false; } + /// + /// + /// + /// + /// + /// + public int? DatePart(string datePartArg, DateTimeOffset? date) => throw new InvalidOperationException($"{nameof(DatePart)} cannot be called client side."); + + /// /// /// /// protected override void OnModelCreating(ModelBuilder modelBuilder) { + var methodInfo = typeof(DbFunctionExtensions).GetMethod(nameof(DatePart)); + + var datePartMethodInfo = typeof(AMESContext) + .GetRuntimeMethod(nameof(AMESContext.DatePart), new[] { typeof(string), typeof(DateTimeOffset) }); + modelBuilder.HasDbFunction(datePartMethodInfo) + .HasTranslation(args => + new SqlFunctionExpression("DatePart", + new[] + { + new SqlFragmentExpression((args.ToArray()[0] as SqlConstantExpression).Value.ToString()), + args.ToArray()[1] + }, + true, + new[] { false, false }, + typeof(int?), + null + ) + ); + /* modelBuilder.Entity() .HasOne(m => m.Module);