7 changed files with 414 additions and 71 deletions
@ -0,0 +1,65 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using AMESCoreStudio.WebApi.Models.AMES; |
|||
using AMESCoreStudio.WebApi.Controllers.AMES; |
|||
using AMESCoreStudio.WebApi.Controllers.BAS; |
|||
|
|||
namespace AMESCoreStudio.WebApi |
|||
{ |
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
public class BarcodeContext |
|||
{ |
|||
private readonly AMESContext _context; |
|||
|
|||
public BarcodeContext(AMESContext context) |
|||
{ |
|||
_context = context; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 確認工單狀態
|
|||
/// </summary>
|
|||
/// <param name="WipNo">工單號碼</param>
|
|||
/// <param name="UnitNo">生產單位</param>
|
|||
/// <param name="FlowRuleID">流程</param>
|
|||
/// <param name="Station">站別</param>
|
|||
/// <param name="Line">線別</param>
|
|||
/// <returns></returns>
|
|||
public async Task<string> CheckWipNoSationAsync(string WipNo, string UnitNo, int FlowRuleID, int Station, int Line) |
|||
{ |
|||
WipInfosController wipInfosController = new WipInfosController(_context); |
|||
|
|||
var q = await wipInfosController.GetWipInfoByWipNo(WipNo); |
|||
if (q.Value.Count() == 0) |
|||
return "找不到工單號碼:" + WipNo; |
|||
|
|||
var WipNoItem = q.Value.Where(w => w.WipNO == WipNo && w.UnitNO == UnitNo).ToList(); |
|||
if (WipNoItem.Count == 0) |
|||
return "工單號碼:" + WipNo + ",尚未設定此生產單位"; |
|||
|
|||
if (!WipNoItem.Where(w => w.FlowRuleID == FlowRuleID).Any()) |
|||
return "工單號碼:" + WipNo + ",尚未設定此流程站"; |
|||
|
|||
if (WipNoItem.Where(w => w.StatusNO == "Y").Any()) |
|||
return "工單號碼:" + WipNo + ",該工單已經投入完工,請切換工單"; |
|||
|
|||
WipLockController wipLockController = new WipLockController(_context); |
|||
var q1 = await wipLockController.GetWipLockByWipNO(WipNo); |
|||
if (q1.Data.Where(w => w.LockStatus == "0" && w.StationID == Station).Any()) |
|||
return "工單號碼:" + WipNo + ",工單在當前站別被鎖定,不可過站"; |
|||
|
|||
int WipID = WipNoItem.FirstOrDefault().WipID; |
|||
LineInfoesController lineInfoesController = new LineInfoesController(_context); |
|||
var q2 = await lineInfoesController.GetLineInfoByWipID(WipID); |
|||
if (!q2.Value.Where(w => w.LineID == Line).Any()) |
|||
return "工單號碼:" + WipNo + ",工單尚未開線,不可過站"; |
|||
|
|||
|
|||
return ""; |
|||
} |
|||
} |
|||
} |
@ -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; |
|||
|
|||
namespace AMESCoreStudio.WebApi.Controllers.AMES |
|||
{ |
|||
/// <summary>
|
|||
/// 過站判斷
|
|||
/// </summary>
|
|||
[Route("api/[controller]")]
|
|||
[ApiController] |
|||
public class BarCodeCheckController : ControllerBase |
|||
{ |
|||
private readonly AMESContext _context; |
|||
|
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
/// <param name="context"></param>
|
|||
public BarCodeCheckController(AMESContext context) |
|||
{ |
|||
_context = context; |
|||
} |
|||
|
|||
|
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
/// <returns></returns>
|
|||
// GET: api/NGReasons
|
|||
[HttpGet] |
|||
public string GetBarCodeCheck(string wipno = null, string unitno = null, string stations = null, string inputbarcode = null) |
|||
{ |
|||
|
|||
|
|||
IQueryable<NGReason> q = _context.NGReasons; |
|||
q = q.OrderBy(p => p.NGClassNo + p.NGReasonNo); |
|||
|
|||
|
|||
|
|||
return ""; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 判斷工單狀態
|
|||
/// </summary>
|
|||
/// <param name="wipno">工單號碼</param>
|
|||
/// <param name="unitno">生產單位</param>
|
|||
/// <param name="station">站別</param>
|
|||
/// <param name="line">線別</param>
|
|||
/// <param name="flowrule">流程</param>
|
|||
/// <returns></returns>
|
|||
[HttpGet("BarCodeDataCheck")] |
|||
public string GetBarCodeDataCheck(string wipno, string unitno, int station, int line, int flowrule) |
|||
{ |
|||
BarcodeContext barcodeContext = new BarcodeContext(_context); |
|||
var result = barcodeContext.CheckWipNoSationAsync(WipNo: wipno, UnitNo: unitno, FlowRuleID: flowrule, Station: station, Line: line); |
|||
return result.Result; |
|||
} |
|||
|
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
/// <param name="id"></param>
|
|||
/// <returns></returns>
|
|||
// GET: api/NGReasons/5
|
|||
[HttpGet("{id}")] |
|||
public async Task<ActionResult<IEnumerable<NGReason>>> GetNGReason(string id) |
|||
{ |
|||
IQueryable<NGReason> q = _context.NGReasons; |
|||
q = q.Where(p => p.NGReasonNo.Equals(id)); |
|||
|
|||
var ngReason = await q.ToListAsync(); |
|||
|
|||
if (ngReason == null) |
|||
{ |
|||
return NotFound(); |
|||
} |
|||
|
|||
return ngReason; |
|||
} |
|||
|
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
/// <param name="id"></param>
|
|||
/// <param name="nGReason"></param>
|
|||
/// <returns></returns>
|
|||
// PUT: api/NGReasons/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<ResultModel<NGReason>> PutNGReason(string id, [FromBody] NGReason nGReason) |
|||
{ |
|||
ResultModel<NGReason> result = new ResultModel<NGReason>(); |
|||
|
|||
if (id != nGReason.NGReasonNo) |
|||
{ |
|||
result.Success = false; |
|||
result.Msg = "原因代碼錯誤"; |
|||
return result; |
|||
} |
|||
|
|||
_context.Entry(nGReason).State = EntityState.Modified; |
|||
|
|||
try |
|||
{ |
|||
await _context.SaveChangesAsync(); |
|||
} |
|||
catch (DbUpdateConcurrencyException) |
|||
{ |
|||
if (!NGReasonExists(id)) |
|||
{ |
|||
result.Success = false; |
|||
result.Msg = "原因代碼不存在"; |
|||
return result; |
|||
} |
|||
else |
|||
{ |
|||
throw; |
|||
} |
|||
} |
|||
|
|||
result.Success = true; |
|||
result.Msg = "OK"; |
|||
return result; |
|||
} |
|||
|
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
/// <param name="nGReason"></param>
|
|||
/// <returns></returns>
|
|||
// POST: api/NGReasons
|
|||
// 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<ResultModel<NGReason>> PostNGReason([FromBody] NGReason nGReason) |
|||
{ |
|||
ResultModel<NGReason> result = new ResultModel<NGReason>(); |
|||
|
|||
_context.NGReasons.Add(nGReason); |
|||
try |
|||
{ |
|||
await _context.SaveChangesAsync(); |
|||
} |
|||
catch (DbUpdateException) |
|||
{ |
|||
if (NGReasonExists(nGReason.NGReasonNo)) |
|||
{ |
|||
result.Success = false; |
|||
result.Msg = "原因代碼重複"; |
|||
return result; |
|||
} |
|||
else |
|||
{ |
|||
throw; |
|||
} |
|||
} |
|||
|
|||
result.Success = true; |
|||
result.Msg = "OK"; |
|||
return result; |
|||
} |
|||
|
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
/// <param name="id"></param>
|
|||
/// <returns></returns>
|
|||
// DELETE: api/NGReasons/5
|
|||
[HttpDelete("{id}")] |
|||
public async Task<ResultModel<NGReason>> DeleteNGReason(string id) |
|||
{ |
|||
ResultModel<NGReason> result = new ResultModel<NGReason>(); |
|||
|
|||
var nGReason = await _context.NGReasons.FindAsync(id); |
|||
if (nGReason == null) |
|||
{ |
|||
result.Success = false; |
|||
result.Msg = "原因代碼不存在"; |
|||
return result; |
|||
} |
|||
|
|||
_context.NGReasons.Remove(nGReason); |
|||
await _context.SaveChangesAsync(); |
|||
|
|||
result.Success = true; |
|||
result.Msg = "OK"; |
|||
return result; |
|||
} |
|||
|
|||
private bool NGReasonExists(string id) |
|||
{ |
|||
return _context.NGReasons.Any(e => e.NGReasonNo == id); |
|||
} |
|||
} |
|||
} |
Loading…
Reference in new issue