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 Myshipping.Core.Entity; using Microsoft.Extensions.Logging; using Furion.FriendlyException; namespace Myshipping.Core.Service { /// /// 网站账号维护服务 /// [ApiDescriptionSettings(Name = "DjyWebsiteAccountConfig", Order = 1)] public class DjyWebsiteAccountConfigService : IDjyWebsiteAccountConfigService, IDynamicApiController, ITransient { private readonly SqlSugarRepository _rep; private readonly ILogger _logger; public DjyWebsiteAccountConfigService(SqlSugarRepository rep, ILogger logger) { _rep = rep; _logger = logger; } /// /// 分页查询网站账号维护 /// /// /// [HttpGet("/DjyWebsiteAccountConfig/page")] public async Task Page([FromQuery] QueryDjyWebsiteAccountConfigInput input) { var entities = await _rep.AsQueryable() .Where(m => m.CreatedUserId == UserManager.UserId) .WhereIF(!string.IsNullOrWhiteSpace(input.TypeCode), u => u.TypeCode == input.TypeCode) .WhereIF(!string.IsNullOrWhiteSpace(input.Account), u => u.Account.Contains(input.Account.Trim())) .ToPagedListAsync(input.PageNo, input.PageSize); return entities.XnPagedResult(); } /// /// 增加网站账号维护(同一用户、同类型账号不允许重复) /// /// /// [HttpPost("/DjyWebsiteAccountConfig/add")] public async Task Add(AddDjyWebsiteAccountConfigInput input) { var cc = _rep.Count(x => x.TypeCode == input.TypeCode && x.CreatedUserId == UserManager.UserId); if (cc > 0) { throw Oops.Bah("已存在同类型账号"); } var entity = input.Adapt(); await _rep.InsertAsync(entity); return entity.Id; } /// /// 更新网站账号维护 /// /// /// [HttpPost("/DjyWebsiteAccountConfig/edit")] public async Task Update(UpdateDjyWebsiteAccountConfigInput input) { var cc = _rep.Count(x => x.TypeCode == input.TypeCode && x.CreatedUserId == UserManager.UserId && x.Id != input.Id); if (cc > 0) { throw Oops.Bah("已存在同类型账号"); } var entity = input.Adapt(); await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); return entity.Id; } /// /// 删除网站账号维护 /// /// /// [HttpPost("/DjyWebsiteAccountConfig/delete")] public async Task Delete(GetDjyWebsiteAccountConfigInput input) { var entity = await _rep.FirstOrDefaultAsync(u => u.Id == input.Id); await _rep.DeleteAsync(entity); } } }