|
|
@ -31,6 +31,307 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES |
|
|
|
_context = context; |
|
|
|
} |
|
|
|
|
|
|
|
#region
|
|
|
|
/// <summary>
|
|
|
|
/// 過站判斷
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="barCodeCheckDto"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost("PassIngByCheck")] |
|
|
|
public async Task<ActionResult<ResultModel<string>>> CheckBarCodeCheck([FromBody] BarCodeCheckDto barCodeCheckDto) |
|
|
|
{ |
|
|
|
ResultModel<string> resultModel = new ResultModel<string> { Success = false }; |
|
|
|
//resultModel = (ResultModel<string>)await CheckWipNoSationAsync("1", "1", 1, 1);
|
|
|
|
|
|
|
|
#region 欄位資料空值判斷
|
|
|
|
if (string.IsNullOrWhiteSpace(barCodeCheckDto.wipNo)) |
|
|
|
{ |
|
|
|
resultModel.Msg = "請輸入工單號碼"; |
|
|
|
return Ok(resultModel); |
|
|
|
} |
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(barCodeCheckDto.barcode)) |
|
|
|
{ |
|
|
|
resultModel.Msg = "請輸入內部條碼"; |
|
|
|
return Ok(resultModel); |
|
|
|
} |
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(barCodeCheckDto.unitNo)) |
|
|
|
{ |
|
|
|
resultModel.Msg = "請輸入生產單位"; |
|
|
|
return Ok(resultModel); |
|
|
|
} |
|
|
|
|
|
|
|
if (barCodeCheckDto.station == 0) |
|
|
|
{ |
|
|
|
resultModel.Msg = "請輸入作業站代碼"; |
|
|
|
return Ok(resultModel); |
|
|
|
} |
|
|
|
|
|
|
|
if (barCodeCheckDto.line == 0) |
|
|
|
{ |
|
|
|
resultModel.Msg = "請輸入線別代碼"; |
|
|
|
return Ok(resultModel); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 宣告各個Controller
|
|
|
|
WipInfosController wipInfosController = new WipInfosController(_context); |
|
|
|
WipMACController wipMACController = new WipMACController(_context); |
|
|
|
WipBarcodeOtherController wipBarcodeOtherController = new WipBarcodeOtherController(_context); |
|
|
|
BarcodeItemsController barcodeItemsController = new BarcodeItemsController(_context); |
|
|
|
BarcodeInfoesController barcodeInfoesController = new BarcodeInfoesController(_context); |
|
|
|
BarcodeStationController barcodeStationController = new BarcodeStationController(_context); |
|
|
|
BarcodeItemChangesController barcodeItemChangesController = new BarcodeItemChangesController(_context); |
|
|
|
RuleStationsController ruleStationsController = new RuleStationsController(_context); |
|
|
|
MaterialKpController materialKpController = new MaterialKpController(_context); |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 宣告參數
|
|
|
|
// 工單ID
|
|
|
|
int wipID = 0; |
|
|
|
// 內部條碼ID
|
|
|
|
int barCodeID = 0; |
|
|
|
// 流程ID
|
|
|
|
int flowRule = 0; |
|
|
|
// 流程站別順序ID
|
|
|
|
int ruleStation = 0; |
|
|
|
// 料號ID
|
|
|
|
int itemID = 0; |
|
|
|
// 作業站順序
|
|
|
|
int stationSEQ = 0; |
|
|
|
// 料號
|
|
|
|
string item = string.Empty; |
|
|
|
// 站別測試類別
|
|
|
|
string stationTestType = string.Empty; |
|
|
|
// 存放要更新BarCodeItem
|
|
|
|
var update_BarCodeItem = new List<BarcodeItem>(); |
|
|
|
var insert_BarCodeItemChange = new List<BarcodeItemChange>(); |
|
|
|
#endregion
|
|
|
|
|
|
|
|
var q_wipinfo = await wipInfosController.GetWipInfoByWipNo(barCodeCheckDto.wipNo); |
|
|
|
|
|
|
|
if (!q_wipinfo.Value.Where(w => w.UnitNO == barCodeCheckDto.unitNo).Any()) |
|
|
|
{ |
|
|
|
resultModel.Msg = "找不到工單號碼【" + barCodeCheckDto.wipNo + "】或所對應的生產單位"; |
|
|
|
return resultModel; |
|
|
|
} |
|
|
|
wipID = q_wipinfo.Value.Where(w => w.UnitNO == barCodeCheckDto.unitNo).FirstOrDefault().WipID; |
|
|
|
flowRule = q_wipinfo.Value.Where(w => w.UnitNO == barCodeCheckDto.unitNo).FirstOrDefault().FlowRuleID; |
|
|
|
barCodeID = BarCodeToID(barCodeCheckDto.barcode).Result; |
|
|
|
item = q_wipinfo.Value.FirstOrDefault().GetWipAtt.ItemNO; |
|
|
|
itemID = ItemNoToItemID(item).Result; |
|
|
|
|
|
|
|
var q_rulestation = await ruleStationsController.GetRuleStationByFlow(flowRule, 0, 0); |
|
|
|
if (q_rulestation.Value.Count() == 0) |
|
|
|
{ |
|
|
|
resultModel.Msg = "找不到工單號碼【" + barCodeCheckDto.wipNo + "】綁定的流程順序檔"; |
|
|
|
return resultModel; |
|
|
|
} |
|
|
|
else if (!q_rulestation.Value.Where(w => w.StationID == barCodeCheckDto.station).Any()) |
|
|
|
{ |
|
|
|
resultModel.Msg = "找不到工單號碼【" + barCodeCheckDto.wipNo + "】所對應的作業站別"; |
|
|
|
return resultModel; |
|
|
|
} |
|
|
|
|
|
|
|
// 抓作業站順序
|
|
|
|
ruleStation = q_rulestation.Value.Where(w => w.StationID == barCodeCheckDto.station).FirstOrDefault().RuleStationID; |
|
|
|
stationSEQ = q_rulestation.Value.Where(w => w.StationID == barCodeCheckDto.station).FirstOrDefault().Sequence; |
|
|
|
stationTestType = q_rulestation.Value.Where(w => w.StationID == barCodeCheckDto.station).FirstOrDefault().Station.TestType; |
|
|
|
|
|
|
|
// 維修過站 組件需獨立判斷
|
|
|
|
if (barCodeCheckDto.barcodeType == "S") |
|
|
|
{ |
|
|
|
// 確認新舊組件序號是否都有值
|
|
|
|
if (barCodeCheckDto.inputItems.Where(w => w.inputType != "NG" && |
|
|
|
(string.IsNullOrWhiteSpace(w.inputData) || string.IsNullOrWhiteSpace(w.oldInputData))).Any()) |
|
|
|
{ |
|
|
|
resultModel.Msg = "工單號碼【" + barCodeCheckDto.wipNo + "】維修過站資料有缺新舊組件序號,請確認"; |
|
|
|
return resultModel; |
|
|
|
} |
|
|
|
|
|
|
|
// 用BarCodeID And WipID 取BarCodeItem
|
|
|
|
|
|
|
|
var q_BarCodeItem = await barcodeItemsController.GetBarcodeItemByBarCodeID(barCodeID); |
|
|
|
q_BarCodeItem = q_BarCodeItem.Value.Where(w => w.WipID == wipID).ToList(); |
|
|
|
|
|
|
|
foreach (var KPs in barCodeCheckDto.inputItems) |
|
|
|
{ |
|
|
|
// 用舊組件序號比對
|
|
|
|
var barCodeItem = q_BarCodeItem.Value.Where(w => w.PartNo == KPs.oldInputData).FirstOrDefault(); |
|
|
|
|
|
|
|
if (barCodeItem != null) |
|
|
|
{ |
|
|
|
|
|
|
|
var MaterialKps = (await materialKpController.GetMaterialKpByItemID(itemID)).ToList(); |
|
|
|
MaterialKps = MaterialKps.Where(w => w.StationType == barCodeCheckDto.unitNo).OrderBy(o => o.KpSeq).ToList(); |
|
|
|
if (MaterialKps.Count == 0) |
|
|
|
{ |
|
|
|
resultModel.Msg = "工單號碼【" + barCodeCheckDto.wipNo + "】找不到相關Key Parts對應"; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
var q_Kp = MaterialKps.Where(w => w.KpNo == barCodeItem.ItemNo).FirstOrDefault(); |
|
|
|
if (q_Kp != null) |
|
|
|
{ |
|
|
|
#region 比對序號長度是否正確
|
|
|
|
if (!string.IsNullOrWhiteSpace(q_Kp.Length.ToString())) |
|
|
|
{ |
|
|
|
if (q_Kp.Length != KPs.inputData.Length) |
|
|
|
resultModel.Msg += "組件序號【" + KPs.inputData + "】 與組件名稱【" + q_Kp.KpName + "】長度不符合</br>"; |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 前置碼正確
|
|
|
|
if (!string.IsNullOrWhiteSpace(q_Kp.Title)) |
|
|
|
{ |
|
|
|
if (!KPs.inputData.ToUpper().StartsWith(q_Kp.Title.ToUpper())) |
|
|
|
resultModel.Msg += "組件序號【" + KPs.inputData + "】 與組件名稱【" + q_Kp.Title + "】前置碼不符合</br>"; |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 組件代碼-組件序號是否重複
|
|
|
|
var checkDataRedundancy = await barcodeItemsController.GetBarcodeItemByDataRedundancy(q_Kp.KpNo, KPs.inputData); |
|
|
|
if (checkDataRedundancy.Value.Count() != 0) |
|
|
|
{ |
|
|
|
resultModel.Msg += "組件名稱【" + q_Kp.KpName + "】已有相同組件序號【" + KPs.inputData + "】紀錄 </br>"; |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 判斷組件序號是否在製狀態
|
|
|
|
if (q_Kp.KpName.ToUpper() == "BOARD") |
|
|
|
{ |
|
|
|
|
|
|
|
var BarCodeInfo = await barcodeInfoesController.GetBarcodeInfoesByNo(KPs.inputData); |
|
|
|
if (BarCodeInfo.Value.Where(w => w.StatusID != -1).Any()) |
|
|
|
{ |
|
|
|
resultModel.Msg += "組件序號【" + KPs.inputData + "】 目前是在製狀態</br>"; |
|
|
|
} |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 判斷MAC區間
|
|
|
|
if (q_Kp.KpName.ToUpper() == "MAC") |
|
|
|
{ |
|
|
|
|
|
|
|
var wipMAC = await wipMACController.GetWipMAC(barCodeCheckDto.wipNo); |
|
|
|
if (wipMAC.Value == null) |
|
|
|
{ |
|
|
|
resultModel.Msg += "工單號碼【" + barCodeCheckDto.wipNo + "】 找不到綁定MAC區間</br>"; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
// 判斷MAC前置碼是否一樣
|
|
|
|
if (!KPs.inputData.StartsWith(wipMAC.Value.Title)) |
|
|
|
{ |
|
|
|
resultModel.Msg += "組件序號【" + KPs.inputData + "】 與MAC【" + wipMAC.Value.Title + "】前置碼不符合 </br>"; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
// 判斷是否符合區間
|
|
|
|
if (KPs.inputData.Length == 12) |
|
|
|
{ |
|
|
|
if (!(Convert.ToInt32(wipMAC.Value.StartNO, 16) <= Convert.ToInt32(KPs.inputData.Substring(7, 6), 16) |
|
|
|
&& Convert.ToInt32(KPs.inputData.Substring(7, 6), 16) <= Convert.ToInt32(wipMAC.Value.EndNO, 16))) |
|
|
|
{ |
|
|
|
resultModel.Msg += "組件序號【" + KPs.inputData + "】 與工單設定MAC區間不符合 </br>"; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 判斷出貨序號
|
|
|
|
// 當KP_NAME是 EXT_NO 判斷組件-出貨序號 是否有在區間
|
|
|
|
if (q_Kp.KpName.ToUpper() == "EXT_NO") |
|
|
|
{ |
|
|
|
|
|
|
|
var WipBarCodeOther = await wipBarcodeOtherController.CheckWipBarcodeOtherByNo(barCodeCheckDto.wipNo, KPs.inputData); |
|
|
|
if (WipBarCodeOther.Value.Count() == 0) |
|
|
|
{ |
|
|
|
resultModel.Msg += "組件序號【" + KPs.inputData + "】 與工單設定出貨序號區間不符合 </br>"; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
//resultModel.Data = new List<string> { KPs.inputData };
|
|
|
|
//resultModel.Msg = "EXT_NO";
|
|
|
|
} |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
barCodeItem.PartNo = KPs.inputData; |
|
|
|
barCodeItem.RuleStationID = ruleStation; |
|
|
|
barCodeItem.UpdateDate = DateTime.Now; |
|
|
|
update_BarCodeItem.Add(barCodeItem); |
|
|
|
|
|
|
|
insert_BarCodeItemChange.Add(new BarcodeItemChange |
|
|
|
{ |
|
|
|
WipID = wipID, |
|
|
|
RuleStationID = ruleStation, |
|
|
|
BarcodeID = barCodeID, |
|
|
|
ItemNo = barCodeItem.ItemNo, |
|
|
|
PartNoOld = KPs.oldInputData, |
|
|
|
ChangeType = "RP", |
|
|
|
KpItemNo = KPs.inputData |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(resultModel.Msg)) |
|
|
|
return resultModel; |
|
|
|
} |
|
|
|
|
|
|
|
//var NextStopCloseStation = await CheckNextStopCloseStation(barCodeCheckDto.wipNo, barCodeCheckDto.unitNo, barCodeCheckDto.station);
|
|
|
|
|
|
|
|
#region 過站判斷正常 往下處理Table
|
|
|
|
|
|
|
|
#region 內部序號輸入後新增 or 更新
|
|
|
|
var barcodeInfo = barcodeInfoesController.GetBarcodeInfoes(barCodeID).Result.Value.FirstOrDefault(); |
|
|
|
barcodeInfo.RuleStationID = ruleStation; |
|
|
|
barcodeInfo.RuleStatus = "P"; |
|
|
|
|
|
|
|
|
|
|
|
var resultBarCodeInfo = await barcodeInfoesController.PutBarcodeInfoes(barcodeInfo); |
|
|
|
if (resultBarCodeInfo.Success) |
|
|
|
{ |
|
|
|
// 新增 BarCodeStation
|
|
|
|
BarcodeStation barcodeStation = new BarcodeStation |
|
|
|
{ |
|
|
|
BarcodeID = barCodeID, |
|
|
|
WipID = wipID, |
|
|
|
RuleStationID = ruleStation, |
|
|
|
RuleStatus = "P", //F 不良
|
|
|
|
InputDate = DateTime.Now, |
|
|
|
LineId = barCodeCheckDto.line |
|
|
|
}; |
|
|
|
await barcodeStationController.PostBarcodeStation(barcodeStation); |
|
|
|
|
|
|
|
// 新增 BarCodeItem
|
|
|
|
// 先查詢已綁定組件數量
|
|
|
|
//var BarCodeItems = await _pcsApi.GetBarcodeItemByBarCodeID(model.BarCodeID);
|
|
|
|
//int KpItemQty = BarCodeItems.Count();
|
|
|
|
|
|
|
|
foreach (var item_barCodeItem in update_BarCodeItem) |
|
|
|
{ |
|
|
|
await barcodeItemsController.PutBarcodeItems(item_barCodeItem.BarcodeItemID, item_barCodeItem); |
|
|
|
} |
|
|
|
|
|
|
|
foreach (var item_barCodeItemChange in insert_BarCodeItemChange) |
|
|
|
{ |
|
|
|
await barcodeItemChangesController.PostBarcodeItemChanges(item_barCodeItemChange); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
} |
|
|
|
resultModel.Msg = "內部序號【" + barCodeCheckDto.barcode + "】 過站完成!"; |
|
|
|
resultModel.Success = true; |
|
|
|
return resultModel; |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 判斷工單狀態
|
|
|
|
/// </summary>
|
|
|
@ -73,7 +374,6 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES |
|
|
|
return Ok(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 內部序號查詢工單號碼
|
|
|
|
/// </summary>
|
|
|
@ -194,7 +494,7 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES |
|
|
|
/// <param name="barcode">內部序號</param>
|
|
|
|
/// <returns>Success:true or false</returns>
|
|
|
|
[HttpGet("BarCodeLock")] |
|
|
|
public async Task<IActionResult> CheckBarCodeLockAsync(string barcode) |
|
|
|
public async Task<ActionResult<ResultModel<string>>> CheckBarCodeLockAsync(string barcode) |
|
|
|
{ |
|
|
|
ResultModel<string> resultModel = new ResultModel<string> { Success = false }; |
|
|
|
if (barcode.Length <= 4) |
|
|
@ -482,7 +782,7 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES |
|
|
|
/// </summary>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpGet("BarCodeKP")] |
|
|
|
public async Task<IResultModel> CheckBarCodeKPAsync([FromQuery]BarcodeItemKPDto barcodeItemKPDto) |
|
|
|
public async Task<IResultModel> CheckBarCodeKPAsync([FromQuery] BarcodeItemKPDto barcodeItemKPDto) |
|
|
|
{ |
|
|
|
ResultModel<string> resultModel = new ResultModel<string> { Success = false }; |
|
|
|
|
|
|
@ -550,13 +850,13 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES |
|
|
|
|
|
|
|
#region 比對組件資料
|
|
|
|
var CheckMsg = string.Empty; |
|
|
|
int x= BarCodeItems.Count; |
|
|
|
int x = BarCodeItems.Count; |
|
|
|
#endregion
|
|
|
|
|
|
|
|
for (int i = 0; i < barcodeItemKPDto.inputKP.Count; i++) |
|
|
|
{ |
|
|
|
#region 比對序號長度是否正確
|
|
|
|
if (!string.IsNullOrWhiteSpace(MaterialKps[x+i].Length.ToString())) |
|
|
|
if (!string.IsNullOrWhiteSpace(MaterialKps[x + i].Length.ToString())) |
|
|
|
{ |
|
|
|
if (MaterialKps[x + i].Length != barcodeItemKPDto.inputKP[i].Length) |
|
|
|
CheckMsg += "組件序號【" + barcodeItemKPDto.inputKP[i] + "】 與組件名稱【" + MaterialKps[x + i].KpName + "】長度不符合</br>"; |
|
|
@ -575,7 +875,7 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES |
|
|
|
var checkDataRedundancy = await barcodeItemsController.GetBarcodeItemByDataRedundancy(MaterialKps[x + i].KpNo, barcodeItemKPDto.inputKP[i]); |
|
|
|
if (checkDataRedundancy.Value.Count() != 0) |
|
|
|
{ |
|
|
|
CheckMsg += "組件名稱【" + MaterialKps[x + i].KpName + "】已有相同組件序號【"+ barcodeItemKPDto.inputKP[i] + "】紀錄 </br>"; |
|
|
|
CheckMsg += "組件名稱【" + MaterialKps[x + i].KpName + "】已有相同組件序號【" + barcodeItemKPDto.inputKP[i] + "】紀錄 </br>"; |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
@ -741,7 +1041,7 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES |
|
|
|
/// <summary>
|
|
|
|
/// 內部序號找BarCodeID
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="BarCode"></param>
|
|
|
|
/// <param name="BarCode">內部條碼</param>
|
|
|
|
/// <returns>0:找不到</returns>
|
|
|
|
private async Task<int> BarCodeToID(string BarCode) |
|
|
|
{ |
|
|
@ -754,6 +1054,21 @@ namespace AMESCoreStudio.WebApi.Controllers.AMES |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 料號找料號ID
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="ItemNo">料號</param>
|
|
|
|
/// <returns>0:找不到</returns>
|
|
|
|
private async Task<int> ItemNoToItemID(string ItemNo) |
|
|
|
{ |
|
|
|
MaterialItemController materialItemController = new MaterialItemController(_context); |
|
|
|
var q = await materialItemController.GetMaterialItemByItemNO(ItemNo); |
|
|
|
if (q == null) |
|
|
|
return 0; |
|
|
|
else |
|
|
|
return q.ItemID; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 取得上一個作業站RuleStationID
|
|
|
|