Browse Source

非Jis结算数据导入

master
mahao 1 year ago
parent
commit
2d1f32532e
  1. 176
      code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/PUB_SA_DTO.cs
  2. 294
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/PUB_SA_SERVICE.cs
  3. 4
      code/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccountApplicationAutoMapperProfile.cs

176
code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/PUB_SA_DTO.cs

@ -57,6 +57,182 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Dtos
public EnumBusinessType BusinessType { get; set; } public EnumBusinessType BusinessType { get; set; }
} }
/// <summary>
/// 直供件BBAC导入
/// </summary>
public class ZhiGongJianBBACImportDto
{
/// <summary>
/// 结算日期
/// </summary>
[Display(Name = "Pstng Date")]
[ImporterHeader(Name = "Pstng Date")]
public DateTime SettleDate { set; get; }
/// <summary>
/// 零件号
/// </summary>
[Display(Name = "Material")]
[Required(ErrorMessage = "{0}不能为空")]
[ImporterHeader(Name = "Material")]
public string LU { get; set; }
/// <summary>
/// 生产号
/// </summary>
[Display(Name = "External Delivery ID")]
[ImporterHeader(Name = "External Delivery ID")]
[Required(ErrorMessage = "{0}不能为空")]
public string PN { get; set; }
/// <summary>
/// 数量
/// </summary>
[Display(Name = "Quantity")]
[ImporterHeader(Name = "Quantity")]
public decimal Qty { get; set; }
/// <summary>
/// 结算分组号
/// </summary>
[Display(Name = "Delivery")]
[ImporterHeader(Name = "Delivery")]
[Required(ErrorMessage = "{0}不能为空")]
public string GroupNum { get; set; }
}
/// <summary>
/// 直供件HBPO导入
/// </summary>
public class ZhiGongJianHBPOImportDto
{
/// <summary>
/// 结算日期
/// </summary>
[Display(Name = "结算日期")]
[ImporterHeader(IsIgnore = true)]
public DateTime SettleDate { set; get; }
/// <summary>
/// 零件号
/// </summary>
[Display(Name = "零件号")]
[Required(ErrorMessage = "{0}不能为空")]
[ImporterHeader(Name = "零件号")]
public string LU { get; set; }
/// <summary>
/// 生产号
/// </summary>
[Display(Name = "订单编号")]
[ImporterHeader(Name = "订单编号")]
[Required(ErrorMessage = "{0}不能为空")]
public string PN { get; set; }
/// <summary>
/// 数量
/// </summary>
[Display(Name = "数量")]
[ImporterHeader(Name = "数量")]
public decimal Qty { get; set; }
/// <summary>
/// 结算分组号
/// </summary>
[Display(Name = "订单编号")]
[ImporterHeader(Name = "订单编号")]
[Required(ErrorMessage = "{0}不能为空")]
public string GroupNum { get; set; }
}
/// <summary>
/// 备件导入
/// </summary>
public class BeiJianImportDto
{
/// <summary>
/// 结算日期
/// </summary>
[Display(Name = "结算日期")]
[ImporterHeader(IsIgnore = true)]
public DateTime SettleDate { set; get; }
/// <summary>
/// 零件号
/// </summary>
[Display(Name = "零件号")]
[Required(ErrorMessage = "{0}不能为空")]
[ImporterHeader(Name = "零件号")]
public string LU { get; set; }
/// <summary>
/// 生产号
/// </summary>
[Display(Name = "交付识别号")]
[ImporterHeader(Name = "交付识别号")]
[Required(ErrorMessage = "{0}不能为空")]
public string PN { get; set; }
/// <summary>
/// 数量
/// </summary>
[Display(Name = "数量")]
[ImporterHeader(Name = "数量")]
public decimal Qty { get; set; }
/// <summary>
/// 结算分组号
/// </summary>
[Display(Name = "凭证号")]
[ImporterHeader(Name = "凭证号")]
[Required(ErrorMessage = "{0}不能为空")]
public string GroupNum { get; set; }
}
/// <summary>
/// 印度件导入
/// </summary>
public class YinDuJianImportDto
{
/// <summary>
/// 结算日期
/// </summary>
[Display(Name = "Delivery Date")]
[ImporterHeader(Name = "Delivery Date")]
public DateTime SettleDate { set; get; }
/// <summary>
/// 零件号
/// </summary>
[Display(Name = "Material")]
[Required(ErrorMessage = "{0}不能为空")]
[ImporterHeader(Name = "Material")]
public string LU { get; set; }
/// <summary>
/// 生产号
/// </summary>
[Display(Name = "External Delivery ID")]
[ImporterHeader(Name = "External Delivery ID")]
[Required(ErrorMessage = "{0}不能为空")]
public string PN { get; set; }
/// <summary>
/// 数量
/// </summary>
[Display(Name = "数量")]
[ImporterHeader(Name = "Item")]
public decimal Qty { get; set; }
/// <summary>
/// 结算分组号
/// </summary>
[Display(Name = "External Delivery ID")]
[ImporterHeader(Name = "External Delivery ID")]
[Required(ErrorMessage = "{0}不能为空")]
public string GroupNum { get; set; }
}
/// <summary> /// <summary>
/// 导入 /// 导入
/// </summary> /// </summary>

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

@ -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");
} }
@ -428,7 +716,7 @@ public class PUB_SA_SERVICE : SettleAccountApplicationBase<PUB_SA>
pubNotSaDetails = await _pubNotSaDetailRepository.GetListAsync(t => t.SettleBillNum == pubSaBillNum); pubNotSaDetails = await _pubNotSaDetailRepository.GetListAsync(t => t.SettleBillNum == pubSaBillNum);
} }
return (pubSas, pubSaDetails, pubCanSas , pubCanSaDetails, pubNotSaDetails); return (pubSas, pubSaDetails, pubCanSas, pubCanSaDetails, pubNotSaDetails);
} }
#endregion #endregion
} }

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

@ -1021,6 +1021,10 @@ namespace Win.Sfs.SettleAccount
CreateMap<PUB_SA_DETAIL, PUB_SA_DETAIL_EXPORT_DTO>(); CreateMap<PUB_SA_DETAIL, PUB_SA_DETAIL_EXPORT_DTO>();
CreateMap<PUB_SA_DETAIL_IMPORT_DTO, PUB_SA_DETAIL>(); CreateMap<PUB_SA_DETAIL_IMPORT_DTO, PUB_SA_DETAIL>();
CreateMap<ZhiGongJianBBACImportDto, PUB_SA_DETAIL>();
CreateMap<ZhiGongJianHBPOImportDto, PUB_SA_DETAIL>();
CreateMap<BeiJianImportDto, PUB_SA_DETAIL>();
CreateMap<YinDuJianImportDto, PUB_SA_DETAIL>();
} }
/// <summary> /// <summary>

Loading…
Cancel
Save