cnf
2025-09-13 528d0370cb57f07e291fbf8fb0052718c3fe584c
MES.Service/service/BasicData/MesStaffManager.cs
@@ -328,7 +328,7 @@
}
 */
 
 namespace MES.Service.service.BasicData;
namespace MES.Service.service.BasicData;
using MES.Service.DB;
using MES.Service.Dto.webApi;
@@ -353,12 +353,17 @@
        {
            switch (unit.Type)
            {
                case "0": return UpdateStaffStatus(db, entity.Id, "A") ? 1 : 0;
                case "1": return UpdateStaffStatus(db, entity.Id, "B") ? 1 : 0;
                case "0":
                    return UpdateStaffStatus(db, entity.Id, "A") ? 1 : 0;
                case "1":
                    return UpdateStaffStatus(db, entity.Id, "B") ? 1 : 0;
                case "2":
                case "4": return InsertOrUpdateStaff(db, new List<SysUser> { sysUser }, new List<MesStaff> { entity }, mesStaffPositionLink) ? 1 : 0;
                case "3": return DeleteStaff(db, new List<SysUser> { sysUser }, new List<MesStaff> { entity }) ? 1 : 0;
                default: throw new ArgumentException($"不支持的类型: {unit.Type}");
                case "4":
                    return InsertOrUpdateStaff(db, new List<SysUser> { sysUser }, new List<MesStaff> { entity }, mesStaffPositionLink) ? 1 : 0;
                case "3":
                    return DeleteStaff(db, new List<SysUser> { sysUser }, new List<MesStaff> { entity }) ? 1 : 0;
                default:
                    throw new ArgumentException($"不支持的类型: {unit.Type}");
            }
        }) > 0;
    }
@@ -429,9 +434,7 @@
        try
        {
            // 1. 批量插入 SysUser(仅新增)
            var newSysUsers = sysUsers
                .Where(u => !db.Queryable<SysUser>().Any(e => e.Sid == u.Sid))
                .ToList();
            var newSysUsers = sysUsers.Where(u => !db.Queryable<SysUser>().Any(e => e.Sid == u.Sid)).ToList();
            if (newSysUsers.Any())
            {
@@ -505,10 +508,7 @@
        }
        
        var ids = staffList.Select(s => s.Id).ToList();
        var updateCount = db.Updateable<MesStaff>()
            .SetColumns(s => s.FforbidStatus == status)
            .Where(s => ids.Contains(s.Id))
            .ExecuteCommand();
        var updateCount = db.Updateable<MesStaff>().SetColumns(s => s.FforbidStatus == status).Where(s => ids.Contains(s.Id)).ExecuteCommand();
            
        if (updateCount <= 0)
        {
@@ -539,9 +539,7 @@
            var staffDeleteCount = db.Deleteable<MesStaff>().Where(s => staffIds.Contains(s.Id)).ExecuteCommand();
            
            // 3. 删除岗位关联 :使用Any方法(推荐)
            db.Deleteable<MesStaffPositionLink>()
                .Where(p => staffIds.Any(id => id == p.StaffId))
                .ExecuteCommand();
            db.Deleteable<MesStaffPositionLink>().Where(p => staffIds.Any(id => id == p.StaffId)).ExecuteCommand();
            Console.WriteLine($"成功删除 {userDeleteCount} 个SysUser和 {staffDeleteCount} 个MesStaff");
            return userDeleteCount > 0 && staffDeleteCount > 0;
@@ -557,10 +555,7 @@
    // 更新员工状态
    private bool UpdateStaffStatus(SqlSugarScope db, decimal staffId, string status)
    {
        var result = db.Updateable<MesStaff>()
            .SetColumns(s => s.FforbidStatus == status)
            .Where(s => s.Id == staffId)
            .ExecuteCommand();
        var result = db.Updateable<MesStaff>().SetColumns(s => s.FforbidStatus == status).Where(s => s.Id == staffId).ExecuteCommand();
        if (result <= 0)
        {
@@ -657,18 +652,11 @@
                    new MesStaffPositionLink
                    {
                        StaffId = Convert.ToDecimal(staff.Id),
                        PositionId = string.IsNullOrEmpty(staffDetail.fPostId?.ToString())
                            ? null
                            : Convert.ToDecimal(staffDetail.fPostId),
                        FPostDeptId = string.IsNullOrEmpty(staffDetail.fPostDeptid?.ToString())
                            ? null
                            : Convert.ToDecimal(staffDetail.fPostDeptid),
                        FStaffStartDate = string.IsNullOrEmpty(staffDetail.fStaffStartDate?.ToString())
                            ? null
                            : DateTime.ParseExact(staffDetail.fStaffStartDate, "yyyy-MM-dd HH:mm:ss", null)
                        PositionId = string.IsNullOrEmpty(staffDetail.fPostId?.ToString()) ? null : Convert.ToDecimal(staffDetail.fPostId),
                        FPostDeptId = string.IsNullOrEmpty(staffDetail.fPostDeptid?.ToString()) ? null : Convert.ToDecimal(staffDetail.fPostDeptid),
                        FStaffStartDate = string.IsNullOrEmpty(staffDetail.fStaffStartDate?.ToString()) ? null : DateTime.ParseExact(staffDetail.fStaffStartDate, "yyyy-MM-dd HH:mm:ss", null)
                    }).ToList();
            }
            return staffDetails;
        }
        catch (Exception ex)