From 976d3ae1547b896cc5c7875408c09616d5c2ee55 Mon Sep 17 00:00:00 2001
From: Ben Lin <maobin001@msn.com>
Date: 星期二, 26 十一月 2024 20:51:17 +0800
Subject: [PATCH] 箱数更新

---
 Tiger.Business.MES/iERP/MES_U9C.cs |  170 +++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 143 insertions(+), 27 deletions(-)

diff --git a/Tiger.Business.MES/iERP/MES_U9C.cs b/Tiger.Business.MES/iERP/MES_U9C.cs
index 069f0a5..6c3009e 100644
--- a/Tiger.Business.MES/iERP/MES_U9C.cs
+++ b/Tiger.Business.MES/iERP/MES_U9C.cs
@@ -19,57 +19,173 @@
 using System.Diagnostics;
 using Tiger.Model.Entitys.MES.U9C;
 using Newtonsoft.Json.Linq;
+using System.Security.Policy;
+using NetTaste;
 
 namespace Tiger.Business.MES
 {
     public partial class MES_U9C : IMES_U9C
     {
-        public static string U9CAuthLoginUrl { get; set; } = "http://172.16.80.20/U9C/webapi/OAuth2/AuthLogin";
+        public static string U9CAuthLoginUrl { get; set; } = Biz.SysParam["U9CAuthLoginUrl_Test", "U9CUrl"].PARAM_VALUE; // "http://172.16.80.20/U9C/webapi/OAuth2/AuthLogin?"; 娴嬭瘯
+        //public static string U9CAuthLoginUrl { get; set; } = Biz.SysParam["U9CAuthLoginUrl", "U9CUrl"].PARAM_VALUE; //姝e紡
+        public static string secret = "&entcode=02&orgcode=101&clientid=mes&clientsecret=12c8ee7e9bb74ad2a6a0fb3315c8af20";
+        public static string RcvRptDocCreateUrl
+        { get; set; } = Biz.SysParam["RcvRptDocCreateUrl_Test", "U9CUrl"].PARAM_VALUE;  //"http://172.16.80.20/u9C/webapi/RcvRptDoc/Create"; 娴嬭瘯
+        //public static string RcvRptDocCreateUrl
+        //{ get; set; } = Biz.SysParam["RcvRptDocCreateUrl", "U9CUrl"].PARAM_VALUE;  //姝e紡
 
         /// <summary>
         /// 鍏ュ簱鍗曟帴鍙�
         /// </summary>
         /// <param name="input"></param>
         /// <returns></returns>
-        public async Task<ApiAction> RcvRptDocCreate(RcvRptDocCreateInput input)
+        public async Task<ApiAction<RcvRptDocCreateInput>> RcvRptDocCreate(RcvRptDocCreateInput input)
         {
             Logger.Interface.Info($"/**\r\n *杩涘叆鍏ュ簱鍗曟帴鍙�....\r\n */\r\n"); //鍥哄畾鍐欐硶
-            var action = new ApiAction();
+            var action = new ApiAction<RcvRptDocCreateInput>();
             try
             {
-                JObject json = new JObject();
-                json["CompleteList"] = new JArray(); // 鍒涘缓涓�涓┖鐨凧Array
-                JObject moKey = new JObject();
-                moKey["DocNo"] = input.WorkOrder;
-                JObject Wh = new JObject();
-                Wh["Code"] = input.WhCode;
-                json["CompleteList"]["Wh"] = Wh;
-                JObject DescFlexField = new JObject();
-                DescFlexField["PrivateDescSeg1"] = input.PkgQty;
-                json["CompleteList"]["DescFlexField"] = DescFlexField;
-                JObject Item = new JObject();
-                Item["Code"] = input.ItemCode;
-                json["CompleteList"]["Item"] = Item;
-                json["CompleteList"]["CompleteQty"] = input.CompleteQty;
-                json["CompleteList"]["OutputType"] = input.OutputType;
-                json["CompleteList"]["StorageType"] = input.StorageType;
-                json["CompleteList"]["DocState"] = input.DocState;
-
-                var response = await HttpHelper.PostAsync(U9CAuthLoginUrl, json);
-                var result = JsonConvert.DeserializeObject<U9CReturnData>(response.Message);
-                Logger.Interface.Info($"鐢熸垚鍏ュ簱鍗曟帴鍙f彁浜son: {json}锛岃繑鍥濲son: {response.Message}");
+                //鍏堜繚瀛樻暟鎹�
+                bool IsSuccessed = true;
                 var db = Biz.Db;
                 var dbTran = db.UseTran(() =>
                 {
-
-
+                    var s = db.Storageable(input.ErpProdInBths, "U9C_RcvRptDocCreate")
+                                .WhereColumns(t => new { t.ORDER_NO, t.WORK_ORDER, t.GHOST_ROW })
+                                .ToStorage();
+                    s.AsInsertable.ExecuteCommand();
+                    s.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand();
                 });
                 if (!dbTran.IsSuccess)
                 {
                     action.CatchExceptionWithLog(dbTran.ErrorException, $"鏁版嵁澶勭悊澶辫触");
                     Logger.Interface.Error(action.Message);
+                    IsSuccessed = false;
                 }
-                Logger.Interface.Info($"鐢熸垚鍏ュ簱鍗曟垚鍔�");
+
+                //淇濆瓨鎴愬姛锛岃皟鐢║9C鎺ュ彛-娴嬭瘯鐢�
+                int i = 1;
+                List<BIZ_ERP_PROD_IN_BTH> ErpProdInBths = new List<BIZ_ERP_PROD_IN_BTH>();
+                foreach (var item in input.RcvRptDocBases.Where(q => q.Status != "Y"))
+                {
+                    var ErpProdInBth = Biz.Db.Queryable<BIZ_ERP_PROD_IN_BTH>().Where(q => q.WORK_ORDER == item.WorkOrder).First();
+                    item.Status = "Y";
+                    if (!ErpProdInBth.IsNullOrEmpty())
+                    {
+                        ErpProdInBth.ORDER_NO = $"XX001-{i}";
+                        ErpProdInBth.IS_HANDLED = "Y";
+                        ErpProdInBth.HANDLED_DATE = DateTime.Now;
+                        ErpProdInBths.Add(ErpProdInBth);
+                    }
+                    foreach (var p in input.PrintJsons)
+                    {
+                        var d = p.Items.Where(q => q.WORK_ORDER == item.WorkOrder).FirstOrDefault();
+                        if (!d.IsNullOrEmpty())
+                        {
+                            d.ORDER_NO = $"XX001-{i}";
+                            d.STATUS = "Y";
+                        }
+                    }
+                    i++;
+                }
+                var _db = Biz.Db;
+                var _dbTran = _db.UseTran(() =>
+                {
+                    _db.Updateable(ErpProdInBths, "U9C_RcvRptDocCreate").UpdateColumns(x => new { x.ORDER_NO, x.REMARK, x.IS_HANDLED, x.HANDLED_DATE }).ExecuteCommand();
+                });
+                if (!dbTran.IsSuccess)
+                {
+                    action.CatchExceptionWithLog(dbTran.ErrorException, $"鏁版嵁澶勭悊澶辫触");
+                    Logger.Interface.Error(action.Message);
+                    IsSuccessed = false;
+                }
+                input.ErpProdInBths = ErpProdInBths;
+
+                //淇濆瓨鎴愬姛锛岃皟鐢║9C鎺ュ彛
+                //if (IsSuccessed)
+                //{
+                //    var u9CLoginResult = await HttpHelper.GetAsync<U9CLoginResult>($"{U9CAuthLoginUrl}userCode=admin{secret}");
+                //    if (u9CLoginResult.Success)
+                //    {
+                //        var token = u9CLoginResult.Data;
+                //        Logger.Interface.Info($"U9C鐧诲綍token: {token}");
+                //        List<BIZ_ERP_PROD_IN_BTH> ErpProdInBths = new List<BIZ_ERP_PROD_IN_BTH>();
+                //        foreach (var item in input.RcvRptDocBases.Where(q=>q.Status != "Y"))
+                //        {
+                //            List<RcvRptDocCreateParam> param = new() {
+                //                new() {
+                //                    CompleteList = new(){
+                //                       new CompleteList
+                //                       {
+                //                            MOKey = new MOKey { DocNo = item.WorkOrder },
+                //                            Wh = new Wh { Code = item.WhCode },
+                //                            DescFlexField = new DescFlexField { PrivateDescSeg1 = item.PkgQty.ToString() },
+                //                            Item = new Item { Code = item.ItemCode },
+                //                            CompleteQty = item.CompleteQty,
+                //                            OutputType = item.OutputType,
+                //                            StorageType = item.StorageType,
+                //                            DocState = item.DocState,
+                //                       }
+                //                    }
+                //                }
+                //            };
+                //            var response = await HttpHelper.PostAsync(RcvRptDocCreateUrl, JsonConvert.SerializeObject(param), new Dictionary<string, string>() { { "token", token } });
+                //            var result = JsonConvert.DeserializeObject<U9CResult>(response.Message);
+                //            var ErpProdInBth = Biz.Db.Queryable<BIZ_ERP_PROD_IN_BTH>().Where(q => q.WORK_ORDER == item.WorkOrder).First();
+                //            if (result != null)
+                //            {
+                //                if (result.Success && result.Data[0].m_isSucess)
+                //                {
+                //                    Logger.Interface.Info($"鐢熸垚鍏ュ簱鍗曟帴鍙f彁浜son: {JsonConvert.SerializeObject(param)}锛岃繑鍥濲son: {response.Message}");
+                //                    item.Status = "Y";
+                //                    if (!ErpProdInBth.IsNullOrEmpty())
+                //                    {
+                //                        ErpProdInBth.ORDER_NO = result.Data[0].m_code;
+                //                        ErpProdInBth.IS_HANDLED = "Y";
+                //                        ErpProdInBth.HANDLED_DATE = DateTime.Now;
+                //                        ErpProdInBths.Add(ErpProdInBth);
+                //                    }
+                //                    foreach (var p in input.PrintJsons)
+                //                    {
+                //                        var d = p.Items.Where(q => q.WORK_ORDER == item.WorkOrder).FirstOrDefault();
+                //                        if (!d.IsNullOrEmpty())
+                //                        {
+                //                            d.ORDER_NO = result.Data[0].m_code;
+                //                        }
+                //                    }
+                //                    Logger.Interface.Info($"鐢熸垚鍏ュ簱鍗曟垚鍔�");
+                //                }
+                //                else
+                //                {
+                //                    action.IsSuccessed = false;
+                //                    action.LocaleMsg = new($"{action.Message}; {result.Data[0].m_errorMsg}");
+                //                    item.Status = "F";
+                //                    if (!ErpProdInBth.IsNullOrEmpty())
+                //                    {
+                //                        ErpProdInBth.REMARK = result.Data[0].m_errorMsg;
+                //                        ErpProdInBth.IS_HANDLED = "F";
+                //                        ErpProdInBth.HANDLED_DATE = DateTime.Now;
+                //                        ErpProdInBths.Add(ErpProdInBth);
+                //                    }
+                //                    Logger.Interface.Info($"鐢熸垚鍏ュ簱鍗曞け璐�:{result.Data[0].m_errorMsg}");
+                //                }
+                //            }
+                //        }
+                //        var _db = Biz.Db;
+                //        var _dbTran = _db.UseTran(() =>
+                //        {
+                //            _db.Updateable(ErpProdInBths, "U9C_RcvRptDocCreate").UpdateColumns(x => new { x.ORDER_NO, x.REMARK, x.IS_HANDLED, x.HANDLED_DATE }).ExecuteCommand();
+                //        });
+                //        if (!dbTran.IsSuccess)
+                //        {
+                //            action.CatchExceptionWithLog(dbTran.ErrorException, $"鏁版嵁澶勭悊澶辫触");
+                //            Logger.Interface.Error(action.Message);
+                //            IsSuccessed = false;
+                //        }
+                //        input.ErpProdInBths = ErpProdInBths;
+                //    }
+                //}
+                action.Data = input;
             }
             catch (System.Exception ex)
             {

--
Gitblit v1.9.3