wanggang 1 year ago
parent
commit
7e6fc05a37
  1. 2
      code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/components/list/index.js
  2. 2
      code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/models/pub_sa_service.js
  3. 98
      code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/BBAC_SA_DTO.cs
  4. 5
      code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/HBPO_SA_DTO.cs
  5. 44
      code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/PUB_SA_DTO.cs
  6. 441
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_SA_SERVICE.cs
  7. 349
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/HBPO_SA_SERVICE.cs
  8. 32
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PUB_SA_SERVICE.cs
  9. 1
      code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs
  10. 2
      code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/BBAC_SA.cs
  11. 5120
      code/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Migrations/20230803033051_20230803-1.Designer.cs
  12. 45
      code/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Migrations/20230803033051_20230803-1.cs
  13. 14
      code/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Migrations/SettleAccountDbContextModelSnapshot.cs

2
code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/components/list/index.js

@ -690,7 +690,7 @@ export default {
} }
}); });
if (config.query.schema.properties.businessType.default) { if (config.query.schema.properties.businessType.default) {
formData.append("bussniType", config.query.schema.properties.businessType.default); formData.append("businessType", config.query.schema.properties.businessType.default);
} }
for (let i = 0; i < fileList.value.length; i++) { for (let i = 0; i < fileList.value.length; i++) {
formData.append(`files`, fileList.value[i].raw); formData.append(`files`, fileList.value[i].raw);

2
code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/wwwroot/models/pub_sa_service.js

@ -21,7 +21,7 @@ const schema = {
}; };
const queryUrl = "settleaccount/pub_sa_service/get-list"; const queryUrl = "settleaccount/pub_sa_service/get-list";
const deleteUrl = "settleaccount/pub_sa_service/delete"; const deleteUrl = "settleaccount/pub_sa_service/delete-list";
const importUrl = "settleaccount/pub_sa_service/import-by-business-type"; const importUrl = "settleaccount/pub_sa_service/import-by-business-type";
const queryMethod = "POST"; const queryMethod = "POST";
const deleteMethod = "POST"; const deleteMethod = "POST";

98
code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/BBAC_SA_DTO.cs

@ -0,0 +1,98 @@
using System;
using System.ComponentModel.DataAnnotations;
using Magicodes.ExporterAndImporter.Core;
using Volo.Abp.Application.Dtos;
namespace Win.Sfs.SettleAccount.Entities.BQ.Dtos;
/// <summary>
/// BBAC结算单
/// </summary>
public class BBAC_SA_DTO : EntityDto<Guid>
{
/// <summary>
/// 期间
/// </summary>
[Display(Name = "期间")]
public int Version { get; set; }
/// <summary>
/// 结算单据
/// </summary>
[Display(Name = "结算单据")]
public string BillNum { get; set; }
/// <summary>
/// 出库单号
/// </summary>
[Display(Name = "出库单号")]
public string DNBillNum { get; set; }
/// <summary>
/// 1、新建 2、已有出库3、已有扣减寄售库
/// </summary>
[Display(Name = "状态")]
public string State { get; set; }
/// <summary>
/// 明细记录行数
/// </summary>
[Display(Name = "明细记录行数")]
public string RecordCount { get; set; }
/// <summary>
/// 工厂地点
/// </summary>
[Display(Name = "工厂地点")]
public string Site { get; set; }
/// <summary>
/// 业务类型
/// </summary>
[Display(Name = "业务类型")]
public EnumBusinessType BusinessType { get; set; }
}
/// <summary>
/// BBAC结算明细导入
/// </summary>
public class BBAC_SA_DETAIL_IMPORT_DTO
{
/// <summary>
/// 结算日期
/// </summary>
[Display(Name = "Posting Date")]
[ImporterHeader(Name = "Posting Date", Format = "yyyy/MM/dd HH:mm:ss")]
public DateTime SettleDate { set; get; }
/// <summary>
/// 结算分组号
/// </summary>
[Display(Name = "Reference")]
[Required(ErrorMessage = "{0}不能为空")]
[ImporterHeader(Name = "Reference")]
public string GroupNum { get; set; }
/// <summary>
/// 客户零件号
/// </summary>
[Display(Name = "Material")]
[Required(ErrorMessage = "{0}不能为空")]
[ImporterHeader(Name = "Material")]
public string LU { get; set; }
/// <summary>
/// 数量
/// </summary>
[Display(Name = "结算数量")]
[ImporterHeader(Name = "Qty")]
public decimal Qty { get; set; }
/// <summary>
/// 生产号
/// </summary>
[Display(Name = "External Call Number")]
[Required(ErrorMessage = "{0}不能为空")]
[ImporterHeader(Name = "External Call Number")]
public string PN { get; set; }
}

5
code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/HBPO_SA_DTO.cs

@ -1,13 +1,14 @@
using System; using System;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using Magicodes.ExporterAndImporter.Core; using Magicodes.ExporterAndImporter.Core;
using Volo.Abp.Application.Dtos;
namespace Win.Sfs.SettleAccount.Entities.BQ.Dtos; namespace Win.Sfs.SettleAccount.Entities.BQ.Dtos;
/// <summary> /// <summary>
/// HBPO结算单 /// HBPO结算单
/// </summary> /// </summary>
public class HBPO_SA_DTO public class HBPO_SA_DTO : EntityDto<Guid>
{ {
/// <summary> /// <summary>
/// 期间 /// 期间
@ -60,7 +61,7 @@ public class HBPO_SA_DETAIL_IMPORT_DTO
/// <summary> /// <summary>
/// 结算日期 /// 结算日期
/// </summary> /// </summary>
[Display(Name = "结算日期")] [Display(Name = "ReceiveDate")]
[ImporterHeader(Name = "ReceiveDate", Format = "yyyy/MM/dd HH:mm:ss")] [ImporterHeader(Name = "ReceiveDate", Format = "yyyy/MM/dd HH:mm:ss")]
public DateTime SettleDate { set; get; } public DateTime SettleDate { set; get; }

44
code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/PUB_SA_DTO.cs

@ -145,6 +145,50 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Dtos
public string GroupNum { get; set; } public string GroupNum { get; set; }
} }
/// <summary>
/// 买单件HBPO导入
/// </summary>
public class MaiDanJianHBPOImportDto
{
/// <summary>
/// 结算日期
/// </summary>
[Display(Name = "买单日期")]
[ImporterHeader(Name = "买单日期")]
public DateTime SettleDate { set; get; }
/// <summary>
/// 零件号
/// </summary>
[Display(Name = "零件号")]
[Required(ErrorMessage = "{0}不能为空")]
[ImporterHeader(Name = "零件号")]
public string LU { get; set; }
/// <summary>
/// 生产号
/// </summary>
[Display(Name = "现产品生产号")]
[ImporterHeader(Name = "现产品生产号")]
[Required(ErrorMessage = "{0}不能为空")]
public string PN { get; set; }
/// <summary>
/// 数量
/// </summary>
[Display(Name = "数量")]
[ImporterHeader(Name = "数量")]
public decimal Qty { get; set; }
/// <summary>
/// 结算分组号
/// </summary>
[Display(Name = "五联单号")]
[ImporterHeader(Name = "五联单号")]
[Required(ErrorMessage = "{0}不能为空")]
public string GroupNum { get; set; }
}
/// <summary> /// <summary>
/// 备件导入 /// 备件导入
/// </summary> /// </summary>

441
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_SA_SERVICE.cs

@ -0,0 +1,441 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.LinqAsync;
using System.Threading.Tasks;
using AutoMapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SettleAccount.Domain.BQ;
using Volo.Abp;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Caching;
using Win.Abp.Snowflakes;
using Win.Sfs.BaseData.ImportExcelCommon;
using Win.Sfs.SettleAccount.Bases;
using Win.Sfs.SettleAccount.CommonManagers;
using Win.Sfs.SettleAccount.Constant;
using Win.Sfs.SettleAccount.Entities.BQ.Dtos;
using Win.Sfs.SettleAccount.Entities.Prices;
using Win.Sfs.SettleAccount.ExcelImporter;
using Win.Sfs.SettleAccount.ExportReports;
using Win.Sfs.SettleAccount.MaterialRelationships;
using Win.Sfs.Shared.RepositoryBase;
namespace Win.Sfs.SettleAccount.Entities.BQ;
/// <summary>
/// JISBBAC结算
/// </summary>
[AllowAnonymous]
[Route("api/settleaccount/[controller]/[action]")]
public class BBAC_SA_SERVICE : SettleAccountApplicationBase<BBAC_SA>
{
/// <summary>
/// BBAC结算仓储
/// </summary>
private readonly INormalEfCoreRepository<BBAC_SA, Guid> _bbacSaRepository;
/// <summary>
/// BBAC结算明细仓储
/// </summary>
private readonly INormalEfCoreRepository<BBAC_SA_DETAIL, Guid> _bbacSaDetailRepository;
/// <summary>
/// BBAC可结算仓储
/// </summary>
private readonly INormalEfCoreRepository<BBAC_CAN_SA, Guid> _bbacCanSaRepository;
/// <summary>
/// BBAC可结算明细仓储
/// </summary>
private readonly INormalEfCoreRepository<BBAC_CAN_SA_DETAIL, Guid> _bbacCanSaDetailRepository;
/// <summary>
/// BBAC不可结算明细仓储
/// </summary>
private readonly INormalEfCoreRepository<BBAC_NOT_SA_DETAIL, Guid> _bbacNotSaDetailRepository;
/// <summary>
/// 销售价格仓储
/// </summary>
private readonly INormalEfCoreRepository<PriceList, Guid> _priceListRepository;
/// <summary>
/// 客户零件关系仓储
/// </summary>
private readonly INormalEfCoreRepository<MaterialRelationship, Guid> _materialRelationshipRepository;
/// <summary>
/// 替换件关系仓储
/// </summary>
private readonly INormalEfCoreRepository<TB_RePartsRelationship, Guid> _tbRePartsRelationshipRepository;
/// <summary>
/// 业务类型
/// </summary>
private readonly EnumBusinessType _businessType = EnumBusinessType.JisBBAC;
/// <summary>
/// 构造
/// </summary>
public BBAC_SA_SERVICE(INormalEfCoreRepository<BBAC_SA, Guid> bbacSaRepository,
INormalEfCoreRepository<BBAC_SA_DETAIL, Guid> bbacSaDetailRepository,
INormalEfCoreRepository<BBAC_CAN_SA, Guid> bbacCanSaRepository,
INormalEfCoreRepository<BBAC_CAN_SA_DETAIL, Guid> bbacCanSaDetailRepository,
INormalEfCoreRepository<BBAC_NOT_SA_DETAIL, Guid> bbacNotSaDetailRepository,
INormalEfCoreRepository<PriceList, Guid> priceListRepository,
INormalEfCoreRepository<MaterialRelationship, Guid> materialRelationshipRepository,
INormalEfCoreRepository<TB_RePartsRelationship, Guid> tbRePartsRelationshipRepository,
IDistributedCache<BBAC_SA> cache,
IExcelImportAppService excelImportService,
ISnowflakeIdGenerator snowflakeIdGenerator,
ICommonManager commonManager
) : base(cache, excelImportService, snowflakeIdGenerator, commonManager)
{
_bbacSaRepository = bbacSaRepository;
_bbacSaDetailRepository = bbacSaDetailRepository;
_bbacCanSaRepository = bbacCanSaRepository;
_bbacCanSaDetailRepository = bbacCanSaDetailRepository;
_bbacNotSaDetailRepository = bbacNotSaDetailRepository;
_priceListRepository = priceListRepository;
_materialRelationshipRepository = materialRelationshipRepository;
_tbRePartsRelationshipRepository = tbRePartsRelationshipRepository;
}
#region 导入、导出
/// <summary>
/// 导入
/// </summary>
[HttpPost]
public async Task<string> ImportAsync([FromForm] IFormFileCollection files)
{
#region 导入数据转换、数据校验
ExportImporter _exportImporter = new ExportImporter();
var result = await _exportImporter.UploadExcelImport<BBAC_SA_DETAIL_IMPORT_DTO>(files, _excelImportService);
var importHBOPSaDetails = ObjectMapper.Map<List<BBAC_SA_DETAIL_IMPORT_DTO>, List<BBAC_SA_DETAIL>>(result);
//Site包含CN1 亦庄
//Site包含CN5 顺义
var importCN1HBOPSaDetails = importHBOPSaDetails.FindAll(t => t.Site.Contains("CN1"));
var importCN5HBOPSaDetails = importHBOPSaDetails.FindAll(t => t.Site.Contains("CN5"));
//数据校验
var checkList = new List<ErrorExportDto>();
//结算分组号
var bbacSaGroupNums = importHBOPSaDetails.Select(t => t.GroupNum).Distinct();
//已存在的结算分组号
var havBBACSaGroupNums = (await _bbacSaDetailRepository.GetListAsync(t => bbacSaGroupNums.Contains(t.GroupNum))).Select(t => t.GroupNum).Distinct();
if (havBBACSaGroupNums.Any() == true)
{
foreach (var item in havBBACSaGroupNums)
{
checkList.Add(new ErrorExportDto(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, $"结算分组号{item}已存在", string.Empty));
}
}
if (checkList.Count > 0)
{
return await ExportErrorReportAsync(checkList);
}
#endregion
if (importCN1HBOPSaDetails.Any())
{
await SaDataHandleAsync(importCN1HBOPSaDetails, "CN1");
}
if (importCN5HBOPSaDetails.Any())
{
await SaDataHandleAsync(importCN5HBOPSaDetails, "CN5");
}
return ApplicationConsts.SuccessStr;
}
#endregion
#region CURD
/// <summary>
/// 获取列表
/// </summary>
[HttpPost]
public async Task<PagedResultDto<BBAC_SA_DTO>> GetListAsync(RequestDto input)
{
var entities = await _bbacSaRepository.GetListByFilterAsync(input.Filters, input.Sorting, input.MaxResultCount, input.SkipCount, true);
var totalCount = await _bbacSaRepository.GetCountByFilterAsync(input.Filters);
var dtos = ObjectMapper.Map<List<BBAC_SA>, List<BBAC_SA_DTO>>(entities);
return new PagedResultDto<BBAC_SA_DTO>(totalCount, dtos);
}
/// <summary>
/// 删除
/// </summary>
[HttpPost]
public async Task DeleteAsync(Guid id)
{
//结算主表
BBAC_SA bbacSaDelEntity;
//结算明细
List<BBAC_SA_DETAIL> bbacSaDetailDelEntitys;
//可结算主表
List<BBAC_CAN_SA> bbacCanSaDelEntitys;
//可结算明细
List<BBAC_CAN_SA_DETAIL> bbacCanSaDetailDelEntitys;
//不可结算
List<BBAC_NOT_SA_DETAIL> bbacNotSaDetailDelEntitys;
bbacSaDelEntity = await _bbacSaRepository.FindAsync(id);
if (bbacSaDelEntity == null)
{
throw new UserFriendlyException($"未获取到结算单!", "400");
}
//结算单据
string bbacSaBillNum = bbacSaDelEntity.BillNum;
bbacCanSaDelEntitys = await _bbacCanSaRepository.GetListAsync(t => t.SettleBillNum == bbacSaBillNum);
//验证可结算主表状态
if (bbacCanSaDelEntitys.Any(t => t.State != SettleBillState.))
{
throw new UserFriendlyException($"该单据可结算单状态无法删除!", "400");
}
bbacSaDetailDelEntitys = await _bbacSaDetailRepository.GetListAsync(t => t.BillNum == bbacSaBillNum);
bbacCanSaDetailDelEntitys = await _bbacCanSaDetailRepository.GetListAsync(t => t.SettleBillNum == bbacSaBillNum);
bbacNotSaDetailDelEntitys = await _bbacNotSaDetailRepository.GetListAsync(t => t.SettleBillNum == bbacSaBillNum);
//删除
await _bbacSaRepository.DeleteAsync(bbacSaDelEntity);
if (bbacSaDetailDelEntitys.Any())
{
await _bbacSaDetailRepository.DeleteManyAsync(bbacSaDetailDelEntitys);
}
if (bbacCanSaDelEntitys.Any())
{
await _bbacCanSaRepository.DeleteManyAsync(bbacCanSaDelEntitys);
}
if (bbacCanSaDetailDelEntitys.Any())
{
await _bbacCanSaDetailRepository.DeleteManyAsync(bbacCanSaDetailDelEntitys);
}
if (bbacNotSaDetailDelEntitys.Any())
{
await _bbacNotSaDetailRepository.DeleteManyAsync(bbacNotSaDetailDelEntitys);
}
}
/// <summary>
/// 删除
/// </summary>
[HttpPost]
public async Task DeleteListAsync(List<Guid> ids)
{
//结算主表
List<BBAC_SA> bbacSas = new List<BBAC_SA>();
//结算明细
List<BBAC_SA_DETAIL> bbacSaDetails = new List<BBAC_SA_DETAIL>();
//可结算主表
List<BBAC_CAN_SA> bbacCanSas = new List<BBAC_CAN_SA>();
//可结算明细
List<BBAC_CAN_SA_DETAIL> bbacCanSaDetails = new List<BBAC_CAN_SA_DETAIL>();
//不可结算
List<BBAC_NOT_SA_DETAIL> bbacNotSaDetails = new List<BBAC_NOT_SA_DETAIL>();
foreach (var id in ids)
{
try
{
var bbacSaDelItems = await GetBBACSaDelItemsAsync(id);
bbacSas.AddRange(bbacSaDelItems.bbacSas);
bbacSaDetails.AddRange(bbacSaDelItems.bbacSaDetails);
bbacCanSas.AddRange(bbacSaDelItems.bbacCanSas);
bbacCanSaDetails.AddRange(bbacSaDelItems.bbacCanSaDetails);
bbacNotSaDetails.AddRange(bbacSaDelItems.bbacNotSaDetails);
}
catch (Exception)
{
throw;
}
}
//删除
if (bbacSas.Any())
{
await _bbacSaRepository.DeleteManyAsync(bbacSas);
}
if (bbacSaDetails.Any())
{
await _bbacSaDetailRepository.DeleteManyAsync(bbacSaDetails);
}
if (bbacCanSas.Any())
{
await _bbacCanSaRepository.DeleteManyAsync(bbacCanSas);
}
if (bbacCanSaDetails.Any())
{
await _bbacCanSaDetailRepository.DeleteManyAsync(bbacCanSaDetails);
}
if (bbacNotSaDetails.Any())
{
await _bbacNotSaDetailRepository.DeleteManyAsync(bbacNotSaDetails);
}
}
#endregion
#region 私有方法
/// <summary>
/// 结算数据处理
/// </summary>
private async Task SaDataHandleAsync(List<BBAC_SA_DETAIL> bbacSaDetails, string site)
{
//结算单号
var bbacSaBillNum = OrderNumberGenerator.GenerateOrderNumber("SA");
//结算主表
var bbacSa = new BBAC_SA()
{
BillNum = bbacSaBillNum,
State = "1",
Site = site,
};
//可结算单号
var bbacCanSaBillNum = OrderNumberGenerator.GenerateOrderNumber("C");
//可结算主表
var bbacCanSa = new BBAC_CAN_SA()
{
BillNum = bbacCanSaBillNum,
SettleBillNum = bbacSaBillNum,
State = SettleBillState.,
BusinessType = _businessType,
Site = site,
};
//可结算明细
var bbacCanSaDetails = new List<BBAC_CAN_SA_DETAIL>();
//不可结算明细
var bbacNotSaDetails = new List<BBAC_NOT_SA_DETAIL>();
//客户零件关系
var materialRelationships = new List<MaterialRelationship>();
#region 处理结算数据
//销售价格
var priceListEntitys = await _priceListRepository.GetAllAsync();
bbacSaDetails.ForEach(bbacSaDetail =>
{
List<string> luList = bbacSaDetail.LU.Split(" ").ToList();
bbacSaDetail.LU = luList[0].Replace(" ", "");
if (luList.Count > 1)
{
luList.RemoveAt(0);
var luAssemble = luList.Select(t => t.Replace(" ", ""));
bbacSaDetail.LU += luAssemble.Aggregate(" ", (current, index) => current + index);
}
bbacSaDetail.BillNum = bbacSaBillNum;
bbacSaDetail.KeyCode = bbacSaDetail.PN + bbacSaDetail.LU;
//根据物料号、结算日期获取价格
var priceListEntity = priceListEntitys.Find(t => t.LU == bbacSaDetail.LU && bbacSaDetail.SettleDate > t.BeginTime && bbacSaDetail.SettleDate < t.EndTime);
bbacSaDetail.Price = priceListEntity?.Price ?? default;
});
//导入的零件号集合
var importPubSaLUs = bbacSaDetails.Select(t => t.LU).Distinct();
var materialRelationshipEntitys = await _materialRelationshipRepository.GetListAsync(t => importPubSaLUs.Contains(t.SettleMaterialCode));
var materialRelationshipEntitySettleMaterialCodes = materialRelationshipEntitys.Select(t => t.SettleMaterialCode).Distinct();
/*
* ()
*
* 6-
*/
var noExistSettleMaterialCodes = importPubSaLUs.Except(materialRelationshipEntitySettleMaterialCodes);
noExistSettleMaterialCodes.ForEach(t =>
{
var materialRelationship = new MaterialRelationship(GuidGenerator.Create(), t.Replace(" ", "-"), "", t, _businessType.ToString());
materialRelationships.Add(materialRelationship);
});
#endregion
#region 入库数据赋值
//根据价格区分结算、不可结算
var bbacSaDetailsCanSes = bbacSaDetails.FindAll(t => t.Price != default);
var bbacSaDetailsNotCanSes = bbacSaDetails.FindAll(t => t.Price == default);
//可结算明细
bbacCanSaDetails = ObjectMapper.Map<List<BBAC_SA_DETAIL>, List<BBAC_CAN_SA_DETAIL>>(bbacSaDetailsCanSes);
//不可结算明细
bbacNotSaDetails = ObjectMapper.Map<List<BBAC_SA_DETAIL>, List<BBAC_NOT_SA_DETAIL>>(bbacSaDetailsNotCanSes);
#endregion
#region 添加入库
await _bbacSaRepository.InsertAsync(bbacSa);
await _bbacSaDetailRepository.InsertManyAsync(bbacSaDetails);
if (bbacCanSaDetails.Count > 0)
{
bbacCanSa.InvGroupNum = bbacCanSaDetails.Count.ToString();
bbacCanSaDetails.ForEach(bbacCanSaDetail =>
{
bbacCanSaDetail.BillNum = bbacCanSaDetail.InvGroupNum = bbacCanSaBillNum;
bbacCanSaDetail.BusinessType = _businessType;
});
await _bbacCanSaRepository.InsertAsync(bbacCanSa);
await _bbacCanSaDetailRepository.InsertManyAsync(bbacCanSaDetails);
}
if (bbacNotSaDetails.Count > 0)
{
bbacNotSaDetails.ForEach(bbacNotSaDetail =>
{
bbacNotSaDetail.BusinessType = _businessType;
});
await _bbacNotSaDetailRepository.InsertManyAsync(bbacNotSaDetails);
}
if (materialRelationships.Count > 0)
{
await _materialRelationshipRepository.InsertManyAsync(materialRelationships);
}
#endregion
}
/// <summary>
/// 获取结算关联项
/// </summary>
private async Task<(List<BBAC_SA> bbacSas, List<BBAC_SA_DETAIL> bbacSaDetails, List<BBAC_CAN_SA> bbacCanSas, List<BBAC_CAN_SA_DETAIL> bbacCanSaDetails, List<BBAC_NOT_SA_DETAIL> bbacNotSaDetails)> GetBBACSaDelItemsAsync(Guid id)
{
//结算主表
List<BBAC_SA> bbacSas = new List<BBAC_SA>();
//结算明细
List<BBAC_SA_DETAIL> bbacSaDetails = new List<BBAC_SA_DETAIL>();
//可结算主表
List<BBAC_CAN_SA> bbacCanSas = new List<BBAC_CAN_SA>();
//可结算明细
List<BBAC_CAN_SA_DETAIL> bbacCanSaDetails = new List<BBAC_CAN_SA_DETAIL>();
//不可结算
List<BBAC_NOT_SA_DETAIL> bbacNotSaDetails = new List<BBAC_NOT_SA_DETAIL>();
var bbacSaEntity = await _bbacSaRepository.FirstOrDefaultAsync(t => t.Id.Equals(id));
if (bbacSaEntity != null)
{
//结算单据
string bbacSaBillNum = bbacSaEntity.BillNum;
bbacCanSas = await _bbacCanSaRepository.GetListAsync(t => t.SettleBillNum == bbacSaBillNum);
//验证可结算主表状态
if (bbacCanSas.Any() && bbacCanSas.Any(t => t.State != SettleBillState.))
{
throw new UserFriendlyException($"{bbacSaBillNum} 该单据可结算单状态无法删除!", "400");
}
bbacSas.Add(bbacSaEntity);
bbacSaDetails = await _bbacSaDetailRepository.GetListAsync(t => t.BillNum == bbacSaBillNum);
bbacCanSaDetails = await _bbacCanSaDetailRepository.GetListAsync(t => t.SettleBillNum == bbacSaBillNum);
bbacNotSaDetails = await _bbacNotSaDetailRepository.GetListAsync(t => t.SettleBillNum == bbacSaBillNum);
}
return (bbacSas, bbacSaDetails, bbacCanSas, bbacCanSaDetails, bbacNotSaDetails);
}
#endregion
}

349
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/HBPO_SA_SERVICE.cs

@ -1,28 +1,26 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using SettleAccount.Domain.BQ; using SettleAccount.Domain.BQ;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Domain.Repositories;
using Volo.Abp; using Volo.Abp;
using Win.Sfs.SettleAccount.Entities.BQ.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.Caching; using Volo.Abp.Caching;
using Win.Abp.Snowflakes; using Win.Abp.Snowflakes;
using Win.Sfs.BaseData.ImportExcelCommon; using Win.Sfs.BaseData.ImportExcelCommon;
using Win.Sfs.SettleAccount.CommonManagers;
using Win.Sfs.SettleAccount.Entities.Prices;
using Win.Sfs.SettleAccount.MaterialRelationships;
using Win.Sfs.Shared.RepositoryBase;
using System;
using System.Linq;
using Microsoft.AspNetCore.Http;
using Win.Sfs.SettleAccount.Bases; using Win.Sfs.SettleAccount.Bases;
using Win.Sfs.SettleAccount.CommonManagers;
using Win.Sfs.SettleAccount.Constant; using Win.Sfs.SettleAccount.Constant;
using Win.Sfs.SettleAccount.Entities.BQ.Dtos;
using Win.Sfs.SettleAccount.Entities.Prices;
using Win.Sfs.SettleAccount.ExcelImporter; using Win.Sfs.SettleAccount.ExcelImporter;
using Win.Sfs.SettleAccount.ExportReports; using Win.Sfs.SettleAccount.ExportReports;
using OfficeOpenXml; using Win.Sfs.SettleAccount.MaterialRelationships;
using OfficeOpenXml.Core; using Win.Sfs.Shared.RepositoryBase;
namespace Win.Sfs.SettleAccount.Entities.BQ; namespace Win.Sfs.SettleAccount.Entities.BQ;
@ -73,6 +71,11 @@ public class HBPO_SA_SERVICE : SettleAccountApplicationBase<HBPO_SA>
/// </summary> /// </summary>
private readonly INormalEfCoreRepository<TB_RePartsRelationship, Guid> _tbRePartsRelationshipRepository; private readonly INormalEfCoreRepository<TB_RePartsRelationship, Guid> _tbRePartsRelationshipRepository;
/// <summary>
/// 业务类型
/// </summary>
private readonly EnumBusinessType _businessType = EnumBusinessType.JisHBPO;
/// <summary> /// <summary>
/// 构造 /// 构造
/// </summary> /// </summary>
@ -107,10 +110,184 @@ public class HBPO_SA_SERVICE : SettleAccountApplicationBase<HBPO_SA>
[HttpPost] [HttpPost]
public async Task<string> ImportAsync([FromForm] IFormFileCollection files) public async Task<string> ImportAsync([FromForm] IFormFileCollection files)
{ {
//业务类型 #region 导入数据转换、数据校验
var businessType = EnumBusinessType.JisHBPO; ExportImporter _exportImporter = new ExportImporter();
var result = await _exportImporter.UploadExcelImport<HBPO_SA_DETAIL_IMPORT_DTO>(files, _excelImportService);
var importHBOPSaDetails = ObjectMapper.Map<List<HBPO_SA_DETAIL_IMPORT_DTO>, List<HBPO_SA_DETAIL>>(result);
//Site包含CN1 亦庄
//Site包含CN5 顺义
var importCN1HBOPSaDetails = importHBOPSaDetails.FindAll(t => t.Site.Contains("CN1"));
var importCN5HBOPSaDetails = importHBOPSaDetails.FindAll(t => t.Site.Contains("CN5"));
//数据校验 //数据校验
var checkList = new List<ErrorExportDto>(); var checkList = new List<ErrorExportDto>();
//结算分组号
var hbpoSaGroupNums = importHBOPSaDetails.Select(t => t.GroupNum).Distinct();
//已存在的结算分组号
var havHBPOSaGroupNums = (await _hbpoSaDetailRepository.GetListAsync(t => hbpoSaGroupNums.Contains(t.GroupNum))).Select(t => t.GroupNum).Distinct();
if (havHBPOSaGroupNums.Any() == true)
{
foreach (var item in havHBPOSaGroupNums)
{
checkList.Add(new ErrorExportDto(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, $"结算分组号{item}已存在", string.Empty));
}
}
if (checkList.Count > 0)
{
return await ExportErrorReportAsync(checkList);
}
#endregion
if (importCN1HBOPSaDetails.Any())
{
await SaDataHandleAsync(importCN1HBOPSaDetails, "CN1");
}
if (importCN5HBOPSaDetails.Any())
{
await SaDataHandleAsync(importCN5HBOPSaDetails, "CN5");
}
return ApplicationConsts.SuccessStr;
}
#endregion
#region CURD
/// <summary>
/// 获取列表
/// </summary>
[HttpPost]
public async Task<PagedResultDto<HBPO_SA_DTO>> GetListAsync(RequestDto input)
{
var entities = await _hbpoSaRepository.GetListByFilterAsync(input.Filters, input.Sorting, input.MaxResultCount, input.SkipCount, true);
var totalCount = await _hbpoSaRepository.GetCountByFilterAsync(input.Filters);
var dtos = ObjectMapper.Map<List<HBPO_SA>, List<HBPO_SA_DTO>>(entities);
return new PagedResultDto<HBPO_SA_DTO>(totalCount, dtos);
}
/// <summary>
/// 删除
/// </summary>
[HttpPost]
public async Task DeleteAsync(Guid id)
{
//结算主表
HBPO_SA hbpoSaDelEntity;
//结算明细
List<HBPO_SA_DETAIL> hbpoSaDetailDelEntitys;
//可结算主表
List<HBPO_CAN_SA> hbpoCanSaDelEntitys;
//可结算明细
List<HBPO_CAN_SA_DETAIL> hbpoCanSaDetailDelEntitys;
//不可结算
List<HBPO_NOT_SA_DETAIL> hbpoNotSaDetailDelEntitys;
hbpoSaDelEntity = await _hbpoSaRepository.FindAsync(id);
if (hbpoSaDelEntity == null)
{
throw new UserFriendlyException($"未获取到结算单!", "400");
}
//结算单据
string hbpoSaBillNum = hbpoSaDelEntity.BillNum;
hbpoCanSaDelEntitys = await _hbpoCanSaRepository.GetListAsync(t => t.SettleBillNum == hbpoSaBillNum);
//验证可结算主表状态
if (hbpoCanSaDelEntitys.Any(t => t.State != SettleBillState.))
{
throw new UserFriendlyException($"该单据可结算单状态无法删除!", "400");
}
hbpoSaDetailDelEntitys = await _hbpoSaDetailRepository.GetListAsync(t => t.BillNum == hbpoSaBillNum);
hbpoCanSaDetailDelEntitys = await _hbpoCanSaDetailRepository.GetListAsync(t => t.SettleBillNum == hbpoSaBillNum);
hbpoNotSaDetailDelEntitys = await _hbpoNotSaDetailRepository.GetListAsync(t => t.SettleBillNum == hbpoSaBillNum);
//删除
await _hbpoSaRepository.DeleteAsync(hbpoSaDelEntity);
if (hbpoSaDetailDelEntitys.Any())
{
await _hbpoSaDetailRepository.DeleteManyAsync(hbpoSaDetailDelEntitys);
}
if (hbpoCanSaDelEntitys.Any())
{
await _hbpoCanSaRepository.DeleteManyAsync(hbpoCanSaDelEntitys);
}
if (hbpoCanSaDetailDelEntitys.Any())
{
await _hbpoCanSaDetailRepository.DeleteManyAsync(hbpoCanSaDetailDelEntitys);
}
if (hbpoNotSaDetailDelEntitys.Any())
{
await _hbpoNotSaDetailRepository.DeleteManyAsync(hbpoNotSaDetailDelEntitys);
}
}
/// <summary>
/// 删除
/// </summary>
[HttpPost]
public async Task DeleteListAsync(List<Guid> ids)
{
//结算主表
List<HBPO_SA> hbpoSas = new List<HBPO_SA>();
//结算明细
List<HBPO_SA_DETAIL> hbpoSaDetails = new List<HBPO_SA_DETAIL>();
//可结算主表
List<HBPO_CAN_SA> hbpoCanSas = new List<HBPO_CAN_SA>();
//可结算明细
List<HBPO_CAN_SA_DETAIL> hbpoCanSaDetails = new List<HBPO_CAN_SA_DETAIL>();
//不可结算
List<HBPO_NOT_SA_DETAIL> hbpoNotSaDetails = new List<HBPO_NOT_SA_DETAIL>();
foreach (var id in ids)
{
try
{
var hbpoSaDelItems = await GetHBPOSaDelItemsAsync(id);
hbpoSas.AddRange(hbpoSaDelItems.hbpoSas);
hbpoSaDetails.AddRange(hbpoSaDelItems.hbpoSaDetails);
hbpoCanSas.AddRange(hbpoSaDelItems.hbpoCanSas);
hbpoCanSaDetails.AddRange(hbpoSaDelItems.hbpoCanSaDetails);
hbpoNotSaDetails.AddRange(hbpoSaDelItems.hbpoNotSaDetails);
}
catch (Exception)
{
throw;
}
}
//删除
if (hbpoSas.Any())
{
await _hbpoSaRepository.DeleteManyAsync(hbpoSas);
}
if (hbpoSaDetails.Any())
{
await _hbpoSaDetailRepository.DeleteManyAsync(hbpoSaDetails);
}
if (hbpoCanSas.Any())
{
await _hbpoCanSaRepository.DeleteManyAsync(hbpoCanSas);
}
if (hbpoCanSaDetails.Any())
{
await _hbpoCanSaDetailRepository.DeleteManyAsync(hbpoCanSaDetails);
}
if (hbpoNotSaDetails.Any())
{
await _hbpoNotSaDetailRepository.DeleteManyAsync(hbpoNotSaDetails);
}
}
#endregion
#region 私有方法
/// <summary>
/// 结算数据处理
/// </summary>
private async Task SaDataHandleAsync(List<HBPO_SA_DETAIL> hbpoSaDetails, string site)
{
//结算单号 //结算单号
var hbpoSaBillNum = OrderNumberGenerator.GenerateOrderNumber("SA"); var hbpoSaBillNum = OrderNumberGenerator.GenerateOrderNumber("SA");
//结算主表 //结算主表
@ -118,10 +295,9 @@ public class HBPO_SA_SERVICE : SettleAccountApplicationBase<HBPO_SA>
{ {
BillNum = hbpoSaBillNum, BillNum = hbpoSaBillNum,
State = "1", State = "1",
BusinessType = businessType BusinessType = _businessType,
Site = site,
}; };
//结算明细
var hbpoSaDetails = new List<HBPO_SA_DETAIL>();
//可结算单号 //可结算单号
var hbpoCanSaBillNum = OrderNumberGenerator.GenerateOrderNumber("C"); var hbpoCanSaBillNum = OrderNumberGenerator.GenerateOrderNumber("C");
//可结算主表 //可结算主表
@ -130,7 +306,8 @@ public class HBPO_SA_SERVICE : SettleAccountApplicationBase<HBPO_SA>
BillNum = hbpoCanSaBillNum, BillNum = hbpoCanSaBillNum,
SettleBillNum = hbpoSaBillNum, SettleBillNum = hbpoSaBillNum,
State = SettleBillState., State = SettleBillState.,
BusinessType = businessType BusinessType = _businessType,
Site = site,
}; };
//可结算明细 //可结算明细
var hbpoCanSaDetails = new List<HBPO_CAN_SA_DETAIL>(); var hbpoCanSaDetails = new List<HBPO_CAN_SA_DETAIL>();
@ -139,61 +316,32 @@ public class HBPO_SA_SERVICE : SettleAccountApplicationBase<HBPO_SA>
//客户零件关系 //客户零件关系
var materialRelationships = new List<MaterialRelationship>(); var materialRelationships = new List<MaterialRelationship>();
#region 导入数据转换、数据校验
ExportImporter _exportImporter = new ExportImporter();
var result = await _exportImporter.UploadExcelImport<HBPO_SA_DETAIL_IMPORT_DTO>(files, _excelImportService);
var importPubSaDetails = ObjectMapper.Map<List<HBPO_SA_DETAIL_IMPORT_DTO>, List<HBPO_SA_DETAIL>>(result);
return "";
//结算分组号
var hbpoSaGroupNums = importPubSaDetails.Select(t => t.GroupNum).Distinct();
//已存在的结算分组号
var havPubSaGroupNums = (await _hbpoSaDetailRepository.GetListAsync(t => hbpoSaGroupNums.Contains(t.GroupNum))).Select(t => t.GroupNum).Distinct();
if (havPubSaGroupNums.Any() == true)
{
foreach (var item in havPubSaGroupNums)
{
checkList.Add(new ErrorExportDto(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, $"结算分组号{item}已存在", string.Empty));
}
//throw new UserFriendlyException($"导入失败,结算分组号({string.Join(",", havPubSaGroupNums)})已存在", "400");
}
if (checkList.Count > 0)
{
return await ExportErrorReportAsync(checkList);
}
#endregion
#region 处理结算数据 #region 处理结算数据
//销售价格 //销售价格
var priceListEntitys = await _priceListRepository.GetAllAsync(); var priceListEntitys = await _priceListRepository.GetAllAsync();
importPubSaDetails.ForEach(importPubSaDetail => hbpoSaDetails.ForEach(hbpoSaDetail =>
{ {
List<string> luList = importPubSaDetail.LU.Split(" ").ToList(); List<string> luList = hbpoSaDetail.LU.Split(" ").ToList();
importPubSaDetail.LU = luList[0].Replace(" ", ""); hbpoSaDetail.LU = luList[0].Replace(" ", "");
if (luList.Count > 1) if (luList.Count > 1)
{ {
luList.RemoveAt(0); luList.RemoveAt(0);
var luAssemble = luList.Select(t => t.Replace(" ", "")); var luAssemble = luList.Select(t => t.Replace(" ", ""));
importPubSaDetail.LU += luAssemble.Aggregate(" ", (current, index) => current + index); hbpoSaDetail.LU += luAssemble.Aggregate(" ", (current, index) => current + index);
} }
importPubSaDetail.BillNum = hbpoSaBillNum; hbpoSaDetail.BillNum = hbpoSaBillNum;
//importPubSaDetail.Site = "XX工厂"; hbpoSaDetail.KeyCode = hbpoSaDetail.PN + hbpoSaDetail.LU;
importPubSaDetail.KeyCode = importPubSaDetail.PN + importPubSaDetail.LU;
//根据物料号、结算日期获取价格 //根据物料号、结算日期获取价格
var priceListEntity = priceListEntitys.Find(t => t.LU == importPubSaDetail.LU && importPubSaDetail.SettleDate > t.BeginTime && importPubSaDetail.SettleDate < t.EndTime); var priceListEntity = priceListEntitys.Find(t => t.LU == hbpoSaDetail.LU && hbpoSaDetail.SettleDate > t.BeginTime && hbpoSaDetail.SettleDate < t.EndTime);
importPubSaDetail.Price = priceListEntity?.Price ?? 0; hbpoSaDetail.Price = priceListEntity?.Price ?? default;
importPubSaDetail.BusinessType = businessType; hbpoSaDetail.BusinessType = _businessType;
}); });
//导入的零件号集合 //导入的零件号集合
var importPubSaLUs = importPubSaDetails.Select(t => t.LU).Distinct(); var importPubSaLUs = hbpoSaDetails.Select(t => t.LU).Distinct();
var materialRelationshipEntitys = await _materialRelationshipRepository.GetListAsync(t => importPubSaLUs.Contains(t.SettleMaterialCode)); var materialRelationshipEntitys = await _materialRelationshipRepository.GetListAsync(t => importPubSaLUs.Contains(t.SettleMaterialCode));
var materialRelationshipEntitySettleMaterialCodes = materialRelationshipEntitys.Select(t => t.SettleMaterialCode).Distinct(); var materialRelationshipEntitySettleMaterialCodes = materialRelationshipEntitys.Select(t => t.SettleMaterialCode).Distinct();
@ -206,19 +354,15 @@ public class HBPO_SA_SERVICE : SettleAccountApplicationBase<HBPO_SA>
noExistSettleMaterialCodes.ForEach(t => noExistSettleMaterialCodes.ForEach(t =>
{ {
var materialRelationship = new MaterialRelationship(GuidGenerator.Create(), t.Replace(" ", "-"), "", t, businessType.ToString()); var materialRelationship = new MaterialRelationship(GuidGenerator.Create(), t.Replace(" ", "-"), "", t, _businessType.ToString());
materialRelationships.Add(materialRelationship); materialRelationships.Add(materialRelationship);
}); });
#endregion #endregion
#region 入库数据赋值 #region 入库数据赋值
//结算明细 //根据价格区分结算、不可结算
hbpoSaDetails = importPubSaDetails; var hbpoSaDetailsCanSes = hbpoSaDetails.FindAll(t => t.Price != default);
var hbpoSaDetailsNotCanSes = hbpoSaDetails.FindAll(t => t.Price == default);
//不可结算 结算分组号码(根据价格区分结算、不可结算)
var hbpoNotSaGroupNums = hbpoSaDetails.FindAll(t => t.Price == default(decimal)).Select(t => t.GroupNum).Distinct();
var hbpoSaDetailsCanSes = hbpoSaDetails.FindAll(t => hbpoNotSaGroupNums.Contains(t.GroupNum) == false);
var hbpoSaDetailsNotCanSes = hbpoSaDetails.FindAll(t => hbpoNotSaGroupNums.Contains(t.GroupNum) == true);
//可结算明细 //可结算明细
hbpoCanSaDetails = ObjectMapper.Map<List<HBPO_SA_DETAIL>, List<HBPO_CAN_SA_DETAIL>>(hbpoSaDetailsCanSes); hbpoCanSaDetails = ObjectMapper.Map<List<HBPO_SA_DETAIL>, List<HBPO_CAN_SA_DETAIL>>(hbpoSaDetailsCanSes);
@ -235,7 +379,7 @@ public class HBPO_SA_SERVICE : SettleAccountApplicationBase<HBPO_SA>
hbpoCanSaDetails.ForEach(hbpoCanSaDetail => hbpoCanSaDetails.ForEach(hbpoCanSaDetail =>
{ {
hbpoCanSaDetail.BillNum = hbpoCanSaDetail.InvGroupNum = hbpoCanSaBillNum; hbpoCanSaDetail.BillNum = hbpoCanSaDetail.InvGroupNum = hbpoCanSaBillNum;
hbpoCanSaDetail.BusinessType = businessType; hbpoCanSaDetail.BusinessType = _businessType;
}); });
await _hbpoCanSaRepository.InsertAsync(hbpoCanSa); await _hbpoCanSaRepository.InsertAsync(hbpoCanSa);
@ -245,7 +389,7 @@ public class HBPO_SA_SERVICE : SettleAccountApplicationBase<HBPO_SA>
{ {
hbpoNotSaDetails.ForEach(hbpoNotSaDetail => hbpoNotSaDetails.ForEach(hbpoNotSaDetail =>
{ {
hbpoNotSaDetail.BusinessType = businessType; hbpoNotSaDetail.BusinessType = _businessType;
}); });
await _hbpoNotSaDetailRepository.InsertManyAsync(hbpoNotSaDetails); await _hbpoNotSaDetailRepository.InsertManyAsync(hbpoNotSaDetails);
@ -255,79 +399,44 @@ public class HBPO_SA_SERVICE : SettleAccountApplicationBase<HBPO_SA>
await _materialRelationshipRepository.InsertManyAsync(materialRelationships); await _materialRelationshipRepository.InsertManyAsync(materialRelationships);
} }
#endregion #endregion
return ApplicationConsts.SuccessStr;
} }
#endregion
#region CURD
/// <summary> /// <summary>
/// 获取列表 /// 获取结算关联项
/// </summary> /// </summary>
[HttpPost] private async Task<(List<HBPO_SA> hbpoSas, List<HBPO_SA_DETAIL> hbpoSaDetails, List<HBPO_CAN_SA> hbpoCanSas, List<HBPO_CAN_SA_DETAIL> hbpoCanSaDetails, List<HBPO_NOT_SA_DETAIL> hbpoNotSaDetails)> GetHBPOSaDelItemsAsync(Guid id)
public async Task<PagedResultDto<HBPO_SA_DTO>> GetListAsync(RequestDto input)
{
var entities = await _hbpoSaRepository.GetListByFilterAsync(input.Filters, input.Sorting, input.MaxResultCount, input.SkipCount, true);
var totalCount = await _hbpoSaRepository.GetCountByFilterAsync(input.Filters);
var dtos = ObjectMapper.Map<List<HBPO_SA>, List<HBPO_SA_DTO>>(entities);
return new PagedResultDto<HBPO_SA_DTO>(totalCount, dtos);
}
/// <summary>
/// 删除
/// </summary>
[HttpPost]
public async Task DeleteAsync(Guid id)
{ {
//结算主表 //结算主表
HBPO_SA hbpoSaDelEntity; List<HBPO_SA> hbpoSas = new List<HBPO_SA>();
//结算明细 //结算明细
List<HBPO_SA_DETAIL> hbpoSaDetailDelEntitys; List<HBPO_SA_DETAIL> hbpoSaDetails = new List<HBPO_SA_DETAIL>();
//可结算主表 //可结算主表
List<HBPO_CAN_SA> hbpoCanSaDelEntitys; List<HBPO_CAN_SA> hbpoCanSas = new List<HBPO_CAN_SA>();
//可结算明细 //可结算明细
List<HBPO_CAN_SA_DETAIL> hbpoCanSaDetailDelEntitys; List<HBPO_CAN_SA_DETAIL> hbpoCanSaDetails = new List<HBPO_CAN_SA_DETAIL>();
//不可结算 //不可结算
List<HBPO_NOT_SA_DETAIL> hbpoNotSaDetailDelEntitys; List<HBPO_NOT_SA_DETAIL> hbpoNotSaDetails = new List<HBPO_NOT_SA_DETAIL>();
hbpoSaDelEntity = await _hbpoSaRepository.FindAsync(id); var hbpoSaEntity = await _hbpoSaRepository.FirstOrDefaultAsync(t => t.Id.Equals(id));
if (hbpoSaDelEntity == null) if (hbpoSaEntity != null)
{ {
throw new UserFriendlyException($"未获取到结算单!", "400");
}
//结算单据 //结算单据
string hbpoSaBillNum = hbpoSaDelEntity.BillNum; string hbpoSaBillNum = hbpoSaEntity.BillNum;
hbpoCanSaDelEntitys = await _hbpoCanSaRepository.GetListAsync(t => t.SettleBillNum == hbpoSaBillNum); hbpoCanSas = await _hbpoCanSaRepository.GetListAsync(t => t.SettleBillNum == hbpoSaBillNum);
//验证可结算主表状态 //验证可结算主表状态
if (hbpoCanSaDelEntitys.Any(t => t.State != SettleBillState.)) if (hbpoCanSas.Any() && hbpoCanSas.Any(t => t.State != SettleBillState.))
{ {
throw new UserFriendlyException($"该单据可结算单状态无法删除!", "400"); throw new UserFriendlyException($"{hbpoSaBillNum} 该单据可结算单状态无法删除!", "400");
} }
hbpoSaDetailDelEntitys = await _hbpoSaDetailRepository.GetListAsync(t => t.BillNum == hbpoSaBillNum); hbpoSas.Add(hbpoSaEntity);
hbpoCanSaDetailDelEntitys = await _hbpoCanSaDetailRepository.GetListAsync(t => t.SettleBillNum == hbpoSaBillNum); hbpoSaDetails = await _hbpoSaDetailRepository.GetListAsync(t => t.BillNum == hbpoSaBillNum);
hbpoNotSaDetailDelEntitys = await _hbpoNotSaDetailRepository.GetListAsync(t => t.SettleBillNum == hbpoSaBillNum); hbpoCanSaDetails = await _hbpoCanSaDetailRepository.GetListAsync(t => t.SettleBillNum == hbpoSaBillNum);
hbpoNotSaDetails = await _hbpoNotSaDetailRepository.GetListAsync(t => t.SettleBillNum == hbpoSaBillNum);
//删除
await _hbpoSaRepository.DeleteAsync(hbpoSaDelEntity);
if (hbpoSaDetailDelEntitys.Any())
{
await _hbpoSaDetailRepository.DeleteManyAsync(hbpoSaDetailDelEntitys);
}
if (hbpoCanSaDelEntitys.Any())
{
await _hbpoCanSaRepository.DeleteManyAsync(hbpoCanSaDelEntitys);
}
if (hbpoCanSaDetailDelEntitys.Any())
{
await _hbpoCanSaDetailRepository.DeleteManyAsync(hbpoCanSaDetailDelEntitys);
}
if (hbpoNotSaDetailDelEntitys.Any())
{
await _hbpoNotSaDetailRepository.DeleteManyAsync(hbpoNotSaDetailDelEntitys);
} }
return (hbpoSas, hbpoSaDetails, hbpoCanSas, hbpoCanSaDetails, hbpoNotSaDetails);
} }
#endregion #endregion
} }

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

@ -110,7 +110,6 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase<PUB_SA>
public async Task<string> ImportByBusinessTypeAsync([FromForm] PUB_SAImportRequestDto pubSaImportRequestDto) public async Task<string> ImportByBusinessTypeAsync([FromForm] PUB_SAImportRequestDto pubSaImportRequestDto)
{ {
string result = string.Empty; string result = string.Empty;
//return await ImportAsync(pubSaImportRequestDto.Files, pubSaImportRequestDto.BusinessType);
switch (pubSaImportRequestDto.BusinessType) switch (pubSaImportRequestDto.BusinessType)
{ {
case EnumBusinessType.None: case EnumBusinessType.None:
@ -128,6 +127,7 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase<PUB_SA>
case EnumBusinessType.MaiDanJianBBAC: case EnumBusinessType.MaiDanJianBBAC:
break; break;
case EnumBusinessType.MaiDanJianHBPO: case EnumBusinessType.MaiDanJianHBPO:
result = await ImportMaiDanJianHBPOAsync(pubSaImportRequestDto.Files);
break; break;
case EnumBusinessType.BeiJian: case EnumBusinessType.BeiJian:
result = await ImportBeiJianAsync(pubSaImportRequestDto.Files); result = await ImportBeiJianAsync(pubSaImportRequestDto.Files);
@ -476,6 +476,34 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase<PUB_SA>
return await SaDataHandleAsync(importPubSaDetails, EnumBusinessType.ZhiGongJianHBPO); return await SaDataHandleAsync(importPubSaDetails, EnumBusinessType.ZhiGongJianHBPO);
} }
/// <summary>
/// 买单件HBPO导入
/// </summary>
private async Task<string> ImportMaiDanJianHBPOAsync([FromForm] IFormFileCollection files)
{
#region 导入数据转换
ExportImporter _exportImporter = new ExportImporter();
var importResults = await _exportImporter.UploadExcelImport<MaiDanJianHBPOImportDto>(files, _excelImportService);
importResults.ForEach(importResult =>
{
importResult.SettleDate = DateTime.Now;
});
var importPubSaDetails = ObjectMapper.Map<List<MaiDanJianHBPOImportDto>, List<PUB_SA_DETAIL>>(importResults);
#endregion
#region 数据校验
var checkList = await CheckAsync(importPubSaDetails);
if (checkList.Count > 0)
{
return await ExportErrorReportAsync(checkList);
}
#endregion
return await SaDataHandleAsync(importPubSaDetails, EnumBusinessType.BeiJian);
}
/// <summary> /// <summary>
/// 备件导入 /// 备件导入
/// </summary> /// </summary>
@ -505,7 +533,7 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase<PUB_SA>
} }
/// <summary> /// <summary>
/// 件导入 /// 印度件导入
/// </summary> /// </summary>
private async Task<string> ImportYinDuJianAsync([FromForm] IFormFileCollection files) private async Task<string> ImportYinDuJianAsync([FromForm] IFormFileCollection files)
{ {

1
code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs

@ -1023,6 +1023,7 @@ namespace Win.Sfs.SettleAccount
CreateMap<PUB_SA_DETAIL_IMPORT_DTO, PUB_SA_DETAIL>(); CreateMap<PUB_SA_DETAIL_IMPORT_DTO, PUB_SA_DETAIL>();
CreateMap<ZhiGongJianBBACImportDto, PUB_SA_DETAIL>(); CreateMap<ZhiGongJianBBACImportDto, PUB_SA_DETAIL>();
CreateMap<ZhiGongJianHBPOImportDto, PUB_SA_DETAIL>(); CreateMap<ZhiGongJianHBPOImportDto, PUB_SA_DETAIL>();
CreateMap<MaiDanJianHBPOImportDto, PUB_SA_DETAIL>();
CreateMap<BeiJianImportDto, PUB_SA_DETAIL>(); CreateMap<BeiJianImportDto, PUB_SA_DETAIL>();
CreateMap<YinDuJianImportDto, PUB_SA_DETAIL>(); CreateMap<YinDuJianImportDto, PUB_SA_DETAIL>();
} }

2
code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/BBAC_SA.cs

@ -7,7 +7,7 @@ namespace SettleAccount.Domain.BQ;
[Display(Name = "BBAC结算导入")] [Display(Name = "BBAC结算导入")]
public class BBAC_SA:FullAuditedAggregateRoot<Guid> public class BBAC_SA : AuditedAggregateRoot<Guid>
{ {
[Display(Name = "期间")] [Display(Name = "期间")]
public int Version { get; set; } public int Version { get; set; }

5120
code/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Migrations/20230803033051_20230803-1.Designer.cs

File diff suppressed because it is too large

45
code/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Migrations/20230803033051_20230803-1.cs

@ -0,0 +1,45 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Win.Sfs.SettleAccount.Migrations
{
public partial class _202308031 : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "DeleterId",
table: "Set_BBAC_SA");
migrationBuilder.DropColumn(
name: "DeletionTime",
table: "Set_BBAC_SA");
migrationBuilder.DropColumn(
name: "IsDeleted",
table: "Set_BBAC_SA");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<Guid>(
name: "DeleterId",
table: "Set_BBAC_SA",
type: "uniqueidentifier",
nullable: true);
migrationBuilder.AddColumn<DateTime>(
name: "DeletionTime",
table: "Set_BBAC_SA",
type: "datetime2",
nullable: true);
migrationBuilder.AddColumn<bool>(
name: "IsDeleted",
table: "Set_BBAC_SA",
type: "bit",
nullable: false,
defaultValue: false);
}
}
}

14
code/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Migrations/SettleAccountDbContextModelSnapshot.cs

@ -400,24 +400,10 @@ namespace Win.Sfs.SettleAccount.Migrations
.HasMaxLength(50) .HasMaxLength(50)
.HasColumnType("nvarchar(50)"); .HasColumnType("nvarchar(50)");
b.Property<Guid?>("DeleterId")
.HasColumnType("uniqueidentifier")
.HasColumnName("DeleterId");
b.Property<DateTime?>("DeletionTime")
.HasColumnType("datetime2")
.HasColumnName("DeletionTime");
b.Property<string>("ExtraProperties") b.Property<string>("ExtraProperties")
.HasColumnType("nvarchar(max)") .HasColumnType("nvarchar(max)")
.HasColumnName("ExtraProperties"); .HasColumnName("ExtraProperties");
b.Property<bool>("IsDeleted")
.ValueGeneratedOnAdd()
.HasColumnType("bit")
.HasDefaultValue(false)
.HasColumnName("IsDeleted");
b.Property<DateTime?>("LastModificationTime") b.Property<DateTime?>("LastModificationTime")
.HasColumnType("datetime2") .HasColumnType("datetime2")
.HasColumnName("LastModificationTime"); .HasColumnName("LastModificationTime");

Loading…
Cancel
Save