服务端的TigerApi 框架,基于.NET6 2024 版本
Ben Lin
2024-11-06 a96e763c96401cbc7695acbcd6b18770d8aedf8d
Tiger.Business.MES/BIZ/BIZ_MES_WO.cs
@@ -18,6 +18,7 @@
using System.Drawing.Printing;
using System.Net.NetworkInformation;
using Tiger.Model.MES.Yada;
using static Microsoft.CodeAnalysis.CSharp.SyntaxTokenParser;
namespace Tiger.Business.MES
{
@@ -453,28 +454,139 @@
        }
        /// <summary>
        /// 获取重打标签信息
        /// 更新行为中的箱号
        /// </summary>
        /// <param name="input"></param>
        /// <param name="code"></param>
        /// <returns></returns>
        public async Task<ApiAction<LOG_LABEL_PRINT>> GetRePrintInfo(RePrintInput input)
        public async Task<ApiAction> SavePrintLabelInAct(string code)
        {
            var result = new ApiAction<LOG_LABEL_PRINT>();
            var result = new ApiAction();
            try
            {
                //先查出工单条码中是否存在
                var woSn = await Biz.Db.Queryable<BIZ_MES_WO_SN>().Where(q => q.SN.Equals(input.Code) || q.FLOW_SN.Equals(input.Code)).FirstAsync();
                var woSn = await Biz.Db.Queryable<BIZ_MES_WO_SN>().Where(q=>q.SN == code || q.FLOW_SN == code || q.OUTER_SN == code).FirstAsync();
                if (woSn == null)
                {
                    result.IsSuccessed = false;
                    result.LocaleMsg = new($"条码不存在!");
                    return result;
                }
                //取得包装列表
                var pkgList = Biz.Db.Queryable<MES_WIP_PKG>().Where(q => q.PARENT_SN == woSn.OUTER_SN && q.OPER_CODE == "SpecPackingNode").ToList();
                if (pkgList.Count == 0)
                {
                    result.IsSuccessed = false;
                    result.LocaleMsg = new($"条码不存在!");
                    return result;
                }
                List<MES_WIP_ACT> actlist = new List<MES_WIP_ACT>();
                //客户标签
                var wipAct = Biz.Db.Queryable<MES_WIP_ACT>().Where(q => q.CARTON_SN == woSn.OUTER_SN && q.NODE_ID == pkgList[0].NODE_ID && !SqlFunc.IsNullOrEmpty(q.ACT_VALUE_3)).First();
                if (!wipAct.IsNullOrEmpty())
                {
                    var label = JsonConvert.DeserializeObject<BAS_LABEL_TEMP>(wipAct.ACT_VALUE_3);
                    var cardNo = label.Variables.Where(q => q.VAR_NAME == "CardQR").FirstOrDefault();
                    if (!woSn.OUTER_SN.IsNullOrEmpty() && !cardNo.IsNullOrEmpty() && !cardNo.Value.StartsWith(woSn.OUTER_SN))
                    {
                        cardNo.Value = $"{woSn.OUTER_SN}{cardNo.Value}";
                    }
                    string ACT_VALUE_3 = JsonConvert.SerializeObject(label);
                    foreach (var pkg in pkgList)
                    {
                        var actSn = Biz.Db.Queryable<MES_WIP_ACT>().Where(q => q.WIP_ID == pkg.WIP_ID && q.NODE_ID == pkg.NODE_ID && q.ACT_VALUE_4 == "Customer").First();
                        if (!actSn.IsNullOrEmpty())
                        {
                            actSn.ACT_VALUE_3 = ACT_VALUE_3;
                            actlist.Add(actSn);
                        }
                    }
                }
                //入库标签
                var wipActInStore = Biz.Db.Queryable<MES_WIP_ACT>().Where(q => q.SN == woSn.SN && q.NODE_ID == pkgList[0].NODE_ID && !SqlFunc.IsNullOrEmpty(q.ACT_VALUE_3) && q.ACT_VALUE_4 == "InStroe").First();
                if (!wipActInStore.IsNullOrEmpty())
                {
                    var label = JsonConvert.DeserializeObject<BAS_LABEL_TEMP>(wipActInStore.ACT_VALUE_3);
                    var cardNo = label.Variables.Where(q => q.VAR_NAME == "CardQR").FirstOrDefault();
                    if (!woSn.OUTER_SN.IsNullOrEmpty() && !cardNo.IsNullOrEmpty() && !cardNo.Value.StartsWith(woSn.OUTER_SN))
                    {
                        cardNo.Value = $"{woSn.OUTER_SN}{cardNo.Value}";
                    }
                    var xh = label.Variables.Where(q => q.VAR_NAME == "XH").FirstOrDefault();
                    if (!woSn.OUTER_SN.IsNullOrEmpty() && !xh.IsNullOrEmpty())
                    {
                        xh.Value = $"{woSn.OUTER_SN}";
                    }
                    string ACT_VALUE_3 = JsonConvert.SerializeObject(label);
                    foreach (var pkg in pkgList)
                    {
                        var actSn = Biz.Db.Queryable<MES_WIP_ACT>().Where(q => q.WIP_ID == pkg.WIP_ID && q.NODE_ID == pkg.NODE_ID && q.ACT_VALUE_4 == "InStroe").First();
                        if (!actSn.IsNullOrEmpty())
                        {
                            actSn.ACT_VALUE_3 = ACT_VALUE_3;
                            actlist.Add(actSn);
                        }
                    }
                }
                var db = Biz.Db;
                var dbTran = db.UseTran(() =>
                {
                    db.Updateable(actlist).UpdateColumns(q => new { q.ACT_VALUE_3 }).ExecuteCommand();
                });
                if (!dbTran.IsSuccess)
                {
                    result.IsSuccessed = false;
                    result.LocaleMsg = new($"更新行为日志中的箱号异常");
                }
            }
            catch (Exception ex)
            {
                result.CatchExceptionWithLog(ex, "更新行为日志中的箱号异常");
            }
            return result;
        }
                result.Data = await Biz.Db.Queryable<LOG_LABEL_PRINT>()
        /// <summary>
        /// 获取重打标签信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task<ApiAction> GetRePrintInfo(RePrintInput input)
        {
            var result = new ApiAction();
            try
            {
                //先查出工单条码中是否存在
                var outerSn = input.Code.Split('|')[0];
                var woSn = await Biz.Db.Queryable<BIZ_MES_WO_SN>().Where(q => q.SN.Equals(input.Code) || q.FLOW_SN.Equals(input.Code) || q.OUTER_SN == outerSn).FirstAsync();
                if (woSn == null)
                {
                    result.IsSuccessed = false;
                    result.LocaleMsg = new($"条码不存在!");
                    return result;
                }
                var woNode = await Biz.Db.Queryable<MES_WO_NODE>().Where(q => q.WORK_ORDER.Equals(woSn.WORK_ORDER) && q.OPER_CODE== "SpecPackingNode").FirstAsync();
                if (woNode == null)
                {
                    result.IsSuccessed = false;
                    result.LocaleMsg = new($"工艺路线节点[SpecPackingNode-装箱]不存在");
                    return result;
                }
                string printParam = "";
                var labelPrint = await Biz.Db.Queryable<LOG_LABEL_PRINT>()
                    .WhereIF(input.ReqType == 0, q => q.SN.Equals(woSn.SN) || q.SN.Equals(woSn.FLOW_SN)) //白盒标签
                    .WhereIF(input.ReqType == 1, q => q.SN.Equals(woSn.OUTER_SN)) //箱标签
                    .WhereIF(input.ReqType == 1, q => q.SN.Equals(woSn.OUTER_SN) && q.PRINT_LABEL != "InStoreLabel") //箱标签-客户
                    .WhereIF(input.ReqType == 2, q => q.SN.Equals(woSn.OUTER_SN) && q.PRINT_LABEL == "InStoreLabel") //箱标签-入库
                    .FirstAsync();
                //如果查不到就去行为日志查
                if (labelPrint.IsNullOrEmpty() && input.ReqType == 1)
                {
                    printParam = Biz.Db.Queryable<MES_WIP_ACT>().Where(q => (q.SN.Equals(input.Code) || q.FLOW_SN.Equals(input.Code)) && q.ACT_VALUE_4 == "Customer").First()?.ACT_VALUE_3 ?? "";
                }
                else
                {
                    printParam = labelPrint.PRINT_PARAM;
                }
                result.Data = printParam;
                result.LocaleMsg = new($"重打条码[{input.Code}]的标签成功");
            }
            catch (Exception ex)
            {
@@ -495,14 +607,15 @@
            {
                DbClient db = Biz.DataSource["YadaU9C"].Client;
                var org = await Biz.Db.Queryable<SYS_ORGANIZATION>().Where(q=>q.ORG_CODE == orgCode).FirstAsync();
                if (db.Queryable<mes_ShipList>().Any(q => q.MoDoc.Equals(wo) && SqlFunc.DateIsSame(q.BusinessDate, DateTime.Now) && q.Status == 2 && q.Org == org.ID.ToInt64()))
                var shipList = db.Queryable<mes_ShipList>().Where(q => q.MoDoc.Equals(wo) && SqlFunc.DateIsSame(q.BusinessDate, DateTime.Now) && q.Status == 2 && q.Org == org.ID.ToInt64()).ToList();
                if (shipList.Any())
                {
                    result.Data = "Customer";
                    result.Data = shipList[0].ShipQty;
                    result.LocaleMsg = new($"出货信息存在!");
                }
                else
                {
                    result.LocaleMsg = new($"出货信息存在!");
                    result.Data = "InStore";
                    result.Data = "InStoreLabel";
                }
            }
            catch (Exception ex)
@@ -511,5 +624,33 @@
            }
            return result;
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="SN"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public async Task<ApiAction> UnbindWipSnFromWO(UnbindWipSnInput input)
        {
            var result = new ApiAction();
            try
            {
                var cartonSn = input.SN.Split('|')[0];
                var wipList = await Biz.Db.Queryable<MES_WIP_DATA>().Where(q => q.SN.Equals(input.SN) || q.FLOW_SN.Equals(input.SN) || q.CARTON_SN == cartonSn).ToListAsync();
                if (wipList.Count == 0)
                {
                    result.IsSuccessed = false;
                    result.LocaleMsg = new($"解绑的条码不存在当前操作表中!");
                }
                var wo = await Biz.Db.Queryable<BIZ_MES_WO>().Where(q => q.ORDER_NO == wipList[0].WORK_ORDER).FirstAsync();
                result = WorkBatch.UnbindWipSnFromWO(wo, wipList, input.user);
            }
            catch (Exception ex)
            {
                result.CatchExceptionWithLog(ex, "解绑条码异常");
            }
            return result;
        }
    }
}