3 changed files with 240 additions and 0 deletions
@ -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 |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 工單各站數量資料檔
|
||||
|
/// </summary>
|
||||
|
[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<ActionResult<IEnumerable<WipStation>>> GetWipStations() |
||||
|
{ |
||||
|
return await _context.WipStations.ToListAsync(); |
||||
|
} |
||||
|
|
||||
|
// GET: api/WipStation/5
|
||||
|
[HttpGet("{id}")] |
||||
|
public async Task<ActionResult<WipStation>> GetWipStation(int id) |
||||
|
{ |
||||
|
var wipStation = await _context.WipStations.FindAsync(id); |
||||
|
|
||||
|
if (wipStation == null) |
||||
|
{ |
||||
|
return NotFound(); |
||||
|
} |
||||
|
|
||||
|
return wipStation; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 基本查詢
|
||||
|
/// </summary>
|
||||
|
/// <param name="wipID">工單ID</param>
|
||||
|
/// <param name="ruleStationID">流程ID</param>
|
||||
|
/// <returns></returns>
|
||||
|
[HttpGet("Query")] |
||||
|
public async Task<ActionResult<WipStation>> GetWipStation(int wipID , int ruleStationID) |
||||
|
{ |
||||
|
IQueryable<WipStation> 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(); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 更新工單各站數量
|
||||
|
/// </summary>
|
||||
|
/// <param name="wipStation"></param>
|
||||
|
/// <returns></returns>
|
||||
|
[HttpPut] |
||||
|
public async Task<ResultModel<WipStation>> PutWipStation(WipStation wipStation) |
||||
|
{ |
||||
|
ResultModel<WipStation> result = new ResultModel<WipStation>(); |
||||
|
_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; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 新增工單各站數量
|
||||
|
/// </summary>
|
||||
|
/// <param name="wipStation"></param>
|
||||
|
/// <returns></returns>
|
||||
|
[HttpPost] |
||||
|
public async Task<ResultModel<WipStation>> PostWipStation(WipStation wipStation) |
||||
|
{ |
||||
|
ResultModel<WipStation> result = new ResultModel<WipStation>(); |
||||
|
_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<ActionResult<WipStation>> 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); |
||||
|
} |
||||
|
} |
||||
|
} |
@ -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 |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 工單各站數量資料檔
|
||||
|
/// </summary>
|
||||
|
[Table("WIP_STATION", Schema = "JHAMES")] |
||||
|
public partial class WipStation |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 工單ID
|
||||
|
/// </summary>
|
||||
|
[Key] |
||||
|
[Required] |
||||
|
[DataMember] |
||||
|
[Column("WIP_ID")] |
||||
|
public int WipID { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 流程站?ID
|
||||
|
/// </summary>
|
||||
|
[Key] |
||||
|
[Required] |
||||
|
[DataMember] |
||||
|
[Column("RULE_STATION_ID")] |
||||
|
public int RuleStationID { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 過站狀態
|
||||
|
/// </summary>
|
||||
|
[Key] |
||||
|
[Required] |
||||
|
[DataMember] |
||||
|
[Column("RULE_STATUS")] |
||||
|
[StringLength(1)] |
||||
|
public string RuleStatus { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 第一次過站數量
|
||||
|
/// </summary>
|
||||
|
[Required] |
||||
|
[DataMember] |
||||
|
[Column("FIRST_CNT")] |
||||
|
public int FirstCnt { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 過站數量
|
||||
|
/// </summary>
|
||||
|
[Required] |
||||
|
[DataMember] |
||||
|
[Column("PASS_CNT")] |
||||
|
public int PassCnt { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 建立UserID
|
||||
|
/// </summary>
|
||||
|
[Column("CREATE_USERID")] |
||||
|
[Required] |
||||
|
[DataMember] |
||||
|
public int CreateUserID { get; set; } = 0; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 建立日期
|
||||
|
/// </summary>
|
||||
|
[Key] |
||||
|
[Required] |
||||
|
[Column("CREATE_DATE")] |
||||
|
[DataMember] |
||||
|
public DateTime CreateDate { get; set; } = DateTime.Now; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 更新日期
|
||||
|
/// </summary>
|
||||
|
[Column("UPDATE_DATE")] |
||||
|
[DataMember] |
||||
|
public DateTime? UpdateDate { get; set; } = DateTime.Now; |
||||
|
|
||||
|
} |
||||
|
} |
Loading…
Reference in new issue