using Furion.DependencyInjection; using Furion.DynamicApiController; using Furion.FriendlyException; using Mapster; using Microsoft.AspNetCore.Mvc; using Myshipping.Application.Entity; using Myshipping.Application.Service.MonthlyPayAccount.Dto; using Myshipping.Core; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Threading.Tasks; namespace Myshipping.Application { /// /// 月结账户操作服务 /// [ApiDescriptionSettings("Application", Name = "MonthlyPayAccount", Description = "月结账户操作服务", Order = 20)] [Route("/MonthlyPayAccount")] public class MonthlyPayAccountService : IMonthlyPayAccountService, IDynamicApiController, ITransient { private readonly SqlSugarRepository _monthlyRep; private readonly string[] UpdateIgnoreColumns = new string[] { "CreatedTime", "CreatedUserId", "CreatedUserName", "TenantId" }; public MonthlyPayAccountService(SqlSugarRepository monthlyRep) { _monthlyRep = monthlyRep; } [HttpPost("SaveOrUpdate")] public async Task SaveOrUpdate(MonthlyPayAccountDto input) { if (string.IsNullOrEmpty(input.Account)) { throw Oops.Bah("户头不能为空"); } if (string.IsNullOrWhiteSpace(input.CardNo)) { throw Oops.Bah("卡号不能为空"); } if (await _monthlyRep.IsExistsAsync(m => m.Account == input.Account && m.CardNo == input.CardNo)) { throw Oops.Bah("已存在同户头同卡号的月结账户"); } MonthlyPayAccount model = input.Adapt(); if ((input.Id ?? 0) == 0) { await _monthlyRep.InsertAsync(model); } else { await _monthlyRep.AsUpdateable(model).IgnoreColumns(UpdateIgnoreColumns).ExecuteCommandAsync(); } } [HttpGet("List")] public async Task> List() { var modelList = await _monthlyRep.ToListAsync(); var result = modelList.Adapt>(); return result; } [HttpPost("Delete")] public async Task Delete([Required] string ids) { long[] idArr = ids.Split(',').Adapt(); await _monthlyRep.UpdateAsync(m => idArr.Contains(m.Id), m => new MonthlyPayAccount() { IsDeleted = true }); } } }