服务端的TigerApi 框架,基于.NET6 2024 版本
Ben Lin
2024-10-10 c4822304dbf523bcbecfbf6e25493ded56540c93
Tiger.Business.MES/Transaction/Position.cs
@@ -13,6 +13,7 @@
using Tiger.Model.Entitys.MES.Position;
using System.Globalization;
using Tiger.Business.MES.WorkAction;
using System.Collections;
namespace Tiger.Business.MES.Transaction
{
@@ -395,15 +396,45 @@
        /// <summary>
        /// 保存工步的数据库提交操作到数据库
        /// </summary>
        protected void SaveStepsCommitActionToDB()
        /// <param name="appendToSave">提交完工步数据后,提交附加的保存内容</param>
        public void SaveStepsCommitActionToDB(Action appendToSave = null)
        {
            //保存工步的数据库提交操作到提交操作列表
            var commitList = new List<Action>();
            foreach (var step in Steps.OrderBy(q => q.Sequence))
            if (!Steps.IsNullOrEmpty())
            {
                commitList.Add(step.DBSubmitAction);
               var commitList = new List<Action>();
               foreach (var step in Steps.OrderBy(q => q.Sequence))
               {
                   commitList.Add(step.DBSubmitAction);
               }
               //记录工序耗时
               commitList.Add(() =>
               {
                   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 (!appendToSave.IsNullOrEmpty())
                {
                    commitList.Add(appendToSave);
                }
               DBCommitList.Add(CurSN, commitList);
            }
            DBCommitList.Add(CurSN, commitList);
            else
            {
                //增加附加的保存内容
                if (!appendToSave.IsNullOrEmpty())
                {
                    if (!DBCommitList.ContainsKey("AppendSaveAction"))
                    {
                        DBCommitList.Add("AppendSaveAction", new List<Action>());
                    }
                    var commitList = DBCommitList["AppendSaveAction"];
                    commitList.Add(appendToSave);
                }
            }
            //如果不需要临时存储数据库提交操作,则把提交操作列表提交到数据库
            if (!NeedTemporaryStoreDBCommitAction)
            {
@@ -413,17 +444,21 @@
                var dbTran = GetCommitDB().UseTran(() =>
                {
                    //在同一个事务中保存所有工步的数据
                    foreach (var wipSn in DBCommitList.Keys)
                    foreach (var wipSn in DBCommitList.Keys.Where(q => q != "AppendSaveAction"))
                    {
                        foreach (var action in DBCommitList[wipSn])
                        {
                            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 (DBCommitList.ContainsKey("AppendSaveAction"))
                    {
                        foreach (var action in DBCommitList["AppendSaveAction"])
                        {
                            action.Invoke();
                        }
                    }
                });
                if (dbTran.IsSuccess)
                {
@@ -516,8 +551,18 @@
                                    return action is PackingAction ? GetBoxCode(lvars, action as PackingAction) : "";
                                case "GetCardQR":
                                    return action is PackingAction ? GetCardCode(lvars, action as PackingAction) : "";
                                case "GetCardSN":
                                    List<string> minPkgList = new List<string>();
                                    var _pkaction = action is PackingAction ? action as PackingAction : null;
                                    if (_pkaction != null)
                                    {
                                        minPkgList = GetMinPkgList(_pkaction);
                                    }
                                    return string.Join("\r\n", minPkgList);
                                case "GetDescription":
                                    return WorkBatch.Product.ITEM_DESC;
                                case "GetFengZ":
                                    return WorkBatch.Product.ExtInfo.Packaging;
                                case "GetPAndO":
                                    return WorkBatch.WO.SALES_CONTRACT;
                                case "GetLTD":
@@ -525,15 +570,19 @@
                                case "GetHWDate":
                                    List<string> list = new List<string>();
                                    var _action = action is PackingAction ? action as PackingAction : null;
                                    if (_action.CurPkg.Item.PKG_LEVEL == 1)
                                    if (_action!=null)
                                    {
                                        list.Add(CurSN);
                                    }
                                    else
                                    {
                                        list = _action != null ? _action.GetMinPackageList(_action.CurPkg.Item).Select(q => q.SN).ToList() : new List<string>();
                                        list = GetMinPkgList(_action);
                                    }
                                    return GetHuaWeiWeek(WorkBatch.Batch.ORDER_NO, list);
                                case "GetQty":
                                    List<string> qtylist = new List<string>();
                                    var _qtyAction = action is PackingAction ? action as PackingAction : null;
                                    if (_qtyAction != null)
                                    {
                                        qtylist = GetMinPkgList(_qtyAction);
                                    }
                                    return $"{qtylist.Count}PCS";
                                case "GetModel":
                                    return GetLabelVarWo(lv, WorkBatch.Product.ExtInfo.Model);
                                case "GetInput":
@@ -579,7 +628,7 @@
                            switch (pv.VAR_METHOD)
                            {
                                case "GetCartonGenerate":
                                    return Biz.CodeRule[lv.BARCODE_RULE ?? ""]?.Generate($"{WorkBatch.Batch.BATCH_NO}-{WorkBatch.Batch.PLAN_QTY}-").Data.ToString() ?? "";
                                    return Biz.CodeRule[lv.BARCODE_RULE ?? ""]?.Generate("B", $"{WorkBatch.Batch.BATCH_NO}-{WorkBatch.Batch.PLAN_QTY}-").Data.ToString() ?? "";
                                case "GetHW21SNGenerate":
                                    return Biz.CodeRule[lv.BARCODE_RULE ?? ""]?.Generate("SN:", "05").Data.ToString() ?? "";
                                default:
@@ -614,6 +663,24 @@
        }
        /// <summary>
        /// 获取最小包装条码列表
        /// </summary>
        /// <param name="action"></param>
        /// <returns></returns>
        private List<string> GetMinPkgList(PackingAction action) {
            List<string> list = new List<string>();
            if (action.CurPkg.Item.PKG_LEVEL == 1)
            {
                list.Add(CurSN);
            }
            else
            {
                list = action.GetMinPackageList(action.CurPkg.Item).Select(q => q.SN).ToList();
            }
            return list;
        }
        /// <summary>
        /// 获取白盒条码
        /// </summary>
        /// <param name="action"></param>
@@ -645,10 +712,12 @@
        /// <returns></returns>
        private string GetCardOrBoxQR(string code, List<BAS_LABEL_VAR> lvars, PackingAction action)
        {
            var itemCode = WorkBatch.Product.CUST_PROD_CODE;
            var minPkgList = action.GetMinPackageList(action.CurPkg.Item).Select(q => q.SN);
            var wo = WorkBatch.Batch.ORDER_NO;
            var snList = string.Join("\r\n", action.GetMinPackageList(action.CurPkg.Item).Select(q => q.SN));
            var snList = string.Join("\r\n", minPkgList);
            if (snList.IsNullOrEmpty()) { snList = $"{CurSN}"; }
            var _sn = minPkgList.FirstOrDefault() ?? CurSN;
            var itemCode = Biz.Db.Queryable<MES_CUST_SN>().Where(q => q.FLOW_SN == _sn || q.CUST_CODE == _sn).First()?.ITEM_CODE;
            var weight = action.CurPkg.WeightInfo.Weight;
            var unit = action.CurPkg.WeightInfo.Unit.ToUpper();
            var model = WorkBatch.Product.ExtInfo.Model;
@@ -699,9 +768,9 @@
                case 1:
                    return weeks.First();
                case 2:
                    return string.Join("/", weeks.Select(q => q + $"({dic.Count(d => d.Value == q)})"));
                    return string.Join("、", weeks.Select(q => q + $"({dic.Count(d => d.Value == q)}PCS)"));
                default:
                    return string.Join("/", weeks.Take(2)) + " (+)";
                    return string.Join("、", weeks.Take(2)) + " (+)";
            }
        }
        #endregion
@@ -715,5 +784,6 @@
            this.IsFinished = true;
            return IsFinished ? base.Close(needSaveHistoryLog) : IsFinished;
        }
    }//endClass
}