diff --git a/AMESCoreStudio.Web/Controllers/SPCController.cs b/AMESCoreStudio.Web/Controllers/SPCController.cs index bc28832f..05f295b9 100644 --- a/AMESCoreStudio.Web/Controllers/SPCController.cs +++ b/AMESCoreStudio.Web/Controllers/SPCController.cs @@ -1483,20 +1483,33 @@ namespace AMESCoreStudio.Web.Controllers { return View(); } + var StationItems = new List(); string WipNO = result.Select(s => s.WipNo).FirstOrDefault(); if (!string.IsNullOrWhiteSpace(WipNO)) { var result1 = await _pcsApi.GetWipInfoByWipNO(WipNO); //站別 - var Wipinfo = await _basApi.GetRuleStationsByFlow(result1.Select(s=>s.FlowRuleID).FirstOrDefault(), 0, 20); - var StationItems = new List(); - - foreach (var item in Wipinfo) + var Wipinfo = await _basApi.GetRuleStationsByFlow(result1.Select(s => s.FlowRuleID).FirstOrDefault(), 0, 20); + + if (Wipinfo.Count() > 0) + { + foreach (var item in Wipinfo) + { + StationItems.Add(new SelectListItem(item.StationDesc, item.StationID.ToString())); + } + } + else { - StationItems.Add(new SelectListItem(item.StationDesc, item.StationID.ToString())); + StationItems.Add(new SelectListItem("N/A", "-1")); } - ViewBag.StationList = StationItems; + + } + else + { + StationItems.Add(new SelectListItem("N/A", "-1")); + } + ViewBag.StationList = StationItems; return View(result[0]); } public async Task SPC006USaveAsync(IPQCTaskNotice model) diff --git a/AMESCoreStudio.Web/Views/SPC/SPC006.cshtml b/AMESCoreStudio.Web/Views/SPC/SPC006.cshtml index be7ac258..6fc2fd39 100644 --- a/AMESCoreStudio.Web/Views/SPC/SPC006.cshtml +++ b/AMESCoreStudio.Web/Views/SPC/SPC006.cshtml @@ -160,7 +160,7 @@ sort: true, templet: function (item) { var btns = ''; - if (item.statusNo == "Y" && item.checkUserID == "-1") + if (item.statusNo == "Y") btns = btns + '確認'; return btns; @@ -186,7 +186,7 @@ //通过行tool编辑,lay-event="edit" function edit(obj) { if (obj.data.ipqcTaskNoticeID) { - hg.open('修改生產工時', '/SPC/SPC006U/' + obj.data.ipqcTaskNoticeID, 480,480); + hg.open('修改任務性IPQC提醒', '/SPC/SPC006U/' + obj.data.ipqcTaskNoticeID, 480,480); } } //通过行tool编辑,lay-event="finish" diff --git a/AMESCoreStudio.Web/Views/SPC/SPC006C.cshtml b/AMESCoreStudio.Web/Views/SPC/SPC006C.cshtml index fd4c2383..a7700470 100644 --- a/AMESCoreStudio.Web/Views/SPC/SPC006C.cshtml +++ b/AMESCoreStudio.Web/Views/SPC/SPC006C.cshtml @@ -84,22 +84,29 @@ getStations(result.data.flowRuleID); } else { + alert("查不到工單資訊"); $('#ItemNo').val(""); $("#UnitNo").val(""); + $("#WipNo").val(""); + $('#WipNo').focus(); getStations(0); - $('#ItemNo').focus(); return false; } }, error: function () { + alert("查不到工單資訊"); $('#ItemNo').val(""); $("#UnitNo").val(""); + $("#WipNo").val(""); + $('#WipNo').focus(); getStations(0); - $('#ItemNo').focus(); return false; } }); } + else + getStations(0); + }); @@ -135,6 +142,7 @@ $('#ItemNo').val(""); $("#UnitNo").val(""); $('#ItemNo').focus(); + alert("工單對應料號不正確"); return false; } }, @@ -147,38 +155,41 @@ function getStations(data) { - - $.ajax({ - url: "/SPC/GetStationsesbyFlow", - data: { id: data }, - dataType: 'json', - contentType: "application/json", - type: 'get', - success: function (result) { - if (result.data) { - $("#StationID").empty(); - $('#StationID').append(new Option("請選擇", "")); - var count = 0; - $.each(result.data, function (index, item) { - + if (data > 0) { + $.ajax({ + url: "/SPC/GetStationsesbyFlow", + data: { id: data }, + dataType: 'json', + contentType: "application/json", + type: 'get', + success: function (result) { + if (result.data) { + $("#StationID").empty(); + $('#StationID').append(new Option("請選擇", "")); + var count = 0; + $.each(result.data, function (index, item) { + $('#StationID').append(new Option(item.stationDesc, item.stationID)); count = count + 1; - - }); - if (count == 0) { + + }); + if (count == 0) { + $("#StationID").empty(); + $('#StationID').append(new Option("N/A", "-1")); + } + } + else { $("#StationID").empty(); $('#StationID').append(new Option("N/A", "-1")); - $('#StationID').append(new Option("無選項", "")); } + layui.form.render("select"); } - else { - $("#StationID").empty(); - $('#StationID').append(new Option("N/A", "-1")); - $('#StationID').append(new Option("無選項", "")); - } - layui.form.render("select"); - } - }); + }); + } + else { + $("#StationID").empty(); + $('#StationID').append(new Option("N/A", "-1")); + } }; diff --git a/AMESCoreStudio.Web/Views/SPC/SPC006U.cshtml b/AMESCoreStudio.Web/Views/SPC/SPC006U.cshtml index ec9167ef..f3542a32 100644 --- a/AMESCoreStudio.Web/Views/SPC/SPC006U.cshtml +++ b/AMESCoreStudio.Web/Views/SPC/SPC006U.cshtml @@ -34,15 +34,15 @@
-
- - - + + +
@Html.ValidationMessage("error")
diff --git a/AMESCoreStudio.WebApi/Controllers/AMES/IPQCTaskMailLogController.cs b/AMESCoreStudio.WebApi/Controllers/AMES/IPQCTaskMailLogController.cs new file mode 100644 index 00000000..25a6c23d --- /dev/null +++ b/AMESCoreStudio.WebApi/Controllers/AMES/IPQCTaskMailLogController.cs @@ -0,0 +1,205 @@ +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.Controllers.BLL; +using Microsoft.Extensions.Configuration; +using System.Net; +using System.Net.Mail; + +namespace AMESCoreStudio.WebApi.Controllers.AMES +{ + /// + /// 任務性IPQC表單维护 + /// + [Route("api/[controller]")] + [ApiController] + public class IPQCTaskMailLogController : ControllerBase + { + private readonly AMESContext _context; + private readonly IConfiguration _config; + + /// + /// + /// + /// + public IPQCTaskMailLogController(AMESContext context, IConfiguration config) + { + _config = _config = new ConfigurationBuilder().SetBasePath(Environment.CurrentDirectory).AddJsonFile("appsettings.json").Build(); + _context = context; + } + /// + /// + /// + /// + + + /// + /// 获取全部任務性IPQC表單 + /// + /// + // GET: api/IPQCTaskMailLogs + [HttpGet] + public async Task>> GetIPQCTaskMailLogs() + { + IQueryable q = _context.IPQCTaskMailLogs; + q = q.OrderBy(p => p.IPQCTaskMailLogID); + var IPQCTaskMailLogs = await q.ToListAsync(); + + if (IPQCTaskMailLogs == null) + { + return NotFound(); + } + + return IPQCTaskMailLogs; + } + + /// + /// 用ID获取该任務性IPQC表單 + /// + /// + /// + // GET: api/IPQCTaskMailLogs/5 + [HttpGet("{id}")] + public async Task>> GetIPQCTaskMailLog(int id) + { + + IQueryable q = _context.IPQCTaskMailLogs; + q = q.Where(p => p.IPQCTaskMailLogID.Equals(id)); + var IPQCTaskMailLog = await q.ToListAsync(); + + if (IPQCTaskMailLog == null) + { + return NotFound(); + } + + return IPQCTaskMailLog; + } + + + /// + /// 更新任務性IPQC表單资料 + /// + /// + /// + /// + [HttpPut("{id}")] + public async Task> PutIPQCTaskMailLog(int id, [FromBody] IPQCTaskMailLog IPQCTaskMailLog) + { + ResultModel result = new ResultModel(); + if (id != IPQCTaskMailLog.IPQCTaskMailLogID) + { + result.Success = false; + result.Msg = "號碼錯誤"; + return result; + } + + _context.Entry(IPQCTaskMailLog).State = EntityState.Modified; + + try + { + await _context.SaveChangesAsync(); + } + catch (Exception e) + { + result.Success = false; + result.Msg = e.Message; + return result; + } + + result.Success = true; + result.Msg = "OK"; + return result; + } + + /// + /// 新增任務性IPQC表單资料 + /// + /// + /// + [HttpPost] + public async Task> PostIPQCTaskMailLog(IPQCTaskMailLog IPQCTaskMailLog) + { + ResultModel result = new ResultModel(); + Helper helper = new Helper(_context); + var IPQCTaskMailLogID = helper.GetIDKey("IPQCTaskMailLogID").Result; + + IPQCTaskMailLog.IPQCTaskMailLogID = IPQCTaskMailLogID; + _context.IPQCTaskMailLogs.Add(IPQCTaskMailLog); + try + { + await _context.SaveChangesAsync(); + } + catch (Exception e) + { + result.Success = false; + result.Msg = e.Message; + return result; + } + + result.Success = true; + result.Msg = "OK"; + return result; + + } + + /// + /// 删除任務性IPQC表單资料 + /// + /// + /// + // DELETE: api/IPQCTaskMailLogs/5 + [HttpDelete("{id}")] + public async Task> DeleteIPQCTaskMailLog(int id) + { + ResultModel result = new ResultModel(); + var IPQCTaskMailLog = await _context.IPQCTaskMailLogs.Where(m => m.IPQCTaskMailLogID == id).FirstOrDefaultAsync(); + if (IPQCTaskMailLog == null) + { + result.Success = false; + result.Msg = "ID不存在"; + return result; + } + + + IPQCTaskMailLog newIPQCTaskMailLog = new IPQCTaskMailLog(); + newIPQCTaskMailLog = IPQCTaskMailLog; + + if (IPQCTaskMailLog.MailStatus == "Y") + { + newIPQCTaskMailLog.MailStatus = "N"; + } + else + { + newIPQCTaskMailLog.MailStatus = "Y"; + } + _context.Entry(newIPQCTaskMailLog).State = EntityState.Modified; + try + { + await _context.SaveChangesAsync(); + } + catch (Exception e) + { + result.Success = false; + result.Msg = e.Message; + return result; + } + + result.Success = true; + result.Msg = "OK"; + return result; + } + + private bool IPQCTaskMailLogsExists(int id) + { + return _context.IPQCTaskMailLogs.Any(e => e.IPQCTaskMailLogID == id); + } + + } +} diff --git a/AMESCoreStudio.WebApi/Controllers/AMES/IPQCTaskNoticeController.cs b/AMESCoreStudio.WebApi/Controllers/AMES/IPQCTaskNoticeController.cs index e7b40d09..03a287de 100644 --- a/AMESCoreStudio.WebApi/Controllers/AMES/IPQCTaskNoticeController.cs +++ b/AMESCoreStudio.WebApi/Controllers/AMES/IPQCTaskNoticeController.cs @@ -175,29 +175,119 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES ResultModel result = new ResultModel(); var q = new List(); - if (!string.IsNullOrWhiteSpace(ItemNO)) + if (string.IsNullOrWhiteSpace(ItemNO)) { result.Msg = "料號不可為空白"; result.Success = false; return result; } - q = _context.IPQCTaskNotices.Where(w=>w.ItemNo == ItemNO && w.StatusNo == "Y").ToList(); - q = q.Where(w => w.CheckContent == null && w.CheckUserID == -1).ToList(); - if (!string.IsNullOrWhiteSpace(WipNo)) + if (string.IsNullOrWhiteSpace(WipNo)) { - if (StationID > 0) - { - q = q.Where(w => w.WipNo == WipNo && w.StationID == StationID).ToList(); - } - else + result.Msg = "工單不可為空白"; + result.Success = false; + return result; + } + if (StationID <= 0) + { + result.Msg = "站別不可為0"; + result.Success = false; + return result; + } + #region 判斷是否為第一站(使用ITEM 的資料寄) + int FlowRuleID = _context.WipInfos.Where(w => w.WipNO == WipNo).Select(s => s.FlowRuleID).FirstOrDefault(); + var Station = _context.RuleStations.Where(w => w.FlowRuleID == FlowRuleID).OrderBy(o=> o.Sequence); + if (Station.Where(w => w.StationID == StationID).Select(s => s.Sequence).FirstOrDefault() == 1) + { + var query1 = from i in _context.IPQCTaskNotices.Where(i => i.ItemNo == ItemNO && + i.StatusNo == "Y" && i.WipNo == null && i.StationID == -1 && + !_context.IPQCTaskMailLogs.Any(ml => ml.IPQCTaskNoticeID == i.IPQCTaskNoticeID && ml.WipNo == WipNo)) + select new IPQCTaskNotice + { + IPQCTaskNoticeID = i.IPQCTaskNoticeID, + WipNo = i.WipNo, + ItemNo = i.ItemNo, + StationID = i.StationID, + NoticeContent = i.NoticeContent, + CheckContent = i.CheckContent, + CreateUserID = i.CreateUserID, + CreateDate = i.CreateDate, + CheckUserID = i.CheckUserID, + CheckDate = i.CheckDate, + UpdateUserID = i.UpdateUserID, + UpdateDate = i.UpdateDate, + StatusNo = i.StatusNo, + UnitNo = i.UnitNo + }; + + foreach (var item in query1) { - result.Msg = "站別不可為空白"; - result.Success = false; - return result; + string PlanQty = string.Empty; + if (!string.IsNullOrWhiteSpace(WipNo)) + { + var Wipinfo = _context.WipInfos.Where(w => w.WipNO == WipNo).FirstOrDefault(); + PlanQty = Wipinfo.PlanQTY.ToString(); + } + string StationName = _context.Stationses.Where(w => w.StationID == StationID).Select(s => s.StationName).FirstOrDefault(); + item.NoticeContent = item.NoticeContent.Replace("\r\n", "
"); + string MailGroup = "IPQC_TASK"; + string Subject = $"[AMES系統通知] ,任務性IPQC預警通知"; + string Body = @$"工單號碼 : {WipNo}
+ 料號 : {ItemNO}
+ 計畫產量 : {PlanQty}
+ 目前已投產至監控站
+ 提示站別:{StationName}
+ 提示內容:
+ {item.NoticeContent}
+ 請人員前去確認相關議題"; + + + var Mail_result = await new MailController(_context, _config).PostMail(Subject, Body, MailGroup, "", false); + IPQCTaskMailLog Log = new IPQCTaskMailLog() + { + + IPQCTaskMailLogID = 0, + IPQCTaskNoticeID = item.IPQCTaskNoticeID, + WipNo = WipNo, + ItemNo = item.ItemNo, + StationID = StationID, + MailGroup = MailGroup, + MailStatus = Mail_result.Success ? "Y" : "N", + MailMsg = Mail_result.Msg.Length <= 200 ? Mail_result.Msg : Mail_result.Msg.Substring(0, 200), + CreateDate = System.DateTime.Now, + CreateUserID = 0 + + }; + var Log_result = await new IPQCTaskMailLogController(_context, _config).PostIPQCTaskMailLog(Log); } + } - - foreach (var item in q) + + #endregion + #region (使用工單+料號+站別 的資料寄) + + var query = from i in _context.IPQCTaskNotices.Where(i=> i.ItemNo == ItemNO && + i.StatusNo == "Y" && i.WipNo == WipNo && i.StationID == StationID && + !_context.IPQCTaskMailLogs.Any(ml => ml.IPQCTaskNoticeID == i.IPQCTaskNoticeID)) + select new IPQCTaskNotice + { + IPQCTaskNoticeID = i.IPQCTaskNoticeID, + WipNo = i.WipNo, + ItemNo = i.ItemNo, + StationID = i.StationID, + NoticeContent =i.NoticeContent, + CheckContent = i.CheckContent, + CreateUserID = i.CreateUserID, + CreateDate = i.CreateDate, + CheckUserID = i.CheckUserID, + CheckDate = i.CheckDate, + UpdateUserID = i.UpdateUserID, + UpdateDate = i.UpdateDate, + StatusNo = i.StatusNo, + UnitNo = i.UnitNo + }; + + + foreach (var item in query) { string PlanQty = string.Empty; if (!string.IsNullOrWhiteSpace(item.WipNo)) @@ -205,41 +295,38 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES var Wipinfo = _context.WipInfos.Where(w => w.WipNO == item.WipNo).FirstOrDefault(); PlanQty = Wipinfo.PlanQTY.ToString(); } + string StationName = _context.Stationses.Where(w => w.StationID == item.StationID).Select(s => s.StationName).FirstOrDefault(); + item.NoticeContent = item.NoticeContent.Replace("\r\n", "
"); string MailGroup = "IPQC_TASK"; - string Subject = $"[AMES系統通知] ,任務性IPQC預警提前通知"; - string Body = @$"工單號碼 :{WipNo} | 料號 : {ItemNO} | 計畫產量 {PlanQty},目前已投產至監控站
- 提示站別: {item.StationName}
- 提示內容:{ item.CheckContent}
+ string Subject = $"[AMES系統通知] ,任務性IPQC預警通知"; + string Body = @$"工單號碼 : {WipNo}
+ 料號 : {ItemNO}
+ 計畫產量 : {PlanQty}
+ 目前已投產至監控站
+ 提示站別:{StationName}
+ 提示內容:
+ {item.NoticeContent}
請人員前去確認相關議題"; - await new MailController(_context, _config).PostMail(Subject, Body, MailGroup, "", false); - - //MailMessage mesMail = new MailMessage(); - //string mailFrom = _config["MailFrom"].ToString(); - //string mailSmtpServer = _config["MailSmtpServer"].ToString(); - //int mailSmtpPort = int.Parse(_config["MailSmtpPort"].ToString()); - //string mailUser = _config["MailUser"].ToString(); - //string mailPassword = _config["MailUserPassword"].ToString(); - //mesMail.From = new MailAddress(mailFrom); - //mesMail.Subject = Subject; - //mesMail.SubjectEncoding = System.Text.Encoding.UTF8; - //mesMail.Body = Body; - //mesMail.IsBodyHtml = true; - //mesMail.BodyEncoding = System.Text.Encoding.UTF8; - - //SmtpClient mailClient = new SmtpClient(mailSmtpServer, mailSmtpPort); + var Mail_result= await new MailController(_context, _config).PostMail(Subject, Body, MailGroup, "", false); + IPQCTaskMailLog Log = new IPQCTaskMailLog() { - ////mailClient.EnableSsl = true; - //NetworkCredential nc = new NetworkCredential(); - //nc.UserName = mailUser; - //nc.Password = mailPassword; - //mailClient.Credentials = nc; - - //mailClient.Send(mesMail); + IPQCTaskMailLogID = 0, + IPQCTaskNoticeID = item.IPQCTaskNoticeID, + WipNo = item.WipNo, + ItemNo = item.ItemNo, + StationID = item.StationID, + MailGroup = MailGroup, + MailStatus = Mail_result.Success ? "Y":"N", + MailMsg = Mail_result.Msg.Length <= 200 ? Mail_result.Msg : Mail_result.Msg.Substring(0, 200), + CreateDate = System.DateTime.Now, + CreateUserID = 0 + }; + var Log_result = await new IPQCTaskMailLogController(_context, _config).PostIPQCTaskMailLog(Log); } - + #endregion result.Success = true; result.Msg = "OK"; diff --git a/AMESCoreStudio.WebApi/Models/AMES/IPQCTaskMailLog.cs b/AMESCoreStudio.WebApi/Models/AMES/IPQCTaskMailLog.cs new file mode 100644 index 00000000..6ceff027 --- /dev/null +++ b/AMESCoreStudio.WebApi/Models/AMES/IPQCTaskMailLog.cs @@ -0,0 +1,109 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; + +namespace AMESCoreStudio.WebApi.Models.AMES +{ + /// + /// 條碼變更資料表 + /// + [Table("IPQC_TASK_MAILLOG", Schema = "JHAMES")] + [DataContract] + public class IPQCTaskMailLog + { + + /// + /// 任務性IPQC ID + /// + [Column("IPQC_TASK_MAILLOG_ID")] + [DataMember] + [Display(Name = "IPQC_TASK_MAILLOG_ID")] + [Key] + + public int IPQCTaskMailLogID { get; set; } + + /// + /// 任務性IPQC ID + /// + [Column("IPQC_TASK_NOTICE_ID")] + [DataMember] + [Display(Name = "IPQC_TASK_NOTICE_ID")] + + + public int IPQCTaskNoticeID { get; set; } + + /// + /// 工單號碼 + /// + [Column("WIP_NO")] + [DataMember] + [Display(Name = "工單號碼")] + + public string WipNo { get; set; } + + /// + /// 料號 + /// + [Column("ITEM_NO")] + [DataMember] + [Required(ErrorMessage = "{0},不能空白")] + [Display(Name = "料號")] + public string ItemNo { get; set; } + + /// + /// 站別ID + /// + [Column("STATION_ID")] + [DataMember] + [Required(ErrorMessage = "{0},不能空白")] + [Display(Name = "站別ID")] + public int StationID { get; set; } + + + /// + /// 建立者 + /// + [Column("CREATE_USERID")] + [DataMember] + [Required(ErrorMessage = "{0},不能空白")] + [Display(Name = "建立者")] + public int CreateUserID { get; set; } = 0; + + /// + /// 建立時間 + /// + [Column("CREATE_DATE")] + [DataMember] + [Required(ErrorMessage = "{0},不能空白")] + [Display(Name = "建立時間")] + public DateTime CreateDate { get; set; } = DateTime.Now; + + + + /// + /// 狀態 Y:啟用 N:停用 + /// + [Column("MAIL_GROUP")] + [DataMember] + [Display(Name = "MAIL_GROUP")] + [Required(ErrorMessage = "{0},不能空白")] + public string MailGroup { get; set; } + + /// + /// 生產單位 + /// + [Column("MAIL_STATUS")] + [DataMember] + [Display(Name = "寄件狀態")] + public string MailStatus { get; set; } + + /// + /// 生產單位 + /// + [Column("MAIL_MSG")] + [DataMember] + [Display(Name = "寄件訊息")] + public string MailMsg { get; set; } + } +} diff --git a/AMESCoreStudio.WebApi/Models/AMESContext.cs b/AMESCoreStudio.WebApi/Models/AMESContext.cs index a9bc0b8e..304f4d80 100644 --- a/AMESCoreStudio.WebApi/Models/AMESContext.cs +++ b/AMESCoreStudio.WebApi/Models/AMESContext.cs @@ -961,6 +961,11 @@ namespace AMESCoreStudio.WebApi /// 任務性IPQC提示 /// public virtual DbSet IPQCTaskNotices { get; set; } + + /// + /// 任務性IPQC提示mail記錄 + /// + public virtual DbSet IPQCTaskMailLogs { get; set; } } }