From bed76502512bd0a7f39cfa7024b238d822746e67 Mon Sep 17 00:00:00 2001 From: Rodney Chen <rodney.chen@hotmail.com> Date: 星期五, 27 九月 2024 01:30:19 +0800 Subject: [PATCH] Merge branch 'master' of http://47.115.28.255:8110/r/TigerClouds-Tech/Server/TigerApi6_2024 --- Tiger.Business.MES/Transaction/Position.cs | 181 ++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 162 insertions(+), 19 deletions(-) diff --git a/Tiger.Business.MES/Transaction/Position.cs b/Tiger.Business.MES/Transaction/Position.cs index 5dcbd97..c2f109a 100644 --- a/Tiger.Business.MES/Transaction/Position.cs +++ b/Tiger.Business.MES/Transaction/Position.cs @@ -11,6 +11,8 @@ using Tiger.Model; using static Tiger.Business.Biz; using Tiger.Model.Entitys.MES.Position; +using System.Globalization; +using Tiger.Business.MES.WorkAction; namespace Tiger.Business.MES.Transaction { @@ -48,6 +50,9 @@ #region Propertys & Variables public string UserCode { get; set; } public string PostCode { get; set; } + protected DateTime BeginAt; + protected DateTime EndAt; + public TimeSpan ElapsedTime => EndAt - BeginAt; public MES_FACTORY CurFactory { get; set; } public MES_WORKSHOP CurWorkshop { get; set; } public MES_LINE CurLine { get; set; } @@ -64,7 +69,7 @@ public WorkStep CurStep { get; set; } public List<WorkStep> NextSteps { get; set; } = new(); public bool IsFinishNodeSteps => !Steps.Any(q => q.NodeType == IWorkStep.NodeTypes.Node && !q.IsFinished); - public bool IsFinishAllSteps => !Steps.Any() || !Steps.Any(q => !q.IsFinished); + public bool IsFinishAllSteps => Steps.Any() && !Steps.Any(q => !q.IsFinished); //public int CurStep => Steps.Where(q => !q.IsFinished).OrderBy(q => q.Sequence).FirstOrDefault()?.Sequence ?? 0; private DbClient CommitDB; /// <summary> @@ -73,8 +78,8 @@ public bool NeedTemporaryStoreDBCommitAction { get; set; } = false; protected Dictionary<string, List<Action>> DBCommitList { get; set; } = new(); protected List<Position> NodeCommitList { get; set; } = new(); - protected Dictionary<string, OperInfo> OperInfoDic { get; set; } = new(); - //protected OperInfo CurOperInfo { get; set; } + private Dictionary<string, OperInfo> OperInfoDic = new(); + #endregion Propertys & Variables #region Functions @@ -137,7 +142,7 @@ { OperInfoDic.Add(CurBatch.Batch.BATCH_NO, new()); } - + action.Data = new { WorkOrder = CurBatch.WO, Bacth = CurBatch.Batch }; } catch (Exception ex) @@ -196,22 +201,32 @@ CurDefects.Clear(); } + //鑾峰彇褰撳墠鐨勫伐搴忎俊鎭� + protected OperInfo CurOperInfo(string locale) + { + OperInfo info = new(); + if (CurBatch?.Batch?.BATCH_NO != null) + { + info = OperInfoDic[CurBatch.Batch.BATCH_NO]; + info.StepsInfo = Steps.Select(q => q.GetInfo(locale)).ToList(); + } + return info; + } + /// <summary> /// 璁剧疆褰撳墠鏉$爜鐨勫伐搴忎俊鎭� /// </summary> - public OperInfo SetOperNodeInfo(OperInfo info, string locale) + public OperInfo SetOperNodeInfo(OperInfo info) { if (CurWipSNs.Any()) { info.CurNode = CurWipSNs.First().NODE_NAME; info.NextNode = string.Join(",", CurBatch.GetNextNodes(CurWipSNs.First()).Select(q => q.NODE_NAME)); - info.StepsInfo = Steps.Select(q => q.GetInfo(locale)).ToList(); } else { info.CurNode = " 鈥� "; info.NextNode = " 鈥� "; - info.StepsInfo = new(); } return info; } @@ -341,11 +356,23 @@ CurStep = step; //鏇存柊鍚庣画鍙墽琛岀殑宸ユ鍒楄〃 NextSteps = GetNextSteps(CurStep); - //杩斿洖缁撴灉鍒板鎴风 - result = canBegin; - result.Data.SetValue(CurBatch, CurStep, CurStep?.ID, IsFinishAllSteps); - + //濡傛灉褰撳墠鎵ц宸ユ灏濊瘯鎵ц鍚庡氨宸茬粡瀹屾垚锛屼笉闇�瑕佸悗缁氦浜掞紝涓旓紝鍒欑户缁紑濮嬩笅涓�宸ユ + if (CurStep.IsFinished && NextSteps.Any()) + { + result = BeginNextActionStep(input); + } + else + { + //杩斿洖缁撴灉鍒板鎴风 + result = canBegin; + result.Data.SetValue(CurBatch, CurStep, CurStep?.ID, IsFinishAllSteps); + } return result; + } + //宸ュ簭琚噸缃� + else if (Steps.IsNullOrEmpty()) + { + return canBegin; } } @@ -393,6 +420,10 @@ action.Invoke(); } } + //璁板綍宸ュ簭鑰楁椂 + EndAt = DateTime.Now; + var ids = CurWipSNHiss.Select(q => q.ID).ToList(); + GetCommitDB().Updateable<MES_WIP_HIS>().SetColumns(q => q.ELAPSED_TIME == ElapsedTime.TotalMilliseconds.ToInt64()).Where(q => ids.Contains(q.ID)).ExecuteCommand(); }); if (dbTran.IsSuccess) { @@ -424,6 +455,7 @@ } } + #region 鎵撳嵃涓撶敤鏂规硶 /// <summary> /// 鑾峰彇鎵撳嵃鏍囩妯℃澘杩囩▼鍙橀噺鍊� /// </summary> @@ -432,7 +464,7 @@ /// <returns></returns> public BAS_LABEL_TEMP SetLabelVariables(List<BAS_LABEL_PV> labelPVs, BAS_LABEL_TEMP label, IWorkAction action) { - foreach (var item in label.Variables) + foreach (var item in label.Variables.OrderBy(q => q.VAR_TYPE == BAS_LABEL_VAR.VAR_TYPEs.BarcodeGenerate.GetValue() ? 0 : 1)) { switch (item.VAR_TYPE.GetEnum<BAS_LABEL_VAR.VAR_TYPEs>()) { @@ -440,7 +472,7 @@ item.Value = item.VAR_VALUE; break; case BAS_LABEL_VAR.VAR_TYPEs.ProcessVariable: - item.Value = GetPrintProcessValue(labelPVs, item, action); + item.Value = GetPrintProcessValue(labelPVs, item, label.Variables, action); break; case BAS_LABEL_VAR.VAR_TYPEs.DateVariable: item.Value = DateTime.Now.ToString(item.VAR_VALUE); @@ -463,7 +495,7 @@ /// <param name="labelPVs">杩囩▼鍙橀噺鍒楄〃</param> /// <param name="lv">鏍囩妯℃澘鍙橀噺</param> /// <returns></returns> - public string GetPrintProcessValue(List<BAS_LABEL_PV> labelPVs, BAS_LABEL_VAR lv, IWorkAction action) + public string GetPrintProcessValue(List<BAS_LABEL_PV> labelPVs, BAS_LABEL_VAR lv, List<BAS_LABEL_VAR> lvars, IWorkAction action) { var pv = labelPVs.FirstOrDefault(q => q.VAR_CODE == lv.VAR_VALUE); if (!pv.IsNullOrEmpty()) @@ -477,11 +509,33 @@ case "GetSN": return CurSN; case "GetBAS_ITEM": - return WorkBatch.Product.ToJson(); + return WorkBatch.Product.ITEM_CODE; case "GetCustomer": return WorkBatch.Batch.ToJson(); + case "GetBoxQR": + return action is PackingAction ? GetBoxCode(lvars, action as PackingAction) : ""; + case "GetCardQR": + return action is PackingAction? GetCardCode(lvars, action as PackingAction) : ""; + case "GetDescription": + return WorkBatch.Product.ITEM_DESC; + case "GetPAndO": + return WorkBatch.WO.SALES_CONTRACT; + case "GetLTD": + return WorkBatch.Batch.Customer.SHORT_NAME; + case "GetHWDate": + return WorkBatch.Batch.ToJson(); + case "GetModel": + return GetLabelVarWo(lv, WorkBatch.Product.ExtInfo.Model); + case "GetInput": + return GetLabelVarWo(lv, WorkBatch.Product.ExtInfo.Input); + case "GetOutput": + return GetLabelVarWo(lv, WorkBatch.Product.ExtInfo.OutPut); + case "GetPower": + return GetLabelVarWo(lv, WorkBatch.Product.ExtInfo.Power); + case "GetAccuracy": + return GetLabelVarWo(lv, WorkBatch.Product.ExtInfo.Accuracy); case "GetVarByWo": - return GetLabelVarWo(lv); + return GetLabelVarWo(lv, ""); default: return ""; } @@ -517,7 +571,7 @@ case "GetCartonGenerate": return Biz.CodeRule[lv.BARCODE_RULE ?? ""]?.Generate($"{WorkBatch.Batch.BATCH_NO}-{WorkBatch.Batch.PLAN_QTY}-").Data.ToString() ?? ""; case "GetHW21SNGenerate": - return Biz.CodeRule[lv.BARCODE_RULE ?? ""]?.Generate("SN:","05").Data.ToString() ?? ""; + return Biz.CodeRule[lv.BARCODE_RULE ?? ""]?.Generate("SN:", "05").Data.ToString() ?? ""; default: return ""; } @@ -534,7 +588,7 @@ /// </summary> /// <param name="labelId"></param> /// <returns></returns> - private string GetLabelVarWo(BAS_LABEL_VAR lv) + private string GetLabelVarWo(BAS_LABEL_VAR lv, string value) { string result = ""; var labelVarwos = Biz.Db.Queryable<BAS_LABEL_VAR_WO>().Where(x => x.LABEL_ID == lv.LABEL_ID && x.VAR_NAME == lv.VAR_NAME).ToList(); @@ -544,11 +598,100 @@ } else { - result = labelVarwos.Count > 0 ? labelVarwos[0].DEFAULT_VALUE : ""; + result = value.IsNullOrEmpty() ? (labelVarwos.Count > 0 ? labelVarwos.First().DEFAULT_VALUE : "") : value; } return result; } + /// <summary> + /// 鑾峰彇鐧界洅鏉$爜 + /// </summary> + /// <param name="action"></param> + /// <returns></returns> + private string GetBoxCode(List<BAS_LABEL_VAR> lvars, PackingAction action) + { + return GetCardOrBoxQR(CurSN, lvars, action); + } + + /// <summary> + /// 鑾峰彇绠辨潯鐮� + /// </summary> + /// <param name="lvars"></param> + /// <param name="action"></param> + /// <returns></returns> + private string GetCardCode(List<BAS_LABEL_VAR> lvars, PackingAction action) + { + var cardCode = lvars.First(q=>q.VAR_NAME == "CardQR").Value; + return GetCardOrBoxQR(cardCode, lvars, action); + } + + /// <summary> + /// 鑾峰彇鐧界洅鎴栬�呯浜岀淮鐮� + /// </summary> + /// <param name="code"></param> + /// <param name="lvars"></param> + /// <param name="action"></param> + /// <returns></returns> + private string GetCardOrBoxQR(string code, List<BAS_LABEL_VAR> lvars, PackingAction action) + { + var itemCode = WorkBatch.Product.ITEM_CODE; + var wo = WorkBatch.Batch.ORDER_NO; + var snList = string.Join("\r\n", action.GetMinPackageList(action.CurPkg.Item).Select(q => q.SN)); + var weight = action.CurPkg.WeightInfo.Weight; + var unit = action.CurPkg.WeightInfo.Unit.ToUpper(); + var model = WorkBatch.Product.ExtInfo.Model; + var Input = WorkBatch.Product.ExtInfo.Input; + var OutPut = WorkBatch.Product.ExtInfo.OutPut; + var Power = WorkBatch.Product.ExtInfo.Power; + var Accuracy = WorkBatch.Product.ExtInfo.Accuracy; + var Remark = WorkBatch.Product.ExtInfo.Remark; + + return $"{code}|{itemCode}|{wo}|{snList}|{weight}|鍨嬪彿:{model},杈撳叆:{Input},杈撳嚭:{OutPut},鐢垫簮:{Power},绮惧害:{Accuracy},澶囨敞:{Remark}"; + } + + /// <summary> + /// 鏍规嵁鍖呰宸ュ崟鍜屾潯鐮佽幏鍙栧崕涓鸿姹傜殑鐢熶骇鍛ㄦ湡 + /// </summary> + /// <param name="snList"></param> + /// <returns></returns> + private string GetHuaWeiWeek(string pkgOrder, List<string> snList) + { + Dictionary<string, string> dic = new(); + var snOrder = Biz.Db.Queryable<MES_CUST_SN, BIZ_MES_WO>((q, w) => new JoinQueryInfos(JoinType.Left, q.WORK_ORDER == w.ORDER_NO)) + .Where((q, w) => q.PKG_ORDER == pkgOrder && (snList.Contains(q.FLOW_SN) || snList.Contains(q.CUST_SN))) + .Select((q, w) => new { q.PKG_ORDER, q.WORK_ORDER, w.ACT_START_TIME, w.PLAN_START_TIME, q.FLOW_SN, q.CUST_SN }).ToList(); + foreach (var sn in snList) + { + var item = snOrder.FirstOrDefault(q => q.FLOW_SN == sn || q.CUST_SN == sn); + if (!item.IsNullOrEmpty()) + { + var date = item.ACT_START_TIME < new DateTime(2000, 1, 1) ? item.PLAN_START_TIME : item.ACT_START_TIME; ; + var firstDay = new DateTime(date.Year, 1, 1); + int daysOffset = firstDay.DayOfWeek.GetValue() > 3 ? (firstDay.DayOfWeek.GetValue() - 7) : 0; + int year = date.Year + ((date - firstDay).TotalDays + daysOffset < 0 ? -1 : 0); + int week = CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(date, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Sunday); + dic.Add(sn, $"{year.ToString().Substring(2, 2)}{week:00}"); + } + else + { + dic.Add(sn, ""); + } + } + var weeks = dic.Select(q => q.Value).Where(q => !q.IsNullOrEmpty()).Distinct().OrderBy(q => q).ToList(); + + switch (weeks.Count) + { + case 0: + return ""; + case 1: + return weeks.First(); + case 2: + return string.Join("/", weeks.Select(q => q + $"({dic.Count(d => d.Value == q)})")); + default: + return string.Join("/", weeks.Take(2)) + " (+)"; + } + } + #endregion #endregion Functions public override bool Close(bool needSaveHistoryLog = false) -- Gitblit v1.9.3