|
@ -20,318 +20,319 @@ 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 Win.Sfs.SettleAccount.MaterialRelationships; |
|
|
using Win.Sfs.SettleAccount.MaterialRelationships; |
|
|
|
|
|
using Win.Sfs.Shared.Filter; |
|
|
using Win.Sfs.Shared.RepositoryBase; |
|
|
using Win.Sfs.Shared.RepositoryBase; |
|
|
|
|
|
|
|
|
namespace Win.Sfs.SettleAccount.Entities.BQ |
|
|
namespace Win.Sfs.SettleAccount.Entities.BQ; |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// PUB结算
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[AllowAnonymous] |
|
|
|
|
|
[Route("api/settleaccount/[controller]/[action]")]
|
|
|
|
|
|
public class PUB_SA_SERVICE : SettleAccountApplicationBase<PUB_SA> |
|
|
{ |
|
|
{ |
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// PUB结算
|
|
|
/// PUB结算仓储
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private readonly INormalEfCoreRepository<PUB_SA, Guid> _repository; |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// PUB结算明细仓储
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private readonly INormalEfCoreRepository<PUB_SA_DETAIL, Guid> _pubSaDetailRepository; |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// PUB可结算仓储
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private readonly INormalEfCoreRepository<PUB_CAN_SA, Guid> _pubCanSaRepository; |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// PUB可结算明细仓储
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private readonly INormalEfCoreRepository<PUB_CAN_SA_DETAIL, Guid> _pubCanSaDetailRepository; |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// PUB不可结算明细仓储
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private readonly INormalEfCoreRepository<PUB_NOT_SA_DETAIL, Guid> _pubNotSaDetailRepository; |
|
|
|
|
|
|
|
|
|
|
|
/// <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>
|
|
|
|
|
|
public PUB_SA_SERVICE(INormalEfCoreRepository<PUB_SA, Guid> repository, |
|
|
|
|
|
INormalEfCoreRepository<PUB_SA_DETAIL, Guid> pubSaDetailRepository, |
|
|
|
|
|
INormalEfCoreRepository<PUB_CAN_SA, Guid> pubCanSaRepository, |
|
|
|
|
|
INormalEfCoreRepository<PUB_CAN_SA_DETAIL, Guid> pubCanSaDetailRepository, |
|
|
|
|
|
INormalEfCoreRepository<PUB_NOT_SA_DETAIL, Guid> pubNotSaDetailRepository, |
|
|
|
|
|
INormalEfCoreRepository<PriceList, Guid> priceListRepository, |
|
|
|
|
|
INormalEfCoreRepository<MaterialRelationship, Guid> materialRelationshipRepository, |
|
|
|
|
|
INormalEfCoreRepository<TB_RePartsRelationship, Guid> tbRePartsRelationshipRepository, |
|
|
|
|
|
IDistributedCache<PUB_SA> cache, |
|
|
|
|
|
IExcelImportAppService excelImportService, |
|
|
|
|
|
ISnowflakeIdGenerator snowflakeIdGenerator, |
|
|
|
|
|
ICommonManager commonManager |
|
|
|
|
|
) : base(cache, excelImportService, snowflakeIdGenerator, commonManager) |
|
|
|
|
|
{ |
|
|
|
|
|
_repository = repository; |
|
|
|
|
|
_pubSaDetailRepository = pubSaDetailRepository; |
|
|
|
|
|
_pubCanSaRepository = pubCanSaRepository; |
|
|
|
|
|
_pubCanSaDetailRepository = pubCanSaDetailRepository; |
|
|
|
|
|
_pubNotSaDetailRepository = pubNotSaDetailRepository; |
|
|
|
|
|
_priceListRepository = priceListRepository; |
|
|
|
|
|
_materialRelationshipRepository = materialRelationshipRepository; |
|
|
|
|
|
_tbRePartsRelationshipRepository = tbRePartsRelationshipRepository; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#region 导入、导出
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 导入
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[HttpPost] |
|
|
|
|
|
public async Task<string> ImportByBusinessTypeAsync([FromForm] IFormFileCollection files, EnumBusinessType businessType) |
|
|
|
|
|
{ |
|
|
|
|
|
return await ImportAsync(files, businessType); |
|
|
|
|
|
} |
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region CURD
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取列表
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
[AllowAnonymous] |
|
|
[HttpPost] |
|
|
[Route("api/settleaccount/[controller]/[action]")]
|
|
|
public async Task<PagedResultDto<PUB_SA_DTO>> GetListAsync(PUB_SARequestDto input) |
|
|
public class PUB_SA_SERVICE : SettleAccountApplicationBase<PUB_SA> |
|
|
|
|
|
{ |
|
|
{ |
|
|
/// <summary>
|
|
|
input.Filters.Add(new FilterCondition("BusinessType", input.BusinessType.ToString(), EnumFilterAction.Equal, EnumFilterLogic.And)); |
|
|
/// PUB结算仓储
|
|
|
var entities = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, input.MaxResultCount, input.SkipCount, true); |
|
|
/// </summary>
|
|
|
var totalCount = await _repository.GetCountByFilterAsync(input.Filters); |
|
|
private readonly INormalEfCoreRepository<PUB_SA, Guid> _repository; |
|
|
var dtos = ObjectMapper.Map<List<PUB_SA>, List<PUB_SA_DTO>>(entities); |
|
|
|
|
|
return new PagedResultDto<PUB_SA_DTO>(totalCount, dtos); |
|
|
/// <summary>
|
|
|
} |
|
|
/// PUB结算明细仓储
|
|
|
|
|
|
/// </summary>
|
|
|
/// <summary>
|
|
|
private readonly INormalEfCoreRepository<PUB_SA_DETAIL, Guid> _pubSaDetailRepository; |
|
|
/// 删除
|
|
|
|
|
|
/// </summary>
|
|
|
/// <summary>
|
|
|
[HttpPost] |
|
|
/// PUB可结算仓储
|
|
|
public async Task DeleteAsync(Guid id) |
|
|
/// </summary>
|
|
|
{ |
|
|
private readonly INormalEfCoreRepository<PUB_CAN_SA, Guid> _pubCanSaRepository; |
|
|
//结算主表
|
|
|
|
|
|
PUB_SA pubSaDelEntity; |
|
|
/// <summary>
|
|
|
//结算明细
|
|
|
/// PUB可结算明细仓储
|
|
|
List<PUB_SA_DETAIL> pubSaDetailDelEntitys; |
|
|
/// </summary>
|
|
|
//可结算主表
|
|
|
private readonly INormalEfCoreRepository<PUB_CAN_SA_DETAIL, Guid> _pubCanSaDetailRepository; |
|
|
List<PUB_CAN_SA> pubCanSaDelEntitys; |
|
|
|
|
|
//可结算明细
|
|
|
/// <summary>
|
|
|
List<PUB_CAN_SA_DETAIL> pubCanSaDetailDelEntitys; |
|
|
/// PUB不可结算明细仓储
|
|
|
//不可结算
|
|
|
/// </summary>
|
|
|
List<PUB_NOT_SA_DETAIL> pubNotSaDetailDelEntitys; |
|
|
private readonly INormalEfCoreRepository<PUB_NOT_SA_DETAIL, Guid> _pubNotSaDetailRepository; |
|
|
|
|
|
|
|
|
pubSaDelEntity = await _repository.FindAsync(id); |
|
|
/// <summary>
|
|
|
if (pubSaDelEntity == null) return; |
|
|
/// 销售价格仓储
|
|
|
//结算单据
|
|
|
/// </summary>
|
|
|
string pubSaBillNum = pubSaDelEntity.BillNum; |
|
|
private readonly INormalEfCoreRepository<PriceList, Guid> _priceListRepository; |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
pubCanSaDelEntitys = await _pubCanSaRepository.GetListAsync(t => t.SettleBillNum == pubSaBillNum); |
|
|
/// 客户零件关系仓储
|
|
|
//验证可结算主表状态
|
|
|
/// </summary>
|
|
|
if (pubCanSaDelEntitys.Any(t => t.State != SettleBillState.未结状态)) |
|
|
private readonly INormalEfCoreRepository<MaterialRelationship, Guid> _materialRelationshipRepository; |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 替换件关系仓储
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private readonly INormalEfCoreRepository<TB_RePartsRelationship, Guid> _tbRePartsRelationshipRepository; |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 构造
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public PUB_SA_SERVICE(INormalEfCoreRepository<PUB_SA, Guid> repository, |
|
|
|
|
|
INormalEfCoreRepository<PUB_SA_DETAIL, Guid> pubSaDetailRepository, |
|
|
|
|
|
INormalEfCoreRepository<PUB_CAN_SA, Guid> pubCanSaRepository, |
|
|
|
|
|
INormalEfCoreRepository<PUB_CAN_SA_DETAIL, Guid> pubCanSaDetailRepository, |
|
|
|
|
|
INormalEfCoreRepository<PUB_NOT_SA_DETAIL, Guid> pubNotSaDetailRepository, |
|
|
|
|
|
INormalEfCoreRepository<PriceList, Guid> priceListRepository, |
|
|
|
|
|
INormalEfCoreRepository<MaterialRelationship, Guid> materialRelationshipRepository, |
|
|
|
|
|
INormalEfCoreRepository<TB_RePartsRelationship, Guid> tbRePartsRelationshipRepository, |
|
|
|
|
|
IDistributedCache<PUB_SA> cache, |
|
|
|
|
|
IExcelImportAppService excelImportService, |
|
|
|
|
|
ISnowflakeIdGenerator snowflakeIdGenerator, |
|
|
|
|
|
ICommonManager commonManager |
|
|
|
|
|
) : base(cache, excelImportService, snowflakeIdGenerator, commonManager) |
|
|
|
|
|
{ |
|
|
{ |
|
|
_repository = repository; |
|
|
throw new UserFriendlyException($"该单据可结算单状态无法删除!", "400"); |
|
|
_pubSaDetailRepository = pubSaDetailRepository; |
|
|
|
|
|
_pubCanSaRepository = pubCanSaRepository; |
|
|
|
|
|
_pubCanSaDetailRepository = pubCanSaDetailRepository; |
|
|
|
|
|
_pubNotSaDetailRepository = pubNotSaDetailRepository; |
|
|
|
|
|
_priceListRepository = priceListRepository; |
|
|
|
|
|
_materialRelationshipRepository = materialRelationshipRepository; |
|
|
|
|
|
_tbRePartsRelationshipRepository = tbRePartsRelationshipRepository; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#region 导入、导出
|
|
|
pubSaDetailDelEntitys = await _pubSaDetailRepository.GetListAsync(t => t.BillNum == pubSaBillNum); |
|
|
/// <summary>
|
|
|
pubCanSaDetailDelEntitys = await _pubCanSaDetailRepository.GetListAsync(t => t.SettleBillNum == pubSaBillNum); |
|
|
/// 导入
|
|
|
pubNotSaDetailDelEntitys = await _pubNotSaDetailRepository.GetListAsync(t => t.SettleBillNum == pubSaBillNum); |
|
|
/// </summary>
|
|
|
|
|
|
[HttpPost] |
|
|
//删除
|
|
|
public async Task<string> ImportByBusinessTypeAsync([FromForm] IFormFileCollection files, EnumBusinessType businessType) |
|
|
await _repository.DeleteAsync(pubSaDelEntity); |
|
|
|
|
|
if (pubSaDetailDelEntitys.Any()) |
|
|
{ |
|
|
{ |
|
|
return await ImportAsync(files, businessType); |
|
|
await _pubSaDetailRepository.DeleteManyAsync(pubSaDetailDelEntitys); |
|
|
} |
|
|
} |
|
|
#endregion
|
|
|
if (pubCanSaDelEntitys.Any()) |
|
|
|
|
|
|
|
|
#region CURD
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取列表
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[HttpPost] |
|
|
|
|
|
public async Task<PagedResultDto<PUB_SA_DTO>> GetListAsync(RequestDto input) |
|
|
|
|
|
{ |
|
|
{ |
|
|
var entities = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, input.MaxResultCount, input.SkipCount, true); |
|
|
await _pubCanSaRepository.DeleteManyAsync(pubCanSaDelEntitys); |
|
|
var totalCount = await _repository.GetCountByFilterAsync(input.Filters); |
|
|
|
|
|
var dtos = ObjectMapper.Map<List<PUB_SA>, List<PUB_SA_DTO>>(entities); |
|
|
|
|
|
return new PagedResultDto<PUB_SA_DTO>(totalCount, dtos); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
if (pubCanSaDetailDelEntitys.Any()) |
|
|
/// <summary>
|
|
|
|
|
|
/// 删除
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[HttpPost] |
|
|
|
|
|
public async Task DeleteAsync(Guid id) |
|
|
|
|
|
{ |
|
|
{ |
|
|
//结算主表
|
|
|
await _pubCanSaDetailRepository.DeleteManyAsync(pubCanSaDetailDelEntitys); |
|
|
PUB_SA pubSaDelEntity; |
|
|
} |
|
|
//结算明细
|
|
|
if (pubNotSaDetailDelEntitys.Any()) |
|
|
List<PUB_SA_DETAIL> pubSaDetailDelEntitys; |
|
|
{ |
|
|
//可结算主表
|
|
|
await _pubNotSaDetailRepository.DeleteManyAsync(pubNotSaDetailDelEntitys); |
|
|
List<PUB_CAN_SA> pubCanSaDelEntitys; |
|
|
} |
|
|
//可结算明细
|
|
|
|
|
|
List<PUB_CAN_SA_DETAIL> pubCanSaDetailDelEntitys; |
|
|
|
|
|
//不可结算
|
|
|
|
|
|
List<PUB_NOT_SA_DETAIL> pubNotSaDetailDelEntitys; |
|
|
|
|
|
|
|
|
|
|
|
pubSaDelEntity = await _repository.FindAsync(id); |
|
|
|
|
|
if (pubSaDelEntity == null) return; |
|
|
|
|
|
//结算单据
|
|
|
|
|
|
string pubSaBillNum = pubSaDelEntity.BillNum; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pubCanSaDelEntitys = await _pubCanSaRepository.GetListAsync(t => t.SettleBillNum == pubSaBillNum); |
|
|
|
|
|
//验证可结算主表状态
|
|
|
|
|
|
if (pubCanSaDelEntitys.Any(t => t.State != SettleBillState.未结状态)) |
|
|
|
|
|
{ |
|
|
|
|
|
throw new UserFriendlyException($"该单据可结算单状态无法删除!", "400"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pubSaDetailDelEntitys = await _pubSaDetailRepository.GetListAsync(t => t.BillNum == pubSaBillNum); |
|
|
} |
|
|
pubCanSaDetailDelEntitys = await _pubCanSaDetailRepository.GetListAsync(t => t.SettleBillNum == pubSaBillNum); |
|
|
#endregion
|
|
|
pubNotSaDetailDelEntitys = await _pubNotSaDetailRepository.GetListAsync(t => t.SettleBillNum == pubSaBillNum); |
|
|
|
|
|
|
|
|
|
|
|
//删除
|
|
|
#region 私有方法
|
|
|
await _repository.DeleteAsync(pubSaDelEntity); |
|
|
/// <summary>
|
|
|
if (pubSaDetailDelEntitys.Any()) |
|
|
/// 导入
|
|
|
{ |
|
|
/// </summary>
|
|
|
await _pubSaDetailRepository.DeleteManyAsync(pubSaDetailDelEntitys); |
|
|
private async Task<string> ImportAsync([FromForm] IFormFileCollection files, EnumBusinessType businessType) |
|
|
} |
|
|
{ |
|
|
if (pubCanSaDelEntitys.Any()) |
|
|
//数据校验
|
|
|
{ |
|
|
var checkList = new List<ErrorExportDto>(); |
|
|
await _pubCanSaRepository.DeleteManyAsync(pubCanSaDelEntitys); |
|
|
//结算单号
|
|
|
} |
|
|
var pubSaBillNum = OrderNumberGenerator.GenerateOrderNumber("SA"); |
|
|
if (pubCanSaDetailDelEntitys.Any()) |
|
|
//结算主表
|
|
|
{ |
|
|
var pubSa = new PUB_SA() |
|
|
await _pubCanSaDetailRepository.DeleteManyAsync(pubCanSaDetailDelEntitys); |
|
|
{ |
|
|
} |
|
|
BillNum = pubSaBillNum, |
|
|
if (pubNotSaDetailDelEntitys.Any()) |
|
|
State = "1", |
|
|
|
|
|
BusinessType = businessType |
|
|
|
|
|
}; |
|
|
|
|
|
//结算明细
|
|
|
|
|
|
var pubSaDetails = new List<PUB_SA_DETAIL>(); |
|
|
|
|
|
//可结算单号
|
|
|
|
|
|
var pubCanSaBillNum = OrderNumberGenerator.GenerateOrderNumber("C"); |
|
|
|
|
|
//可结算主表
|
|
|
|
|
|
var pubCanSa = new PUB_CAN_SA() |
|
|
|
|
|
{ |
|
|
|
|
|
BillNum = pubCanSaBillNum, |
|
|
|
|
|
SettleBillNum = pubSaBillNum, |
|
|
|
|
|
State = SettleBillState.未结状态, |
|
|
|
|
|
BusinessType = businessType |
|
|
|
|
|
}; |
|
|
|
|
|
//可结算明细
|
|
|
|
|
|
var pubCanSaDetails = new List<PUB_CAN_SA_DETAIL>(); |
|
|
|
|
|
//不可结算明细
|
|
|
|
|
|
var pubNotSaDetails = new List<PUB_NOT_SA_DETAIL>(); |
|
|
|
|
|
//客户零件关系
|
|
|
|
|
|
var materialRelationships = new List<MaterialRelationship>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 导入数据转换、数据校验
|
|
|
|
|
|
ExportImporter _exportImporter = new ExportImporter(); |
|
|
|
|
|
var result = await _exportImporter.UploadExcelImport<PUB_SA_DETAIL_IMPORT_DTO>(files, _excelImportService); |
|
|
|
|
|
var importPubSaDetails = ObjectMapper.Map<List<PUB_SA_DETAIL_IMPORT_DTO>, List<PUB_SA_DETAIL>>(result); |
|
|
|
|
|
|
|
|
|
|
|
//结算分组号
|
|
|
|
|
|
var pubSaGroupNums = importPubSaDetails.Select(t => t.GroupNum).Distinct(); |
|
|
|
|
|
|
|
|
|
|
|
//已存在的结算分组号
|
|
|
|
|
|
var havPubSaGroupNums = (await _pubSaDetailRepository.GetListAsync(t => pubSaGroupNums.Contains(t.GroupNum))).Select(t => t.GroupNum).Distinct(); |
|
|
|
|
|
if (havPubSaGroupNums.Any() == true) |
|
|
|
|
|
{ |
|
|
|
|
|
foreach (var item in havPubSaGroupNums) |
|
|
{ |
|
|
{ |
|
|
await _pubNotSaDetailRepository.DeleteManyAsync(pubNotSaDetailDelEntitys); |
|
|
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
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
#region 私有方法
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 导入
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private async Task<string> ImportAsync([FromForm] IFormFileCollection files, EnumBusinessType businessType) |
|
|
|
|
|
{ |
|
|
|
|
|
//数据校验
|
|
|
|
|
|
var checkList = new List<ErrorExportDto>(); |
|
|
|
|
|
//结算单号
|
|
|
|
|
|
var pubSaBillNum = OrderNumberGenerator.GenerateOrderNumber("SA"); |
|
|
|
|
|
//结算主表
|
|
|
|
|
|
var pubSa = new PUB_SA() |
|
|
|
|
|
{ |
|
|
|
|
|
BillNum = pubSaBillNum, |
|
|
|
|
|
State = "1", |
|
|
|
|
|
BusinessType = businessType |
|
|
|
|
|
}; |
|
|
|
|
|
//结算明细
|
|
|
|
|
|
var pubSaDetails = new List<PUB_SA_DETAIL>(); |
|
|
|
|
|
//可结算单号
|
|
|
|
|
|
var pubCanSaBillNum = OrderNumberGenerator.GenerateOrderNumber("C"); |
|
|
|
|
|
//可结算主表
|
|
|
|
|
|
var pubCanSa = new PUB_CAN_SA() |
|
|
|
|
|
{ |
|
|
|
|
|
BillNum = pubCanSaBillNum, |
|
|
|
|
|
SettleBillNum = pubSaBillNum, |
|
|
|
|
|
State = SettleBillState.未结状态, |
|
|
|
|
|
BusinessType = businessType |
|
|
|
|
|
}; |
|
|
|
|
|
//可结算明细
|
|
|
|
|
|
var pubCanSaDetails = new List<PUB_CAN_SA_DETAIL>(); |
|
|
|
|
|
//不可结算明细
|
|
|
|
|
|
var pubNotSaDetails = new List<PUB_NOT_SA_DETAIL>(); |
|
|
|
|
|
//客户零件关系
|
|
|
|
|
|
var materialRelationships = new List<MaterialRelationship>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 导入数据转换、数据校验
|
|
|
|
|
|
ExportImporter _exportImporter = new ExportImporter(); |
|
|
|
|
|
var result = await _exportImporter.UploadExcelImport<PUB_SA_DETAIL_IMPORT_DTO>(files, _excelImportService); |
|
|
|
|
|
var importPubSaDetails = ObjectMapper.Map<List<PUB_SA_DETAIL_IMPORT_DTO>, List<PUB_SA_DETAIL>>(result); |
|
|
|
|
|
|
|
|
|
|
|
//结算分组号
|
|
|
|
|
|
var pubSaGroupNums = importPubSaDetails.Select(t => t.GroupNum).Distinct(); |
|
|
|
|
|
|
|
|
|
|
|
//已存在的结算分组号
|
|
|
|
|
|
var havPubSaGroupNums = (await _pubSaDetailRepository.GetListAsync(t => pubSaGroupNums.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) |
|
|
#region 处理结算数据
|
|
|
|
|
|
//销售价格
|
|
|
|
|
|
var priceListEntitys = await _priceListRepository.GetAllAsync(); |
|
|
|
|
|
|
|
|
|
|
|
importPubSaDetails.ForEach(importPubSaDetail => |
|
|
|
|
|
{ |
|
|
|
|
|
List<string> luList = importPubSaDetail.LU.Split(" ").ToList(); |
|
|
|
|
|
importPubSaDetail.LU = luList[0].Replace(" ", ""); |
|
|
|
|
|
if (luList.Count > 1) |
|
|
{ |
|
|
{ |
|
|
return await ExportErrorReportAsync(checkList); |
|
|
luList.RemoveAt(0); |
|
|
|
|
|
var luAssemble = luList.Select(t => t.Replace(" ", "")); |
|
|
|
|
|
importPubSaDetail.LU += luAssemble.Aggregate(" ", (current, index) => current + index); |
|
|
} |
|
|
} |
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 处理结算数据
|
|
|
importPubSaDetail.BillNum = pubSaBillNum; |
|
|
//销售价格
|
|
|
importPubSaDetail.Site = "XX工厂"; |
|
|
var priceListEntitys = await _priceListRepository.GetAllAsync(); |
|
|
importPubSaDetail.KeyCode = importPubSaDetail.PN + importPubSaDetail.LU; |
|
|
|
|
|
|
|
|
importPubSaDetails.ForEach(importPubSaDetail => |
|
|
//根据物料号、结算日期获取价格
|
|
|
{ |
|
|
var priceListEntity = priceListEntitys.Find(t => t.LU == importPubSaDetail.LU && importPubSaDetail.SettleDate > t.BeginTime && importPubSaDetail.SettleDate < t.EndTime); |
|
|
List<string> luList = importPubSaDetail.LU.Split(" ").ToList(); |
|
|
importPubSaDetail.Price = priceListEntity?.Price ?? 0; |
|
|
importPubSaDetail.LU = luList[0].Replace(" ", ""); |
|
|
}); |
|
|
if (luList.Count > 1) |
|
|
|
|
|
{ |
|
|
|
|
|
luList.RemoveAt(0); |
|
|
|
|
|
var luAssemble = luList.Select(t => t.Replace(" ", "")); |
|
|
|
|
|
importPubSaDetail.LU += luAssemble.Aggregate(" ", (current, index) => current + index); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
importPubSaDetail.BillNum = pubSaBillNum; |
|
|
|
|
|
importPubSaDetail.Site = "XX工厂"; |
|
|
|
|
|
importPubSaDetail.KeyCode = importPubSaDetail.PN + importPubSaDetail.LU; |
|
|
|
|
|
|
|
|
|
|
|
//根据物料号、结算日期获取价格
|
|
|
|
|
|
var priceListEntity = priceListEntitys.Find(t => t.LU == importPubSaDetail.LU && importPubSaDetail.SettleDate > t.BeginTime && importPubSaDetail.SettleDate < t.EndTime); |
|
|
|
|
|
importPubSaDetail.Price = priceListEntity?.Price ?? 0; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
//导入的零件号集合
|
|
|
//导入的零件号集合
|
|
|
var importPubSaLUs = importPubSaDetails.Select(t => t.LU).Distinct(); |
|
|
var importPubSaLUs = importPubSaDetails.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(); |
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
|
* (不存在的客户零件号)差集 |
|
|
* (不存在的客户零件号)差集 |
|
|
* 转换为厂内零件号 |
|
|
* 转换为厂内零件号 |
|
|
* 转换规则6个空格替换成“-” |
|
|
* 转换规则6个空格替换成“-” |
|
|
*/ |
|
|
*/ |
|
|
var noExistSettleMaterialCodes = importPubSaLUs.Except(materialRelationshipEntitySettleMaterialCodes); |
|
|
var noExistSettleMaterialCodes = importPubSaLUs.Except(materialRelationshipEntitySettleMaterialCodes); |
|
|
|
|
|
|
|
|
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 入库数据赋值
|
|
|
//结算明细
|
|
|
//结算明细
|
|
|
pubSaDetails = importPubSaDetails; |
|
|
pubSaDetails = importPubSaDetails; |
|
|
|
|
|
|
|
|
//不可结算 结算分组号码(根据价格区分结算、不可结算)
|
|
|
//不可结算 结算分组号码(根据价格区分结算、不可结算)
|
|
|
var pubNotSaGroupNums = importPubSaDetails.FindAll(t => t.Price == default(decimal)).Select(t => t.GroupNum).Distinct(); |
|
|
var pubNotSaGroupNums = importPubSaDetails.FindAll(t => t.Price == default(decimal)).Select(t => t.GroupNum).Distinct(); |
|
|
var pubSaDetailsCanSes = importPubSaDetails.FindAll(t => pubNotSaGroupNums.Contains(t.GroupNum) == false); |
|
|
var pubSaDetailsCanSes = importPubSaDetails.FindAll(t => pubNotSaGroupNums.Contains(t.GroupNum) == false); |
|
|
var pubSaDetailsNotCanSes = importPubSaDetails.FindAll(t => pubNotSaGroupNums.Contains(t.GroupNum) == true); |
|
|
var pubSaDetailsNotCanSes = importPubSaDetails.FindAll(t => pubNotSaGroupNums.Contains(t.GroupNum) == true); |
|
|
|
|
|
|
|
|
//可结算明细
|
|
|
//可结算明细
|
|
|
pubCanSaDetails = ObjectMapper.Map<List<PUB_SA_DETAIL>, List<PUB_CAN_SA_DETAIL>>(pubSaDetailsCanSes); |
|
|
pubCanSaDetails = ObjectMapper.Map<List<PUB_SA_DETAIL>, List<PUB_CAN_SA_DETAIL>>(pubSaDetailsCanSes); |
|
|
//不可结算明细
|
|
|
//不可结算明细
|
|
|
pubNotSaDetails = ObjectMapper.Map<List<PUB_SA_DETAIL>, List<PUB_NOT_SA_DETAIL>>(pubSaDetailsNotCanSes); |
|
|
pubNotSaDetails = ObjectMapper.Map<List<PUB_SA_DETAIL>, List<PUB_NOT_SA_DETAIL>>(pubSaDetailsNotCanSes); |
|
|
#endregion
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
#region 添加入库
|
|
|
#region 添加入库
|
|
|
await _repository.InsertAsync(pubSa); |
|
|
await _repository.InsertAsync(pubSa); |
|
|
await _pubSaDetailRepository.InsertManyAsync(importPubSaDetails); |
|
|
await _pubSaDetailRepository.InsertManyAsync(importPubSaDetails); |
|
|
if (pubCanSaDetails.Count > 0) |
|
|
if (pubCanSaDetails.Count > 0) |
|
|
{ |
|
|
{ |
|
|
pubCanSa.InvGroupNum = pubCanSaDetails.Count.ToString(); |
|
|
pubCanSa.InvGroupNum = pubCanSaDetails.Count.ToString(); |
|
|
pubCanSaDetails.ForEach(pubCanSaDetail => |
|
|
pubCanSaDetails.ForEach(pubCanSaDetail => |
|
|
{ |
|
|
|
|
|
pubCanSaDetail.BillNum = pubCanSaDetail.InvGroupNum = pubCanSaBillNum; |
|
|
|
|
|
pubCanSaDetail.BusinessType = businessType; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
await _pubCanSaRepository.InsertAsync(pubCanSa); |
|
|
|
|
|
await _pubCanSaDetailRepository.InsertManyAsync(pubCanSaDetails); |
|
|
|
|
|
} |
|
|
|
|
|
if (pubNotSaDetails.Count > 0) |
|
|
|
|
|
{ |
|
|
{ |
|
|
pubNotSaDetails.ForEach(pubNotSaDetail => |
|
|
pubCanSaDetail.BillNum = pubCanSaDetail.InvGroupNum = pubCanSaBillNum; |
|
|
{ |
|
|
pubCanSaDetail.BusinessType = businessType; |
|
|
pubNotSaDetail.BusinessType = businessType; |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
await _pubNotSaDetailRepository.InsertManyAsync(pubNotSaDetails); |
|
|
await _pubCanSaRepository.InsertAsync(pubCanSa); |
|
|
} |
|
|
await _pubCanSaDetailRepository.InsertManyAsync(pubCanSaDetails); |
|
|
if (materialRelationships.Count > 0) |
|
|
} |
|
|
|
|
|
if (pubNotSaDetails.Count > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
pubNotSaDetails.ForEach(pubNotSaDetail => |
|
|
{ |
|
|
{ |
|
|
await _materialRelationshipRepository.InsertManyAsync(materialRelationships); |
|
|
pubNotSaDetail.BusinessType = businessType; |
|
|
} |
|
|
}); |
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
return ApplicationConsts.SuccessStr; |
|
|
await _pubNotSaDetailRepository.InsertManyAsync(pubNotSaDetails); |
|
|
|
|
|
} |
|
|
|
|
|
if (materialRelationships.Count > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
await _materialRelationshipRepository.InsertManyAsync(materialRelationships); |
|
|
} |
|
|
} |
|
|
#endregion
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
return ApplicationConsts.SuccessStr; |
|
|
} |
|
|
} |
|
|
|
|
|
#endregion
|
|
|
} |
|
|
} |
|
|