¶Ô±ÈÐÂÎļþ |
| | |
| | | using Rhea.Common; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using Tiger.IBusiness; |
| | | using Tiger.IBusiness.MES.WorkAction; |
| | | using Tiger.Model; |
| | | using Tiger.Model.Entitys.MES.Position; |
| | | |
| | | namespace Tiger.Business.MES.WorkAction |
| | | { |
| | | public class InputQty : IInputQty |
| | | { |
| | | #region Propertys & Variables |
| | | #region åºå®åæ³ï¼å·¥åºä¸çå¿
è¦ä¿¡æ¯ |
| | | public DbClient MainDB { get; set; } |
| | | public bool IsFinished { get; set; } = false; |
| | | public IWorkStep CurStep { get; set; } |
| | | public IPosition CurPosition { get; set; } |
| | | public MES_WO_NODE_ACT NodeAct { get; set; } |
| | | public MES_WO_ACTION Setting { get; set; } |
| | | #endregion |
| | | public double NewQty { get; set; } |
| | | public double NewWoInputQty { get; set; } |
| | | public double NewBatchInputQty { get; set; } |
| | | #endregion Propertys & Variables |
| | | |
| | | #region Functions |
| | | /// <summary> |
| | | /// åå§åå·¥åºè¡ä¸º |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public void Init(IWorkStep curStep, IPosition position, MES_WO_NODE_ACT nodeAct, MES_WO_ACTION setting) |
| | | { |
| | | #region åºå®åæ³ï¼ç»é»è®¤åéèµå¼ |
| | | MainDB = position.MainDB; |
| | | CurStep = curStep; |
| | | CurPosition = position; |
| | | NodeAct = nodeAct; |
| | | Setting = setting; |
| | | #endregion |
| | | |
| | | CurStep.Message = Biz.L("çå¾
è¾å
¥æ¡ç æ°é"); |
| | | CurStep.Status = StepStatus.Normal; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è·åè¡ä¸ºå¼å§çæç¤ºä¿¡æ¯ |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public Locale GetBeginMsg() |
| | | { |
| | | //var msg = new Locale($"请è¾å
¥æ¡ç [{0}]çæ°é"); |
| | | var msg = new Locale("MES.WorkAction.InputQty.BeginMsg", CurPosition.CurSN); |
| | | |
| | | return msg; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å°è¯å¼å§æ§è¡å·¥åºè¡ä¸º |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public ApiAction<SubmitOutput> TryBegin(SubmitInput input) |
| | | { |
| | | var action = new ApiAction<SubmitOutput>(new SubmitOutput()); |
| | | |
| | | action.LocaleMsg = GetBeginMsg(); |
| | | |
| | | //妿è¿åæåå认为å½åè¡ä¸ºå¯ä»¥å¼å§æ§è¡ï¼å¦åè¿å失败 |
| | | CurStep.Message = Biz.L("请è¾å
¥æ°é"); |
| | | CurStep.Status = StepStatus.Normal; |
| | | action.IsSuccessed = true; |
| | | action.Data.ShortMsg = new("请è¾å
¥æ°é", ShortMessage.Types.Success); |
| | | return action; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å·¥åºè¡ä¸ºæäº¤æ°æ® |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public ApiAction<SubmitOutput> Submit(SubmitInput input) |
| | | { |
| | | var action = new ApiAction<SubmitOutput>(new SubmitOutput()); |
| | | |
| | | action = SaveSnQty(input, action); |
| | | //ä¸ææ°æ®ä¿å失败 |
| | | if (!action.IsSuccessed) |
| | | { |
| | | //妿è¡ä¸ºè®¾ç½®ä¸ºåºééè¦éç½®å·¥åºæä½ |
| | | if (NodeAct.NEED_RESET == "Y") |
| | | { |
| | | CurPosition.ResetNode(); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | action = End(input); |
| | | } |
| | | return action; |
| | | } |
| | | |
| | | public ApiAction<SubmitOutput> SaveSnQty(SubmitInput input, ApiAction<SubmitOutput> action) |
| | | { |
| | | try |
| | | { |
| | | NewQty = input?.Data?.ToInt32() ?? 0; |
| | | if (NewQty > 0) |
| | | { |
| | | var newInput = CurPosition.CurWipSNs.Sum(q => NewQty); |
| | | var woInput = CurPosition.WorkBatch.WoSNs.Where(q => q.WORK_ORDER == CurPosition.WorkBatch.WO.ORDER_NO && BIZ_MES_WO_SN.STATUSs.NotInput.GetValue() < q.STATUS && q.STATUS <= BIZ_MES_WO_SN.STATUSs.Finished.GetValue()) |
| | | .Where(q => !CurPosition.CurWipSNs.Any(sn => sn.ID == q.WIP_ID)).DistinctBy(q => q.WIP_ID).Sum(q => q.QTY); |
| | | var batchInput = CurPosition.WorkBatch.WoSNs.Where(q => q.BATCH_NO == CurPosition.WorkBatch.Batch.BATCH_NO && BIZ_MES_WO_SN.STATUSs.NotInput.GetValue() < q.STATUS && q.STATUS <= BIZ_MES_WO_SN.STATUSs.Finished.GetValue()) |
| | | .Where(q => !CurPosition.CurWipSNs.Any(sn => sn.ID == q.WIP_ID)).DistinctBy(q => q.WIP_ID).Sum(q => q.QTY); |
| | | |
| | | //å·¥åæ¹æ¬¡æå
¥æ°éå廿¥åºæ°é妿大äºçäºè®¡åæ°éï¼åä¸å
许ç产 |
| | | if ((NewBatchInputQty = batchInput + newInput) > CurPosition.WorkBatch.Batch.PLAN_QTY) |
| | | { |
| | | CurStep.Message = Biz.L("éæ°è¾å
¥æ°é"); |
| | | CurStep.Status = StepStatus.Error; |
| | | action.IsSuccessed = false; |
| | | action.Data.ShortMsg = new("éæ°è¾å
¥æ°é", ShortMessage.Types.Error); |
| | | //action.LocaleMsg = new($"æ¡ç æ´æ°æ°é[{0}]åï¼å·¥åæ¹æ¬¡[{1}]æå
¥æ°é[{2}]è¶
åºè®¡åæ°é[{3}]ï¼è¯·éæ°è¾å
¥æ£ç¡®çæ°é"); |
| | | action.LocaleMsg = new("MES.WorkAction.InputQty.BatchInputEnough", input.Data, CurPosition.WorkBatch.Batch.BATCH_NO, batchInput + newInput, CurPosition.WorkBatch.Batch.PLAN_QTY); |
| | | } |
| | | //å·¥åæå
¥æ°éå廿¥åºæ°é妿大äºçäºè®¡åæ°éï¼åä¸å
许ç产 |
| | | else if ((NewWoInputQty = woInput + newInput) > CurPosition.WorkBatch.WO.PLAN_QTY) |
| | | { |
| | | CurStep.Message = Biz.L("éæ°è¾å
¥æ°é"); |
| | | CurStep.Status = StepStatus.Error; |
| | | action.IsSuccessed = false; |
| | | action.Data.ShortMsg = new("éæ°è¾å
¥æ°é", ShortMessage.Types.Error); |
| | | //action.LocaleMsg = new($"æ¡ç æ´æ°æ°é[{0}]åï¼å·¥å[{1}]æå
¥æ°é[{2}]è¶
åºè®¡åæ°é[{3}]ï¼è¯·éæ°è¾å
¥æ£ç¡®çæ°é"); |
| | | action.LocaleMsg = new("MES.WorkAction.InputQty.WoInputEnough", input.Data, CurPosition.WorkBatch.WO.ORDER_NO, woInput + newInput, CurPosition.WorkBatch.WO.PLAN_QTY); |
| | | } |
| | | else |
| | | { |
| | | action = End(input); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | CurStep.Message = Biz.L("éæ°è¾å
¥æ°é"); |
| | | CurStep.Status = StepStatus.Error; |
| | | action.IsSuccessed = false; |
| | | action.Data.ShortMsg = new("éæ°è¾å
¥æ°é", ShortMessage.Types.Error); |
| | | //action.LocaleMsg = new($"æ°é[{0}]å¿
é¡»æ¯å¤§äº0çæ´æ°ï¼è¯·éæ°è¾å
¥æ£ç¡®çæ°é"); |
| | | action.LocaleMsg = new("MES.WorkAction.InputQty.QtyError", input.Data); |
| | | |
| | | } |
| | | } |
| | | catch (System.Exception ex) |
| | | { |
| | | CurStep.Message = Biz.L("æ´æ°æ°éå¼å¸¸"); |
| | | CurStep.Status = StepStatus.Error; |
| | | action.Data.ShortMsg = new("æ´æ°æ°éå¼å¸¸", ShortMessage.Types.Error); |
| | | //action.CatchExceptionWithLog(ex, $"æ´æ°æ°éè¡ä¸ºï¼æ´æ°æ¡ç [{0}]æ°é[{1}]å¼å¸¸"); |
| | | action.LocaleMsg = new("MES.WorkAction.InputQty.SaveQtyException", CurPosition.CurSN, input?.Data.ToString()); |
| | | } |
| | | return action; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ç»ææ§è¡å·¥åºè¡ä¸º |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public ApiAction<SubmitOutput> End(SubmitInput input) |
| | | { |
| | | var action = new ApiAction<SubmitOutput>(new SubmitOutput()); |
| | | //è®°å½è¡ä¸ºæä½è®°å½ |
| | | var wipActs = new List<MES_WIP_ACT>(); |
| | | foreach (var wipSn in CurPosition.CurWipSNs) |
| | | { |
| | | var wipAct = new MES_WIP_ACT() |
| | | { |
| | | AUTH_ORG = CurPosition.WorkBatch.WO.AUTH_ORG, |
| | | AUTH_PROD = CurPosition.CurLine.LINE_CODE, |
| | | WIP_ID = wipSn.ID, |
| | | HIS_ID = CurPosition.CurWipSNHiss.First(q => q.SN == wipSn.SN).ID, |
| | | SN = wipSn.SN, |
| | | STATUS = wipSn.STATUS, |
| | | ITEM_CODE = wipSn.ITEM_CODE, |
| | | WORK_ORDER = wipSn.WORK_ORDER, |
| | | BATCH_NO = wipSn.BATCH_NO, |
| | | ROT_CODE = wipSn.ROT_CODE, |
| | | NODE_ID = wipSn.NODE_ID, |
| | | NODE_NAME = wipSn.NODE_NAME, |
| | | ACT_ID = NodeAct.ID, |
| | | ACT_NAME = NodeAct.ACT_NAME, |
| | | FTY_CODE = wipSn.FTY_CODE, |
| | | WS_CODE = wipSn.WS_CODE, |
| | | LINE_CODE = wipSn.LINE_CODE, |
| | | POST_CODE = wipSn.POST_CODE, |
| | | OPER_CODE = wipSn.OPER_CODE, |
| | | SEGMENT = wipSn.SEGMENT, |
| | | FLOW_SN = wipSn.FLOW_SN, |
| | | TRAY_SN = wipSn.TRAY_SN, |
| | | INNER_SN = wipSn.INNER_SN, |
| | | CARTON_SN = wipSn.CARTON_SN, |
| | | PALLET_SN = wipSn.PALLET_SN, |
| | | OPERATION_TIME = DateTime.Now, |
| | | SFTS_CODE = wipSn.SFTS_CODE, |
| | | SFT_CODE = wipSn.SFT_CODE, |
| | | PRD_CODE = wipSn.PRD_CODE, |
| | | ACT_TYPE = NodeAct.ACT_TYPE, |
| | | ACT_SN = wipSn.SN, |
| | | ACT_RESULT = "Y", |
| | | ELAPSED_TIME = CurStep.GetElapsedTime().TotalMilliseconds.ToInt64(), |
| | | TRACE_INFO = $"æ¡ç [{CurPosition.CurSN}]æ´æ°æ°é为[{NewQty}]ä¿åæå", |
| | | }; |
| | | wipActs.Add(wipAct); |
| | | } |
| | | |
| | | //å建åéå
é对象ç¨äºä¼ å
¥DBSubmitActionä¸ä¿åå½åéè¦æåçæ°æ®å¼ |
| | | var _wipActs = wipActs.Clone(); |
| | | var wo = CurPosition.WorkBatch.WO.ORDER_NO; |
| | | var batch = CurPosition.WorkBatch.Batch.BATCH_NO; |
| | | var nodeID = NodeAct.NODE_ID; |
| | | var _wipIDs = CurPosition.CurWipSNs.Select(q => q.ID).ToList().Clone(); |
| | | //ä¿åæ°æ® |
| | | CurStep.DBSubmitAction = () => |
| | | { |
| | | var db = CurPosition.GetCommitDB(); |
| | | //å¨å¶åä¿¡æ¯è¡¨ |
| | | db.Updateable<MES_WIP_DATA>(CurPosition.UserCode) |
| | | .SetColumns(q => q.QTY == NewQty) |
| | | .Where(q => q.WORK_ORDER == wo && _wipIDs.Contains(q.ID)) |
| | | .ExecuteCommand(); |
| | | //ç产è¿ç¨è®°å½ |
| | | db.Updateable<MES_WIP_HIS>(CurPosition.UserCode) |
| | | .SetColumns(q => q.QTY == NewQty) |
| | | .Where(q => q.WORK_ORDER == wo && q.NODE_ID == nodeID && _wipIDs.Contains(q.WIP_ID)) |
| | | .ExecuteCommand(); |
| | | //å·¥å表 |
| | | db.Updateable<BIZ_MES_WO>(CurPosition.UserCode) |
| | | .SetColumns(q => q.INPUT_QTY == NewWoInputQty) |
| | | .Where(q => q.ORDER_NO == wo) |
| | | .ExecuteCommand(); |
| | | //å·¥åæ¹æ¬¡è¡¨ |
| | | db.Updateable<BIZ_MES_WO_BATCH>(CurPosition.UserCode) |
| | | .SetColumns(q => q.INPUT_QTY == NewBatchInputQty) |
| | | .Where(q => q.BATCH_NO == batch) |
| | | .ExecuteCommand(); |
| | | //å·¥åæ¡ç æç»è¡¨ |
| | | db.Updateable<BIZ_MES_WO_SN>(CurPosition.UserCode) |
| | | .SetColumns(q => q.QTY == NewQty) |
| | | .Where(q => q.WORK_ORDER == wo && _wipIDs.Contains(q.WIP_ID)) |
| | | .ExecuteCommand(); |
| | | db.Storageable(_wipActs, CurPosition.UserCode).ExecuteCommand(); |
| | | }; |
| | | |
| | | IsFinished = true; |
| | | CurStep.Message = Biz.L("æ´æ°æ°éæå"); |
| | | CurStep.Status = StepStatus.Finished; |
| | | action.Data.ShortMsg = new("æ´æ°æ°éæå", ShortMessage.Types.Success); |
| | | //action.LocaleMsg = new($"æ¡ç [{0}]æ´æ°æ°é为[{1}]ä¿åæå"); |
| | | action.LocaleMsg = new("MES.WorkAction.InputQty.SaveSuccess", CurPosition.CurSN, NewQty); |
| | | return action; |
| | | } |
| | | |
| | | #endregion Functions |
| | | } |
| | | } |