using DS.Module.Core; using DS.Module.Core.Data; using DS.Module.Core.Extensions; using DS.WMS.Core.Info.Dtos; using DS.WMS.Core.Info.Entity; using DS.WMS.Core.Info.Interface; using Mapster; namespace DS.WMS.Core.Info.Method; /// /// 往来单位银行 /// public class ClientBankService : ServiceBase, IClientBankService { /// /// /// /// public ClientBankService(IServiceProvider serviceProvider) : base(serviceProvider) { } /// /// 列表 /// /// /// public DataResult> GetListByPage(PageRequest request) { //序列化查询条件 var whereList = request.GetConditionalModels(Db); var result = TenantDb.Queryable() .Where(whereList) .Select().ToQueryPage(request.PageCondition); if (result.Data?.Count > 0) { var ids = result.Data.Select(x => x.Id); var list = TenantDb.Queryable().Where(x => ids.Contains(x.RelativeId)).ToList(); foreach (var item in result.Data) { item.InvoiceHeaders = list.FindAll(x => x.RelativeId == item.Id); } } return result; } /// /// 编辑 /// /// /// public async Task EditClientBankAsync(ClientBankReq req) { if (req.Id == 0) { if (await TenantDb.Queryable().Where(x => x.CodeName == req.CodeName).AnyAsync()) return DataResult.Failed("客户银行信息已存在!", MultiLanguageConst.ClientBankExist); var data = req.Adapt(); var entity = await TenantDb.InsertNav(data).Include(x => x.InvoiceHeaders).ExecuteReturnEntityAsync(); return DataResult.Successed("添加成功!", entity.Id, MultiLanguageConst.DataCreateSuccess); } else { var info = await TenantDb.Queryable().Where(x => x.Id == req.Id).FirstAsync(); if (info == null) { return DataResult.FailedWithDesc(MultiLanguageConst.EmptyData); } info = req.Adapt(info); await TenantDb.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); //创建或更新发票抬头 if (req.InvoiceHeaders?.Count > 0) await TenantDb.Storageable(req.InvoiceHeaders).DefaultAddElseUpdate().ExecuteCommandAsync(); return DataResult.Successed("更新成功!", MultiLanguageConst.DataUpdateSuccess); } } /// /// 详情 /// /// /// public async Task> GetClientBankInfoAsync(long id) { var data = await TenantDb.Queryable() .Where(a => a.Id == id) .Select() .FirstAsync(); if (data != null) data.InvoiceHeaders = await TenantDb.Queryable().Where(x => x.RelativeId == data.Id).ToListAsync(); return DataResult.Success(data, MultiLanguageConst.DataQuerySuccess); } /// /// 批量删除 /// /// /// public async Task DeleteAsync(IdModel req) { //删除客户信息 int rows = await TenantDb.Deleteable().Where(x => req.Ids.Contains(x.Id)).ExecuteCommandAsync(); return rows > 0 ? DataResult.Success : DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed)); } }