|
@ -2,6 +2,7 @@ using System; |
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
|
using System.Linq; |
|
|
using System.Linq; |
|
|
using System.Threading.Tasks; |
|
|
using System.Threading.Tasks; |
|
|
|
|
|
using EFCore.BulkExtensions; |
|
|
using Magicodes.ExporterAndImporter.Core; |
|
|
using Magicodes.ExporterAndImporter.Core; |
|
|
using Magicodes.ExporterAndImporter.Excel; |
|
|
using Magicodes.ExporterAndImporter.Excel; |
|
|
using Microsoft.AspNetCore.Authorization; |
|
|
using Microsoft.AspNetCore.Authorization; |
|
@ -14,8 +15,6 @@ using Win.Abp.Snowflakes; |
|
|
using Win.Sfs.BaseData.ImportExcelCommon; |
|
|
using Win.Sfs.BaseData.ImportExcelCommon; |
|
|
using Win.Sfs.SettleAccount.CommonManagers; |
|
|
using Win.Sfs.SettleAccount.CommonManagers; |
|
|
using Win.Sfs.SettleAccount.Entities.BQ.Dtos; |
|
|
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.ExcelImporter; |
|
|
using Win.Sfs.SettleAccount.ExportReports; |
|
|
using Win.Sfs.SettleAccount.ExportReports; |
|
|
using Win.Sfs.Shared.RepositoryBase; |
|
|
using Win.Sfs.Shared.RepositoryBase; |
|
@ -29,26 +28,26 @@ namespace Win.Sfs.SettleAccount.Entities.Prices; |
|
|
[Route("api/settleaccount/[controller]/[action]")]
|
|
|
[Route("api/settleaccount/[controller]/[action]")]
|
|
|
public class PriceListAppService : SettleAccountApplicationBase<PriceList> |
|
|
public class PriceListAppService : SettleAccountApplicationBase<PriceList> |
|
|
{ |
|
|
{ |
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 数据上下文
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private readonly SettleAccountDbContext _settleAccountDbContext; |
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// 销售价格仓储
|
|
|
/// 销售价格仓储
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
private readonly INormalEfCoreRepository<PriceList, Guid> _priceListRepository; |
|
|
private readonly INormalEfCoreRepository<PriceList, Guid> _priceListRepository; |
|
|
|
|
|
|
|
|
private readonly ISettleAccountBranchEfCoreRepository<ImportColumnMap, Guid> _mapRepository; |
|
|
|
|
|
private readonly TaskJobService _service; |
|
|
|
|
|
public PriceListAppService( |
|
|
public PriceListAppService( |
|
|
|
|
|
SettleAccountDbContext settleAccountDbContext, |
|
|
INormalEfCoreRepository<PriceList, Guid> priceListRepository, |
|
|
INormalEfCoreRepository<PriceList, Guid> priceListRepository, |
|
|
ISettleAccountBranchEfCoreRepository<ImportColumnMap, Guid> mapRepository, |
|
|
|
|
|
TaskJobService service, |
|
|
|
|
|
IDistributedCache<PriceList> cache, |
|
|
IDistributedCache<PriceList> cache, |
|
|
IExcelImportAppService excelImportService, |
|
|
IExcelImportAppService excelImportService, |
|
|
ISnowflakeIdGenerator snowflakeIdGenerator, |
|
|
ISnowflakeIdGenerator snowflakeIdGenerator, |
|
|
ICommonManager commonManager |
|
|
ICommonManager commonManager |
|
|
) : base(cache, excelImportService, snowflakeIdGenerator, commonManager) |
|
|
) : base(cache, excelImportService, snowflakeIdGenerator, commonManager) |
|
|
{ |
|
|
{ |
|
|
|
|
|
_settleAccountDbContext = settleAccountDbContext; |
|
|
_priceListRepository = priceListRepository; |
|
|
_priceListRepository = priceListRepository; |
|
|
_mapRepository = mapRepository; |
|
|
|
|
|
_service = service; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#region 导入、导出
|
|
|
#region 导入、导出
|
|
@ -69,22 +68,52 @@ public class PriceListAppService : SettleAccountApplicationBase<PriceList> |
|
|
public virtual async Task<IActionResult> ImportAsync([FromForm] IFormFileCollection files, string version) |
|
|
public virtual async Task<IActionResult> ImportAsync([FromForm] IFormFileCollection files, string version) |
|
|
{ |
|
|
{ |
|
|
var checkList = new List<ErrorExportDto>(); |
|
|
var checkList = new List<ErrorExportDto>(); |
|
|
ExportImporter _exportImporter = new ExportImporter(); |
|
|
var _exportImporter = new ExportImporter(); |
|
|
var result = await _exportImporter.UploadExcelImportByHeadDesc<PriceListImportDto>(files, _excelImportService).ConfigureAwait(false); |
|
|
var result = await _exportImporter.UploadExcelImportByHeadDesc<PriceListImportDto>(files, _excelImportService).ConfigureAwait(false); |
|
|
List<string> _checkls = new List<string>(); |
|
|
var filter = new List<string> |
|
|
_checkls.Add("1040"); |
|
|
{ |
|
|
_checkls.Add("1046"); |
|
|
"1040", |
|
|
_checkls.Add("104T"); |
|
|
"1046", |
|
|
result = result.Where(p => _checkls.Contains(p.Plant)).ToList(); |
|
|
"104T" |
|
|
result.Where(t => !string.IsNullOrEmpty(t.ES1) || !string.IsNullOrEmpty(t.ES2)).ForEach(t => t.PartNo = t.PartNo + new string(' ', 6) + t.ES1 + t.ES2); |
|
|
}; |
|
|
|
|
|
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); |
|
|
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()); |
|
|
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 = "导入成功" }); |
|
|
return new JsonResult(new { Code = 200, Message = "导入成功" }); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|