明细表删除引用实体基类

usertest
嵇文龙 4 months ago
parent a1d2c07192
commit c0c630bbee

@ -1,5 +1,4 @@
using DS.Module.Core;
using DS.Module.Core.Data;
using DS.Module.Core.Enums;
using DS.WMS.Core.Fee.Entity;
using SqlSugar;
@ -10,8 +9,14 @@ namespace DS.WMS.Core.Application.Entity
/// 费用相关申请明细
/// </summary>
[SugarTable("application_detail", TableDescription = "费用相关申请明细")]
public class ApplicationDetail : BaseModelV2<long>
public class ApplicationDetail
{
/// <summary>
/// 主键ID
/// </summary>
[SugarColumn(IsPrimaryKey = true)]
public long Id { get; set; }
/// <summary>
/// 申请单ID
/// </summary>

@ -0,0 +1,43 @@
using DS.WMS.Core.Fee.Entity;
using SqlSugar;
namespace DS.WMS.Core.Application.Entity
{
/// <summary>
/// 费用代码与发票申请明细关系
/// </summary>
[SugarTable("fee_code_invoice_detail", TableDescription = "费用代码与发票申请明细关系")]
public class FeeCodeInvoiceDetail
{
/// <summary>
/// 费用代码ID
/// </summary>
[SugarColumn(IsPrimaryKey = true)]
public long FeeCodeId { get; set; }
/// <summary>
/// 费用代码
/// </summary>
[Navigate(NavigateType.OneToOne, nameof(FeeCodeId))]
public FeeCode? FeeCode { get; set; }
/// <summary>
/// 发票明细ID
/// </summary>
[SugarColumn(IsPrimaryKey = true)]
public long InvoiceDetailId { get; set; }
/// <summary>
/// 费用代码
/// </summary>
[Navigate(NavigateType.OneToOne, nameof(InvoiceDetailId))]
public InvoiceDetail? InvoiceDetail { get; set; }
/// <summary>
/// 发票明细名称
/// </summary>
[SugarColumn(ColumnDescription = "发票明细名称", Length = 50, IsNullable = false)]
public string DetailName { get; set; } = string.Empty;
}
}

@ -1,5 +1,4 @@
using DS.Module.Core.Data;
using DS.Module.Core.Enums;
using DS.Module.Core.Enums;
using SqlSugar;
namespace DS.WMS.Core.Application.Entity
@ -8,8 +7,14 @@ namespace DS.WMS.Core.Application.Entity
/// 发票申请明细
/// </summary>
[SugarTable("application_invoice_detail", TableDescription = "发票申请明细")]
public class InvoiceDetail : BaseModelV2<long>
public class InvoiceDetail
{
/// <summary>
/// 主键ID
/// </summary>
[SugarColumn(IsPrimaryKey = true)]
public long Id { get; set; }
/// <summary>
/// 申请单ID
/// </summary>

@ -37,5 +37,12 @@ namespace DS.WMS.Core.Application.Interface
/// <param name="items">业务ID与业务类型</param>
/// <returns></returns>
Task<DataResult<InvoiceApplicaitonBiz>> GetFeesAsync(params BizItem[] items);
/// <summary>
/// 删除发票明细
/// </summary>
/// <param name="ids">发票明细ID</param>
/// <returns></returns>
Task<DataResult> DeleteInvoiceDetailAsync(params long[] ids);
}
}

@ -387,6 +387,17 @@ namespace DS.WMS.Core.Application.Method
return DataResult<InvoiceApplicationDto>.Success(dto);
}
/// <summary>
/// 删除发票明细
/// </summary>
/// <param name="ids">发票明细ID</param>
/// <returns></returns>
public async Task<DataResult> DeleteInvoiceDetailAsync(params long[] ids)
{
int rows = await TenantDb.Deleteable<InvoiceDetail>().Where(x => ids.Contains(x.Id)).ExecuteCommandAsync();
return rows > 0 ? DataResult.Success : DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
}
protected override async Task<List<ApplicationDetail>> GetDetailsAsync(IEnumerable<BizItem> items)
{
var ids1 = items.Select(x => x.Id);
@ -411,7 +422,6 @@ namespace DS.WMS.Core.Application.Method
return list;
}
protected override DataResult EnsureApplication(InvoiceApplication application, InvoiceApplication dbValue)
{
if (dbValue != null && dbValue.Status != InvoiceApplicationStatus.Pending && dbValue.Status != InvoiceApplicationStatus.AuditRejected)

@ -31,6 +31,13 @@ namespace DS.WMS.Core.Invoice.Interface
/// <returns></returns>
Task<DataResult<TEntity>> SaveAsync(InvoiceRequest<TEntity> request);
/// <summary>
/// 删除发票明细
/// </summary>
/// <param name="ids">发票明细ID</param>
/// <returns></returns>
Task<DataResult> DeleteInvoiceDetailAsync(params long[] ids);
/// <summary>
/// 删除发票明细
/// </summary>

@ -186,9 +186,6 @@ namespace DS.WMS.Core.Invoice.Method
IsLocked = x.IsLocked,
Type = x.Type,
}).FirstAsync(x => x.Id == request.Invoice.Id);
if (dbValue != null && dbValue.IsLocked)
return DataResult<TEntity>.FailedWithDesc(nameof(MultiLanguageConst.InvoiceIsLocked));
}
var result = EnsureSettlement(request.Invoice, dbValue);
if (!result.Succeeded)
@ -261,7 +258,6 @@ namespace DS.WMS.Core.Invoice.Method
invoice.Details.Add(detail);
}
}
//自由申请
if (request.Details?.Count > 0)
{
@ -292,6 +288,7 @@ namespace DS.WMS.Core.Invoice.Method
}).ToList();
}
if (invoice.Details?.Count > 0)
{
//金额禁止为0
@ -334,22 +331,14 @@ namespace DS.WMS.Core.Invoice.Method
if (invoice.Details?.Count > 0)
{
await TenantDb.Insertable(invoice.Details).ExecuteCommandAsync();
//因需要重新生成明细,所以要先清空现有发票明细
await TenantDb.Deleteable<InvoiceDetail>().Where(x => x.ApplicationId == invoice.Id).ExecuteCommandAsync();
////因需要重新生成明细,所以要先清空现有发票明细
//await TenantDb.Deleteable<InvoiceDetail>().Where(x => x.ApplicationId == invoice.Id).ExecuteCommandAsync();
}
else if (invoice.InvoiceDetails?.Count > 0)
{
await TenantDb.Updateable(invoice.InvoiceDetails).UpdateColumns(x => new
{
x.Name,
x.Specification,
x.Unit,
x.UnitPrice,
x.TaxRate,
x.TaxAmount,
x.UpdateTime,
x.UpdateBy
}).ExecuteCommandAsync();
//更新发票明细
await TenantDb.Updateable(invoice.InvoiceDetails).IgnoreColumns(x => new { x.Category }).ExecuteCommandAsync();
}
await TenantDb.Updateable(invoice).IgnoreColumns(x => new
@ -378,7 +367,7 @@ namespace DS.WMS.Core.Invoice.Method
.UpdateColumns(x => new { x.InvoiceAmount })
.ExecuteCommandAsync();
await CreateInvoiceDetailsAsync([invoice]);
await BuildInvoiceDetailAsync([invoice]);
if (invoice.InvoiceDetails?.Count > 0)
await TenantDb.Insertable(invoice.InvoiceDetails).ExecuteCommandAsync();
}
@ -404,7 +393,13 @@ namespace DS.WMS.Core.Invoice.Method
/// <param name="invoice">提交的发票</param>
/// <param name="dbValue">数据库值新增时为null</param>
/// <returns></returns>
protected virtual DataResult EnsureSettlement(TEntity invoice, TEntity? dbValue) => DataResult.Success;
protected virtual DataResult EnsureSettlement(TEntity invoice, TEntity? dbValue)
{
if (dbValue != null && dbValue.IsLocked)
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.InvoiceIsLocked));
return DataResult.Success;
}
/// <summary>
/// 在保存前调用
@ -527,6 +522,17 @@ namespace DS.WMS.Core.Invoice.Method
}
}
/// <summary>
/// 删除发票明细
/// </summary>
/// <param name="ids">发票明细ID</param>
/// <returns></returns>
public async Task<DataResult> DeleteInvoiceDetailAsync(params long[] ids)
{
int rows = await TenantDb.Deleteable<InvoiceDetail>().Where(x => ids.Contains(x.Id)).ExecuteCommandAsync();
return rows > 0 ? DataResult.Success : DataResult.FailedWithDesc(nameof(MultiLanguageConst.Operation_Failed));
}
/// <summary>
/// 在删除发票或其明细之前调用,用于检查状态
/// </summary>
@ -549,12 +555,11 @@ namespace DS.WMS.Core.Invoice.Method
protected virtual async Task OnDeleteDetailAsync(List<TEntity> invoices, DeleteOption deleteOption)
{
var excludeIds = invoices.SelectMany(x => x.Details).Select(x => x.Id).ToList();
await TenantDb.Deleteable<InvoiceDetail>().Where(x => excludeIds.Contains(x.Id)).ExecuteCommandAsync();
//await TenantDb.Deleteable<InvoiceDetail>().Where(x => excludeIds.Contains(x.Id)).ExecuteCommandAsync();
if (deleteOption == DeleteOption.DetailOnly)
{
var appIds = invoices.Select(x => x.Id).ToList();
//删除明细需要同时变更发票明细
var details = await TenantDb.Queryable<ApplicationDetail>().Where(x => appIds.Contains(x.ApplicationId) && !excludeIds.Contains(x.Id))
.Select(x => new ApplicationDetail
{
@ -572,10 +577,11 @@ namespace DS.WMS.Core.Invoice.Method
item.AmountUppercase = new Money(item.ApplyAmount).ToString();
}
await CreateInvoiceDetailsAsync(invoices);
var invDetails = invoices.SelectMany(x => x.InvoiceDetails).ToList();
if (invDetails.Count > 0)
await TenantDb.Insertable(invDetails).ExecuteCommandAsync();
////删除明细需要同时变更发票明细
//await CreateInvoiceDetailsAsync(invoices);
//var invDetails = invoices.SelectMany(x => x.InvoiceDetails).ToList();
//if (invDetails.Count > 0)
// await TenantDb.Insertable(invDetails).ExecuteCommandAsync();
await TenantDb.Updateable(invoices).UpdateColumns(x => new
{
@ -603,7 +609,7 @@ namespace DS.WMS.Core.Invoice.Method
/// </summary>
/// <param name="invoices"></param>
/// <returns></returns>
protected async Task CreateInvoiceDetailsAsync(IEnumerable<TEntity> invoices)
protected async Task BuildInvoiceDetailAsync(IEnumerable<TEntity> invoices)
{
foreach (var invoice in invoices)
{

@ -257,8 +257,7 @@ namespace DS.WMS.Core.Settlement.Method
OriginalCurrency = d.OriginalCurrency,
OriginalRate = f.ExchangeRate,
ApplyAmount = d.ApplyAmount,
Currency = d.Currency,
Note = d.Note
Currency = d.Currency
}).ToListAsync();
var gList = model.Details.GroupBy(x => x.BusinessType);

@ -86,6 +86,20 @@ namespace DS.WMS.FeeApi.Controllers
return await _service.SaveAsync(request);
}
/// <summary>
/// 删除发票明细
/// </summary>
/// <param name="model">发票明细ID</param>
/// <returns></returns>
[HttpPost, Route("DeleteInvoiceDetail")]
public async Task<DataResult> DeleteInvoiceDetailAsync([FromBody] IdModel model)
{
if (!ModelState.IsValid)
return DataResult.Failed(ModelState.GetErrorMessage(), MultiLanguageConst.IllegalRequest);
return await _service.DeleteInvoiceDetailAsync(model.Ids);
}
/// <summary>
/// 删除发票明细
/// </summary>

@ -5,6 +5,7 @@ using DS.WMS.Core.Application.Dtos;
using DS.WMS.Core.Application.Entity;
using DS.WMS.Core.Application.Interface;
using DS.WMS.Core.Fee.Dtos;
using DS.WMS.Core.Invoice.Entity;
using Microsoft.AspNetCore.Mvc;
namespace DS.WMS.FeeApi.Controllers
@ -98,6 +99,20 @@ namespace DS.WMS.FeeApi.Controllers
return await _service.SaveAsync(request);
}
/// <summary>
/// 删除发票明细
/// </summary>
/// <param name="model">发票明细ID</param>
/// <returns></returns>
[HttpPost, Route("DeleteInvoiceDetail")]
public async Task<DataResult> DeleteInvoiceDetailAsync([FromBody] IdModel model)
{
if (!ModelState.IsValid)
return DataResult.Failed(ModelState.GetErrorMessage(), MultiLanguageConst.IllegalRequest);
return await _service.DeleteInvoiceDetailAsync(model.Ids);
}
/// <summary>
/// 删除申请单明细
/// </summary>
@ -106,8 +121,8 @@ namespace DS.WMS.FeeApi.Controllers
[HttpPost, Route("DeleteDetail")]
public async Task<DataResult> DeleteDetailAsync([FromBody] IdModel model)
{
if (model.Ids == null || model.Ids.Length == 0)
return DataResult.Failed("参数无效", MultiLanguageConst.IllegalRequest);
if (!ModelState.IsValid)
return DataResult.Failed(ModelState.GetErrorMessage(), MultiLanguageConst.IllegalRequest);
return await _service.DeleteDetailAsync(model.Ids);
}
@ -120,8 +135,8 @@ namespace DS.WMS.FeeApi.Controllers
[HttpPost, Route("Delete")]
public async Task<DataResult> DeleteAsync([FromBody] IdModel model)
{
if (model.Ids == null || model.Ids.Length == 0)
return DataResult.Failed("参数无效", MultiLanguageConst.IllegalRequest);
if (!ModelState.IsValid)
return DataResult.Failed(ModelState.GetErrorMessage(), MultiLanguageConst.IllegalRequest);
return await _service.DeleteAsync(model.Ids);
}
@ -134,8 +149,8 @@ namespace DS.WMS.FeeApi.Controllers
[HttpPost, Route("ApplyAudit")]
public async Task<DataResult> ApplyAuditAsync([FromBody] IdModel model)
{
if (model.Ids == null || model.Ids.Length == 0)
return DataResult.Failed("参数无效", MultiLanguageConst.IllegalRequest);
if (!ModelState.IsValid)
return DataResult.Failed(ModelState.GetErrorMessage(), MultiLanguageConst.IllegalRequest);
return await _service.SubmitApprovalAsync(AuditType.PaidApplication, model.Remark, model.Ids);
}
@ -148,8 +163,8 @@ namespace DS.WMS.FeeApi.Controllers
[HttpPost, Route("Withdraw")]
public async Task<DataResult> WithdrawAsync([FromBody] IdModel model)
{
if (model.Ids == null || model.Ids.Length == 0)
return DataResult.Failed("参数无效", MultiLanguageConst.IllegalRequest);
if (!ModelState.IsValid)
return DataResult.Failed(ModelState.GetErrorMessage(), MultiLanguageConst.IllegalRequest);
return await _service.WithdrawAsync(model.Ids);
}

Loading…
Cancel
Save