服务端的TigerApi 框架,基于.NET6 2024 版本
Rodney Chen
2024-10-15 d0eb14b78b4d84c3e77a917da25e82750b4de335
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
{
@@ -96,12 +97,12 @@
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<ApiAction> SelectOrder(WoInput input)
        public async Task<ApiAction> SelectOrder(WoInput input, string batchNo = "")
        {
            var action = new ApiAction();
            try
            {
                if (!WoContext.ExistsBatch(input.OrderNo, CurLine.LINE_CODE))
                if (!WoContext.ExistsBatch(input.OrderNo, CurLine.LINE_CODE, batchNo, true))
                {
                    var wo = await Biz.Db.Queryable<BIZ_MES_WO>().ByAuth(input.AuthOption).Where(q => q.ORDER_NO == input.OrderNo).FirstAsync();
                    //验证明细是否正确
@@ -115,11 +116,14 @@
                    if (wo.STATUS != BIZ_MES_WO.STATUSs.Release.GetValue() && wo.STATUS != BIZ_MES_WO.STATUSs.Working.GetValue())
                    {
                        action.IsSuccessed = false;
                        //action.LocaleMsg = new($"工单[{input.OrderNo}]状态[{wo.STATUS.GetEnum<BIZ_MES_WO.STATUSs>().GetName()}]不能生产");
                        //action.LocaleMsg = new($"工单[{0}]状态[{1}]不能生产");
                        action.LocaleMsg = new("MES.Transaction.Position.SelectOrder.StatusException", input.OrderNo, wo.STATUS.GetEnum<BIZ_MES_WO.STATUSs>().GetName());
                        return action;
                    }
                    var batch = await Biz.Db.Queryable<BIZ_MES_WO_BATCH>().ByAuth(input.AuthOption).Where(q => q.ORDER_NO == input.OrderNo && q.ACT_LINE == CurLine.LINE_CODE).FirstAsync();
                    var batch = await Biz.Db.Queryable<BIZ_MES_WO_BATCH>().ByAuth(input.AuthOption)
                        .Where(q => q.ORDER_NO == input.OrderNo && q.ACT_LINE == CurLine.LINE_CODE)
                        .WhereIF(!batchNo.IsNullOrEmpty(), q => q.BATCH_NO == batchNo)
                        .OrderBy(q => q.STATUS).FirstAsync();
                    if (batch.IsNullOrEmpty())
                    {
                        action.IsSuccessed = false;
@@ -130,14 +134,14 @@
                    if (batch.STATUS != BIZ_MES_WO_BATCH.STATUSs.Release.GetValue() && batch.STATUS != BIZ_MES_WO_BATCH.STATUSs.Working.GetValue())
                    {
                        action.IsSuccessed = false;
                        //action.LocaleMsg = new($"工单[{input.OrderNo}]状态[{wo.STATUS.GetEnum<BIZ_MES_WO_BATCH.STATUSs>().GetName()}]不能生产");
                        action.LocaleMsg = new("MES.Transaction.Position.SelectOrder.StatusException", input.OrderNo, batch.STATUS.GetEnum<BIZ_MES_WO_BATCH.STATUSs>().GetName());
                        //action.LocaleMsg = new($"工单[{0}]批次[1]状态[{2}]不能生产");
                        action.LocaleMsg = new("MES.Transaction.Position.SelectOrder.BatchStatusException", input.OrderNo, batch.BATCH_NO, batch.STATUS.GetEnum<BIZ_MES_WO_BATCH.STATUSs>().GetName());
                        return action;
                    }
                    var wb = new WorkBatch(input.OrderNo).Init(CurLine.LINE_CODE);
                    WoContext.WoBatchDic.Add(wb.Batch.BATCH_NO, wb);
                }
                CurBatch = WoContext.GetBatch(input.OrderNo, CurLine.LINE_CODE);
                CurBatch = WoContext.GetBatch(input.OrderNo, CurLine.LINE_CODE, batchNo);
                if (!OperInfoDic.ContainsKey(CurBatch.Batch.BATCH_NO))
                {
                    OperInfoDic.Add(CurBatch.Batch.BATCH_NO, new());
@@ -221,7 +225,12 @@
            if (CurWipSNs.Any())
            {
                info.CurNode = CurWipSNs.First().NODE_NAME;
                info.NextNode = string.Join(",", CurBatch.GetNextNodes(CurWipSNs.First()).Select(q => q.NODE_NAME));
                var nextNodes = CurBatch.GetNextNodes(CurWipSNs.First());
                info.NextNode = string.Join(",", nextNodes.Select(q => q.NODE_NAME));
                if (nextNodes.Count == 1 && nextNodes.Single().OPER_CODE == "EndNode")
                {
                    info.IsReachedEndNode = true;
                }
            }
            else
            {
@@ -550,8 +559,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":
@@ -559,25 +578,29 @@
                                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":
                                    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);
                                    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, "");
                                default:
@@ -648,6 +671,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>
@@ -679,10 +720,11 @@
        /// <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 itemCode = Biz.Db.Queryable<MES_CUST_SN>().Where(q => q.FLOW_SN == CurWipSNs.First().FLOW_SN).First()?.ITEM_CODE;
            var weight = action.CurPkg.WeightInfo.Weight;
            var unit = action.CurPkg.WeightInfo.Unit.ToUpper();
            var model = WorkBatch.Product.ExtInfo.Model;
@@ -717,7 +759,7 @@
                    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}");
                    dic.Add(sn, $"{year.ToString("0000").Substring(2, 2)}{week:00}");
                }
                else
                {
@@ -733,12 +775,33 @@
                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
        #region 包装专用方法
        /// <summary>
        /// 根据传入的包装对象返回所有的包装实体列表
        /// </summary>
        /// <param name="parent"></param>
        /// <returns></returns>
        public List<MES_WIP_PKG> GetPackageList(WipPkgItem parent)
        {
            List<MES_WIP_PKG> list = new();
            if (!parent.Package.IsNullOrEmpty())
            {
                list.Add(parent.Package);
            }
            foreach (var item in parent.Items)
            {
                item.Package.PARENT_SN = parent.Package?.SN;
                list.AddRange(GetPackageList(item));
            }
            return list;
        }
        #endregion
        #endregion Functions
        public override bool Close(bool needSaveHistoryLog = false)