Browse Source

PUB结算导入

master
mahao 1 year ago
parent
commit
6d8ab3b9a0
  1. 89
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PUB_SA_SERVICE.cs
  2. 5
      code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs

89
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PUB_SA_SERVICE.cs

@ -2,12 +2,14 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using NPOI.Util;
using NUglify.Helpers;
using SettleAccount.Bases;
using SettleAccount.Domain.BQ;
using Shouldly;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Application.Dtos;
@ -67,6 +69,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
public PUB_SA_SERVICE(INormalEfCoreRepository<PUB_SA, Guid> repository,
INormalEfCoreRepository<PUB_SA_DETAIL, Guid> pubSaDetailRepository,
INormalEfCoreRepository<PriceList, Guid> priceListRepository,
INormalEfCoreRepository<PUB_CAN_SA, Guid> pubCanSaRepository,
INormalEfCoreRepository<PUB_CAN_SA_DETAIL, Guid> pubCanSaDetailRepository,
INormalEfCoreRepository<PUB_NOT_SA_DETAIL, Guid> pubNotSaDetailRepository,
IDistributedCache<PUB_SA> cache,
IExcelImportAppService excelImportService,
ISnowflakeIdGenerator snowflakeIdGenerator,
@ -75,6 +80,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
{
_repository = repository;
_pubSaDetailRepository = pubSaDetailRepository;
_pubCanSaRepository = pubCanSaRepository;
_pubCanSaDetailRepository = pubCanSaDetailRepository;
_pubNotSaDetailRepository = pubNotSaDetailRepository;
_priceListRepository = priceListRepository;
}
@ -89,9 +97,14 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
[HttpPost]
public async Task<string> ZGJImportAsync([FromForm] IFormFileCollection files)
{
//类型(直供件)
EnumBusinessType businessType = EnumBusinessType.ZhiGongJian;
ExportImporter _exportImporter = new ExportImporter();
var result = await _exportImporter.UploadExcelImport<ZGJ_PUB_SA_DETAIL_IMPORT_DTO>(files, _excelImportService);
var _ls = ObjectMapper.Map<List<ZGJ_PUB_SA_DETAIL_IMPORT_DTO>, List<PUB_SA_DETAIL>>(result);
var importPubSaDetails = ObjectMapper.Map<List<ZGJ_PUB_SA_DETAIL_IMPORT_DTO>, List<PUB_SA_DETAIL>>(result);
//结算分组号
var pubSaGroupNums = importPubSaDetails.Select(t => t.GroupNum).Distinct();
//销售价格
var priceListEntitys = await _priceListRepository.GetAllAsync();
@ -103,63 +116,70 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
State = "1"
};
_ls.ForEach(s =>
importPubSaDetails.ForEach(importPubSaDetail =>
{
if (s.LU != null)
List<string> luList = importPubSaDetail.LU.Split(" ").ToList();
if (luList.Count > 1)
{
List<string> luList = s.LU.Split(" ").ToList();
s.LU = luList[0].Replace(" ", "");
if (luList.Count > 1)
{
luList.RemoveAt(0);
luList.Reverse();
var luAssemble = luList.Select(t => t.Replace(" ", ""));
s.LU += luAssemble.Aggregate(" ", (current, index) => current + index);
}
importPubSaDetail.LU = luList[0].Replace(" ", "");
luList.RemoveAt(0);
var luAssemble = luList.Select(t => t.Replace(" ", ""));
importPubSaDetail.LU += luAssemble.Aggregate(" ", (current, index) => current + index);
}
s.LU = s.LU;
s.BillNum = pubSaBillNum;
s.Site = "XX工厂";
s.KeyCode = s.LU + s.PN;
importPubSaDetail.BillNum = pubSaBillNum;
importPubSaDetail.Site = "XX工厂";
importPubSaDetail.KeyCode = importPubSaDetail.PN + importPubSaDetail.LU;
//根据物料号、结算日期获取价格
var priceListEntity = priceListEntitys.Find(t => t.LU == s.LU && s.SettleDate > t.BeginTime && s.SettleDate < t.EndTime);
s.Price = priceListEntity?.Price ?? 0;
var priceListEntity = priceListEntitys.Find(t => t.LU == importPubSaDetail.LU && importPubSaDetail.SettleDate > t.BeginTime && importPubSaDetail.SettleDate < t.EndTime);
importPubSaDetail.Price = priceListEntity?.Price ?? 0;
});
//可结算
var pubCanSaBillNum = OrderNumberGenerator.GenerateOrderNumber("INV");
var pubCanSaBillNum = OrderNumberGenerator.GenerateOrderNumber("C");
var pubCanSa = new PUB_CAN_SA()
{
BillNum = pubCanSaBillNum,
SettleBillNum = pubSaBillNum,
State = SettleBillState.,
BusinessType = EnumBusinessType.ZhiGongJian
BusinessType = businessType
};
//不可结算 结算分组号码(根据价格区分结算、不可结算)
var pubNotSaGroupNum = _ls.FindAll(t => t.Price != 0).Select(t => t.GroupNum).Distinct();
var pubSaDetailsCanSe = _ls.FindAll(t => pubNotSaGroupNum.Contains(t.GroupNum) == false);
var pubSaDetailsNotCanSe = _ls.FindAll(t => pubNotSaGroupNum.Contains(t.GroupNum) == true);
var pubNotSaGroupNums = importPubSaDetails.FindAll(t => t.Price == default(decimal)).Select(t => t.GroupNum).Distinct();
var pubSaDetailsCanSes = importPubSaDetails.FindAll(t => pubNotSaGroupNums.Contains(t.GroupNum) == false);
var pubSaDetailsNotCanSes = importPubSaDetails.FindAll(t => pubNotSaGroupNums.Contains(t.GroupNum) == true);
//可结算
var pubCanSaDetails = ObjectMapper.Map<List<PUB_SA_DETAIL>, List<PUB_CAN_SA_DETAIL>>(pubSaDetailsCanSe);
var pubCanSaDetails = ObjectMapper.Map<List<PUB_SA_DETAIL>, List<PUB_CAN_SA_DETAIL>>(pubSaDetailsCanSes);
//不可结算
var pubNotSaDetails = ObjectMapper.Map<List<PUB_SA_DETAIL>, List<PUB_NOT_SA_DETAIL>>(pubSaDetailsNotCanSe);
var pubNotSaDetails = ObjectMapper.Map<List<PUB_SA_DETAIL>, List<PUB_NOT_SA_DETAIL>>(pubSaDetailsNotCanSes);
//添加入库
await _repository.InsertAsync(pubSa);
await _pubSaDetailRepository.InsertManyAsync(_ls);
await _pubSaDetailRepository.InsertManyAsync(importPubSaDetails);
if (pubCanSaDetails.Count > 0)
{
pubCanSa.InvGroupNum = pubCanSaDetails.Count.ToString();
pubCanSaDetails.ForEach(pubCanSaDetail =>
{
pubCanSaDetail.BillNum = pubCanSaDetail.InvGroupNum = pubCanSaBillNum;
pubCanSaDetail.BusinessType = businessType;
});
await _pubCanSaRepository.InsertAsync(pubCanSa);
await _pubCanSaDetailRepository.InsertManyAsync(pubCanSaDetails);
}
if (pubNotSaDetails.Count > 0)
{
pubNotSaDetails.ForEach(pubNotSaDetail =>
{
pubNotSaDetail.InvGroupNum = pubCanSaBillNum;
pubNotSaDetail.BusinessType = businessType;
});
await _pubNotSaDetailRepository.InsertManyAsync(pubNotSaDetails);
}
return ApplicationConsts.SuccessStr;
@ -206,30 +226,31 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
//结算主表
PUB_SA pubSaDelEntity;
//结算明细
IEnumerable<PUB_SA_DETAIL> pubSaDetailDelEntitys = default;
List<PUB_SA_DETAIL> pubSaDetailDelEntitys;
//可结算主表
IEnumerable<PUB_CAN_SA> pubCanSaDelEntitys = default;
List<PUB_CAN_SA> pubCanSaDelEntitys;
//可结算明细
IEnumerable<PUB_CAN_SA_DETAIL> pubCanSaDetailDelEntitys = default;
List<PUB_CAN_SA_DETAIL> pubCanSaDetailDelEntitys;
//不可结算
IEnumerable<PUB_NOT_SA_DETAIL> pubNotSaDetailDelEntitys = default;
List<PUB_NOT_SA_DETAIL> pubNotSaDetailDelEntitys;
pubSaDelEntity = await _repository.FindAsync(id);
if (pubSaDelEntity != null) return;
if (pubSaDelEntity == null) return;
//结算单据
string pubSaBillNum = pubSaDelEntity.BillNum;
pubCanSaDelEntitys = _pubCanSaRepository.Where(t => t.SettleBillNum == pubSaBillNum);
pubCanSaDelEntitys = await _pubCanSaRepository.GetListAsync(t => t.SettleBillNum == pubSaBillNum);
//验证可结算主表状态
if (pubCanSaDelEntitys.Any(t => t.State != SettleBillState.))
{
throw new UserFriendlyException($"该单据可结算单状态无法删除!");
}
pubCanSaDetailDelEntitys = _pubCanSaDetailRepository.Where(t => t.SettleBillNum == pubSaBillNum);
pubNotSaDetailDelEntitys = _pubNotSaDetailRepository.Where(t => t.SettleBillNum == pubSaBillNum);
pubSaDetailDelEntitys = await _pubSaDetailRepository.GetListAsync(t => t.BillNum == pubSaBillNum);
pubCanSaDetailDelEntitys = await _pubCanSaDetailRepository.GetListAsync(t => t.SettleBillNum == pubSaBillNum);
pubNotSaDetailDelEntitys = await _pubNotSaDetailRepository.GetListAsync(t => t.SettleBillNum == pubSaBillNum);
//删除
await _repository.DeleteAsync(pubSaDelEntity);

5
code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs

@ -820,6 +820,11 @@ namespace Win.Sfs.SettleAccount
{
CreateMap<PUB_SA, PUB_SA_DTO>();
CreateMap<PUB_SA_DETAIL, PUB_CAN_SA_DETAIL>()
.ForMember(x => x.SettleBillNum, y => y.MapFrom(d => d.BillNum));
CreateMap<PUB_SA_DETAIL, PUB_NOT_SA_DETAIL>()
.ForMember(x => x.SettleBillNum, y => y.MapFrom(d => d.BillNum));
CreateMap<ZGJ_PUB_SA_DETAIL_IMPORT_DTO, PUB_SA_DETAIL>();
}

Loading…
Cancel
Save