11
啊鑫
2024-10-30 b957cfb89c9968f47cc5ce9795e6ffb05bc57fd8
MES.Service/service/BasicData/MesStaffManager.cs
@@ -27,7 +27,6 @@
                    break;
                case "2":
                case "4":
                    DeleteStaff(db, sysUser, entity.Id);
                    if (InsertOrUpdateStaff(db, sysUser, entity)) // 插入或更新员工
                        return 1;
                    break;
@@ -62,6 +61,12 @@
    private bool InsertOrUpdateStaff(SqlSugarScope db, SysUser sysUser,
        MesStaff entity)
    {
        db.Deleteable<SysUser>()
            .Where(s => s.Account == sysUser.Account).ExecuteCommand();
        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();
@@ -157,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)) // 批量插入或更新员工
@@ -200,7 +201,6 @@
    private bool InsertStaffBatch(SqlSugarScope db, List<SysUser> userList,
        List<MesStaff> staffList)
    {
        var userInsert = userList.FindAll(s => s.Type == "2");
        var executeCommand = db.Insertable(userInsert).ExecuteCommand();
        if (executeCommand <= 0) throw new ArgumentNullException("审核失败");
@@ -232,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.StaffNo == sysUser.Account);
            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();
    }
}