|
@ -1,8 +1,10 @@ |
|
|
using System; |
|
|
using System; |
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
|
|
|
|
using System.Globalization; |
|
|
using System.Linq; |
|
|
using System.Linq; |
|
|
using System.Linq.Dynamic.Core; |
|
|
using System.Linq.Dynamic.Core; |
|
|
using System.Threading.Tasks; |
|
|
using System.Threading.Tasks; |
|
|
|
|
|
using Magicodes.ExporterAndImporter.Core.Models; |
|
|
using Microsoft.AspNetCore.Authorization; |
|
|
using Microsoft.AspNetCore.Authorization; |
|
|
using Microsoft.AspNetCore.Http; |
|
|
using Microsoft.AspNetCore.Http; |
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
using Microsoft.AspNetCore.Mvc; |
|
@ -107,7 +109,36 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase<PUB_SA> |
|
|
[HttpPost] |
|
|
[HttpPost] |
|
|
public async Task<string> ImportByBusinessTypeAsync([FromForm] PUB_SAImportRequestDto pubSaImportRequestDto) |
|
|
public async Task<string> ImportByBusinessTypeAsync([FromForm] PUB_SAImportRequestDto pubSaImportRequestDto) |
|
|
{ |
|
|
{ |
|
|
return await ImportAsync(pubSaImportRequestDto.Files, pubSaImportRequestDto.BusinessType); |
|
|
string result = string.Empty; |
|
|
|
|
|
//return await ImportAsync(pubSaImportRequestDto.Files, pubSaImportRequestDto.BusinessType);
|
|
|
|
|
|
switch (pubSaImportRequestDto.BusinessType) |
|
|
|
|
|
{ |
|
|
|
|
|
case EnumBusinessType.None: |
|
|
|
|
|
break; |
|
|
|
|
|
case EnumBusinessType.JisBBAC: |
|
|
|
|
|
break; |
|
|
|
|
|
case EnumBusinessType.JisHBPO: |
|
|
|
|
|
break; |
|
|
|
|
|
case EnumBusinessType.ZhiGongJianBBAC: |
|
|
|
|
|
result = await ImportZhiGongJianBBACAsync(pubSaImportRequestDto.Files); |
|
|
|
|
|
break; |
|
|
|
|
|
case EnumBusinessType.ZhiGongJianHBPO: |
|
|
|
|
|
result = await ImportZhiGongJianHBPOAsync(pubSaImportRequestDto.Files); |
|
|
|
|
|
break; |
|
|
|
|
|
case EnumBusinessType.MaiDanJianBBAC: |
|
|
|
|
|
break; |
|
|
|
|
|
case EnumBusinessType.MaiDanJianHBPO: |
|
|
|
|
|
break; |
|
|
|
|
|
case EnumBusinessType.BeiJian: |
|
|
|
|
|
result = await ImportBeiJianAsync(pubSaImportRequestDto.Files); |
|
|
|
|
|
break; |
|
|
|
|
|
case EnumBusinessType.YinDuJian: |
|
|
|
|
|
result = await ImportYinDuJianAsync(pubSaImportRequestDto.Files); |
|
|
|
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
return result; |
|
|
} |
|
|
} |
|
|
#endregion
|
|
|
#endregion
|
|
|
|
|
|
|
|
@ -242,6 +273,7 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase<PUB_SA> |
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// 导入
|
|
|
/// 导入
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
|
|
|
[Obsolete(message: "过时废弃")] |
|
|
private async Task<string> ImportAsync([FromForm] IFormFileCollection files, EnumBusinessType businessType) |
|
|
private async Task<string> ImportAsync([FromForm] IFormFileCollection files, EnumBusinessType businessType) |
|
|
{ |
|
|
{ |
|
|
//数据校验
|
|
|
//数据校验
|
|
@ -393,6 +425,262 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase<PUB_SA> |
|
|
return ApplicationConsts.SuccessStr; |
|
|
return ApplicationConsts.SuccessStr; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 直供件BBAC导入
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private async Task<string> ImportZhiGongJianBBACAsync([FromForm] IFormFileCollection files) |
|
|
|
|
|
{ |
|
|
|
|
|
#region 导入数据转换
|
|
|
|
|
|
ExportImporter _exportImporter = new ExportImporter(); |
|
|
|
|
|
var importResults = await _exportImporter.UploadExcelImport<ZhiGongJianBBACImportDto>(files, _excelImportService); |
|
|
|
|
|
var importPubSaDetails = ObjectMapper.Map<List<ZhiGongJianBBACImportDto>, List<PUB_SA_DETAIL>>(importResults); |
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 数据校验
|
|
|
|
|
|
var checkList = await CheckAsync(importPubSaDetails); |
|
|
|
|
|
if (checkList.Count > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
return await ExportErrorReportAsync(checkList); |
|
|
|
|
|
} |
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
return await SaDataHandleAsync(importPubSaDetails, EnumBusinessType.ZhiGongJianBBAC); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 直供件HBPO导入
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private async Task<string> ImportZhiGongJianHBPOAsync([FromForm] IFormFileCollection files) |
|
|
|
|
|
{ |
|
|
|
|
|
#region 导入数据转换
|
|
|
|
|
|
ExportImporter _exportImporter = new ExportImporter(); |
|
|
|
|
|
var importResults = await _exportImporter.UploadExcelImport<ZhiGongJianHBPOImportDto>(files, _excelImportService); |
|
|
|
|
|
|
|
|
|
|
|
//截取结算分组前8位为结算日期
|
|
|
|
|
|
importResults.ForEach(importResult => |
|
|
|
|
|
{ |
|
|
|
|
|
importResult.SettleDate = DateTime.ParseExact(importResult.GroupNum.Substring(0, 8), "yyyyMMdd", CultureInfo.InvariantCulture); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
var importPubSaDetails = ObjectMapper.Map<List<ZhiGongJianHBPOImportDto>, List<PUB_SA_DETAIL>>(importResults); |
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 数据校验
|
|
|
|
|
|
var checkList = await CheckAsync(importPubSaDetails); |
|
|
|
|
|
if (checkList.Count > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
return await ExportErrorReportAsync(checkList); |
|
|
|
|
|
} |
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
return await SaDataHandleAsync(importPubSaDetails, EnumBusinessType.ZhiGongJianHBPO); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 备件导入
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private async Task<string> ImportBeiJianAsync([FromForm] IFormFileCollection files) |
|
|
|
|
|
{ |
|
|
|
|
|
#region 导入数据转换
|
|
|
|
|
|
ExportImporter _exportImporter = new ExportImporter(); |
|
|
|
|
|
var importResults = await _exportImporter.UploadExcelImport<BeiJianImportDto>(files, _excelImportService); |
|
|
|
|
|
|
|
|
|
|
|
importResults.ForEach(importResult => |
|
|
|
|
|
{ |
|
|
|
|
|
importResult.SettleDate = DateTime.Now; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
var importPubSaDetails = ObjectMapper.Map<List<BeiJianImportDto>, List<PUB_SA_DETAIL>>(importResults); |
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 数据校验
|
|
|
|
|
|
var checkList = await CheckAsync(importPubSaDetails); |
|
|
|
|
|
if (checkList.Count > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
return await ExportErrorReportAsync(checkList); |
|
|
|
|
|
} |
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
return await SaDataHandleAsync(importPubSaDetails, EnumBusinessType.BeiJian); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 备件导入
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private async Task<string> ImportYinDuJianAsync([FromForm] IFormFileCollection files) |
|
|
|
|
|
{ |
|
|
|
|
|
#region 导入数据转换
|
|
|
|
|
|
ExportImporter _exportImporter = new ExportImporter(); |
|
|
|
|
|
var importResults = await _exportImporter.UploadExcelImport<YinDuJianImportDto>(files, _excelImportService); |
|
|
|
|
|
var importPubSaDetails = ObjectMapper.Map<List<YinDuJianImportDto>, List<PUB_SA_DETAIL>>(importResults); |
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 数据校验
|
|
|
|
|
|
var checkList = await CheckAsync(importPubSaDetails); |
|
|
|
|
|
if (checkList.Count > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
return await ExportErrorReportAsync(checkList); |
|
|
|
|
|
} |
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
return await SaDataHandleAsync(importPubSaDetails, EnumBusinessType.YinDuJian); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 数据校验
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private async Task<List<ErrorExportDto>> CheckAsync(List<PUB_SA_DETAIL> pubSaDetails) |
|
|
|
|
|
{ |
|
|
|
|
|
#region 数据校验
|
|
|
|
|
|
//数据校验
|
|
|
|
|
|
var checkList = new List<ErrorExportDto>(); |
|
|
|
|
|
//结算分组号
|
|
|
|
|
|
var pubSaGroupNums = pubSaDetails.Select(t => t.GroupNum).Distinct(); |
|
|
|
|
|
//已存在的结算分组号
|
|
|
|
|
|
var havPubSaGroupNums = (await _pubSaDetailRepository.GetListAsync(t => pubSaGroupNums.Contains(t.GroupNum))).Select(t => t.GroupNum).Distinct(); |
|
|
|
|
|
if (havPubSaGroupNums.Any() == true) |
|
|
|
|
|
{ |
|
|
|
|
|
foreach (var item in havPubSaGroupNums) |
|
|
|
|
|
{ |
|
|
|
|
|
checkList.Add(new ErrorExportDto(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, $"结算分组号{item}已存在", string.Empty)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return checkList; |
|
|
|
|
|
#endregion
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 结算数据处理
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private async Task<string> SaDataHandleAsync(List<PUB_SA_DETAIL> pubSaDetails, EnumBusinessType businessType) |
|
|
|
|
|
{ |
|
|
|
|
|
//客户零件关系
|
|
|
|
|
|
var materialRelationships = new List<MaterialRelationship>(); |
|
|
|
|
|
|
|
|
|
|
|
#region 处理结算数据
|
|
|
|
|
|
//销售价格
|
|
|
|
|
|
var priceListEntitys = await _priceListRepository.GetAllAsync(); |
|
|
|
|
|
|
|
|
|
|
|
pubSaDetails.ForEach(importPubSaDetail => |
|
|
|
|
|
{ |
|
|
|
|
|
List<string> luList = importPubSaDetail.LU.Split(" ").ToList(); |
|
|
|
|
|
importPubSaDetail.LU = luList[0].Replace(" ", ""); |
|
|
|
|
|
if (luList.Count > 1) |
|
|
|
|
|
{ |
|
|
|
|
|
luList.RemoveAt(0); |
|
|
|
|
|
var luAssemble = luList.Select(t => t.Replace(" ", "")); |
|
|
|
|
|
importPubSaDetail.LU += luAssemble.Aggregate(" ", (current, index) => current + index); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
importPubSaDetail.BusinessType = businessType; |
|
|
|
|
|
importPubSaDetail.Site = "XX工厂"; |
|
|
|
|
|
importPubSaDetail.KeyCode = importPubSaDetail.PN + importPubSaDetail.LU; |
|
|
|
|
|
|
|
|
|
|
|
//根据物料号、结算日期获取价格
|
|
|
|
|
|
var priceListEntity = priceListEntitys.Find(t => t.LU == importPubSaDetail.LU && importPubSaDetail.SettleDate > t.BeginTime && importPubSaDetail.SettleDate < t.EndTime); |
|
|
|
|
|
importPubSaDetail.Price = priceListEntity?.Price ?? 0; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
//导入的零件号集合
|
|
|
|
|
|
var importPubSaLUs = pubSaDetails.Select(t => t.LU).Distinct(); |
|
|
|
|
|
var materialRelationshipEntitys = await _materialRelationshipRepository.GetListAsync(t => importPubSaLUs.Contains(t.SettleMaterialCode)); |
|
|
|
|
|
var materialRelationshipEntitySettleMaterialCodes = materialRelationshipEntitys.Select(t => t.SettleMaterialCode).Distinct(); |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
* (不存在的客户零件号)差集 |
|
|
|
|
|
* 转换为厂内零件号 |
|
|
|
|
|
* 转换规则6个空格替换成“-” |
|
|
|
|
|
*/ |
|
|
|
|
|
var noExistSettleMaterialCodes = importPubSaLUs.Except(materialRelationshipEntitySettleMaterialCodes); |
|
|
|
|
|
|
|
|
|
|
|
noExistSettleMaterialCodes.ForEach(t => |
|
|
|
|
|
{ |
|
|
|
|
|
var materialRelationship = new MaterialRelationship(GuidGenerator.Create(), t.Replace(" ", "-"), "", t, businessType.ToString()); |
|
|
|
|
|
materialRelationships.Add(materialRelationship); |
|
|
|
|
|
}); |
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 添加入库
|
|
|
|
|
|
await SeDataEntryAsync(pubSaDetails); |
|
|
|
|
|
if (materialRelationships.Count > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
await _materialRelationshipRepository.InsertManyAsync(materialRelationships); |
|
|
|
|
|
} |
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
return ApplicationConsts.SuccessStr; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 结算数据入库
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private async Task SeDataEntryAsync(List<PUB_SA_DETAIL> pubSaDetails) |
|
|
|
|
|
{ |
|
|
|
|
|
//业务类型
|
|
|
|
|
|
EnumBusinessType businessType = pubSaDetails.First().BusinessType; |
|
|
|
|
|
//结算单号
|
|
|
|
|
|
var pubSaBillNum = OrderNumberGenerator.GenerateOrderNumber("SA"); |
|
|
|
|
|
//结算主表
|
|
|
|
|
|
var pubSa = new PUB_SA() |
|
|
|
|
|
{ |
|
|
|
|
|
BillNum = pubSaBillNum, |
|
|
|
|
|
State = "1", |
|
|
|
|
|
BusinessType = businessType |
|
|
|
|
|
}; |
|
|
|
|
|
//可结算单号
|
|
|
|
|
|
var pubCanSaBillNum = OrderNumberGenerator.GenerateOrderNumber("C"); |
|
|
|
|
|
//可结算主表
|
|
|
|
|
|
var pubCanSa = new PUB_CAN_SA() |
|
|
|
|
|
{ |
|
|
|
|
|
BillNum = pubCanSaBillNum, |
|
|
|
|
|
SettleBillNum = pubSaBillNum, |
|
|
|
|
|
State = SettleBillState.未结状态, |
|
|
|
|
|
BusinessType = businessType |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
#region 入库数据赋值
|
|
|
|
|
|
pubSaDetails.ForEach(pubSaDetail => |
|
|
|
|
|
{ |
|
|
|
|
|
pubSaDetail.BillNum = pubSaBillNum; |
|
|
|
|
|
}); |
|
|
|
|
|
//不可结算 结算分组号码(根据价格区分结算、不可结算)
|
|
|
|
|
|
var pubNotSaGroupNums = pubSaDetails.FindAll(t => t.Price == default(decimal)).Select(t => t.GroupNum).Distinct(); |
|
|
|
|
|
var pubSaDetailsCanSes = pubSaDetails.FindAll(t => pubNotSaGroupNums.Contains(t.GroupNum) == false); |
|
|
|
|
|
var pubSaDetailsNotCanSes = pubSaDetails.FindAll(t => pubNotSaGroupNums.Contains(t.GroupNum) == true); |
|
|
|
|
|
|
|
|
|
|
|
//可结算明细
|
|
|
|
|
|
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>>(pubSaDetailsNotCanSes); |
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 添加入库
|
|
|
|
|
|
await _repository.InsertAsync(pubSa); |
|
|
|
|
|
await _pubSaDetailRepository.InsertManyAsync(pubSaDetails); |
|
|
|
|
|
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.BusinessType = businessType; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
await _pubNotSaDetailRepository.InsertManyAsync(pubNotSaDetails); |
|
|
|
|
|
} |
|
|
|
|
|
#endregion
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// 获取结算关联项
|
|
|
/// 获取结算关联项
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
@ -417,7 +705,7 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase<PUB_SA> |
|
|
|
|
|
|
|
|
pubCanSas = await _pubCanSaRepository.GetListAsync(t => t.SettleBillNum == pubSaBillNum); |
|
|
pubCanSas = await _pubCanSaRepository.GetListAsync(t => t.SettleBillNum == pubSaBillNum); |
|
|
//验证可结算主表状态
|
|
|
//验证可结算主表状态
|
|
|
if (pubCanSas.Any(t => t.State != SettleBillState.未结状态) == false) |
|
|
if (pubCanSas.Any() && pubCanSas.Any(t => t.State != SettleBillState.未结状态)) |
|
|
{ |
|
|
{ |
|
|
throw new UserFriendlyException($"{pubSaBillNum} 该单据可结算单状态无法删除!", "400"); |
|
|
throw new UserFriendlyException($"{pubSaBillNum} 该单据可结算单状态无法删除!", "400"); |
|
|
} |
|
|
} |
|
|