| | |
| | | using Tiger.Model; |
| | | using static Tiger.Business.Biz; |
| | | using Tiger.Model.Entitys.MES.Position; |
| | | using System.Globalization; |
| | | |
| | | namespace Tiger.Business.MES.Transaction |
| | | { |
| | |
| | | #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; } |
| | |
| | | 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> |
| | |
| | | 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 |
| | |
| | | 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; |
| | | } |
| | |
| | | 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; |
| | | } |
| | | } |
| | | |
| | |
| | | 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) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | #region 打印专用方法 |
| | | /// <summary> |
| | | /// 获取打印标签模板过程变量值 |
| | | /// </summary> |
| | |
| | | return result; |
| | | } |
| | | |
| | | /// <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) |