From bdf068f827106978440b392701ccd0a414c505b8 Mon Sep 17 00:00:00 2001 From: Marvin Date: Tue, 24 May 2022 22:41:54 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=96=B0=E5=A2=9E=E7=B6=AD=E4=BF=AE=E9=80=B2?= =?UTF-8?q?/=E5=87=BA=E7=B5=B1=E8=A8=88=E5=A0=B1=E8=A1=A8REP013=202.?= =?UTF-8?q?=E4=BF=AE=E6=94=B9WipAlarmsController=E5=A2=9E=E5=8A=A0PostWipA?= =?UTF-8?q?larm4ErrorCode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/REPController.cs | 17 + AMESCoreStudio.Web/HttpApis/AMES/IREP.cs | 7 + AMESCoreStudio.Web/Views/REP/REP013.cshtml | 300 ++++++++++++++++++ .../Controllers/AMES/NgRepairsController.cs | 145 +++++++++ .../Controllers/AMES/WipAlarmsController.cs | 127 ++++++++ 5 files changed, 596 insertions(+) create mode 100644 AMESCoreStudio.Web/Views/REP/REP013.cshtml diff --git a/AMESCoreStudio.Web/Controllers/REPController.cs b/AMESCoreStudio.Web/Controllers/REPController.cs index 18d751a8..2d79b89d 100644 --- a/AMESCoreStudio.Web/Controllers/REPController.cs +++ b/AMESCoreStudio.Web/Controllers/REPController.cs @@ -1108,5 +1108,22 @@ namespace AMESCoreStudio.Web.Controllers return Json(new Table() { count = 0, data = null }); } #endregion + + public IActionResult REP013() + { + return View(); + } + + public async Task REP013QueryAsync(string wipNO, string itemNO, string dateStart, string dateEnd, int page = 0, int limit = 10) + { + + var result = await _repApi.GetRepairData4REP013(wipNO, itemNO, dateStart, dateEnd, 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/IREP.cs b/AMESCoreStudio.Web/HttpApis/AMES/IREP.cs index 3e4d3df1..d7be5396 100644 --- a/AMESCoreStudio.Web/HttpApis/AMES/IREP.cs +++ b/AMESCoreStudio.Web/HttpApis/AMES/IREP.cs @@ -225,5 +225,12 @@ namespace AMESCoreStudio.Web ITask> GetWipAlarmsByType(int id, int page = 0, int limit = 10); #endregion + + /// + /// 維修進/出統計報表 + /// + /// + [WebApiClient.Attributes.HttpGet("api/NgRepairs/GetRepairData4REP013")] + ITask> GetRepairData4REP013(string wipNo, string itemNo, string dateStart, string dateEnd, int page, int limit); } } diff --git a/AMESCoreStudio.Web/Views/REP/REP013.cshtml b/AMESCoreStudio.Web/Views/REP/REP013.cshtml new file mode 100644 index 00000000..c54229b3 --- /dev/null +++ b/AMESCoreStudio.Web/Views/REP/REP013.cshtml @@ -0,0 +1,300 @@ +@{ + ViewData["Title"] = "維修進/出統計報表"; + Layout = "~/Views/Shared/_AMESLayout.cshtml"; +} + + + + +
+
+
+
+
@ViewBag.Title
+
+
+
+
+
+
+
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+
+
+
+
+
+
+ +
+ +
+
+
+ +
+
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+ +@section Scripts{ + + +} diff --git a/AMESCoreStudio.WebApi/Controllers/AMES/NgRepairsController.cs b/AMESCoreStudio.WebApi/Controllers/AMES/NgRepairsController.cs index d504b8ca..aeff34f2 100644 --- a/AMESCoreStudio.WebApi/Controllers/AMES/NgRepairsController.cs +++ b/AMESCoreStudio.WebApi/Controllers/AMES/NgRepairsController.cs @@ -354,6 +354,151 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES return result; } + + /// + /// 維修進/出統計報表 + /// + /// + /// + /// + /// + /// + /// + /// + [Route("[action]")] + [HttpGet] + public async Task> GetRepairData4REP013(string wipNo, string itemNo, string dateStart, string dateEnd, int page = 0, int limit = 10) + { + ResultModel result = new ResultModel(); + var q = from q1 in _context.NgRepairs + join q2 in _context.NgInfos on q1.NgID equals q2.NgID + join q3 in _context.BarcodeInfoes on q2.BarcodeID equals q3.BarcodeID + join q4 in _context.WipInfos on q3.WipID equals q4.WipID + join q5 in _context.WipAtts on q4.WipNO equals q5.WipNO + join q6 in _context.LineInfoes on q4.LineID equals q6.LineID + join q7 in _context.Stationses on q2.StationId equals q7.StationID + join q8 in _context.NgComponents on q2.NgID equals q8.NgID + join q9 in _context.RepairResponsibleUnitses on q1.RepairResponsibleID equals q9.RRID + join qa in _context.NGReasons on q8.NgNo equals qa.NGReasonNo + join qb in _context.RepairTypes on q1.RepairTypeNo equals qb.RepairTypeNo + join qc in _context.UserInfoes on q1.CreateUserID equals qc.UserID + join qd in _context.UserInfoes on q2.CreateUserID equals qd.UserID + join qe in _context.TestTypes on q2.TypeNo equals qe.TypeNo + join qf in _context.UserInfoes on q8.ReplyUserID equals qf.UserID + join qg in _context.RMAReasons on q1.RepairNo equals qg.RMAReasonNo + join qh in _context.QATypes on qg.QATypeId equals qh.QATypeID + join qi in _context.CalendarTables on q1.CreateDate.Date equals qi.TimeID + select new + { + q4.UnitNO, + q6.LineDesc, + q1.CreateDate, + qi.Month, + qi.WeekOfYearISO, + q7.StationName, + q4.WipNO, + q4.PlanQTY, + q3.BarcodeNo, + q5.ModelNO, + q5.ItemNO, + q8.SemiItemNo, + q8.OldPartNo, + q8.NewPartNo, + q8.NgNo, + ReasonDesc = q8.NgNo + '-' + qa.NGReasonDesc, + q8.LocationNo, + q8.ChangeMaterial, + RepairReason = q1.RepairNo + '-' + q1.RepairDesc, + RepairType2 = qb.RepairTypeNo + '-' + qb.RepairTypeDesc, + q1.Memo, + q1.RepairDesc, + NgType2 = qa.NGReasonNo + '-' + qa.NGReasonDesc, + ResponsibleUnit = q9.RRID + '-' + q9.RRDesc, + q9.RRDesc, + qc.UserNo, + qc.UserName, + q8.ReplyDate, + //RepairDays = (q8.ReplyDate-q2.CreateDate).TotalDays, + TestDate = q2.CreateDate, + TestUserNo = qd.UserNo, + TestUserName = qd.UserName, + TestTypeName = qe.TypeName, + qh.QATypeName, + qa.NGReasonDescEn, + q1.PartNo, + q8.PinNo, + q8.ReelNo, + q8.DateCode, + q8.VendorCode, + q8.ReplyReason, + q8.ReplyMeasure, + q8.ReplyUserID, + ReplyUserNo = qf.UserNo, + ReplyUserName = qf.UserName, + q4.LineID, + q2.TypeNo, + q2.StationId, + q1.RepairNo, + q2.ReasonNo, + CheckInDate = q2.CreateDate, + CheckInUserNo = qd.UserNo, + CheckInUserName = qd.UserName, + CheckOutUserNo = qc.UserNo, + CheckOutUserName = qc.UserName, + CheckOutDate = q1.CreateDate, + TAT = EF.Functions.DateDiffHour(q2.CreateDate, q1.CreateDate), + StateDesc = (qc.UserName != "" ? "出站" : "進站") + }; + + if (wipNo != null) + { + if (wipNo != "") + { + q = q.Where(w => w.WipNO == wipNo); + } + } + + if (itemNo != null) + { + if (itemNo != "") + { + q = q.Where(w => w.ItemNO == itemNo); + } + } + + if (dateStart != null && dateEnd != null) + { + if (dateStart != "" && dateEnd != "") + { + q = q.Where(w => w.CreateDate >= DateTime.Parse(dateStart) && w.CreateDate <= DateTime.Parse(dateEnd)); + } + } + + q = q.OrderBy(w => w.CreateDate); + + //紀錄筆數 + 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; + } + /// /// 維修資料統計by不良代碼 /// diff --git a/AMESCoreStudio.WebApi/Controllers/AMES/WipAlarmsController.cs b/AMESCoreStudio.WebApi/Controllers/AMES/WipAlarmsController.cs index 7eb0b165..9c7e810f 100644 --- a/AMESCoreStudio.WebApi/Controllers/AMES/WipAlarmsController.cs +++ b/AMESCoreStudio.WebApi/Controllers/AMES/WipAlarmsController.cs @@ -7,7 +7,11 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using AMESCoreStudio.WebApi; using AMESCoreStudio.WebApi.Models.AMES; +using AMESCoreStudio.WebApi.Models.BAS; using AMESCoreStudio.CommonTools.Result; +using Microsoft.Extensions.Configuration; +using System.Net; +using System.Net.Mail; namespace AMESCoreStudio.WebApi.Controllers.AMES { @@ -19,6 +23,7 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES public class WipAlarmsController : ControllerBase { private readonly AMESContext _context; + private readonly IConfiguration _config; /// /// @@ -182,6 +187,128 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES return result; } + /// + /// 判斷同一不良代碼累計預警 + /// + /// 工單號碼 + /// 不良代碼 + /// + [Route("[action]")] + [HttpPost] + public async Task> PostWipAlarm4ErrorCode(string wipNO, string errorCode) + { + ResultModel result = new ResultModel(); + + //判断预警 + var q1 = from a in _context.NgComponents + join b in _context.NgInfos on a.NgID equals b.NgID + join c in _context.BarcodeInfoes on b.BarcodeID equals c.BarcodeID + join d in _context.WipInfos on c.WipID equals d.WipID + select new + { + a.NgNo, + d.WipNO + }; + + q1 = q1.Where(w => w.WipNO.Equals(wipNO)); + q1 = q1.Where(w => w.NgNo.Equals(errorCode)); + + var data1 = await q1.ToListAsync(); + + if (data1.Count > 3) + { + try + { + //保存警报资料 + string alarmDesc = string.Format("工單號碼{0}不良代碼{1}累積超過{2}次", wipNO, errorCode, data1.Count); + + Helper helper = new Helper(_context); + + WipAlarm wipAlarm = new WipAlarm(); + wipAlarm.WipAlarmID = helper.GetIDKey("WIP_ALARMID").Result; + wipAlarm.AlarmTypeID = 1; + wipAlarm.WipNO = wipNO; + wipAlarm.AlarmParam = errorCode; + wipAlarm.AlarmValue = data1.Count.ToString(); + wipAlarm.AlarmDesc = alarmDesc; + wipAlarm.AlarmDateTime = DateTime.Now; + + _context.WipAlarms.Add(wipAlarm); + await _context.SaveChangesAsync(); + + //发送警报资料 + + string mailSubject = "警報持續郵件" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + string mailBody = ""; + mailBody = mailBody + "警報工單:" + wipNO + "
"; + mailBody = mailBody + "警報時間:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "
"; + mailBody = mailBody + "警報原因:" + alarmDesc + "
"; + + string mailFrom = _config["MailForm"].ToString(); + //string mailTo = _config["MailTo"].ToString(); + string mailSmtpServer = _config["MailSmtpServer"].ToString(); + int mailSmtpPort = int.Parse(_config["MailSmtpPort"].ToString()); + string mailUser = _config["MailUser"].ToString(); + string mailPassword = _config["MailUserPassword"].ToString(); + + MailMessage mesMail = new MailMessage(); + mesMail.From = new MailAddress(mailFrom); + + IQueryable q3 = _context.MailGroups; + q3 = q3.Where(p => p.GroupNo.Equals("WIP_ALARM")); + var mail1 = await q3.ToListAsync(); + + if (mail1.Count > 0) + { + var q4 = from a in _context.MailGroups + join b in _context.MailGroupDetails on a.GroupID equals b.GroupID + join c in _context.UserInfoes on b.UserID equals c.UserID + select new + { + a.GroupID, + b.UserID, + c.UserEMail + }; + + q4 = q4.Where(w => w.GroupID.Equals(mail1[0].GroupID)); + + var mail2 = await q4.ToListAsync(); + if (mail2.Count > 0) + { + for (int i = 0; i < mail2.Count; i++) + { + mesMail.To.Add(new MailAddress(mail2[i].UserEMail)); + } + } + + //mesMail.To.Add(new MailAddress(mailTo)); + + mesMail.Subject = mailSubject; + mesMail.SubjectEncoding = System.Text.Encoding.UTF8; + mesMail.Body = mailBody; + mesMail.IsBodyHtml = true; + mesMail.BodyEncoding = System.Text.Encoding.UTF8; + + SmtpClient mailClient = new SmtpClient(mailSmtpServer, mailSmtpPort); + + //mailClient.EnableSsl = true; + NetworkCredential nc = new NetworkCredential(); + nc.UserName = mailUser; + nc.Password = mailPassword; + mailClient.Credentials = nc; + + mailClient.Send(mesMail); + + } + } + catch { } + + } + result.Success = true; + result.Msg = "OK"; + return result; + } + /// /// ///