学 赵 1 year ago
parent
commit
b0ac96296a
  1. 4
      code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/Prices/PriceListDtoBase.cs
  2. 39
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_SA_SERVICE.cs
  3. 231
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/Prices/PriceListAppServiceBJ.cs

4
code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/Prices/PriceListDtoBase.cs

@ -148,13 +148,13 @@ public class PriceListImportDto
/// 开始时间
/// </summary>
[ImporterHeader(Name = "*Valid From")]
public string ValidFrom { get; set; }
public DateTime ValidFrom { get; set; }
/// <summary>
/// 结束时间
/// </summary>
[ImporterHeader(Name = "*Valid To")]
public string ValidTo { get; set; }
public DateTime ValidTo { get; set; }
/// <summary>
/// 客户编码

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

@ -1,17 +1,9 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.LinqAsync;
using System.Security.Policy;
using System.Threading.Tasks;
using AutoMapper;
using DocumentFormat.OpenXml.Drawing.Charts;
using DocumentFormat.OpenXml.Wordprocessing;
using EFCore.BulkExtensions;
using FlexLabs.EntityFrameworkCore.Upsert.Internal;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SettleAccount.Domain.BQ;
using Volo.Abp;
@ -162,7 +154,7 @@ public class BBAC_SA_SERVICE : SettleAccountApplicationBase<BBAC_SA>
//结算分组号
var bbacSaGroupNums = importBBACSaDetails.Select(t => t.GroupNum).Distinct();
//已存在的结算分组号
var havBBACSaGroupNums = (await _bbacSaDetailRepository.GetListAsync(t => bbacSaGroupNums.Contains(t.GroupNum))).Select(t => t.GroupNum).Distinct();
var havBBACSaGroupNums = (await _bbacSaDetailRepository.GetListAsync(t => bbacSaGroupNums.Contains(t.GroupNum)).ConfigureAwait(false)).Select(t => t.GroupNum).Distinct();
if (havBBACSaGroupNums.Any() == true)
{
foreach (var item in havBBACSaGroupNums)
@ -396,7 +388,7 @@ 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 materialRelationshipEntitys = await _materialRelationshipRepository.GetListAsync(t => importPubSaLUs.Contains(t.SettleMaterialCode));
var materialRelationshipEntitys = await _materialRelationshipRepository.GetListAsync(t => importPubSaLUs.Contains(t.SettleMaterialCode)).ConfigureAwait(false);
bbacSaDetails.ForEach(bbacSaDetail =>
{
//根据物料号、结算日期获取价格
@ -420,6 +412,19 @@ public class BBAC_SA_SERVICE : SettleAccountApplicationBase<BBAC_SA>
#region 添加入库
await _bbacSaRepository.InsertAsync(bbacSa).ConfigureAwait(false);
//存在买单将BBAC数据添加买单件BBAC主表数据
if (bbacSaDetails.Any(t => t.BusinessType == EnumBusinessType.MaiDanJianBBAC))
{
//买单件结算主表
await _bbacSaRepository.InsertAsync(new BBAC_SA()
{
BillNum = bbacSaBillNum,
State = "0",
BusinessType = EnumBusinessType.MaiDanJianBBAC,
Site = Site,
Version = Version
}).ConfigureAwait(false);
}
await _bbacSaDetailRepository.DbContext.BulkInsertAsync(bbacSaDetails).ConfigureAwait(false);
if (bbacCanSaDetails.Count > 0)
{
@ -443,7 +448,7 @@ public class BBAC_SA_SERVICE : SettleAccountApplicationBase<BBAC_SA>
}
if (materialRelationships.Count > 0)
{
await _materialRelationshipRepository.InsertManyAsync(materialRelationships);
await _materialRelationshipRepository.InsertManyAsync(materialRelationships).ConfigureAwait(false);
}
#endregion
}
@ -454,15 +459,15 @@ public class BBAC_SA_SERVICE : SettleAccountApplicationBase<BBAC_SA>
private async Task<(List<BBAC_SA> bbacSas, List<BBAC_SA_DETAIL> bbacSaDetails, List<BBAC_CAN_SA> bbacCanSas, List<BBAC_CAN_SA_DETAIL> bbacCanSaDetails, List<BBAC_NOT_SA_DETAIL> bbacNotSaDetails)> GetBBACSaDelItemsAsync(Guid id)
{
//结算主表
List<BBAC_SA> bbacSas = new List<BBAC_SA>();
var bbacSas = new List<BBAC_SA>();
//结算明细
List<BBAC_SA_DETAIL> bbacSaDetails = new List<BBAC_SA_DETAIL>();
var bbacSaDetails = new List<BBAC_SA_DETAIL>();
//可结算主表
List<BBAC_CAN_SA> bbacCanSas = new List<BBAC_CAN_SA>();
var bbacCanSas = new List<BBAC_CAN_SA>();
//可结算明细
List<BBAC_CAN_SA_DETAIL> bbacCanSaDetails = new List<BBAC_CAN_SA_DETAIL>();
var bbacCanSaDetails = new List<BBAC_CAN_SA_DETAIL>();
//不可结算
List<BBAC_NOT_SA_DETAIL> bbacNotSaDetails = new List<BBAC_NOT_SA_DETAIL>();
var bbacNotSaDetails = new List<BBAC_NOT_SA_DETAIL>();
var bbacSaEntity = await _bbacSaRepository.FindAsync(id).ConfigureAwait(false);
if (bbacSaEntity != null)
{
@ -476,7 +481,7 @@ public class BBAC_SA_SERVICE : SettleAccountApplicationBase<BBAC_SA>
throw new UserFriendlyException($"{bbacSaBillNum} 该单据可结算单状态无法删除!", "400");
}
bbacSas.Add(bbacSaEntity);
bbacSas = await _bbacSaRepository.GetListAsync(t => t.BillNum == bbacSaBillNum).ConfigureAwait(false);
bbacSaDetails = await _bbacSaDetailRepository.GetListAsync(t => t.BillNum == bbacSaBillNum).ConfigureAwait(false);
bbacCanSaDetails = await _bbacCanSaDetailRepository.GetListAsync(t => t.SettleBillNum == bbacSaBillNum).ConfigureAwait(false);
bbacNotSaDetails = await _bbacNotSaDetailRepository.GetListAsync(t => t.SettleBillNum == bbacSaBillNum).ConfigureAwait(false);

231
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;
/// <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
}

Loading…
Cancel
Save