| | |
| | | break; |
| | | case "2": |
| | | case "4": |
| | | DeleteStaff(db, sysUser, entity.Id); |
| | | if (InsertOrUpdateStaff(db, sysUser, entity)) // 插入或更新员工 |
| | | return 1; |
| | | break; |
| | |
| | | private bool InsertOrUpdateStaff(SqlSugarScope db, SysUser sysUser, |
| | | MesStaff entity) |
| | | { |
| | | var insertUser = db.Insertable(sysUser).ExecuteCommand(); |
| | | if (insertUser <= 0) return false; |
| | | |
| | | var exists = db.Queryable<SysUser>().Any(u => u.Account == sysUser.Account); |
| | | if (!exists) |
| | | { |
| | | var insertUser = db.Insertable(sysUser).ExecuteCommand(); |
| | | if (insertUser <= 0) return false; |
| | | } |
| | | |
| | | //db.Deleteable<SysUser>() |
| | | // .Where(s => s.Account == sysUser.Account).ExecuteCommand(); |
| | | |
| | | db.Deleteable<MesStaff>() |
| | | .Where(s => s.Id == entity.Id).ExecuteCommand(); |
| | | |
| | | |
| | | |
| | | var insertStaff = db.Insertable(entity).ExecuteCommand(); |
| | | return insertStaff > 0; |
| | | } |
| | |
| | | { |
| | | return new SysUser |
| | | { |
| | | IsStatus = true, |
| | | Account = staff.FStaffNumber, |
| | | UserName = staff.FName, |
| | | Password = "E1ADC3949BA59ABBE56E057F2F883E", // 初始密码 |
| | | DepartNo = staff.FPostDept, |
| | | Type = staff.Type |
| | | Type = staff.Type, |
| | | CreateTime = DateTime.Now |
| | | }; |
| | | } |
| | | |
| | |
| | | "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)) // 批量插入或更新员工 |
| | |
| | | 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(); |
| | | } |
| | | } |