From e5d3f5d9e36d78a8383fbe0de3a0f818b4df203c Mon Sep 17 00:00:00 2001
From: 快乐的昕的电脑 <快乐的昕的电脑@DESKTOP-C2BQPQU>
Date: 星期四, 27 十一月 2025 14:20:01 +0800
Subject: [PATCH] 仓库信息

---
 MES.Service/service/BasicData/MesDepotsManager.cs |   98 +++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 87 insertions(+), 11 deletions(-)

diff --git a/MES.Service/service/BasicData/MesDepotsManager.cs b/MES.Service/service/BasicData/MesDepotsManager.cs
index 1a6bee0..9fa8176 100644
--- a/MES.Service/service/BasicData/MesDepotsManager.cs
+++ b/MES.Service/service/BasicData/MesDepotsManager.cs
@@ -76,25 +76,82 @@
         throw new NotImplementedException("鍙嶅鏍稿け璐�");
     }
 
-    // 鎻掑叆鎴栨洿鏂颁粨搴撶殑鏂规硶
+    /// <summary>
+    /// 鍚屾鐗╂枡淇℃伅new_0/4
+    /// </summary>
+    /// <param name="db"></param>
+    /// <param name="entity"></param>
+    /// <returns></returns>
     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)
+        {
+            // 鏂板鎯呭喌锛氱敓鎴愭柊ID骞舵彃鍏�
+            var newId = GenerateNewId();
+            entity.DepotId = newId;
+            entity.Guid = newId.ToString();
+            return db.Insertable(entity).ExecuteCommand() > 0;
+        }
+        else
+        {
+            // 鏇存柊鎯呭喌锛氬垹闄ゅ悗閲嶆柊鎻掑叆锛屼繚鎸佸師鏈塈D
+            var originalId = entity.DepotId;
+
+            // 鍏堝垹闄ゅ師璁板綍锛堝鏋滃瓨鍦級
+            db.Deleteable<MesDepots>().Where(s => s.DepotId == originalId).ExecuteCommand();
+
+            // 閲嶆柊鎻掑叆锛屼繚鎸佸師鏈塈D
+            entity.DepotId = originalId;
+            entity.Guid = originalId.ToString();
+            return db.Insertable(entity).ExecuteCommand() > 0;
+        }
+    }
+
+    // 鎻掑叆鎴栨洿鏂颁粨搴撶殑鏂规硶
+    //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;
+    //}
+
+    /// <summary>
+    /// 鐢熸垚鏂扮殑ID锛岀‘淇濅笉閲嶅
+    /// </summary>
+    private decimal GenerateNewId()
+    {
+        // 澶勭悊绌鸿〃鐨勬儏鍐碉紝浠�1寮�濮�
+        var maxId = Db.Queryable<MesDepots>().Max(x => (decimal?)x.DepotId) ?? 0;
+        var newId = maxId + 1;
+
+        // 鍙岄噸妫�鏌ワ紝纭繚鐢熸垚鐨処D涓嶅瓨鍦�
+        while (Db.Queryable<MesDepots>().Where(x => x.DepotId == newId).Any())
+        {
+            newId++;
+        }
+
+        return newId;
     }
 
     // 灏� ErpDepots 瀵硅薄杞崲涓� MesDepots 瀵硅薄鐨勬柟娉�
     private MesDepots GetMesDepots(ErpDepots depots)
     {
-        return new MesDepots
+        // 鏌ユ壘鏄惁宸插瓨鍦ㄧ浉鍚岀紪鐮佺殑璁板綍銆�
+        var existingCustomer = Db.Queryable<MesDepots>()
+            .Where(s => s.DepotCode == depots.FNumber)
+            .First();
+
+        var entity = new MesDepots
         {
-            Guid = depots.Id,
+            // 濡傛灉瀛樺湪锛屼娇鐢ㄧ幇鏈夌殑ID锛屽悗缁皢鍒犻櫎鍚庨噸鏂版彃鍏�
+            // 濡傛灉涓嶅瓨鍦紝璁句负0锛孖nsertOrUpdate鏂规硶灏嗙敓鎴愭柊ID
+            DepotId = existingCustomer?.DepotId ?? 0,
+            //DepotId = Convert.ToDecimal(depots.Id),
+            Guid = existingCustomer?.Guid ?? string.Empty,
             DepotCode = depots.FNumber,
             DepotName = depots.FName,
-            DepotId = Convert.ToDecimal(depots.Id),
             IsFkc = depots.FAllowMinusQty,
             CreateBy = depots.FPrincipal,
             Depottype = depots.FStockProperty,
@@ -102,15 +159,34 @@
             Zuid = depots.FGroup,
             FSubsidiary = depots.FUseOrgId,
             Fumbrella = depots.FCreateOrgId,
-            CreateDate = DateTime.Now,
+            // 濡傛灉瀛樺湪锛屼娇鐢ㄧ幇鏈夌殑CreateDate锛屽悗缁皢鍒犻櫎鍚庨噸鏂版彃鍏�
+            // 濡傛灉涓嶅瓨鍦紝璁句负褰撳墠鏃堕棿
+            CreateDate = existingCustomer?.CreateDate ?? DateTime.Now,
             LastupdateDate = DateTime.Now,
             SupplierId = depots.FSUPPLIERID,
             ClientId = depots.ClientId,
             Department = depots.Fdeptid,
             Phone = depots.Phone,
             Company = "1000",
-            Factory = "1000"
+            Factory = depots.Factory??"1000",
+            Remark3 = depots.remark3,
+            Remark4 = depots.remark4,
+            Remark5 = depots.remark5,
         };
+        // ERP: 0=鏈鐢�, 1=绂佺敤
+        // MES: A=鏈鐢�, B=绂佺敤
+        if (string.IsNullOrEmpty(depots.FForbidStatus))
+        {
+            entity.IsNg = "A";
+        }
+        else
+        {
+            //鎴戞湡鏈涚殑鍊兼槸A=鍚�,B=鏄�
+            //瀹為檯缁欐垜鐨勫�兼槸0鎴�1锛屾垜甯屾湜涓烘垜杞崲浠嶢鍜孊鐨勬柟寮�
+            entity.IsNg = depots.FForbidStatus == "1" ? "B" : "A";
+        }
+
+        return entity;
     }
 
     // SaveList 鏂规硶鐢ㄤ簬淇濆瓨澶氫釜浠撳簱璁板綍锛屾牴鎹被鍨嬫壒閲忔墽琛屼笉鍚岀殑鎿嶄綔

--
Gitblit v1.9.3