diff --git a/AMESCoreStudio.WebApi/Controllers/AMES/WipClearDetailsController.cs b/AMESCoreStudio.WebApi/Controllers/AMES/WipClearDetailsController.cs new file mode 100644 index 00000000..a83e9294 --- /dev/null +++ b/AMESCoreStudio.WebApi/Controllers/AMES/WipClearDetailsController.cs @@ -0,0 +1,237 @@ +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; + +namespace AMESCoreStudio.WebApi.Controllers.AMES +{ + /// + /// + /// + [Route("api/[controller]")] + [ApiController] + public class WipClearDetailsController : ControllerBase + { + private readonly AMESContext _context; + + /// + /// + /// + /// + public WipClearDetailsController(AMESContext context) + { + _context = context; + } + + /// + /// 根據清線ID查詢全部明細資料 + /// + /// + /// + /// + /// + // GET: api/WipClearDetails/Clear/1 + [HttpGet("Clear/{id}")] + public async Task> GetWipClearDetailByClear(int id, int page = 0, int limit = 10) + { + ResultModel result = new ResultModel(); + + var q = from a in _context.WipClearDetails + join b in _context.Stationses on a.StationID equals b.StationID + select new + { + a.ClearID, + a.ClearDetailID, + a.StationID, + b.StationName, + a.SurplusFlag, + a.PartNo, + a.Qty, + a.ReasonDesc, + a.CheckUser + }; + + + q = q.Where(p => p.ClearID.Equals(id)); + + result.DataTotal = q.ToList().Count; + + if (page > 0) + { + q = q.OrderBy(p => p.ClearDetailID).Skip((page - 1) * limit).Take(limit); + } + else + { + q = q.OrderBy(p => p.ClearDetailID); + } + + var wipClearDetail = await q.ToListAsync(); + + result.Data = wipClearDetail; + + if (wipClearDetail == null) + { + result.Success = false; + result.Msg = "查无资料"; + return result; + } + + result.Success = true; + result.Msg = "OK"; + return result; + } + + /// + /// 根據清線明細ID查詢指定資料 + /// + /// + /// + // GET: api/WipClearDetails/5 + [HttpGet("{id}")] + public async Task>> GetWipClearDetail(int id) + { + IQueryable q = _context.WipClearDetails; + q = q.Where(p => p.ClearDetailID.Equals(id)); + + var wipClearDetail = await q.ToListAsync(); + + if (wipClearDetail == null) + { + return NotFound(); + } + + return wipClearDetail; + } + + /// + /// 根據清線明細ID修改指定資料 + /// + /// + /// + /// + // PUT: api/WipClearDetails/5 + // To protect from overposting attacks, enable the specific properties you want to bind to, for + // more details, see https://go.microsoft.com/fwlink/?linkid=2123754. + [HttpPut("{id}")] + public async Task> PutWipClearDetail(int id, WipClearDetail wipClearDetail) + { + ResultModel result = new ResultModel(); + + if (id != wipClearDetail.ClearDetailID) + { + result.Success = false; + result.Msg = "清線明細編號錯誤"; + return result; + } + + _context.Entry(wipClearDetail).State = EntityState.Modified; + + try + { + await _context.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + if (!WipClearDetailExists(id)) + { + result.Success = false; + result.Msg = "清線明細編號不存在"; + return result; + } + else + { + throw; + } + } + + result.Success = true; + result.Msg = "OK"; + return result; + } + + /// + /// + /// + /// + /// + // POST: api/WipClearDetails + // To protect from overposting attacks, enable the specific properties you want to bind to, for + // more details, see https://go.microsoft.com/fwlink/?linkid=2123754. + [HttpPost] + public async Task> PostWipClearDetail(WipClearDetail wipClearDetail) + { + ResultModel result = new ResultModel(); + + Helper helper = new Helper(_context); + int detailID = helper.GetIDKey("CLEAR_DETAILID").Result; + wipClearDetail.ClearDetailID = detailID; + + _context.WipClearDetails.Add(wipClearDetail); + + //更新wip_clear + var wipClear = await _context.WipClears.FindAsync(wipClearDetail.ClearID); + if(wipClear!=null) + { + wipClear.DetailQty = wipClear.DetailQty + 1; + _context.WipClears.Attach(wipClear); + + _context.Entry(wipClear).Property(p => p.DetailQty).IsModified = true; + } + + await _context.SaveChangesAsync(); + + result.Success = true; + result.Msg = "OK"; + return result; + } + + /// + /// + /// + /// + /// + // DELETE: api/WipClearDetails/5 + [HttpDelete("{id}")] + public async Task> DeleteWipClearDetail(int id) + { + ResultModel result = new ResultModel(); + + var wipClearDetail = await _context.WipClearDetails.FindAsync(id); + if (wipClearDetail == null) + { + result.Success = false; + result.Msg = "清線明細編號不存在"; + return result; + } + + _context.WipClearDetails.Remove(wipClearDetail); + + //更新wip_clear + var wipClear = await _context.WipClears.FindAsync(wipClearDetail.ClearID); + if (wipClear != null) + { + wipClear.DetailQty = wipClear.DetailQty - 1; + _context.WipClears.Attach(wipClear); + + _context.Entry(wipClear).Property(p => p.DetailQty).IsModified = true; + } + + await _context.SaveChangesAsync(); + + result.Success = true; + result.Msg = "OK"; + return result; + } + + private bool WipClearDetailExists(int id) + { + return _context.WipClearDetails.Any(e => e.ClearDetailID == id); + } + } +} diff --git a/AMESCoreStudio.WebApi/Controllers/AMES/WipClearsController.cs b/AMESCoreStudio.WebApi/Controllers/AMES/WipClearsController.cs new file mode 100644 index 00000000..7c84e54f --- /dev/null +++ b/AMESCoreStudio.WebApi/Controllers/AMES/WipClearsController.cs @@ -0,0 +1,241 @@ +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; + +namespace AMESCoreStudio.WebApi.Controllers.AMES +{ + /// + /// + /// + [Route("api/[controller]")] + [ApiController] + public class WipClearsController : ControllerBase + { + private readonly AMESContext _context; + + /// + /// + /// + /// + public WipClearsController(AMESContext context) + { + _context = context; + } + + /// + /// 獲取全部清線資料 + /// + /// + /// + /// + // GET: api/WipClears + [HttpGet] + public async Task> GetWipClear(int page = 0, int limit = 10) + { + ResultModel result = new ResultModel(); + + var q = from a in _context.WipClears + join b in _context.WipInfos on a.WipID equals b.WipID + join c in _context.WipAtts on b.WipNO equals c.WipNO + select new + { + a.ClearID, + a.ClearNo, + a.WipID, + b.WipNO, + b.WerksNO, + b.PlanQTY, + c.ModelNO, + a.DetailQty, + a.HeadmanCheckFlag, + a.DirectorCheckFlag, + a.DirectorCheckDate, + a.ClearDesc + }; + + result.DataTotal = q.ToList().Count; + + if (page > 0) + { + q = q.OrderBy(p => p.ClearNo).Skip((page - 1) * limit).Take(limit); + } + else + { + q = q.OrderBy(p => p.ClearNo); + } + + var wipClear = await q.ToListAsync(); + + result.Data = wipClear; + + if (wipClear == null) + { + result.Success = false; + result.Msg = "查无资料"; + return result; + } + + result.Success = true; + result.Msg = "OK"; + return result; + } + + /// + /// 根據ID查詢單一清線資料 + /// + /// + /// + // GET: api/WipClears/5 + [HttpGet("{id}")] + public async Task>> GetWipClear(int id) + { + IQueryable q = _context.WipClears; + q = q.Where(p => p.ClearID.Equals(id)); + + var wipClear = await q.ToListAsync(); + + if (wipClear == null) + { + return NotFound(); + } + + return wipClear; + } + + /// + /// + /// + /// + /// + /// + // PUT: api/WipClears/5 + // To protect from overposting attacks, enable the specific properties you want to bind to, for + // more details, see https://go.microsoft.com/fwlink/?linkid=2123754. + [HttpPut("{id}")] + public async Task> PutWipClear(int id, WipClear wipClear) + { + ResultModel result = new ResultModel(); + + if (id != wipClear.ClearID) + { + result.Success = false; + result.Msg = "清線編號錯誤"; + return result; + } + + _context.Entry(wipClear).State = EntityState.Modified; + if (wipClear.HeadmanCheckFlag != null && wipClear.HeadmanCheckFlag == "Y") + { + if (wipClear.HeadmanCheckDate.ToString("yyyyMMdd") == "00010101") + { + wipClear.HeadmanCheckDate = DateTime.Now; + _context.Entry(wipClear).Property(p => p.HeadmanCheckDate).IsModified = true; + } + else + { + _context.Entry(wipClear).Property(p => p.HeadmanCheckDate).IsModified = false; + } + } + if (wipClear.DirectorCheckFlag != null && wipClear.DirectorCheckFlag == "Y") + { + if (wipClear.DirectorCheckDate.ToString("yyyyMMdd") == "00010101") + { + wipClear.DirectorCheckDate = DateTime.Now; + _context.Entry(wipClear).Property(p => p.DirectorCheckDate).IsModified = true; + } + else + { + _context.Entry(wipClear).Property(p => p.DirectorCheckDate).IsModified = false; + } + } + + + try + { + await _context.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + if (!WipClearExists(id)) + { + result.Success = false; + result.Msg = "清線編號不存在"; + return result; + } + else + { + throw; + } + } + + result.Success = true; + result.Msg = "OK"; + return result; + } + + /// + /// + /// + /// + /// + // POST: api/WipClears + // To protect from overposting attacks, enable the specific properties you want to bind to, for + // more details, see https://go.microsoft.com/fwlink/?linkid=2123754. + [HttpPost] + public async Task> PostWipClear(WipClear wipClear) + { + ResultModel result = new ResultModel(); + + Helper helper = new Helper(_context); + int clearID = helper.GetIDKey("CLEAR_ID").Result; + wipClear.ClearID = clearID; + wipClear.ClearNo = DateTime.Now.ToString("yyMM") + clearID.ToString().PadLeft(8, '0'); + + _context.WipClears.Add(wipClear); + await _context.SaveChangesAsync(); + + result.Success = true; + result.Msg = "OK"; + return result; + } + + /// + /// + /// + /// + /// + // DELETE: api/WipClears/5 + [HttpDelete("{id}")] + public async Task> DeleteWipClear(int id) + { + ResultModel result = new ResultModel(); + + var wipClear = await _context.WipClears.FindAsync(id); + if (wipClear == null) + { + result.Success = false; + result.Msg = "清線編號不存在"; + return result; + } + + _context.WipClears.Remove(wipClear); + await _context.SaveChangesAsync(); + + result.Success = true; + result.Msg = "OK"; + return result; + } + + private bool WipClearExists(int id) + { + return _context.WipClears.Any(e => e.ClearID == id); + } + } +} diff --git a/AMESCoreStudio.WebApi/Models/AMES/WipClear.cs b/AMESCoreStudio.WebApi/Models/AMES/WipClear.cs new file mode 100644 index 00000000..cadc4ec1 --- /dev/null +++ b/AMESCoreStudio.WebApi/Models/AMES/WipClear.cs @@ -0,0 +1,138 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; + +namespace AMESCoreStudio.WebApi.Models.AMES +{ + /// + /// 清線作業紀錄 + /// + [Table("WIP_CLEAR", Schema = "JHAMES")] + [DataContract] + public class WipClear + { + /// + /// 清線ID + /// + [Key] + [Column("CLEAR_ID")] + [DataMember] + public int ClearID { get; set; } + + /// + /// 清線編號 + /// + [Column("CLEAR_NO")] + [DataMember] + [Required(ErrorMessage = "{0},不能空白")] + [Display(Name = "清線編號")] + public string ClearNo { get; set; } + + /// + /// 工單編號 + /// + [Column("WIP_ID")] + [DataMember] + [Display(Name = "工單編號")] + public int WipID { get; set; } + + /// + /// 清線明細筆數 + /// + [Column("DETAIL_QTY")] + [DataMember] + [Required(ErrorMessage = "{0},不能空白")] + [Display(Name = "清線明細筆數")] + public int DetailQty { get; set; } = 0; + + /// + /// 組長確認 + /// + [Column("HEADMAN_CHECKFLAG")] + [DataMember] + [Display(Name = "組長確認")] + public string HeadmanCheckFlag { get; set; } + + /// + /// 組長編號 + /// + [Column("HEADMAN_USERID")] + [DataMember] + [Display(Name = "組長")] + public int HeadmanUserID { get; set; } + + /// + /// 組長確認日期 + /// + [Column("HEADMAN_CHECKDATE")] + [DataMember] + [Display(Name = "組長確認日期")] + public DateTime HeadmanCheckDate { get; set; } + + /// + /// 主管確認 + /// + [Column("DIRECTOR_CHECKFLAG")] + [DataMember] + [Display(Name = "主管確認")] + public string DirectorCheckFlag { get; set; } + + /// + /// 主管 + /// + [Column("DIRECTOR_USERID")] + [DataMember] + [Display(Name = "主管")] + public int DirectorUserID { get; set; } + + /// + /// 主管確認日期 + /// + [Column("DIRECTOR_CHECKDATE")] + [DataMember] + [Display(Name = "主管確認日期")] + public DateTime DirectorCheckDate { get; set; } + + /// + /// 清線描述 + /// + [Column("CLEAR_DESC")] + [DataMember] + [Display(Name = "清線描述")] + public string ClearDesc { get; set; } + + /// + /// 建立者 + /// + [Column("CREATE_USERID")] + [DataMember] + [Display(Name = "建立者")] + public int CreateUserID { get; set; } = 0; + + /// + /// 建立日期 + /// + [Column("CREATE_DATE")] + [DataMember] + [Display(Name = "建立日期")] + public DateTime CreateDate { get; set; } = DateTime.Now; + + /// + /// 更新者 + /// + [Column("UPDATE_USERID")] + [DataMember] + [Display(Name = "更新者")] + public int UpdateUserID { get; set; } = 0; + + /// + /// 更新日期 + /// + [Column("UPDATE_DATE")] + [DataMember] + [Display(Name = "更新日期")] + public DateTime UpdateDate { get; set; } = DateTime.Now; + + } +} diff --git a/AMESCoreStudio.WebApi/Models/AMES/WipClearDetail.cs b/AMESCoreStudio.WebApi/Models/AMES/WipClearDetail.cs new file mode 100644 index 00000000..4030966f --- /dev/null +++ b/AMESCoreStudio.WebApi/Models/AMES/WipClearDetail.cs @@ -0,0 +1,112 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; + +namespace AMESCoreStudio.WebApi.Models.AMES +{ + /// + /// 清線作業明細紀錄 + /// + [Table("WIP_CLEAR_DETAIL", Schema = "JHAMES")] + [DataContract] + public class WipClearDetail + { + /// + /// 清線明細ID + /// + [Key] + [Column("CLEAR_DETAILID")] + [DataMember] + public int ClearDetailID { get; set; } + + /// + /// 清線ID + /// + [Column("CLEAR_ID")] + [DataMember] + [Display(Name = "清線ID")] + public int ClearID { get; set; } + + /// + /// 站別ID + /// + [Column("STATION_ID")] + [DataMember] + [Display(Name = "站別ID")] + public int StationID { get; set; } + + /// + /// 是否剩料 + /// + [Column("SURPLUS_FLAG")] + [DataMember] + [Display(Name = "是否剩料")] + public string SurplusFlag { get; set; } + + /// + /// 料號 + /// + [Column("PART_NO")] + [DataMember] + [Display(Name = "料號")] + public string PartNo { get; set; } + + /// + /// 數量 + /// + [Column("QTY")] + [DataMember] + [Display(Name = "數量")] + public int Qty { get; set; } + + /// + /// 原因分析 + /// + [Column("REASON_DESC")] + [DataMember] + [Display(Name = "原因分析")] + public string ReasonDesc { get; set; } + + /// + /// 確認人員 + /// + [Column("CHECK_USER")] + [DataMember] + [Display(Name = "確認人員")] + public string CheckUser { get; set; } + + /// + /// 建立者 + /// + [Column("CREATE_USERID")] + [DataMember] + [Display(Name = "建立者")] + public int CreateUserID { get; set; } = 0; + + /// + /// 建立日期 + /// + [Column("CREATE_DATE")] + [DataMember] + [Display(Name = "建立日期")] + public DateTime CreateDate { get; set; } = DateTime.Now; + + /// + /// 更新者 + /// + [Column("UPDATE_USERID")] + [DataMember] + [Display(Name = "更新者")] + public int UpdateUserID { get; set; } = 0; + + /// + /// 更新日期 + /// + [Column("UPDATE_DATE")] + [DataMember] + [Display(Name = "更新日期")] + public DateTime UpdateDate { get; set; } = DateTime.Now; + + } +}