using Myshipping.Core;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Furion.FriendlyException;
using Myshipping.Core.Entity;
namespace Myshipping.Core.Service
{
///
/// 用户邮箱账号服务
///
[ApiDescriptionSettings(Name = "DjyUserMailAccount", Order = 1)]
public class DjyUserMailAccountService : IDjyUserMailAccountService, IDynamicApiController, ITransient
{
private readonly SqlSugarRepository _rep;
private readonly ILogger _logger;
public DjyUserMailAccountService(SqlSugarRepository rep, ILogger logger)
{
_rep = rep;
_logger = logger;
}
///
/// 分页查询用户邮箱账号
///
///
///
[HttpGet("/DjyUserMailAccount/page")]
public async Task Page([FromQuery] QueryDjyUserMailAccountInput input)
{
var entities = await _rep.AsQueryable()
.Where(m => m.CreatedUserId == UserManager.UserId)
.WhereIF(!string.IsNullOrWhiteSpace(input.MailAccount), u => u.MailAccount.Contains(input.MailAccount.Trim()))
.ToPagedListAsync(input.PageNo, input.PageSize);
return entities.XnPagedResult();
}
///
/// 增加用户邮箱账号
///
///
///
[HttpPost("/DjyUserMailAccount/add")]
public async Task Add(AddDjyUserMailAccountInput input)
{
var cc = _rep.AsQueryable().Filter(null, true).Count(x => x.MailAccount == input.MailAccount);
if (cc > 0)
{
throw Oops.Oh(ErrorCode.EMAIL001);
}
var entity = input.Adapt();
await _rep.InsertAsync(entity);
}
///
/// 更新用户邮箱账号
///
///
///
[HttpPost("/DjyUserMailAccount/edit")]
public async Task Update(UpdateDjyUserMailAccountInput input)
{
var cc = _rep.AsQueryable().Filter(null, true).Count(x => x.MailAccount == input.MailAccount && x.Id != input.Id);
if (cc > 0)
{
throw Oops.Oh(ErrorCode.EMAIL001);
}
var entity = input.Adapt();
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
}
///
/// 删除用户邮箱账号
///
///
///
[HttpPost("/DjyUserMailAccount/delete")]
public async Task Delete(GetDjyUserMailAccountInput input)
{
var entity = await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
await _rep.DeleteAsync(entity);
}
///
/// 获取用户邮箱账号
///
///
///
[HttpGet("/DjyUserMailAccount/detail")]
public async Task Get([FromQuery] GetDjyUserMailAccountInput input)
{
return await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
}
/////
///// 获取用户邮箱账号列表
/////
/////
/////
//[HttpGet("/DjyUserMailAccount/list")]
//public async Task List([FromQuery] QueryDjyUserMailAccountInput input)
//{
// return await _rep.ToListAsync();
//}
}
}