From 1cd100eb5bd01a1a7c49008fe0899965aa58ca9c Mon Sep 17 00:00:00 2001
From: 快乐的昕的电脑 <快乐的昕的电脑@DESKTOP-C2BQPQU>
Date: 星期四, 27 十一月 2025 17:04:30 +0800
Subject: [PATCH] 岗位信息

---
 MES.Service/service/BasicData/MesPositionManager.cs |  103 +++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 91 insertions(+), 12 deletions(-)

diff --git a/MES.Service/service/BasicData/MesPositionManager.cs b/MES.Service/service/BasicData/MesPositionManager.cs
index 6b67858..a108107 100644
--- a/MES.Service/service/BasicData/MesPositionManager.cs
+++ b/MES.Service/service/BasicData/MesPositionManager.cs
@@ -57,14 +57,43 @@
         throw new NotImplementedException(status == "A" ? "鍚敤澶辫触" : "绂佺敤澶辫触");
     }
 
-    // 鎻掑叆鎴栨洿鏂板矖浣嶇殑鏂规硶
+    /// <summary>
+    /// 鍚屾鐗╂枡淇℃伅new_0/4
+    /// </summary>
+    /// <param name="db"></param>
+    /// <param name="entity"></param>
+    /// <returns></returns>
     private bool InsertOrUpdatePosition(SqlSugarScope db, MesPosition entity)
     {
-        db.Deleteable<MesPosition>()
-            .Where(s => s.Id == entity.Id).ExecuteCommand();
-        var insert = db.Insertable(entity).ExecuteCommand();
-        return insert > 0;
+        if (entity.Id == 0)
+        {
+            // 鏂板鎯呭喌锛氱敓鎴愭柊ID骞舵彃鍏�
+            var newId = GenerateNewId();
+            entity.Id = newId;
+            return db.Insertable(entity).ExecuteCommand() > 0;
+        }
+        else
+        {
+            // 鏇存柊鎯呭喌锛氬垹闄ゅ悗閲嶆柊鎻掑叆锛屼繚鎸佸師鏈塈D
+            var originalId = entity.Id;
+
+            // 鍏堝垹闄ゅ師璁板綍锛堝鏋滃瓨鍦級
+            db.Deleteable<MesPosition>().Where(s => s.Id == originalId).ExecuteCommand();
+
+            // 閲嶆柊鎻掑叆锛屼繚鎸佸師鏈塈D
+            entity.Id = originalId;
+            return db.Insertable(entity).ExecuteCommand() > 0;
+        }
     }
+
+    // 鎻掑叆鎴栨洿鏂板矖浣嶇殑鏂规硶
+    //private bool InsertOrUpdatePosition(SqlSugarScope db, MesPosition entity)
+    //{
+    //    db.Deleteable<MesPosition>()
+    //        .Where(s => s.Id == entity.Id).ExecuteCommand();
+    //    var insert = db.Insertable(entity).ExecuteCommand();
+    //    return insert > 0;
+    //}
 
     // 鍒犻櫎宀椾綅鐨勬柟娉�
     private bool DeletePosition(SqlSugarScope db, decimal positionId)
@@ -77,12 +106,38 @@
         throw new NotImplementedException("鍒犻櫎澶辫触");
     }
 
+    /// <summary>
+    /// 鐢熸垚鏂扮殑ID锛岀‘淇濅笉閲嶅
+    /// </summary>
+    private decimal GenerateNewId()
+    {
+        // 澶勭悊绌鸿〃鐨勬儏鍐碉紝浠�1寮�濮�
+        var maxId = Db.Queryable<MesPosition>().Max(x => (decimal?)x.Id) ?? 0;
+        var newId = maxId + 1;
+
+        // 鍙岄噸妫�鏌ワ紝纭繚鐢熸垚鐨処D涓嶅瓨鍦�
+        while (Db.Queryable<MesPosition>().Where(x => x.Id == newId).Any())
+        {
+            newId++;
+        }
+
+        return newId;
+    }
+
     // 灏� ErpPosition 瀵硅薄杞崲涓� MesPosition 瀵硅薄鐨勬柟娉�
     private MesPosition GetMesPosition(ErpPosition position)
     {
-        return new MesPosition
-        {
-            Id = Convert.ToDecimal(position.Id),
+        // 鏌ユ壘鏄惁宸插瓨鍦ㄧ浉鍚岀紪鐮佺殑璁板綍銆�
+        var existingCustomer = Db.Queryable<MesPosition>()
+            .Where(s => s.PositionId == position.FNumber)
+            .First();
+
+        var entity = new MesPosition
+        {            
+            // 濡傛灉瀛樺湪锛屼娇鐢ㄧ幇鏈夌殑ID锛屽悗缁皢鍒犻櫎鍚庨噸鏂版彃鍏�
+            // 濡傛灉涓嶅瓨鍦紝璁句负0锛孖nsertOrUpdate鏂规硶灏嗙敓鎴愭柊ID
+            Id = existingCustomer?.Id ?? 0,
+            //Id = Convert.ToDecimal(position.Id),
             PositionId = position.FNumber,
             PositionName = position.FName,
             PositionDescription = position.FDESCRIPTIONS,
@@ -90,16 +145,40 @@
             Fforbidstatus = position.FForbidStatus,
             FUseOrgId = position.FUseOrgId,
             FCreateOrgId = position.FCreateOrgId,
-            CreationDate = position.FCreateDate != null
-                ? DateTime.ParseExact(position.FCreateDate,
-                    "yyyy-MM-dd HH:mm:ss", null)
-                : null,
+            //// 濡傛灉瀛樺湪锛屼娇鐢ㄧ幇鏈夌殑CreateDate锛屽悗缁皢鍒犻櫎鍚庨噸鏂版彃鍏�
+            //// 濡傛灉涓嶅瓨鍦紝璁句负褰撳墠鏃堕棿
+            //CreationDate = existingCustomer?.CreationDate ?? DateTime.Now,
+
+            //濡傛灉瀛樺湪锛屼娇鐢ㄧ幇鏈夌殑CreateDate锛屽悗缁皢鍒犻櫎鍚庨噸鏂版彃鍏�
+            // 濡傛灉涓嶅瓨鍦紝璁句负褰撳墠鏃堕棿锛堟牸寮忎负 yyyy - MM - dd HH:mm: ss锛�
+            CreationDate = existingCustomer?.CreationDate
+            ?? DateTime.ParseExact(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "yyyy-MM-dd HH:mm:ss", null),
+
+            //CreationDate = position.FCreateDate != null
+            //    ? DateTime.ParseExact(position.FCreateDate,
+            //        "yyyy-MM-dd HH:mm:ss", null)
+            //    : null,
             DisabledBy = position.FForbidderId,
             DisabledDate = position.FForbidDate != null
                 ? DateTime.ParseExact(position.FForbidDate,
                     "yyyy-MM-dd HH:mm:ss", null)
                 : null
         };
+
+        // ERP: 0=鏈鐢�, 1=绂佺敤
+        // MES: A=鏈鐢�, B=绂佺敤
+        if (string.IsNullOrEmpty(position.FForbidStatus))
+        {
+            entity.Fforbidstatus = "A";
+        }
+        else
+        {
+            //鎴戞湡鏈涚殑鍊兼槸A=鍚�,B=鏄�
+            //瀹為檯缁欐垜鐨勫�兼槸0鎴�1锛屾垜甯屾湜涓烘垜杞崲浠嶢鍜孊鐨勬柟寮�
+            entity.Fforbidstatus = position.FForbidStatus == "1" ? "B" : "A";
+        }
+
+        return entity;
     }
 
     // SaveList 鏂规硶鐢ㄤ簬淇濆瓨澶氫釜宀椾綅璁板綍锛屾牴鎹被鍨嬫壒閲忔墽琛屼笉鍚岀殑鎿嶄綔

--
Gitblit v1.9.3