服务端的TigerApi 框架,基于.NET6 2024 版本
Ben Lin
2024-12-31 3586cc81669e86578ae69d69873c7844874d6ad1
Tiger.Business.MES/BIZ/BIZ_MES_WO.cs
@@ -20,6 +20,7 @@
using Tiger.Model.MES.Yada;
using static Microsoft.CodeAnalysis.CSharp.SyntaxTokenParser;
using Tiger.Model.Minsun;
using Tiger.Model.Entitys.MES.U9C;
namespace Tiger.Business.MES
{
@@ -131,20 +132,30 @@
                    return result;
                }
                var batchs = await Biz.Db.Queryable<BIZ_MES_WO_BATCH>().Where(x => x.ORDER_NO == input.Wo.ORDER_NO).ToListAsync();
                if ((batchs.Count > 0 && batchs.Sum(x => x.PLAN_QTY) + input.WoBatch.PLAN_QTY > _wo.PLAN_QTY) || input.WoBatch.PLAN_QTY > _wo.PLAN_QTY)
                if (batchs.Count > 0)
                {
                    result.IsSuccessed = false;
                    result.LocaleMsg = new($"工单下发的数量超过工单计划数量,不能下发!");
                    return result;
                }
                var _batch = Biz.Db.Queryable<BIZ_MES_WO_BATCH>().Where(x => x.ORDER_NO == input.Wo.ORDER_NO && x.ACT_LINE == input.WoBatch.ACT_LINE && x.STATUS < BIZ_MES_WO.STATUSs.Closed.GetValue()).First();
                if (_batch != null)
                {
                    result.IsSuccessed = false;
                    result.LocaleMsg = new($"工单[{input.Wo.ORDER_NO}]已经存在工单批次[{_batch.BATCH_NO}]在线体[{input.WoBatch.ACT_LINE}]中状态为[{_batch.STATUS.GetEnumDesc<BIZ_MES_WO.STATUSs>()}],不能下发!");
                    return result;
                    if ((batchs.Sum(x => x.PLAN_QTY) + input.WoBatch.PLAN_QTY > _wo.PLAN_QTY) || input.WoBatch.PLAN_QTY > _wo.PLAN_QTY)
                    {
                        result.IsSuccessed = false;
                        result.LocaleMsg = new($"工单下发的数量超过工单计划数量,不能下发!");
                        return result;
                    }
                    if (batchs.Any(x => x.ORDER_NO == input.Wo.ORDER_NO && x.ACT_LINE == input.WoBatch.ACT_LINE && x.STATUS < BIZ_MES_WO.STATUSs.Closed.GetValue()))
                    {
                        result.IsSuccessed = false;
                        result.LocaleMsg = new($"工单[{input.Wo.ORDER_NO}]已经有批次存在线体[{input.WoBatch.ACT_LINE}]中,而且状态不为关闭,不能下发!");
                        return result;
                    }
                    if (batchs.Any(x => x.ORDER_NO == input.Wo.ORDER_NO && x.STATUS == BIZ_MES_WO.STATUSs.Init.GetValue() && SqlFunc.DateIsSame(x.PLAN_DATE, DateTime.Now)))
                    {
                        result.IsSuccessed = false;
                        result.LocaleMsg = new($"工单[{input.Wo.ORDER_NO}]已经有批次存在计划日期相同,而且状态为[初始化],请转到工单批次中下发!");
                        return result;
                    }
                }
                //WoContext.RemoveBatch(input.WoBatch.BATCH_NO);
                input.WoBatch.PLAN_DATE = DateTime.Now;
                input.Wo.PLAN_DATE += input.Wo.PLAN_DATE.Contains(input.WoBatch.PLAN_DATE.ToString("yyyy-MM-dd")) ? "" : $",{input.WoBatch.PLAN_DATE.ToString("yyyy-MM-dd")}";
                input.Wo.ACT_LINE = input.WoBatch.ACT_LINE;
                input.Wo.RELEASE_TIME = DateTime.Now;
                input.Wo.RELEASE_USER = input.WoBatch.UPDATE_USER;
@@ -166,7 +177,7 @@
                       .WhereColumns(t => new { t.ORDER_NO, t.GHOST_ROW })
                       .ToStorage();
                    y.AsInsertable.ExecuteCommand();
                    y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
                    y.AsUpdateable.IgnoreColumns(x => x.ID).UpdateColumns(q=>new { q.PLAN_DATE,q.ACT_LINE,q.RELEASE_TIME,q.RELEASE_USER,q.UPDATE_TIME,q.UPDATE_USER}).ExecuteCommand();
                    db.Insertable(input.WoBatch).ExecuteCommand();
                });
@@ -186,7 +197,6 @@
                            pars[1].Direction = System.Data.ParameterDirection.Output;
                            pars[2].Direction = System.Data.ParameterDirection.Output;
                            Biz.Db.Ado.UseStoredProcedure().ExecuteCommand("SP_MES_WO2CUST", pars);
                            //response.LocaleMsg = new(pars[2].Value.ToString());
                            if (pars[1].Value.ToInt32() == 0)
                            {
                                Logger.Default.Info($"工单[{input.Wo.ORDER_NO}]下发完成后保存工艺路线数据到产品[{input.Wo.ITEM_CODE}]的客户[{input.Wo.CUST_CODE ?? ""}]的工艺路线中,{pars[2].Value.ToString()}");
@@ -292,6 +302,14 @@
                        _woBatch.ACT_LINE = input.ActLine;
                        _woBatch.CHANGE_USER = input.UserId;
                        _woBatch.CHANGE_TIME = DateTime.Now;
                        _wo.STATUS = BIZ_MES_WO.STATUSs.Release.GetValue();
                    }
                    else
                    {
                        if (input.Status == BIZ_MES_WO_BATCH.STATUSs.Init.GetValue() && !Biz.Db.Queryable<BIZ_MES_WO_BATCH>().Where(x => x.ORDER_NO == input.WorkOrder && x.BATCH_NO != input.WoBatch && x.STATUS > BIZ_MES_WO_BATCH.STATUSs.Init.GetValue()).Any())
                        {
                            _wo.STATUS = BIZ_MES_WO.STATUSs.Init.GetValue();
                        }
                    }
                }
                else
@@ -312,6 +330,10 @@
                    else
                    {
                        db.Updateable(_woBatch, input.UserId).UpdateColumns(x => new { x.STATUS, x.UPDATE_USER, x.UPDATE_TIME, x.CHANGE_USER, x.CHANGE_TIME }).ExecuteCommand();
                    }
                    if (!_wo.IsNullOrEmpty())
                    {
                        db.Updateable(_wo, input.UserId).UpdateColumns(x => new { x.STATUS, x.UPDATE_USER, x.UPDATE_TIME }).ExecuteCommand();
                    }
                });
                if (!dbTran.IsSuccess)
@@ -586,7 +608,7 @@
                //如果查不到就去行为日志查
                if (labelPrint.IsNullOrEmpty() && input.ReqType == 1)
                {
                    printParam = Biz.Db.Queryable<MES_WIP_ACT>().Where(q => q.CARTON_SN.Equals(woSn.OUTER_SN) && q.ACT_VALUE_4 == "Customer").First()?.ACT_VALUE_3 ?? "";
                    printParam = Biz.Db.Queryable<MES_WIP_ACT>().Where(q => q.CARTON_SN.Equals(woSn.OUTER_SN) && q.ACT_VALUE_4 == "Customer" && !SqlFunc.IsNullOrEmpty(q.ACT_VALUE_3)).First()?.ACT_VALUE_3 ?? "";
                }
                else if (labelPrint.IsNullOrEmpty() && input.ReqType == 2)
                {
@@ -631,12 +653,12 @@
                    result.Data = ship.BusinessDate.Date == DateTime.Now.Date ? new()
                    {
                        ShipDoc = ship.ShipDoc,
                        ShippingQty = ship.ShipQty,
                        ShippingQty = ship.ShipQty.ToDouble(),
                        Tag = "Customer"
                    } : new()
                    {
                        ShipDoc = ship.ShipDoc,
                        ShippingQty = ship.ShipQty,
                        ShippingQty = ship.ShipQty.ToDouble(),
                        Tag = "InStoreLabel"
                    };
                    result.LocaleMsg = new($"出货信息存在!");
@@ -703,40 +725,37 @@
            try
            {
                //得到工单条码记录
                var woSns = await Biz.Db.Queryable<BIZ_MES_WO_SN>().Where(q => q.OUTER_SN == code).ToListAsync();
                var cartonSn = code.Split('|')[0];
                var woSns = await Biz.Db.Queryable<BIZ_MES_WO_SN>().Where(q => q.OUTER_SN == cartonSn).ToListAsync();
                if (woSns.Count == 0)
                {
                    result.IsSuccessed = false;
                    result.LocaleMsg = new($"条码不存在!");
                    return result;
                }
                var wo = await Biz.Db.Queryable<BIZ_MES_WO>().Where(q => q.ORDER_NO == woSns[0].WORK_ORDER ).IncludesAllFirstLayer().FirstAsync();
                var wo = await Biz.Db.Queryable<BIZ_MES_WO>().Where(q => q.ORDER_NO == woSns[0].WORK_ORDER ).IncludesAllFirstLayer().IncludesAllSecondLayer(q => q._ItemInfos).FirstAsync();
                if (wo == null)
                {
                    result.IsSuccessed = false;
                    result.LocaleMsg = new($"条码对应的工单不存在");
                    return result;
                }
                //判断工单是否已经全部入库
                InStoreInfo inStoreInfo = new() {
                    ErpProdInBth= new() { 
                        WORK_ORDER = wo.ORDER_NO,
                        BATCH_NO = woSns[0].BATCH_NO,
                        ITEM_CODE = wo.ITEM_CODE,
                        ITEM_NAME = wo.ItemInfo?.ITEM_DESC,
                        SCAN_QTY = woSns.Count
                    },
                    ProdInBatch = new()
                    {
                        WORK_ORDER = wo.ORDER_NO,
                        SALES_ORDER = wo.SALES_ORDER,
                        BATCH_NO = woSns[0].BATCH_NO,
                        ITEM_CODE = wo.ITEM_CODE,
                        ITEM_NAME = wo.ItemInfo?.ITEM_DESC,
                        PLAN_QTY = wo.PLAN_QTY,
                        SCAN_QTY = woSns.Count
                        SapCode = wo.ItemInfo?.ExtInfo?.SapCode,
                        SCAN_QTY = woSns.Count,
                        IS_HANDLED = "N" //Y-已生成,N-未生成,F-失败
                    },
                    InStoreScanInfo = new() { 
                        SN = code,
                        SN = cartonSn,
                        SALES_ORDER = wo.SALES_ORDER,
                        WORK_ORDER = wo.ORDER_NO,
                        BATCH_NO = woSns[0].BATCH_NO,
@@ -752,5 +771,28 @@
            }
            return result;
        }
        #region 提交前通用方法
        /// <summary>
        /// 提交前检查是否岗位、工单和不良代码
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public async Task<ApiAction<CheckCodeOutput>> CheckCode(string code)
        {
            var action = new ApiAction<CheckCodeOutput>($"检查条码{code}成功", new CheckCodeOutput());
            try
            {
                action.Data.Position = DbCache.Cache.Position[code];
                action.Data.WorkOrder = await Biz.Db.Queryable<BIZ_MES_WO>().Where(q => q.ORDER_NO == code).FirstAsync();
                action.Data.Defect = DbCache.Cache.Defect[code];
            }
            catch (Exception ex)
            {
                action.CatchExceptionWithLog(ex, $"检查条码{code}异常");
            }
            return action;
        }
        #endregion
    }
}