You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
773 lines
32 KiB
773 lines
32 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Options;
|
|
using Volo.Abp.BackgroundWorkers;
|
|
using Volo.Abp.Threading;
|
|
using Volo.Abp.Uow;
|
|
using Win_in.Sfs.Basedata.Application.Contracts;
|
|
using Win_in.Sfs.Shared.Domain;
|
|
using Win_in.Sfs.Shared.Domain.Shared;
|
|
using Win_in.Sfs.Wms.DataExchange.Application.Contracts.Iac.Mes.Mes;
|
|
using Win_in.Sfs.Wms.DataExchange.Application.Contracts.Iac.Mes.Mes.Inputs;
|
|
using Win_in.Sfs.Wms.DataExchange.Domain.Shared;
|
|
using Win_in.Sfs.Wms.Store.Application.Contracts;
|
|
|
|
namespace Win_in.Sfs.Wms.DataExchange.MesAgent;
|
|
|
|
/// <summary>
|
|
/// 传输相关的L7零件信息
|
|
/// </summary>
|
|
public class JisInfoIncomingDataWorker : AsyncPeriodicBackgroundWorkerBase
|
|
{
|
|
private readonly IOptions<DataExchangeOptions> _options;
|
|
|
|
/// <summary>
|
|
/// 发送信息的log开头
|
|
/// </summary>
|
|
private readonly string SendLogTitieString = "Send FileInfo:";
|
|
|
|
public JisInfoIncomingDataWorker(
|
|
AbpAsyncTimer timer,
|
|
IOptions<DataExchangeOptions> options,
|
|
IServiceScopeFactory serviceScopeFactory
|
|
) : base(timer, serviceScopeFactory)
|
|
{
|
|
_options = options;
|
|
Timer.Period = options.Value.IncomingOptions.PeriodSeconds * 1000; //default 5 minutes
|
|
}
|
|
|
|
[UnitOfWork]
|
|
protected override async Task DoWorkAsync(PeriodicBackgroundWorkerContext workerContext)
|
|
{
|
|
#region 初始化服务是否开启
|
|
Logger.LogInformation($"{SendLogTitieString}Starting File Data Exchange...");
|
|
if (!_options.Value.IncomingOptions.Active)
|
|
{
|
|
Logger.LogInformation($"{SendLogTitieString} File Data Exchange is not active!");
|
|
return;
|
|
}
|
|
#endregion
|
|
|
|
//记录报错的文件名称
|
|
string fileName = "";
|
|
try
|
|
{
|
|
|
|
#region 获取需要更新的文件信息
|
|
//Resolve dependencies
|
|
var messageReceiveAppService = workerContext
|
|
.ServiceProvider
|
|
.GetRequiredService<QAD.IMessageReceiveAppService>();
|
|
List<MessageReceiveDTO> receiveFileDataList = await messageReceiveAppService.GetListAsync().ConfigureAwait(false);
|
|
|
|
if (receiveFileDataList.Count == 0)
|
|
{
|
|
Logger.LogInformation($"{SendLogTitieString}Can't find any file data...");
|
|
|
|
return;
|
|
}
|
|
|
|
Logger.LogInformation($"{SendLogTitieString}:There are total {receiveFileDataList.Count} file data to be managed.");
|
|
|
|
////删除列表
|
|
//var deleteFileList = incomingDataList.Where(p=>p.Type== ((int)EnumExchangeDataAction.Delete).ToString()).ToList();
|
|
|
|
//Logger.LogInformation($"{SendLogTitieString} {deleteFileList.Count} file data to be deleted.");
|
|
|
|
////修改列表
|
|
//var modifyFileList = incomingDataList.Where(p => p.Type == ((int)EnumExchangeDataAction.Modify).ToString()).ToList();
|
|
|
|
//Logger.LogInformation($"{SendLogTitieString} {modifyFileList.Count} file data to be modified.");
|
|
|
|
////新增列表
|
|
//var addFileList = incomingDataList.Where(p => p.Type == ((int)EnumExchangeDataAction.Add).ToString()).ToList();
|
|
|
|
//Logger.LogInformation($"{SendLogTitieString} {addFileList.Count} file data to be added.");
|
|
;
|
|
#endregion
|
|
|
|
#region 声明需要包含的服务
|
|
Logger.LogInformation($"{SendLogTitieString}Initial IMesProductL7PartsNoteAppService...");
|
|
|
|
//声明需要的服务信息
|
|
var mesProductL7PartsNoteAppService = workerContext
|
|
.ServiceProvider
|
|
.GetRequiredService<IMesProductL7PartsNoteAppService>();
|
|
|
|
Logger.LogInformation($"{SendLogTitieString}Initial IMesProductL7PartsNoteAppService End...");
|
|
|
|
Logger.LogInformation($"{SendLogTitieString}Initial IProductL7PartsNoteAppService...");
|
|
|
|
//Resolve dependencies
|
|
var productL7PartsNoteAppService = workerContext
|
|
.ServiceProvider
|
|
.GetRequiredService<IProductL7PartsNoteAppService>();
|
|
|
|
Logger.LogInformation($"{SendLogTitieString}Initial IProductL7PartsNoteAppService End...");
|
|
|
|
Logger.LogInformation($"{SendLogTitieString}Initial IItemBasicAppService ...");
|
|
|
|
//Resolve dependencies
|
|
var itemBasicAppService = workerContext
|
|
.ServiceProvider
|
|
.GetRequiredService<IItemBasicAppService>();
|
|
|
|
Logger.LogInformation($"{SendLogTitieString}Initial IItemBasicAppService end...");
|
|
|
|
#endregion
|
|
|
|
//开始循环对文件进行增加、修改、删除操作
|
|
|
|
foreach (var receiveFileData in receiveFileDataList)
|
|
{
|
|
//赋值对应的文件名称,出错好记录
|
|
fileName = receiveFileData.MessageFileName;
|
|
|
|
//对文件名称做拆解,获取项目、生产码和年份
|
|
|
|
string[] topInfos = fileName.Split("_");
|
|
|
|
string program = topInfos[0];//项目
|
|
|
|
string productNo = topInfos[1]; //生产码
|
|
|
|
string year = topInfos[2].Substring(0, 4); //年份
|
|
|
|
//如果是删除文件
|
|
if (receiveFileData.Type == ((int)EnumFileTypeStatus.Delete).ToString())
|
|
{
|
|
//开始删除相关数据
|
|
await DeleteReceivedFileData(fileName, year, program, productNo, messageReceiveAppService, mesProductL7PartsNoteAppService, productL7PartsNoteAppService).ConfigureAwait(false);
|
|
}
|
|
//如果是新增文件
|
|
else if (receiveFileData.Type == ((int)EnumFileTypeStatus.Add).ToString())
|
|
{
|
|
//开始添加新数据
|
|
await AddReceivedFileData(fileName, year, program, productNo, receiveFileData, messageReceiveAppService, mesProductL7PartsNoteAppService, productL7PartsNoteAppService, itemBasicAppService).ConfigureAwait(false);
|
|
|
|
}
|
|
|
|
//如果是修改文件
|
|
else if (receiveFileData.Type == ((int)EnumFileTypeStatus.Modify).ToString())
|
|
{
|
|
//开始删除相关数据
|
|
await DeleteReceivedFileData(fileName, year, program, productNo, messageReceiveAppService, mesProductL7PartsNoteAppService, productL7PartsNoteAppService).ConfigureAwait(false);
|
|
|
|
//开始添加新数据
|
|
await AddReceivedFileData(fileName, year, program, productNo, receiveFileData, messageReceiveAppService, mesProductL7PartsNoteAppService, productL7PartsNoteAppService, itemBasicAppService).ConfigureAwait(false);
|
|
|
|
}
|
|
else
|
|
{
|
|
Logger.LogError($"{SendLogTitieString}Unknown file operation type {receiveFileData.Type}, file name is {fileName},id is {receiveFileData.Id}.");
|
|
|
|
continue;
|
|
}
|
|
|
|
#region Archived File Data
|
|
|
|
Logger.LogInformation($"{SendLogTitieString}Start archiving file data.File name is {fileName}");
|
|
|
|
await messageReceiveAppService.UpdateReceiveStatusByIdsAsync(new List<Guid>() { receiveFileData.Id }, EnumReceiveStatus.Archived).ConfigureAwait(false);
|
|
Logger.LogInformation($"{SendLogTitieString}Finished archiving file data.File name is {fileName}");
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string errorMsg = $"{SendLogTitieString}调用TransmissionMessageAsync方法出错,报文名称{fileName}:" + ex.Message;
|
|
string errorMsg2 = $"{SendLogTitieString}调用TransmissionMessageAsync方法出错,报文名称{fileName}:" + ex.ToString();
|
|
//_logRemindDomainService.WriteLogRemind(fileName, errorMsg, LogTypeEnum.M100);
|
|
Logger.LogError(errorMsg);
|
|
Logger.LogError(errorMsg2);
|
|
}
|
|
|
|
//Timer.Start(); //运行结束,开启计时;
|
|
Logger.LogInformation($"{SendLogTitieString}Completed File Data Exchange...");
|
|
}
|
|
|
|
#region 私有方法
|
|
|
|
/// <summary>
|
|
/// 添加L7文件方法
|
|
/// </summary>
|
|
/// <param name="fileName"></param>
|
|
/// <param name="year"></param>
|
|
/// <param name="program"></param>
|
|
/// <param name="productNo"></param>
|
|
/// <param name="receiveFileData"></param>
|
|
/// <param name="messageReceiveAppService"></param>
|
|
/// <param name="mesProductL7PartsNoteAppService"></param>
|
|
/// <param name="productL7PartsNoteAppService"></param>
|
|
/// <param name="itemBasicAppService"></param>
|
|
/// <returns></returns>
|
|
private async Task AddReceivedFileData(string fileName, string year, string program, string productNo, MessageReceiveDTO receiveFileData, QAD.IMessageReceiveAppService messageReceiveAppService, IMesProductL7PartsNoteAppService mesProductL7PartsNoteAppService, IProductL7PartsNoteAppService productL7PartsNoteAppService, IItemBasicAppService itemBasicAppService)
|
|
{
|
|
#region 开始操作添加文件信息
|
|
|
|
#region Add DataExchange Database Data
|
|
|
|
Logger.LogInformation($"{SendLogTitieString}Start adding exist file data in DataExchange Database.File name is {fileName}");
|
|
|
|
//开始添加在DataExchange数据库中的L7零件信息
|
|
|
|
Logger.LogInformation($"{SendLogTitieString}Changing file data to MesProductL7PartsNoteCreateInput.");
|
|
|
|
List<MesProductL7PartsNoteCreateInput> deInputs = ConvertToInputList(year, program, productNo, receiveFileData);
|
|
|
|
#endregion Add DataExchange Database Data
|
|
|
|
#region 开始保存Store DataBase
|
|
|
|
#region 添加没有的配置码零件信息
|
|
|
|
Logger.LogInformation($"{SendLogTitieString}Start adding exist file data in 开始保存Store Database.File name is {fileName}");
|
|
|
|
var L7PartCodes = deInputs.Select(p => p.L7Part).Distinct().ToList();
|
|
|
|
//需要查询的零件列表
|
|
var partCodeList = deInputs.Select(p => p.Configuration).Distinct().ToList();
|
|
partCodeList.AddRange(L7PartCodes);
|
|
|
|
//按照零件进行归总
|
|
var sumEntityList = deInputs.GroupBy(p => new { p.Year, p.ProductNo, p.Program, p.FATA, p.Configuration, p.Position }).ToList();
|
|
|
|
//获取所有的L7零件信息,并获取零件是不是采购件、制造件
|
|
SfsBaseDataRequestInputBase requestInput = new SfsBaseDataRequestInputBase() { MaxResultCount = 999 };
|
|
if (L7PartCodes.Count > 0)
|
|
{
|
|
string partCodesStr = System.Text.Json.JsonSerializer.Serialize(partCodeList);
|
|
requestInput.Condition.Filters.Add(new Sfs.Shared.Domain.Filter() { Action = EnumFilterAction.In.ToString(), Column = "Code", Logic = EnumFilterLogic.And.ToString(), Value = partCodesStr, });
|
|
|
|
}
|
|
|
|
Logger.LogInformation($"{SendLogTitieString}Start geting item basic infos.");
|
|
|
|
var itemDtoListResult = await itemBasicAppService.GetPagedListByFilterAsync(requestInput, false).ConfigureAwait(false);
|
|
|
|
//返回的所有需要的零件信息表
|
|
var itemBaseList = itemDtoListResult.Items;
|
|
|
|
Logger.LogInformation($"{SendLogTitieString}Finished geting item basic infos.Info count is{itemDtoListResult.Items.Count}.");
|
|
#endregion
|
|
|
|
#region 开始构建Store的L7零件结构表
|
|
List<ProductL7PartsNoteEditInput> noteList = new List<ProductL7PartsNoteEditInput>();
|
|
|
|
foreach (var sumEntity in sumEntityList)
|
|
{
|
|
|
|
#region 先是获取配置码的基本信息是否存在,存在就继续,不存在就先保存配置码信息,然后在进行后面的库存操作
|
|
|
|
try
|
|
{
|
|
//先是获取配置码的基本信息是否存在,存在就继续,不存在就先保存配置码信息,然后在进行后面的库存操作.
|
|
var item = itemBaseList.FirstOrDefault(p => p.Code == sumEntity.Key.Configuration);
|
|
|
|
if (item == null)
|
|
{
|
|
await InsertItemBasic(sumEntity.Key.Program, sumEntity.Key.ProductNo, sumEntity.Key.Configuration, sumEntity.Key.FATA, sumEntity.Key.Program, itemBasicAppService).ConfigureAwait(false);
|
|
Logger.LogInformation($"{SendLogTitieString}Add item basic info.Code is{sumEntity.Key.Configuration}.");
|
|
|
|
}
|
|
}
|
|
|
|
catch (Volo.Abp.UserFriendlyException)
|
|
{
|
|
await InsertItemBasic(sumEntity.Key.Program, sumEntity.Key.ProductNo, sumEntity.Key.Configuration, sumEntity.Key.FATA, sumEntity.Key.Program, itemBasicAppService).ConfigureAwait(false);
|
|
Logger.LogInformation($"{SendLogTitieString}Add item basic info.Code is{sumEntity.Key.Configuration}.");
|
|
}
|
|
|
|
#endregion
|
|
|
|
ProductL7PartsNoteEditInput note = new ProductL7PartsNoteEditInput()
|
|
{
|
|
ProductNo = sumEntity.Key.ProductNo,
|
|
Program = sumEntity.Key.Program,
|
|
FATA = sumEntity.Key.FATA,
|
|
Configuration = sumEntity.Key.Configuration,
|
|
Position = sumEntity.Key.Position,
|
|
Year = sumEntity.Key.Year,
|
|
Details = new List<ProductL7PartsNoteDetailInput>(),
|
|
};
|
|
|
|
var detailList = deInputs.Where(p => p.Year == sumEntity.Key.Year &&
|
|
p.ProductNo == sumEntity.Key.ProductNo &&
|
|
p.Program == sumEntity.Key.Program &&
|
|
p.FATA == sumEntity.Key.FATA &&
|
|
p.Configuration == sumEntity.Key.Configuration &&
|
|
p.Position == sumEntity.Key.Position).ToList();
|
|
|
|
foreach (var detail in detailList)
|
|
{
|
|
|
|
ProductL7PartsNoteDetailInput noteDetail = new ProductL7PartsNoteDetailInput()
|
|
|
|
{
|
|
ProductNo = sumEntity.Key.ProductNo,
|
|
Program = sumEntity.Key.Program,
|
|
FATA = sumEntity.Key.FATA,
|
|
Configuration = sumEntity.Key.Configuration,
|
|
Position = sumEntity.Key.Position,
|
|
L7Part = detail.L7Part,
|
|
ItemCode = detail.L7Part,
|
|
State = detail.State,
|
|
CreateDate = detail.CreateDate,
|
|
Qty = detail.Qty,
|
|
RowID = detail.RowID,
|
|
};
|
|
|
|
var itemBase = itemBaseList.FirstOrDefault(p => p.Code == detail.L7Part);
|
|
if (itemBase == null)
|
|
{
|
|
//throw new Exception($"未找到零件{detail.L7PartCode}的零件基础信息,请确认基础信息是否齐全!");
|
|
|
|
}
|
|
else
|
|
{
|
|
noteDetail.CanMake = itemBase.CanMake;
|
|
noteDetail.CanBuy = itemBase.CanBuy;
|
|
}
|
|
|
|
note.Details.AddIfNotContains(noteDetail);
|
|
}
|
|
|
|
noteList.Add(note);
|
|
}
|
|
|
|
#endregion 开始构建Store的L7零件结构表
|
|
|
|
Logger.LogInformation($"{SendLogTitieString}Starting productL7PartsNoteAppService.CreateAsync.");
|
|
//开始添加在Store数据库中的L7零件信息
|
|
await productL7PartsNoteAppService.CreateAsync(noteList).ConfigureAwait(false);
|
|
Logger.LogInformation($"{SendLogTitieString}Finished productL7PartsNoteAppService.CreateAsync.");
|
|
|
|
Logger.LogInformation($"{SendLogTitieString}Finished adding exist file data in Store Database.File name is {fileName}");
|
|
|
|
#endregion
|
|
|
|
Logger.LogInformation($"{SendLogTitieString}Start mesProductL7PartsNoteAppService AddManyAsync.");
|
|
|
|
await mesProductL7PartsNoteAppService.AddManyAsync(deInputs).ConfigureAwait(false);
|
|
|
|
Logger.LogInformation($"{SendLogTitieString}Finished mesProductL7PartsNoteAppService AddManyAsync.");
|
|
|
|
#endregion
|
|
}
|
|
|
|
/// <summary>
|
|
/// 插入对应的零件基础信息
|
|
/// </summary>
|
|
private static async Task InsertItemBasic(string program, string productNo, string configuration, string fata, string position, IItemBasicAppService itemBasicAppService)
|
|
{
|
|
string desc;
|
|
switch (position)
|
|
{
|
|
case "FL":
|
|
|
|
desc = "左前门";
|
|
break;
|
|
|
|
case "RL":
|
|
|
|
desc = "左后门";
|
|
break;
|
|
|
|
case "FR":
|
|
|
|
desc = "右前门";
|
|
break;
|
|
|
|
case "RR":
|
|
|
|
desc = "右后门";
|
|
break;
|
|
|
|
default:
|
|
|
|
desc = position;
|
|
break;
|
|
}
|
|
|
|
var exist = new ItemBasicEditInput
|
|
{
|
|
Code = configuration,
|
|
Name = program + "项目" + desc,
|
|
Desc1 = fata, //FATA码
|
|
Desc2 = fata, //位置信息
|
|
Status = EnumItemStatus.Active,
|
|
CanBuy = false,
|
|
CanMake = true,
|
|
Type = string.Empty, //类型
|
|
Category = string.Empty, //种类
|
|
Group = string.Empty, //分组
|
|
Color = string.Empty, //颜色
|
|
Configuration = string.Empty, //配置
|
|
BasicUom = "E", //基本计量单位
|
|
AbcClass = "Z", //ABC类
|
|
Project = program, //项目
|
|
Version = "1", //版本
|
|
Eco = string.Empty, //工程变革
|
|
Validity = 365, //有效期
|
|
ValidityUnit = EnumValidityUnit.Day, //有效期单位
|
|
ManageType = EnumItemManageType.SingleUnit, //管理类型
|
|
Elevel = string.Empty, //打印标签用的一个等级
|
|
Remark = productNo //产品码
|
|
};
|
|
|
|
//添加该Item信息
|
|
await itemBasicAppService.UpsertAsync(exist).ConfigureAwait(false);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 将文件数据转化为mes保存的数据
|
|
/// </summary>
|
|
/// <param name="year"></param>
|
|
/// <param name="program"></param>
|
|
/// <param name="productNo"></param>
|
|
/// <param name="msgReceObj"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="Exception"></exception>
|
|
private static List<MesProductL7PartsNoteCreateInput> ConvertToInputList(string year, string program, string productNo, MessageReceiveDTO msgReceObj)
|
|
{
|
|
List<MesProductL7PartsNoteCreateInput> inputList = new List<MesProductL7PartsNoteCreateInput>();
|
|
try
|
|
{
|
|
|
|
//string[] topInfos = msgReceObj.MessageFileName.Split("_");
|
|
|
|
//string program = topInfos[0];//项目
|
|
|
|
//string productNo = topInfos[1]; //生产码
|
|
|
|
//string year = topInfos[2].Substring(0, 4); //年份
|
|
|
|
//获取对应的明细字段
|
|
string[] txtLines = msgReceObj.MessageContent.Split("\r\n");
|
|
|
|
foreach (var txtLine in txtLines)
|
|
{
|
|
if (txtLine.Trim() == "" || txtLine.StartsWith("Position,"))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
string[] strs = txtLine.Split(",");
|
|
|
|
//Position,FATA,Configuration,L7Part,Qty
|
|
//FL,254FLB2Y34BBBO1111111N11,FL012,A2547205501,1
|
|
|
|
string position = strs[0]; //位置
|
|
string FATA = strs[1]; //Fata
|
|
string configuration = strs[2]; //配置码
|
|
string l7Part = strs[3]; //L7零件号
|
|
string qty = strs[4]; //数量
|
|
|
|
MesProductL7PartsNoteCreateInput createInput = new MesProductL7PartsNoteCreateInput()
|
|
{
|
|
RowID = 0,
|
|
State = Convert.ToInt32(msgReceObj.Type),
|
|
Year = year,
|
|
ProductNo = productNo,
|
|
Program = program,
|
|
Position = position,
|
|
FATA = FATA,
|
|
Configuration = configuration,
|
|
L7Part = l7Part,
|
|
Qty = Convert.ToInt32(qty),
|
|
CreateDate = msgReceObj.CreationTime,
|
|
Number = "Mes",
|
|
|
|
};
|
|
|
|
inputList.Add(createInput);
|
|
|
|
}//foreach
|
|
|
|
return inputList;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string errorMsg = $"调用ConvertToInputList方法时报错,文件名称={msgReceObj.MessageFileName}:" + ex.Message;
|
|
throw new Exception(errorMsg);
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 开始删除之前保存过的数据
|
|
/// </summary>
|
|
/// <param name="fileName"></param>
|
|
/// <param name="year"></param>
|
|
/// <param name="program"></param>
|
|
/// <param name="productNo"></param>
|
|
/// <param name="messageReceiveAppService"></param>
|
|
/// <param name="mesProductL7PartsNoteAppService"></param>
|
|
/// <param name="productL7PartsNoteAppService"></param>
|
|
/// <returns></returns>
|
|
private async Task DeleteReceivedFileData(string fileName, string year, string program, string productNo, QAD.IMessageReceiveAppService messageReceiveAppService, IMesProductL7PartsNoteAppService mesProductL7PartsNoteAppService, IProductL7PartsNoteAppService productL7PartsNoteAppService)
|
|
{
|
|
#region 开始操作需要删除的文件
|
|
|
|
#region Delete Store Database Data
|
|
Logger.LogInformation($"{SendLogTitieString}Start deleteing exist file data in Store Database.File name is {fileName}");
|
|
|
|
//开始删除在Store数据库中的L7零件信息
|
|
|
|
Logger.LogInformation($"{SendLogTitieString}Starting productL7PartsNoteAppService.DeleteByBaseInfoAsync.");
|
|
|
|
//保存相关L7零件信息
|
|
await productL7PartsNoteAppService.DeleteByBaseInfoAsync(year, program, productNo).ConfigureAwait(false);
|
|
Logger.LogInformation($"{SendLogTitieString}Finished productL7PartsNoteAppService.DeleteByBaseInfoAsync.");
|
|
|
|
Logger.LogInformation($"{SendLogTitieString}Finished deleteing exist file data in Store Database.File name is {fileName}");
|
|
|
|
#endregion
|
|
|
|
#region Delete DataExchange Database Data
|
|
|
|
Logger.LogInformation($"{SendLogTitieString}Start deleteing exist file data in DataExchange Database.File name is {fileName}");
|
|
|
|
//开始删除在DataExchange数据库中的L7零件信息
|
|
|
|
await mesProductL7PartsNoteAppService.DeleteByBaseInfoAsync(year, program, productNo).ConfigureAwait(false);
|
|
|
|
Logger.LogInformation($"{SendLogTitieString}Finished deleteing exist file data in DataExchange Database.File name is {fileName}");
|
|
|
|
#endregion
|
|
//#region Archiving File Data
|
|
|
|
//Logger.LogInformation($"{SendLogTitieString}Start archiving file data.File name is {fileName}");
|
|
|
|
//await messageReceiveAppService.UpdateReceiveStatusByIdsAsync(new List<Guid>() { receiveFileData.Id }, EnumReceiveStatus.Archived);
|
|
//Logger.LogInformation($"{SendLogTitieString}Finished archiving file data.File name is {fileName}");
|
|
|
|
//#endregion
|
|
|
|
#endregion
|
|
}
|
|
|
|
#endregion 私有方法
|
|
|
|
#region delete method
|
|
|
|
////[UnitOfWork]
|
|
//protected override async Task DoWorkAsyncBak(PeriodicBackgroundWorkerContext workerContext)
|
|
//{
|
|
|
|
// Logger.LogInformation("{SendLogTitieString}Starting File Data Exchange...");
|
|
// if (!_options.Value.IncomingOptions.Active)
|
|
// {
|
|
// Logger.LogInformation("{SendLogTitieString} File Data Exchange is not active!");
|
|
// return;
|
|
// }
|
|
|
|
// //Timer.Stop(); //运行期间,暂定计时
|
|
|
|
// string fileName = "";
|
|
// try
|
|
// {
|
|
|
|
// #region 获取需要更新的文件
|
|
// //Resolve dependencies
|
|
// var messageReceiveAppService = workerContext
|
|
// .ServiceProvider
|
|
// .GetRequiredService<QAD.IMessageReceiveAppService>();
|
|
// List<MessageReceiveDTO> incomingDataList = await messageReceiveAppService.GetListAsync();
|
|
|
|
// if (incomingDataList.Count == 0)
|
|
// {
|
|
// Logger.LogInformation("{SendLogTitieString}Can't find any file data...");
|
|
|
|
// return;
|
|
// }
|
|
|
|
// Logger.LogInformation($"{SendLogTitieString}:There are total {incomingDataList.Count} file data to be managed.");
|
|
|
|
// ;
|
|
// #endregion
|
|
|
|
// List<MesProductL7PartsNoteCreateInput> mesNotes = new List<MesProductL7PartsNoteCreateInput>();
|
|
|
|
// foreach (var mesIncomData in incomingDataList)
|
|
// {
|
|
// var inputList = ConvertToInputList(mesIncomData);
|
|
|
|
// mesNotes.AddRange(inputList);
|
|
// }
|
|
|
|
// #region 添加所有的L7零件信息
|
|
// //获取所有的L7零件信息,并获取零件是不是采购件、制造件
|
|
|
|
// var L7PartCodes = mesNotes.Select(p => p.L7Part).Distinct().ToList();
|
|
// Logger.LogInformation("{SendLogTitieString}Initial mesProductL7PartsNoteAppService...");
|
|
|
|
// #region 声明需要的服务信息
|
|
// //Resolve dependencies
|
|
// var mesProductL7PartsNoteAppService = workerContext
|
|
// .ServiceProvider
|
|
// .GetRequiredService<IMesProductL7PartsNoteAppService>();
|
|
|
|
// #endregion
|
|
// Logger.LogInformation("{SendLogTitieString}Initial mesProductL7PartsNoteAppService end...");
|
|
|
|
// await mesProductL7PartsNoteAppService.AddManyAsync(mesNotes);
|
|
|
|
// Logger.LogInformation("{SendLogTitieString}Initial mesProductL7PartsNoteAppService AddManyAsync end...");
|
|
|
|
// Logger.LogInformation("{SendLogTitieString}Initial itemBasicAppService ...");
|
|
|
|
// //Resolve dependencies
|
|
// var itemBasicAppService = workerContext
|
|
// .ServiceProvider
|
|
// .GetRequiredService<IItemBasicAppService>();
|
|
|
|
// Logger.LogInformation("{SendLogTitieString}Initial itemBasicAppService end...");
|
|
|
|
// //Do the work
|
|
|
|
// //var itemBaseList = await itemBasicAppService.GetByCodesAsync(L7PartCodes);
|
|
// //var itemBaseList = new List<ItemBasicDTO>();
|
|
|
|
// ItemBasicRequestInput requestInput = new ItemBasicRequestInput() { MaxResultCount = 99999 };
|
|
// if (L7PartCodes.Count > 0)
|
|
// {
|
|
// string partCodesStr = System.Text.Json.JsonSerializer.Serialize(L7PartCodes);
|
|
// requestInput.Condition.Filters.Add(new Sfs.Shared.Domain.Filter() { Action = EnumFilterAction.In.ToString(), Column = "Code", Logic = EnumFilterLogic.And.ToString(), Value = partCodesStr, });
|
|
// }
|
|
// //requestInput.MaxResultCount = 99999;
|
|
// var itemDtoListResult = await itemBasicAppService.GetListAsync(requestInput, false);
|
|
|
|
// var itemBaseList = itemDtoListResult.Items;
|
|
|
|
// #endregion
|
|
|
|
// //按照零件进行归总
|
|
// var sumEntityList = mesNotes.GroupBy(p => new { p.ProductNo, p.Program, p.FATA, p.Configuration, p.Position }).ToList();
|
|
|
|
// List<ProductL7PartsNoteCreateInput> noteList = new List<ProductL7PartsNoteCreateInput>();
|
|
|
|
// foreach (var sumEntity in sumEntityList)
|
|
// {
|
|
|
|
// #region 先是获取配置码的基本信息是否存在,存在就继续,不存在就先保存配置码信息,然后在进行后面的库存操作
|
|
|
|
// try
|
|
// {
|
|
// //先是获取配置码的基本信息是否存在,存在就继续,不存在就先保存配置码信息,然后在进行后面的库存操作.
|
|
// var item = await itemBasicAppService.GetByTypeAsync(sumEntity.Key.Configuration);
|
|
|
|
// if (item == null)
|
|
// {
|
|
// await InsertItemBasic(sumEntity.Key.Program, sumEntity.Key.ProductNo, sumEntity.Key.Configuration, sumEntity.Key.FATA, sumEntity.Key.Program, itemBasicAppService);
|
|
// }
|
|
// }
|
|
|
|
// catch (Volo.Abp.UserFriendlyException ex)
|
|
// {
|
|
|
|
// await InsertItemBasic(sumEntity.Key.Program, sumEntity.Key.ProductNo, sumEntity.Key.Configuration, sumEntity.Key.FATA, sumEntity.Key.Program, itemBasicAppService);
|
|
|
|
// }
|
|
|
|
// #endregion
|
|
|
|
// ProductL7PartsNoteCreateInput note = new ProductL7PartsNoteCreateInput()
|
|
// {
|
|
// ProductNo = sumEntity.Key.ProductNo,
|
|
// Program = sumEntity.Key.Program,
|
|
// FATA = sumEntity.Key.FATA,
|
|
// Configuration = sumEntity.Key.Configuration,
|
|
// Position = sumEntity.Key.Position,
|
|
// Details = new List<ProductL7PartsNoteDetailInput>(),
|
|
// };
|
|
|
|
// var detailList = mesNotes.Where(p => p.ProductNo == sumEntity.Key.ProductNo &&
|
|
// p.Program == sumEntity.Key.Program &&
|
|
// p.FATA == sumEntity.Key.FATA &&
|
|
// p.Configuration == sumEntity.Key.Configuration &&
|
|
// p.Position == sumEntity.Key.Position).ToList();
|
|
|
|
// foreach (var detail in detailList)
|
|
// {
|
|
|
|
// ProductL7PartsNoteDetailInput noteDetail = new ProductL7PartsNoteDetailInput()
|
|
|
|
// {
|
|
// ProductNo = sumEntity.Key.ProductNo,
|
|
// Program = sumEntity.Key.Program,
|
|
// FATA = sumEntity.Key.FATA,
|
|
// Configuration = sumEntity.Key.Configuration,
|
|
// Position = sumEntity.Key.Position,
|
|
// L7Part = detail.L7Part,
|
|
// ItemCode = detail.L7Part,
|
|
// State = detail.State,
|
|
// CreateDate = detail.CreateDate,
|
|
// Qty = detail.Qty,
|
|
// RowID = detail.RowID,
|
|
// };
|
|
|
|
// var itemBase = itemBaseList.FirstOrDefault(p => p.Code == detail.L7Part);
|
|
// if (itemBase == null)
|
|
// {
|
|
// //throw new Exception($"未找到零件{detail.L7PartCode}的零件基础信息,请确认基础信息是否齐全!");
|
|
|
|
// }
|
|
// else
|
|
// {
|
|
// noteDetail.CanMake = itemBase.CanMake;
|
|
// noteDetail.CanBuy = itemBase.CanBuy;
|
|
// }
|
|
|
|
// note.Details.AddIfNotContains(noteDetail);
|
|
// }
|
|
|
|
// noteList.Add(note);
|
|
// }
|
|
|
|
// Logger.LogInformation($"{SendLogTitieString}开始声明 IProductL7PartsNoteAppService...");
|
|
|
|
// //Resolve dependencies
|
|
// var productL7PartsNoteAppService = workerContext
|
|
// .ServiceProvider
|
|
// .GetRequiredService<IProductL7PartsNoteAppService>();
|
|
|
|
// Logger.LogInformation($"{SendLogTitieString}声明结束 IProductL7PartsNoteAppService...");
|
|
|
|
// Logger.LogInformation($"{SendLogTitieString}productL7PartsNoteAppService.CreateAsync," + productL7PartsNoteAppService.ToString());
|
|
|
|
// //保存相关L7零件信息
|
|
// await productL7PartsNoteAppService.CreateAsync(noteList);
|
|
// Logger.LogInformation($"{SendLogTitieString}productL7PartsNoteAppService.CreateAsync 结束");
|
|
|
|
// //更新读取的文件信息为已经归档
|
|
|
|
// var incomeDataIds = incomingDataList.Select(p => p.Id).ToList();
|
|
|
|
// Logger.LogInformation($"{SendLogTitieString}更新读取的文件信息为已经归档 开始...");
|
|
|
|
// await messageReceiveAppService.UpdateReceiveStatusByIdsAsync(incomeDataIds, EnumReceiveStatus.Archived);
|
|
// Logger.LogInformation($"{SendLogTitieString}更新读取的文件信息为已经归档完毕...");
|
|
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// string errorMsg = $"{SendLogTitieString}调用TransmissionMessageAsync方法出错,报文名称{fileName}:" + ex.Message;
|
|
// string errorMsg2 = $"{SendLogTitieString}调用TransmissionMessageAsync方法出错,报文名称{fileName}:" + ex.ToString();
|
|
// //_logRemindDomainService.WriteLogRemind(fileName, errorMsg, LogTypeEnum.M100);
|
|
// Logger.LogError(errorMsg);
|
|
// Logger.LogError(errorMsg2);
|
|
// }
|
|
|
|
// //Timer.Start(); //运行结束,开启计时
|
|
// Logger.LogInformation("{SendLogTitieString}Completed File Data Exchange...");
|
|
//}
|
|
|
|
#endregion
|
|
|
|
}
|
|
|