From ed05efdc17aab076146b134ebe105b6382f221d7 Mon Sep 17 00:00:00 2001
From: 啊鑫 <t2856754968@163.com>
Date: 星期四, 10 七月 2025 10:09:29 +0800
Subject: [PATCH] 格式化代码

---
 MES.Service/service/BasicData/MesStaffManager.cs |  128 +++++++++---------------------------------
 1 files changed, 27 insertions(+), 101 deletions(-)

diff --git a/MES.Service/service/BasicData/MesStaffManager.cs b/MES.Service/service/BasicData/MesStaffManager.cs
index 9977229..7f37ec4 100644
--- a/MES.Service/service/BasicData/MesStaffManager.cs
+++ b/MES.Service/service/BasicData/MesStaffManager.cs
@@ -11,7 +11,6 @@
     public bool Save(ErpStaff unit)
     {
         var entity = GetMesStaff(unit); // 灏� ErpStaff 杞崲涓� MesStaff
-        var sysUser = GetUser(unit); // 鑾峰彇 SysUser 瀹炰緥
 
         return UseTransaction(db =>
         {
@@ -27,11 +26,11 @@
                     break;
                 case "2":
                 case "4":
-                    if (InsertOrUpdateStaff(db, sysUser, entity)) // 鎻掑叆鎴栨洿鏂板憳宸�
+                    if (InsertOrUpdateStaff(db, entity)) // 鎻掑叆鎴栨洿鏂板憳宸�
                         return 1;
                     break;
                 case "3":
-                    if (DeleteStaff(db, sysUser, entity.Id)) // 鍒犻櫎鍛樺伐
+                    if (DeleteStaff(db, entity.Id)) // 鍒犻櫎鍛樺伐
                         return 1;
                     break;
                 default:
@@ -51,57 +50,35 @@
             .SetColumns(s => s.FforbidStatus == status)
             .Where(s => s.Id == staffId).ExecuteCommand();
 
-        if (result > 0)
-            return true;
-
+        if (result > 0) return true;
         throw new NotImplementedException(status == "A" ? "鍚敤澶辫触" : "绂佺敤澶辫触");
     }
 
     // 鎻掑叆鎴栨洿鏂板憳宸ョ殑鏂规硶
-    private bool InsertOrUpdateStaff(SqlSugarScope db, SysUser sysUser,
-        MesStaff entity)
+    private bool InsertOrUpdateStaff(SqlSugarScope db, MesStaff entity)
     {
-        var exists = db.Queryable<SysUser>().Any(u => u.Sid == sysUser.Sid);
+        var exists = db.Queryable<MesStaff>()
+            .Any(u => u.StaffNo == entity.StaffNo);
         if (exists)
         {
-            var updateUser = db.Updateable<SysUser>()
-                .SetColumns(s => s.Fcode == sysUser.Fcode)
-                .SetColumns(s => s.Fname == sysUser.Fname)
-                .Where(s => s.Sid == sysUser.Sid)
-                .ExecuteCommand();
-            if (updateUser > 0)
-            {
-                var updateStaff = db.Updateable(entity).ExecuteCommand();
-                if (updateStaff > 0)
-                    return true;
-            }
+            var updateStaff = db.Updateable(entity).ExecuteCommand();
+            if (updateStaff > 0) return true;
         }
         else
         {
-            var insertUser = db.Insertable(sysUser).ExecuteCommand();
-            if (insertUser > 0)
-            {
-                var insertStaff = db.Insertable(entity).ExecuteCommand();
-                if (insertStaff > 0)
-                    return true;
-            }
+            var insertStaff = db.Insertable(entity).ExecuteCommand();
+            if (insertStaff > 0) return true;
         }
 
         return false;
     }
 
     // 鍒犻櫎鍛樺伐鐨勬柟娉�
-    private bool DeleteStaff(SqlSugarScope db, SysUser sysUser, decimal staffId)
+    private bool DeleteStaff(SqlSugarScope db, decimal staffId)
     {
-        var deleteUser = db.Deleteable<SysUser>()
-            .Where(s => s.Sid == sysUser.Sid).ExecuteCommand();
-        if (deleteUser > 0)
-        {
-            var deleteStaff =
-                db.Deleteable<MesStaff>().In(staffId).ExecuteCommand();
-            if (deleteStaff > 0)
-                return true;
-        }
+        var deleteStaff =
+            db.Deleteable<MesStaff>().In(staffId).ExecuteCommand();
+        if (deleteStaff > 0) return true;
 
         throw new NotImplementedException("鍙嶅鏍稿け璐�");
     }
@@ -131,52 +108,16 @@
         return entity;
     }
 
-    // 灏� ErpStaff 瀵硅薄杞崲涓� SysUser 瀵硅薄鐨勬柟娉�
-    private SysUser GetUser(ErpStaff staff)
-    {
-        return new SysUser
-        {
-            Sid = Convert.ToDecimal(staff.Id),
-            Fcode = staff.FStaffNumber,
-            Fname = staff.FName,
-            Fpassword = "8+()./,", // 鍒濆瀵嗙爜
-            Fsystem = "娉拌幈濮�",
-            Lever = 0,
-            Fcompany = "1000",
-            Ffactory = "1000",
-            DelFlag = 0,
-            Dev=0,
-            Tet=0,
-            Prd=1,
-            Ismanager = 0,
-            Isacq = 0,
-            ExpField9 = "1020",
-            QmUser = 0,
-            Status = 0,
-            Isdeparture = 0,
-            CheckFlag = 0,
-            ExpFiel12 = 0,
-            FirstLogin = 0,
-            CreateDate = DateTime.Now,
-            PswEditTime = DateTime.Now
-        };
-    }
-
     // SaveList 鏂规硶鐢ㄤ簬淇濆瓨澶氫釜鍛樺伐璁板綍锛屾牴鎹被鍨嬫壒閲忔墽琛屼笉鍚岀殑鎿嶄綔
     public bool SaveList(List<ErpStaff> departments)
     {
         var list = new List<MesStaff>();
-        var userList = new List<SysUser>();
 
         departments.ForEach(s =>
         {
             var entity = GetMesStaff(s);
             entity.Type = s.Type;
             list.Add(entity);
-
-            var sysUser = GetUser(s);
-            sysUser.Type = s.Type;
-            userList.Add(sysUser);
         });
 
         var groupBy = list.GroupBy(s => s.Type)
@@ -197,17 +138,15 @@
                             throw new NotImplementedException("绂佺敤澶辫触");
                         break;
                     case "2":
-                        if (!InsertStaffBatch(db, userList,
-                                staffGroup.Value)) // 鎵归噺鎻掑叆鍛樺伐
+                        if (!InsertStaffBatch(db, staffGroup.Value)) // 鎵归噺鎻掑叆鍛樺伐
                             throw new NotImplementedException("鎻掑叆澶辫触");
                         break;
                     case "3":
-                        if (!DeleteStaffBatch(db, userList,
-                                staffGroup.Value)) // 鎵归噺鍒犻櫎鍛樺伐
+                        if (!DeleteStaffBatch(db, staffGroup.Value)) // 鎵归噺鍒犻櫎鍛樺伐
                             throw new NotImplementedException("鍒犻櫎澶辫触");
                         break;
                     case "4":
-                        if (!InsertOrUpdateBatch(db, userList,
+                        if (!InsertOrUpdateBatch(db,
                                 staffGroup.Value)) // 鎵归噺鎻掑叆鎴栨洿鏂板憳宸�
                             throw new NotImplementedException("鍚屾澶辫触");
                         break;
@@ -229,17 +168,15 @@
             .SetColumns(s => s.FforbidStatus == status)
             .Where(s => ids.Contains(s.Id)).ExecuteCommand();
 
-        if (result > 0)
-            return true;
+        if (result > 0) return true;
 
         throw new NotImplementedException(status == "A" ? "鍚敤澶辫触" : "绂佺敤澶辫触");
     }
 
     // 鎵归噺鎻掑叆鍛樺伐鐨勬柟娉�
-    private bool InsertStaffBatch(SqlSugarScope db, List<SysUser> userList,
-        List<MesStaff> staffList)
+    private bool InsertStaffBatch(SqlSugarScope db, List<MesStaff> staffList)
     {
-        var userInsert = userList.FindAll(s => s.Type == "INSERT");
+        var userInsert = staffList.FindAll(s => s.Type == "INSERT");
         var executeCommand = db.Insertable(userInsert).ExecuteCommand();
         if (executeCommand > 0)
             if (db.Insertable(staffList).ExecuteCommand() > 0)
@@ -249,32 +186,21 @@
     }
 
     // 鎵归噺鍒犻櫎鍛樺伐鐨勬柟娉�
-    private bool DeleteStaffBatch(SqlSugarScope db, List<SysUser> userList,
-        List<MesStaff> staffList)
+    private bool DeleteStaffBatch(SqlSugarScope db, List<MesStaff> staffList)
     {
-        var sid = userList.FindAll(s => s.Type == "DELETE").Select(s => s.Sid)
-            .ToArray();
-        var result = db.Deleteable<SysUser>()
-            .Where(s => sid.Contains(s.Sid)).ExecuteCommand();
-
-        if (result > 0)
-        {
-            var ids = staffList.Select(it => it.Id).ToArray();
-            if (db.Deleteable<MesStaff>().In(ids).ExecuteCommand() > 0)
-                return true;
-        }
+        var ids = staffList.Select(it => it.Id).ToArray();
+        if (db.Deleteable<MesStaff>().In(ids).ExecuteCommand() > 0) return true;
 
         throw new ArgumentNullException("鍙嶅鏍稿け璐�");
     }
 
     // 鎵归噺鎻掑叆鎴栨洿鏂板憳宸ョ殑鏂规硶
-    private bool InsertOrUpdateBatch(SqlSugarScope db, List<SysUser> userList,
-        List<MesStaff> staffList)
+    private bool InsertOrUpdateBatch(SqlSugarScope db, List<MesStaff> staffList)
     {
-        foreach (var sysUser in userList)
+        foreach (var staff in staffList)
         {
-            var entity = staffList.First(s => s.Id == sysUser.Sid);
-            if (!InsertOrUpdateStaff(db, sysUser, entity)) return false;
+            var entity = staffList.First(s => s.StaffNo == staff.StaffNo);
+            if (!InsertOrUpdateStaff(db, entity)) return false;
         }
 
         return true;

--
Gitblit v1.9.3