wanggang 1 year ago
parent
commit
1c9c11a705
  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. 75
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisBBACSeEdiCompareAppService.cs
  5. 135
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisHBPOSeEdiCompareAppService.cs
  6. 66
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/Prices/PriceListAppService.cs
  7. 58
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/Prices/PriceListAppServiceBJ.cs
  8. 21
      code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/Prices/PriceList.cs
  9. 5777
      code/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Migrations/20230907075720_20230907-1.Designer.cs
  10. 190
      code/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Migrations/20230907075720_20230907-1.cs
  11. 28
      code/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Migrations/SettleAccountDbContextModelSnapshot.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

75
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisBBACSeEdiCompareAppService.cs

@ -29,40 +29,44 @@ public class JisBBACSeEdiCompareAppService : ApplicationService, IInvocable
/// </summary>
public async Task Invoke()
{
try
{
using var serviceScope = _serviceProvider.CreateScope();
var db = serviceScope.ServiceProvider.GetRequiredService<SettleAccountDbContext>();
using var serviceScope = _serviceProvider.CreateScope();
var db = serviceScope.ServiceProvider.GetRequiredService<SettleAccountDbContext>();
await HandDelEdiDataAsync().ConfigureAwait(false);
await HandDelEdiDataAsync().ConfigureAwait(false);
var seDetailGroup = db.Set<BBAC_SE_DETAIL>()
.Where(t => t.IsHaveEdiData == false)
.GroupBy(t => new { t.PN, t.CustomerPartCodeNoSpace })
.Select(t => t.Key);
var ediDetailGroup = db.Set<BBAC_SE_EDI>()
.Where(t => t.IsDeleted == false)
.GroupBy(t => new { t.PN, t.CustomerPartCodeNoSpace })
.Select(t => t.Key);
var seDetailGroup = db.Set<BBAC_SE_DETAIL>()
.Where(t => t.IsHaveEdiData == false)
.GroupBy(t => new { t.PN, t.CustomerPartCodeNoSpace })
.Select(t => t.Key);
var ediDetailGroup = db.Set<BBAC_SE_EDI>()
.Where(t => t.IsDeleted == false && t.IsHaveSeData == false)
.GroupBy(t => new { t.PN, t.CustomerPartCodeNoSpace })
.Select(t => t.Key);
var keyCodes = from se in seDetailGroup
from edi in ediDetailGroup
where se.PN == edi.PN && se.CustomerPartCodeNoSpace == edi.CustomerPartCodeNoSpace
select new { se.PN, se.CustomerPartCodeNoSpace };
var seDetailsQuery = from se in db.Set<BBAC_SE_DETAIL>()
from keyCode in keyCodes
where se.PN == keyCode.PN && se.CustomerPartCodeNoSpace == keyCode.CustomerPartCodeNoSpace && se.IsHaveEdiData == false
select se;
var ediDetailsQuery = from edi in db.Set<BBAC_SE_EDI>()
from keyCode in keyCodes
where edi.PN == keyCode.PN && edi.CustomerPartCodeNoSpace == keyCode.CustomerPartCodeNoSpace && edi.IsDeleted == false && edi.IsHaveSeData == false
select edi;
var keyCodes = (from se in seDetailGroup
from edi in ediDetailGroup
where se.PN == edi.PN && se.CustomerPartCodeNoSpace == edi.CustomerPartCodeNoSpace
select new { se.PN, se.CustomerPartCodeNoSpace }
).Take(1000).ToList();
if (keyCodes.Any())
{
var pns = keyCodes.Select(t => t.PN).Distinct().ToList();
var seDetails = seDetailsQuery.Take(5000).ToList();
var ediDetails = ediDetailsQuery.Take(5000).ToList();
var seDetails = db.Set<BBAC_SE_DETAIL>()
.Where(t => t.IsHaveEdiData == false)
.Where(t => pns.Contains(t.PN))
.AsEnumerable<BBAC_SE_DETAIL>()
.GroupJoin(keyCodes, x => new { x.PN, x.CustomerPartCodeNoSpace }, y => y, (x, y) => x)
.ToList();
var ediDetails = db.Set<BBAC_SE_EDI>()
.Where(t => t.IsDeleted == false)
.Where(t => t.IsHaveSeData == false)
.Where(t => pns.Contains(t.PN))
.AsEnumerable<BBAC_SE_EDI>()
.GroupJoin(keyCodes, x => new { x.PN, x.CustomerPartCodeNoSpace }, y => y, (x, y) => x)
.ToList();
seDetails.ForEach(t => t.IsHaveEdiData = true);
ediDetails.ForEach(t => t.IsHaveSeData = true);
using var transaction = await db.Database.BeginTransactionAsync().ConfigureAwait(false);
try
{
@ -73,13 +77,8 @@ public class JisBBACSeEdiCompareAppService : ApplicationService, IInvocable
catch (Exception)
{
await transaction.RollbackAsync().ConfigureAwait(false);
throw;
}
}
catch (Exception)
{
throw;
}
}
/// <summary>
@ -100,27 +99,27 @@ public class JisBBACSeEdiCompareAppService : ApplicationService, IInvocable
{
seed++;
//Edi 删除的数据(有发运数据)
var ediDelKeyCodes = db.Set<HBPO_SE_EDI>().Where(t => t.IsDeleted == true && t.IsHaveSeData == true).GroupBy(t => t.PN).Select(t => t.Key).Take(1000).ToList();
var ediDelKeyCodes = db.Set<BBAC_SE_EDI>().Where(t => t.IsDeleted == true && t.IsHaveSeData == true).GroupBy(t => t.PN).Select(t => t.Key).Take(1000).ToList();
if (ediDelKeyCodes.Any())
{
var seDetails = db.Set<HBPO_SE_DETAIL>()
var seDetails = db.Set<BBAC_SE_DETAIL>()
.Where(t => t.IsHaveEdiData == true)
.Where(t => ediDelKeyCodes.Contains(t.PN))
.ToList();
if (seDetails.Any())
{
seDetails.ForEach(t => t.IsHaveEdiData = false);
await db.BulkUpdateAsync<HBPO_SE_DETAIL>(seDetails).ConfigureAwait(false);
await db.BulkUpdateAsync<BBAC_SE_DETAIL>(seDetails).ConfigureAwait(false);
}
var ediDetails = db.Set<HBPO_SE_EDI>()
var ediDetails = db.Set<BBAC_SE_EDI>()
.Where(t => t.IsHaveSeData == true)
.Where(t => ediDelKeyCodes.Contains(t.PN))
.ToList();
if (ediDetails.Any())
{
ediDetails.ForEach(t => t.IsHaveSeData = false);
await db.BulkUpdateAsync<HBPO_SE_EDI>(ediDetails).ConfigureAwait(false);
await db.BulkUpdateAsync<BBAC_SE_EDI>(ediDetails).ConfigureAwait(false);
}
}
else

135
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisHBPOSeEdiCompareAppService.cs

@ -25,111 +25,49 @@ public class JisHBPOSeEdiCompareAppService : ApplicationService, IInvocable
_serviceProvider = serviceProvider;
}
/// <summary>
/// 执行
/// </summary>
public async Task InvokeOld()
{
try
{
using var serviceScope = _serviceProvider.CreateScope();
var db = serviceScope.ServiceProvider.GetRequiredService<SettleAccountDbContext>();
await HandDelEdiDataAsync().ConfigureAwait(false);
var seDetailGroup = db.Set<HBPO_SE_DETAIL>()
.Where(t => t.IsHaveEdiData == false)
.GroupBy(t => new { t.PN, t.CustomerPartCodeNoSpace })
.Select(t => t.Key);
var ediDetailGroup = db.Set<HBPO_SE_EDI>()
.Where(t => t.IsDeleted == false && t.IsHaveSeData == false)
.GroupBy(t => new { t.PN, t.CustomerPartCodeNoSpace })
.Select(t => t.Key);
var keyCodes = (from se in seDetailGroup
from edi in ediDetailGroup
where se.PN == edi.PN && se.CustomerPartCodeNoSpace == edi.CustomerPartCodeNoSpace
select new { se.PN, se.CustomerPartCodeNoSpace }
).Take(5000).ToList();
if (keyCodes.Any())
{
var pnGroup = keyCodes.GroupBy(t => t.PN).Select(t => new { t.Key, CustomerPartCodeNoSpaces = t.Select(s => s.CustomerPartCodeNoSpace).Distinct() });
foreach (var item in pnGroup)
{
var pn = item.Key;
var lus = item.CustomerPartCodeNoSpaces;
}
}
var seDetailsQuery = from se in db.Set<HBPO_SE_DETAIL>()
from keyCode in keyCodes
where se.PN == keyCode.PN && se.CustomerPartCodeNoSpace == keyCode.CustomerPartCodeNoSpace && se.IsHaveEdiData == false
select se;
var ediDetailsQuery = from edi in db.Set<HBPO_SE_EDI>()
from keyCode in keyCodes
where edi.PN == keyCode.PN && edi.CustomerPartCodeNoSpace == keyCode.CustomerPartCodeNoSpace && edi.IsDeleted == false && edi.IsHaveSeData == false
select edi;
var seDetails = seDetailsQuery.Take(5000).ToList();
var ediDetails = ediDetailsQuery.Take(5000).ToList();
seDetails.ForEach(t => t.IsHaveEdiData = true);
ediDetails.ForEach(t => t.IsHaveSeData = true);
using var transaction = await db.Database.BeginTransactionAsync().ConfigureAwait(false);
try
{
await db.BulkUpdateAsync<HBPO_SE_DETAIL>(seDetails).ConfigureAwait(false);
await db.BulkUpdateAsync<HBPO_SE_EDI>(ediDetails).ConfigureAwait(false);
await transaction.CommitAsync().ConfigureAwait(false);
}
catch (Exception)
{
await transaction.RollbackAsync().ConfigureAwait(false);
throw;
}
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// 执行
/// </summary>
public async Task Invoke()
{
try
{
using var serviceScope = _serviceProvider.CreateScope();
var db = serviceScope.ServiceProvider.GetRequiredService<SettleAccountDbContext>();
await HandDelEdiDataAsync().ConfigureAwait(false);
var seDetailGroup = db.Set<HBPO_SE_DETAIL>().Where(t => t.IsHaveEdiData == false).GroupBy(t => new { t.PN, t.CustomerPartCodeNoSpace }).Select(t => new { t.Key.PN, t.Key.CustomerPartCodeNoSpace });
var ediDetailGroup = db.Set<HBPO_SE_EDI>().Where(t => t.IsDeleted == false && t.IsHaveSeData == false).GroupBy(t => new { t.PN, t.CustomerPartCodeNoSpace }).Select(t => new { t.Key.PN, t.Key.CustomerPartCodeNoSpace });
using var serviceScope = _serviceProvider.CreateScope();
var db = serviceScope.ServiceProvider.GetRequiredService<SettleAccountDbContext>();
var keyCodes = from se in seDetailGroup
from edi in ediDetailGroup
where se.PN == edi.PN && se.CustomerPartCodeNoSpace == edi.CustomerPartCodeNoSpace
select new { se.PN, se.CustomerPartCodeNoSpace };
var seDetailsQuery = from se in db.Set<HBPO_SE_DETAIL>()
from keyCode in keyCodes
where se.PN == keyCode.PN && se.CustomerPartCodeNoSpace == keyCode.CustomerPartCodeNoSpace && se.IsHaveEdiData == false
select se;
var ediDetailsQuery = from edi in db.Set<HBPO_SE_EDI>()
from keyCode in keyCodes
where edi.PN == keyCode.PN && edi.CustomerPartCodeNoSpace == keyCode.CustomerPartCodeNoSpace && edi.IsDeleted == false && edi.IsHaveSeData == false
select edi;
await HandDelEdiDataAsync().ConfigureAwait(false);
var seDetailGroup = db.Set<HBPO_SE_DETAIL>()
.Where(t => t.IsHaveEdiData == false)
.GroupBy(t => new { t.PN, t.CustomerPartCodeNoSpace })
.Select(t => t.Key);
var ediDetailGroup = db.Set<HBPO_SE_EDI>()
.Where(t => t.IsDeleted == false && t.IsHaveSeData == false)
.GroupBy(t => new { t.PN, t.CustomerPartCodeNoSpace })
.Select(t => t.Key);
var keyCodes = (from se in seDetailGroup
from edi in ediDetailGroup
where se.PN == edi.PN && se.CustomerPartCodeNoSpace == edi.CustomerPartCodeNoSpace
select new { se.PN, se.CustomerPartCodeNoSpace }
).Take(1000).ToList();
if (keyCodes.Any())
{
var pns = keyCodes.Select(t => t.PN).Distinct().ToList();
var seDetails = seDetailsQuery.Take(5000).ToList();
var ediDetails = ediDetailsQuery.Take(5000).ToList();
var seDetails = db.Set<HBPO_SE_DETAIL>()
.Where(t => t.IsHaveEdiData == false)
.Where(t => pns.Contains(t.PN))
.AsEnumerable<HBPO_SE_DETAIL>()
.GroupJoin(keyCodes, x => new { x.PN, x.CustomerPartCodeNoSpace }, y => y, (x, y) => x)
.ToList();
var ediDetails = db.Set<HBPO_SE_EDI>()
.Where(t => t.IsDeleted == false)
.Where(t => t.IsHaveSeData == false)
.Where(t => pns.Contains(t.PN))
.AsEnumerable<HBPO_SE_EDI>()
.GroupJoin(keyCodes, x => new { x.PN, x.CustomerPartCodeNoSpace }, y => y, (x, y) => x)
.ToList();
seDetails.ForEach(t => t.IsHaveEdiData = true);
ediDetails.ForEach(t => t.IsHaveSeData = true);
using var transaction = await db.Database.BeginTransactionAsync().ConfigureAwait(false);
try
{
@ -140,13 +78,8 @@ public class JisHBPOSeEdiCompareAppService : ApplicationService, IInvocable
catch (Exception)
{
await transaction.RollbackAsync().ConfigureAwait(false);
throw;
}
}
catch (Exception)
{
throw;
}
}
/// <summary>

66
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;
@ -13,10 +14,7 @@ using Volo.Abp.Caching;
using Win.Abp.Snowflakes;
using Win.Sfs.BaseData.ImportExcelCommon;
using Win.Sfs.SettleAccount.CommonManagers;
using Win.Sfs.SettleAccount.Constant;
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;
@ -30,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 导入、导出
@ -70,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 = "导入成功" });
}

58
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;
@ -11,7 +12,6 @@ using Volo.Abp.Caching;
using Win.Abp.Snowflakes;
using Win.Sfs.BaseData.ImportExcelCommon;
using Win.Sfs.SettleAccount.CommonManagers;
using Win.Sfs.SettleAccount.Constant;
using Win.Sfs.SettleAccount.Entities.BQ.Dtos;
using Win.Sfs.SettleAccount.ExcelImporter;
using Win.Sfs.SettleAccount.ExportReports;
@ -26,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,
@ -36,6 +41,7 @@ public class PriceListAppServiceBJ : SettleAccountApplicationBase<PriceListBJ>
ICommonManager commonManager
) : base(cache, excelImportService, snowflakeIdGenerator, commonManager)
{
_settleAccountDbContext = settleAccountDbContext;
_repository = repository;
}
@ -47,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>

21
code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/Prices/PriceList.cs

@ -75,43 +75,41 @@ namespace Win.Sfs.SettleAccount.Entities.Prices
/// </summary>
[Display(Name = "零件号")]
public string LU { get; set; }
/// <summary>
/// 价格
/// </summary>
[Display(Name = "价格")]
public Decimal Price { set; get; }
/// <summary>
/// 开始时间
/// </summary>
[Display(Name = "开始时间")]
public DateTime BeginTime { set; get; }
/// <summary>
/// 结束时间
/// </summary>
[Display(Name = "结束时间")]
public DateTime EndTime { set; get; }
/// <summary>
/// 客户编码
/// </summary>
[Display(Name = "客户编码")]
public string ClientCode { get; set; }
/// <summary>
/// 合同签订时间
/// </summary>
[Display(Name = "合同签订时间")]
public DateTime Date { get; set; }
/// <summary>
/// 合同号
/// </summary>
[Display(Name = "合同号")]
public string ContractNo { get; set; }
/// <summary>
/// 是否作废
/// </summary>
[Display(Name = "是否作废")]
public bool IsCancel { get; set; }
@ -227,25 +225,26 @@ namespace Win.Sfs.SettleAccount.Entities.Prices
/// </summary>
[Display(Name = "结算时间")]
public DateTime EndDate { set; get; }
/// <summary>
/// 客户编码
/// </summary>
[Display(Name = "客户编码")]
public string ClientCode { get; set; }
/// <summary>
/// 合同签订时间
/// </summary>
[Display(Name = "合同签订时间")]
public DateTime Date { get; set; }
/// <summary>
/// 合同号
/// </summary>
[Display(Name = "合同号")]
public string ContractNo { get; set; }
/// <summary>
/// 是否作废
/// </summary>
[Display(Name = "是否作废")]
public bool IsCancel { get; set; }

5777
code/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Migrations/20230907075720_20230907-1.Designer.cs

File diff suppressed because it is too large

190
code/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Migrations/20230907075720_20230907-1.cs

@ -0,0 +1,190 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Win.Sfs.SettleAccount.Migrations
{
public partial class _202309071 : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "IsCancel",
table: "Set_PriceListBJ",
type: "bit",
nullable: false,
defaultValue: false);
migrationBuilder.AddColumn<bool>(
name: "IsCancel",
table: "Set_PriceList",
type: "bit",
nullable: false,
defaultValue: false);
migrationBuilder.UpdateData(
table: "Set_JobItem",
keyColumn: "Id",
keyValue: new Guid("185c5968-e02b-267e-db2f-225fccfc9716"),
column: "ConcurrencyStamp",
value: "540d27f55bd9415bae51a264d888b256");
migrationBuilder.UpdateData(
table: "Set_JobItem",
keyColumn: "Id",
keyValue: new Guid("1bb02f67-ed05-6cc1-1507-502e8f6c7a31"),
column: "ConcurrencyStamp",
value: "f311bbe27f2d4dd088690d28c4dd8495");
migrationBuilder.UpdateData(
table: "Set_JobItem",
keyColumn: "Id",
keyValue: new Guid("49b1da12-418c-544d-fe8b-be7e5b572452"),
column: "ConcurrencyStamp",
value: "a641ae00f7db4b3cbf58dc098442c08b");
migrationBuilder.UpdateData(
table: "Set_JobItem",
keyColumn: "Id",
keyValue: new Guid("6f68fc8f-b058-c3f4-e07d-722c61f3f7fa"),
column: "ConcurrencyStamp",
value: "fc2fa51cd9124e2593e457241b79bc2b");
migrationBuilder.UpdateData(
table: "Set_JobItem",
keyColumn: "Id",
keyValue: new Guid("7a0dc087-a859-5863-eb6e-56f588bd779e"),
column: "ConcurrencyStamp",
value: "610f376ade18446f87589b9b99b16c6a");
migrationBuilder.UpdateData(
table: "Set_JobItem",
keyColumn: "Id",
keyValue: new Guid("8f7dc23d-e2e9-3691-cfe9-545bb958e3f2"),
column: "ConcurrencyStamp",
value: "272db8024ec645dc837afb433687572f");
migrationBuilder.UpdateData(
table: "Set_JobItem",
keyColumn: "Id",
keyValue: new Guid("b9b9c79f-4894-474b-4f67-b1ec121c41e5"),
column: "ConcurrencyStamp",
value: "54a845290661424dbd6600f40a77ec27");
migrationBuilder.UpdateData(
table: "Set_JobItem",
keyColumn: "Id",
keyValue: new Guid("c09c23ea-815f-1b43-4476-2365a8d9a60b"),
column: "ConcurrencyStamp",
value: "8c5c164e5abc471a97ec8dada4195a53");
migrationBuilder.UpdateData(
table: "Set_JobItem",
keyColumn: "Id",
keyValue: new Guid("c1f71240-1b81-0107-8b23-ddc9811a3efe"),
column: "ConcurrencyStamp",
value: "9072cbd6edd74b80821d92e9d98d8d61");
migrationBuilder.UpdateData(
table: "Set_JobItem",
keyColumn: "Id",
keyValue: new Guid("ef3d8e8a-a88e-ca1f-e615-714c6bc48824"),
column: "ConcurrencyStamp",
value: "090f151b1c6e418299e23b7b2397a0cb");
migrationBuilder.UpdateData(
table: "Set_JobItem",
keyColumn: "Id",
keyValue: new Guid("f306b380-47e5-5c01-b902-67ca4113a8f4"),
column: "ConcurrencyStamp",
value: "dcd7451cfe3d4472b8eca39f7e890038");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "IsCancel",
table: "Set_PriceListBJ");
migrationBuilder.DropColumn(
name: "IsCancel",
table: "Set_PriceList");
migrationBuilder.UpdateData(
table: "Set_JobItem",
keyColumn: "Id",
keyValue: new Guid("185c5968-e02b-267e-db2f-225fccfc9716"),
column: "ConcurrencyStamp",
value: "25540a425f78445b98a5590b3d708bcd");
migrationBuilder.UpdateData(
table: "Set_JobItem",
keyColumn: "Id",
keyValue: new Guid("1bb02f67-ed05-6cc1-1507-502e8f6c7a31"),
column: "ConcurrencyStamp",
value: "42328476bcab4eb38035d28596d5ecd9");
migrationBuilder.UpdateData(
table: "Set_JobItem",
keyColumn: "Id",
keyValue: new Guid("49b1da12-418c-544d-fe8b-be7e5b572452"),
column: "ConcurrencyStamp",
value: "7d49bd0d15124ee0b6de9f558fc9a429");
migrationBuilder.UpdateData(
table: "Set_JobItem",
keyColumn: "Id",
keyValue: new Guid("6f68fc8f-b058-c3f4-e07d-722c61f3f7fa"),
column: "ConcurrencyStamp",
value: "4aea58b425a34947869fba8e92ade9f2");
migrationBuilder.UpdateData(
table: "Set_JobItem",
keyColumn: "Id",
keyValue: new Guid("7a0dc087-a859-5863-eb6e-56f588bd779e"),
column: "ConcurrencyStamp",
value: "f65d6d2f92684535a920d7f3ed75699d");
migrationBuilder.UpdateData(
table: "Set_JobItem",
keyColumn: "Id",
keyValue: new Guid("8f7dc23d-e2e9-3691-cfe9-545bb958e3f2"),
column: "ConcurrencyStamp",
value: "ec6c990fce2a4728a00c488c7757c172");
migrationBuilder.UpdateData(
table: "Set_JobItem",
keyColumn: "Id",
keyValue: new Guid("b9b9c79f-4894-474b-4f67-b1ec121c41e5"),
column: "ConcurrencyStamp",
value: "dda70cc2fd7f4328be7860a550006ecb");
migrationBuilder.UpdateData(
table: "Set_JobItem",
keyColumn: "Id",
keyValue: new Guid("c09c23ea-815f-1b43-4476-2365a8d9a60b"),
column: "ConcurrencyStamp",
value: "5e50b42897c1455597888da08f8587de");
migrationBuilder.UpdateData(
table: "Set_JobItem",
keyColumn: "Id",
keyValue: new Guid("c1f71240-1b81-0107-8b23-ddc9811a3efe"),
column: "ConcurrencyStamp",
value: "afe6ab9a36024802ba83dd3e32de0ad4");
migrationBuilder.UpdateData(
table: "Set_JobItem",
keyColumn: "Id",
keyValue: new Guid("ef3d8e8a-a88e-ca1f-e615-714c6bc48824"),
column: "ConcurrencyStamp",
value: "f98cf5180c124d88a4853f8c9e1ebece");
migrationBuilder.UpdateData(
table: "Set_JobItem",
keyColumn: "Id",
keyValue: new Guid("f306b380-47e5-5c01-b902-67ca4113a8f4"),
column: "ConcurrencyStamp",
value: "2f035dd2eca74570a85ae5276cc99e1c");
}
}
}

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

@ -4461,7 +4461,7 @@ namespace Win.Sfs.SettleAccount.Migrations
new
{
Id = new Guid("ef3d8e8a-a88e-ca1f-e615-714c6bc48824"),
ConcurrencyStamp = "f98cf5180c124d88a4853f8c9e1ebece",
ConcurrencyStamp = "090f151b1c6e418299e23b7b2397a0cb",
Cron = "0 0 8 26 *",
IsDisabled = false,
IsRunning = false,
@ -4471,7 +4471,7 @@ namespace Win.Sfs.SettleAccount.Migrations
new
{
Id = new Guid("185c5968-e02b-267e-db2f-225fccfc9716"),
ConcurrencyStamp = "25540a425f78445b98a5590b3d708bcd",
ConcurrencyStamp = "540d27f55bd9415bae51a264d888b256",
Cron = "0 0/1 * * * ?",
IsDisabled = false,
IsRunning = false,
@ -4481,7 +4481,7 @@ namespace Win.Sfs.SettleAccount.Migrations
new
{
Id = new Guid("1bb02f67-ed05-6cc1-1507-502e8f6c7a31"),
ConcurrencyStamp = "42328476bcab4eb38035d28596d5ecd9",
ConcurrencyStamp = "f311bbe27f2d4dd088690d28c4dd8495",
Cron = "0 0/1 * * * ?",
IsDisabled = false,
IsRunning = false,
@ -4491,7 +4491,7 @@ namespace Win.Sfs.SettleAccount.Migrations
new
{
Id = new Guid("b9b9c79f-4894-474b-4f67-b1ec121c41e5"),
ConcurrencyStamp = "dda70cc2fd7f4328be7860a550006ecb",
ConcurrencyStamp = "54a845290661424dbd6600f40a77ec27",
Cron = "0 0/30 * * * ? ",
IsDisabled = false,
IsRunning = false,
@ -4501,7 +4501,7 @@ namespace Win.Sfs.SettleAccount.Migrations
new
{
Id = new Guid("49b1da12-418c-544d-fe8b-be7e5b572452"),
ConcurrencyStamp = "7d49bd0d15124ee0b6de9f558fc9a429",
ConcurrencyStamp = "a641ae00f7db4b3cbf58dc098442c08b",
Cron = "0 0/30 * * * ? ",
IsDisabled = false,
IsRunning = false,
@ -4511,7 +4511,7 @@ namespace Win.Sfs.SettleAccount.Migrations
new
{
Id = new Guid("7a0dc087-a859-5863-eb6e-56f588bd779e"),
ConcurrencyStamp = "f65d6d2f92684535a920d7f3ed75699d",
ConcurrencyStamp = "610f376ade18446f87589b9b99b16c6a",
Cron = "0 0/30 * * * ? ",
IsDisabled = false,
IsRunning = false,
@ -4521,7 +4521,7 @@ namespace Win.Sfs.SettleAccount.Migrations
new
{
Id = new Guid("6f68fc8f-b058-c3f4-e07d-722c61f3f7fa"),
ConcurrencyStamp = "4aea58b425a34947869fba8e92ade9f2",
ConcurrencyStamp = "fc2fa51cd9124e2593e457241b79bc2b",
Cron = "0 0/30 * * * ? ",
IsDisabled = false,
IsRunning = false,
@ -4531,7 +4531,7 @@ namespace Win.Sfs.SettleAccount.Migrations
new
{
Id = new Guid("f306b380-47e5-5c01-b902-67ca4113a8f4"),
ConcurrencyStamp = "2f035dd2eca74570a85ae5276cc99e1c",
ConcurrencyStamp = "dcd7451cfe3d4472b8eca39f7e890038",
Cron = "0 0/30 * * * ? ",
IsDisabled = false,
IsRunning = false,
@ -4541,7 +4541,7 @@ namespace Win.Sfs.SettleAccount.Migrations
new
{
Id = new Guid("8f7dc23d-e2e9-3691-cfe9-545bb958e3f2"),
ConcurrencyStamp = "ec6c990fce2a4728a00c488c7757c172",
ConcurrencyStamp = "272db8024ec645dc837afb433687572f",
Cron = "0 0/30 * * * ? ",
IsDisabled = false,
IsRunning = false,
@ -4551,7 +4551,7 @@ namespace Win.Sfs.SettleAccount.Migrations
new
{
Id = new Guid("c1f71240-1b81-0107-8b23-ddc9811a3efe"),
ConcurrencyStamp = "afe6ab9a36024802ba83dd3e32de0ad4",
ConcurrencyStamp = "9072cbd6edd74b80821d92e9d98d8d61",
Cron = "0 0/30 * * * ? ",
IsDisabled = false,
IsRunning = false,
@ -4561,7 +4561,7 @@ namespace Win.Sfs.SettleAccount.Migrations
new
{
Id = new Guid("c09c23ea-815f-1b43-4476-2365a8d9a60b"),
ConcurrencyStamp = "5e50b42897c1455597888da08f8587de",
ConcurrencyStamp = "8c5c164e5abc471a97ec8dada4195a53",
Cron = "0 0/30 * * * ? ",
IsDisabled = false,
IsRunning = false,
@ -5331,6 +5331,9 @@ namespace Win.Sfs.SettleAccount.Migrations
.HasColumnType("nvarchar(max)")
.HasColumnName("ExtraProperties");
b.Property<bool>("IsCancel")
.HasColumnType("bit");
b.Property<string>("LU")
.HasColumnType("nvarchar(max)");
@ -5406,6 +5409,9 @@ namespace Win.Sfs.SettleAccount.Migrations
.HasColumnType("nvarchar(max)")
.HasColumnName("ExtraProperties");
b.Property<bool>("IsCancel")
.HasColumnType("bit");
b.Property<string>("LU")
.HasColumnType("nvarchar(max)");

Loading…
Cancel
Save