616 lines
30 KiB
C#
616 lines
30 KiB
C#
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
|
||
//
|
||
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
|
||
//
|
||
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
|
||
|
||
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;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using Vistar.Application.Common;
|
||
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>
|
||
/// 变更通知ECN服务
|
||
/// </summary>
|
||
[ApiDescriptionSettings(ApplicationConst.GroupName, Name = "ChangeNoticeEcn", Order = 100)]
|
||
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
|
||
|
||
)
|
||
{
|
||
_obj118Rep = obj118Rep;
|
||
_obj137Rep = obj137Rep;
|
||
_solidWorksManageService = solidWorksManageService;
|
||
_configurationDataRep = configurationDataRep;
|
||
_processesRequestItemsRep = processesRequestItemsRep;
|
||
_sysConfigService = sysConfigService;
|
||
_dataValidationService = dataValidationService;
|
||
_sapService = sapService;
|
||
|
||
}
|
||
/// <summary>
|
||
/// 分页查询变更通知ECN
|
||
/// </summary>
|
||
/// <param name="input"></param>
|
||
/// <returns></returns>
|
||
[ApiDescriptionSettings(Name = "page", Description = "分页查询", Order = 1000), HttpPost]
|
||
[DisplayName("分页查询变更通知ECN")]
|
||
public async Task<SqlSugarPagedList<ChangeNoticeEcnOutput>> Page(PageChangeNoticeEcnInput input)
|
||
{
|
||
var query = await _obj118Rep.AsQueryable()
|
||
.Where(x => x.CheckedStatus == 1 && x.deleted == false && x.IsLatestVersion == true && x._System_CurrentStage == "标准化审核")
|
||
.WhereIF(!string.IsNullOrWhiteSpace(input._System_objNBS), u => u._System_objNBS.Contains(input._System_objNBS.Trim()))
|
||
.WhereIF(input.fld004693Range != null && input.fld004693Range.Length == 2, u => u.fld004693 >= input.fld004693Range[0] && u.fld004693 <= input.fld004693Range[1])
|
||
.Select<ChangeNoticeEcnOutput>()
|
||
.ToPagedListAsync(input.Page, input.PageSize);
|
||
return query;
|
||
}
|
||
/// <summary>
|
||
/// 变更通知ECN-同步到 SAP
|
||
/// </summary>
|
||
/// <param name="input"></param>
|
||
/// <returns></returns>
|
||
[ApiDescriptionSettings(Name = "syncToSAP"), HttpPost]
|
||
[DisplayName("变更通知ECN-同步到 SAP")]
|
||
public async Task<SapOutput> SyncToSAP(ChangeNoticeEcnInput input)
|
||
{
|
||
//获取时间戳精确到毫秒,sap要求每次调用生成不重复guid
|
||
string millisecondTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
|
||
var sapEcnInput = new SapEcnInput()
|
||
{
|
||
Reqkeyid = "",
|
||
Businessid = "",
|
||
Messageid = "",
|
||
Sndprn = "PLM",
|
||
Rcvprn = "SAP",
|
||
Requser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName),
|
||
Note1 = "",
|
||
Note2 = "",
|
||
Note3 = "",
|
||
|
||
Aennr = input._System_objNBS,
|
||
Aetxt = input._System_ObjDescription,
|
||
Datuv = input.fld004693.ToDateTime().ToString("yyyy-MM-dd"),
|
||
Lvorm = input.fld004694,
|
||
ItemList = await _dataValidationService.ChangeModuleMaterial(input.idRecord)
|
||
};
|
||
|
||
var apiOutput = await _sapService.SapEcnApi(sapEcnInput);
|
||
string codeVal = apiOutput.code == "S" ? "成功" : "失败";
|
||
var msg = apiOutput.msg;
|
||
if (apiOutput.msg == "" && apiOutput.code == "S")
|
||
{
|
||
msg = "同步成功";
|
||
}
|
||
|
||
await _obj118Rep.AsUpdateable()
|
||
.SetColumns(it => new Obj118
|
||
{
|
||
fld005293 = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
|
||
fld005294 = codeVal,
|
||
fld005292 = "N",
|
||
fld005295 = msg
|
||
})
|
||
.Where(it => it.idRecord == input.idRecord)
|
||
.ExecuteCommandAsync();
|
||
var output = new SapOutput()
|
||
{
|
||
parameter = apiOutput.parameter,
|
||
code = codeVal,
|
||
msg = msg,
|
||
result = apiOutput.result
|
||
};
|
||
return output;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 变更通知ECN-批量同步到SAP
|
||
/// </summary>
|
||
/// <param name="input"></param>
|
||
/// <returns></returns>
|
||
[ApiDescriptionSettings(Name = "BatchSyncToSAP"), HttpPost]
|
||
[DisplayName("变更通知ECN-批量同步到SAP")]
|
||
public async Task<List<SapOutput>> BatchSyncToSAP(List<ChangeNoticeEcnInput> input)
|
||
{
|
||
|
||
var SapOutputList = new List<SapOutput>();
|
||
var Requser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName);
|
||
for (int i = 0; i < input.Count; i++)
|
||
{
|
||
//获取时间戳精确到毫秒,sap要求每次调用生成不重复guid
|
||
string millisecondTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
|
||
|
||
var sapEcnInput = new SapEcnInput()
|
||
{
|
||
Reqkeyid = "",
|
||
Businessid = "",
|
||
Messageid = "",
|
||
Sndprn = "PLM",
|
||
Rcvprn = "SAP",
|
||
Requser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName),
|
||
Note1 = "",
|
||
Note2 = "",
|
||
Note3 = "",
|
||
|
||
Aennr = input[i]._System_objNBS,
|
||
Aetxt = input[i]._System_ObjDescription,
|
||
Datuv = input[i].fld004693.ToDateTime().ToString("yyyy-MM-dd"),
|
||
Lvorm = input[i].fld004694,
|
||
ItemList = await _dataValidationService.ChangeModuleMaterial(input[i].idRecord)
|
||
};
|
||
var apiOutput = await _sapService.SapEcnApi(sapEcnInput);
|
||
string codeVal = apiOutput.code == "S" ? "成功" : "失败";
|
||
var msg = apiOutput.msg;
|
||
if (apiOutput.msg == "" && apiOutput.code == "S")
|
||
{
|
||
msg = "同步成功";
|
||
}
|
||
await _obj118Rep.AsUpdateable()
|
||
.SetColumns(it => new Obj118
|
||
{
|
||
fld005293 = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
|
||
fld005294 = codeVal,
|
||
fld005292 = "N",
|
||
fld005295 = msg
|
||
})
|
||
.Where(it => it.idRecord == input[i].idRecord)
|
||
.ExecuteCommandAsync();
|
||
var output = new SapOutput()
|
||
{
|
||
parameter = apiOutput.parameter,
|
||
code = codeVal,
|
||
msg = msg,
|
||
result = apiOutput.result
|
||
};
|
||
SapOutputList.Add(output);
|
||
}
|
||
|
||
return SapOutputList;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 变更通知ECN-定时同步到SAP
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[ApiDescriptionSettings(Name = "TimingSyncToSAP"), HttpGet]
|
||
[DisplayName("变更通知ECN-定时同步到SAP")]
|
||
[AllowAnonymous]
|
||
public async Task<List<SapOutput>> TimingSyncToSAP()
|
||
{
|
||
var input = await _obj118Rep.AsQueryable()
|
||
.Where(x => x.CheckedStatus == 1 && x._System_CurrentStage == "标准化审核" && x.deleted == false && x.IsLatestVersion == true && x.fld005292 == "A")
|
||
.ToListAsync();
|
||
var SapOutputList = new List<SapOutput>();
|
||
var Requser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName);
|
||
for (int i = 0; i < input.Count; i++)
|
||
{
|
||
//获取时间戳精确到毫秒,sap要求每次调用生成不重复guid
|
||
string millisecondTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
|
||
|
||
var sapEcnInput = new SapEcnInput()
|
||
{
|
||
Reqkeyid = "",
|
||
Businessid = "",
|
||
Messageid = "",
|
||
Sndprn = "PLM",
|
||
Rcvprn = "SAP",
|
||
Requser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName),
|
||
Note1 = "",
|
||
Note2 = "",
|
||
Note3 = "",
|
||
|
||
Aennr = input[i]._System_objNBS,
|
||
Aetxt = input[i]._System_ObjDescription,
|
||
Datuv = input[i].fld004693.ToDateTime().ToString("yyyy-MM-dd"),
|
||
Lvorm = input[i].fld004694,
|
||
ItemList = await _dataValidationService.ChangeModuleMaterial(input[i].idRecord)
|
||
};
|
||
var apiOutput = await _sapService.SapEcnApi(sapEcnInput);
|
||
string codeVal = apiOutput.code == "S" ? "成功" : "失败";
|
||
var msg = apiOutput.msg;
|
||
if (apiOutput.msg == "" && apiOutput.code == "S")
|
||
{
|
||
msg = "同步成功";
|
||
}
|
||
await _obj118Rep.AsUpdateable()
|
||
.SetColumns(it => new Obj118
|
||
{
|
||
fld005293 = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
|
||
fld005294 = codeVal,
|
||
fld005292 = "N",
|
||
fld005295 = msg
|
||
})
|
||
.Where(it => it.idRecord == input[i].idRecord)
|
||
.ExecuteCommandAsync();
|
||
var output = new SapOutput()
|
||
{
|
||
parameter = apiOutput.parameter,
|
||
code = codeVal,
|
||
msg = msg,
|
||
result = apiOutput.result
|
||
};
|
||
SapOutputList.Add(output);
|
||
}
|
||
|
||
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 = bomChange[i].QtyManual.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();
|
||
}
|
||
|
||
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 versionChange = await _dataValidationService.ComparativeVersion(bomChangeVersion[i].ChildObjID, bomListChildGuid, (int)bomListItem.childVersion, (int)bomChangeVersion[i].childVersion);
|
||
if (string.IsNullOrWhiteSpace(versionChange))
|
||
{
|
||
continue;
|
||
}
|
||
//创建子项
|
||
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 = 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 "对比完成,请到前端查看结果";
|
||
}
|
||
}
|