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

Loading…
Cancel
Save