From e8e8a06fc68a6a645ce32be2cc9c3aaa67a97d68 Mon Sep 17 00:00:00 2001
From: schangxiang@126.com <schangxiang@126.com>
Date: 周三, 17 9月 2025 13:51:36 +0800
Subject: [PATCH] 优化

---
 DEmon/WebWIPAPI/Controllers/MesIntegrController.cs |  343 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 324 insertions(+), 19 deletions(-)

diff --git a/DEmon/WebWIPAPI/Controllers/MesIntegrController.cs b/DEmon/WebWIPAPI/Controllers/MesIntegrController.cs
index 1c2a566..b1f80da 100644
--- a/DEmon/WebWIPAPI/Controllers/MesIntegrController.cs
+++ b/DEmon/WebWIPAPI/Controllers/MesIntegrController.cs
@@ -1,12 +1,18 @@
-锘縰sing iWareDataCore.BASE.Entity;
+锘縰sing AutoMapper;
+using iWareCommon.Common.Entity;
+using iWareCommon.Utils;
+using iWareDataCore.BASE.Entity;
 using iWareDataCore.BASE.Service;
 using Newtonsoft.Json;
+using System;
 using System.Collections.Generic;
+using System.Linq;
+using System.Threading;
 using System.Web.Mvc;
 using WebWIPAPI.Models;
 using WebWIPAPI.Properties;
 using WebWIPAPI.Utils;
-
+using LogTextHelper = WebWIPAPI.Utils.LogTextHelper;
 
 namespace WebWIPAPI.Controllers
 {
@@ -17,35 +23,334 @@
     {
 
         /// <summary>
-        /// 鍚屾绔嬪簱鐨勭墿鏂欎俊鎭�
-        /// WCS>>WIP:姣忓ぉ瀹氭椂WCS鎺ㄩ�佺珛搴撻噷鐨勭墿鏂欎俊鎭�
+        /// 鎻愪緵搴撳瓨淇℃伅
         /// </summary>
-        /// <param name="sysCode"></param>
-        /// <param name="wareHouseInfo"></param>
-        /// <param name="processCardNumber"></param>
-        /// <param name="wareHouseId"></param>
-        /// <param name="timestamp"></param>
         /// <returns></returns>
         [HttpPost]
         public ActionResult syncMaterialInfo()
         {
-            var msg = "";
-            var datalist = PlaceMaterialViewService.GetInstance().GetPlacePreview(out msg);
-
-            var responseMessage = new ApiResponse<List<PlaceMaterialViewEntity>>()
+            var responseMessage = new ApiResponse<List<PlaceMaterialViewEntity>>();
+            try
             {
-                Code = 200,
-                Success = true,
-                Message = "鎴愬姛",
-                Data = datalist,
-            };
-
+                var msg = "";
+                var datalist = PlaceMaterialViewService.GetInstance().GetPlacePreview(out msg);
+                if (!string.IsNullOrEmpty(msg))
+                {
+                    responseMessage = new ApiResponse<List<PlaceMaterialViewEntity>>()
+                    {
+                        Code = 500,
+                        Success = false,
+                        Message = "鑾峰彇寮傚父:" + msg,
+                        Data = null,
+                    };
+                }
+                else
+                {
+                    responseMessage = new ApiResponse<List<PlaceMaterialViewEntity>>()
+                    {
+                        Code = 200,
+                        Success = true,
+                        Message = "鎴愬姛",
+                        Data = datalist,
+                    };
+                }
+            }
+            catch (Exception ex)
+            {
+                responseMessage = new ApiResponse<List<PlaceMaterialViewEntity>>()
+                {
+                    Code = 500,
+                    Success = false,
+                    Message = "寮傚父:" + ex.Message,
+                    Data = null,
+                };
+            }
             //灏嗗璞¤浆鍖栦负json鏍煎紡
             var responseStr = JsonConvert.SerializeObject(responseMessage);
             LogTextHelper.WriteLine(Resources.LogDir, "WIPAPI:{0},{1}, {2}", "syncMaterialInfo", "璇锋眰鍙傛暟锛�" + "", "鍝嶅簲淇℃伅;" + responseStr);
             return Json(responseMessage, JsonRequestBehavior.DenyGet);
         }
 
+        /// <summary>
+        /// 瀵煎叆鍏ュ簱鍗�
+        /// </summary>
+        /// <param name="inputmaterials"></param>
+        /// <returns></returns>
+        [HttpPost]
+        public ActionResult importInOrder(List<MaterialViewForMesEntity> importMaterials)
+        {
+            var responseMessage = new ApiResponse<string>();
+            var msg = "";
+
+            try
+            {
+                #region 楠岃瘉
+                if (importMaterials?.Count() == 0)
+                {
+                    responseMessage = new ApiResponse<string>()
+                    {
+                        Code = 500,
+                        Success = false,
+                        Message = "鏁版嵁鏉℃暟涓�0",
+                        Data = null,
+                    };
+                    return ApiResponseHelper.ReturnApiResponse(responseMessage, "importInOrder", "");
+                }
+                if (importMaterials.Select(x => x.ListNo).Distinct().Count() != 1)
+                {
+                    responseMessage = new ApiResponse<string>()
+                    {
+                        Code = 500,
+                        Success = false,
+                        Message = "鏈璇锋眰鍗曞彿蹇呴』涓哄悓涓�鍊�",
+                        Data = null,
+                    };
+                    return ApiResponseHelper.ReturnApiResponse(responseMessage, "importInOrder", "");
+                }
+                #endregion
+
+                #region 涓氬姟澶勭悊
+
+                //绗竴姝ワ細鍏堟柊澧炲埌鐗╂枡鍩虹琛�
+                List<MaterialViewEntity> materials = new List<MaterialViewEntity>();
+
+                materials = ClassHelper.RotationMapping_Json<List<MaterialViewEntity>, List<MaterialViewForMesEntity>>(importMaterials);
+
+
+                MaterialViewService.GetInstance().ImportExcelFromMes(materials, out msg);
+                if (!string.IsNullOrEmpty(msg))
+                {
+                    responseMessage = new ApiResponse<string>()
+                    {
+                        Code = 500,
+                        Success = false,
+                        Message = "鏂板鍒扮墿鏂欏熀纭�琛ㄥ紓甯�:" + msg,
+                        Data = null,
+                    };
+                }
+                else
+                {
+                    Thread.Sleep(400);//娉ㄦ剰锛氫紤鐪犳绉掞紝鐢ㄤ簬鏁版嵁搴撲簨鍔℃彁浜�
+
+                    string typeName = "鍏ュ簱";
+                    List<InputMaterialEntity> inputmaterials = new List<InputMaterialEntity>();
+                    inputmaterials = ClassHelper.RotationMapping_Json<List<InputMaterialEntity>, List<MaterialViewForMesEntity>>(importMaterials);
+                    handler_importOutOrder(typeName, inputmaterials, out msg);
+
+                    #endregion
+
+                    if (!string.IsNullOrEmpty(msg))
+                    {
+                        responseMessage = new ApiResponse<string>()
+                        {
+                            Code = 500,
+                            Success = false,
+                            Message = "鐢熸垚鍏ュ簱浠诲姟寮傚父:" + msg,
+                            Data = null,
+                        };
+                    }
+                    else
+                    {
+                        responseMessage = new ApiResponse<string>()
+                        {
+                            Code = 200,
+                            Success = true,
+                            Message = "鎴愬姛",
+                            Data = null,
+                        };
+                    }
+                }
+
+            }
+            catch (Exception ex)
+            {
+                responseMessage = new ApiResponse<string>()
+                {
+                    Code = 500,
+                    Success = false,
+                    Message = "寮傚父:" + ex.Message,
+                    Data = null,
+                };
+            }
+
+            return ApiResponseHelper.ReturnApiResponse(responseMessage, "importInOrder", "");
+        }
+
+
+        /// <summary>
+        /// 瀵煎叆鍑哄簱鍗�
+        /// </summary>
+        /// <param name="inputmaterials"></param>
+        /// <returns></returns>
+        [HttpPost]
+        public ActionResult importOutOrder(List<InputMaterialEntity> inputmaterials)
+        {
+            var responseMessage = new ApiResponse<string>();
+            try
+            {
+                var msg = "";
+
+                #region 楠岃瘉
+                if (inputmaterials?.Count() == 0)
+                {
+                    responseMessage = new ApiResponse<string>()
+                    {
+                        Code = 500,
+                        Success = false,
+                        Message = "鏁版嵁鏉℃暟涓�0",
+                        Data = null,
+                    };
+                    return ApiResponseHelper.ReturnApiResponse(responseMessage, "importOutOrder", "");
+                }
+                if (inputmaterials.Select(x => x.ListNo).Distinct().Count() != 1)
+                {
+                    responseMessage = new ApiResponse<string>()
+                    {
+                        Code = 500,
+                        Success = false,
+                        Message = "鏈璇锋眰鍗曞彿蹇呴』涓哄悓涓�鍊�",
+                        Data = null,
+                    };
+                    return ApiResponseHelper.ReturnApiResponse(responseMessage, "importOutOrder", "");
+                }
+                #endregion
+
+                #region 涓氬姟澶勭悊
+
+                string typeName = "鍑哄簱";
+                handler_importOutOrder(typeName, inputmaterials, out msg);
+
+                #endregion
+
+                if (!string.IsNullOrEmpty(msg))
+                {
+                    responseMessage = new ApiResponse<string>()
+                    {
+                        Code = 500,
+                        Success = false,
+                        Message = "鐢熸垚鍑哄簱浠诲姟寮傚父:" + msg,
+                        Data = null,
+                    };
+                }
+                else
+                {
+                    responseMessage = new ApiResponse<string>()
+                    {
+                        Code = 200,
+                        Success = true,
+                        Message = "鎴愬姛",
+                        Data = null,
+                    };
+                }
+
+            }
+            catch (Exception ex)
+            {
+                responseMessage = new ApiResponse<string>()
+                {
+                    Code = 500,
+                    Success = false,
+                    Message = "寮傚父:" + ex.Message,
+                    Data = null,
+                };
+            }
+
+            return ApiResponseHelper.ReturnApiResponse(responseMessage, "importOutOrder", "");
+        }
+
+
+        /// <summary>
+        /// 鍏叡瀵煎叆 鍏ュ簱鍗曟垨鍑哄簱鍗�
+        /// </summary>
+        /// <param name="typeName"></param>
+        /// <param name="inputmaterials"></param>
+        /// <param name="msg"></param>
+        private void handler_importOutOrder(string typeName, List<InputMaterialEntity> inputmaterials, out string msg)
+        {
+            try
+            {
+                #region 涓氬姟澶勭悊
+
+                msg = "";
+                //var inputmaterials = InputMaterialService.GetInstance().QueryByParam(new QueryParam { Filter = new Dictionary<string, object> { { "Status", "鏈敓鎴�" } } }, out msg);
+                if (inputmaterials != null && inputmaterials.Count > 0)
+                {
+                    var placeMaterial = PlaceMaterialViewService.GetInstance().QueryByParam(new QueryParam { }, out msg);
+                    var inoutdetails = InOutListDetailViewService.GetInstance().QueryByParam(new QueryParam { }, out msg);
+                    List<string> codes = new List<string>();
+                    inputmaterials.ForEach(x => codes.Add(x.Code));
+                    List<int> ids = new List<int>();
+                    var materials = InputMaterialService.GetInstance().GetIds(codes);
+                    List<InOutListDetailEntity> detail = new List<InOutListDetailEntity>();
+                    for (int i = 0; i < materials.Count; i++)
+                    {
+                        if (typeName == "鍏ュ簱")
+                        {
+
+                            if (placeMaterial.Select(x => x.MaterialId).Contains(materials[i].id))
+                            {
+                                msg = materials[i].code + "宸插瓨鍦ㄧ珛搴撲腑锛屼笉鑳芥坊鍔犲埌鍏ュ簱鍗曟槑缁嗕腑锛�";
+                                break;
+                            }
+                            if (inoutdetails.Select(x => x.MaterialId).Contains(materials[i].id))
+                            {
+                                msg = materials[i].code + "宸插瓨鍦ㄤ箣鍓嶇殑鍏ュ簱鍗曟槑缁嗕腑锛屼笉鑳芥坊鍔犲埌褰撳墠鍏ュ簱鍗曟槑缁嗕腑锛�";
+                                break;
+                            }
+
+                        }
+                        else
+                        {
+                            if (!placeMaterial.Select(x => x.MaterialId).Contains(materials[i].id))
+                            {
+                                msg = materials[i].code + "涓嶅湪绔嬪簱涓紝涓嶈兘娣诲姞鍒板嚭搴撳崟鏄庣粏涓紒";
+                                break;
+                            }
+                            if (inoutdetails.Select(x => x.MaterialId).Contains(materials[i].id))
+                            {
+                                var inoutdeta = inoutdetails.FirstOrDefault(x => x.MaterialId == materials[i].id);
+                                if (inoutdeta.TypeName == "鍑哄簱")
+                                {
+                                    msg = materials[i].name + "宸插瓨鍦ㄤ箣鍓嶇殑鍑哄簱鍗曟槑缁嗕腑锛屼笉鑳芥坊鍔犲埌褰撳墠鍑哄簱鍗曟槑缁嗕腑锛�";
+                                    break;
+                                }
+                            }
+                        }
+                        InOutListDetailEntity inoutdetail = new InOutListDetailEntity()
+                        {
+                            MaterialId = materials[i].id,
+                            IsFinish = 0
+                        };
+                        detail.Add(inoutdetail);
+                    }
+                    if (!string.IsNullOrEmpty(msg))
+                    {
+                        return;
+                    }
+                    InOutListService.GetInstance().CreateListAndDetial(
+                        new InOutListEntity
+                        {
+                            ListNo = inputmaterials.First().ListNo,
+                            CreateTime = DateTime.Now,
+                            TypeName = typeName,
+                            Status = 0,
+                            Remark = "",
+                            InOutListDetail = detail
+                        }, out msg);
+                }
+                else
+                {
+                    msg = ("璇峰厛纭繚鍑哄叆搴撳崟鐗╂枡鏄庣粏涓嶄负绌猴紒");
+                }
+
+
+                #endregion
+            }
+            catch (Exception)
+            {
+                throw;
+            }
+        }
 
     }
 }

--
Gitblit v1.9.3