| | |
| | | public MES_WO_NODE_ACT NodeAct { 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(); |
| | | public BAS_WIP_EXT ExtInfo { get; set; } |
| | | public MES_WIP_EXT CurWipExt { get; set; } |
| | | #endregion Propertys & Variables |
| | | |
| | | #region Functions |
| | |
| | | Setting = setting; |
| | | #endregion |
| | | |
| | | //获取产品BOM |
| | | Boms = Biz.Db.Queryable<BAS_PROD_BOM>().Where(q => q.PROD_CODE == CurPosition.WorkBatch.WO.ITEM_CODE).ToList(); |
| | | //获取上料物料 |
| | | var assyList = new List<AssemblySetting>(); |
| | | try |
| | | //获取扩展字段定义 |
| | | var seq = Setting.ITEM_CODE.ToInt32(); |
| | | ExtInfo = Biz.Db.Queryable<BAS_WIP_EXT>().Where(q => q.SEQ == seq).First(); |
| | | //获取当前SN的扩展信息 |
| | | CurWipExt = Biz.Db.Queryable<MES_WIP_EXT>().Where(q => q.SN == CurPosition.CurWipSN.SN).First() ?? new () |
| | | { |
| | | assyList = setting.ITEM_CODE.JsonToObject<List<AssemblySetting>>(); |
| | | } |
| | | catch (System.Exception ex) |
| | | { |
| | | var codeList = setting.ITEM_CODE.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); |
| | | foreach (var code in codeList) |
| | | { |
| | | assyList.Add(new() { ItemCode = code }); |
| | | } |
| | | } |
| | | var codes = assyList.Select(q => q.ItemCode).ToList(); |
| | | var items = Biz.Db.Queryable<BAS_ITEM>().Where(q => codes.Contains(q.ITEM_CODE) && q.AUTH_ORG == CurPosition.WorkBatch.WO.AUTH_ORG).ToList(); |
| | | //获取上料物料的替代料 |
| | | foreach (var assy in assyList) |
| | | { |
| | | var info = items.FirstOrDefault(q => q.ITEM_CODE == assy.ItemCode); |
| | | if (!info.IsNullOrEmpty()) |
| | | { |
| | | var item = new AssemblyItem |
| | | { |
| | | ItemInfo = info, |
| | | RuleCode = assy.RuleCode, |
| | | LoadQty = assy.Qty, |
| | | }; |
| | | var bom = Boms.FirstOrDefault(q => q.ITEM_CODE == assy.ItemCode); |
| | | 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.ItemCode)) |
| | | { |
| | | SubItemDic.Add(assy.ItemCode, surItems); |
| | | } |
| | | } |
| | | CurAssembly.Items.Add(item); |
| | | } |
| | | } |
| | | AUTH_ORG = CurPosition.CurWipSN.AUTH_ORG, |
| | | AUTH_PROD = CurPosition.CurWipSN.AUTH_PROD, |
| | | SN = CurPosition.CurWipSN.SN, |
| | | }; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// <returns></returns> |
| | | public Locale GetBeginMsg() |
| | | { |
| | | var msg = new Locale("MES.WorkAction.WipExtInfo.BeginMsg", string.Join(",", CurAssembly.Items.Select(q => $"{q.ItemInfo.ITEM_NAME}({q.ItemInfo.ITEM_CODE})"))); |
| | | //var msg = new Locale($"请扫描以下需要上料的物料条码:{string.Join(",", CurAssembly.Items.Select(q => $"{q.ItemInfo.ITEM_NAME}({q.ItemInfo.ITEM_CODE})"))}"); |
| | | var msg = new Locale("MES.WorkAction.WipExtInfo.BeginMsg", ExtInfo.FIELD_NAME); |
| | | //var msg = new Locale($"请扫描产品[{CurPosition.CurWipSN.SN}]需要绑定的[{ExtInfo.FIELD_NAME}]标签条码"); |
| | | return msg; |
| | | } |
| | | |
| | |
| | | { |
| | | var action = new ApiAction<SubmitOutput>(new SubmitOutput()); |
| | | |
| | | if (input.SN != CurPosition.CurWipSN.SN) |
| | | { |
| | | action = SaveAssembly(input, action); |
| | | return action; |
| | | } |
| | | action.LocaleMsg = GetBeginMsg(); |
| | | |
| | | //如果返回成功则认为当前行为可以开始执行,否则返回失败 |
| | | action.IsSuccessed = false; |
| | | action.IsSuccessed = true; |
| | | return action; |
| | | } |
| | | |
| | |
| | | { |
| | | var action = new ApiAction<SubmitOutput>(new SubmitOutput()); |
| | | |
| | | action = SaveAssembly(input, action); |
| | | action = SaveExtInfo(input, action); |
| | | //上料数据保存失败 |
| | | if (!action.IsSuccessed) |
| | | { |
| | |
| | | return action; |
| | | } |
| | | |
| | | public ApiAction<SubmitOutput> SaveAssembly(SubmitInput input, ApiAction<SubmitOutput> action) |
| | | public ApiAction<SubmitOutput> SaveExtInfo(SubmitInput input, ApiAction<SubmitOutput> action) |
| | | { |
| | | try |
| | | { |
| | | foreach (var item in CurAssembly.Items.Where(q => !q.IsFinished)) |
| | | var isOK = true; |
| | | //验证扫描的条码是否SN的扩展信息的标签 |
| | | if (input.SN.IsNullOrEmpty()) |
| | | { |
| | | var isOK = true; |
| | | //根据条码规则验证上料是否正确 |
| | | if (!item.RuleCode.IsNullOrEmpty()) |
| | | { |
| | | if (!Biz.CodeRule[item.RuleCode].IsNullOrEmpty()) |
| | | { |
| | | var result = Biz.CodeRule[item.RuleCode].Verify(input.SN); |
| | | if (!result.IsSuccessed) |
| | | { |
| | | isOK = false; |
| | | } |
| | | } |
| | | //不存在条码规则,则判断是否有自定义规则,没有则返回失败 |
| | | else |
| | | { |
| | | switch (item.RuleCode) |
| | | { |
| | | case "自行验证": |
| | | break; |
| | | default: |
| | | isOK = false; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | //验证通过则保存上料信息 |
| | | if (isOK) |
| | | { |
| | | var record = new MES_WIP_ASSY() |
| | | { |
| | | AUTH_ORG = CurPosition.WorkBatch.WO.AUTH_ORG, |
| | | AUTH_PROD = CurPosition.CurLine.LINE_CODE, |
| | | SN = input.SN, |
| | | PROD_SN = CurPosition.CurWipSN.SN, |
| | | ITEM_CODE = item.ItemInfo.ITEM_CODE, |
| | | QTY = 1, |
| | | UNIT = item.ItemInfo.UNIT, |
| | | WORK_ORDER = CurPosition.CurWipSN.WORK_ORDER, |
| | | BATCH_NO = CurPosition.CurWipSN.BATCH_NO, |
| | | ROT_CODE = CurPosition.CurWipSN.ROT_CODE, |
| | | NODE_ID = CurPosition.CurWipSN.NODE_ID, |
| | | NODE_NAME = CurPosition.CurWipSN.NODE_NAME, |
| | | FTY_CODE = CurPosition.CurWipSN.FTY_CODE, |
| | | WS_CODE = CurPosition.CurWipSN.WS_CODE, |
| | | LINE_CODE = CurPosition.CurWipSN.LINE_CODE, |
| | | POST_CODE = CurPosition.CurWipSN.POST_CODE, |
| | | OPER_CODE = CurPosition.CurWipSN.OPER_CODE, |
| | | SEGMENT = CurPosition.CurWipSN.SEGMENT, |
| | | }; |
| | | item.Records.Add(record); |
| | | if (item.Records.Sum(q => q.QTY) >= item.LoadQty) |
| | | { |
| | | item.IsFinished = true; |
| | | } |
| | | |
| | | 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.WipExtInfo.LoadSuccess", item.ItemInfo.ITEM_NAME, item.ItemInfo.ITEM_CODE); |
| | | |
| | | //上料完成 |
| | | if (CurAssembly.IsFinished) |
| | | { |
| | | action = End(); |
| | | } |
| | | return action; |
| | | } |
| | | action.IsSuccessed = isOK = false; |
| | | //action.LocaleMsg = new Locale($"错误:[{ExtInfo.FIELD_NAME}]标签条码不能为空,请重新扫描"); |
| | | action.LocaleMsg = new Locale("MES.WorkAction.WipExtInfo.SnEmptyError", ExtInfo.FIELD_NAME); |
| | | } |
| | | if (input.SN == CurPosition.CurWipSN.SN) |
| | | { |
| | | action.IsSuccessed = isOK = false; |
| | | //action.LocaleMsg = new Locale($"错误:扫描到产品条码[{input.SN}],请重新扫描[{ExtInfo.FIELD_NAME}]标签条码"); |
| | | action.LocaleMsg = new Locale("MES.WorkAction.WipExtInfo.ScanProdSnError", input.SN, ExtInfo.FIELD_NAME); |
| | | } |
| | | |
| | | //验证通过则保存上料信息 |
| | | if (isOK) |
| | | { |
| | | CurWipExt.GetType().GetProperty($"FIELD_{ExtInfo.SEQ.ToString("00")}")?.SetValue(CurWipExt, input.SN); |
| | | action = End(); |
| | | } |
| | | |
| | | //都没有物料验证通过,则返回错误信息 |
| | | action.IsSuccessed = false; |
| | | //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.WipExtInfo.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) |
| | | { |
| | | action.CatchExceptionWithLog(ex, $"上料行为:验证条码[{input.SN}]并保存数据失败"); |
| | | action.CatchExceptionWithLog(ex, $"扩展信息绑定行为:产品[{CurPosition.CurWipSN.SN}]绑定[{ExtInfo.FIELD_NAME}]标签条码[{input.SN}]保存异常"); |
| | | action.IsSuccessed = false; |
| | | action.LocaleMsg = new($"验证条码[{input.SN}]并保存数据失败,工序已重置,请重新扫描进站产品条码"); |
| | | action.LocaleMsg = new("MES.WorkAction.WipExtInfo.SaveAssemblyException", input.SN); |
| | | //action.LocaleMsg = new($"产品[{CurPosition.CurWipSN.SN}]绑定[{ExtInfo.FIELD_NAME}]标签条码[{input.SN}]保存异常,工序已重置,请重新扫描进站产品条码"); |
| | | action.LocaleMsg = new("MES.WorkAction.WipExtInfo.SaveExtInfoException", CurPosition.CurWipSN.SN, ExtInfo.FIELD_NAME, input.SN); |
| | | CurPosition.ResetNode(); |
| | | } |
| | | return action; |
| | |
| | | PRD_CODE = CurPosition.CurWipSN.PRD_CODE, |
| | | ACT_TYPE = NodeAct.ACT_TYPE, |
| | | ACT_SN = CurPosition.CurWipSN.SN, |
| | | ACT_VALUE_1 = CurAssembly.ToJson(), |
| | | ACT_VALUE_1 = CurWipExt.ToJson(), |
| | | ACT_RESULT = "Y", |
| | | TRACE_INFO = $"以下物料上料完成:{string.Join(",", CurAssembly.Items.Select(q => $"{q.ItemInfo.ITEM_NAME}({q.ItemInfo.ITEM_CODE})"))}", |
| | | TRACE_INFO = $"产品[{CurPosition.CurWipSN.SN}]绑定[{ExtInfo.FIELD_NAME}]标签条码[{CurWipExt.GetType().GetProperty($"FIELD_{ExtInfo.SEQ.ToString("00")}")?.GetValue(CurWipExt)?.ToString()}]保存成功", |
| | | }; |
| | | var records = new List<MES_WIP_ASSY>(); |
| | | foreach (var item in CurAssembly.Items) |
| | | { |
| | | records.AddRange(item.Records); |
| | | } |
| | | |
| | | //保存数据 |
| | | CurStep.DBSubmitAction = () => |
| | | { |
| | | var db = CurPosition.GetCommitDB(); |
| | | db.Storageable(wipAct, CurPosition.UserCode).ExecuteCommand(); |
| | | db.Insertable(records, CurPosition.UserCode).ExecuteCommand(); |
| | | db.Storageable(CurWipExt, CurPosition.UserCode).ExecuteCommand(); |
| | | }; |
| | | |
| | | IsFinished = true; |
| | | //action.LocaleMsg = new($"以下物料上料完成:{string.Join(",", CurAssembly.Items.Select(q => $"{q.ItemInfo.ITEM_NAME}({q.ItemInfo.ITEM_CODE})"))}"); |
| | | action.LocaleMsg = new("MES.WorkAction.WipExtInfo.LoadFinish", string.Join(",", CurAssembly.Items.Select(q => $"{q.ItemInfo.ITEM_NAME}({q.ItemInfo.ITEM_CODE})"))); |
| | | //action.LocaleMsg = new($"产品[{CurPosition.CurWipSN.SN}]绑定[{ExtInfo.FIELD_NAME}]标签条码[{CurWipExt.GetType().GetProperty($"FIELD_{ExtInfo.SEQ.ToString("00")}")?.GetValue(CurWipExt)?.ToString()}]保存成功"); |
| | | action.LocaleMsg = new("MES.WorkAction.WipExtInfo.SaveSuccess", CurPosition.CurWipSN.SN, ExtInfo.FIELD_NAME, CurWipExt.GetType().GetProperty($"FIELD_{ExtInfo.SEQ.ToString("00")}")?.GetValue(CurWipExt)?.ToString()); |
| | | return action; |
| | | } |
| | | |