From ab01d75a3fbc8467d81a895cba5d6dde76fbe053 Mon Sep 17 00:00:00 2001
From: 啊鑫 <t2856754968@163.com>
Date: 星期二, 16 九月 2025 23:29:30 +0800
Subject: [PATCH] 1111

---
 MES.Service/service/BasicData/MesDepotsManager.cs |   96 +++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 74 insertions(+), 22 deletions(-)

diff --git a/MES.Service/service/BasicData/MesDepotsManager.cs b/MES.Service/service/BasicData/MesDepotsManager.cs
index 1c5745a..d18ed52 100644
--- a/MES.Service/service/BasicData/MesDepotsManager.cs
+++ b/MES.Service/service/BasicData/MesDepotsManager.cs
@@ -1,4 +1,5 @@
-锘縰sing MES.Service.DB;
+锘縰sing Masuit.Tools;
+using MES.Service.DB;
 using MES.Service.Dto.webApi;
 using MES.Service.Modes;
 using SqlSugar;
@@ -42,7 +43,7 @@
     }
 
     // 鏇存柊浠撳簱鐘舵�佺殑鏂规硶
-    private bool UpdateDepotStatus(SqlSugarScope db, long depotId,
+    private bool UpdateDepotStatus(SqlSugarScope db, decimal depotId,
         string status)
     {
         var result = db.Updateable<MesDepots>()
@@ -76,14 +77,46 @@
         throw new NotImplementedException("鍙嶅鏍稿け璐�");
     }
 
+    /// <summary>
+    /// 鐢熸垚鏂扮殑DepotId锛岀‘淇濅笉閲嶅
+    /// </summary>
+    private decimal GenerateNewId()
+    {
+        // 澶勭悊绌鸿〃鐨勬儏鍐碉紝浠�1寮�濮�
+        var maxId = Db.Queryable<MesDepots>().Max(x => (decimal?)x.DepotId) ?? 0;
+        var newId = maxId + 1;
+        
+        // 鍙岄噸妫�鏌ワ紝纭繚鐢熸垚鐨凞epotId涓嶅瓨鍦�
+        while (Db.Queryable<MesDepots>().Where(x => x.DepotId == newId).Any())
+        {
+            newId++;
+        }
+        
+        return newId;
+    }
+
     // 鎻掑叆鎴栨洿鏂颁粨搴撶殑鏂规硶
     private bool InsertOrUpdate(SqlSugarScope db, MesDepots entity)
     {
-        db.Deleteable<MesDepots>()
-            .Where(s => s.DepotId == entity.DepotId)
-            .ExecuteCommand();
-        var insert = db.Insertable(entity).ExecuteCommand();
-        return insert > 0;
+        if (entity.DepotId == 0)
+        {
+            // 鏂板鎯呭喌锛氱敓鎴愭柊DepotId骞舵彃鍏�
+            var newId = GenerateNewId();
+            entity.DepotId = newId;
+            return db.Insertable(entity).IgnoreColumns(ignoreNullColumn:true).ExecuteCommand() > 0;
+        }
+        else
+        {
+            // 鏇存柊鎯呭喌锛氬垹闄ゅ悗閲嶆柊鎻掑叆锛屼繚鎸佸師鏈塂epotId
+            var originalId = entity.DepotId;
+            
+            // 鍏堝垹闄ゅ師璁板綍锛堝鏋滃瓨鍦級
+            db.Deleteable<MesDepots>().Where(s => s.DepotId == originalId).ExecuteCommand();
+            
+            // 閲嶆柊鎻掑叆锛屼繚鎸佸師鏈塂epotId
+            entity.DepotId = originalId;
+            return db.Insertable(entity).IgnoreColumns(ignoreNullColumn:true).ExecuteCommand() > 0;
+        }
     }
 
     // 灏� ErpDepots 瀵硅薄杞崲涓� MesDepots 瀵硅薄鐨勬柟娉�
@@ -93,35 +126,54 @@
         {
             DepotCode = depots.FNumber,
             DepotName = depots.FName,
-            DepotId = string.IsNullOrEmpty(depots.Id)
-                ? DateTimeOffset.UtcNow.ToUnixTimeSeconds()
-                : long.Parse(depots.Id),
             IsFkc = depots.FAllowMinusQty,
             CreateBy = depots.FPrincipal,
             Depottype = depots.FStockProperty,
-            IsNg = depots.FForbidStatus,
             Zuid = depots.FGroup,
             DocumentStatus = depots.FDocumentStatus,
             
-            UseOrg = string.IsNullOrEmpty(depots.FUseOrgId)
-                ? 1
-                : long.Parse(depots.FUseOrgId),
-            CreateOrg = string.IsNullOrEmpty(depots.FCreateOrgId)
-                ? 1
-                : long.Parse(depots.FCreateOrgId),
-            CreateDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
-            LastupdateDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
+            IsNg = "A",
+            FSubsidiary = "1",
+            Fumbrella = "1",
+            // IsNg = depots.FForbidStatus,
+            // FSubsidiary = string.IsNullOrEmpty(depots.FUseOrgId)
+            //     ? "1"
+            //     :  depots.FUseOrgId,
+            // Fumbrella = string.IsNullOrEmpty(depots.FCreateOrgId)
+            //     ? "1"
+            //     : depots.FCreateOrgId,
+            CreateDate = DateTime.Now,
+            LastupdateDate = DateTime.Now,
             Company = "1000",
             Factory = "1000"
         };
+        
+        //IsNg = depots.FForbidStatus,
+        if (depots.FForbidStatus.IsNullOrEmpty())
+        {
+            entity.IsNg = "A";
+        }
+        else
+        {
+            //鎴戞湡鏈涚殑鍊兼槸A=鍚�,B=鏄�
+            //瀹為檯缁欐垜鐨勫�兼槸0鎴�1锛屾垜甯屾湜涓烘垜杞崲浠嶢鍜孊鐨勬柟寮�
+            entity.IsNg = depots.FForbidStatus == "1" ? "B" : "A";
+        }
 
-        var mesDepots = Db.Queryable<MesDepots>()
+        // 鏌ユ壘鏄惁宸插瓨鍦ㄧ浉鍚屼粨搴撶紪鐮佺殑璁板綍
+        var existingDepot = Db.Queryable<MesDepots>()
             .Where(s => s.DepotCode == entity.DepotCode)
             .First();
 
-        if (mesDepots != null)
+        if (existingDepot != null)
         {
-            entity.DepotId = mesDepots.DepotId;
+            // 濡傛灉瀛樺湪锛屼娇鐢ㄧ幇鏈夌殑DepotId锛屽悗缁皢鍒犻櫎鍚庨噸鏂版彃鍏�
+            entity.DepotId = existingDepot.DepotId;
+        }
+        else
+        {
+            // 濡傛灉涓嶅瓨鍦紝璁句负0锛孖nsertOrUpdate鏂规硶灏嗙敓鎴愭柊DepotId
+            entity.DepotId = 0;
         }
 
         return entity;

--
Gitblit v1.9.3