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.Impl { public class BaseSysUserInfoServiceImpl : ISysUserInfoService { 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.UserName == 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; } } 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; } } } }