sjz
5 天以前 6761b0ed84fd7a03400b557244d0835f671dad94
MES.Service/service/BasicData/MesStaffManager.cs
@@ -30,12 +30,11 @@
                        return 1;
                    break;
                case "3":
                    if (DeleteStaff(db, entity.Id)) // 删除员工
                    if (UpdateStaffStatus(db, entity.Id, "B")) // 禁用员工
                        return 1;
                    break;
                default:
                    throw new ArgumentNullException(
                        $"type没有{unit.Type}这个类型的参数");
                    throw new ArgumentNullException($"type没有{unit.Type}这个类型的参数");
            }
            throw new NotImplementedException("操作失败");
@@ -46,48 +45,30 @@
    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();
        if (result > 0)
        {
            return true;
        }
        throw new NotImplementedException(status == "A" ? "启用失败" : "禁用失败");
        return true;
    }
    // 插入或更新员工的方法
    private bool InsertOrUpdateStaff(SqlSugarScope db,MesStaff entity)
    {
        var exists = db.Queryable<MesStaff>().Any(u => u.StaffNo == entity.StaffNo);
        var exists = db.Queryable<MesStaff>().Any(e => e.Id == entity.Id);
        if (exists)
        {
            var updateStaff = db.Updateable(entity).ExecuteCommand();
            if (updateStaff > 0)
            {
                return true;
            }
            var update = db.Updateable(entity).ExecuteCommand();
            return true;
        }
        else
        {
            var insertStaff = db.Insertable(entity).ExecuteCommand();
            if (insertStaff > 0)
            var insert = db.Insertable(entity).ExecuteCommand();
            if (insert > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        return false;
    }
    // 删除员工的方法
    private bool DeleteStaff(SqlSugarScope db,decimal staffId)
    {
        var deleteStaff =db.Deleteable<MesStaff>().In(staffId).ExecuteCommand();
        if (deleteStaff > 0)
        {
            return true;
        }
        throw new NotImplementedException("反审核失败");
    }
    // 将 ErpStaff 对象转换为 MesStaff 对象的方法
@@ -117,18 +98,9 @@
    }
    // SaveList 方法用于保存多个员工记录,根据类型批量执行不同的操作
    public bool SaveList(List<ErpStaff> departments)
    public bool SaveList(List<ErpStaff> staffs)
    {
        var list = new List<MesStaff>();
        departments.ForEach(s =>
        {
            var entity = GetMesStaff(s);
            entity.Type = s.Type;
            list.Add(entity);
        });
        var list = staffs.Select(GetMesStaff).ToList();
        var groupBy = list.GroupBy(s => s.Type).ToDictionary(g => g.Key, g => g.ToList());
        return UseTransaction(db =>
        {
@@ -148,7 +120,7 @@
                            throw new NotImplementedException("插入失败");
                        break;
                    case "3":
                        if (!DeleteStaffBatch(db,staffGroup.Value)) // 批量删除员工
                        if (!UpdateStaffStatusBatch(db, staffGroup.Value, "B")) // 批量禁用员工
                            throw new NotImplementedException("删除失败");
                        break;
                    case "4":
@@ -168,51 +140,33 @@
    {
        var ids = staffList.Select(it => it.Id).ToArray();
        var result = db.Updateable<MesStaff>().SetColumns(s => s.FforbidStatus == status).Where(s => ids.Contains(s.Id)).ExecuteCommand();
        if (result > 0)
        {
            return true;
        }
        throw new NotImplementedException(status == "A" ? "启用失败" : "禁用失败");
        return true;
    }
    // 批量插入员工的方法
    private bool InsertStaffBatch(SqlSugarScope db,List<MesStaff> staffList)
    {
        var userInsert = staffList.FindAll(s => s.Type == "INSERT");
        var executeCommand = db.Insertable(userInsert).ExecuteCommand();
        if (executeCommand > 0)
            if (db.Insertable(staffList).ExecuteCommand() > 0)
                return true;
        throw new ArgumentNullException("审核失败");
    }
    // 批量删除员工的方法
    private bool DeleteStaffBatch(SqlSugarScope db, List<MesStaff> staffList)
    {
        var ids = staffList.Select(it => it.Id).ToArray();
        if (db.Deleteable<MesStaff>().In(ids).ExecuteCommand() > 0)
        foreach (var entity in staffList)
        {
            return true;
        }
        throw new ArgumentNullException("反审核失败");
    }
    // 批量插入或更新员工的方法
    private bool InsertOrUpdateBatch(SqlSugarScope db, List<MesStaff> staffList)
    {
        foreach (var staff in staffList)
        {
            var entity = staffList.First(s => s.StaffNo == staff.StaffNo);
            if (!InsertOrUpdateStaff(db, entity))
            {
                return false;
            }
        }
        return true;
    }
    // 批量插入或更新员工的方法
    private bool InsertOrUpdateBatch(SqlSugarScope db, List<MesStaff> staffList)
    {
        foreach (var entity in staffList)
        {
            if (!InsertOrUpdateStaff(db, entity))
            {
                return false;
            }
        }
        return true;
    }
}