😎新增生成ECN差异清单接口

This commit is contained in:
bairubing 2024-11-29 09:42:27 +08:00
parent 8334e96164
commit 9b82e073d4
3 changed files with 381 additions and 0 deletions

View File

@ -607,4 +607,17 @@ public class ConfigurationData
public string fld006145 { get; set; }
public string fld006146 { get; set; }
public string fld006147 { get; set; }
public string fld006567 { get; set; }
public string fld006581 { get; set; }
public string fld006565 { get; set; }
/// <summary>
/// 变更前数量
/// </summary>
public string fld006564 { get; set; }
/// <summary>
/// 变更后数据
/// </summary>
public string fld006566 { get; set; }
public string fld006586 { get; set; }
}

View File

@ -282,4 +282,22 @@ public class Obj118
/// </summary>
[SugarColumn(ColumnName = "fld005295", ColumnDescription = "", Length = -1)]
public string? fld005295 { get; set; }
/// <summary>
///
/// </summary>
[SugarColumn(ColumnName = "fld006576", ColumnDescription = "", Length = -1)]
public string? fld006576 { get; set; }
/// <summary>
///
/// </summary>
[SugarColumn(ColumnName = "fld006577", ColumnDescription = "", Length = -1)]
public string? fld006577 { get; set; }
/// <summary>
///
/// </summary>
[SugarColumn(ColumnName = "fld006578", ColumnDescription = "", Length = -1)]
public string? fld006578 { get; set; }
}

View File

@ -6,10 +6,14 @@
using Admin.NET.Core;
using Admin.NET.Core.Service;
using DocumentFormat.OpenXml.Drawing.Charts;
using DocumentFormat.OpenXml.Spreadsheet;
using DocumentFormat.OpenXml.Wordprocessing;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using RazorEngine;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@ -21,7 +25,11 @@ using Vistar.Application.Const;
using Vistar.Application.Entity;
using Vistar.Application.SapService.Dto;
using Vistar.Application.Service.ChangeNoticeEcn.Dto;
using Vistar.Application.SolidWorksManageService.Dto;
using Vistar.Application.Util;
using static COSXML.Model.Tag.DeleteResult;
using static Microsoft.CodeAnalysis.AssemblyIdentityComparer;
using static SKIT.FlurlHttpClient.Wechat.TenpayV3.Models.CreateMerchantStoreRequest.Types;
namespace Vistar.Application.Service.ChangeNoticeEcn;
/// <summary>
@ -31,12 +39,20 @@ namespace Vistar.Application.Service.ChangeNoticeEcn;
public class ChangeNoticeEcnService : IDynamicApiController, ITransient
{
public SqlSugarRepository<Obj118> _obj118Rep;
public SqlSugarRepository<Obj137> _obj137Rep;
public SolidWorksManageService.SolidWorksManageService _solidWorksManageService;
public SqlSugarRepository<ConfigurationData> _configurationDataRep;
public SqlSugarRepository<ProcessesRequestItems> _processesRequestItemsRep;
private readonly SysConfigService _sysConfigService;
public Common.DataValidationService _dataValidationService;
public SapService.SapService _sapService;
public ChangeNoticeEcnService(
SqlSugarRepository<Obj118> obj118Rep,
SqlSugarRepository<Obj137> obj137Rep,
SolidWorksManageService.SolidWorksManageService solidWorksManageService,
SqlSugarRepository<ConfigurationData> configurationDataRep,
SqlSugarRepository<ProcessesRequestItems> processesRequestItemsRep,
SysConfigService sysConfigService,
DataValidationService dataValidationService,
SapService.SapService sapService
@ -44,6 +60,10 @@ public class ChangeNoticeEcnService : IDynamicApiController, ITransient
)
{
_obj118Rep = obj118Rep;
_obj137Rep = obj137Rep;
_solidWorksManageService = solidWorksManageService;
_configurationDataRep = configurationDataRep;
_processesRequestItemsRep = processesRequestItemsRep;
_sysConfigService = sysConfigService;
_dataValidationService = dataValidationService;
_sapService = sapService;
@ -256,4 +276,334 @@ public class ChangeNoticeEcnService : IDynamicApiController, ITransient
return SapOutputList;
}
/// <summary>
/// 生成ECN差异清单
/// </summary>
/// <returns></returns>
public async Task<string> EcnVarianceList()
{
//获取符合条件的变更通知Ecn数据
var list = await _obj118Rep.AsQueryable()
.Where(x => x.CheckedStatus == 1 && x.deleted == false && x.fld006576 == "A" && x._System_CurrentStage == "差异清单对比中" && x.IsLatestVersion == true)
.ToListAsync();
//分组查询获取最大id的数据
var ecnList = list.GroupBy(x => x.RecordGuid)
.Select(group => group.OrderByDescending(item => item.idRecord).First())
.ToList();
foreach (var ecnListItem in ecnList)
{
//ecn表对比结果
var ecnComparisonResult = "成功";
//条目对比结果
var itemComparisonResult = "成功";
var ecnRecordGuid = ecnListItem.RecordGuid;
//最新id
var ecnidRecord = ecnListItem.idRecord;
//最新版本
var ecnVersionIndex = ecnListItem.VersionIndex;
//获取条目记录
var listOfDrawing = await _processesRequestItemsRep.AsQueryable()
.Where(x => x.ProcObjId == 118 && x.fld006573 == "A" && x.ProcRecGuid == ecnRecordGuid)
.ToListAsync();
foreach (var listOfDrawingItem in listOfDrawing)
{
var listOfDrawingRecordGuid = listOfDrawingItem.RecordGuid;
var listOfDrawingRequestItemsId = listOfDrawingItem.RequestItemsId;
//获取137表记录
var recordData = await _obj137Rep.AsQueryable()
.Where(x => x.RecordGuid == listOfDrawingRecordGuid && x.SWPDMConfigurationName == "默认" && x.deleted == false && !string.IsNullOrEmpty(x.fld005686)).OrderByDescending(x => x.idRecord)
.FirstAsync();
if (recordData == null)
{
continue;
}
var recordRecordGuid = recordData.RecordGuid;
var recordVersionIndex = recordData.VersionIndex;
//同步版本
var fld005686 = recordData.fld005686;
var OrderIndex = await _dataValidationService.GetLineNumber(118, ecnRecordGuid, (int)ecnVersionIndex, 14) + 1;
var BOMGuid = await _dataValidationService.GetGuid();
//新增父项
var parentBom = new ConfigurationData
{
ParentGuid = ecnRecordGuid,
ChildGuid = recordRecordGuid,
ChildObjID = 137,//逻辑写死后期根据需求更改
ConfigId = 14,
childVersion = recordVersionIndex,
ParentVersion = (int)ecnVersionIndex,
isDeleted = false,
Quantity = 1,
Description = recordData._System_ObjDescription,
OrderIndex = OrderIndex,
PartNumber = recordData._System_objNBS,
BOMGuid = BOMGuid,
fld006567 = "父项",
CreatedDate = DateTime.Now,
ModifiedDate = DateTime.Now,
EffectiveFrom = DateTime.Now,
EffectiveTo = DateTime.Now.AddYears(100),
ChildSwFileType = 1,//记录属于137PDM库的默认1 属性112原材料库默认 0
ParentSwFileType = -1,
ParentObjectID=118,
CreatedUserID=2,
ModifiedUserID=2,
ChildConfigID=8,
isAddedFromSW=true
};
var addParentBom = await _configurationDataRep.AsInsertable(parentBom)
.InsertColumns(x=> new { x.ParentGuid, x.ChildGuid, x.ChildObjID, x.ConfigId, x.childVersion, x.ParentVersion, x.isDeleted, x.Quantity, x.Description, x.OrderIndex, x.PartNumber, x.BOMGuid, x.fld006567, x.CreatedDate, x.ModifiedDate, x.EffectiveFrom, x.EffectiveTo, x.ChildSwFileType, x.ParentSwFileType,x.ParentObjectID, x.CreatedUserID ,x.ModifiedUserID,x.ChildConfigID,x.isAddedFromSW })
.ExecuteReturnEntityAsync();
//当前版本BOM
var bomList = await _configurationDataRep.AsQueryable().Where(x => x.ParentGuid == recordRecordGuid && x.ParentVersion == recordVersionIndex && x.isDeleted == false && x.ConfigId == 8 && (x.fld005577 != "不包含" || x.fld005577 == null) && x.isSuppressed == false && x.inContext == false).ToListAsync();
//旧版本BOM
var historyBomList = await _configurationDataRep.AsQueryable().Where(x => x.ParentGuid == recordRecordGuid && x.ParentVersion == Convert.ToInt32(fld005686) && x.isDeleted == false && x.ConfigId == 8 && (x.fld005577 != "不包含" || x.fld005577 == null) && x.isSuppressed == false && x.inContext == false).ToListAsync();
//遍历新BOM
foreach (var bomListItem in bomList)
{
var bomListQuantity = bomListItem.QtyManual;
var bomListChildGuid = bomListItem.ChildGuid;
var bomListChildObjID = bomListItem.ChildObjID;
var ChildConfigID = 8;
if (bomListChildObjID == 112)
{
ChildConfigID = 0;
}
//记录属于137PDM库的默认1 属性112原材料库默认 0
int ChildSwFileType = 1;
if (bomListChildObjID == 112)
{
ChildSwFileType = 0;
}
//BOM对比-修改
var bomChange = historyBomList.Where(x => x.ChildGuid == bomListChildGuid && x.QtyManual != bomListQuantity).ToList();
for (var i = 0; i < bomChange.Count; i++)
{
var versionChange = "";
if (bomListItem.childVersion== bomChange[i].childVersion)
{
var contrastResult = await _dataValidationService.ComparativeVersion(bomChange[i].ChildObjID, bomListChildGuid, (int)bomListItem.childVersion,(int)bomChange[i].childVersion);
versionChange = contrastResult;
}
//创建子项
var childBom = new ConfigurationData
{
ParentGuid = ecnRecordGuid,
ChildGuid = bomListChildGuid,
ChildObjID = bomListChildObjID,
ConfigId = 14,
childVersion = bomListItem.childVersion,
ParentVersion = (int)ecnVersionIndex,
isDeleted = false,
Quantity = 1,
Description = bomListItem.Description,
OrderIndex = await _dataValidationService.GetLineNumber(118, ecnRecordGuid, (int)ecnVersionIndex, 14) + 1,
PartNumber = bomListItem.PartNumber,
BOMGuid = await _dataValidationService.GetGuid(),
CreatedDate = DateTime.Now,
ModifiedDate = DateTime.Now,
EffectiveFrom = DateTime.Now,
EffectiveTo = DateTime.Now.AddYears(100),
ChildSwFileType = ChildSwFileType,
ParentSwFileType = -1,
ParentObjectID = 118,
CreatedUserID = 2,
ModifiedUserID = 2,
ChildConfigID = ChildConfigID,
isAddedFromSW=true,
fld006586= versionChange,
fld006567 = "子项",
fld006581 = recordData._System_objNBS,
fld006565 = "修改",
fld006564 = bomListQuantity.ToString(),
fld006566 = bomChange[i].QtyManual.ToString()
};
var addChildBomBom = await _configurationDataRep.AsInsertable(childBom).InsertColumns(x => new{ x.ParentGuid, x.ChildGuid, x.ChildObjID, x.ConfigId, x.childVersion, x.ParentVersion, x.isDeleted, x.Quantity, x.Description, x.OrderIndex, x.PartNumber, x.BOMGuid, x.CreatedDate, x.ModifiedDate, x.EffectiveFrom, x.EffectiveTo, x.ChildSwFileType, x.ParentSwFileType, x.ParentObjectID, x.CreatedUserID, x.ModifiedUserID, x.ChildConfigID, x.fld006567, x.fld006581, x.fld006565, x.fld006564, x.fld006566,x.isAddedFromSW,x.fld006586 }).ExecuteReturnEntityAsync();
}
var bomChangeVersion = historyBomList.Where(x => x.ChildGuid == bomListChildGuid && x.QtyManual == bomListQuantity && x.childVersion!= bomListItem.childVersion).ToList();
for (var i = 0; i < bomChangeVersion.Count; i++)
{
//创建子项
var childBom = new ConfigurationData
{
ParentGuid = ecnRecordGuid,
ChildGuid = bomListChildGuid,
ChildObjID = bomListChildObjID,
ConfigId = 14,
childVersion = bomListItem.childVersion,
ParentVersion = (int)ecnVersionIndex,
isDeleted = false,
Quantity = 1,
Description = bomListItem.Description,
OrderIndex = await _dataValidationService.GetLineNumber(118, ecnRecordGuid, (int)ecnVersionIndex, 14) + 1,
PartNumber = bomListItem.PartNumber,
BOMGuid = await _dataValidationService.GetGuid(),
CreatedDate = DateTime.Now,
ModifiedDate = DateTime.Now,
EffectiveFrom = DateTime.Now,
EffectiveTo = DateTime.Now.AddYears(100),
ChildSwFileType = ChildSwFileType,
ParentSwFileType = -1,
ParentObjectID = 118,
CreatedUserID = 2,
ModifiedUserID = 2,
ChildConfigID = ChildConfigID,
isAddedFromSW = true,
fld006586 = await _dataValidationService.ComparativeVersion(bomChange[i].ChildObjID, bomListChildGuid, (int)bomListItem.childVersion, (int)bomChange[i].childVersion),
fld006567 = "子项",
fld006581 = recordData._System_objNBS,
fld006565 = "修改",
fld006564 = bomListQuantity.ToString(),
fld006566 = bomListQuantity.ToString()
};
var addChildBomBom = await _configurationDataRep.AsInsertable(childBom).InsertColumns(x => new { x.ParentGuid, x.ChildGuid, x.ChildObjID, x.ConfigId, x.childVersion, x.ParentVersion, x.isDeleted, x.Quantity, x.Description, x.OrderIndex, x.PartNumber, x.BOMGuid, x.CreatedDate, x.ModifiedDate, x.EffectiveFrom, x.EffectiveTo, x.ChildSwFileType, x.ParentSwFileType, x.ParentObjectID, x.CreatedUserID, x.ModifiedUserID, x.ChildConfigID, x.fld006567, x.fld006581, x.fld006565, x.fld006564, x.fld006566, x.isAddedFromSW ,x.fld006586 }).ExecuteReturnEntityAsync();
}
//BOM对比-新增
var bomAdd = historyBomList.Where(x => x.ChildGuid == bomListChildGuid).ToList();
if (bomAdd.Count == 0)
{
//创建子项
var childBom = new ConfigurationData
{
ParentGuid = ecnRecordGuid,
ChildGuid = bomListChildGuid,
ChildObjID = bomListChildObjID,
ConfigId = 14,
childVersion = bomListItem.childVersion,
ParentVersion = (int)ecnVersionIndex,
isDeleted = false,
Quantity = 1,
Description = bomListItem.Description,
OrderIndex = await _dataValidationService.GetLineNumber(118, ecnRecordGuid, (int)ecnVersionIndex, 14) + 1,
PartNumber = bomListItem.PartNumber,
BOMGuid = await _dataValidationService.GetGuid(),
CreatedDate = DateTime.Now,
ModifiedDate = DateTime.Now,
EffectiveFrom = DateTime.Now,
EffectiveTo = DateTime.Now.AddYears(100),
ChildSwFileType = ChildSwFileType,
ParentSwFileType = -1,
ParentObjectID = 118,
CreatedUserID = 2,
ModifiedUserID = 2,
ChildConfigID = ChildConfigID,
isAddedFromSW = true,
fld006567 = "子项",
fld006581 = recordData._System_objNBS,
fld006565 = "新增",
fld006564 = "0",
fld006566 = bomListQuantity.ToString()
};
var addChildBomBom = await _configurationDataRep.AsInsertable(childBom).InsertColumns(x => new { x.ParentGuid, x.ChildGuid, x.ChildObjID, x.ConfigId, x.childVersion, x.ParentVersion, x.isDeleted, x.Quantity, x.Description, x.OrderIndex, x.PartNumber, x.BOMGuid, x.CreatedDate, x.ModifiedDate, x.EffectiveFrom, x.EffectiveTo, x.ChildSwFileType, x.ParentSwFileType, x.ParentObjectID, x.CreatedUserID, x.ModifiedUserID, x.ChildConfigID, x.fld006567, x.fld006581, x.fld006565, x.fld006564, x.fld006566 ,x.isAddedFromSW }).ExecuteReturnEntityAsync();
}
}
//BOM对比-删除
foreach (var historyBomListItem in historyBomList)
{
var historyBomQuantity = historyBomListItem.QtyManual;
var historyBomChildGuid = historyBomListItem.ChildGuid;
var historyBomChildObjID = historyBomListItem.ChildObjID;
var ChildConfigID = 8;
if (historyBomChildObjID == 112)
{
ChildConfigID = 0;
}
//记录属于137PDM库的默认1 属性112原材料库默认 0
int ChildSwFileType = 1;
if (historyBomChildObjID == 112)
{
ChildSwFileType = 0;
}
var deleteListData = bomList.Where(x => x.ChildGuid == historyBomChildGuid).ToList();
if (deleteListData.Count == 0)
{
//创建子项
var childBom = new ConfigurationData
{
ParentGuid = ecnRecordGuid,
ChildGuid = historyBomChildGuid,
ChildObjID = historyBomChildObjID,
ConfigId =14,
childVersion = historyBomListItem.childVersion,
ParentVersion = (int)ecnVersionIndex,
isDeleted = false,
Quantity = 1,
Description = historyBomListItem.Description,
OrderIndex = await _dataValidationService.GetLineNumber(118, ecnRecordGuid, (int)ecnVersionIndex, 14) + 1,
PartNumber = historyBomListItem.PartNumber,
BOMGuid = await _dataValidationService.GetGuid(),
CreatedDate = DateTime.Now,
ModifiedDate = DateTime.Now,
EffectiveFrom = DateTime.Now,
EffectiveTo = DateTime.Now.AddYears(100),
ChildSwFileType = ChildSwFileType,
ParentSwFileType = -1,
ParentObjectID = 118,
CreatedUserID = 2,
ModifiedUserID = 2,
ChildConfigID = ChildConfigID,
isAddedFromSW=true,
fld006567 = "子项",
fld006581 = recordData._System_objNBS,
fld006565 = "删除",
fld006564 = historyBomQuantity.ToString(),
fld006566 = "0"
};
var addChildBomBom = await _configurationDataRep.AsInsertable(childBom).InsertColumns(x => new { x.ParentGuid, x.ChildGuid, x.ChildObjID, x.ConfigId, x.childVersion, x.ParentVersion, x.isDeleted, x.Quantity, x.Description, x.OrderIndex, x.PartNumber, x.BOMGuid, x.CreatedDate, x.ModifiedDate, x.EffectiveFrom, x.EffectiveTo, x.ChildSwFileType, x.ParentSwFileType, x.ParentObjectID, x.CreatedUserID, x.ModifiedUserID, x.ChildConfigID, x.fld006567, x.fld006581, x.fld006565, x.fld006564, x.fld006566,x.isAddedFromSW }).ExecuteReturnEntityAsync();
}
}
await _processesRequestItemsRep.AsUpdateable()
.SetColumns(it => new ProcessesRequestItems
{
fld006574 = itemComparisonResult,
fld006575 = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"),
fld006573 = "N"
})
.Where(it => it.RequestItemsId == listOfDrawingRequestItemsId)
.ExecuteCommandAsync();
ecnComparisonResult = ecnComparisonResult + itemComparisonResult;
}
await _obj118Rep.AsUpdateable()
.SetColumns(it => new Obj118
{
fld006577 = ecnComparisonResult,
fld006578 = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"),
fld006576 = "N"
})
.Where(it => it.idRecord == ecnListItem.idRecord)
.ExecuteCommandAsync();
}
return "对比完成,请到前端查看结果";
}
}