From b957cfb89c9968f47cc5ce9795e6ffb05bc57fd8 Mon Sep 17 00:00:00 2001
From: 啊鑫 <t2856754968@163.com>
Date: 星期三, 30 十月 2024 16:05:48 +0800
Subject: [PATCH] 11

---
 MES.Service/service/BasicData/MesStaffManager.cs |  124 +++++++++++++----------------------------
 1 files changed, 40 insertions(+), 84 deletions(-)

diff --git a/MES.Service/service/BasicData/MesStaffManager.cs b/MES.Service/service/BasicData/MesStaffManager.cs
index 42269b8..776945d 100644
--- a/MES.Service/service/BasicData/MesStaffManager.cs
+++ b/MES.Service/service/BasicData/MesStaffManager.cs
@@ -1,5 +1,4 @@
-锘縰sing Castle.Core.Resource;
-using MES.Service.DB;
+锘縰sing MES.Service.DB;
 using MES.Service.Dto.webApi;
 using MES.Service.Modes;
 using SqlSugar;
@@ -62,47 +61,29 @@
     private bool InsertOrUpdateStaff(SqlSugarScope db, SysUser sysUser,
         MesStaff entity)
     {
-        var exists = db.Queryable<SysUser>().Any(u => u.Sid == sysUser.Sid);
-        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;
-            }
-        }
-        else
-        {
-            var insertUser = db.Insertable(sysUser).ExecuteCommand();
-            if (insertUser > 0)
-            {
-                var insertStaff = db.Insertable(entity).ExecuteCommand();
-                if (insertStaff > 0)
-                    return true;
-            }
-        }
+        db.Deleteable<SysUser>()
+            .Where(s => s.Account == sysUser.Account).ExecuteCommand();
 
-        return false;
+        db.Deleteable<MesStaff>()
+            .Where(s => s.Id == entity.Id).ExecuteCommand();
+
+        var insertUser = db.Insertable(sysUser).ExecuteCommand();
+        if (insertUser <= 0) return false;
+        var insertStaff = db.Insertable(entity).ExecuteCommand();
+        return insertStaff > 0;
     }
 
     // 鍒犻櫎鍛樺伐鐨勬柟娉�
     private bool DeleteStaff(SqlSugarScope db, SysUser sysUser, 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;
-        }
+            .Where(s => s.Account == sysUser.Account).ExecuteCommand();
+        if (deleteUser <= 0) throw new NotImplementedException("鍙嶅鏍稿け璐�");
+        var deleteStaff =
+            db.Deleteable<MesStaff>()
+                .Where(s => s.Id == staffId).ExecuteCommand();
+        if (deleteStaff > 0)
+            return true;
 
         throw new NotImplementedException("鍙嶅鏍稿け璐�");
     }
@@ -116,14 +97,15 @@
             StaffNo = staff.FStaffNumber,
             StaffName = staff.FName,
             DepartmentName = staff.FPostDept,
-            PositionName = staff.FPost,
+            PositionCode = staff.FPostId,
             PhoneNumber = staff.FMobile,
             Remark = staff.FDescription,
             FforbidStatus = staff.FForbidStatus,
-            FSubsidiary = staff.FUSEORGID,
-            Fumbrella = staff.FCREATEORGID,
+            FSubsidiary = staff.FUseOrgId,
+            Fumbrella = staff.FCreateOrgId,
             CreateDate = DateTime.Now,
-            LastupdateDate = DateTime.Now
+            LastupdateDate = DateTime.Now,
+            Type = staff.Type
         };
 
         if (staff.FStaffStartDate != null)
@@ -138,26 +120,11 @@
     {
         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,
-            Ismanager = 0,
-            Isacq = 0,
-            ExpField9 = "1020",
-            QmUser = 0,
-            Status = 0,
-            Isdeparture = 0,
-            CheckFlag = 0,
-            ExpFiel12 = 0,
-            Dev = 0,
-            Tet = 0,
-            Prd = 1
+            Account = staff.FStaffNumber,
+            UserName = staff.FName,
+            Password = "E1ADC3949BA59ABBE56E057F2F883E", // 鍒濆瀵嗙爜
+            DepartNo = staff.FPostDept,
+            Type = staff.Type
         };
     }
 
@@ -195,16 +162,12 @@
                                 "B")) // 鎵归噺绂佺敤鍛樺伐
                             throw new NotImplementedException("绂佺敤澶辫触");
                         break;
-                    case "2":
-                        if (!InsertStaffBatch(db, userList,
-                                staffGroup.Value)) // 鎵归噺鎻掑叆鍛樺伐
-                            throw new NotImplementedException("鎻掑叆澶辫触");
-                        break;
                     case "3":
                         if (!DeleteStaffBatch(db, userList,
                                 staffGroup.Value)) // 鎵归噺鍒犻櫎鍛樺伐
                             throw new NotImplementedException("鍒犻櫎澶辫触");
                         break;
+                    case "2":
                     case "4":
                         if (!InsertOrUpdateBatch(db, userList,
                                 staffGroup.Value)) // 鎵归噺鎻掑叆鎴栨洿鏂板憳宸�
@@ -238,11 +201,11 @@
     private bool InsertStaffBatch(SqlSugarScope db, List<SysUser> userList,
         List<MesStaff> staffList)
     {
-        var userInsert = userList.FindAll(s => s.Type == "INSERT");
+        var userInsert = userList.FindAll(s => s.Type == "2");
         var executeCommand = db.Insertable(userInsert).ExecuteCommand();
-        if (executeCommand > 0)
-            if (db.Insertable(staffList).ExecuteCommand() > 0)
-                return true;
+        if (executeCommand <= 0) throw new ArgumentNullException("瀹℃牳澶辫触");
+        if (db.Insertable(staffList).ExecuteCommand() > 0)
+            return true;
 
         throw new ArgumentNullException("瀹℃牳澶辫触");
     }
@@ -251,17 +214,16 @@
     private bool DeleteStaffBatch(SqlSugarScope db, List<SysUser> userList,
         List<MesStaff> staffList)
     {
-        var sid = userList.FindAll(s => s.Type == "DELETE").Select(s => s.Sid)
+        var sid = userList.FindAll(s => s.Type == "3").Select(s => s.Account)
             .ToArray();
         var result = db.Deleteable<SysUser>()
-            .Where(s => sid.Contains(s.Sid)).ExecuteCommand();
+            .Where(s => sid.Contains(s.Account)).ExecuteCommand();
 
-        if (result > 0)
-        {
-            var ids = staffList.Select(it => it.Id).ToArray();
-            if (db.Deleteable<MesStaff>().In(ids).ExecuteCommand() > 0)
-                return true;
-        }
+        if (result <= 0) throw new ArgumentNullException("鍙嶅鏍稿け璐�");
+        var ids = staffList.Select(it => it.Id).ToArray();
+        if (db.Deleteable<MesStaff>()
+                .Where(s => ids.Contains(s.Id)).ExecuteCommand() > 0)
+            return true;
 
         throw new ArgumentNullException("鍙嶅鏍稿け璐�");
     }
@@ -270,12 +232,6 @@
     private bool InsertOrUpdateBatch(SqlSugarScope db, List<SysUser> userList,
         List<MesStaff> staffList)
     {
-        foreach (var sysUser in userList)
-        {
-            var entity = staffList.First(s => s.Id == sysUser.Sid);
-            if (!InsertOrUpdateStaff(db, sysUser, entity)) return false;
-        }
-
-        return true;
+        return !(from sysUser in userList let entity = staffList.First(s => s.StaffNo == sysUser.Account) where !InsertOrUpdateStaff(db, sysUser, entity) select sysUser).Any();
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3