|
|
@ -1,15 +1,13 @@ |
|
|
|
using Microsoft.AspNetCore.Authorization; |
|
|
|
using Microsoft.AspNetCore.Http; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Shouldly; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Diagnostics.Contracts; |
|
|
|
using System.Linq; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Microsoft.AspNetCore.Authorization; |
|
|
|
using Microsoft.AspNetCore.Http; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Shouldly; |
|
|
|
using Volo.Abp.Application.Dtos; |
|
|
|
using Volo.Abp.Caching; |
|
|
|
using Volo.Abp.Domain.Repositories; |
|
|
|
using Win.Abp.Snowflakes; |
|
|
|
using Win.Sfs.BaseData.ImportExcelCommon; |
|
|
|
using Win.Sfs.SettleAccount.CommonManagers; |
|
|
@ -19,136 +17,135 @@ using Win.Sfs.SettleAccount.ExcelImporter; |
|
|
|
using Win.Sfs.SettleAccount.ExportReports; |
|
|
|
using Win.Sfs.Shared.RepositoryBase; |
|
|
|
|
|
|
|
namespace Win.Sfs.SettleAccount.Entities.Prices |
|
|
|
namespace Win.Sfs.SettleAccount.Entities.Prices; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 备件价格
|
|
|
|
/// </summary>
|
|
|
|
[AllowAnonymous] |
|
|
|
[Route("api/settleaccount/[controller]/[action]")]
|
|
|
|
public class PriceListAppServiceBJ : SettleAccountApplicationBase<PriceListBJ> |
|
|
|
{ |
|
|
|
private readonly INormalEfCoreRepository<PriceListBJ, Guid> _repository; |
|
|
|
|
|
|
|
public PriceListAppServiceBJ( |
|
|
|
INormalEfCoreRepository<PriceListBJ, Guid> repository, |
|
|
|
IDistributedCache<PriceListBJ> cache, |
|
|
|
IExcelImportAppService excelImportService, |
|
|
|
ISnowflakeIdGenerator snowflakeIdGenerator, |
|
|
|
ICommonManager commonManager |
|
|
|
) : base(cache, excelImportService, snowflakeIdGenerator, commonManager) |
|
|
|
{ |
|
|
|
_repository = repository; |
|
|
|
} |
|
|
|
|
|
|
|
#region 导入、导出
|
|
|
|
/// <summary>
|
|
|
|
/// 备件价格
|
|
|
|
/// 导入
|
|
|
|
/// </summary>
|
|
|
|
[AllowAnonymous] |
|
|
|
[Route("api/settleaccount/[controller]/[action]")]
|
|
|
|
public class PriceListAppServiceBJ : SettleAccountApplicationBase<PriceListBJ> |
|
|
|
[HttpPost] |
|
|
|
public async Task<IActionResult> ImportAsync([FromForm] IFormFileCollection files, string version) |
|
|
|
{ |
|
|
|
private readonly INormalEfCoreRepository<PriceListBJ, Guid> _repository; |
|
|
|
var checkList = new List<ErrorExportDto>(); |
|
|
|
ExportImporter _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(); |
|
|
|
|
|
|
|
public PriceListAppServiceBJ( |
|
|
|
INormalEfCoreRepository<PriceListBJ, Guid> repository, |
|
|
|
IDistributedCache<PriceListBJ> cache, |
|
|
|
IExcelImportAppService excelImportService, |
|
|
|
ISnowflakeIdGenerator snowflakeIdGenerator, |
|
|
|
ICommonManager commonManager |
|
|
|
) : base(cache, excelImportService, snowflakeIdGenerator, commonManager) |
|
|
|
{ |
|
|
|
_repository = repository; |
|
|
|
} |
|
|
|
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 contractNo = entityList.FirstOrDefault().ContractNo; |
|
|
|
|
|
|
|
#region 导入、导出
|
|
|
|
/// <summary>
|
|
|
|
/// 导入
|
|
|
|
/// </summary>
|
|
|
|
[HttpPost] |
|
|
|
public async Task<IActionResult> ImportAsync([FromForm] IFormFileCollection files, string version) |
|
|
|
#region 校验
|
|
|
|
if (entityList.Any()) |
|
|
|
{ |
|
|
|
var checkList = new List<ErrorExportDto>(); |
|
|
|
ExportImporter _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 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 contractNo = entityList.FirstOrDefault().ContractNo; |
|
|
|
|
|
|
|
#region 校验
|
|
|
|
if (entityList.Any()) |
|
|
|
{ |
|
|
|
var query = from item1 in entityList |
|
|
|
join item2 in entityList |
|
|
|
on new { item1.LU } equals new { item2.LU } |
|
|
|
where (item1.BeginDate > item2.BeginDate && item1.EndDate < item2.EndDate) || (item2.BeginDate > item1.BeginDate && item2.EndDate < item1.EndDate) || (item1.BeginDate == item2.BeginDate && item1.EndDate != item2.EndDate) || (item1.BeginDate != item2.BeginDate && item1.EndDate == item2.EndDate) |
|
|
|
select item1.LU; |
|
|
|
var repeat = query.Distinct().ToList(); |
|
|
|
foreach (var item in query) |
|
|
|
{ |
|
|
|
checkList.Add(new ErrorExportDto(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, $"导入文件中物料号:{item},时间区间存在交集", string.Empty)); |
|
|
|
} |
|
|
|
} |
|
|
|
if (checkList.Count > 0) |
|
|
|
{ |
|
|
|
string fileName = await ExportErrorReportAsync(checkList).ConfigureAwait(false); |
|
|
|
return new JsonResult(new { code = ApplicationConsts.ImportFailCode, message = "导入失败", fileName = fileName }); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
var lus = entityList.Select(p => p.LU); |
|
|
|
|
|
|
|
var prices = _repository.Where(t => lus.Contains(t.LU) && t.ContractNo != contractNo).ToList(); |
|
|
|
if (prices.Any()) |
|
|
|
{ |
|
|
|
var query = from item1 in entityList |
|
|
|
join item2 in prices |
|
|
|
on new { item1.LU } equals new { item2.LU } |
|
|
|
where (item1.BeginDate >= item2.BeginDate && item1.EndDate <= item2.EndDate) || (item2.BeginDate >= item1.BeginDate && item2.EndDate <= item1.EndDate) |
|
|
|
select item1.LU; |
|
|
|
var repeat = query.Distinct().ToList(); |
|
|
|
foreach (var item in repeat) |
|
|
|
{ |
|
|
|
checkList.Add(new ErrorExportDto(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, $"导入文件中物料号:{item},时间区间与系统内数据存在交集", string.Empty)); |
|
|
|
} |
|
|
|
} |
|
|
|
if (checkList.Count > 0) |
|
|
|
{ |
|
|
|
string fileName = await ExportErrorReportAsync(checkList).ConfigureAwait(false); |
|
|
|
return new JsonResult(new { code = ApplicationConsts.ImportFailCode, message = "导入失败", fileName = fileName }); |
|
|
|
} |
|
|
|
|
|
|
|
var priceListModelEntitys = _repository.Where(t => t.ContractNo == contractNo && lus.Contains(t.LU)).ToList(); |
|
|
|
if (priceListModelEntitys.Any()) |
|
|
|
var query = from item1 in entityList |
|
|
|
join item2 in entityList |
|
|
|
on new { item1.LU } equals new { item2.LU } |
|
|
|
where (item1.BeginDate > item2.BeginDate && item1.EndDate < item2.EndDate) || (item2.BeginDate > item1.BeginDate && item2.EndDate < item1.EndDate) || (item1.BeginDate == item2.BeginDate && item1.EndDate != item2.EndDate) || (item1.BeginDate != item2.BeginDate && item1.EndDate == item2.EndDate) |
|
|
|
select item1.LU; |
|
|
|
var repeat = query.Distinct().ToList(); |
|
|
|
foreach (var item in query) |
|
|
|
{ |
|
|
|
await _repository.DeleteManyAsync(priceListModelEntitys).ConfigureAwait(false); |
|
|
|
checkList.Add(new ErrorExportDto(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, $"导入文件中物料号:{item},时间区间存在交集", string.Empty)); |
|
|
|
} |
|
|
|
} |
|
|
|
if (checkList.Count > 0) |
|
|
|
{ |
|
|
|
string fileName = await ExportErrorReportAsync(checkList).ConfigureAwait(false); |
|
|
|
return new JsonResult(new { code = ApplicationConsts.ImportFailCode, message = "导入失败", fileName = fileName }); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
var lus = entityList.Select(p => p.LU); |
|
|
|
|
|
|
|
foreach (var item in entityList) |
|
|
|
var prices = _repository.Where(t => lus.Contains(t.LU) && t.ContractNo != contractNo).ToList(); |
|
|
|
if (prices.Any()) |
|
|
|
{ |
|
|
|
var query = from item1 in entityList |
|
|
|
join item2 in prices |
|
|
|
on new { item1.LU } equals new { item2.LU } |
|
|
|
where (item1.BeginDate >= item2.BeginDate && item1.EndDate <= item2.EndDate) || (item2.BeginDate >= item1.BeginDate && item2.EndDate <= item1.EndDate) |
|
|
|
select item1.LU; |
|
|
|
var repeat = query.Distinct().ToList(); |
|
|
|
foreach (var item in repeat) |
|
|
|
{ |
|
|
|
item.Update(GuidGenerator.Create()); |
|
|
|
checkList.Add(new ErrorExportDto(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, $"导入文件中物料号:{item},时间区间与系统内数据存在交集", string.Empty)); |
|
|
|
} |
|
|
|
await _repository.InsertManyAsync(entityList).ConfigureAwait(false); |
|
|
|
return new JsonResult(new { Code = 200, Message = "导入成功" }); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 导出
|
|
|
|
/// </summary>
|
|
|
|
[HttpPost] |
|
|
|
public async Task<string> ExportAsync(RequestDto input) |
|
|
|
if (checkList.Count > 0) |
|
|
|
{ |
|
|
|
string fileName = $"备件价格_{Guid.NewGuid()}.xlsx"; |
|
|
|
var entities = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, 0, true); |
|
|
|
var dtos = ObjectMapper.Map<List<PriceListBJ>, List<PriceListBJExportDto>>(entities); |
|
|
|
|
|
|
|
ExportImporter _exportImporter = new ExportImporter(); |
|
|
|
var result = await _exportImporter.ExcelExporter(dtos); |
|
|
|
result.ShouldNotBeNull(); |
|
|
|
string fileName = await ExportErrorReportAsync(checkList).ConfigureAwait(false); |
|
|
|
return new JsonResult(new { code = ApplicationConsts.ImportFailCode, message = "导入失败", fileName = fileName }); |
|
|
|
} |
|
|
|
|
|
|
|
await _excelImportService.SaveBlobAsync(new SaveExcelImportInputDto { Name = fileName, Content = result }); |
|
|
|
return fileName; |
|
|
|
var priceListModelEntitys = _repository.Where(t => t.ContractNo == contractNo && lus.Contains(t.LU)).ToList(); |
|
|
|
if (priceListModelEntitys.Any()) |
|
|
|
{ |
|
|
|
await _repository.DeleteManyAsync(priceListModelEntitys).ConfigureAwait(false); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region CURD
|
|
|
|
/// <summary>
|
|
|
|
/// 获取列表
|
|
|
|
/// </summary>
|
|
|
|
[HttpPost] |
|
|
|
public async Task<PagedResultDto<PriceListBJDto>> GetListAsync(RequestDto input) |
|
|
|
foreach (var item in entityList) |
|
|
|
{ |
|
|
|
var entities = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, input.MaxResultCount, input.SkipCount, true).ConfigureAwait(false); |
|
|
|
var totalCount = await _repository.GetCountByFilterAsync(input.Filters).ConfigureAwait(false); |
|
|
|
var dtos = ObjectMapper.Map<List<PriceListBJ>, List<PriceListBJDto>>(entities); |
|
|
|
return new PagedResultDto<PriceListBJDto>(totalCount, dtos); |
|
|
|
item.Update(GuidGenerator.Create()); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
await _repository.InsertManyAsync(entityList).ConfigureAwait(false); |
|
|
|
return new JsonResult(new { Code = 200, Message = "导入成功" }); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 导出
|
|
|
|
/// </summary>
|
|
|
|
[HttpPost] |
|
|
|
public async Task<string> ExportAsync(RequestDto input) |
|
|
|
{ |
|
|
|
string fileName = $"备件价格_{Guid.NewGuid()}.xlsx"; |
|
|
|
var entities = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, int.MaxValue, 0, true); |
|
|
|
var dtos = ObjectMapper.Map<List<PriceListBJ>, List<PriceListBJExportDto>>(entities); |
|
|
|
|
|
|
|
ExportImporter _exportImporter = new ExportImporter(); |
|
|
|
var result = await _exportImporter.ExcelExporter(dtos); |
|
|
|
result.ShouldNotBeNull(); |
|
|
|
|
|
|
|
await _excelImportService.SaveBlobAsync(new SaveExcelImportInputDto { Name = fileName, Content = result }); |
|
|
|
return fileName; |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region CURD
|
|
|
|
/// <summary>
|
|
|
|
/// 获取列表
|
|
|
|
/// </summary>
|
|
|
|
[HttpPost] |
|
|
|
public async Task<PagedResultDto<PriceListBJDto>> GetListAsync(RequestDto input) |
|
|
|
{ |
|
|
|
var entities = await _repository.GetListByFilterAsync(input.Filters, input.Sorting, input.MaxResultCount, input.SkipCount, true).ConfigureAwait(false); |
|
|
|
var totalCount = await _repository.GetCountByFilterAsync(input.Filters).ConfigureAwait(false); |
|
|
|
var dtos = ObjectMapper.Map<List<PriceListBJ>, List<PriceListBJDto>>(entities); |
|
|
|
return new PagedResultDto<PriceListBJDto>(totalCount, dtos); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
} |
|
|
|
|
|
|
|