服务端的TigerApi 框架,基于.NET6 2024 版本
Rodney Chen
2024-11-28 d0fe891cac88bbd5087a0ee90a41421bbf0ec5c5
优化了一些已知问题
已修改3个文件
已添加1个文件
163 ■■■■ 文件已修改
Tiger.Api/Program.cs 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Tiger.Business.MES/Transaction/YadaPacking.cs 47 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Tiger.Model.Net/Base/TraceDebug.cs 112 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Tiger.Model.Net/Tiger.Model.Net.csproj 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Tiger.Api/Program.cs
@@ -17,7 +17,7 @@
using Autofac;
using Tiger.IBusiness;
var begin = DateTime.Now;
try
{
    //非UI线程未捕获异常处理事件
@@ -95,6 +95,7 @@
    // Call Configure(), passing in the dependencies
    startup.Configure(app, app.Environment);
    Logger.Console.Info($"Run {prod} Successful");
    Logger.Console.Info($"Total Elapsed Time: {(DateTime.Now - begin).TotalSeconds:0.000} seconds");
    
    app.Run();
    Logger.Console.Info($"{prod} Host is shut down");
Tiger.Business.MES/Transaction/YadaPacking.cs
@@ -13,6 +13,7 @@
using Tiger.Business.MES.WorkAction;
using Tiger.Model.MES.Yada;
using System.Data;
using System.Diagnostics;
namespace Tiger.Business.MES.Transaction
{
@@ -40,10 +41,10 @@
        public PackingAction TempPkgAction { get; set; }
        public bool IsPrintCustomerLabel { get; set; }
        public string ShippingOrder { get; set; }
        public DbClient U9CDB { get; set; }
        public Model.TraceDebug debug { get; set; }
        public DateTime curtime = DateTime.Now;
        public DateTime prevtime = DateTime.Now;
        public DbClient U9CDB { get; set; }
        #endregion Propertys & Variables
        #region Functions
@@ -54,7 +55,8 @@
        /// <returns></returns>
        public async Task<ApiAction<SubmitOutput>> Submit(SubmitInput input)
        {
            curtime = prevtime = DateTime.Now; Logger.Console.Info($"{CurSN} : ***** 1 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime;
            debug = new(new StackFrame(true));
            debug.Log(new StackFrame(true), "***** 1", info => { ConsoleExt.WriteLine(info.ToString()); });
            var action = new ApiAction<SubmitOutput>(new SubmitOutput());
            try
            {
@@ -97,13 +99,13 @@
                        var wosns = MainDB.Queryable<BIZ_MES_WO_BATCH, BIZ_MES_WO_SN>((q, s) => new JoinQueryInfos(JoinType.Inner, q.ORDER_NO == s.WORK_ORDER && q.BATCH_NO == s.BATCH_NO))
                                                .ByAuth(input.AuthOption)//.Where((q, s) => s.STATUS < BIZ_MES_WO_SN.STATUSs.Finished.GetValue())
                                                .Where((q, s) => s.SN == input.SN || s.FLOW_SN == input.SN || s.TRAY_SN == input.SN).Select((q, s) => new { Batch = q, SN = s }).ToList();
                        curtime = DateTime.Now;  Logger.Console.Info($"{CurSN} : ***** 2 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime;
                        debug.Log(new StackFrame(true), "***** 2", info => { ConsoleExt.WriteLine(info.ToString()); });
                        //先判断当前工单不为空且当前岗位在当前工单是不是首站,如果是则不允许变更当前工单,尝试把条码绑定到当前工单
                        if (!CurBatch.IsNullOrEmpty() && CurBatch.IsFirstNode(PostCode))
                        {
                            //更新CurBatch
                            CurBatch?.Update();
                            curtime = DateTime.Now;  Logger.Console.Info($"{CurSN} : ***** 3 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime;
                            debug.Log(new StackFrame(true), "***** 3", info => { ConsoleExt.WriteLine(info.ToString()); });
                            var wosn = wosns.FirstOrDefault(q => q.Batch.ORDER_NO == CurBatch.WO.ORDER_NO && (q.SN.STATUS == BIZ_MES_WO_SN.STATUSs.Finished.GetValue() || q.SN.STATUS == BIZ_MES_WO_SN.STATUSs.Scrap.GetValue()));
                            if (!wosn.IsNullOrEmpty())
                            {
@@ -117,7 +119,7 @@
                            {
                                //提交数据
                                action = NodeSubmit(action, input);
                                curtime = DateTime.Now;  Logger.Console.Info($"{CurSN} : ***** 4 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime;
                                debug.Log(new StackFrame(true), "***** 4", info => { ConsoleExt.WriteLine(info.ToString()); });
                                //更新工序信息
                                if (!action.IsSuccessed)
                                {
@@ -238,23 +240,23 @@
                    {
                        //更新CurBatch
                        CurBatch?.Update();
                        curtime = DateTime.Now;  Logger.Console.Info($"{CurSN} : ***** 5 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime;
                        debug.Log(new StackFrame(true), "***** 5", info => { ConsoleExt.WriteLine(info.ToString()); });
                        var submitStep = Steps.Where(q => q.ID == input.CurStepID && !q.IsFinished).FirstOrDefault();
                        //如果客户端返回的当前工步ID找不到未完成的行为工步,则直接开始下一个行为工步
                        if (submitStep.IsNullOrEmpty())
                        {
                            action = BeginNextActionStep(input);
                            curtime = DateTime.Now;  Logger.Console.Info($"{CurSN} : ***** 6 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime;
                            debug.Log(new StackFrame(true), "***** 6", info => { ConsoleExt.WriteLine(info.ToString()); });
                        }
                        else
                        {
                            action = submitStep.Submit(input);
                            curtime = DateTime.Now;  Logger.Console.Info($"{CurSN} : ***** 7 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime;
                            debug.Log(new StackFrame(true), "***** 7", info => { ConsoleExt.WriteLine(info.ToString()); });
                            //如果当前工步已完成,开始执行下一工步
                            if (action.IsSuccessed && submitStep.IsFinished)
                            {
                                action = BeginNextActionStep(input);
                                curtime = DateTime.Now;  Logger.Console.Info($"{CurSN} : ***** 8 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime;
                                debug.Log(new StackFrame(true), "***** 8", info => { ConsoleExt.WriteLine(info.ToString()); });
                            }
                            //如果当前工步未完成
                            else
@@ -299,7 +301,7 @@
                //action.CatchExceptionWithLog(ex, $"包装工序:提交操作数据异常");
                action.CatchExceptionWithLog(ex, Biz.L("MES.Transaction.PackingNode.SubmitException"));
            }
            curtime = DateTime.Now;  Logger.Console.Info($"{CurSN} : ***** 9 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime;
            debug.Log(new StackFrame(true), "***** 9", info => { ConsoleExt.WriteLine(info.ToString()); });
            return SetOutPutMqttMsg(action, input.Locale);
        }
@@ -311,7 +313,7 @@
        /// <returns></returns>
        public ApiAction<SubmitOutput> NodeSubmit(ApiAction<SubmitOutput> action, SubmitInput input)
        {
            curtime = DateTime.Now;  Logger.Console.Info($"{CurSN} : ***** 10 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime;
            debug.Log(new StackFrame(true), "***** 10", info => { ConsoleExt.WriteLine(info.ToString()); });
            var curNode = CurBatch.GetNode(PostCode);
            try
            {
@@ -395,14 +397,15 @@
                    //设置当前指令为正常产品过站
                    NodeCmd = "NodeSubmit";
                    curtime = DateTime.Now;  Logger.Console.Info($"{CurSN} : ***** 11 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime;
                    debug.Log(new StackFrame(true), "***** 11", info => { ConsoleExt.WriteLine(info.ToString()); });
                    //获取出货状态
                    var ship = U9CDB.Queryable<mes_ShipList>().Where(q => q.MoDoc == CurBatch.WO.ORDER_NO && q.Status == 2 && SqlFunc.DateIsSame(q.BusinessDate, DateTime.Now)).First();
                    int CurShipQty = 0;
                    int WaitShipmentCarton = 0;
                    int WaitShipment = 0;
                    if (ship.IsNullOrEmpty()) { IsPrintCustomerLabel = false; } else
                    if (ship.IsNullOrEmpty()) { IsPrintCustomerLabel = false; }
                    else
                    {
                        CurShipQty = ship.ShipQty;
                        IsPrintCustomerLabel = true;
@@ -439,7 +442,7 @@
                    //    Context.Add("CurWaitShipmentCarton", WaitShipmentCarton);
                    //}
                    curtime = DateTime.Now;  Logger.Console.Info($"{CurSN} : ***** 12 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime;
                    debug.Log(new StackFrame(true), "***** 12", info => { ConsoleExt.WriteLine(info.ToString()); });
                    //绑定条码到工单
                    foreach (var wipSN in wipSNs)
                    {
@@ -583,7 +586,7 @@
                    var _curNodeSetting = curNodeSetting.Clone();
                    var _Batch = CurBatch.Batch.Clone();
                    curtime = DateTime.Now;  Logger.Console.Info($"{CurSN} : ***** 13 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime;
                    debug.Log(new StackFrame(true), "***** 13", info => { ConsoleExt.WriteLine(info.ToString()); });
                    //初始化工步列表
                    Steps.Clear();
                    var curStep = new WorkStep(IWorkStep.NodeTypes.Node, this)
@@ -707,7 +710,7 @@
                //action.CatchExceptionWithLog(ex, $"{curNode.NODE_NAME}:工序节点工步提交数据异常,请检查工序节点设置");
                action.CatchExceptionWithLog(ex, Biz.L("MES.Transaction.PackingNode.NodeSubmitException", curNode.NODE_NAME));
            }
            curtime = DateTime.Now;  Logger.Console.Info($"{CurSN} : ***** 13.1 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime;
            debug.Log(new StackFrame(true), "***** 13.1", info => { ConsoleExt.WriteLine(info.ToString()); });
            return action;
        }
@@ -721,7 +724,7 @@
            var curPkg = Context.ContainsKey("CurPackage") ? Context["CurPackage"] as WipPkg : null;
            var operInfo = SetOperNodeInfo(CurOperInfo(locale));
            Action endAction = null;
            curtime = DateTime.Now;  Logger.Console.Info($"{CurSN} : ***** 14 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime;
            debug.Log(new StackFrame(true), "***** 14", info => { ConsoleExt.WriteLine(info.ToString()); });
            //如果当前条码已经走到流程终点则记录条码完工
            if (operInfo.IsReachedEndNode)
@@ -806,7 +809,7 @@
            //重置工序
            ResetNode();
            curtime = DateTime.Now; Logger.Console.Info($"{CurSN} : ***** 15 : {(curtime - prevtime).TotalSeconds}s", ConsoleColor.Green); prevtime = curtime;
            debug.Log(new StackFrame(true), "***** 15", info => { ConsoleExt.WriteLine(info.ToString()); });
            return action;
        }
@@ -979,9 +982,11 @@
            var action = new ApiAction<ShipingInfo>();
            try
            {
                action.Data = new ShipingInfo() {
                action.Data = new ShipingInfo()
                {
                    IsPrintCustomerLabel= IsPrintCustomerLabel,
                    ShipQty =Context.GetOrDefault("CurWaitShipment").ToInt32()>= Context.GetOrDefault("CurShipQty").ToInt32()? CurBatch.Batch.PLAN_QTY - Context.GetOrDefault("CurShipQty").ToInt32(): Context.GetOrDefault("CurShipQty").ToInt32() };
                    ShipQty = Context.GetOrDefault("CurWaitShipment").ToInt32() >= Context.GetOrDefault("CurShipQty").ToInt32() ? CurBatch.Batch.PLAN_QTY - Context.GetOrDefault("CurShipQty").ToInt32() : Context.GetOrDefault("CurShipQty").ToInt32()
                };
            }
            catch (Exception ex)
            {
Tiger.Model.Net/Base/TraceDebug.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,112 @@
using SqlSugar.DbConvert;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using static Tiger.Model.MQTT;
namespace Tiger.Model
{
    /// <summary>
    /// è°ƒè¯•
    /// </summary>
    public class TraceDebug
    {
        public TraceDebug(StackFrame frame)
        {
            var info = new TraceInfo("Begin Trace");
            info.File = frame?.GetFileName();
            info.Function = frame?.GetMethod().DeclaringType.FullName + "." + frame?.GetMethod().Name;
            info.Line = frame?.GetFileLineNumber() ?? default;
            TraceInfos.Add(info);
        }
        public TraceDebug(StackFrame frame, string title) : this(frame)
        {
            Title = title;
        }
        /// <summary>
        /// è°ƒè¯•标题
        /// </summary>
        public string Title { get; set; } = "Trace Information";
        /// <summary>
        /// è°ƒè¯•信息列表
        /// </summary>
        public List<TraceInfo> TraceInfos { get; set; } = new List<TraceInfo>();
        /// <summary>
        /// å¼€å§‹è®°å½•æ—¶é—´
        /// </summary>
        public DateTime BeginTime { get; set; } = DateTime.Now;
        /// <summary>
        /// æŒç»­æ—¶é—´ï¼ˆç§’)
        /// </summary>
        public double Duration { get; set; } = 0;
        public override string ToString() => $"========== {Title} ==========\r\n{string.Join("\r\n", TraceInfos.Select(q => " " + q.ToString()))}\r\n========== Total Elapsed Time: {Duration:0.000}s ==========";
        public string ToDetailString() => $"========== {Title} ==========\r\n{string.Join("\r\n", TraceInfos.Select(q => " " + q.ToDetailString()))}\r\n========== Total Elapsed Time: {Duration:0.000}s ==========";
        /// <summary>
        /// æ·»åŠ è°ƒè¯•ä¿¡æ¯
        /// </summary>
        public TraceDebug Log(StackFrame frame, string msg, Action<TraceInfo> doSomthing = null)
        {
            var f = new StackFrame(true);
            var info = new TraceInfo(msg);
            Duration = (info.ActionTime - BeginTime).TotalSeconds;
            info.File = frame?.GetFileName();
            info.Function = frame?.GetMethod().DeclaringType.FullName + "." + frame?.GetMethod().Name;
            info.Line = frame?.GetFileLineNumber() ?? default;
            info.Index = TraceInfos.Max(q => q.Index) + 1;
            info.Duration = (info.ActionTime - TraceInfos.Max(q => q.ActionTime)).TotalSeconds;
            //string w = null; w.ToString();
            TraceInfos.Add(info);
            doSomthing?.Invoke(info);
            return this;
        }
    }
    /// <summary>
    /// è°ƒè¯•信息
    /// </summary>
    public class TraceInfo
    {
        public TraceInfo()
        {
        }
        public TraceInfo(string message)
        {
            Message = message;
        }
        /// <summary>
        /// åºå·
        /// </summary>
        public int Index { get; set; } = 0;
        /// <summary>
        /// è°ƒè¯•文件
        /// </summary>
        public string File { get; set; } = "Anonymous";
        /// <summary>
        /// è°ƒè¯•方法
        /// </summary>
        public string Function { get; set; } = "Anonymous";
        /// <summary>
        /// è¡Œå·
        /// </summary>
        public int Line { get; set; } = 0;
        /// <summary>
        /// ä¿¡æ¯
        /// </summary>
        public string Message { get; set; }
        /// <summary>
        /// æ‰§è¡Œæ—¶é—´
        /// </summary>
        public DateTime ActionTime { get; set; } = DateTime.Now;
        /// <summary>
        /// æŒç»­æ—¶é—´ï¼ˆç§’)
        /// </summary>
        public double Duration { get; set; } = 0;
        public override string ToString() => $"{ActionTime:yyyy/MM/dd HH:mm:ss.fff} > Trace[{Index}](took {Duration:0.000}s) : {Message}.";
        public string ToDetailString() => $"{ActionTime:yyyy/MM/dd HH:mm:ss.fff} > Trace[{Index}](took {Duration:0.000}s) : {Message}.\r\n\tRun at {Function} in {File}:line {Line}";
    }
}
Tiger.Model.Net/Tiger.Model.Net.csproj
@@ -76,6 +76,7 @@
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Base\DbEntityBase.cs" />
    <Compile Include="Base\TraceDebug.cs" />
    <Compile Include="DTO\MESDTO.cs" />
    <Compile Include="Entitys\MQTTEntity.cs" />
    <Compile Include="Entitys\Api\Base.cs" />