diff --git a/AMESCoreStudio.WebApi/Controllers/AMES/WipStationController.cs b/AMESCoreStudio.WebApi/Controllers/AMES/WipStationController.cs new file mode 100644 index 00000000..35ca62ab --- /dev/null +++ b/AMESCoreStudio.WebApi/Controllers/AMES/WipStationController.cs @@ -0,0 +1,146 @@ +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.WebApi.DTO.AMES; +using AMESCoreStudio.CommonTools.Result; + +namespace AMESCoreStudio.WebApi.Controllers.AMES +{ + /// + /// 工單各站數量資料檔 + /// + [Route("api/[controller]")] + [ApiController] + public class WipStationController : ControllerBase + { + private readonly AMESContext _context; + + public WipStationController(AMESContext context) + { + _context = context; + } + + // GET: api/WipStation + [HttpGet] + public async Task>> GetWipStations() + { + return await _context.WipStations.ToListAsync(); + } + + // GET: api/WipStation/5 + [HttpGet("{id}")] + public async Task> GetWipStation(int id) + { + var wipStation = await _context.WipStations.FindAsync(id); + + if (wipStation == null) + { + return NotFound(); + } + + return wipStation; + } + + /// + /// 基本查詢 + /// + /// 工單ID + /// 流程ID + /// + [HttpGet("Query")] + public async Task> GetWipStation(int wipID , int ruleStationID) + { + IQueryable q = _context.WipStations; + + + if (wipID != 0) + q = q.Where(w => w.WipID == wipID); + + + if (ruleStationID != 0) + q = q.Where(w => w.RuleStationID == ruleStationID); + + var result = await q.ToListAsync(); + + return result.FirstOrDefault(); + } + + /// + /// 更新工單各站數量 + /// + /// + /// + [HttpPut] + public async Task> PutWipStation(WipStation wipStation) + { + ResultModel result = new ResultModel(); + _context.Entry(wipStation).State = EntityState.Modified; + wipStation.UpdateDate = DateTime.Now; + + try + { + await _context.SaveChangesAsync(); + result.Success = true; + result.Msg = "OK"; + } + catch (Exception ex) + { + result.Success = false; + result.Msg = ex.Message; + } + return result; + } + + + /// + /// 新增工單各站數量 + /// + /// + /// + [HttpPost] + public async Task> PostWipStation(WipStation wipStation) + { + ResultModel result = new ResultModel(); + _context.WipStations.Add(wipStation); + try + { + await _context.SaveChangesAsync(); + result.Success = true; + result.Msg = "OK"; + } + catch (Exception ex) + { + result.Success = false; + result.Msg = ex.Message; + } + return result; + } + + // DELETE: api/WipStation/5 + [HttpDelete("{id}")] + public async Task> DeleteWipStation(int id) + { + var wipStation = await _context.WipStations.FindAsync(id); + if (wipStation == null) + { + return NotFound(); + } + + _context.WipStations.Remove(wipStation); + await _context.SaveChangesAsync(); + + return wipStation; + } + + private bool WipStationExists(int id) + { + return _context.WipStations.Any(e => e.WipID == id); + } + } +} diff --git a/AMESCoreStudio.WebApi/Models/AMES/WipStation.cs b/AMESCoreStudio.WebApi/Models/AMES/WipStation.cs new file mode 100644 index 00000000..abd64357 --- /dev/null +++ b/AMESCoreStudio.WebApi/Models/AMES/WipStation.cs @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using Microsoft.EntityFrameworkCore; +using System.Runtime.Serialization; + +#nullable disable + +namespace AMESCoreStudio.WebApi.Models.AMES +{ + /// + /// 工單各站數量資料檔 + /// + [Table("WIP_STATION", Schema = "JHAMES")] + public partial class WipStation + { + /// + /// 工單ID + /// + [Key] + [Required] + [DataMember] + [Column("WIP_ID")] + public int WipID { get; set; } + + /// + /// 流程站?ID + /// + [Key] + [Required] + [DataMember] + [Column("RULE_STATION_ID")] + public int RuleStationID { get; set; } + + /// + /// 過站狀態 + /// + [Key] + [Required] + [DataMember] + [Column("RULE_STATUS")] + [StringLength(1)] + public string RuleStatus { get; set; } + + /// + /// 第一次過站數量 + /// + [Required] + [DataMember] + [Column("FIRST_CNT")] + public int FirstCnt { get; set; } + + /// + /// 過站數量 + /// + [Required] + [DataMember] + [Column("PASS_CNT")] + public int PassCnt { get; set; } + + /// + /// 建立UserID + /// + [Column("CREATE_USERID")] + [Required] + [DataMember] + public int CreateUserID { get; set; } = 0; + + /// + /// 建立日期 + /// + [Key] + [Required] + [Column("CREATE_DATE")] + [DataMember] + public DateTime CreateDate { get; set; } = DateTime.Now; + + /// + /// 更新日期 + /// + [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 434e2447..e5c0f52d 100644 --- a/AMESCoreStudio.WebApi/Models/AMESContext.cs +++ b/AMESCoreStudio.WebApi/Models/AMESContext.cs @@ -92,6 +92,8 @@ namespace AMESCoreStudio.WebApi modelBuilder.Entity().HasOne(r => r.Wip).WithMany().HasForeignKey(r => r.WipId).IsRequired(); modelBuilder.Entity().HasOne(r => r.Station).WithMany().HasForeignKey(r => r.StationId).IsRequired(); //modelBuilder.Entity().HasOne(r => r.User).WithMany().HasForeignKey(r => r.OperatorID).IsRequired(); + + modelBuilder.Entity().HasKey(c => new { c.WipID, c.RuleStationID, c.RuleStatus, c.CreateDate}); } /// @@ -634,6 +636,11 @@ namespace AMESCoreStudio.WebApi /// 工單箱號資料檔 /// public virtual DbSet WipBoxs { get; set; } + + /// + /// 工單各站數量資料檔 + /// + public virtual DbSet WipStations { get; set; } } }