Browse Source

HBPO EDI发运数据定时任我对比

master
mahao 1 year ago
parent
commit
a6973084ea
  1. 2
      code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/BBAC_SA_DTO.cs
  2. 35
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/BBAC_SA_SERVICE.cs
  3. 4
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/HBPO_SA_SERVICE.cs
  4. 78
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisHBPOSeEdiCompareAppService.cs

2
code/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/BQ/Dtos/BBAC_SA_DTO.cs

@ -79,7 +79,7 @@ public class BBAC_SA_DETAIL_IMPORT_DTO
[Display(Name = "Material")] [Display(Name = "Material")]
[Required(ErrorMessage = "{0}不能为空")] [Required(ErrorMessage = "{0}不能为空")]
[ImporterHeader(Name = "Material")] [ImporterHeader(Name = "Material")]
public string LU { get; set; } public string PartCode { get; set; }
/// <summary> /// <summary>
/// 数量 /// 数量

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

@ -114,14 +114,7 @@ public class BBAC_SA_SERVICE : SettleAccountApplicationBase<BBAC_SA>
#region 导入数据转换、数据校验 #region 导入数据转换、数据校验
ExportImporter _exportImporter = new ExportImporter(); ExportImporter _exportImporter = new ExportImporter();
var importDtos = await _exportImporter.UploadExcelImport<BBAC_SA_DETAIL_IMPORT_DTO>(files, _excelImportService); var importDtos = await _exportImporter.UploadExcelImport<BBAC_SA_DETAIL_IMPORT_DTO>(files, _excelImportService);
var importBBACSaDetails = ObjectMapper.Map<List<BBAC_SA_DETAIL_IMPORT_DTO>, List<BBAC_SA_DETAIL>>(importDtos);
//JisBBAC
var importHBOPDtos = importDtos.FindAll(t => t.PN.Contains("R0") == false);
//买单件BBAC
var importMaiDanJianHBOPDtos = importDtos.FindAll(t => t.PN.Contains("R0"));
var importBBACSaDetails = ObjectMapper.Map<List<BBAC_SA_DETAIL_IMPORT_DTO>, List<BBAC_SA_DETAIL>>(importHBOPDtos);
var importMaiDanJianBBACSaDetails = ObjectMapper.Map<List<BBAC_SA_DETAIL_IMPORT_DTO>, List<PUB_SA_DETAIL>>(importHBOPDtos);
//数据校验 //数据校验
var checkList = new List<ErrorExportDto>(); var checkList = new List<ErrorExportDto>();
@ -139,14 +132,14 @@ public class BBAC_SA_SERVICE : SettleAccountApplicationBase<BBAC_SA>
if (checkList.Count > 0) if (checkList.Count > 0)
{ {
string fileName = await ExportErrorReportAsync(checkList); string fileName = await ExportErrorReportAsync(checkList).ConfigureAwait(false);
return new JsonResult(new { Code = ApplicationConsts.ImportFailCode, fileName = fileName }); return new JsonResult(new { Code = ApplicationConsts.ImportFailCode, fileName = fileName });
} }
#endregion #endregion
if (importBBACSaDetails.Any()) if (importBBACSaDetails.Any())
{ {
await SaDataHandleAsync(importBBACSaDetails, importMaiDanJianBBACSaDetails); await SaDataHandleAsync(importBBACSaDetails).ConfigureAwait(false);
} }
return new JsonResult(new { Code = 200, Message = "导入成功" }); return new JsonResult(new { Code = 200, Message = "导入成功" });
@ -286,7 +279,7 @@ public class BBAC_SA_SERVICE : SettleAccountApplicationBase<BBAC_SA>
/// <summary> /// <summary>
/// 结算数据处理 /// 结算数据处理
/// </summary> /// </summary>
private async Task SaDataHandleAsync(List<BBAC_SA_DETAIL> bbacSaDetails, List<PUB_SA_DETAIL> maiDanJianBBACSaDetails) private async Task SaDataHandleAsync(List<BBAC_SA_DETAIL> bbacSaDetails)
{ {
//结算单号 //结算单号
var bbacSaBillNum = OrderNumberGenerator.GenerateOrderNumber("SA"); var bbacSaBillNum = OrderNumberGenerator.GenerateOrderNumber("SA");
@ -319,13 +312,13 @@ public class BBAC_SA_SERVICE : SettleAccountApplicationBase<BBAC_SA>
bbacSaDetails.ForEach(bbacSaDetail => bbacSaDetails.ForEach(bbacSaDetail =>
{ {
List<string> luList = bbacSaDetail.LU.Split(" ").ToList(); List<string> partCodes = bbacSaDetail.PartCode.Split(" ").ToList();
bbacSaDetail.LU = luList[0].Replace(" ", ""); bbacSaDetail.PartCode = partCodes[0].Replace(" ", "");
if (luList.Count > 1) if (partCodes.Count > 1)
{ {
luList.RemoveAt(0); partCodes.RemoveAt(0);
var luAssemble = luList.Select(t => t.Replace(" ", "")); var partCodeAssemble = partCodes.Select(t => t.Replace(" ", ""));
bbacSaDetail.LU += luAssemble.Aggregate(" ", (current, index) => current + index); bbacSaDetail.PartCode += partCodeAssemble.Aggregate(" ", (current, index) => current + index);
} }
bbacSaDetail.BillNum = bbacSaBillNum; bbacSaDetail.BillNum = bbacSaBillNum;
@ -334,6 +327,7 @@ public class BBAC_SA_SERVICE : SettleAccountApplicationBase<BBAC_SA>
//根据物料号、结算日期获取价格 //根据物料号、结算日期获取价格
var priceListEntity = priceListEntitys.Find(t => t.LU == bbacSaDetail.LU && bbacSaDetail.SettleDate > t.BeginTime && bbacSaDetail.SettleDate < t.EndTime); var priceListEntity = priceListEntitys.Find(t => t.LU == bbacSaDetail.LU && bbacSaDetail.SettleDate > t.BeginTime && bbacSaDetail.SettleDate < t.EndTime);
bbacSaDetail.Price = priceListEntity?.Price ?? default; bbacSaDetail.Price = priceListEntity?.Price ?? default;
bbacSaDetail.IsMaiDan = bbacSaDetail.PN.Contains("R0");
}); });
//导入的零件号集合 //导入的零件号集合
@ -353,6 +347,13 @@ public class BBAC_SA_SERVICE : SettleAccountApplicationBase<BBAC_SA>
var materialRelationship = new MaterialRelationship(GuidGenerator.Create(), t.Replace(" ", "-"), "", t, _businessType.ToString()); var materialRelationship = new MaterialRelationship(GuidGenerator.Create(), t.Replace(" ", "-"), "", t, _businessType.ToString());
materialRelationships.Add(materialRelationship); materialRelationships.Add(materialRelationship);
}); });
var seAllMaterialRelationships = materialRelationshipEntitys.Union(materialRelationships);
bbacSaDetails.ForEach(bbacSaDetail =>
{
bbacSaDetail.LU = seAllMaterialRelationships.FirstOrDefault(t => t.SettleMaterialCode == bbacSaDetail.PartCode)?.ErpMaterialCode ?? bbacSaDetail.PartCode.Replace(" ", "-");
bbacSaDetail.KeyCode = bbacSaDetail.PN + bbacSaDetail.LU;
});
#endregion #endregion
#region 入库数据赋值 #region 入库数据赋值

4
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/HBPO_SA_SERVICE.cs

@ -328,8 +328,8 @@ public class HBPO_SA_SERVICE : SettleAccountApplicationBase<HBPO_SA>
if (partCodes.Count > 1) if (partCodes.Count > 1)
{ {
partCodes.RemoveAt(0); partCodes.RemoveAt(0);
var luAssemble = partCodes.Select(t => t.Replace(" ", "")); var partCodeAssemble = partCodes.Select(t => t.Replace(" ", ""));
hbpoSaDetail.PartCode += luAssemble.Aggregate(" ", (current, index) => current + index); hbpoSaDetail.PartCode += partCodeAssemble.Aggregate(" ", (current, index) => current + index);
} }
hbpoSaDetail.BillNum = hbpoSaBillNum; hbpoSaDetail.BillNum = hbpoSaBillNum;

78
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/JisHBPOSeEdiCompareAppService.cs

@ -1,17 +1,15 @@
using System; using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Coravel.Invocable; using Coravel.Invocable;
using LinqToDB;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using SettleAccount.Domain.BQ; using SettleAccount.Domain.BQ;
using Volo.Abp.Application.Services; using Volo.Abp.Application.Services;
using Win.Sfs.Shared.RepositoryBase; using Win.Sfs.Shared.RepositoryBase;
using System.Linq;
using DocumentFormat.OpenXml.Office2010.ExcelAc;
using System.Collections.Generic;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Application;
using System.Runtime.Intrinsics.X86;
namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs; namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs;
@ -47,56 +45,38 @@ public class JisHBPOSeEdiCompareAppService : ApplicationService, IInvocable
/// </summary> /// </summary>
public async Task Invoke() public async Task Invoke()
{ {
await Task.CompletedTask; Debug.WriteLine($"执行了:{this.GetType()}");
Debug.WriteLine($"执行了 {this.GetType()}");
using var serviceScope = _serviceProvider.CreateScope(); using var serviceScope = _serviceProvider.CreateScope();
var db = serviceScope.ServiceProvider.GetRequiredService<SettleAccountDbContext>(); var db = serviceScope.ServiceProvider.GetRequiredService<SettleAccountDbContext>();
//var query = from se in db.Set<HBPO_SE_DETAIL>()
//List<HBPO_SE_DETAIL> hbpoSeDetails = await _hbpoSeDetailRepository.GetListAsync(t => t.IsHaveEdiData == false); // join edi in db.Set<HBPO_SE_EDI>() on new
//var hbpoSeDetails = db.Set<HBPO_SE_DETAIL>().Where(t => t.IsHaveEdiData == false).OrderBy(t => t.BillTime);
//var hbpoSeEdis = db.Set<HBPO_SE_EDI>().Where(t => t.IsHaveSeData == false && hbpoSeDetails.Any(w => w.PN.Equals(t.PN) && w.LU.Equals(t.LU) && w.Qty.Equals(t.Qty)));
var query = from se in db.Set<HBPO_SE_DETAIL>()
join edi in db.Set<HBPO_SE_EDI>() on new
{
se.LU,
se.PN,
se.Qty
} equals new
{
edi.LU,
edi.PN,
edi.Qty
}
where se.IsHaveEdiData == false && edi.IsHaveSeData == false
//select new
// { // {
// SeID = se.Id,
// se.PN,
// se.LU, // se.LU,
// se.Qty, // se.PN,
// EdiID = edi.Id // se.Qty
// } equals new
// {
// edi.LU,
// edi.PN,
// edi.Qty
// }
// where se.IsHaveEdiData == false && edi.IsHaveSeData == false
// select new
// {
// se,
// edi
// }; // };
select new var query = db.Set<HBPO_SE_DETAIL>().Join(db.Set<HBPO_SE_EDI>(), a => new { a.PN, a.LU, a.Qty }, b => new { b.PN, b.LU, b.Qty }, (se, edi) => new { se, edi }).Where(t => t.se.IsHaveEdiData == false && t.edi.IsHaveSeData == false);
{ var ses = query.Select(t => t.se);
se, var edis = query.Select(t => t.edi);
edi
};
query.ForEach(item => ses.ForEach(t => t.IsHaveEdiData = true);
{ edis.ForEach(t => t.IsHaveSeData = true);
Debug.WriteLine($"{Newtonsoft.Json.JsonConvert.SerializeObject(item)}");
});
//var ses = query.SelectMany(t => t.se);
//var edis = query.SelectMany(t => t.edi);
//hbpoSeEdis.ForEach(hbpoSeEdi => db.Set<HBPO_SE_DETAIL>().UpdateRange(ses);
//{ db.Set<HBPO_SE_EDI>().UpdateRange(edis);
// Debug.WriteLine($"{hbpoSeEdi.Id}"); await db.SaveChangesAsync().ConfigureAwait(false);
//});
Debug.WriteLine($"处理数量:{query.Count()}");
} }
} }

Loading…
Cancel
Save