| | |
| | | { |
| | | #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_ACTION Setting { get; set; } |
| | | #endregion |
| | | public List<BAS_PROD_BOM> Boms { get; set; } = new(); |
| | | public Dictionary<string, List<BAS_ITEM>> SubItemDic { get; set; } = new(); |
| | | public AssemblyInfo CurAssembly { get; set; } = new(); |
| | | #endregion Propertys & Variables |
| | | |
| | |
| | | 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; |
| | |
| | | #endregion |
| | | |
| | | //获取产品BOM |
| | | Boms = Biz.Db.Queryable<BAS_PROD_BOM>().Where(q => q.PROD_CODE == CurPosition.WorkBatch.WO.ITEM_CODE).ToList(); |
| | | Boms = MainDB.Queryable<BAS_PROD_BOM>().Where(q => q.PROD_CODE == CurPosition.WorkBatch.WO.ITEM_CODE).ToList(); |
| | | //获取上料物料 |
| | | var assyList = new List<AssemblySetting>(); |
| | | try |
| | |
| | | } |
| | | } |
| | | var codes = assyList.Select(q => q.ITEM_CODE).ToList(); |
| | | var items = Biz.Db.Queryable<BAS_ITEM>().Where(q => codes.Contains(q.ITEM_CODE) && q.AUTH_ORG == CurPosition.WorkBatch.WO.AUTH_ORG).ToList(); |
| | | var items = MainDB.Queryable<BAS_ITEM>().Where(q => codes.Contains(q.ITEM_CODE) && q.AUTH_ORG == CurPosition.WorkBatch.WO.AUTH_ORG).ToList(); |
| | | //获取上料物料的替代料 |
| | | foreach (var assy in assyList) |
| | | { |
| | |
| | | if (!bom.IsNullOrEmpty()) |
| | | { |
| | | var subs = bom.SUB_CODE.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); |
| | | var surItems = Biz.Db.Queryable<BAS_ITEM>().Where(q => subs.Contains(q.ITEM_CODE) && q.AUTH_ORG == CurPosition.WorkBatch.WO.AUTH_ORG).ToList(); |
| | | if (!SubItemDic.ContainsKey(assy.ITEM_CODE)) |
| | | { |
| | | SubItemDic.Add(assy.ITEM_CODE, surItems); |
| | | } |
| | | var surItems = MainDB.Queryable<BAS_ITEM>().Where(q => subs.Contains(q.ITEM_CODE) && q.AUTH_ORG == CurPosition.WorkBatch.WO.AUTH_ORG).ToList(); |
| | | foreach (var sub in surItems) |
| | | { |
| | | if (!item.SubItems.Any(q => q.ITEM_CODE == sub.ITEM_CODE)) |
| | | { |
| | | item.SubItems.Add(sub); |
| | | } |
| | | } |
| | | } |
| | | CurAssembly.Items.Add(item); |
| | | } |
| | | } |
| | | |
| | | CurStep.Message = Biz.L("扫描上料物料"); |
| | | CurStep.Status = StepStatus.Normal; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | } |
| | | |
| | | //如果返回成功则认为当前行为可以开始执行,否则返回失败 |
| | | CurStep.Message = Biz.L("等待上料"); |
| | | CurStep.Status = StepStatus.Normal; |
| | | action.IsSuccessed = false; |
| | | action.Data.ShortMsg = new("等待上料", ShortMessage.Types.Normal); |
| | | return action; |
| | | } |
| | | |
| | |
| | | foreach (var item in CurAssembly.Items.Where(q => !q.IsFinished)) |
| | | { |
| | | var isOK = true; |
| | | var matchItem = item.ItemInfo; |
| | | //根据条码规则验证上料是否正确 |
| | | if (!item.RuleCode.IsNullOrEmpty()) |
| | | { |
| | | if (!Biz.CodeRule[item.RuleCode].IsNullOrEmpty()) |
| | | if (!Cache.CodeRule[item.RuleCode].IsNullOrEmpty()) |
| | | { |
| | | var result = Biz.CodeRule[item.RuleCode].Verify(input.SN); |
| | | var result = Cache.CodeRule[item.RuleCode].Verify(input.SN); |
| | | if (!result.IsSuccessed) |
| | | { |
| | | isOK = false; |
| | |
| | | } |
| | | } |
| | | } |
| | | //主料验证不通过,则尝试验证替代料 |
| | | if (!isOK && item.SubItems.Any()) |
| | | { |
| | | foreach (var subItem in item.SubItems) |
| | | { |
| | | if (!subItem.RULE_CODE.IsNullOrEmpty()) |
| | | { |
| | | if (!Cache.CodeRule[subItem.RULE_CODE].IsNullOrEmpty()) |
| | | { |
| | | var result = Cache.CodeRule[item.RuleCode].Verify(input.SN); |
| | | //只要有一个替代料通过验证则可以上料 |
| | | if (result.IsSuccessed) |
| | | { |
| | | isOK = true; |
| | | matchItem = subItem; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | //验证通过则保存上料信息 |
| | | if (isOK) |
| | | { |
| | |
| | | { |
| | | AUTH_ORG = CurPosition.WorkBatch.WO.AUTH_ORG, |
| | | AUTH_PROD = CurPosition.CurLine.LINE_CODE, |
| | | WIP_ID = wipSn.ID, |
| | | SN = input.SN, |
| | | PROD_SN = wipSn.SN, |
| | | ITEM_CODE = item.ItemInfo.ITEM_CODE, |
| | | ITEM_CODE = matchItem.ITEM_CODE, |
| | | QTY = 1, |
| | | UNIT = item.ItemInfo.UNIT, |
| | | UNIT = matchItem.UNIT, |
| | | WORK_ORDER = wipSn.WORK_ORDER, |
| | | BATCH_NO = wipSn.BATCH_NO, |
| | | ROT_CODE = wipSn.ROT_CODE, |
| | |
| | | } |
| | | else |
| | | { |
| | | var record = new MES_WIP_ASSY() |
| | | foreach (var wipSn in CurPosition.CurWipSNs) |
| | | { |
| | | AUTH_ORG = CurPosition.WorkBatch.WO.AUTH_ORG, |
| | | AUTH_PROD = CurPosition.CurLine.LINE_CODE, |
| | | SN = input.SN, |
| | | PROD_SN = CurPosition.CurSN, |
| | | ITEM_CODE = item.ItemInfo.ITEM_CODE, |
| | | QTY = 1, |
| | | UNIT = item.ItemInfo.UNIT, |
| | | WORK_ORDER = CurPosition.CurWipSNs.First().WORK_ORDER, |
| | | BATCH_NO = CurPosition.CurWipSNs.First().BATCH_NO, |
| | | ROT_CODE = CurPosition.CurWipSNs.First().ROT_CODE, |
| | | NODE_ID = CurPosition.CurWipSNs.First().NODE_ID, |
| | | NODE_NAME = CurPosition.CurWipSNs.First().NODE_NAME, |
| | | FTY_CODE = CurPosition.CurWipSNs.First().FTY_CODE, |
| | | WS_CODE = CurPosition.CurWipSNs.First().WS_CODE, |
| | | LINE_CODE = CurPosition.CurWipSNs.First().LINE_CODE, |
| | | POST_CODE = CurPosition.CurWipSNs.First().POST_CODE, |
| | | OPER_CODE = CurPosition.CurWipSNs.First().OPER_CODE, |
| | | SEGMENT = CurPosition.CurWipSNs.First().SEGMENT, |
| | | }; |
| | | item.Records.Add(record); |
| | | var record = new MES_WIP_ASSY() |
| | | { |
| | | AUTH_ORG = CurPosition.WorkBatch.WO.AUTH_ORG, |
| | | AUTH_PROD = CurPosition.CurLine.LINE_CODE, |
| | | WIP_ID = wipSn.ID, |
| | | SN = input.SN, |
| | | PROD_SN = wipSn.SN, |
| | | ITEM_CODE = matchItem.ITEM_CODE, |
| | | QTY = 1, |
| | | UNIT = matchItem.UNIT, |
| | | 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, |
| | | 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, |
| | | }; |
| | | item.Records.Add(record); |
| | | } |
| | | |
| | | if (item.Records.Sum(q => q.QTY) >= item.LoadQty * CurPosition.CurWipSNs.Count) |
| | | if (item.Records.Sum(q => q.QTY) / item.Records.Count >= item.LoadQty * CurPosition.CurWipSNs.Count) |
| | | { |
| | | item.IsFinished = true; |
| | | } |
| | | } |
| | | |
| | | CurStep.Message = Biz.L("上料成功"); |
| | | CurStep.Status = StepStatus.Success; |
| | | action.IsSuccessed = true; |
| | | action.Data.Data = CurAssembly; |
| | | //action.LocaleMsg = new Locale($"扫描物料[{item.ItemInfo.ITEM_NAME}({item.ItemInfo.ITEM_CODE})的条码[{input.SN}]成功,请继续上料"); |
| | | action.LocaleMsg = new Locale("MES.WorkAction.Assembly.LoadSuccess", item.ItemInfo.ITEM_NAME, item.ItemInfo.ITEM_CODE); |
| | | action.Data.ShortMsg = new("上料成功", ShortMessage.Types.Success); |
| | | action.Data.Data = CurAssembly; |
| | | //action.LocaleMsg = new Locale($"扫描物料[{matchItem.ITEM_NAME}({matchItem.ITEM_CODE})的条码[{input.SN}]成功,请继续上料"); |
| | | action.LocaleMsg = new Locale("MES.WorkAction.Assembly.LoadSuccess", matchItem.ITEM_NAME, matchItem.ITEM_CODE); |
| | | |
| | | //上料完成 |
| | | if (CurAssembly.IsFinished) |
| | | { |
| | | action = End(); |
| | | action = End(input); |
| | | } |
| | | return action; |
| | | } |
| | | } |
| | | //都没有物料验证通过,则返回错误信息 |
| | | CurStep.Message = Biz.L("上料失败"); |
| | | CurStep.Status = StepStatus.Error; |
| | | action.IsSuccessed = false; |
| | | action.Data.ShortMsg = new("上料失败", ShortMessage.Types.Failed); |
| | | //action.LocaleMsg = new($"条码[{input.SN}]验证失败,不是以下物料的条码:{string.Join(",", CurAssembly.Items.Where(q => !q.IsFinished).Select(q => $"{q.ItemInfo.ITEM_NAME}({q.ItemInfo.ITEM_CODE})"))}"); |
| | | action.LocaleMsg = new("MES.WorkAction.Assembly.LoadFail", input.SN, string.Join(",", CurAssembly.Items.Where(q => !q.IsFinished).Select(q => $"{q.ItemInfo.ITEM_NAME}({q.ItemInfo.ITEM_CODE})"))); |
| | | } |
| | | catch (System.Exception ex) |
| | | { |
| | | CurStep.Message = Biz.L("上料异常"); |
| | | CurStep.Status = StepStatus.Error; |
| | | action.Data.ShortMsg = new("上料异常", ShortMessage.Types.Exception); |
| | | action.CatchExceptionWithLog(ex, $"上料行为:验证条码[{input.SN}]并保存数据异常"); |
| | | action.IsSuccessed = false; |
| | | //action.LocaleMsg = new($"验证条码[{input.SN}]并保存数据异常,工序已重置,请重新扫描进站产品条码"); |
| | |
| | | /// 结束执行工序行为 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public ApiAction<SubmitOutput> End() |
| | | public ApiAction<SubmitOutput> End(SubmitInput input) |
| | | { |
| | | var action = new ApiAction<SubmitOutput>(new SubmitOutput()); |
| | | |
| | | //记录行为操作记录 |
| | | var wipActs = new List<MES_WIP_ACT>(); |
| | | var wipVars = new List<MES_WIP_ACT_VAR>(); |
| | | 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, |
| | |
| | | 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, |
| | |
| | | ACT_TYPE = NodeAct.ACT_TYPE, |
| | | ACT_SN = wipSn.SN, |
| | | ACT_VALUE_1 = CurAssembly.ToJson(), |
| | | ACT_VAR_DIC = CurStep.ActionDic.ToJson(), |
| | | ACT_RESULT = "Y", |
| | | ELAPSED_TIME = CurStep.GetElapsedTime().TotalMilliseconds.ToInt64(), |
| | | TRACE_INFO = $"以下物料上料完成:{string.Join(",", CurAssembly.Items.Select(q => $"{q.ItemInfo.ITEM_NAME}({q.ItemInfo.ITEM_CODE})"))}", |
| | | }; |
| | | wipActs.Add(wipAct); |
| | | } |
| | | //整理上料记录 |
| | | var records = new List<MES_WIP_ASSY>(); |
| | | foreach (var item in CurAssembly.Items) |
| | | { |
| | | records.AddRange(item.Records); |
| | | foreach (var item in NodeAct.Variables) |
| | | { |
| | | var wipVar = new MES_WIP_ACT_VAR() |
| | | { |
| | | AUTH_ORG = CurPosition.WorkBatch.WO.AUTH_ORG, |
| | | AUTH_PROD = CurPosition.CurLine.LINE_CODE, |
| | | HIS_ID = CurPosition.CurWipSNHiss.First(q => q.SN == wipSn.SN).ID, |
| | | WIP_ID = wipSn.ID, |
| | | SN = wipSn.SN, |
| | | ITEM_CODE = wipSn.ITEM_CODE, |
| | | WORK_ORDER = wipSn.WORK_ORDER, |
| | | BATCH_NO = wipSn.BATCH_NO, |
| | | CUST_CODE = CurPosition.WorkBatch.WO.CUST_CODE, |
| | | 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, |
| | | VAR_CODE = item.VAR_CODE, |
| | | VAR_NAME = item.VAR_NAME, |
| | | VAR_CONTROL = item.VAR_CONTROL, |
| | | VALUE_TYPE = item.VALUE_TYPE, |
| | | PROCESS_VAR = item.PROCESS_VAR, |
| | | INPUT_VALUE = CurStep.ActionDic.GetOrDefault(item.VAR_CODE), |
| | | TRACE_INFO = CurStep.ActionDic.ToJson(), |
| | | }; |
| | | wipVars.Add(wipVar); |
| | | } |
| | | } |
| | | |
| | | |
| | | //创建变量克隆对象用于传入DBSubmitAction中保存当前需要暂存的数据值 |
| | | var _wipActs = wipActs.Clone(); |
| | | var _wipVars = wipVars.Clone(); |
| | | //整理上料记录 |
| | | var _records = new List<MES_WIP_ASSY>(); |
| | | foreach (var item in CurAssembly.Items) |
| | | { |
| | | _records.AddRange(item.Records.Clone()); |
| | | } |
| | | //保存数据 |
| | | CurStep.DBSubmitAction = () => |
| | | { |
| | | var db = CurPosition.GetCommitDB(); |
| | | db.Storageable(wipActs, CurPosition.UserCode).ExecuteCommand(); |
| | | db.Insertable(records, CurPosition.UserCode).ExecuteCommand(); |
| | | db.Storageable(_wipActs, CurPosition.UserCode).ExecuteCommand(); |
| | | db.Storageable(_wipVars, CurPosition.UserCode).ExecuteCommand(); |
| | | db.Insertable(_records, CurPosition.UserCode).ExecuteCommand(); |
| | | }; |
| | | |
| | | IsFinished = true; |
| | | CurStep.Message = Biz.L("上料完成"); |
| | | CurStep.Status = StepStatus.Finished; |
| | | action.Data.ShortMsg = new("上料完成", ShortMessage.Types.Success); |
| | | //action.LocaleMsg = new($"以下物料上料完成:{string.Join(",", CurAssembly.Items.Select(q => $"{q.ItemInfo.ITEM_NAME}({q.ItemInfo.ITEM_CODE})"))}"); |
| | | action.LocaleMsg = new("MES.WorkAction.Assembly.LoadFinish", string.Join(",", CurAssembly.Items.Select(q => $"{q.ItemInfo.ITEM_NAME}({q.ItemInfo.ITEM_CODE})"))); |
| | | return action; |