using MiaoYu.Repository.LiveForum.Admin.Entities.Apps;
namespace MiaoYu.Api.Admin.ApplicationServices.Apps.LiveForum;
///
/// 用户表,存储用户基本信息(移除登录相关字段) 服务 T_UsersService
///
public class T_UsersService : ApplicationService>
{
public T_UsersService(IRepository defaultRepository)
: base(defaultRepository)
{
}
///
/// 获取列表数据
///
///
///
public async Task FindListAsync(PagingSearchInput pagingSearchInput)
{
var query = this._defaultRepository.Select
//用户ID
.WhereIf(pagingSearchInput.Search?.Id!=null&&pagingSearchInput.Search?.Id>0,
w => w.Id== pagingSearchInput.Search.Id)
//用户昵称
.WhereIf(!string.IsNullOrWhiteSpace(pagingSearchInput.Search?.NickName),
w => w.NickName.Contains(pagingSearchInput.Search.NickName ?? ""))
//手机号
.WhereIf(!string.IsNullOrWhiteSpace(pagingSearchInput.Search?.PhoneNumber),
w => w.PhoneNumber.Contains(pagingSearchInput.Search.PhoneNumber ?? ""))
.OrderByDescending(w => w.Id)
.Select(w => new
{
w.Id,
w.NickName,w.Avatar,w.Gender,w.PhoneNumber,w.Birthday,w.Signature,w.LevelId,w.Experience,w.IsVip,w.VipExpireTime,w.IsCertified,w.CertifiedType,w.Status,w.LastLoginTime,w.LastLoginIp,w.RegisterIp,w.CreatedAt,w.UpdatedAt,
// w.LastModificationTime,
// w.CreationTime
})
;
var result = await _defaultRepository.AsPagingViewAsync(query, pagingSearchInput);
// result
// .FormatValue(query, w => w.CreationTime, (oldValue) => oldValue.ToString("yyyy-MM-dd"))
// .FormatValue(query, w => w.LastModificationTime, (oldValue) => oldValue?.ToString("yyyy-MM-dd"))
// ;
// 设置列
//result.GetColumn(query, w => w.OperatorName).SetColumn("操作人");
//result.GetColumn(query, w => w.OperatorName!).SetColumn(w => w.Name!);
return result;
}
///
/// 根据id数组删除
///
/// ids
///
public async Task DeleteListAsync(List ids)
{
await this._defaultRepository.DeleteByIdsAsync(ids);
}
///
/// 查询表单数据
///
/// id
///
public async Task> FindFormAsync(int id)
{
var res = new Dictionary();
var form = await this._defaultRepository.FindByIdAsync(id);
form = form.NullSafe();
//if (form.CreateTime == null || form.CreateTime == DateTime.MinValue)
//{
// form.CreateTime = DateTime.Now;
//}
//if (form.UpdateTime == null || form.UpdateTime == DateTime.MinValue)
//{
// form.UpdateTime = DateTime.Now;
//}
res[nameof(id)] = id;
res[nameof(form)] = form;
return res;
}
///
/// 保存数据
///
/// form
///
public Task SaveFormAsync(T_Users form)
{
return this._defaultRepository.InsertOrUpdateAsync(form);
}
///
/// 导出Excel
///
///
///
public async Task ExportExcelAsync(PagingSearchInput pagingSearchInput)
{
pagingSearchInput.Page = -1;
var tableViewModel = await this.FindListAsync(pagingSearchInput);
return ExcelUtil.ExportExcelByPagingView(tableViewModel, null, "Id");
}
}