diff --git a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/Prices/PriceListAppServiceBJ.cs b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/Prices/PriceListAppServiceBJ.cs
index dd6e30ad..5f02b23f 100644
--- a/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/Prices/PriceListAppServiceBJ.cs
+++ b/code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/Prices/PriceListAppServiceBJ.cs
@@ -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;
+
+///
+/// 备件价格
+///
+[AllowAnonymous]
+[Route("api/settleaccount/[controller]/[action]")]
+public class PriceListAppServiceBJ : SettleAccountApplicationBase
{
+ private readonly INormalEfCoreRepository _repository;
+
+ public PriceListAppServiceBJ(
+ INormalEfCoreRepository repository,
+ IDistributedCache cache,
+ IExcelImportAppService excelImportService,
+ ISnowflakeIdGenerator snowflakeIdGenerator,
+ ICommonManager commonManager
+ ) : base(cache, excelImportService, snowflakeIdGenerator, commonManager)
+ {
+ _repository = repository;
+ }
+
+ #region 导入、导出
///
- /// 备件价格
+ /// 导入
///
- [AllowAnonymous]
- [Route("api/settleaccount/[controller]/[action]")]
- public class PriceListAppServiceBJ : SettleAccountApplicationBase
+ [HttpPost]
+ public async Task ImportAsync([FromForm] IFormFileCollection files, string version)
{
- private readonly INormalEfCoreRepository _repository;
+ var checkList = new List();
+ ExportImporter _exportImporter = new ExportImporter();
+ var result = await _exportImporter.UploadExcelImportByHeadDesc(files, _excelImportService).ConfigureAwait(false);
+ List _checkls = new List();
+ _checkls.Add("1040");
+ _checkls.Add("1046");
+ _checkls.Add("104T");
+ result = result.Where(p => _checkls.Contains(p.ClientCode)).ToList();
- public PriceListAppServiceBJ(
- INormalEfCoreRepository repository,
- IDistributedCache cache,
- IExcelImportAppService excelImportService,
- ISnowflakeIdGenerator snowflakeIdGenerator,
- ICommonManager commonManager
- ) : base(cache, excelImportService, snowflakeIdGenerator, commonManager)
- {
- _repository = repository;
- }
+ var entityList = ObjectMapper.Map, List>(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 导入、导出
- ///
- /// 导入
- ///
- [HttpPost]
- public async Task ImportAsync([FromForm] IFormFileCollection files, string version)
+ #region 校验
+ if (entityList.Any())
{
- var checkList = new List();
- ExportImporter _exportImporter = new ExportImporter();
- var result = await _exportImporter.UploadExcelImportByHeadDesc(files, _excelImportService).ConfigureAwait(false);
- List _checkls = new List();
- _checkls.Add("1040");
- _checkls.Add("1046");
- _checkls.Add("104T");
- result = result.Where(p => _checkls.Contains(p.ClientCode)).ToList();
-
- var entityList = ObjectMapper.Map, List>(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 = "导入成功" });
}
-
- ///
- /// 导出
- ///
- [HttpPost]
- public async Task 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>(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
- ///
- /// 获取列表
- ///
- [HttpPost]
- public async Task> 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>(entities);
- return new PagedResultDto(totalCount, dtos);
+ item.Update(GuidGenerator.Create());
}
- #endregion
+ await _repository.InsertManyAsync(entityList).ConfigureAwait(false);
+ return new JsonResult(new { Code = 200, Message = "导入成功" });
+ }
+
+ ///
+ /// 导出
+ ///
+ [HttpPost]
+ public async Task 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>(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
+ ///
+ /// 获取列表
+ ///
+ [HttpPost]
+ public async Task> 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>(entities);
+ return new PagedResultDto(totalCount, dtos);
}
+ #endregion
}