using DS.Module.Core; using DS.Module.Core.Enums; using DS.WMS.Core.Application.Entity; using DS.WMS.Core.Fee.Method; using DS.WMS.Core.Invoice.Dto; using DS.WMS.Core.Invoice.Interface; using DS.Module.Core.Extensions; using DS.WMS.Core.Sys.Entity; using SqlSugar; namespace DS.WMS.Core.Invoice.Method { /// /// 发票服务基类 /// /// public class InvoiceService : FeeServiceBase, IInvoiceService where TEntity : Entity.Invoice, new() { /// /// 初始化 /// /// public InvoiceService(IServiceProvider provider) : base(provider) { } /// /// 获取分页列表 /// /// /// public async Task>> GetListAsync(PageRequest request) { var query = TenantDb.Queryable() .Select(i => new InvoiceDto { Id = i.Id, InvoiceNO = i.InvoiceNO, BillNO = i.BillNO, InvoiceDate = i.InvoiceDate, CustomerId = i.CustomerId, CustomerName = i.CustomerName, Type = i.Type, Category = i.Category, InvoiceHeader = i.InvoiceHeader, TaxID = i.TaxID, CustomerAddTel = i.CustomerAddTel, CustomerBank = i.CustomerBank, AutualCustomerName = i.AutualCustomerName, Currency = i.Currency, ReceiptCurrency = i.ReceiptCurrency, ApplyAmount = i.ApplyAmount, InvoiceAmount = i.InvoiceAmount, OperatorId = i.OperatorId, IsLocked = i.IsLocked, LockUserId = i.LockUserId, LockTime = i.LockTime, TaxRate = i.TaxRate, OrgId = i.OrgId, SaleDeptId = i.SaleDeptId, IsCancelled = i.IsCancelled, CancelUserId = i.CancelUserId, CancelTime = i.CancelTime, CreateTime = i.CreateTime, CreateBy = i.CreateBy, InvoiceApplicationList = SqlFunc.Subqueryable().InnerJoin((d, a) => d.ApplicationId == i.Id && d.Category == DetailCategory.InvoiceIssuance && d.RefId == a.Id) .GroupBy((d, a) => a.ApplicationNO).ToList((d, a) => a.ApplicationNO) }); if (!request.OtherQueryCondition.IsNullOrEmpty()) { query = query.Where(i => i.InvoiceApplicationList.Contains(request.OtherQueryCondition)); } var whereList = request.GetConditionalModels(Db); var result = await query.Where(whereList).ToQueryPageAsync(request.PageCondition); if (result.Data.Count > 0) { var userIds = result.Data.Select(x => x.CreateBy) .Union(result.Data.Where(x => x.LockUserId.HasValue).Select(x => x.LockUserId.Value)) .Union(result.Data.Where(x => x.OperatorId.HasValue).Select(x => x.OperatorId.Value)) .Distinct(); var users = await Db.Queryable().Where(x => userIds.Contains(x.Id)).Select(x => new { x.Id, x.UserName }).ToListAsync(); var orgIds = result.Data.Where(x => x.SaleDeptId.HasValue).Select(x => x.SaleDeptId.Value) .Union(result.Data.Where(x => x.OrgId.HasValue).Select(x => x.OrgId.Value)) .Distinct(); var orgs = await Db.Queryable().Where(x => orgIds.Contains(x.Id)).Select(x => new { x.Id, x.OrgName }).ToListAsync(); foreach (var item in result.Data) { item.CreateByName = users.Find(x => x.Id == item.CreateBy)?.UserName; item.LockUserName = users.Find(x => x.Id == item.LockUserId)?.UserName; item.OperatorName = users.Find(x => x.Id == item.OperatorId)?.UserName; item.SaleDeptName = orgs.Find(x => x.Id == item.SaleDeptId)?.OrgName; item.OrgName = orgs.Find(x => x.Id == item.OrgId)?.OrgName; } } return result; } public Task DeleteAsync(params long[] ids) { throw new NotImplementedException(); } public Task DeleteDetailAsync(params long[] ids) { throw new NotImplementedException(); } public Task SetLockAsync(bool isLocked, params long[] ids) { throw new NotImplementedException(); } } }