using HighWayIot.Log4net; using HighWayIot.Repository.domain; using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; using System.Threading.Tasks; namespace HighWayIot.Repository.service { public class SysUserInfoService { private static readonly Lazy lazy = new Lazy(() => new SysUserInfoService()); public static SysUserInfoService Instance { get { return lazy.Value; } } private LogHelper log = LogHelper.Instance; Repository _repository => new Repository("sqlserver"); /// /// 条件查询所有用户列表 用户名为模糊查询 /// /// 用户名 /// 用户角色 /// 开始时间 /// 结束时间 /// 是否 /// public List GetUserInfos(string userName = null, string userRole = null, DateTime? beginTime = null, DateTime? endTime = null, bool isSelectByTime = false) { try { List deviceInfo = _repository.GetList(x => x.IsDeleted == false); if (!string.IsNullOrEmpty(userName)) { deviceInfo = deviceInfo.Where(x => x.UserName.Contains(userName)).ToList(); } if (!string.IsNullOrEmpty(userRole)) { deviceInfo = deviceInfo.Where(x => x.UserRole == userRole).ToList(); } if (isSelectByTime) { deviceInfo = deviceInfo.Where(x => x.LastLoginTime >= beginTime && x.LastLoginTime <= endTime).ToList(); } return deviceInfo; } catch (Exception ex) { log.Error("用户信息获取异常", ex); return null; } } /// /// 添加用户信息 /// /// /// public bool InsertUserInfo(SysUserEntity sysUserEntity) { try { return _repository.Insert(sysUserEntity); } catch (Exception ex) { log.Error("用户信息插入异常", ex); return false; } } /// /// 修改用户信息 /// /// /// public bool UpdateUserInfo(SysUserEntity sysUserEntity) { try { return _repository.Update(sysUserEntity); } catch(Exception ex) { log.Error("用户信息修改异常", ex); return false; } } /// /// 根据ID删除用户信息 /// /// /// public bool DeleteUserInfoById(int id) { try { SysUserEntity entity = _repository.GetById(id); entity.IsDeleted = true; return _repository.Update(entity); } catch (Exception ex) { log.Error("用户信息删除异常", ex); return false; } } /// /// 根据用户名查询单条用户信息 /// /// /// public List GetUserInfoByUserName(string userName) { try { var list = _repository.GetList(x => x.UserName == userName && x.IsDeleted == false); return list; } catch (Exception ex) { log.Error("单条用户信息查询异常", ex); return null; } } } }