From 2d98bf8e7e8fc8cc86e60b88ba5ead9d0600817e Mon Sep 17 00:00:00 2001 From: Sai Date: Wed, 8 Jan 2025 09:37:26 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E6=96=B0=E5=A2=9E=20=3D>=20=E5=96=AE?= =?UTF-8?q?=E7=AB=99=E5=A0=B1=E5=B7=A5=E7=B6=AD=E8=AD=B7(WHS024)=202.=20?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=20Table=20=3D>=20WORK=5FSTATION=5FLOG(?= =?UTF-8?q?=E5=96=AE=E7=AB=99=E5=A0=B1=E5=B7=A5=E8=B3=87=E6=96=99)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/WHSController.cs | 319 ++++++++++++++---- AMESCoreStudio.Web/HttpApis/AMES/IWHS.cs | 47 ++- AMESCoreStudio.Web/Views/WHS/WHS024.cshtml | 170 ++++++++++ AMESCoreStudio.Web/Views/WHS/WHS024C.cshtml | 171 ++++++++++ AMESCoreStudio.Web/Views/WHS/WHS024U.cshtml | 130 +++++++ .../AMES/WorkStationLogController.cs | 201 +++++++++++ .../DTO/AMES/WorkStationLogDto.cs | 109 ++++++ .../Models/AMES/WorkStationLog.cs | 118 +++++++ AMESCoreStudio.WebApi/Models/AMESContext.cs | 5 + 9 files changed, 1212 insertions(+), 58 deletions(-) create mode 100644 AMESCoreStudio.Web/Views/WHS/WHS024.cshtml create mode 100644 AMESCoreStudio.Web/Views/WHS/WHS024C.cshtml create mode 100644 AMESCoreStudio.Web/Views/WHS/WHS024U.cshtml create mode 100644 AMESCoreStudio.WebApi/Controllers/AMES/WorkStationLogController.cs create mode 100644 AMESCoreStudio.WebApi/DTO/AMES/WorkStationLogDto.cs create mode 100644 AMESCoreStudio.WebApi/Models/AMES/WorkStationLog.cs diff --git a/AMESCoreStudio.Web/Controllers/WHSController.cs b/AMESCoreStudio.Web/Controllers/WHSController.cs index b0549f0b..0e03adfe 100644 --- a/AMESCoreStudio.Web/Controllers/WHSController.cs +++ b/AMESCoreStudio.Web/Controllers/WHSController.cs @@ -1,16 +1,15 @@ -using Microsoft.AspNetCore.Mvc; -using System.Threading.Tasks; -using Microsoft.Extensions.Logging; +using AMESCoreStudio.CommonTools.Result; using AMESCoreStudio.Web.Models; +using AMESCoreStudio.Web.ViewModels.WHS; +using AMESCoreStudio.WebApi.Models.AMES; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.Extensions.Logging; using Newtonsoft.Json; -using AMESCoreStudio.WebApi; +using System; using System.Collections.Generic; -using Microsoft.AspNetCore.Mvc.Rendering; -using AMESCoreStudio.WebApi.Models.AMES; -using AMESCoreStudio.WebApi.Models.BAS; -using AMESCoreStudio.CommonTools.Result; using System.Linq; -using AMESCoreStudio.Web.ViewModels.WHS; +using System.Threading.Tasks; namespace AMESCoreStudio.Web.Controllers { @@ -23,7 +22,7 @@ namespace AMESCoreStudio.Web.Controllers public readonly ISYS _sysApi; public readonly IPPS _ppsApi; - public WHSController(ILogger logger, IWHS whsApi,IBAS basApi, IPCS pcsApi, ISYS sysApi, IPPS ppsApi) + public WHSController(ILogger logger, IWHS whsApi, IBAS basApi, IPCS pcsApi, ISYS sysApi, IPPS ppsApi) { _logger = logger; _whsApi = whsApi; @@ -99,7 +98,7 @@ namespace AMESCoreStudio.Web.Controllers var UnitItems = new List(); for (int i = 0; i < result.Count; i++) { - + UnitItems.Add(new SelectListItem(result[i].UnitName, result[i].UnitNo.ToString())); } ViewBag.FactoryUnit = UnitItems; @@ -130,7 +129,7 @@ namespace AMESCoreStudio.Web.Controllers var result = await _basApi.GetStationses(); var StationItems = new List(); - StationItems.Add( new SelectListItem("N/A", "-1")); + StationItems.Add(new SelectListItem("N/A", "-1")); for (int i = 0; i < result.Count; i++) { StationItems.Add(new SelectListItem(result[i].StationName, result[i].StationID.ToString())); @@ -142,10 +141,10 @@ namespace AMESCoreStudio.Web.Controllers var result = await _basApi.GetLineInfoes(); var LineItems = new List(); - LineItems.Add( new SelectListItem("N/A", "0")); + LineItems.Add(new SelectListItem("N/A", "0")); for (int i = 0; i < result.Count; i++) { - LineItems.Add(new SelectListItem(result[i].LineDesc , result[i].LineID.ToString())); + LineItems.Add(new SelectListItem(result[i].LineDesc, result[i].LineID.ToString())); } ViewBag.LineList = LineItems; } @@ -186,7 +185,7 @@ namespace AMESCoreStudio.Web.Controllers private void GetSideList() { - var SideItems = new List() ; + var SideItems = new List(); SideItems.Add(new SelectListItem("N/A", "N/A")); SideItems.Add(new SelectListItem("正面", "正面")); SideItems.Add(new SelectListItem("背面", "背面")); @@ -210,10 +209,10 @@ namespace AMESCoreStudio.Web.Controllers StationItems.Add(new SelectListItem("N/A", "0")); for (int i = 0; i < result.Count; i++) { - if(result[i].UnitNo==unit) + if (result[i].UnitNo == unit) StationItems.Add(new SelectListItem(result[i].StationName, result[i].StationID.ToString())); } - if(StationItems.Count==0) + if (StationItems.Count == 0) StationItems.Add(new SelectListItem("N/A", "")); ViewBag.StationList = StationItems; @@ -348,7 +347,7 @@ namespace AMESCoreStudio.Web.Controllers public async Task WHS001USaveAsync(WorkGroup model) { - if (ModelState.IsValid) + if (ModelState.IsValid) { IResultModel result; @@ -432,8 +431,8 @@ namespace AMESCoreStudio.Web.Controllers { IResultModel result; - result = await _whsApi.PostWorkClass(JsonConvert.SerializeObject(model)); - + result = await _whsApi.PostWorkClass(JsonConvert.SerializeObject(model)); + if (result.Success) //yiru modify 2022-09-27 { @@ -500,12 +499,12 @@ namespace AMESCoreStudio.Web.Controllers #endregion #region WHS003/WHS005標準工時維護相關 - public async Task WHS003(string unitNo,int lineID,string modelname) + public async Task WHS003(string unitNo, int lineID, string modelname) { await GetFactoryUnitsList(); GetUserID(); WHS003ViewModel model = new WHS003ViewModel(); - if (lineID == 0) + if (lineID == 0) lineID = -99; if (string.IsNullOrEmpty(modelname)) //若沒輸入料號查詢 就不帶出資料 return View(null); @@ -513,7 +512,7 @@ namespace AMESCoreStudio.Web.Controllers { unitNo = "Null"; ViewBag.line = null; - } + } else { var result = await _basApi.GetLineInfoByUnit(unitNo); @@ -535,7 +534,7 @@ namespace AMESCoreStudio.Web.Controllers ViewBag.LineId = lineID.ToString(); GetSideList(); var q = await _whsApi.GetStandardWorkTimes004(unitNo, lineID, modelname); - if(q.Count!=0) + if (q.Count != 0) { model.StandardWorkTimes = q.ToList(); return View(model); @@ -545,13 +544,13 @@ namespace AMESCoreStudio.Web.Controllers //新增頁面 public async Task WHS003C() { - // await GetStationListByUnit(unit); + // await GetStationListByUnit(unit); await GetFactoryUnitsList(); - // var result = await _basApi.GetFactoryUnit(unit); + // var result = await _basApi.GetFactoryUnit(unit); //await GetMFGType(); - // ViewBag.LineID = lineID; - // ViewBag.UnitNo = unit; - // ViewBag.FactoryU = result[0].UnitName; + // ViewBag.LineID = lineID; + // ViewBag.UnitNo = unit; + // ViewBag.FactoryU = result[0].UnitName; GetSideList(); return View(); } @@ -575,21 +574,21 @@ namespace AMESCoreStudio.Web.Controllers return Json(new Result() { success = true, msg = "" }); } [HttpPost] - public async Task WHS003SaveAsync([FromBody] List model) + public async Task WHS003SaveAsync([FromBody] List model) { GetUserID(); if (ModelState.IsValid) //yiru modify 2022-09-27 { IResultModel result; string msg = null; - if(model[0].StandardID == 0) + if (model[0].StandardID == 0) { result = await _whsApi.PostStandardWorkTime(JsonConvert.SerializeObject(model)); msg = "添加成功!"; } else { - var x1= await _whsApi.GetStandardWorkTimes004("Null", -99, model.FirstOrDefault().ItemNo); + var x1 = await _whsApi.GetStandardWorkTimes004("Null", -99, model.FirstOrDefault().ItemNo); var _CreateDate = x1.Where(a => a.StandardID == model.FirstOrDefault().StandardID).Select(a => a.CreateDate).FirstOrDefault(); var _CreateUserID = x1.Where(a => a.StandardID == model.FirstOrDefault().StandardID).Select(a => a.CreateUserID).FirstOrDefault(); foreach (var item in model) @@ -683,20 +682,20 @@ namespace AMESCoreStudio.Web.Controllers [ResponseCache(Duration = 0)] [HttpGet] - public async Task GetStandardWorkTimes2Async(string u,int l,string i) + public async Task GetStandardWorkTimes2Async(string u, int l, string i) { if (l == 0) //yiru modify 2022-10-04 l = -99; - // return Json(new Table() { count = 0, data = null }); + // return Json(new Table() { count = 0, data = null }); if (string.IsNullOrEmpty(i)) //若沒輸入料號查詢 就不帶出資料 return Json(new Table() { count = 0, data = null }); //i = "Null"; if (string.IsNullOrEmpty(u)) u = "Null"; - if (u=="0") + if (u == "0") u = "Null"; - var result = await _whsApi.GetStandardWorkTimes003(u,l,i); + var result = await _whsApi.GetStandardWorkTimes003(u, l, i); if (result.Count > 0) { return Json(new Table() { code = 0, msg = "", data = result, count = result.Count }); @@ -707,7 +706,7 @@ namespace AMESCoreStudio.Web.Controllers [ResponseCache(Duration = 0)] [HttpGet] - public async Task GetStandardWorkTimesAddDefaultAsync(string UnitType,string ItemNo, string Unit, int LineId) + public async Task GetStandardWorkTimesAddDefaultAsync(string UnitType, string ItemNo, string Unit, int LineId) { await GetFactoryUnitsList(); GetSideList(); @@ -726,7 +725,7 @@ namespace AMESCoreStudio.Web.Controllers WHS003ViewModel model = new WHS003ViewModel(); if (ItemCheckResult.Count > 0) DefaultWorktimeResult = await _whsApi.GetStandardWorkTimes003AddDefault("2", ItemNo); - else + else DefaultWorktimeResult = await _whsApi.GetStandardWorkTimes003AddDefault(UnitType, ItemNo); ItemCheckResult = await _whsApi.GetStandardWorkTimes004(Unit, LineId, ItemNo); result = DefaultWorktimeResult.Select(q1 => new StandardWorkTime @@ -777,7 +776,7 @@ namespace AMESCoreStudio.Web.Controllers model.StandardWorkTimes = result.ToList(); // return View(model); //return Json(new Table() { data = result, count = result.Count() }); - return View("WHS003",model); + return View("WHS003", model); } @@ -796,7 +795,7 @@ namespace AMESCoreStudio.Web.Controllers return Json(new Table() { count = 0, data = null }); if (string.IsNullOrEmpty(i)) i = "Null"; - if (string.IsNullOrEmpty(u) || u=="0") + if (string.IsNullOrEmpty(u) || u == "0") u = "Null"; var result = await _whsApi.GetStandardWorkTimes005(u, l, i); @@ -972,13 +971,13 @@ namespace AMESCoreStudio.Web.Controllers { sd = System.DateTime.Now.AddDays(-1).ToString(); } - if (ed == null ) + if (ed == null) { ed = System.DateTime.Now.ToString(); } //var result = await _whsApi.GetWorkManPowersByQuery( factoryid, unitid, lineid, classID, stationID, userNo, sdate, edate); - var result = await _whsApi.GetWorkManPowersByQuery(fid, uid, lid, cID, sID, uNo , dID, sd, ed); + var result = await _whsApi.GetWorkManPowersByQuery(fid, uid, lid, cID, sID, uNo, dID, sd, ed); if (result.Count > 0) { return Json(new Table() { code = 0, msg = "", data = result, count = result.Count }); @@ -1006,8 +1005,8 @@ namespace AMESCoreStudio.Web.Controllers await GetFactoryList(); //線別 await GetLineList(); - //站別 - await GetStationList(); + //站別 + await GetStationList(); //班別 GetClassList(); //其他部門 @@ -1016,7 +1015,7 @@ namespace AMESCoreStudio.Web.Controllers } //修改页面 [HttpGet] - public async Task WHS008UAsync(int id,string type) + public async Task WHS008UAsync(int id, string type) { //製程單位 await GetFactoryUnitsList2(); @@ -1109,13 +1108,13 @@ namespace AMESCoreStudio.Web.Controllers if (!string.IsNullOrEmpty(Msg)) { - + ModelState.AddModelError("error", Msg); - return View("WHS008C",model); + return View("WHS008C", model); } else - { + { IResultModel result; result = await _whsApi.PostSupportUser(JsonConvert.SerializeObject(model)); @@ -1136,8 +1135,8 @@ namespace AMESCoreStudio.Web.Controllers ModelState.AddModelError("error", result.Msg); } } + } } - } return View("WHS008C", model); } public async Task WHS008USaveAsync(SupportUser model) @@ -1183,7 +1182,7 @@ namespace AMESCoreStudio.Web.Controllers public async Task GetSupportUser2Async(string f, string type, string unit, string sd, string ed) { - var result = await _whsApi.GetSupportUserByQuery( f,type, unit, sd, ed); + var result = await _whsApi.GetSupportUserByQuery(f, type, unit, sd, ed); if (result.Count > 0) { @@ -1261,7 +1260,7 @@ namespace AMESCoreStudio.Web.Controllers await GetUserInfo(); - var result = await _whsApi.GetExceptionWorktime(id); + var result = await _whsApi.GetExceptionWorktime(id); var result2 = await _whsApi.GetExceptionCode(result[0].ExceptionNo); ViewBag.ClassNo = result2[0].ExceptionClassNo; var result3 = await _whsApi.GetExceptionClass(result2[0].ExceptionClassNo); @@ -1295,7 +1294,7 @@ namespace AMESCoreStudio.Web.Controllers { model.MeasureDate = System.DateTime.Now; } - + result = await _whsApi.PostExceptionWorktime(JsonConvert.SerializeObject(model)); //yiru modify 2022-10-04 @@ -1640,7 +1639,7 @@ namespace AMESCoreStudio.Web.Controllers [HttpGet] public async Task GetExceptionWorktimeOlineByQueryAsync(string factoryid, string unitid, string lineid, string deptid, string sdate, string edate) { - if (factoryid == null ) + if (factoryid == null) { factoryid = "*"; } @@ -2289,7 +2288,7 @@ namespace AMESCoreStudio.Web.Controllers edate = "*"; } - var result = await _whsApi.GetWorkingHoursCollectionByQuery( unitNo, lineid, stationid, wipno, itemno, user, sdate, edate); + var result = await _whsApi.GetWorkingHoursCollectionByQuery(unitNo, lineid, stationid, wipno, itemno, user, sdate, edate); if (result.Count > 0) @@ -2347,7 +2346,7 @@ namespace AMESCoreStudio.Web.Controllers { wipno = "*"; } - + if (user == null) { user = "*"; @@ -2695,7 +2694,7 @@ namespace AMESCoreStudio.Web.Controllers } [HttpGet] - public async Task WHS022OWByUserQuery(string sUnitNo,string sItemNo,string sUserId) + public async Task WHS022OWByUserQuery(string sUnitNo, string sItemNo, string sUserId) { var result = await _whsApi.GetOutsourceWorktimeByUserWHS022(sUnitNo, sItemNo, sUserId); @@ -2712,7 +2711,7 @@ namespace AMESCoreStudio.Web.Controllers [HttpGet] public async Task WHS022ColumnNameQuery(string sUnitNo) { - + var result = await _whsApi.GetOutsourceWorktimeColumnNameWHS022(sUnitNo); if (result.Count > 0) @@ -2766,6 +2765,193 @@ namespace AMESCoreStudio.Web.Controllers return Json(new Table() { count = 0, data = null }); } #endregion + + #region WHS024 單站報工 + + public async Task WHS024() + { + return View(); + } + + [HttpGet] + public async Task WHS024Query(string wipNo = null, string status = null, string dateStr = null, string dateEnd = null, int page = 0, int limit = 10) + { + var result = await _whsApi.GetWorkStationLogByQuery(wipNo, status, dateStr, dateEnd, page, limit); + + if (result.Data.Count() != 0) + { + return Json(new Table() { code = 0, msg = "", data = result.Data, count = result.DataTotal }); + } + + return Json(new Table() { count = 0, data = null }); + } + + //新增頁面 + public async Task WHS024C() + { + return View(new WorkStationLog()); + } + + [HttpPost] + public async Task WHS024CQuery(string wipNo) + { + var result = new ResultModel(); + var result_Wip = await _pcsApi.GetWipInfoByWipNO(wipNo.Trim().ToUpper()); + var itemNo = string.Empty; + var wipQty = 0; + if (!result_Wip.Any()) + { + result.Success = false; + result.Msg = "找不到工單號碼【" + wipNo + "】建立資料"; + } + else + { + itemNo = result_Wip.FirstOrDefault().GetWipAtt.ItemNO; + wipQty = result_Wip.FirstOrDefault().PlanQTY; + var flowRuleid = result_Wip.FirstOrDefault().FlowRuleID; + var result_RuleStation = await _basApi.GetRuleStationsByFlow(flowRuleid, 0); + result_RuleStation = result_RuleStation.Where(w => w.StationType == "M" && w.StationID != 1000).OrderBy(o => o.Sequence).ToList(); + var rleStations = new List(); + for (int i = 0; i < result_RuleStation.Count; i++) + { + rleStations.Add(new SelectListItem(result_RuleStation[i].Sequence + "-" + result_RuleStation[i].StationDesc, result_RuleStation[i].StationID.ToString())); + } + + result.Data = rleStations; + result.Success = true; + } + + return Json(new { item = result, itemNo, wipQty }); + } + + //修改页面 + [HttpGet] + public async Task WHS024U(int id) + { + var result = await _whsApi.GetWorkStationLog(id); + var result_Wip = await _pcsApi.GetWipInfoByWipNO(result.wipNo); + var flowRuleid = result_Wip.FirstOrDefault().FlowRuleID; + var result_RuleStation = await _basApi.GetRuleStationsByFlow(flowRuleid, 0); + var stationList = new List(); + foreach (var item in result_RuleStation.Where(w => w.StationID == result.StationID)) + { + stationList.Add(new SelectListItem(item.Sequence + "-" + item.StationDesc, item.StationID.ToString())); + } + ViewBag.GetStationsList = stationList; + ViewBag.wipQty = result_Wip.FirstOrDefault().PlanQTY; + return View(result); + } + + //頁面提交,id=0 添加,id>0 修改 + [HttpPost] + public async Task WHS024Async(WorkStationLog model, int wipQty = 0) + { + IResultModel result; + var _msg = string.Empty; + + // 工單沒有輸入 + try + { + if (string.IsNullOrWhiteSpace(model.wipNo)) + { + _msg += " 請輸入工單"; + } + + // 工單沒有輸入 + if (model.StationID == 0) + { + _msg += " 請選擇作業站"; + } + + if (model.startTime != null && model.endTime != null) + { + // 確認日期是否同一天 + if (model.startTime.Value.Date != model.endTime.Value.Date) + { + _msg += "開始與結束不同一天,請在確認"; + } + + // 確認日期格式正確 + if (model.startTime.Value.Date > model.endTime.Value.Date) + { + _msg += "結束時間早於開始時間,請在確認"; + } + + // 類型是生產工時 + if (model.type == "A") + { + var workStationByWipNo = await _whsApi.GetWorkStationLogByQuery(wipNo: model.wipNo); + var workQty = workStationByWipNo.Data.Where(w => w.StationID == model.StationID).Sum(s => s.productionQty); + + if (workQty + (model.productionQty ?? 0) > wipQty) + { + _msg += $"本次生產數量【{model.productionQty ?? 0}】+ 累積生產數量【{workQty}】已超過工單數,請在確認"; + } + } + // 無效工時、異常工時 + else + { + if (string.IsNullOrWhiteSpace(model.remarks) || string.IsNullOrWhiteSpace(model.exceptionCode)) + _msg += "請填寫異常代碼跟備註"; + } + } + + if (!string.IsNullOrWhiteSpace(_msg)) + { + ModelState.AddModelError("error", _msg); + } + else + { + model.CreateUserID = GetLogInUserID(); + model.UpdateUserID = GetLogInUserID(); + if (model.workStationid == 0) + { + result = await _whsApi.PostWorkStationLog(JsonConvert.SerializeObject(model)); + } + else + { + result = await _whsApi.PutWorkStationLog(JsonConvert.SerializeObject(model)); + } + + if (result.Success) + { + _msg = model.workStationid == 0 ? "新增成功!" : "修改成功!"; + return RedirectToAction("Refresh", "Home", new { msg = _msg }); + } + else + { + ModelState.AddModelError("error", result.Msg); + } + } + + var result_Wip = await _pcsApi.GetWipInfoByWipNO(model.wipNo); + var flowRuleid = result_Wip.FirstOrDefault()?.FlowRuleID ?? 999; + var result_RuleStation = await _basApi.GetRuleStationsByFlow(flowRuleid, 0); + var stationList = new List(); + foreach (var item in result_RuleStation) + { + stationList.Add(new SelectListItem(item.Sequence + "-" + item.StationDesc, item.StationID.ToString())); + } + ViewBag.GetStationsList = stationList; + ViewBag.wipQty = result_Wip.FirstOrDefault()?.PlanQTY ?? 0; + + if (model.workStationid == 0) + return View("WHS024C", model); + else + return View("WHS024U", model); + } + catch (Exception ex) + { + ModelState.AddModelError("error", $"系統錯誤:{ex.Message}"); + if (model.workStationid == 0) + return View("WHS024C", model); + else + return View("WHS024U", model); + } + } + + #endregion + public void GetUserID() { var userID = ""; @@ -2780,5 +2966,24 @@ namespace AMESCoreStudio.Web.Controllers } ViewBag.UserID = user_id; } + + /// + /// 取登入者ID + /// + /// + public int GetLogInUserID() + { + int user_id = 0; + HttpContext.Request.Cookies.TryGetValue("UserID", out string userID); + + if (userID != null) + { + if (int.Parse(userID.ToString()) >= 0) + { + user_id = int.Parse(userID.ToString()); + } + } + return user_id; + } } } diff --git a/AMESCoreStudio.Web/HttpApis/AMES/IWHS.cs b/AMESCoreStudio.Web/HttpApis/AMES/IWHS.cs index 0b3e8001..e13dc4fb 100644 --- a/AMESCoreStudio.Web/HttpApis/AMES/IWHS.cs +++ b/AMESCoreStudio.Web/HttpApis/AMES/IWHS.cs @@ -602,7 +602,7 @@ namespace AMESCoreStudio.Web /// //2024-02-27 BB.Wang Modify 增加查詢工時收集單狀態 [WebApiClient.Attributes.HttpGet("api/WorkingHoursCollections/DtoByQuery/{unitNo}/{lineid}/{stationid}/{wipno}/{itemno}/{user}/{sdate}/{edate}")] //ask> GetWorkingHoursCollectionDtoByQuery(string unitNo, string lineid, string stationid, string wipno, string itemno, string user, string sdate, string edate); - ITask> GetWorkingHoursCollectionDtoByQuery(string unitNo, string lineid, string stationid, string wipno, string itemno, string user, string sdate, string edate, string type = null ); + ITask> GetWorkingHoursCollectionDtoByQuery(string unitNo, string lineid, string stationid, string wipno, string itemno, string user, string sdate, string edate, string type = null); #endregion @@ -625,5 +625,50 @@ namespace AMESCoreStudio.Web [WebApiClient.Attributes.HttpGet("api/OutsourceWorktime/WHS023OWByQuery/{sUnitNo}/{sItemNo}/{sUserId}")] ITask> GetOutsourceWorktimeWHS023(string sUnitNo, string sItemNo, string sUserId); #endregion + + #region WHS024 單站報工 + + /// + /// 新增 單站報工資料 + /// + /// + [WebApiClient.Attributes.HttpPost("api/WorkStationLog")] + ITask> PostWorkStationLog([FromBody, RawJsonContent] string model); + + /// + /// 更新 單站報工資料 + /// + /// + [WebApiClient.Attributes.HttpPut("api/WorkStationLog")] + ITask> PutWorkStationLog([FromBody, RawJsonContent] string model); + + ///// + ///// 刪除重工標準工時 + ///// + ///// + //[WebApiClient.Attributes.HttpDelete("api/ExceptionReasons/{id}")] + //ITask> DeleteExceptionReason(string id); + + /// + /// 單站報工資料 By Id + /// + /// + [WebApiClient.Attributes.HttpGet("api/WorkStationLog/{id}")] + ITask GetWorkStationLog(int id); + + /// + /// 查詢 單站報工資料 ByQuery + /// + /// 工單號碼 + /// 狀態 + /// 開始日期 + /// 結束日期 + /// 頁數 + /// + /// + [WebApiClient.Attributes.HttpGet("api/WorkStationLog/Query")] + ITask> GetWorkStationLogByQuery(string wipNo = null, string type = null, string dateStr = null, string dateEnd = null, int page = 0, int limit = 10); + + #endregion } } diff --git a/AMESCoreStudio.Web/Views/WHS/WHS024.cshtml b/AMESCoreStudio.Web/Views/WHS/WHS024.cshtml new file mode 100644 index 00000000..bfa8be97 --- /dev/null +++ b/AMESCoreStudio.Web/Views/WHS/WHS024.cshtml @@ -0,0 +1,170 @@ +@{ + ViewData["Title"] = "單站報工查詢"; + Layout = "~/Views/Shared/_AMESLayout.cshtml"; +} + +
+
+
+
+
@ViewBag.Title
+
+
+
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+ +
+
+
+
+
+ +
+ +
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +@section Scripts { + +} \ No newline at end of file diff --git a/AMESCoreStudio.Web/Views/WHS/WHS024C.cshtml b/AMESCoreStudio.Web/Views/WHS/WHS024C.cshtml new file mode 100644 index 00000000..d8d65c1d --- /dev/null +++ b/AMESCoreStudio.Web/Views/WHS/WHS024C.cshtml @@ -0,0 +1,171 @@ +@model AMESCoreStudio.WebApi.Models.AMES.WorkStationLog + +@{ + ViewData["Title"] = "WHS024C"; + Layout = "~/Views/Shared/_AMESLayout.cshtml"; +} + + + +
+
+
+
+
+ +
+
+ +
+ + 輸入工單號碼後按Enter +
+ +
+ +
+ +
+ + +
+
+
+ +
+
+ +
+ + +
+ + + + +
+
+ +
+
+ +
+ +
+ +
+ +
+
+
+ +
+
+ +
+ +
+ +
+ +
+
+
+ +
+ +
+ +
+
+ + @Html.ValidationMessage("error") +
+
+ +
+
+
+
+
+
+ +@section Scripts { + @{ + await Html.RenderPartialAsync("_ValidationScriptsPartial"); + await Html.RenderPartialAsync("_FileinputScriptsPartial"); + } + @{ + var now = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + } + + + +} diff --git a/AMESCoreStudio.Web/Views/WHS/WHS024U.cshtml b/AMESCoreStudio.Web/Views/WHS/WHS024U.cshtml new file mode 100644 index 00000000..d4f2a98b --- /dev/null +++ b/AMESCoreStudio.Web/Views/WHS/WHS024U.cshtml @@ -0,0 +1,130 @@ +@model AMESCoreStudio.WebApi.Models.AMES.WorkStationLog + +@{ + ViewData["Title"] = "WHS024U"; + Layout = "~/Views/Shared/_AMESLayout.cshtml"; +} + + + +
+
+
+
+
+ +
+
+ +
+ +
+ +
+ +
+ +
+ + +
+
+
+ +
+
+ +
+ + +
+ + + + + +
+
+ +
+
+ +
+ +
+ +
+ +
+
+
+ +
+
+ +
+ +
+ +
+ +
+
+
+ +
+ +
+ +
+
+ + @Html.ValidationMessage("error") +
+
+ +
+
+
+
+
+
+ +@section Scripts { + @{ + await Html.RenderPartialAsync("_ValidationScriptsPartial"); + await Html.RenderPartialAsync("_FileinputScriptsPartial"); + } + @{ + var now = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + } + +} diff --git a/AMESCoreStudio.WebApi/Controllers/AMES/WorkStationLogController.cs b/AMESCoreStudio.WebApi/Controllers/AMES/WorkStationLogController.cs new file mode 100644 index 00000000..cd3ac9d5 --- /dev/null +++ b/AMESCoreStudio.WebApi/Controllers/AMES/WorkStationLogController.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using AMESCoreStudio.WebApi; +using AMESCoreStudio.WebApi.Models.AMES; +using AMESCoreStudio.CommonTools.Result; +using AMESCoreStudio.WebApi.DTO.AMES; +using AMESCoreStudio.WebApi.Enum; + +namespace AMESCoreStudio.WebApi.Controllers.AMES +{ + /// + /// 單站報工資料 + /// + [Route("api/[controller]")] + [ApiController] + public class WorkStationLogController : ControllerBase + { + private readonly AMESContext _context; + + public WorkStationLogController(AMESContext context) + { + _context = context; + } + + [HttpGet] + public async Task>> GetWorkStationLogs() + { + return await _context.WorkStationLogs.ToListAsync(); + } + + [HttpGet("{id}")] + public async Task> GetWorkStationLog(int id) + { + var workStationLog = await _context.WorkStationLogs.FindAsync(id); + return workStationLog; + } + + /// + /// 查詢 單站報工資料 ByQuery + /// + /// 工單號碼 + /// 狀態 + /// 開始日期 + /// 結束日期 + /// 頁數 + /// + /// + [HttpGet("Query")] + public async Task> GetWorkStationLogQuery(string wipNo = null, string dateStr = null, string dateEnd = null, string type = null, int page = 0, int limit = 10) + { + ResultModel result = new ResultModel(); + + IQueryable q = from q1 in _context.WorkStationLogs + join q2 in _context.WipInfos on q1.wipNo equals q2.WipNO + join q3 in _context.Stationses on q1.StationID equals q3.StationID + join q4 in _context.UserInfoes on q1.CreateUserID equals q4.UserID + select new WorkStationLogDto + { + workStationid = q1.workStationid, + wipNo = q1.wipNo, + wipQty = q2.PlanQTY, + itemNo = q1.itemNo, + StationID = q1.StationID, + StationName = q3.StationName, + productionQty = q1.productionQty, + exceptionCode = q1.exceptionCode, + remarks = q1.remarks, + type = q1.type, + startTime = q1.startTime, + endTime = q1.endTime, + CreateUserName = q4.UserName + }; + + + if (!string.IsNullOrWhiteSpace(wipNo)) + q = q.Where(w => w.wipNo == wipNo); + + if (!string.IsNullOrWhiteSpace(type)) + q = q.Where(w => w.type == type); + + if (DateTime.TryParse(dateStr, out _)) + { + q = q.Where(w => w.startTime >= DateTime.Parse(dateStr + " 00:00:00")); + } + + if (DateTime.TryParse(dateEnd, out _)) + { + q = q.Where(w => w.startTime <= DateTime.Parse(dateEnd + " 23:59:59")); + } + + // 紀錄筆數 + result.DataTotal = q.Count(); + + // Table 頁數 + if (page > 0) + { + q = q.Skip((page - 1) * limit).Take(limit); + } + + result.Data = await q.ToListAsync(); + + foreach (var item in result.Data) + { + item.type = item.type == "A" ? "生產工時" : + item.type == "B" ? "無效工時" : + item.type == "C" ? "異常工時" : + item.type; + } + + return result; + } + + /// + /// 更新單站報工資料 + /// + /// + /// + [HttpPut] + public async Task> PutWorkStationLog(WorkStationLog workStationLog) + { + ResultModel result = new ResultModel(); + _context.Entry(workStationLog).State = EntityState.Modified; + _context.Entry(workStationLog).Property("CreateDate").IsModified = false; + _context.Entry(workStationLog).Property("CreateUserID").IsModified = false; + workStationLog.UpdateDate = DateTime.Now; + + try + { + await _context.SaveChangesAsync(); + result.Success = true; + result.Msg = "OK"; + } + catch (Exception ex) + { + result.Success = false; + result.Msg = ex.InnerException.Message; + } + return result; + } + + /// + /// 新增單站報工資料 + /// + /// + /// + [HttpPost] + public async Task> PostWorkStationLog(WorkStationLog workStationLog) + { + ResultModel result = new ResultModel(); + Helper helper = new Helper(_context); + workStationLog.workStationid = helper.GetIDKey("WORK_STATION_ID").Result; + _context.WorkStationLogs.Add(workStationLog); + try + { + await _context.SaveChangesAsync(); + result.Success = true; + result.Msg = "OK"; + } + catch (Exception ex) + { + result.Success = false; + result.Msg = ex.InnerException.Message; + } + return result; + } + + [HttpDelete("{id}")] + public async Task> DeleteWorkStationLog(int id) + { + ResultModel result = new ResultModel(); + var workStationLog = await _context.WorkStationLogs.FindAsync(id); + + try + { + if (workStationLog == null) + { + result.Success = false; + result.Msg = "找不到要刪除資料"; + } + else + { + _context.WorkStationLogs.Remove(workStationLog); + await _context.SaveChangesAsync(); + result.Success = true; + result.Msg = "OK"; + } + } + catch (Exception ex) + { + result.Success = false; + result.Msg = ex.InnerException.Message; + } + return result; + } + } +} diff --git a/AMESCoreStudio.WebApi/DTO/AMES/WorkStationLogDto.cs b/AMESCoreStudio.WebApi/DTO/AMES/WorkStationLogDto.cs new file mode 100644 index 00000000..17327cc9 --- /dev/null +++ b/AMESCoreStudio.WebApi/DTO/AMES/WorkStationLogDto.cs @@ -0,0 +1,109 @@ +using System; + +#nullable disable + +namespace AMESCoreStudio.WebApi.DTO.AMES +{ + /// + /// 單站報工資料Dto + /// + public partial class WorkStationLogDto + { + /// + /// 流水號 + /// + + public int workStationid { get; set; } = 0; + + /// + /// 工單號碼 + /// + + public string wipNo { get; set; } + + /// + /// 工單料號 + /// + + public string itemNo { get; set; } + + /// + /// 工單數量 + /// + + public int wipQty { get; set; } + + /// + /// 作業站 + /// + + public int StationID { get; set; } + + /// + /// 作業站 + /// + + public string StationName { get; set; } + + /// + /// 型態 + /// + public string type { get; set; } + + /// + /// 生產數量 + /// + public int? productionQty { get; set; } = 0; + + /// + /// 開始時間 + /// + public DateTime? startTime { get; set; } + + /// + /// 結束時間 + /// + public DateTime? endTime { get; set; } + + /// + /// 無效/異常代碼 + /// + public string exceptionCode { get; set; } + + /// + /// 備註 + /// + public string remarks { get; set; } + + /// + /// 建立UserID + /// + public int CreateUserID { get; set; } = 0; + + /// + /// 建立UserName + /// + public string CreateUserName { get; set; } + + /// + /// 建立日期 + /// + public DateTime CreateDate { get; set; } = DateTime.Now; + + /// + /// 更新UserID + /// + + public int? UpdateUserID { get; set; } = 0; + + /// + /// 建立UserName + /// + public string UpdateUserName { get; set; } + + /// + /// 更新日期 + /// + public DateTime? UpdateDate { get; set; } = DateTime.Now; + } +} diff --git a/AMESCoreStudio.WebApi/Models/AMES/WorkStationLog.cs b/AMESCoreStudio.WebApi/Models/AMES/WorkStationLog.cs new file mode 100644 index 00000000..3c4cf32a --- /dev/null +++ b/AMESCoreStudio.WebApi/Models/AMES/WorkStationLog.cs @@ -0,0 +1,118 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; + +#nullable disable + +namespace AMESCoreStudio.WebApi.Models.AMES +{ + /// + /// 單站報工資料 + /// + [Table("WORK_STATION_LOG", Schema = "JHAMES")] + public partial class WorkStationLog + { + /// + /// 流水號 + /// + [Key] + [Required] + [DataMember] + [Column("WORK_STATION_ID")] + public int workStationid { get; set; } = 0; + + /// + /// 工單號碼 + /// + [DataMember] + [Column("WIP_NO")] + public string wipNo { get; set; } + + /// + /// 工單料號 + /// + [DataMember] + [Column("ITEM_NO")] + public string itemNo { get; set; } + + /// + /// 作業站 + /// + [DataMember] + [Column("STATION_ID")] + public int StationID { get; set; } = 0; + + /// + /// 型態 + /// + [DataMember] + [Column("TYPE")] + public string type { get; set; } + + /// + /// 生產數量 + /// + [DataMember] + [Column("PRODUCTION_QTY")] + public int? productionQty { get; set; } = 0; + + /// + /// 開始時間 + /// + [Column("START_TIME")] + [DataMember] + [DataType(DataType.Text), DisplayFormat(DataFormatString = "{0:yyyy-MM-dd HH:mm:ss}", ApplyFormatInEditMode = true)] + public DateTime? startTime { get; set; } + + /// + /// 結束時間 + /// + [Column("END_TIME")] + [DataMember] + [DataType(DataType.Text), DisplayFormat(DataFormatString = "{0:yyyy-MM-dd HH:mm:ss}", ApplyFormatInEditMode = true)] + public DateTime? endTime { get; set; } + + /// + /// 無效/異常代碼 + /// + [DataMember] + [Column("EXCEPTION_CODE")] + public string exceptionCode { get; set; } + + /// + /// 備註 + /// + [DataMember] + [Column("REMARKS")] + public string remarks { get; set; } + + /// + /// 建立UserID + /// + [Column("CREATE_USERID")] + [DataMember] + public int CreateUserID { get; set; } = 0; + + /// + /// 建立日期 + /// + [Column("CREATE_DATE")] + [DataMember] + public DateTime CreateDate { get; set; } = DateTime.Now; + + /// + /// 更新UserID + /// + [Column("UPDATE_USERID")] + [DataMember] + public int? UpdateUserID { get; set; } = 0; + + /// + /// 更新日期 + /// + [Column("UPDATE_DATE")] + [DataMember] + public DateTime? UpdateDate { get; set; } = DateTime.Now; + } +} diff --git a/AMESCoreStudio.WebApi/Models/AMESContext.cs b/AMESCoreStudio.WebApi/Models/AMESContext.cs index bad4098b..a9a0adbd 100644 --- a/AMESCoreStudio.WebApi/Models/AMESContext.cs +++ b/AMESCoreStudio.WebApi/Models/AMESContext.cs @@ -1083,6 +1083,11 @@ namespace AMESCoreStudio.WebApi /// 異常警報檔案 /// public virtual DbSet NgInfoAlertBlobs { get; set; } + + /// + /// 單站報工資料 + /// + public virtual DbSet WorkStationLogs { get; set; } } }