mahao 1 year ago
parent
commit
52fb43d4ba
  1. 5
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_SA_SERVICE.cs
  2. 4
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/HBPO_SA_SERVICE.cs
  3. 9
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PUB_SA_SERVICE.cs
  4. 65
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/Prices/PriceListAppService.cs
  5. 57
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/Prices/PriceListAppServiceBJ.cs

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

@ -400,11 +400,10 @@ public class BBAC_SA_SERVICE : SettleAccountApplicationBase<BBAC_SA>
//导入的零件号集合
var importPubSaLUs = bbacSaDetails.Select(t => t.LU).Distinct();
//销售价格
var priceListEntitys = _priceListRepository.Where(t => importPubSaLUs.Contains(t.LU)).ToList();
var priceListEntitys = _priceListRepository.Where(t => t.IsCancel == false).Where(t => importPubSaLUs.Contains(t.LU)).ToList();
var materialRelationshipEntitys = await _materialRelationshipRepository.GetListAsync(t => importPubSaLUs.Contains(t.SettleMaterialCode)).ConfigureAwait(false);
bbacSaDetails.ForEach(bbacSaDetail =>
{
//根据物料号、结算日期获取价格
//根据物料号、结算日期获取价格
var priceListEntity = priceListEntitys
.Where(t => t.LU == bbacSaDetail.LU)
@ -414,7 +413,7 @@ public class BBAC_SA_SERVICE : SettleAccountApplicationBase<BBAC_SA>
.FirstOrDefault();
bbacSaDetail.Price = priceListEntity?.Price ?? 0;
bbacSaDetail.PartCode = materialRelationshipEntitys.FirstOrDefault(t => t.SettleMaterialCode == bbacSaDetail.LU)?.ErpMaterialCode ?? bbacSaDetail.LU.Replace(new string(' ', 6), "-");
bbacSaDetail.PartCode = materialRelationshipEntitys.FirstOrDefault(t => t.SettleMaterialCode == bbacSaDetail.LU)?.ErpMaterialCode;
});
#endregion

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

@ -370,7 +370,7 @@ public class HBPO_SA_SERVICE : SettleAccountApplicationBase<HBPO_SA>
//导入的零件号集合
var importPubSaLUs = hbpoSaDetails.Select(t => t.LU).Distinct();
//销售价格
var priceListEntitys = _priceListRepository.Where(t => importPubSaLUs.Contains(t.LU)).ToList();
var priceListEntitys = _priceListRepository.Where(t => t.IsCancel == false).Where(t => importPubSaLUs.Contains(t.LU)).ToList();
var materialRelationshipEntitys = await _materialRelationshipRepository.GetListAsync(t => importPubSaLUs.Contains(t.SettleMaterialCode)).ConfigureAwait(false);
hbpoSaDetails.ForEach(hbpoSaDetail =>
{
@ -383,7 +383,7 @@ public class HBPO_SA_SERVICE : SettleAccountApplicationBase<HBPO_SA>
.FirstOrDefault();
hbpoSaDetail.Price = priceListEntity?.Price ?? 0;
hbpoSaDetail.PartCode = materialRelationshipEntitys.FirstOrDefault(t => t.SettleMaterialCode == hbpoSaDetail.LU)?.ErpMaterialCode ?? hbpoSaDetail.LU.Replace(new string(' ', 6), "-");
hbpoSaDetail.PartCode = materialRelationshipEntitys.FirstOrDefault(t => t.SettleMaterialCode == hbpoSaDetail.LU)?.ErpMaterialCode;
});
#endregion

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

@ -443,7 +443,8 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase<PUB_SA>
if (businessType == EnumBusinessType.BeiJian)
{
//备件销售价格
var priceListEntitys = _priceBjListRepository.Where(t => lus.Contains(t.LU)).ToList();
var priceListEntitys = _priceBjListRepository.Where(t => t.IsCancel == false)
.Where(t => lus.Contains(t.LU)).ToList();
pubSaDetails.ForEach(importPubSaDetail =>
{
//根据物料号、结算日期获取价格
@ -459,7 +460,8 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase<PUB_SA>
else
{
//销售价格
var priceListEntitys = _priceListRepository.Where(t => lus.Contains(t.LU)).ToList();
var priceListEntitys = _priceListRepository.Where(t => t.IsCancel == false)
.Where(t => lus.Contains(t.LU)).ToList();
pubSaDetails.ForEach(importPubSaDetail =>
{
//根据物料号、结算日期获取价格
@ -467,6 +469,7 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase<PUB_SA>
.Where(t => t.LU == importPubSaDetail.LU)
.Where(t => importPubSaDetail.SettleDate >= t.BeginTime && importPubSaDetail.SettleDate <= t.EndTime)
.OrderByDescending(t => t.Date)
.ThenByDescending(t => t.CreationTime)
.FirstOrDefault();
importPubSaDetail.Price = priceListEntity?.Price ?? 0;
});
@ -479,7 +482,7 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase<PUB_SA>
var seAllMaterialRelationships = materialRelationshipEntitys.Union(materialRelationships);
pubSaDetails.ForEach(pubSaDetail =>
{
pubSaDetail.PartCode = materialRelationshipEntitys.FirstOrDefault(t => t.SettleMaterialCode == pubSaDetail.LU)?.ErpMaterialCode ?? pubSaDetail.LU.Replace(new string(' ', 6), "-");
pubSaDetail.PartCode = materialRelationshipEntitys.FirstOrDefault(t => t.SettleMaterialCode == pubSaDetail.LU)?.ErpMaterialCode;
});
#endregion

65
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/Prices/PriceListAppService.cs

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using EFCore.BulkExtensions;
using Magicodes.ExporterAndImporter.Core;
using Magicodes.ExporterAndImporter.Excel;
using Microsoft.AspNetCore.Authorization;
@ -14,8 +15,6 @@ using Win.Abp.Snowflakes;
using Win.Sfs.BaseData.ImportExcelCommon;
using Win.Sfs.SettleAccount.CommonManagers;
using Win.Sfs.SettleAccount.Entities.BQ.Dtos;
using Win.Sfs.SettleAccount.Entities.ImportMap;
using Win.Sfs.SettleAccount.Entities.TaskJobs;
using Win.Sfs.SettleAccount.ExcelImporter;
using Win.Sfs.SettleAccount.ExportReports;
using Win.Sfs.Shared.RepositoryBase;
@ -29,26 +28,26 @@ namespace Win.Sfs.SettleAccount.Entities.Prices;
[Route("api/settleaccount/[controller]/[action]")]
public class PriceListAppService : SettleAccountApplicationBase<PriceList>
{
/// <summary>
/// 数据上下文
/// </summary>
private readonly SettleAccountDbContext _settleAccountDbContext;
/// <summary>
/// 销售价格仓储
/// </summary>
private readonly INormalEfCoreRepository<PriceList, Guid> _priceListRepository;
private readonly ISettleAccountBranchEfCoreRepository<ImportColumnMap, Guid> _mapRepository;
private readonly TaskJobService _service;
public PriceListAppService(
SettleAccountDbContext settleAccountDbContext,
INormalEfCoreRepository<PriceList, Guid> priceListRepository,
ISettleAccountBranchEfCoreRepository<ImportColumnMap, Guid> mapRepository,
TaskJobService service,
IDistributedCache<PriceList> cache,
IExcelImportAppService excelImportService,
ISnowflakeIdGenerator snowflakeIdGenerator,
ICommonManager commonManager
) : base(cache, excelImportService, snowflakeIdGenerator, commonManager)
{
_settleAccountDbContext = settleAccountDbContext;
_priceListRepository = priceListRepository;
_mapRepository = mapRepository;
_service = service;
}
#region 导入、导出
@ -69,22 +68,52 @@ public class PriceListAppService : SettleAccountApplicationBase<PriceList>
public virtual async Task<IActionResult> ImportAsync([FromForm] IFormFileCollection files, string version)
{
var checkList = new List<ErrorExportDto>();
ExportImporter _exportImporter = new ExportImporter();
var _exportImporter = new ExportImporter();
var result = await _exportImporter.UploadExcelImportByHeadDesc<PriceListImportDto>(files, _excelImportService).ConfigureAwait(false);
List<string> _checkls = new List<string>();
_checkls.Add("1040");
_checkls.Add("1046");
_checkls.Add("104T");
result = result.Where(p => _checkls.Contains(p.Plant)).ToList();
result.Where(t => !string.IsNullOrEmpty(t.ES1) || !string.IsNullOrEmpty(t.ES2)).ForEach(t => t.PartNo = t.PartNo + new string(' ', 6) + t.ES1 + t.ES2);
var filter = new List<string>
{
"1040",
"1046",
"104T"
};
result = result.FindAll(p => filter.Contains(p.Plant)).ToList();
result.FindAll(t => !string.IsNullOrEmpty(t.ES1) || !string.IsNullOrEmpty(t.ES2)).ForEach(t => t.PartNo = t.PartNo + new string(' ', 6) + t.ES1 + t.ES2);
var entityList = ObjectMapper.Map<List<PriceListImportDto>, List<PriceList>>(result);
entityList = entityList.GroupBy(p => new { p.LU, p.ClientCode, p.BeginTime, p.EndTime }).Select(p => p.FirstOrDefault()).ToList();
var newPrice = entityList.GroupBy(p => p.LU).Select(p => p.FirstOrDefault()).ToList();
foreach (var item in entityList)
var importLus = newPrice.Select(t => t.LU).Distinct().ToList();
var oldPrices = _settleAccountDbContext.Set<PriceList>()
.Where(t => t.IsCancel == false)
.Where(t => importLus.Contains(t.LU))
.ToList();
//系统中合同日期比导入文件中的合同日期晚
var oldpriceNewDate = from oldprice in oldPrices
from newprice in newPrice
where oldprice.LU == newprice.LU && oldprice.Date > newprice.Date
select oldprice;
oldPrices.ForEach(t => t.IsCancel = true);
if (oldpriceNewDate.Any())
{
oldPrices.FindAll(t => oldpriceNewDate.Contains(t)).ForEach(t => t.IsCancel = false);
var importCancelLus = oldPrices.Select(t => t.LU).Distinct();
newPrice.FindAll(t => importCancelLus.Contains(t.LU)).ForEach(t => t.IsCancel = true);
}
foreach (var item in newPrice)
{
item.Update(GuidGenerator.Create());
}
await _priceListRepository.InsertManyAsync(entityList).ConfigureAwait(false);
using var transaction = await _settleAccountDbContext.Database.BeginTransactionAsync().ConfigureAwait(false);
try
{
await _settleAccountDbContext.BulkUpdateAsync<PriceList>(oldPrices).ConfigureAwait(false);
await _settleAccountDbContext.BulkInsertAsync<PriceList>(newPrice).ConfigureAwait(false);
await transaction.CommitAsync().ConfigureAwait(false);
}
catch (Exception)
{
await transaction.RollbackAsync().ConfigureAwait(false);
return new JsonResult(new { Code = 200, Message = "导入失败" });
}
return new JsonResult(new { Code = 200, Message = "导入成功" });
}

57
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/Prices/PriceListAppServiceBJ.cs

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using EFCore.BulkExtensions;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
@ -25,9 +26,14 @@ namespace Win.Sfs.SettleAccount.Entities.Prices;
[Route("api/settleaccount/[controller]/[action]")]
public class PriceListAppServiceBJ : SettleAccountApplicationBase<PriceListBJ>
{
/// <summary>
/// 数据上下文
/// </summary>
private readonly SettleAccountDbContext _settleAccountDbContext;
private readonly INormalEfCoreRepository<PriceListBJ, Guid> _repository;
public PriceListAppServiceBJ(
SettleAccountDbContext settleAccountDbContext,
INormalEfCoreRepository<PriceListBJ, Guid> repository,
IDistributedCache<PriceListBJ> cache,
IExcelImportAppService excelImportService,
@ -35,6 +41,7 @@ public class PriceListAppServiceBJ : SettleAccountApplicationBase<PriceListBJ>
ICommonManager commonManager
) : base(cache, excelImportService, snowflakeIdGenerator, commonManager)
{
_settleAccountDbContext = settleAccountDbContext;
_repository = repository;
}
@ -46,23 +53,53 @@ public class PriceListAppServiceBJ : SettleAccountApplicationBase<PriceListBJ>
public async Task<IActionResult> ImportAsync([FromForm] IFormFileCollection files, string version)
{
var checkList = new List<ErrorExportDto>();
ExportImporter _exportImporter = new ExportImporter();
var _exportImporter = new ExportImporter();
var result = await _exportImporter.UploadExcelImportByHeadDesc<PriceListBJImportDto>(files, _excelImportService).ConfigureAwait(false);
List<string> _checkls = new List<string>();
_checkls.Add("1040");
_checkls.Add("1046");
_checkls.Add("104T");
result = result.Where(p => _checkls.Contains(p.ClientCode)).ToList();
var filter = new List<string>
{
"1040",
"1046",
"104T"
};
result = result.Where(p => filter.Contains(p.ClientCode)).ToList();
var entityList = ObjectMapper.Map<List<PriceListBJImportDto>, List<PriceListBJ>>(result);
entityList = entityList.GroupBy(p => new { p.LU, p.ClientCode, p.BeginDate, p.EndDate }).Select(p => p.FirstOrDefault()).ToList();
var newPrice = entityList.GroupBy(p => p.LU).Select(p => p.FirstOrDefault()).ToList();
foreach (var item in entityList)
var importLus = newPrice.Select(t => t.LU).Distinct().ToList();
var oldPrices = _settleAccountDbContext.Set<PriceListBJ>()
.Where(t => t.IsCancel == false)
.Where(t => importLus.Contains(t.LU))
.ToList();
//系统中合同日期比导入文件中的合同日期晚
var oldpriceNewDate = from oldprice in oldPrices
from newprice in newPrice
where oldprice.LU == newprice.LU && oldprice.Date > newprice.Date
select oldprice;
oldPrices.ForEach(t => t.IsCancel = true);
if (oldpriceNewDate.Any())
{
oldPrices.FindAll(t => oldpriceNewDate.Contains(t)).ForEach(t => t.IsCancel = false);
var importCancelLus = oldPrices.Select(t => t.LU).Distinct();
newPrice.FindAll(t => importCancelLus.Contains(t.LU)).ForEach(t => t.IsCancel = true);
}
foreach (var item in newPrice)
{
item.Update(GuidGenerator.Create());
}
await _repository.InsertManyAsync(entityList).ConfigureAwait(false);
using var transaction = await _settleAccountDbContext.Database.BeginTransactionAsync().ConfigureAwait(false);
try
{
await _settleAccountDbContext.BulkUpdateAsync<PriceListBJ>(oldPrices).ConfigureAwait(false);
await _settleAccountDbContext.BulkInsertAsync<PriceListBJ>(newPrice).ConfigureAwait(false);
await transaction.CommitAsync().ConfigureAwait(false);
}
catch (Exception)
{
await transaction.RollbackAsync().ConfigureAwait(false);
return new JsonResult(new { Code = 200, Message = "导入失败" });
}
return new JsonResult(new { Code = 200, Message = "导入成功" });
}
/// <summary>

Loading…
Cancel
Save