From ef97dd26551b647ca7b0525b1e1c38672f6737a4 Mon Sep 17 00:00:00 2001
From: wxw <Administrator@DESKTOP-5BIMHQ3>
Date: 星期五, 13 十二月 2024 09:20:49 +0800
Subject: [PATCH] 修改问题

---
 Wms/WMS.BLL/SysServer/PalletsServer.cs |  141 ++++++++++++++++++++++++++++++++---------------
 1 files changed, 96 insertions(+), 45 deletions(-)

diff --git a/Wms/WMS.BLL/SysServer/PalletsServer.cs b/Wms/WMS.BLL/SysServer/PalletsServer.cs
index adbdd82..622d79e 100644
--- a/Wms/WMS.BLL/SysServer/PalletsServer.cs
+++ b/Wms/WMS.BLL/SysServer/PalletsServer.cs
@@ -5,11 +5,13 @@
 using System.Text;
 using System.Threading;
 using System.Threading.Tasks;
+using Model.InterFaceModel;
 using Model.ModelDto.LogDto;
 using Model.ModelDto.SysDto;
 using SqlSugar;
 using WMS.BLL.LogServer;
 using WMS.Entity.Context;
+using WMS.Entity.DataEntity;
 using WMS.Entity.SysEntity;
 using WMS.IBLL.ILogServer;
 using WMS.IBLL.ISysServer;
@@ -111,62 +113,111 @@
             }
         }
 
-        public async Task<bool> AddPallets(int groupCount, int userId)
+        /// <summary>
+        /// 娣诲姞妗朵俊鎭苟澧炲姞搴撳瓨
+        /// </summary>
+        /// <param name="palletNo"></param>
+        /// <param name="locatNo"></param>
+        /// <param name="userId"></param>
+        /// <exception cref="Exception"></exception>
+        public void AddPallets(string palletNo,string locatNo,int userId)
         {
+            var db = DataContext.Db;
             try
-            {
-                var db = DataContext.Db;
-                if (groupCount <= 0)
+            {                
+                if (string.IsNullOrEmpty(palletNo))
                 {
-                    throw new Exception("缁勬暟闇�澶т簬0");
+                    throw new Exception("璇疯緭鍏ユ《鍙�");
                 }
-
-                var pallNo = db.Queryable<SysPallets>().Max(m => m.PalletNo);
-
-                var str = pallNo.Substring(3, 5);
-                string remove = pallNo.Substring(0, 3);
-                int sibelius = Convert.ToInt16(str);
-                var num = 0;
-                for (int i = 0; i < groupCount; i++)
+                if (string.IsNullOrEmpty(locatNo))
                 {
-                    sibelius += 1;
-                    if (sibelius>99999)
-                    {
-                        throw new Exception("鎵樼洏鐮佷綅鏁板凡杈句笂绾�");
-                    }
-                    string code = remove + Convert.ToString(sibelius).PadLeft(5, '0');
-                    if (db.Queryable<SysPallets>().Count(m=>m.PalletNo == code)>=1)
-                    {
-                        continue;
-                    }
-                    var item = new SysPallets
-                    {
-                        PalletNo = code,
-                        Status = "0",
-                        Type = "0",
-                        CreateUser = userId
-                    };
-                    Thread.Sleep(100);
-                    num += db.Insertable(item).ExecuteCommand();
-                    if (num > 0)
-                    {
-                        if (groupCount > 1)
-                        {
-                            await _operation.InsertOperation("浠撳簱璁剧疆", "鏉$爜绠$悊", item.PalletNo, "鎵归噺娣诲姞", "鎵归噺娣诲姞鎵樼洏淇℃伅 鎵樼洏鍙凤細" + item.PalletNo, userId);
-                        }
-                        else
-                        {
-                            await _operation.InsertOperation("浠撳簱璁剧疆", "鏉$爜绠$悊", item.PalletNo, "娣诲姞", "娣诲姞鎵樼洏淇℃伅 鎵樼洏鍙凤細" + item.PalletNo, userId);
-                        }
-                        
-                    }
+                    throw new Exception("璇疯緭鍏ュ偍浣嶅湴鍧�");
                 }
+                var palletModel = db.Queryable<SysPallets>().First(w => w.PalletNo == palletNo && w.IsDel == "0");
+                if (palletModel != null)
+                {
+                    throw new Exception("璇ユ《鍙峰凡瀛樺湪");
+                }
+                var locatModel= db.Queryable<SysStorageLocat>().First(w => w.LocatNo == locatNo && w.IsDel == "0");
+                if (locatModel == null)
+                {
+                    throw new Exception("鍌ㄤ綅鍦板潃涓嶅瓨鍦�");
+                }
+                if (locatModel.Status != "0")
+                {
+                    throw new Exception("璇ュ偍浣嶅湴鍧�闈炵┖闂茬姸鎬�");
+                }
+                var areaModel = db.Queryable<SysStorageArea>().First(w => w.IsDel == "0" && w.AreaNo == locatModel.AreaNo);
+                if (areaModel == null)
+                {
+                    throw new Exception("鍌ㄤ綅鍦板潃鎵�灞炲尯鍩熶笉瀛樺湪");
+                }
+                if (!areaModel.AreaName.Contains("鍑�妗�"))
+                {
+                    throw new Exception("鏂版坊鍔犵殑妗跺彧鑳界粦瀹氬噣妗跺尯");
+                }
+                //寮�鍚簨鍔�
+                db.BeginTran();
 
-                return num > 0;
+                palletModel = new SysPallets();
+                palletModel.PalletNo = palletNo;
+                palletModel.Type = "0";
+                palletModel.Status = "0";
+                palletModel.CreateUser = userId;
+                //娣诲姞妗�
+                db.Insertable(palletModel).ExecuteCommand();
 
+                var comTime = DateTime.Now;
+                var model = new DataStockDetail()
+                {
+                    ASNNo = "",
+                    Qty = 0,
+                    LockQty = 0,
+                    FrozenQty = 0,
+                    InspectQty = 0,
+                    WareHouseNo = locatModel.WareHouseNo,//鎵�灞炰粨搴�
+                    RoadwayNo = "",//鎵�灞炲贩閬�
+                    AreaNo = locatModel.AreaNo,//鎵�灞炲尯鍩�
+                    LocatNo = locatModel.LocatNo,//鍌ㄤ綅鍦板潃
+                    PalletNo = palletNo,
+                    PalletNo2 = "",
+                    PalletNo3 = "",
+                    PalletTags = "0",
+                    CompleteTime = comTime,
+                    ProductionTime = null,
+                    ExpirationTime = null,
+                    Status = "0",
+                    InspectMark = "0",
+                    InspectStatus = "0",//寰呮楠�
+                    BitPalletMark = "0",
+                    PackagNo = "",
+                    IsBale = "0",
+                    IsBelt = "0",
+
+                    SkuNo = "",
+                    SkuName = "",
+                    LotNo = "",
+
+                    PalletStatus = "0",//鍑�妗�
+
+                    IsDel = "0",
+                    CreateUser = userId,
+                    CreateTime = comTime
+                };
+                //鎻掑叆搴撳瓨鏄庣粏
+                db.Insertable(model).ExecuteCommand();
+
+                //鏇存柊鍌ㄤ綅鐘舵��
+                locatModel.Status = "1";//鏈夌墿鍝�
+                db.Updateable(locatModel).ExecuteCommand();
+
+                //鎻愪氦浜嬪姟
+                db.CommitTran();
             }
             catch (Exception e)
             {
+                //鍥炴粴浜嬪姟
+                db.RollbackTran();
                 throw new Exception(e.Message);
             }
         }

--
Gitblit v1.8.0