From 6295e95e558ab6e9da2e7ff860b6918cc6b414b6 Mon Sep 17 00:00:00 2001 From: Rodney Chen <rodney.chen@hotmail.com> Date: 星期六, 22 三月 2025 21:00:44 +0800 Subject: [PATCH] 优化了一些已知问题 --- Tiger.Api/Controllers/Test/TestController.R.cs | 210 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 186 insertions(+), 24 deletions(-) diff --git a/Tiger.Api/Controllers/Test/TestController.R.cs b/Tiger.Api/Controllers/Test/TestController.R.cs index b184f61..9e42073 100644 --- a/Tiger.Api/Controllers/Test/TestController.R.cs +++ b/Tiger.Api/Controllers/Test/TestController.R.cs @@ -21,6 +21,12 @@ using System.Net; using System.Reflection; using Swifter.Tools; +using Tiger.Model.Entitys.MES.Position; +using Microsoft.CodeAnalysis.Options; +using System.IO; +using System.Runtime.Loader; +using MailKit.Search; +using Tiger.Model.DigitalTwin; namespace Tiger.Api.Controllers.Test { @@ -62,9 +68,9 @@ public async Task<IActionResult> GetAsync(string param) { //var data = await Biz.Db.Queryable<SYS_PARAM>().Where(q => q.PARAM_CODE == param).FirstAsync(); - //var data = Biz.SysParam["Blue"]; - //var data = Biz.SysParam.Groups; - //var data = Biz.CodeRule["X0001"]; + //var data = Cache.SysParam["Blue"]; + //var data = Cache.SysParam.Groups; + //var data = Cache.CodeRule["X0001"]; //鍙栧彿娴嬭瘯 //var data = Biz.Db.Queryable<BAS_CODE_RULE>().Where(q => q.RULE_CODE == "X0001").IncludesAllFirstLayer().First(); //var key = string.Join("|", data.Details.Where(q => q.DATA_TYPE == BAS_CODE_DTL.DATA_TYPEs.DbCheck.GetValue()).Select(q => q.GenerateValue)); @@ -77,7 +83,7 @@ // try // { // var dtl = data.Details.First(q => q.RULE_SEQ == 6); - // var sn = Biz.CodeRule.FetchSerialNo(key, dtl, index.ToString(), false); + // var sn = Cache.CodeRule.FetchSerialNo(key, dtl, index.ToString(), false); // Console.WriteLine($"{index}: {DateTime.Now:HH:mm:ss.fff} > 鍙栧彿瀹屾垚[{sn}]"); // } // catch (Exception ex) @@ -86,14 +92,14 @@ // } // }); //} - //var data = Biz.CodeRule["X0001"].Generate("PDFG", 5); - //var data1 = Biz.CodeRule["X0001"].TryGenerate("PDFG", 6); + //var data = Cache.CodeRule["X0001"].Generate("PDFG", 5); + //var data1 = Cache.CodeRule["X0001"].TryGenerate("PDFG", 6); //鏉$爜瑙勫垯楠岃瘉 //Expression<Func<BAS_CODE_RULE, bool>> predicate = q => true; ////predicate = predicate.And(q => q.RULE_CODE == "X0002" || q.RULE_CODE == "X0001"); //predicate = predicate.And(q => q.RULE_TYPE == 0); - ////var data = Biz.CodeRule.Rules.Where(predicate.Compile()); - //var data = Biz.CodeRule.Verify("AB23#7930000002010", predicate.Compile()); + ////var data = Cache.CodeRule.Rules.Where(predicate.Compile()); + //var data = Cache.CodeRule.Verify("AB23#7930000002010", predicate.Compile()); return Ok(""); } @@ -104,14 +110,19 @@ [HttpGet] public async Task<IActionResult> Get2Async(string param) { - //var auth = new AuthOption() { UserId = "admin", ByOrg = true, ByWh = true }; + var auth = new AuthOption() { UserId = "admin", ByOrg = true, ByWh = true }; //var data = await Biz.Db.Queryable<BIZ_ERP_PO>().Where(q => q.BILLTYPE == 11) // //.ByAuth("admin", DbAuth.Org | DbAuth.Wh) // .ByAuth(auth) // .ToListAsync(); //data = await Biz.Db.Queryable<BIZ_ERP_PO>().ByAuth("admin", DbAuth.Org).Where(q => q.BILLTYPE == 11).ToListAsync(); - var data = await Biz.Db.Queryable<BIZ_ERP_PO>().Where(q => q.BILLTYPE == 11).ToListAsync(); + //var data = await Biz.Db.Queryable<BIZ_ERP_PO>().Where(q => q.BILLTYPE == 11).ToListAsync(); //var dtl = await Biz.Db.Queryable<BIZ_ERP_PO_DTL>().ByAuth("admin", DbAuth.Org | DbAuth.Wh).Where(q => q.BILLCODE == "AH3301-221000108").ToListAsync(); + var query = Biz.Db.Queryable<WMS_ITEM_PKG>().ByAuth("admin", DbAuth.Org | DbAuth.Wh).Where(t => t.SN == "barcode.SN").First();// + var data = Biz.Db.Queryable<BIZ_MES_WO_BATCH, BIZ_MES_WO_SN>((q, s) => new JoinQueryInfos(JoinType.Inner, q.ORDER_NO == s.WORK_ORDER)) + .ByAuth(auth)//.ByAuth("admin", DbAuth.Org | DbAuth.Wh) + .Where((q, s) => s.SN == "input.SN" && q.ACT_LINE == "CurLine.LINE_CODE" && (q.STATUS == BIZ_MES_WO_BATCH.STATUSs.Release.GetValue() || q.STATUS == BIZ_MES_WO_BATCH.STATUSs.Working.GetValue())) + .Select((q, s) => new { Batch = q, SN = s }).First(); return Ok(data); } @@ -143,7 +154,7 @@ //var data = 0; //try //{ - // data = Biz.Db.Ado.UseStoredProcedure().ExecuteCommand("pkg_ImportItemFromSRM", new SugarParameter("dlvyNo", "BAD202308240443")); + // data = Biz.Db.Ado.UseStoredProcedure().ExecuteCommand("sp_ImportItemFromSRM", new SugarParameter("dlvyNo", "BAD202308240443")); //} //catch (System.Exception ex) //{ @@ -159,8 +170,8 @@ //Biz.Db.Insertable(data, "Interface").ExecuteCommand(); var root = new SugarParameter("root", "system01"); - var dt = Biz.Db.Ado.UseStoredProcedure().GetDataTable("PKG_SYS_GET_MENU", root);//杩斿洖dt - var data = Biz.Db.Ado.UseStoredProcedure().SqlQuery<SYS_MENU>("PKG_SYS_GET_MENU", root);//杩斿洖List + var dt = Biz.Db.Ado.UseStoredProcedure().GetDataTable("SP_SYS_GET_MENU", root);//杩斿洖dt + var data = Biz.Db.Ado.UseStoredProcedure().SqlQuery<SYS_MENU>("SP_SYS_GET_MENU", root);//杩斿洖List ; //var data = Biz.Db.Queryable<BIZ_SRM_DLVY>() // .IncludesAllFirstLayer() @@ -190,7 +201,7 @@ //{ // throw dbTran.ErrorException; //} - return Ok(""); + return Ok(data); } /// <summary> /// @@ -226,6 +237,37 @@ [HttpGet] public async Task<IActionResult> D1Async(string param) { + Work.DoAsync(() => { HttpHelper.GetAsync("http://172.16.80.40:9529/api/_Test/DoSomething?duration=10&code=01"); ConsoleExt.WriteLine($"{DateTime.Now:HH:mm:ss.fff} - 01 Finished", ConsoleColor.Blue); }); + Work.DoAsync(() => { HttpHelper.GetAsync("http://172.16.80.40:9529/api/_Test/DoSomething?duration=10&code=02"); ConsoleExt.WriteLine($"{DateTime.Now:HH:mm:ss.fff} - 02 Finished", ConsoleColor.Blue); }); + Work.DoAsync(() => { HttpHelper.GetAsync("http://172.16.80.40:9529/api/_Test/DoSomething?duration=10&code=03"); ConsoleExt.WriteLine($"{DateTime.Now:HH:mm:ss.fff} - 03 Finished", ConsoleColor.Blue); }); + Work.DoAsync(() => { HttpHelper.GetAsync("http://172.16.80.40:9529/api/_Test/DoSomething?duration=10&code=04"); ConsoleExt.WriteLine($"{DateTime.Now:HH:mm:ss.fff} - 04 Finished", ConsoleColor.Blue); }); + Work.DoAsync(() => { HttpHelper.GetAsync("http://172.16.80.40:9529/api/_Test/DoSomething?duration=10&code=05"); ConsoleExt.WriteLine($"{DateTime.Now:HH:mm:ss.fff} - 05 Finished", ConsoleColor.Blue); }); + Work.DoAsync(() => { HttpHelper.GetAsync("http://172.16.80.40:9529/api/_Test/DoSomething?duration=10&code=06"); ConsoleExt.WriteLine($"{DateTime.Now:HH:mm:ss.fff} - 06 Finished", ConsoleColor.Blue); }); + Work.DoAsync(() => { HttpHelper.GetAsync("http://172.16.80.40:9529/api/_Test/DoSomething?duration=10&code=07"); ConsoleExt.WriteLine($"{DateTime.Now:HH:mm:ss.fff} - 07 Finished", ConsoleColor.Blue); }); + Work.DoAsync(() => { HttpHelper.GetAsync("http://172.16.80.40:9529/api/_Test/DoSomething?duration=10&code=08"); ConsoleExt.WriteLine($"{DateTime.Now:HH:mm:ss.fff} - 08 Finished", ConsoleColor.Blue); }); + Work.DoAsync(() => { HttpHelper.GetAsync("http://172.16.80.40:9529/api/_Test/DoSomething?duration=10&code=09"); ConsoleExt.WriteLine($"{DateTime.Now:HH:mm:ss.fff} - 09 Finished", ConsoleColor.Blue); }); + Work.DoAsync(() => { HttpHelper.GetAsync("http://172.16.80.40:9529/api/_Test/DoSomething?duration=10&code=10"); ConsoleExt.WriteLine($"{DateTime.Now:HH:mm:ss.fff} - 10 Finished", ConsoleColor.Blue); }); + Work.DoAsync(() => { HttpHelper.GetAsync("http://172.16.80.40:9529/api/_Test/DoSomething?duration=10&code=11"); ConsoleExt.WriteLine($"{DateTime.Now:HH:mm:ss.fff} - 11 Finished", ConsoleColor.Blue); }); + Work.DoAsync(() => { HttpHelper.GetAsync("http://172.16.80.40:9529/api/_Test/DoSomething?duration=10&code=12"); ConsoleExt.WriteLine($"{DateTime.Now:HH:mm:ss.fff} - 12 Finished", ConsoleColor.Blue); }); + Work.DoAsync(() => { HttpHelper.GetAsync("http://172.16.80.40:9529/api/_Test/DoSomething?duration=10&code=13"); ConsoleExt.WriteLine($"{DateTime.Now:HH:mm:ss.fff} - 13 Finished", ConsoleColor.Blue); }); + Work.DoAsync(() => { HttpHelper.GetAsync("http://172.16.80.40:9529/api/_Test/DoSomething?duration=10&code=14"); ConsoleExt.WriteLine($"{DateTime.Now:HH:mm:ss.fff} - 14 Finished", ConsoleColor.Blue); }); + Work.DoAsync(() => { HttpHelper.GetAsync("http://172.16.80.40:9529/api/_Test/DoSomething?duration=10&code=15"); ConsoleExt.WriteLine($"{DateTime.Now:HH:mm:ss.fff} - 15 Finished", ConsoleColor.Blue); }); + Work.DoAsync(() => { HttpHelper.GetAsync("http://172.16.80.40:9529/api/_Test/DoSomething?duration=10&code=16"); ConsoleExt.WriteLine($"{DateTime.Now:HH:mm:ss.fff} - 16 Finished", ConsoleColor.Blue); }); + Work.DoAsync(() => { HttpHelper.GetAsync("http://172.16.80.40:9529/api/_Test/DoSomething?duration=10&code=17"); ConsoleExt.WriteLine($"{DateTime.Now:HH:mm:ss.fff} - 17 Finished", ConsoleColor.Blue); }); + Work.DoAsync(() => { HttpHelper.GetAsync("http://172.16.80.40:9529/api/_Test/DoSomething?duration=10&code=18"); ConsoleExt.WriteLine($"{DateTime.Now:HH:mm:ss.fff} - 18 Finished", ConsoleColor.Blue); }); + Work.DoAsync(() => { HttpHelper.GetAsync("http://172.16.80.40:9529/api/_Test/DoSomething?duration=10&code=19"); ConsoleExt.WriteLine($"{DateTime.Now:HH:mm:ss.fff} - 19 Finished", ConsoleColor.Blue); }); + Work.DoAsync(() => { HttpHelper.GetAsync("http://172.16.80.40:9529/api/_Test/DoSomething?duration=10&code=20"); ConsoleExt.WriteLine($"{DateTime.Now:HH:mm:ss.fff} - 20 Finished", ConsoleColor.Blue); }); + Work.DoAsync(() => { HttpHelper.GetAsync("http://172.16.80.40:9529/api/_Test/DoSomething?duration=10&code=21"); ConsoleExt.WriteLine($"{DateTime.Now:HH:mm:ss.fff} - 21 Finished", ConsoleColor.Blue); }); + Work.DoAsync(() => { HttpHelper.GetAsync("http://172.16.80.40:9529/api/_Test/DoSomething?duration=10&code=22"); ConsoleExt.WriteLine($"{DateTime.Now:HH:mm:ss.fff} - 22 Finished", ConsoleColor.Blue); }); + Work.DoAsync(() => { HttpHelper.GetAsync("http://172.16.80.40:9529/api/_Test/DoSomething?duration=10&code=23"); ConsoleExt.WriteLine($"{DateTime.Now:HH:mm:ss.fff} - 23 Finished", ConsoleColor.Blue); }); + Work.DoAsync(() => { HttpHelper.GetAsync("http://172.16.80.40:9529/api/_Test/DoSomething?duration=10&code=24"); ConsoleExt.WriteLine($"{DateTime.Now:HH:mm:ss.fff} - 24 Finished", ConsoleColor.Blue); }); + Work.DoAsync(() => { HttpHelper.GetAsync("http://172.16.80.40:9529/api/_Test/DoSomething?duration=10&code=25"); ConsoleExt.WriteLine($"{DateTime.Now:HH:mm:ss.fff} - 25 Finished", ConsoleColor.Blue); }); + Work.DoAsync(() => { HttpHelper.GetAsync("http://172.16.80.40:9529/api/_Test/DoSomething?duration=10&code=26"); ConsoleExt.WriteLine($"{DateTime.Now:HH:mm:ss.fff} - 26 Finished", ConsoleColor.Blue); }); + Work.DoAsync(() => { HttpHelper.GetAsync("http://172.16.80.40:9529/api/_Test/DoSomething?duration=10&code=27"); ConsoleExt.WriteLine($"{DateTime.Now:HH:mm:ss.fff} - 27 Finished", ConsoleColor.Blue); }); + Work.DoAsync(() => { HttpHelper.GetAsync("http://172.16.80.40:9529/api/_Test/DoSomething?duration=10&code=28"); ConsoleExt.WriteLine($"{DateTime.Now:HH:mm:ss.fff} - 28 Finished", ConsoleColor.Blue); }); + Work.DoAsync(() => { HttpHelper.GetAsync("http://172.16.80.40:9529/api/_Test/DoSomething?duration=10&code=29"); ConsoleExt.WriteLine($"{DateTime.Now:HH:mm:ss.fff} - 29 Finished", ConsoleColor.Blue); }); + Work.DoAsync(() => { HttpHelper.GetAsync("http://172.16.80.40:9529/api/_Test/DoSomething?duration=10&code=30"); ConsoleExt.WriteLine($"{DateTime.Now:HH:mm:ss.fff} - 30 Finished", ConsoleColor.Blue); }); + ConsoleExt.WriteLine($"{DateTime.Now:HH:mm:ss.fff} - Send Finished", ConsoleColor.Blue); //Logger.Scheduler.Info("杩欐槸涓�娆℃垚鍔熺殑娴嬭瘯"); //var data = iBiz.Biz.Db.Queryable<BAS_CODE_RULE>() // .IncludesAllFirstLayer() @@ -299,18 +341,138 @@ public partial class _TestController : ControllerBase { [HttpGet] - public async Task<IActionResult> DoSomething(int duration) + public async Task<IActionResult> DoSomething(int duration, string code) { var begin = DateTime.Now; - while ((DateTime.Now - begin).TotalSeconds <= duration) - { - Thread.Sleep(1000); - var total = (DateTime.Now - begin).TotalSeconds; - var percent = total / duration; - ConsoleExt.WriteLine($"Working {begin:mmssfff} ... {(percent > 1 ? 1 : percent):P0} ...", ConsoleColor.Green); - } - Logger.Default.Info($"{begin:mmssfff} completed"); - return Ok($"{begin:mmssfff} completed"); + Work.Do(() => { + while ((DateTime.Now - begin).TotalSeconds <= duration) + { + //Thread.Sleep(1000); + var total = (DateTime.Now - begin).TotalSeconds; + var percent = total / duration; + //ConsoleExt.WriteLine($"Working {begin:mmssfff} ... {(percent > 1 ? 1 : percent):P0} ...", ConsoleColor.Green); + } + Logger.Default.Info($"{begin:mmssfff} completed"); + }); + return Ok($"{code.IsNullOrEmpty("", code + ": ")}{begin:mmssfff} completed"); + } + + [HttpPost] + public async Task<IActionResult> MESSubmitAsync([FromBody] ApiAction<SubmitInput> action) + { + var data = action.Data.Data; + + var act = Biz.Db.Queryable<MES_WO_ACTION>().First(q => q.ID == data); + + + var result = act.OPTION_1?.ToString().JsonToObject<List<WipPkgItem>>(); + + return Ok(result?.ToJson()); + } + + [HttpPost] + public async Task<IActionResult> InterfaceAsync([FromBody] ApiAction action) + { + var data = action.Data; + + //var json = new { + // SN = "V025720241120000161", + // ItemCode = "160305330", + // Qty = 1700, + // Unit = "PCS", + // Supplier = "V0381", + // DeliveryDate = DateTime.Now, + // ProdDate = DateTime.Now, + // BatchNo = "20241120", + // ValidityDays = 365, + // SerialNo = 161, + // ItemName = "L-CW1323GA 涓や釜瑁呭僵鐩� 闅旀澘 鏉愯川300g鍗曠矇瑁盰F鍔犲己杩囧搼鑶� 105 mm 85 mm 3 mm 鍗楁嘲 ", + // Warehouse = "W0001", + // ItemModel = "鏉愭枡 闆朵欢 鍟嗗搧", + //}; + //var result = action.GetResponse("GetSnInfo success.", json, true); + + //var json = new List<object> + //{ + // new { + // OrderNo = "RE202404308721", + // Warehouse = "", + // Details = new List<object> + // { + // new { ItemCode = "442500010", ItemName = "闀挎き鍦嗗舰鍗¢拡 35 x7.3 x0.9mm SUS304H 鏂粶娉�", Qty = 1000 }, + // new { ItemCode = "442500011", ItemName = "鐭き鍦嗗舰鍗¢拡 35 x7.3 x0.9mm SUS304H 鏂粶娉�", Qty = 500 } + // }, + // SnDetails = new List<object> + // { + // new { SN = "V029720240427000069", ItemCode = "442500010", Qty = 500, Carton = "CV029720240427000001", Pallet = "PV029720240427000001" }, + // new { SN = "V029720240427000070", ItemCode = "442500010", Qty = 500, Carton = "CV029720240427000001", Pallet = "PV029720240427000001" }, + // new { SN = "V029720240427000071", ItemCode = "442500011", Qty = 500, Carton = "CV029720240427000002", Pallet = "PV029720240427000001" }, + // }, + // } + //}; + //var result = action.GetResponse("GetInOrder success.", json, true); + + //var json = new List<object> + //{ + // new { + // OrderNo = "XC5406-231014306", + // Warehouse = "XC003", + // Details = new List<object> + // { + // new { ItemCode = "250100420", ItemName = "IC SMD DC-DC 0.6V 鍗曡矾 1A 1.5MHZ SOT563 TLV62568DRL TI", Qty = 1000 }, + // new { ItemCode = "200203670", ItemName = "CAP SMD X5R 0402 6.3V 4.7uF卤20%", Qty = 1500 } + // }, + // } + //}; + //var result = action.GetResponse("GetOutOrder success.", json, true); + + var result = action.GetResponse("OutTask success.", true); + + return Ok(new { result.Timestamp, result.IsSuccessed, result.Message, result.Data }); + } + + [HttpGet] + public async Task<IActionResult> RefreashPlugin(string path) + { + var assemblies = AppDomain.CurrentDomain.GetAssemblies().Where(a => a.GetName().Name == "Tiger.Business.MES"); + // 鏌ユ壘鎸囧畾鍚嶇О鐨勭▼搴忛泦 + //var assembly = Array.Find(assemblies, a => a.GetName().Name == "Tiger.Business.MES"); + + //var ass = Assembly.LoadFrom(AppDomain.CurrentDomain.BaseDirectory + "\\Tiger.Business.MES1.dll"); + + + var mes1 = new AssemblyLoadContext("mes1", true); + var assembly1 = mes1.LoadFromAssemblyPath(AppDomain.CurrentDomain.BaseDirectory + "\\Tiger.Business1.MES.dll"); + mes1.Unloading += context => { Console.WriteLine($"褰撳墠鍗歌浇{context.Name}绋嬪簭闆嗭細" + string.Join(',', context.Assemblies.Select(x => x.FullName))); }; + assemblies = AppDomain.CurrentDomain.GetAssemblies().Where(a => a.GetName().Name == "Tiger.Business.MES"); + + var mes2 = new AssemblyLoadContext("mes2", true); + var assembly2 = mes2.LoadFromAssemblyPath(AppDomain.CurrentDomain.BaseDirectory + "\\Tiger.Business2.MES.dll"); + mes2.Unloading += context => { Console.WriteLine($"褰撳墠鍗歌浇{context.Name}绋嬪簭闆嗭細" + string.Join(',', context.Assemblies.Select(x => x.FullName))); }; + assemblies = AppDomain.CurrentDomain.GetAssemblies().Where(a => a.GetName().Name == "Tiger.Business.MES"); + + mes1.Unload(); + assemblies = AppDomain.CurrentDomain.GetAssemblies().Where(a => a.GetName().Name == "Tiger.Business.MES"); + mes2.Unload(); + assemblies = AppDomain.CurrentDomain.GetAssemblies().Where(a => a.GetName().Name == "Tiger.Business.MES"); + + + + + + //var newBuilder = new ContainerBuilder(); + + ////AutoFac 閰嶇疆鏂囦欢娉ㄥ叆 + //AutoFacContainer.Init(newBuilder); + //newBuilder.RegisterBuildCallback(scope => + //{ + + // AutoFacContainer.Instance = (IContainer)scope; + //}); + //var newContainer = newBuilder.Build(); + //var trans = AutoFacContainer.Instance.Resolve<ITestNode>().Init("action.ID", "Request.Host.Value", "action.Data?.USER_CODE", "OQC001"); + //var d = trans.GetDefects(); + return Ok($""); } } -- Gitblit v1.9.3