From 28d119ab8b64fcc0ae62efc3104fa14b777cb2cd Mon Sep 17 00:00:00 2001 From: Marvin Date: Tue, 21 Jun 2022 20:17:31 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=96=B0=E5=A2=9E=E5=A4=96=E5=8C=85=E6=A9=9F?= =?UTF-8?q?=E7=A8=AE=E8=B3=87=E6=96=99=E4=B8=8A=E5=82=B3PDS003?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/PDSController.cs | 443 ++++++++++++++++++ AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs | 11 + AMESCoreStudio.Web/HttpApis/AMES/IPDS.cs | 61 +++ AMESCoreStudio.Web/Views/PDS/PDS003.cshtml | 163 +++++++ .../Controllers/AMES/WipBarcodeController.cs | 1 + .../Controllers/AMES/WipInfosController.cs | 52 ++ AMESCoreStudio.WebApi/Models/AMESContext.cs | 7 + 7 files changed, 738 insertions(+) create mode 100644 AMESCoreStudio.Web/Controllers/PDSController.cs create mode 100644 AMESCoreStudio.Web/HttpApis/AMES/IPDS.cs create mode 100644 AMESCoreStudio.Web/Views/PDS/PDS003.cshtml diff --git a/AMESCoreStudio.Web/Controllers/PDSController.cs b/AMESCoreStudio.Web/Controllers/PDSController.cs new file mode 100644 index 00000000..683d7a3e --- /dev/null +++ b/AMESCoreStudio.Web/Controllers/PDSController.cs @@ -0,0 +1,443 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Logging; +using System.Threading.Tasks; +using System.Collections.Generic; +using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.AspNetCore.Http; +using System.IO; +using AMESCoreStudio.WebApi.Models.AMES; +using AMESCoreStudio.CommonTools.Result; +using Newtonsoft.Json; +using AMESCoreStudio.WebApi.DTO.AMES; +using AMESCoreStudio.Web.Models; +using Newtonsoft.Json.Linq; +using AMESCoreStudio.WebApi.Models.BAS; + +namespace AMESCoreStudio.Web.Controllers +{ + public class PDSController : Controller + { + private readonly ILogger _logger; + public readonly IBAS _basApi; + public readonly IPCS _pcsApi; + public readonly IPDS _pdsApi; + + public PDSController(ILogger logger, IPCS pcsApi, IBAS basApi,IPDS pdsApi) + { + _logger = logger; + _pcsApi = pcsApi; + _basApi = basApi; + _pdsApi = pdsApi; + } + + private async Task GetUnitList() + { + var result = await _basApi.GetFactoryUnits(); + + var UnitItems = new List(); + for (int i = 0; i < result.Count; i++) + { + UnitItems.Add(new SelectListItem(result[i].UnitName, result[i].UnitNo.ToString())); + } + ViewBag.UnitList = UnitItems; + } + + private async Task GetLineInfoList() + { + var result = await _basApi.GetLineInfoes(); + + var LineItems = new List(); + for (int i = 0; i < result.Count; i++) + { + LineItems.Add(new SelectListItem(result[i].LineDesc, result[i].LineID.ToString())); + } + ViewBag.LineList = LineItems; + } + + private async Task GetFlowRuleList() + { + var result = await _basApi.GetFlowRules(); + + var FlowRuleItems = new List(); + for (int i = 0; i < result.Count; i++) + { + FlowRuleItems.Add(new SelectListItem(result[i].UnitNo + result[i].FlowRuleName, result[i].FlowRuleID.ToString())); + } + ViewBag.FlowRuleList = FlowRuleItems; + } + + [HttpPost] + public async Task GetUnitLineJson(string unit_no) + { + var result = await _basApi.GetLineInfoByUnit(unit_no); + + var item = new List(); + + for (int i = 0; i < result.Count; i++) + { + item.Add(new SelectListItem(result[i].LineDesc, result[i].LineID.ToString())); + } + + if (item.Count == 0) + { + item.Add(new SelectListItem("全部", "0")); + } + + //将数据Json化并传到前台视图 + return Json(new { data = item }); + } + + public async Task PDS003() + { + await GetUnitList(); + await GetLineInfoList(); + await GetFlowRuleList(); + + return View(); + } + + [HttpPost] + public async Task PDS003SaveAsync(string unitNo,int lineId,int flowId,IFormFile formFile) + { + IResultModel result1; + IResultModel result2; + + var userID = ""; + HttpContext.Request.Cookies.TryGetValue("UserID", out userID); + int user_id = 0; + if (userID != null) + { + if (int.Parse(userID.ToString()) >= 0) + { + user_id = int.Parse(userID.ToString()); + } + } + + await GetUnitList(); + await GetLineInfoList(); + await GetFlowRuleList(); + + var file = formFile; + var msg = ""; + + if (unitNo == "*") + { + msg += "未選擇製程單位"; + ModelState.AddModelError("error", msg); + return View("PDS003"); + } + + if (lineId == 0) + { + msg += "未選擇線別"; + ModelState.AddModelError("error", msg); + return View("PDS003"); + } + + if (flowId == 0) + { + msg += "未選擇流程"; + ModelState.AddModelError("error", msg); + return View("PDS003"); + } + + + if (formFile == null) + { + msg += "未選取檔案或檔案上傳失敗"; + ModelState.AddModelError("error", msg); + return View("PDS003"); + } + + if (Path.GetExtension(file.FileName) != ".xlsx") + { + msg += "請使用Excel 2007(.xlsx)格式"; + ModelState.AddModelError("error", msg); + return View("PDS003"); + } + + if (file.Length > 0) + { + string[] fileTitle = file.FileName.Split("_"); + + string wipNO = fileTitle[2]; + string itemNO = fileTitle[3]; + int playQty = 0; + int.TryParse(fileTitle[4].Replace("pc", ""), out playQty); + int wipID = -1; + bool existFlag = false; + ViewBag.WipNo = wipNO; + + //虛擬工單 + result2 = await _pcsApi.GetWipInfo4PDS003(wipNO); + if (result2.DataTotal == 0) + { + WipInfo wip_info = new WipInfo(); + wip_info.WipNO = wipNO; + wip_info.PlanQTY = playQty; + wip_info.LineID = lineId; + wip_info.UnitNO = unitNo; + wip_info.FlowRuleID = flowId; + wip_info.StatusNO = "A"; + wip_info.WipTimes = 1; + wip_info.Werks = "YSOS"; + wip_info.WipType = "S"; + wip_info.CustomerType = -1; + wip_info.CreateUserID = user_id; + wip_info.CreateDate = System.DateTime.Now; + + result1 = await _pcsApi.PostWipInfo(JsonConvert.SerializeObject(wip_info)); + + if (!result1.Success) + { + msg += "虛擬工單建立WIP_INFO失敗!!!原因:" + result1.Msg + "\r\n"; + ModelState.AddModelError("error", msg); + return View("PDS003"); + } + else + { + int.TryParse(result1.Msg, out wipID); + + //WIP_ATT + WipAtt wip_att = new WipAtt(); + wip_att.WipNO = wipNO; + wip_att.ItemNO = itemNO; + wip_att.CreateUserID = user_id; + wip_att.CreateDate = System.DateTime.Now; + + result1 = await _pcsApi.PostWipAtt(JsonConvert.SerializeObject(wip_att)); + if (!result1.Success) + { + msg += "虛擬工單建立WIP_ATT失敗!!!原因:" + result1.Msg + "\r\n"; + ModelState.AddModelError("error", msg); + return View("PDS003"); + } + + //開線 + var line_info = await _basApi.GetLineInfo(lineId); + LineInfo line = new LineInfo(); + line.LineID = lineId; + line.DeptID = line_info[0].DeptID; + line.LineDesc = line_info[0].LineDesc; + line.Story = line_info[0].Story; + line.UnitNo = line_info[0].UnitNo; + line.WipNo = wipID; + line.StatusNo = line_info[0].StatusNo; + line.CreateUserId = line_info[0].CreateUserId; + line.CreateDate = line_info[0].CreateDate; + line.UpdateDate = line_info[0].UpdateDate; + + result1 = await _basApi.PutLineInfo(lineId, JsonConvert.SerializeObject(line)); + if (!result1.Success) + { + msg += "虛擬工單開線失敗!!!原因:" + result1.Msg + "\r\n"; + ModelState.AddModelError("error", msg); + return View("PDS003"); + } + } + } + else + { + existFlag = true; + + foreach (var item in result2.Data) + { + JObject jo = JObject.Parse(item.ToString()); + wipID = int.Parse(jo["wipID"].ToString()); + lineId = int.Parse(jo["lineID"].ToString()); + flowId = int.Parse(jo["flowRuleID"].ToString()); + + } + } + using (var ms = new MemoryStream()) + { + file.CopyTo(ms); + var fileBytes = ms.ToArray(); + string s = System.Convert.ToBase64String(fileBytes); + ClosedXML.Excel.XLWorkbook wb = new ClosedXML.Excel.XLWorkbook(ms); + + if (wb.Worksheets.Count > 1) + { + msg = "工作表大於一頁"; + ModelState.AddModelError("error", msg); + return View("PDS003"); + } + else + { + // 讀取第一個 Sheet + ClosedXML.Excel.IXLWorksheet worksheet = wb.Worksheet(1); + + // 定義資料起始/結束 Cell + var firstCell = worksheet.FirstCellUsed(); + var lastCell = worksheet.LastCellUsed(); + var firstCol1 = worksheet.Cell(1, 1).Value.ToString(); + var firstCol2 = worksheet.Cell(1, 2).Value.ToString(); + var firstCol3 = worksheet.Cell(1, 3).Value.ToString(); + var firstCol4 = worksheet.Cell(1, 4).Value.ToString(); + var firstCol5 = worksheet.Cell(1, 5).Value.ToString(); + var firstCol6 = worksheet.Cell(1, 6).Value.ToString(); + var erroCol = ""; + + + if (lastCell.Address.ColumnNumber != 6) + erroCol += "請確認欄位是否正確,總數應為6欄\r\n"; + + if (firstCol1 != "DATE") + erroCol += "第一個欄位標題應該為DATE\r\n"; + + if (firstCol2 != "ITEM") + erroCol += "第二個欄位標題應該為ITEM\r\n"; + + if (firstCol3 != "SN") + erroCol += "第三個欄位標題應該為SN\r\n"; + + if (firstCol4 != "MB") + erroCol += "第四個欄位標題應該為MB\r\n"; + + if (firstCol5 != "MAC") + erroCol += "第五個欄位標題應該為MAC\r\n"; + + if (firstCol6 != "Panel") + erroCol += "第六個欄位標題應該為Panel\r\n"; + + var resultMsg = ""; + var count = 0; + + for (int i = 2; i <= lastCell.Address.RowNumber; i++) + { + var Cell1 = worksheet.Cell(i, 1).Value.ToString().ToUpper(); + var Cell2 = worksheet.Cell(i, 2).Value.ToString().ToUpper(); + var Cell3 = worksheet.Cell(i, 3).Value.ToString().ToUpper(); + var Cell4 = worksheet.Cell(i, 4).Value.ToString().ToUpper(); + var Cell5 = worksheet.Cell(i, 5).Value.ToString().ToUpper(); + var Cell6 = worksheet.Cell(i, 6).Value.ToString().ToUpper(); + + if (string.IsNullOrEmpty(Cell1) || string.IsNullOrEmpty(Cell2) || string.IsNullOrEmpty(Cell3) || string.IsNullOrEmpty(Cell4) || string.IsNullOrEmpty(Cell5) || string.IsNullOrEmpty(Cell6)) + { + resultMsg += "第" + i + "列有缺少資料!!\r\n"; + } + else + { + if (!existFlag) + { + //設定工單條碼起訖 + WipBarcode wip_barcode = new WipBarcode(); + wip_barcode.WipNO = wipNO; + wip_barcode.StartNO = Cell3; + wip_barcode.EndNO = Cell3; + wip_barcode.UnitNO = unitNo; + wip_barcode.WipID = wipID; + + result1 = await _pcsApi.PostWipBarcode(JsonConvert.SerializeObject(wip_barcode)); + if (result1.Success) + { + resultMsg += "第" + i + "行:設定工單起訖成功!!!" + "\r\n"; + } + else + { + resultMsg += "第" + i + "行:設定工單起訖失敗!!!原因:" + result1.Msg + "\r\n"; + } + } + + //获取站别 + var rule_station = await _basApi.GetRuleStationsByFlow(flowId); + int ruleStationID = rule_station[0].RuleStationID; + int stationID = rule_station[0].StationID; + //自動過站 + var barCode = new BarCodeCheckDto + { + wipNo = wipNO, + barcode = Cell3, + barcodeType = "S", + station = stationID, + line = lineId, + unitNo = unitNo, + inputItems = null, + userID = user_id + }; + + var barcode_result = new ResultModel(); + try + { + barcode_result = await _pcsApi.PassIngByCheck(JsonConvert.SerializeObject(barCode)); + } + catch { } + + if (barcode_result.Success) + { + resultMsg += "第" + i + "行:資料過站成功!!!" + "\r\n"; + } + else + { + resultMsg += "第" + i + "行:資料過站失敗!!!原因:" + barcode_result.Msg + "\r\n"; + } + + //保存資料 + + SNKeyPart snKeyPart = new SNKeyPart(); + snKeyPart.StockInNo = fileTitle[2]; + snKeyPart.StockInPn = fileTitle[3]; + snKeyPart.KPDate = System.DateTime.Parse(Cell1); + snKeyPart.KPItem = int.Parse(Cell2); + snKeyPart.KPSn = Cell3; + snKeyPart.KPMb = Cell4; + snKeyPart.KPMac = Cell5; + snKeyPart.KPPanel = Cell6; + snKeyPart.CreateUserID = user_id; + snKeyPart.CreateDate = System.DateTime.Now; + + result1 = await _pdsApi.PostSNKeyPart(JsonConvert.SerializeObject(snKeyPart)); + + if (!result1.Success) + { + resultMsg += "第" + i + "行:資料寫入失敗!!!原因:" + result1.Msg + "\r\n"; + } + else + count++; + + /* + if (Cell1.Length > 20) + erroCol += "第" + i + "列DATE資料過長!!\r\n"; + */ + } + + } + if (resultMsg != "") + { + ModelState.AddModelError("error", resultMsg); + return View("PDS003"); + + } + else + { + ModelState.AddModelError("error", "資料寫入成功!!"); + return View("PDS003"); + } + + } + + } + + + } + + return View("PDS003"); + } + + [ResponseCache(Duration = 0)] + [HttpGet] + public async Task GetSNKeyPartByStockInNo(string no, int page = 0, int limit = 10) + { + var result_total = await _pdsApi.GetSNKeyPartByStockInNo(no, 0, limit); + var result = await _pdsApi.GetSNKeyPartByStockInNo(no, page, limit); + + if (result.Count > 0) + { + return Json(new Table() { code = 0, msg = "", data = result, count = result.Count }); + } + + 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 2c6f1ef2..126ed28f 100644 --- a/AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs +++ b/AMESCoreStudio.Web/HttpApis/AMES/IPCS.cs @@ -992,6 +992,17 @@ namespace AMESCoreStudio.Web #endregion + #region PDS003 查詢工單基本資料 + + /// + /// 查詢工單基本資料PDS003 + /// + /// + [WebApiClient.Attributes.HttpGet("api/WipInfos/GetWipInfo4PDS003")] + ITask> GetWipInfo4PDS003(string wipNO); + + #endregion + #region WipKp 工單KP資訊資料檔 /// /// 查詢工單號碼 對應 WipKp diff --git a/AMESCoreStudio.Web/HttpApis/AMES/IPDS.cs b/AMESCoreStudio.Web/HttpApis/AMES/IPDS.cs new file mode 100644 index 00000000..69a8cde9 --- /dev/null +++ b/AMESCoreStudio.Web/HttpApis/AMES/IPDS.cs @@ -0,0 +1,61 @@ +using System.Collections.Generic; +using WebApiClient; +using WebApiClient.Attributes; +using AMESCoreStudio.WebApi; +using Microsoft.AspNetCore.Mvc; +using AMESCoreStudio.WebApi.Models.AMES; +using AMESCoreStudio.WebApi.Models.BAS; +using AMESCoreStudio.CommonTools.Result; + +namespace AMESCoreStudio.Web +{ + [JsonReturn] + public interface IPDS:IHttpApi + { + #region PDS003 外包機種資料維護 + + /// + /// 新增外包機種資料 + /// + /// + [WebApiClient.Attributes.HttpPost("api/SNKeyParts")] + ITask> PostSNKeyPart([FromBody, RawJsonContent] string model); + + /// + /// 更新外包機種資料 + /// + /// + [WebApiClient.Attributes.HttpPut("api/SNKeyParts/{id}")] + ITask> PutSNKeyPart(string id, [FromBody, RawJsonContent] string model); + + /// + /// 刪除外包機種資料 + /// + /// + [WebApiClient.Attributes.HttpDelete("api/SNKeyParts/{id}")] + ITask> DeleteSNKeyPart(string id); + + /// + /// 根據ID獲取指定外包機種資料 + /// + /// + [WebApiClient.Attributes.HttpGet("api/SNKeyParts/{id}")] + ITask> GetSNKeyPart(string id); + + /// + /// 獲取外包機種資料 + /// + /// + [WebApiClient.Attributes.HttpGet("api/SNKeyParts")] + ITask> GetSNKeyParts(int page = 0, int limit = 10); + + /// + /// 獲取外包機種資料by入庫單 + /// + /// + [WebApiClient.Attributes.HttpGet("api/SNKeyParts/StockInNo")] + ITask> GetSNKeyPartByStockInNo(string no,int page = 0, int limit = 10); + + #endregion + } +} diff --git a/AMESCoreStudio.Web/Views/PDS/PDS003.cshtml b/AMESCoreStudio.Web/Views/PDS/PDS003.cshtml new file mode 100644 index 00000000..353c06f5 --- /dev/null +++ b/AMESCoreStudio.Web/Views/PDS/PDS003.cshtml @@ -0,0 +1,163 @@ +@{ + ViewData["Title"] = "PDS003"; + Layout = "~/Views/Shared/_AMESLayout.cshtml"; +} + +
+
+
+
+
@ViewBag.Title
+
+
+
+ +
+
+
+
+
+
+
+ +
+ +
+ +
+
+
+
+ +
+ +
+ +
+
+
+
+ +
+ +
+ +
+
+
+
+
+
+
+ + + +
+
+
+
+
+
+
@Html.ValidationMessage("error")
+
+
+
+
+
+
+
+ + +@section Scripts{ + +} \ No newline at end of file diff --git a/AMESCoreStudio.WebApi/Controllers/AMES/WipBarcodeController.cs b/AMESCoreStudio.WebApi/Controllers/AMES/WipBarcodeController.cs index c27c4983..699b6295 100644 --- a/AMESCoreStudio.WebApi/Controllers/AMES/WipBarcodeController.cs +++ b/AMESCoreStudio.WebApi/Controllers/AMES/WipBarcodeController.cs @@ -97,6 +97,7 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES wipBarcode.WipID = wipBarcode.WipID == 0 ? helper.GetIDKeyNoPost("WIP_ID").Result : wipBarcode.WipID; _context.WipBarcodes.Add(wipBarcode); await _context.SaveChangesAsync(); + result.Success = true; } catch (DbUpdateConcurrencyException ex) { diff --git a/AMESCoreStudio.WebApi/Controllers/AMES/WipInfosController.cs b/AMESCoreStudio.WebApi/Controllers/AMES/WipInfosController.cs index 1fcee954..94b6f558 100644 --- a/AMESCoreStudio.WebApi/Controllers/AMES/WipInfosController.cs +++ b/AMESCoreStudio.WebApi/Controllers/AMES/WipInfosController.cs @@ -103,6 +103,58 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES return result; } + /// + /// 查詢工單資料PDS003 + /// + /// + [Route("[action]")] + [HttpGet] + public async Task> GetWipInfo4PDS003(string wipNO) + { + ResultModel result = new ResultModel(); + var q = from q1 in _context.WipInfos + join q2 in _context.WipAtts on q1.WipNO equals q2.WipNO into wip_att + from x in wip_att.DefaultIfEmpty() + join q3 in _context.LineInfoes on q1.LineID equals q3.LineID + join q4 in _context.FactoryUnits on q1.UnitNO equals q4.UnitNo + select new + { + q1.WipID, + q1.WipNO, + q1.PlanQTY, + q1.CompleteQTY, + q1.UnitNO, + q1.LineID, + q1.FlowRuleID, + q1.StatusNO, + q1.CreateDate, + x.ItemNO, + q3.LineDesc, + q4.UnitName + }; + + if (wipNO != null && wipNO != "") + { + q = q.Where(w => w.WipNO == wipNO); + } + + //紀錄筆數 + result.DataTotal = q.Count(); + + result.Data = await q.ToListAsync(); + + if (result == null) + { + result.Msg = "查無資料"; + result.Success = false; + return result; + } + + result.Success = true; + result.Msg = "OK"; + return result; + } + /// /// 查詢工單資料QRS011 /// diff --git a/AMESCoreStudio.WebApi/Models/AMESContext.cs b/AMESCoreStudio.WebApi/Models/AMESContext.cs index 02c7b3b5..99fefe90 100644 --- a/AMESCoreStudio.WebApi/Models/AMESContext.cs +++ b/AMESCoreStudio.WebApi/Models/AMESContext.cs @@ -108,6 +108,8 @@ namespace AMESCoreStudio.WebApi //modelBuilder.Entity().HasOne(r => r.User).WithMany().HasForeignKey(r => r.MissingUserID).IsRequired(); modelBuilder.Entity().HasOne(r => r.InspectionItem).WithMany().HasForeignKey(r => r.InspectionItemID).IsRequired(); modelBuilder.Entity().HasOne(r => r.FactoryUnit).WithMany().HasForeignKey(r => r.UnitNo).IsRequired(); + + modelBuilder.Entity().HasKey(c => new { c.StockInNo, c.KPItem }); } /// @@ -800,6 +802,11 @@ namespace AMESCoreStudio.WebApi /// 工時收集資料檔 /// public DbSet WorkingHoursCollections { get; set; } + + /// + /// 外包機種資料 + /// + public DbSet SNKeyParts { get; set; } } }