From 5f3129c47cc8d3aa9ddffb2c468d908f2416e544 Mon Sep 17 00:00:00 2001
From: chengsc <Demo@DESKTOP-CPA90BF>
Date: 星期二, 27 八月 2024 11:02:12 +0800
Subject: [PATCH] 修改MES接口问题

---
 Wms/WMS.Entity/SysEntity/SysToken.cs               |   34 +++
 Wms/Wms/Controllers/UpApiController.cs             |  125 +++++++++++--
 Wms/WMS.Entity/Context/DataContext.cs              |   17 +
 Wms/WMS.IBLL/IBllAsnServer/IArrivalNoticeServer.cs |   10 
 Wms/WMS.BLL/BllAsnServer/ArrivalNoticeServer.cs    |   55 +++++-
 Wms/Wms/Tools/ApiUrlConfig.cs                      |    2 
 Wms/WMS.IBLL/IBllSoServer/IExportNoticeServer.cs   |    2 
 Wms/WMS.IBLL/ISysServer/IToken.cs                  |   16 +
 Wms/Wms/Startup.cs                                 |    3 
 Wms/WMS.IBLL/ISysServer/IStorageLocatServer.cs     |    3 
 Wms/WMS.BLL/BllSoServer/ExportNoticeServer.cs      |   49 ++--
 Wms/Wms/appsettings.json                           |   10 
 Wms/Wms/Controllers/SysController.cs               |   11 
 Wms/WMS.BLL/SysServer/StorageLocatServer.cs        |   20 ++
 Wms/Model/InterFaceModel/AsnModels.cs              |   13 +
 Wms/Model/InterFaceModel/HttpModel.cs              |   60 ++++++
 Wms/WMS.BLL/SysServer/Token.cs                     |  109 ++++++++++++
 17 files changed, 471 insertions(+), 68 deletions(-)

diff --git a/Wms/Model/InterFaceModel/AsnModels.cs b/Wms/Model/InterFaceModel/AsnModels.cs
index a2b2e43..8d13886 100644
--- a/Wms/Model/InterFaceModel/AsnModels.cs
+++ b/Wms/Model/InterFaceModel/AsnModels.cs
@@ -5,6 +5,19 @@
 
 namespace Model.InterFaceModel
 {
+
+    public class FinishAsnModel
+    {
+        /// <summary>
+        /// 鐢熶骇宸ュ崟
+        /// </summary>
+        public string no { get; set; }
+        /// <summary>
+        /// 鏁伴噺
+        /// </summary>
+        public decimal? qty { get; set; }
+    }
+
     /// <summary>
     /// 鍏ュ簱鍗曚俊鎭�
     /// </summary>
diff --git a/Wms/Model/InterFaceModel/HttpModel.cs b/Wms/Model/InterFaceModel/HttpModel.cs
index 1445bc4..9040f1a 100644
--- a/Wms/Model/InterFaceModel/HttpModel.cs
+++ b/Wms/Model/InterFaceModel/HttpModel.cs
@@ -5,6 +5,15 @@
 
 namespace Model.InterFaceModel
 {
+    /// <summary>
+    /// 澶栭儴绯荤粺杩斿洖鍙傛暟
+    /// </summary>
+    public class HttpReturnModel
+    {
+        public string Success { get; set; }
+        public string Message { get; set; }
+    }
+
     #region Erp-Model
 
     /// <summary>
@@ -27,18 +36,63 @@
     #region MES-Model
 
     /// <summary>
-    /// 鍙戦�佹帴鏀秏es鎺ュ彛鍙傛暟鐨刴odel
+    /// 鎺ユ敹mes鎺ュ彛鍙傛暟鐨刴odel
     /// </summary>
     public class MesModel
     {
         /// <summary>
         /// 鐘舵�佺爜 0 鎴愬姛 -1澶辫触
         /// </summary>
-        public int Success { get; set; }
+        public string status { get; set; }
         /// <summary>
         /// 淇℃伅璇︽儏
         /// </summary>
-        public string Message { get; set; }
+        public string message { get; set; }
+    }
+    /// <summary>
+    /// Mes浠ょ墝Model
+    /// </summary>
+    public class MesTokenModel
+    {
+        /// <summary>
+        /// 鐘舵�佺爜 0 鎴愬姛 -1澶辫触
+        /// </summary>
+        public string status { get; set; }
+        /// <summary>
+        /// 淇℃伅璇︽儏
+        /// </summary>
+        public string message { get; set; }
+        /// <summary>
+        /// 淇℃伅璇︽儏
+        /// </summary>
+        public GetTokenModel Data { get; set; }
+
+        /// <summary>
+        /// 淇℃伅璇︽儏
+        /// </summary>
+        public string type { get; set; }
+        /// <summary>
+        /// 寮傚父鎽樿淇℃伅銆愬瓧绗﹀瀷銆�
+        /// </summary>
+        public string summary { get; set; } 
+        
+    }
+
+    public class GetTokenModel
+    {
+        public string token { get; set; }
+        public string expire_time { get; set; }
+    }
+
+
+    /// <summary>
+    /// 閲婃斁澶囨枡鍖哄偍浣嶇姸鎬丮odel
+    /// </summary>
+    public class UpLocateModel
+    {
+        public string WareHouseNo { get; set; }
+        public string LocatNo { get; set; }
+        public string Origin { get; set; }
     }
 
     #endregion
diff --git a/Wms/WMS.BLL/BllAsnServer/ArrivalNoticeServer.cs b/Wms/WMS.BLL/BllAsnServer/ArrivalNoticeServer.cs
index fa13375..5020166 100644
--- a/Wms/WMS.BLL/BllAsnServer/ArrivalNoticeServer.cs
+++ b/Wms/WMS.BLL/BllAsnServer/ArrivalNoticeServer.cs
@@ -17,6 +17,7 @@
 using WMS.Entity.Context;
 using WMS.Entity.SysEntity;
 using WMS.IBLL.IBllAsnServer;
+using WMS.BLL.SysServer;
 
 namespace WMS.BLL.BllAsnServer
 {
@@ -869,11 +870,11 @@
         /// </summary>
         /// <param name="model"></param>
         /// <returns></returns>
-        public ErpModel CreateAsn(AsnInfo model)
+        public HttpReturnModel HttpCreateAsn(AsnInfo model)
         {
             try
             {
-                var resultModel = new ErpModel() { Success = -1, Message = "" };
+                var resultModel = new HttpReturnModel() { Success = "-1", Message = "" };
                 if (string.IsNullOrEmpty(model.AsnType))
                 {
                     resultModel.Message = "鍗曟嵁绫诲瀷涓嶅彲涓虹┖!";
@@ -972,7 +973,7 @@
                 Db.Insertable(detailModels).ExecuteCommand();
                 Db.CommitTran();
 
-                resultModel.Success = 0;
+                resultModel.Success = "0";
                 resultModel.Message = "鎴愬姛";
                 return resultModel;
             }
@@ -984,7 +985,7 @@
         }
 
         //璁㈠崟鍥炰紶涓婃父绯荤粺
-        public bool FinishAsn(int id, string erpUrl, string mesUrl, int userId)
+        public bool FinishAsn(int id, string erpUrl, string mesUrl,string mesTokenUrl, int userId)
         {
             try
             {
@@ -1019,7 +1020,7 @@
                     };
                     list.Add(item);
                 }
-                var soInfo = new AsnInfo()
+                var asnInfo = new AsnInfo()
                 {
                     OrderCode = notice.OrderCode,
                     AsnDetails = list
@@ -1027,18 +1028,31 @@
 
                 #region 閫氳繃鎺ュ彛鍙戦�佽嚦erp 鎴� mes
                 //绯荤粺瀵规帴鍚庢斁寮�
-                var jsonData = JsonConvert.SerializeObject(soInfo);
+                var jsonData = JsonConvert.SerializeObject(asnInfo);
                 var mesList = new List<string>() { "0", "4" };  //0 鎴愬搧鍏ュ簱 4浣欐枡閫�鍥炲叆搴�
                 var erpList = new List<string>() { "1", "2", "3" }; //1 閲囪喘鍏ュ簱  2涓棿鍝佸叆搴�  3 閫�璐у叆搴�
 
                 if (mesList.Contains(notice.Type)) // mes 
                 {
-                    var response = HttpHelper.DoPost(mesUrl, jsonData, "鍏ュ簱鍗曞畬鎴愪笂浼�", "MES");
+                    //鑾峰彇浠ょ墝
+                    var token = new Token().GetMesToken(mesTokenUrl);
+                    Dictionary<string, string> mesDic = new Dictionary<string, string>()
+                    {
+                        {"Authorization",token }
+                    };
+                    var mesData = new FinishAsnModel()
+                    {
+                        no = asnInfo.OrderCode,
+                        qty = asnInfo.AsnDetails.Sum(m=>m.Qty)
+                    };
+                    jsonData = JsonConvert.SerializeObject(mesData);
+                    //璋冪敤鎺ュ彛
+                    var response = HttpHelper.DoPost(mesUrl, jsonData, "鍏ュ簱鍗曞畬鎴愪笂浼�", "MES", mesDic);
 
                     var obj = JsonConvert.DeserializeObject<MesModel>(response);//瑙f瀽杩斿洖鏁版嵁
-                    if (obj.Success != 0)
+                    if (obj.status != "0")
                     {
-                        throw new Exception("涓婁紶澶辫触" + obj.Message);
+                        throw new Exception("涓婁紶澶辫触" + obj.message);
                     }
                 }
                 else if (erpList.Contains(notice.Type)) //erp  
@@ -1069,6 +1083,29 @@
             }
         }
 
+        public void UpLocate(string wareNo,string locatNo)
+        {
+            try
+            {
+                if (string.IsNullOrWhiteSpace(wareNo) || string.IsNullOrWhiteSpace(locatNo))
+                {
+                    throw new Exception("浠撳簱鎴栧偍浣嶄笉鑳戒负绌�");
+                }
+                var locate = Db.Queryable<SysStorageLocat>().First(m=>m.IsDel == "0" && m.LocatNo == locatNo && m.WareHouseNo == wareNo);
+                if (locate == null)
+                {
+                    throw new Exception("鏈煡璇㈠埌鍌ㄤ綅淇℃伅");
+                }
+                locate.Status = "0";//鍌ㄤ綅鐘舵�佸彉鏇寸┖鍌ㄤ綅
+                Db.Updateable(locate).ExecuteCommand();
+
+            }
+            catch (Exception e)
+            {
+                throw new Exception(e.Message);
+            }
+        }
+
         #endregion
     }
 
diff --git a/Wms/WMS.BLL/BllSoServer/ExportNoticeServer.cs b/Wms/WMS.BLL/BllSoServer/ExportNoticeServer.cs
index f671968..61a35d6 100644
--- a/Wms/WMS.BLL/BllSoServer/ExportNoticeServer.cs
+++ b/Wms/WMS.BLL/BllSoServer/ExportNoticeServer.cs
@@ -41,7 +41,7 @@
         /// </summary>
         /// <param name="model"></param>
         /// <returns></returns>
-        public bool ErpAddExportNotice(SoInfo model)
+        public void HttpAddExportNotice(SoInfo model)
         {
             try
             {
@@ -226,7 +226,7 @@
                         SONo = billNo,
                         Type = model.SoType,
                         Status = "0",
-                        Origin = "WMS",
+                        Origin = model.Origin,
                         CustomerNo = model.Customer,
                         CustomerName = customer.CustomerName,
                         LogisticsId = logisticsId,
@@ -242,12 +242,10 @@
 
                     if (n <= 0 || m <= 0)
                     {
-                        Db.RollbackTran();
-                        return false;
+                        throw new Exception("鍏ュ簱鍗曟垨鏄庣粏娣诲姞淇濆瓨澶辫触");
                     }
                     Db.CommitTran();
-                    return true;
-
+                    
                 }
                 catch (Exception ex)
                 {
@@ -259,7 +257,6 @@
             }
             catch (Exception ex)
             {
-                Db.RollbackTran();
                 throw new Exception(ex.Message);
             }
         }
@@ -363,31 +360,31 @@
                     .LeftJoin<SysUserInfor>((a, b, c, d, e) => a.CheckUser == e.Id)
                     .Select((a, b, c, d, e) => new ExportNoticeDto()
                     {
-                        Id = a.Id,
-                        SONo = a.SONo,
-                        Type = a.Type,
-                        Status = a.Status,
-                        Origin = a.Origin,
-                        CustomerNo = a.CustomerNo,
-                        CustomerName = a.CustomerName,
-                        LotNo = a.LotNo,
-                        LotText = a.LotText,
-                        SupplierLot = a.SupplierLot,
-                        LogisticsId = a.LogisticsId,
+                        //Id = a.Id,
+                        //SONo = a.SONo,
+                        //Type = a.Type,
+                        //Status = a.Status,
+                        //Origin = a.Origin,
+                        //CustomerNo = a.CustomerNo,
+                        //CustomerName = a.CustomerName,
+                        //LotNo = a.LotNo,
+                        //LotText = a.LotText,
+                        //SupplierLot = a.SupplierLot,
+                        //LogisticsId = a.LogisticsId,
                         LogisticsName = b.CarrierName,
-                        IsWave = a.IsWave,
-                        WaveNo = a.WaveNo,
-                        IsDespatch = a.IsDespatch,
-                        Demo = a.Demo,
+                        //IsWave = a.IsWave,
+                        //WaveNo = a.WaveNo,
+                        //IsDespatch = a.IsDespatch,
+                        //Demo = a.Demo,
 
                         CreateUserName = c.RealName,
                         UpdateUserName = c.RealName,
-                        CreateTime = a.CreateTime,
-                        UpdateTime = a.UpdateTime,
+                        //CreateTime = a.CreateTime,
+                        //UpdateTime = a.UpdateTime,
 
                         CheckUserName = e.RealName,
-                        CheckTime = a.CheckTime
-                    })
+                        //CheckTime = a.CheckTime
+                    },true)
                     .OrderByDescending(a => a.CreateTime)
                     .ToOffsetPage(page, limit, ref total);
                 count = total;
diff --git a/Wms/WMS.BLL/SysServer/StorageLocatServer.cs b/Wms/WMS.BLL/SysServer/StorageLocatServer.cs
index 75671e8..e87f209 100644
--- a/Wms/WMS.BLL/SysServer/StorageLocatServer.cs
+++ b/Wms/WMS.BLL/SysServer/StorageLocatServer.cs
@@ -110,6 +110,7 @@
             try
             {
                 var data = LocatRst.GetOneById(id);
+                //var data = Db.Queryable<SysStorageLocat>().First(m=>m.Id == id);
                 return data;
             }
             catch (Exception e)
@@ -118,7 +119,24 @@
                 throw;
             }
         }
-
+        public List<SysStorageLocat> GetStorageLocat(List<int> id)
+        {
+            try
+            {
+                var SysStorageLocats = new List<SysStorageLocat>();
+                foreach (var item in id)
+                {
+                    var storage = LocatRst.GetOneById(item);
+                    SysStorageLocats.Add(storage);
+                }
+                return SysStorageLocats;
+            }
+            catch (Exception e)
+            {
+                Console.WriteLine(e);
+                throw;
+            }
+        }
 
         public bool EditStorageLocat(EditLocateVm model, int userId)
         {
diff --git a/Wms/WMS.BLL/SysServer/Token.cs b/Wms/WMS.BLL/SysServer/Token.cs
new file mode 100644
index 0000000..b73c03f
--- /dev/null
+++ b/Wms/WMS.BLL/SysServer/Token.cs
@@ -0,0 +1,109 @@
+锘縰sing Microsoft.IdentityModel.Protocols;
+using Model.InterFaceModel;
+using Newtonsoft.Json;
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Security.Policy;
+using System.Text; 
+using Utility.Tools;
+using WMS.DAL;
+using WMS.Entity.Context;
+using WMS.Entity.SysEntity;
+using WMS.IBLL.ISysServer;
+
+namespace WMS.BLL.SysServer
+{
+    public class Token : DbHelper<SysToken>,IToken
+    {
+        private static readonly SqlSugarScope Db = DataContext.Db;
+
+        public Token() : base(Db)
+        {
+        }
+        public string GetMesToken(string url)
+        {
+            try
+            {
+                var str = "";
+
+                //棣栧厛鍒ゆ柇绯荤粺鍐呮槸鍚︽湁token鍊硷紝鏁堟湡鏄惁澶辨晥
+                var sysToken = Db.Queryable<SysToken>().First(m => m.IsDel == "0" && m.SystemName == "MES");
+                if (sysToken != null && !string.IsNullOrWhiteSpace(sysToken.Token) && sysToken.ExpireTime > DateTime.Now)
+                {
+                    str = sysToken.Token;
+                    return str;  //杩斿洖token鍊�
+                }
+
+                #region 鑾峰彇鏂扮殑浠ょ墝
+                
+                var user = MesConfig.MesUser;
+                var pass = MesConfig.MesPassWord;
+                var secretKey = Md5Tools.CalcMd5(pass);
+                var nonce = Guid.NewGuid().ToString("N");
+                var timestamp = DateTimeOffset.Now.ToUnixTimeSeconds().ToString();
+                
+                var info = new string[] { user, secretKey, nonce, timestamp };
+                Array.Sort(info,string.CompareOrdinal); //ASCII鎺掑簭
+                var miyao = string.Join("", info); //鏁扮粍杞崲鎴愬瓧绗︿覆
+                var sign = Md5Tools.CalcMd5(miyao);  //绛惧悕
+
+                var data = new
+                {
+                    user = user,
+                    nonce = nonce,
+                    timestamp = timestamp,
+                    sign = sign,
+                    jwt = true,      //鏄惁杩斿洖JWT浠ょ墝
+                };
+                #endregion
+
+                #region 閫氳繃鎺ュ彛鍙戦�佽嚦erp 鎴� mes
+                //绯荤粺瀵规帴鍚庢斁寮�
+                var jsonData = JsonConvert.SerializeObject(data);
+
+                var response = HttpHelper.DoPost(url, jsonData, "MES鐢宠鑾峰彇浠ょ墝", "MES");
+
+                var obj = JsonConvert.DeserializeObject<MesTokenModel>(response);//瑙f瀽杩斿洖鏁版嵁
+                
+                if (obj.status != "success")
+                {
+                    throw new Exception("涓婁紶澶辫触" + obj.message);
+                }
+                else
+                {
+                    var token = obj.Data.token;
+                    var expireTime = obj.Data.expire_time;
+                    var time = DateTime.Now.AddMilliseconds(double.Parse(expireTime));
+                    if (sysToken == null)//娣诲姞
+                    {
+                        var addToken = new SysToken()
+                        {
+                            SystemName = "MES",
+                            Token = token,
+                            ExpireTime = time,
+                            CreateUser = 0
+                        };
+                        Db.Insertable(addToken).ExecuteCommand();
+                        return token;
+                    }
+                    else //淇敼
+                    {
+                        sysToken.Token = token;
+                        sysToken.ExpireTime = time;
+                        sysToken.UpdateTime = DateTime.Now;
+                        Db.Updateable(sysToken).ExecuteCommand();
+                        return token;
+                    }
+                }
+
+                #endregion 
+            }
+            catch (Exception)
+            {
+                return "";
+            }
+        }
+    }
+}
diff --git a/Wms/WMS.Entity/Context/DataContext.cs b/Wms/WMS.Entity/Context/DataContext.cs
index c8181fb..9271ea3 100644
--- a/Wms/WMS.Entity/Context/DataContext.cs
+++ b/Wms/WMS.Entity/Context/DataContext.cs
@@ -98,4 +98,21 @@
         public static string ConnectionString { get; set; }
 
     }
+    /// <summary>
+    /// MES鑾峰彇浠ょ墝璐﹀彿瀵嗙爜
+    /// </summary>
+    public class MesConfig
+    {
+        /// <summary>
+        /// 璐﹀彿
+        /// </summary>
+        public static string MesUser { get; set; }
+        /// <summary>
+        /// 瀵嗙爜
+        /// </summary>
+        public static string MesPassWord { get; set; }
+
+    }
+
+
 }
diff --git a/Wms/WMS.Entity/SysEntity/SysToken.cs b/Wms/WMS.Entity/SysEntity/SysToken.cs
new file mode 100644
index 0000000..f0525d7
--- /dev/null
+++ b/Wms/WMS.Entity/SysEntity/SysToken.cs
@@ -0,0 +1,34 @@
+锘縰sing SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace WMS.Entity.SysEntity
+{
+    /// <summary>
+    /// 澶栭儴绯荤粺token浠ょ墝鏁堟湡琛�
+    /// </summary>
+    [SugarTable("SysToken")]
+    public class SysToken : BaseEntity
+    {
+
+        /// <summary>
+        /// 澶栭儴绯荤粺鍚嶇О
+        /// Nullable:False
+        /// </summary>
+        public string SystemName { get; set; }
+
+        /// <summary>
+        /// token鍊�
+        /// Nullable:True
+        /// </summary>
+        public string Token { get; set; }
+
+        /// <summary>
+        /// 鏈夋晥鏈�
+        /// Nullable:true
+        /// </summary>
+        public DateTime? ExpireTime { get; set; }
+
+    }
+}
diff --git a/Wms/WMS.IBLL/IBllAsnServer/IArrivalNoticeServer.cs b/Wms/WMS.IBLL/IBllAsnServer/IArrivalNoticeServer.cs
index 366dfba..1d48688 100644
--- a/Wms/WMS.IBLL/IBllAsnServer/IArrivalNoticeServer.cs
+++ b/Wms/WMS.IBLL/IBllAsnServer/IArrivalNoticeServer.cs
@@ -93,15 +93,19 @@
         /// </summary>
         /// <param name="model"></param>
         /// <returns></returns>
-        ErpModel CreateAsn(AsnInfo model);
+        HttpReturnModel HttpCreateAsn(AsnInfo model);
         /// <summary>
         /// 璁㈠崟鍥炰紶涓婃父绯荤粺
         /// </summary>
         /// <param name="id">鍏ュ簱鍗旾D</param>
-        /// <param name="url">涓婁紶璺緞</param>
+        /// <param name="erpurl">涓婁紶璺緞</param>
+        /// <param name="mesUrl">涓婁紶璺緞</param>
+        /// <param name="mesTokenUrl">mes鑾峰彇浠ょ墝璺緞</param>
         /// <param name="userId">鎿嶄綔浜�</param>
         /// <returns></returns>
-        bool FinishAsn(int id, string erpurl, string mesUrl, int userId);
+        bool FinishAsn(int id, string erpurl, string mesUrl,string mesTokenUrl, int userId);
+
+        void UpLocate(string wareNo, string locatNo);
 
         #endregion
     }
diff --git a/Wms/WMS.IBLL/IBllSoServer/IExportNoticeServer.cs b/Wms/WMS.IBLL/IBllSoServer/IExportNoticeServer.cs
index 462db76..165a748 100644
--- a/Wms/WMS.IBLL/IBllSoServer/IExportNoticeServer.cs
+++ b/Wms/WMS.IBLL/IBllSoServer/IExportNoticeServer.cs
@@ -15,7 +15,7 @@
         /// </summary>
         /// <param name="model">妯″瀷</param>
         /// <returns></returns>
-        bool ErpAddExportNotice(SoInfo model);
+        void HttpAddExportNotice(SoInfo model);
         /// <summary>
         /// 鑾峰彇鎵ц瀹屾垚鐨勫崟鎹彂閫佽嚦erp
         /// </summary>
diff --git a/Wms/WMS.IBLL/ISysServer/IStorageLocatServer.cs b/Wms/WMS.IBLL/ISysServer/IStorageLocatServer.cs
index 86169c8..fe4f801 100644
--- a/Wms/WMS.IBLL/ISysServer/IStorageLocatServer.cs
+++ b/Wms/WMS.IBLL/ISysServer/IStorageLocatServer.cs
@@ -34,6 +34,9 @@
         /// <param name="id"></param>
         /// <returns></returns>
         SysStorageLocat GetStorageLocat(int id);
+
+        List<SysStorageLocat> GetStorageLocat(List<int> id);
+
         /// <summary>
         /// 缂栬緫鍌ㄤ綅淇℃伅
         /// </summary>
diff --git a/Wms/WMS.IBLL/ISysServer/IToken.cs b/Wms/WMS.IBLL/ISysServer/IToken.cs
new file mode 100644
index 0000000..040d73a
--- /dev/null
+++ b/Wms/WMS.IBLL/ISysServer/IToken.cs
@@ -0,0 +1,16 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace WMS.IBLL.ISysServer
+{
+    public interface IToken
+    {
+        /// <summary>
+        /// 鑾峰彇MES鐨則oken浠ょ墝
+        /// </summary>
+        /// <param name="url">mes鑾峰彇浠ょ墝璺緞</param>
+        /// <returns>token鍊�</returns>
+        string GetMesToken(string url);
+    }
+}
diff --git a/Wms/Wms/Controllers/SysController.cs b/Wms/Wms/Controllers/SysController.cs
index 1ec3250..24560ea 100644
--- a/Wms/Wms/Controllers/SysController.cs
+++ b/Wms/Wms/Controllers/SysController.cs
@@ -1226,11 +1226,16 @@
                         string msg = "鍌ㄤ綅鐘舵�� 鍌ㄤ綅鍙凤細" + storage.RoadwayNo;
                         if (model.Id.Count > 1)
                         {
-                            foreach (var item in model.Id)
+                            var sstorage = _locatSvc.GetStorageLocat(model.Id);
+                            foreach (var item in sstorage)
                             {
-                                storage = _locatSvc.GetStorageLocat(item);
-                                _operation.InsertOperation("浠撳簱璁剧疆", "鍌ㄤ綅绠$悊", storage.LocatNo, "鎵归噺缂栬緫", "鎵归噺淇敼鍌ㄤ綅淇℃伅 鍌ㄤ綅鍙凤細" + storage.LocatNo, Convert.ToInt32(userId));
+                                _operation.InsertOperation("浠撳簱璁剧疆", "鍌ㄤ綅绠$悊", item.LocatNo, "鎵归噺缂栬緫", "鎵归噺淇敼鍌ㄤ綅淇℃伅 鍌ㄤ綅鍙凤細" + item.LocatNo, Convert.ToInt32(userId));
                             }
+                            //foreach (var item in model.Id)
+                            //{
+                            //    storage = _locatSvc.GetStorageLocat(item);
+                            //    _operation.InsertOperation("浠撳簱璁剧疆", "鍌ㄤ綅绠$悊", storage.LocatNo, "鎵归噺缂栬緫", "鎵归噺淇敼鍌ㄤ綅淇℃伅 鍌ㄤ綅鍙凤細" + storage.LocatNo, Convert.ToInt32(userId));
+                            //}
                         }
                         else
                         {
diff --git a/Wms/Wms/Controllers/UpApiController.cs b/Wms/Wms/Controllers/UpApiController.cs
index 589782f..0c805e3 100644
--- a/Wms/Wms/Controllers/UpApiController.cs
+++ b/Wms/Wms/Controllers/UpApiController.cs
@@ -12,6 +12,7 @@
 using WMS.IBLL.IBllAsnServer;
 using WMS.IBLL.IBllCheckServer;
 using Model.ModelVm.BllCheckVm;
+using Microsoft.Extensions.Logging;
 
 namespace Wms.Controllers
 {
@@ -88,7 +89,7 @@
                 {
                     return Ok(new { code = 1, msg = "鏈幏鍙栧埌褰撳墠鎿嶄綔浜轰俊鎭�" });
                 }
-                _arrivalNoticeSvc.FinishAsn(model.Id, _config.ErpHost + _config.AsnFinishUrl, _config.MesHost + _config.MesAsnFinishUrl, int.Parse(userId));
+                _arrivalNoticeSvc.FinishAsn(model.Id, _config.ErpHost + _config.AsnFinishUrl, _config.MesHost + _config.MesAsnFinishUrl, _config.MesHost + _config.MesGetTokenUrl, int.Parse(userId));
 
                 return Ok(new { code = 0, count = 0, msg = "鍏ュ簱鍗曞鏍稿苟涓婁紶鎴愬姛" });
             }
@@ -223,27 +224,42 @@
         [HttpPost]
         public IActionResult CreateAsn(AsnInfo model)
         {
-            var result = new ErpModel { Success = -1, Message = "" };
+            var result = new HttpReturnModel { Success = "-1", Message = "" };
+            var logStr = "";
+            if (model.Origin == "MES")
+            {
+                logStr = $@".\log\MES\鍏ュ簱鍗曚笅鍙�" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
+            }
+            else if (model.Origin == "ERP")
+            {
+                logStr = $@".\log\ERP\鍏ュ簱鍗曚笅鍙�" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
+            }
+            
             try
             {
-                var claimsIdentity = this.User.Identity as ClaimsIdentity;
-                if (claimsIdentity == null)
+                //log鏃ュ織璁板綍 
+                if (logStr != "")
                 {
-                    throw new Exception("鏈幏鍙栧埌鐢ㄦ埛淇℃伅");
-                }
-                string UserId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
-                if (string.IsNullOrWhiteSpace(UserId))
-                {
-                    throw new Exception("鏈幏鍙栧埌鐢ㄦ埛淇℃伅");
+                    var jsonData = JsonConvert.SerializeObject(model);
+                    LogFile.SaveLogToFile($"鍏ュ簱鍗曚笅鍙戯細( {jsonData} ),", logStr);
                 }
 
-                result = _arrivalNoticeSvc.CreateAsn(model);
-
+                result = _arrivalNoticeSvc.HttpCreateAsn(model);
+                if (logStr != "")
+                {
+                    var jsonData = JsonConvert.SerializeObject(result);
+                    LogFile.SaveLogToFile($"鍏ュ簱鍗曚笅鍙戣繑鍥炲弬鏁帮細( {jsonData} ),", logStr);
+                }
                 return Ok(result);
             }
             catch (Exception e)
             {
                 result.Message = e.Message;
+                if (logStr != "")
+                {
+                    var jsonData = JsonConvert.SerializeObject(result);
+                    LogFile.SaveLogToFile($"鍏ュ簱鍗曚笅鍙戣繑鍥炲弬鏁帮細( {jsonData} ),", logStr);
+                }
                 return Ok(result);
             }
         }
@@ -256,26 +272,95 @@
         [HttpPost]
         public IActionResult CreateSo(SoInfo model)
         {
+            var logStr = "";
+            if (model.Origin == "MES")
+            {
+                logStr = $@".\log\MES\鍑哄簱鍗曚笅鍙�" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
+            }
+            else if(model.Origin == "ERP")
+            {
+                logStr = $@".\log\ERP\鍑哄簱鍗曚笅鍙�" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
+            }
+            
             try
-            { 
-                var bl = _exNoticeSvc.ErpAddExportNotice(model);
-                if (bl)
+            {
+                //log鏃ュ織璁板綍 
+                if (logStr!="")
                 {
-                    return Ok(new ErpModel { Success = 0, Message = "鎴愬姛"});
+                    var jsonData = JsonConvert.SerializeObject(model);
+                    LogFile.SaveLogToFile($"鍑哄簱鍗曚笅鍙戯細( {jsonData} ),", logStr);
                 }
-                else
+                
+                _exNoticeSvc.HttpAddExportNotice(model);
+
+                var data = new HttpReturnModel { Success = "0", Message = "鎴愬姛" };
+
+                if (logStr != "")
                 {
-                    return Ok(new ErpModel { Success = -1, Message = "澶辫触" });
+                    var jsonData = JsonConvert.SerializeObject(data);
+                    LogFile.SaveLogToFile($"鍑哄簱鍗曚笅鍙戣繑鍥炲弬鏁帮細( {jsonData} ),", logStr);
                 }
+
+                return Ok(data);
+                
                 
             }
             catch (Exception e)
             {
-                return Ok(new ErpModel { Success = -1, Message = e.Message });
+                var data = new HttpReturnModel { Success = "-1", Message = "澶辫触"+e.Message };
+                if (logStr != "")
+                {
+                    var jsonData = JsonConvert.SerializeObject(data);
+                    LogFile.SaveLogToFile($"鍑哄簱鍗曚笅鍙戣繑鍥炲弬鏁帮細( {jsonData} ),", logStr);
+                }
+                return Ok(data);
             }
         }
 
-        //绠辩爜淇℃伅 鎵嬫寔缁勬墭鐢� (璧嬬爜鎴栬拷婧笅鍙戝埌wms)
+        /// <summary>
+        /// 閲婃斁澶囨枡鍖哄偍浣嶇姸鎬丣C24
+        /// </summary>
+        /// <returns></returns>
+        [HttpPost]
+        public IActionResult UpLocate(UpLocateModel model)
+        {
+            //璁板綍log
+            var logStr = "";
+            if (model.Origin == "MES")
+            {
+                logStr = $@".\log\MES\閲婃斁澶囨枡鍖哄偍浣嶇姸鎬�" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
+            }
+            try
+            {
+                if (logStr != "")
+                {
+                    var jsonData = JsonConvert.SerializeObject(model);
+                    LogFile.SaveLogToFile($"閲婃斁澶囨枡鍖哄偍浣嶇姸鎬侊細( {jsonData} ),", logStr);
+                }
+                _arrivalNoticeSvc.UpLocate(model.WareHouseNo,model.LocatNo);
+
+                var data = new HttpReturnModel { Success = "0", Message = "鎴愬姛" };
+
+                if (logStr != "")
+                {
+                    var jsonData = JsonConvert.SerializeObject(data);
+                    LogFile.SaveLogToFile($"閲婃斁澶囨枡鍖哄偍浣嶇姸鎬佽繑鍥炲弬鏁帮細( {jsonData} ),", logStr);
+                }
+                return Ok(data);
+                 
+            }
+            catch (Exception e)
+            {
+                var data = new HttpReturnModel { Success = "0", Message = "澶辫触锛�" + e.Message };
+                if (logStr != "")
+                {
+                    var jsonData = JsonConvert.SerializeObject(data);
+                    LogFile.SaveLogToFile($"閲婃斁澶囨枡鍖哄偍浣嶇姸鎬佽繑鍥炲弬鏁帮細( {jsonData} ),", logStr);
+                }
+                return Ok(data);
+            }
+        }
+
 
         //璐ㄦ缁撴灉涓嬪彂鎺ュ彛 
 
diff --git a/Wms/Wms/Startup.cs b/Wms/Wms/Startup.cs
index 378cf57..3d69d79 100644
--- a/Wms/Wms/Startup.cs
+++ b/Wms/Wms/Startup.cs
@@ -97,6 +97,9 @@
             services.Configure<ApiUrlConfig>(Configuration.GetSection("ApiUrlConfig"));
             //数据库配置
             BaseDbConfig.ConnectionString = Configuration.GetSection("AppSettings:ConnectionString").Value;
+            //MES账号密码
+            MesConfig.MesUser = Configuration.GetSection("MesConfig:MesUser").Value;
+            MesConfig.MesPassWord = Configuration.GetSection("MesConfig:MesPassWord").Value;
 
 
             #region AutoMapper注入
diff --git a/Wms/Wms/Tools/ApiUrlConfig.cs b/Wms/Wms/Tools/ApiUrlConfig.cs
index b80fa6a..7c8a345 100644
--- a/Wms/Wms/Tools/ApiUrlConfig.cs
+++ b/Wms/Wms/Tools/ApiUrlConfig.cs
@@ -57,6 +57,8 @@
         /// </summary>
         public string MesAsnFinishUrl { get; set; }
 
+        public string MesGetTokenUrl { get; set; }
+
         #endregion
 
         #region 涓嬫父绯荤粺
diff --git a/Wms/Wms/appsettings.json b/Wms/Wms/appsettings.json
index 287a51a..f7539d7 100644
--- a/Wms/Wms/appsettings.json
+++ b/Wms/Wms/appsettings.json
@@ -39,8 +39,8 @@
     "GetBoxUrl": "/api/wmsInterface/OutStockTask", //鑾峰彇绠辩爜淇℃伅
 
     //MES
-    "MesAsnFinishUrl": "/api/wmsInterface/OutStockTask",//鍏ュ簱鍗曞叧鍗�
-
+    "MesAsnFinishUrl": "/port/mes/service/mes/save_worder_feedback", //鍏ュ簱鍗曞叧鍗�
+    "MesGetTokenUrl": "/port/mes/service/system/sign_login", //鑾峰彇浠ょ墝
     // 璧嬬爜
 
 
@@ -48,5 +48,11 @@
     "GenAgvSchedulingTask": "http://IP:PORT/rcms/services/rest/hikRpcService/genAgvSchedulingTask", //鐢熸垚浠诲姟鍗曟帴鍙�
     "ContinueTask": "http://IP:PORT/rcms/services/rest/hikRpcService/continueTask", //缁х画鎵ц浠诲姟鎺ュ彛
     "GenPreScheduleTask": "http://IP:PORT/rcms/services/rest/hikRpcService/genPreScheduleTask" // 棰勮皟搴﹀澶栨帴鍙�
+  },
+  "MesConfig": {
+    "MesUser": "wms",
+    "MesPassWord": "wmS@2024"
   }
+
+
 }

--
Gitblit v1.8.0