Browse Source

结算删除接口

master
mahao 2 years ago
parent
commit
f9e4a11019
  1. 150
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PUB_SA_SERVICE.cs

150
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PUB_SA_SERVICE.cs

@ -6,6 +6,7 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using SettleAccount.Domain.BQ;
using Volo.Abp;
using Volo.Abp.Application.Dtos;
@ -131,52 +132,109 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase<PUB_SA>
public async Task DeleteAsync(Guid id)
{
//结算主表
PUB_SA pubSaDelEntity;
List<PUB_SA> pubSas = new List<PUB_SA>();
//结算明细
List<PUB_SA_DETAIL> pubSaDetailDelEntitys;
List<PUB_SA_DETAIL> pubSaDetails = new List<PUB_SA_DETAIL>();
//可结算主表
List<PUB_CAN_SA> pubCanSaDelEntitys;
List<PUB_CAN_SA> pubCanSas = new List<PUB_CAN_SA>();
//可结算明细
List<PUB_CAN_SA_DETAIL> pubCanSaDetailDelEntitys;
List<PUB_CAN_SA_DETAIL> pubCanSaDetails = new List<PUB_CAN_SA_DETAIL>();
//不可结算
List<PUB_NOT_SA_DETAIL> pubNotSaDetailDelEntitys;
List<PUB_NOT_SA_DETAIL> pubNotSaDetails = new List<PUB_NOT_SA_DETAIL>();
pubSaDelEntity = await _repository.FindAsync(id);
if (pubSaDelEntity == null) return;
//结算单据
string pubSaBillNum = pubSaDelEntity.BillNum;
try
{
var pubSaDelItems = await GetPubSaDelItemsAsync(id);
pubSas.AddRange(pubSaDelItems.pubSas);
pubSaDetails.AddRange(pubSaDelItems.pubSaDetails);
pubCanSas.AddRange(pubSaDelItems.pubCanSas);
pubCanSaDetails.AddRange(pubSaDelItems.pubCanSaDetails);
pubNotSaDetails.AddRange(pubSaDelItems.pubNotSaDetails);
}
catch (Exception)
{
throw;
}
//删除
if (pubSas.Any())
{
await _repository.DeleteManyAsync(pubSas);
}
if (pubSaDetails.Any())
{
await _pubSaDetailRepository.DeleteManyAsync(pubSaDetails);
}
if (pubCanSas.Any())
{
await _pubCanSaRepository.DeleteManyAsync(pubCanSas);
}
if (pubCanSaDetails.Any())
{
await _pubCanSaDetailRepository.DeleteManyAsync(pubCanSaDetails);
}
if (pubNotSaDetails.Any())
{
await _pubNotSaDetailRepository.DeleteManyAsync(pubNotSaDetails);
}
}
/// <summary>
/// 删除
/// </summary>
[HttpPost]
public async Task DeleteListAsync(List<Guid> ids)
{
//结算主表
List<PUB_SA> pubSas = new List<PUB_SA>();
//结算明细
List<PUB_SA_DETAIL> pubSaDetails = new List<PUB_SA_DETAIL>();
//可结算主表
List<PUB_CAN_SA> pubCanSas = new List<PUB_CAN_SA>();
//可结算明细
List<PUB_CAN_SA_DETAIL> pubCanSaDetails = new List<PUB_CAN_SA_DETAIL>();
//不可结算
List<PUB_NOT_SA_DETAIL> pubNotSaDetails = new List<PUB_NOT_SA_DETAIL>();
pubCanSaDelEntitys = await _pubCanSaRepository.GetListAsync(t => t.SettleBillNum == pubSaBillNum);
//验证可结算主表状态
if (pubCanSaDelEntitys.Any(t => t.State != SettleBillState.))
foreach (var id in ids)
{
throw new UserFriendlyException($"该单据可结算单状态无法删除!", "400");
}
try
{
var pubSaDelItems = await GetPubSaDelItemsAsync(id);
pubSaDetailDelEntitys = await _pubSaDetailRepository.GetListAsync(t => t.BillNum == pubSaBillNum);
pubCanSaDetailDelEntitys = await _pubCanSaDetailRepository.GetListAsync(t => t.SettleBillNum == pubSaBillNum);
pubNotSaDetailDelEntitys = await _pubNotSaDetailRepository.GetListAsync(t => t.SettleBillNum == pubSaBillNum);
pubSas.AddRange(pubSaDelItems.pubSas);
pubSaDetails.AddRange(pubSaDelItems.pubSaDetails);
pubCanSas.AddRange(pubSaDelItems.pubCanSas);
pubCanSaDetails.AddRange(pubSaDelItems.pubCanSaDetails);
pubNotSaDetails.AddRange(pubSaDelItems.pubNotSaDetails);
}
catch (Exception)
{
throw;
}
}
//删除
await _repository.DeleteAsync(pubSaDelEntity);
if (pubSaDetailDelEntitys.Any())
if (pubSas.Any())
{
await _pubSaDetailRepository.DeleteManyAsync(pubSaDetailDelEntitys);
await _repository.DeleteManyAsync(pubSas);
}
if (pubCanSaDelEntitys.Any())
if (pubSaDetails.Any())
{
await _pubCanSaRepository.DeleteManyAsync(pubCanSaDelEntitys);
await _pubSaDetailRepository.DeleteManyAsync(pubSaDetails);
}
if (pubCanSaDetailDelEntitys.Any())
if (pubCanSas.Any())
{
await _pubCanSaDetailRepository.DeleteManyAsync(pubCanSaDetailDelEntitys);
await _pubCanSaRepository.DeleteManyAsync(pubCanSas);
}
if (pubNotSaDetailDelEntitys.Any())
if (pubCanSaDetails.Any())
{
await _pubNotSaDetailRepository.DeleteManyAsync(pubNotSaDetailDelEntitys);
await _pubCanSaDetailRepository.DeleteManyAsync(pubCanSaDetails);
}
if (pubNotSaDetails.Any())
{
await _pubNotSaDetailRepository.DeleteManyAsync(pubNotSaDetails);
}
}
#endregion
@ -334,5 +392,43 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase<PUB_SA>
return ApplicationConsts.SuccessStr;
}
/// <summary>
/// 获取结算关联项
/// </summary>
private async Task<(List<PUB_SA> pubSas, List<PUB_SA_DETAIL> pubSaDetails, List<PUB_CAN_SA> pubCanSas, List<PUB_CAN_SA_DETAIL> pubCanSaDetails, List<PUB_NOT_SA_DETAIL> pubNotSaDetails)> GetPubSaDelItemsAsync(Guid id)
{
//结算主表
List<PUB_SA> pubSas = new List<PUB_SA>();
//结算明细
List<PUB_SA_DETAIL> pubSaDetails = new List<PUB_SA_DETAIL>();
//可结算主表
List<PUB_CAN_SA> pubCanSas = new List<PUB_CAN_SA>();
//可结算明细
List<PUB_CAN_SA_DETAIL> pubCanSaDetails = new List<PUB_CAN_SA_DETAIL>();
//不可结算
List<PUB_NOT_SA_DETAIL> pubNotSaDetails = new List<PUB_NOT_SA_DETAIL>();
var pubSaEntity = await _repository.FirstOrDefaultAsync(t => t.Id.Equals(id));
if (pubSaEntity != null)
{
//结算单据
string pubSaBillNum = pubSaEntity.BillNum;
pubCanSas = await _pubCanSaRepository.GetListAsync(t => t.SettleBillNum == pubSaBillNum);
//验证可结算主表状态
if (pubCanSas.Any(t => t.State != SettleBillState.) == false)
{
throw new UserFriendlyException($"{pubSaBillNum} 该单据可结算单状态无法删除!", "400");
}
pubSas.Add(pubSaEntity);
pubSaDetails = await _pubSaDetailRepository.GetListAsync(t => t.BillNum == pubSaBillNum);
pubCanSaDetails = await _pubCanSaDetailRepository.GetListAsync(t => t.SettleBillNum == pubSaBillNum);
pubNotSaDetails = await _pubNotSaDetailRepository.GetListAsync(t => t.SettleBillNum == pubSaBillNum);
}
return (pubSas, pubSaDetails, pubCanSas , pubCanSaDetails, pubNotSaDetails);
}
#endregion
}

Loading…
Cancel
Save