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.

116 lines
4.0 KiB
C#

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
{
/// <summary>
/// 用户邮箱账号服务
/// </summary>
[ApiDescriptionSettings(Name = "DjyUserMailAccount", Order = 1)]
public class DjyUserMailAccountService : IDjyUserMailAccountService, IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<DjyUserMailAccount> _rep;
private readonly ILogger<DjyUserMailAccount> _logger;
public DjyUserMailAccountService(SqlSugarRepository<DjyUserMailAccount> rep, ILogger<DjyUserMailAccount> logger)
{
_rep = rep;
_logger = logger;
}
/// <summary>
/// 分页查询用户邮箱账号
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("/DjyUserMailAccount/page")]
public async Task<dynamic> 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();
}
/// <summary>
/// 增加用户邮箱账号
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[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<DjyUserMailAccount>();
await _rep.InsertAsync(entity);
}
/// <summary>
/// 更新用户邮箱账号
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[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<DjyUserMailAccount>();
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
}
/// <summary>
/// 删除用户邮箱账号
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/DjyUserMailAccount/delete")]
public async Task Delete(GetDjyUserMailAccountInput input)
{
var entity = await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
await _rep.DeleteAsync(entity);
}
/// <summary>
/// 获取用户邮箱账号
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("/DjyUserMailAccount/detail")]
public async Task<DjyUserMailAccount> Get([FromQuery] GetDjyUserMailAccountInput input)
{
return await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
}
///// <summary>
///// 获取用户邮箱账号列表
///// </summary>
///// <param name="input"></param>
///// <returns></returns>
//[HttpGet("/DjyUserMailAccount/list")]
//public async Task<dynamic> List([FromQuery] QueryDjyUserMailAccountInput input)
//{
// return await _rep.ToListAsync();
//}
}
}