1
0
Fork 0
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
3.0 KiB
C#

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<SysUserEntity> _repository => new Repository<SysUserEntity>("sqlserver");
public List<SysUserEntity> GetUserInfos(string userName = null, string userRole = null, DateTime? beginTime = null, DateTime? endTime = null, bool isSelectByTime = false)
{
try
{
List<SysUserEntity> 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<SysUserEntity> 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;
}
}
}
}