1728 lines
69 KiB
C#
1728 lines
69 KiB
C#
using Admin.NET.Core;
|
||
using Admin.NET.Core.Service;
|
||
using COSXML.Network;
|
||
using Elastic.Clients.Elasticsearch;
|
||
using Furion.DependencyInjection;
|
||
using Furion.DynamicApiController;
|
||
using Microsoft.AspNetCore.Authorization;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
using Microsoft.Extensions.Configuration;
|
||
using Microsoft.Extensions.DependencyInjection;
|
||
using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
|
||
using RazorEngine;
|
||
using SqlSugar;
|
||
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.MaterialManagement.Dto;
|
||
using Vistar.Application.Service.ProjectManagement.Dto;
|
||
using Vistar.Application.Util;
|
||
|
||
namespace Vistar.Application.Service.ProjectManagement;
|
||
/// <summary>
|
||
/// 项目管理服务
|
||
/// </summary>
|
||
[ApiDescriptionSettings(ApplicationConst.GroupName, Name = "ProjectManagement", Order = 100)]
|
||
public class ProjectManagementService : IDynamicApiController, ITransient
|
||
{
|
||
private readonly SqlSugarRepository<Obj109> _obj109Rep;
|
||
private readonly SysConfigService _sysConfigService;
|
||
public SapService.SapService _sapService;
|
||
private readonly SqlSugarRepository<Configurations> _configurationsRep;
|
||
private readonly SqlSugarRepository<ConfigurationData> _configurationDataRep;
|
||
public SqlSugarRepository<Obj118> _obj118Rep;
|
||
public Common.DataValidationService _dataValidationService;
|
||
public SqlSugarRepository<Obj122> _obj122Rep;
|
||
public SqlSugarRepository<Obj121> _obj121Rep;
|
||
public SqlSugarRepository<Obj126> _obj126Rep;
|
||
public SqlSugarRepository<CasesStagesMain> _casesStagesMainRep;
|
||
private readonly IServiceScopeFactory _scopeFactory;
|
||
|
||
public ProjectManagementService(
|
||
SqlSugarRepository<Obj109> obj109Rep,
|
||
SysConfigService sysConfigService,
|
||
SapService.SapService sapService,
|
||
SqlSugarRepository<Configurations> configurationsRep,
|
||
SqlSugarRepository<ConfigurationData> configurationDataRep,
|
||
SqlSugarRepository<Obj118> obj118Rep,
|
||
DataValidationService dataValidationService,
|
||
SqlSugarRepository<Obj122> obj122Rep,
|
||
SqlSugarRepository<Obj121> obj121Rep,
|
||
SqlSugarRepository<Obj126> obj126Rep,
|
||
SqlSugarRepository<CasesStagesMain> casesStagesMainRep,
|
||
IServiceScopeFactory scopeFactory
|
||
)
|
||
{
|
||
_obj109Rep = obj109Rep;
|
||
_sysConfigService = sysConfigService;
|
||
_sapService = sapService;
|
||
_configurationsRep = configurationsRep;
|
||
_configurationDataRep = configurationDataRep;
|
||
_obj118Rep = obj118Rep;
|
||
_dataValidationService = dataValidationService;
|
||
_obj122Rep = obj122Rep;
|
||
_obj121Rep = obj121Rep;
|
||
_obj126Rep = obj126Rep;
|
||
_casesStagesMainRep = casesStagesMainRep;
|
||
_scopeFactory = scopeFactory;
|
||
}
|
||
/// <summary>
|
||
/// 分页查询项目管理
|
||
/// </summary>
|
||
/// <param name="input"></param>
|
||
/// <returns></returns>
|
||
[ApiDescriptionSettings(Name = "page", Description = "分页查询", Order = 1000), HttpPost]
|
||
[DisplayName("分页查询项目管理")]
|
||
public async Task<SqlSugarPagedList<ProjectManagementOutput>> Page(PageProjectManagementInput input)
|
||
{
|
||
var query = await _obj109Rep.AsQueryable()
|
||
.Where(x => (x.CheckedStatus == 0 || x.CheckedStatus == 1) && x.deleted == false && x.IsLatestVersion == true && x.fld005040 == "发布")
|
||
.WhereIF(!string.IsNullOrWhiteSpace(input._System_objNBS), u => u._System_objNBS.Contains(input._System_objNBS.Trim()))
|
||
.WhereIF(!string.IsNullOrWhiteSpace(input.fld004502), u => u.fld004502.Contains(input.fld004502.Trim()))
|
||
.WhereIF(input.fld004683Range != null && input.fld004683Range.Length == 2, u => u.fld004683 >= input.fld004683Range[0] && u.fld004683 <= input.fld004683Range[1])
|
||
.Select<ProjectManagementOutput>()
|
||
.ToPagedListAsync(input.Page, input.PageSize);
|
||
return query;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 项目管理-同步到 SAP
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[ApiDescriptionSettings(Name = "syncToSAP"), HttpPost]
|
||
[DisplayName("项目管理-同步到 SAP")]
|
||
public async Task<SapOutput> SyncToSAP(ProjectManagementInput input)
|
||
{
|
||
const string lengthError = "项目描述长度大于40,请检查!";
|
||
|
||
// 验证物料描述长度
|
||
if (input.fld004502.Length > 40)
|
||
{
|
||
await _obj109Rep.AsUpdateable()
|
||
.SetColumns(it => new Obj109
|
||
{
|
||
fld004508 = DateTime.Now,
|
||
fld004510 = "N",
|
||
fld004507 = lengthError,
|
||
fld004509 = "失败"
|
||
})
|
||
.Where(it => it.idRecord == input.idRecord)
|
||
.ExecuteCommandAsync().ConfigureAwait(false);
|
||
|
||
return new SapOutput
|
||
{
|
||
code = "失败",
|
||
msg = lengthError,
|
||
result = lengthError
|
||
};
|
||
}
|
||
|
||
//获取时间戳精确到毫秒,sap要求每次调用生成不重复guid
|
||
string millisecondTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
|
||
Random random = new Random();
|
||
// 生成1000到9999之间的随机数
|
||
string randomNumber = random.Next(1000, 10000).ToString();
|
||
millisecondTimestamp = millisecondTimestamp + randomNumber;
|
||
|
||
var sapMaterialInput = new SapMaterialInput()
|
||
{
|
||
Reqkeyid = "",
|
||
Businessid = "",
|
||
Messageid = "",
|
||
Sndprn = "PLM",
|
||
Rcvprn = "SAP",
|
||
Requser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName),
|
||
Note1 = "",
|
||
Note2 = "",
|
||
Note3 = "",
|
||
Zwbid = millisecondTimestamp,
|
||
Matnr = input._System_objNBS,
|
||
Mbrsh = input.fld004521,
|
||
Mtart = input.fld004519,
|
||
Maktx = input.fld004502,
|
||
Meins = input.fld005281,
|
||
Matkl = input.fld004520,
|
||
Bismt = input.fld004686,
|
||
Groes = input.fld004685,
|
||
Normt = input.fld004924,
|
||
Ferth = input.fld004925,
|
||
Zeinr = input.fld004926,
|
||
Mstae = input.fld004927,
|
||
Raube = input.fld004932,
|
||
Mhdrz = input.fld004933.ToString(),
|
||
Mhdhb = input.fld004934.ToString(),
|
||
Werks = input.fld004522,
|
||
Beskz = input.fld004928,
|
||
Sobsl = input.fld004929,
|
||
Schgt = input.fld004930,
|
||
Rgekz = input.fld004931,
|
||
Zbom = input.fld004935
|
||
};
|
||
|
||
var apiOutput = await _sapService.SapMaterialApi(sapMaterialInput);
|
||
string codeVal = apiOutput.code == "S" ? "成功" : "失败";
|
||
var msg = apiOutput.msg;
|
||
if (apiOutput.msg == "")
|
||
{
|
||
msg = "同步成功";
|
||
}
|
||
|
||
await _obj109Rep.AsUpdateable()
|
||
.SetColumns(it => new Obj109
|
||
{
|
||
fld004508 = DateTime.Now,
|
||
fld004507 = msg,
|
||
fld004509 = codeVal,
|
||
fld004510 = "N"
|
||
})
|
||
.Where(it => it.idRecord == input.idRecord)
|
||
.ExecuteCommandAsync();
|
||
var output = new SapOutput()
|
||
{
|
||
parameter = apiOutput.parameter,
|
||
code = codeVal,
|
||
msg = msg,
|
||
result = apiOutput.result
|
||
};
|
||
return output;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 项目管理-批量同步到SAP
|
||
/// </summary>
|
||
/// <param name="input"></param>
|
||
/// <returns></returns>
|
||
[ApiDescriptionSettings(Name = "BatchSyncToSAP"), HttpPost]
|
||
[DisplayName("项目管理-批量同步到SAP")]
|
||
public async Task<List<SapOutput>> BatchSyncToSAP(List<ProjectManagementInput> input)
|
||
{
|
||
const string lengthError = "物料描述长度大于40,请检查!";
|
||
const string synchronized = "该项目编号已同步或已停用!";
|
||
var SapOutputList = new List<SapOutput>();
|
||
var Requser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName);
|
||
for (int i = 0; i < input.Count; i++)
|
||
{
|
||
// 验证物料描述长度
|
||
if (input[i].fld004502.Length > 40)
|
||
{
|
||
await _obj109Rep.AsUpdateable()
|
||
.SetColumns(it => new Obj109
|
||
{
|
||
fld004508 = DateTime.Now,
|
||
fld004510 = "N",
|
||
fld004507 = lengthError,
|
||
fld004509 = "失败"
|
||
})
|
||
.Where(it => it.idRecord == input[i].idRecord)
|
||
.ExecuteCommandAsync().ConfigureAwait(false);
|
||
|
||
SapOutputList.Add(new SapOutput()
|
||
{
|
||
materialCode = input[i]._System_objNBS,
|
||
code = "失败",
|
||
msg = lengthError,
|
||
result = lengthError
|
||
});
|
||
continue;
|
||
}
|
||
if (input[i].fld004510 == "N" || input[i].fld004510 == "D" || input[i].fld004510 == null)
|
||
{
|
||
SapOutputList.Add(new SapOutput()
|
||
{
|
||
materialCode = input[i]._System_objNBS,
|
||
code = "失败",
|
||
msg = synchronized,
|
||
result = synchronized
|
||
});
|
||
continue;
|
||
}
|
||
//获取时间戳精确到毫秒,sap要求每次调用生成不重复guid
|
||
string millisecondTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
|
||
Random random = new Random();
|
||
// 生成1000到9999之间的随机数
|
||
string randomNumber = random.Next(1000, 10000).ToString();
|
||
millisecondTimestamp = millisecondTimestamp + randomNumber;
|
||
|
||
var sapMaterialInput = new SapMaterialInput()
|
||
{
|
||
Reqkeyid = "",
|
||
Businessid = "",
|
||
Messageid = "",
|
||
Sndprn = "PLM",
|
||
Rcvprn = "SAP",
|
||
Requser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName),
|
||
Note1 = "",
|
||
Note2 = "",
|
||
Note3 = "",
|
||
Zwbid = millisecondTimestamp,
|
||
Matnr = input[i]._System_objNBS,
|
||
Mbrsh = input[i].fld004521,
|
||
Mtart = input[i].fld004519,
|
||
Maktx = input[i].fld004502,
|
||
Meins = input[i].fld005281,
|
||
Matkl = input[i].fld004520,
|
||
Bismt = input[i].fld004686,
|
||
Groes = input[i].fld004685,
|
||
Normt = input[i].fld004924,
|
||
Ferth = input[i].fld004925,
|
||
Zeinr = input[i].fld004926,
|
||
Mstae = input[i].fld004927,
|
||
Raube = input[i].fld004932,
|
||
Mhdrz = input[i].fld004933.ToString(),
|
||
Mhdhb = input[i].fld004934.ToString(),
|
||
Werks = input[i].fld004522,
|
||
Beskz = input[i].fld004928,
|
||
Sobsl = input[i].fld004929,
|
||
Schgt = input[i].fld004930,
|
||
Rgekz = input[i].fld004931,
|
||
Zbom = input[i].fld004935
|
||
};
|
||
var sapOutput = await _sapService.SapMaterialApi(sapMaterialInput);
|
||
string codeVal = sapOutput.code == "S" ? "成功" : "失败";
|
||
string msg = sapOutput.msg;
|
||
|
||
if (sapOutput.msg == "")
|
||
{
|
||
msg = "同步成功";
|
||
}
|
||
await _obj109Rep.AsUpdateable()
|
||
.SetColumns(it => new Obj109
|
||
{
|
||
fld004508 = DateTime.Now,
|
||
fld004507 = msg,
|
||
fld004509 = codeVal,
|
||
fld004510 = "N"
|
||
})
|
||
.Where(it => it.idRecord == input[i].idRecord)
|
||
.ExecuteCommandAsync();
|
||
var output = new SapOutput()
|
||
{
|
||
parameter = sapOutput.parameter,
|
||
materialCode = input[0]._System_objNBS,
|
||
code = codeVal,
|
||
msg = msg,
|
||
result = sapOutput.result
|
||
};
|
||
SapOutputList.Add(output);
|
||
}
|
||
|
||
return SapOutputList;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取BOM
|
||
/// </summary>
|
||
/// <param name="input"></param>
|
||
/// <returns></returns>
|
||
[ApiDescriptionSettings(Name = "GetBOM", Description = "获取BOM", Order = 1000), HttpPost]
|
||
[DisplayName("获取BOM")]
|
||
public async Task<SqlSugarPagedList<ProjectManagementBomOutput>> GetBOM(BomProjectManagementInput input)
|
||
{
|
||
var configid = await _configurationsRep.AsQueryable().Where(x => x.ObjectId == 109 && x.ConfigSystemName == "mBOM").FirstAsync();
|
||
var parent = await _obj109Rep.AsQueryable().Where(x => x.RecordGuid == input.ParentGuid && x.deleted == false).MaxAsync(x => x.VersionIndex);
|
||
var BomData = await _configurationDataRep.AsQueryable()
|
||
.Where(x => x.ConfigId == configid.ConfigID && x.ParentGuid == input.ParentGuid && x.isDeleted == false && x.ParentVersion == parent)
|
||
.WhereIF(!string.IsNullOrWhiteSpace(input.Description), u => u.Description.Contains(input.Description.Trim()))
|
||
.WhereIF(!string.IsNullOrWhiteSpace(input.PartNumber), u => u.PartNumber.Contains(input.PartNumber.Trim()))
|
||
.Select<ProjectManagementBomOutput>().ToPagedListAsync(input.Page, input.PageSize);
|
||
return BomData;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 项目管理-Bom同步到SAP
|
||
/// </summary>
|
||
/// <param name="input"></param>
|
||
/// <returns></returns>
|
||
[ApiDescriptionSettings(Name = "SyncToSAPBom"), HttpPost]
|
||
[DisplayName("项目管理-Bom同步到SAP")]
|
||
public async Task<SapOutput> SyncToSAPBom(List<BomProjectManagementInput> input)
|
||
{
|
||
var ParentData = await _obj109Rep.AsQueryable().Where(x => x.RecordGuid == input[0].ParentGuid && x.deleted == false && x.VersionIndex == input[0].ParentVersion).FirstAsync();
|
||
var EcnData = await _obj118Rep.AsQueryable().Where(x => x.RecordGuid == ParentData.fld004947_Rec && x.deleted == false).OrderByDescending(x => x.VersionIndex).FirstAsync();
|
||
var ecn = "";
|
||
if (EcnData != null)
|
||
{
|
||
ecn = EcnData._System_objNBS;
|
||
}
|
||
|
||
var itemDataList = new List<ItemData>();
|
||
|
||
for (int i = 0; i < input.Count; i++)
|
||
{
|
||
var Verification = await _dataValidationService.VerificationMaterial(input[i].ChildObjID, input[i].PartNumber, input[i].ChildGuid);
|
||
if (Verification == "不存在")
|
||
{
|
||
continue;
|
||
}
|
||
int sun = i + 1;
|
||
var itemData = new ItemData()
|
||
{
|
||
POSNR = sun.ToString(),//组件序号
|
||
IDNRK = input[i].PartNumber,//组件物料号
|
||
MENGE = input[i].QtyManual.ToString(),//组件数量
|
||
SORTF = input[i].fld004936,
|
||
ITISOB = input[i].fld004937,
|
||
ALPGR = input[i].fld004938,
|
||
ALPRF = input[i].fld004939,
|
||
ZDELETE = input[i].fld004940,
|
||
POSTP = input[i].fld004492,
|
||
ZYFMK = input[i].fld004941
|
||
};
|
||
itemDataList.Add(itemData);
|
||
}
|
||
|
||
//获取时间戳精确到毫秒,sap要求每次调用生成不重复guid
|
||
string millisecondTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
|
||
Random random = new Random();
|
||
// 生成1000到9999之间的随机数
|
||
string randomNumber = random.Next(1000, 10000).ToString();
|
||
millisecondTimestamp = millisecondTimestamp + randomNumber;
|
||
|
||
var isreq = new IS_REQ()
|
||
{
|
||
ReqKeyId = "",
|
||
BusinessId = "",
|
||
MessageId = "",
|
||
SndPrn = "PLM",
|
||
RcvPrn = "SAP",
|
||
ReqUser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName),
|
||
Note1 = "",
|
||
Note2 = "",
|
||
Note3 = "",
|
||
Zwbid = millisecondTimestamp,
|
||
Matnr = ParentData._System_objNBS,//父物料编码
|
||
Werks = ParentData.fld004522,//工厂
|
||
Bmeng = ParentData.fld004946.ToString(),
|
||
Aennr = ecn,
|
||
Datuv = ParentData.fld004949.ToString(),
|
||
ItemList = itemDataList
|
||
};
|
||
var apiOutput = await _sapService.SapBomApi(isreq);
|
||
string codeVal = apiOutput.code == "S" ? "成功" : "失败";
|
||
await _obj109Rep.AsUpdateable()
|
||
.SetColumns(it => new Obj109
|
||
{
|
||
fld004513 = DateTime.Now,
|
||
fld004511 = codeVal,
|
||
fld004514 = "N",
|
||
fld004512 = apiOutput.msg
|
||
})
|
||
.Where(it => it.idRecord == ParentData.idRecord)
|
||
.ExecuteCommandAsync();
|
||
var msg = apiOutput.msg;
|
||
if (apiOutput.msg == "")
|
||
{
|
||
msg = "同步成功";
|
||
}
|
||
var output = new SapOutput()
|
||
{
|
||
parameter = apiOutput.parameter,
|
||
code = codeVal,
|
||
msg = msg,
|
||
result = apiOutput.result
|
||
};
|
||
return output;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 项目管理-定时同步到SAP
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[ApiDescriptionSettings(Name = "TimingSyncToSAP"), HttpGet]
|
||
[DisplayName("项目管理-定时同步到SAP")]
|
||
public async Task<List<SapOutput>> TimingSyncToSAP()
|
||
{
|
||
using var serviceScope = _scopeFactory.CreateScope();
|
||
var db = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("启威星 1.94.4.74").CopyNew();
|
||
|
||
var input = await db.CopyNew().Queryable<Obj109>()
|
||
.Where(x => (x.CheckedStatus == 0 || x.CheckedStatus == 1) && x.deleted == false && x.IsLatestVersion == true && x.fld005040 == "发布" && (x.fld004510 == "A" || x.fld004510 == "M"))
|
||
.ToListAsync();
|
||
const string lengthError = "物料描述长度大于40,请检查!";
|
||
var SapOutputList = new List<SapOutput>();
|
||
var Requser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName);
|
||
for (int i = 0; i < input.Count; i++)
|
||
{
|
||
// 验证物料描述长度
|
||
if (input[i].fld004502.Length > 40)
|
||
{
|
||
db.CopyNew().Updateable<Obj109>()
|
||
.SetColumns(it => new Obj109
|
||
{
|
||
fld004508 = DateTime.Now,
|
||
fld004510 = "N",
|
||
fld004507 = lengthError,
|
||
fld004509 = "失败"
|
||
})
|
||
.Where(it => it.idRecord == input[i].idRecord)
|
||
.ExecuteCommand();
|
||
|
||
SapOutputList.Add(new SapOutput()
|
||
{
|
||
materialCode = input[i]._System_objNBS,
|
||
code = "失败",
|
||
msg = lengthError,
|
||
result = lengthError
|
||
});
|
||
continue;
|
||
}
|
||
|
||
//获取时间戳精确到毫秒,sap要求每次调用生成不重复guid
|
||
string millisecondTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
|
||
Random random = new Random();
|
||
// 生成1000到9999之间的随机数
|
||
string randomNumber = random.Next(1000, 10000).ToString();
|
||
millisecondTimestamp = millisecondTimestamp + randomNumber;
|
||
|
||
var sapMaterialInput = new SapMaterialInput()
|
||
{
|
||
Reqkeyid = "",
|
||
Businessid = "",
|
||
Messageid = "",
|
||
Sndprn = "PLM",
|
||
Rcvprn = "SAP",
|
||
Requser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName),
|
||
Note1 = "",
|
||
Note2 = "",
|
||
Note3 = "",
|
||
Zwbid = millisecondTimestamp,
|
||
Matnr = input[i]._System_objNBS,
|
||
Mbrsh = input[i].fld004521,
|
||
Mtart = input[i].fld004519,
|
||
Maktx = input[i].fld004502,
|
||
Meins = input[i].fld005281,
|
||
Matkl = input[i].fld004520,
|
||
Bismt = input[i].fld004686,
|
||
Groes = input[i].fld004685,
|
||
Normt = input[i].fld004924,
|
||
Ferth = input[i].fld004925,
|
||
Zeinr = input[i].fld004926,
|
||
Mstae = input[i].fld004927,
|
||
Raube = input[i].fld004932,
|
||
Mhdrz = input[i].fld004933.ToString(),
|
||
Mhdhb = input[i].fld004934.ToString(),
|
||
Werks = input[i].fld004522,
|
||
Beskz = input[i].fld004928,
|
||
Sobsl = input[i].fld004929,
|
||
Schgt = input[i].fld004930,
|
||
Rgekz = input[i].fld004931,
|
||
Zbom = input[i].fld004935
|
||
};
|
||
var sapOutput = await _sapService.SapMaterialApi(sapMaterialInput);
|
||
string codeVal = sapOutput.code == "S" ? "成功" : "失败";
|
||
string msg = sapOutput.msg;
|
||
|
||
if (sapOutput.msg == "")
|
||
{
|
||
msg = "同步成功";
|
||
}
|
||
db.CopyNew().Updateable<Obj109>()
|
||
.SetColumns(it => new Obj109
|
||
{
|
||
fld004508 = DateTime.Now,
|
||
fld004509 = codeVal,
|
||
fld004510 = "N",
|
||
fld004507 = msg
|
||
})
|
||
.Where(it => it.idRecord == input[i].idRecord)
|
||
.ExecuteCommand();
|
||
var output = new SapOutput()
|
||
{
|
||
parameter = sapOutput.parameter,
|
||
materialCode = input[0]._System_objNBS,
|
||
code = codeVal,
|
||
msg = msg,
|
||
result = sapOutput.result
|
||
};
|
||
SapOutputList.Add(output);
|
||
}
|
||
|
||
return SapOutputList;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 项目管理-定时同步 BOM 到 SAP
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[ApiDescriptionSettings(Name = "TimingSyncToSAPBom"), HttpGet]
|
||
[DisplayName("项目管理-定时同步 Bom 到 SAP")]
|
||
[AllowAnonymous]
|
||
public async Task<List<SapOutput>> TimingSyncToSAPBom()
|
||
{
|
||
using var serviceScope = _scopeFactory.CreateScope();
|
||
var db = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("启威星 1.94.4.74").CopyNew();
|
||
|
||
var sapOutputList = new List<SapOutput>();
|
||
var sapUserName = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName);
|
||
|
||
var materialData = await db.CopyNew().Queryable<Obj109>()
|
||
.Where(x => (x.CheckedStatus == 0 || x.CheckedStatus == 1) && x.deleted == false && x.IsLatestVersion == true && x.fld005040 == "发布" && x.fld004510 == "N" && x.fld004509 == "成功" && (x.fld004514 == "A" || x.fld004514 == "M"))
|
||
.ToListAsync();
|
||
var groupedData = materialData.GroupBy(item => item.RecordGuid)
|
||
.Select(group => group.OrderByDescending(item => item.VersionIndex).First())
|
||
.ToList();
|
||
|
||
foreach (var item in groupedData)
|
||
{
|
||
// 获取版本号
|
||
var versionIndex = item.VersionIndex;
|
||
// 获取 ECN guid
|
||
var ecnGuid = item.fld004947_Rec;
|
||
// 查询 BOM
|
||
var bomData = await db.CopyNew().Queryable<ConfigurationData>()
|
||
.Where(x => x.ConfigId == 2 && x.ParentGuid == item.RecordGuid && x.isDeleted == false && x.ParentVersion == versionIndex).ToListAsync();
|
||
if (bomData.Count == 0)
|
||
{
|
||
continue;
|
||
}
|
||
// 查询 ECN 编码
|
||
var ecnData = await db.CopyNew().Queryable<Obj118>().Where(x => x.RecordGuid == ecnGuid && x.deleted == false).OrderByDescending(x => x.VersionIndex).FirstAsync();
|
||
var ecn = ecnData != null ? ecnData._System_objNBS : "";
|
||
|
||
var itemDataList = new List<ItemData>();
|
||
foreach (var bomItem in bomData)
|
||
{
|
||
var verification = await _dataValidationService.VerificationMaterial(bomItem.ChildObjID, bomItem.PartNumber, bomItem.ChildGuid);
|
||
if (verification == "不存在")
|
||
{
|
||
continue;
|
||
}
|
||
|
||
var itemData = new ItemData
|
||
{
|
||
POSNR = (bomData.IndexOf(bomItem) + 1).ToString(),
|
||
IDNRK = bomItem.PartNumber,
|
||
MENGE = bomItem.QtyManual.ToString(),
|
||
SORTF = bomItem.fld004936,
|
||
ITISOB = bomItem.fld004937,
|
||
ALPGR = bomItem.fld004938,
|
||
ALPRF = bomItem.fld004939,
|
||
ZDELETE = bomItem.fld004940,
|
||
POSTP = bomItem.fld004492,
|
||
ZYFMK = bomItem.fld004941
|
||
};
|
||
itemDataList.Add(itemData);
|
||
|
||
}
|
||
// 获取时间戳精确到毫秒,sap 要求每次调用生成不重复 guid
|
||
string millisecondTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
|
||
Random random = new Random();
|
||
// 生成1000到9999之间的随机数
|
||
string randomNumber = random.Next(1000, 10000).ToString();
|
||
millisecondTimestamp = millisecondTimestamp + randomNumber;
|
||
|
||
var isreq = new IS_REQ
|
||
{
|
||
ReqKeyId = "",
|
||
BusinessId = "",
|
||
MessageId = "",
|
||
SndPrn = "PLM",
|
||
RcvPrn = "SAP",
|
||
ReqUser = sapUserName,
|
||
Note1 = "",
|
||
Note2 = "",
|
||
Note3 = "",
|
||
Zwbid = millisecondTimestamp,
|
||
Matnr = item._System_objNBS,
|
||
Werks = item.fld004522,
|
||
Bmeng = item.fld004946.ToString(),
|
||
Aennr = ecn,
|
||
Datuv = item.fld004949.ToString(),
|
||
ItemList = itemDataList
|
||
};
|
||
|
||
var apiOutput = await _sapService.SapBomApi(isreq);
|
||
string codeVal = apiOutput.code == "S" ? "成功" : "失败";
|
||
db.CopyNew().Updateable<Obj109>()
|
||
.SetColumns(it => new Obj109
|
||
{
|
||
fld004513 = DateTime.Now,
|
||
fld004511 = codeVal,
|
||
fld004514 = "N",
|
||
fld004512 = apiOutput.msg
|
||
})
|
||
.Where(it => it.idRecord == item.idRecord)
|
||
.ExecuteCommand();
|
||
|
||
var msg = apiOutput.msg;
|
||
if (string.IsNullOrEmpty(msg))
|
||
{
|
||
msg = "同步成功";
|
||
}
|
||
|
||
var output = new SapOutput
|
||
{
|
||
parameter = apiOutput.parameter,
|
||
materialCode = item._System_objNBS,
|
||
code = codeVal,
|
||
msg = msg,
|
||
result = apiOutput.result
|
||
};
|
||
sapOutputList.Add(output);
|
||
}
|
||
return sapOutputList;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 项目管理-获取工艺路线
|
||
/// </summary>
|
||
/// <param name="input"></param>
|
||
/// <returns></returns>
|
||
[ApiDescriptionSettings(Name = "GetProcessRoute", Description = "获取工艺路线", Order = 1000), HttpPost]
|
||
[DisplayName("获取工艺路线")]
|
||
public async Task<SqlSugarPagedList<ProductManagementBomOutput>> GetProcessRoute(BomPageProductManagementInput input)
|
||
{
|
||
var configid = await _configurationsRep.AsQueryable().Where(x => x.ObjectId == 109 && x.ConfigSystemName == "pBOM").FirstAsync();
|
||
var parent = await _obj109Rep.AsQueryable().Where(x => x.RecordGuid == input.ParentGuid && x.deleted == false).MaxAsync(x => x.VersionIndex);
|
||
var BomData = await _configurationDataRep.AsQueryable()
|
||
.Where(x => x.ConfigId == configid.ConfigID && x.ParentGuid == input.ParentGuid && x.isDeleted == false && x.ParentVersion == parent)
|
||
.WhereIF(!string.IsNullOrWhiteSpace(input.Description), u => u.Description.Contains(input.Description.Trim()))
|
||
.WhereIF(!string.IsNullOrWhiteSpace(input.PartNumber), u => u.PartNumber.Contains(input.PartNumber.Trim()))
|
||
.Select<ProductManagementBomOutput>().ToPagedListAsync(input.Page, input.PageSize);
|
||
return BomData;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 项目管理-工艺路线同步到SAP
|
||
/// </summary>
|
||
/// <param name="input"></param>
|
||
/// <returns></returns>
|
||
[ApiDescriptionSettings(Name = "SyncToSAPProcessRoute"), HttpPost]
|
||
[DisplayName("项目管理-工艺路线同步到SAP")]
|
||
public async Task<SapOutput> SyncToSAPProcessRoute(List<BomPageProductManagementInput> input)
|
||
{
|
||
var ParentData = await _obj109Rep.AsQueryable().Where(x => x.RecordGuid == input[0].ParentGuid && x.deleted == false && x.VersionIndex == input[0].ParentVersion).FirstAsync();
|
||
|
||
var itemDataList = new List<SapProcessRouteItemData>();
|
||
|
||
for (int i = 0; i < input.Count; i++)
|
||
{
|
||
var Verification = await _dataValidationService.VerificationMaterial(input[i].ChildObjID, input[i].PartNumber, input[i].ChildGuid);
|
||
if (Verification == "不存在")
|
||
{
|
||
continue;
|
||
}
|
||
|
||
//获取工序描述
|
||
var procedureDescription = await _obj122Rep.AsQueryable().Where(x => x.RecordGuid == input[i].ChildGuid).ToListAsync();
|
||
//获取工作中心
|
||
var workCenter = await _obj121Rep.AsQueryable().Where(x => x.RecordGuid == procedureDescription[0].fld005059_Rec).ToListAsync();
|
||
//int sun = i + 1;
|
||
var itemData = new SapProcessRouteItemData()
|
||
{
|
||
VORNR = input[i].Marker,
|
||
LTXA1 = procedureDescription[0]._System_ObjDescription,
|
||
ARBPL = workCenter[0]._System_objNBS,
|
||
VGW01 = input[i].fld004994.ToString(),
|
||
VGE01 = input[i].fld004995,
|
||
STEUS = input[i].fld004996,
|
||
BMSCH = input[i].fld005298.ToString()
|
||
|
||
};
|
||
itemDataList.Add(itemData);
|
||
}
|
||
|
||
//获取时间戳精确到毫秒,sap要求每次调用生成不重复guid
|
||
string millisecondTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
|
||
Random random = new Random();
|
||
// 生成1000到9999之间的随机数
|
||
string randomNumber = random.Next(1000, 10000).ToString();
|
||
millisecondTimestamp = millisecondTimestamp + randomNumber;
|
||
|
||
var Datuv = ParentData.fld004949.ToString();
|
||
if (!string.IsNullOrEmpty(Datuv))
|
||
{
|
||
Datuv = ParentData.fld004949.ToDateTime().ToString("yyyy-MM-dd");
|
||
}
|
||
var isreq = new SapProcessRouteIS_REQ()
|
||
{
|
||
ReqKeyId = "",
|
||
BusinessId = "",
|
||
MessageId = "",
|
||
SndPrn = "PLM",
|
||
RcvPrn = "SAP",
|
||
ReqUser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName),
|
||
Note1 = "",
|
||
Note2 = "",
|
||
Note3 = "",
|
||
Zwbid = millisecondTimestamp,
|
||
Matnr = ParentData._System_objNBS,
|
||
Werks = ParentData.fld004522,
|
||
Datuv = Datuv,
|
||
Plnal = "",
|
||
|
||
ItemList = itemDataList
|
||
};
|
||
var apiOutput = await _sapService.SapProcessRouteApi(isreq);
|
||
string codeVal = apiOutput.code == "S" ? "成功" : "失败";
|
||
await _obj109Rep.AsUpdateable()
|
||
.SetColumns(it => new Obj109
|
||
{
|
||
fld004518 = DateTime.Now,
|
||
fld004515 = codeVal,
|
||
fld004517 = "N",
|
||
fld004516 = apiOutput.msg
|
||
})
|
||
.Where(it => it.idRecord == ParentData.idRecord)
|
||
.ExecuteCommandAsync();
|
||
var msg = apiOutput.msg;
|
||
if (apiOutput.msg == "")
|
||
{
|
||
msg = "同步成功";
|
||
}
|
||
var output = new SapOutput()
|
||
{
|
||
parameter = apiOutput.parameter,
|
||
code = codeVal,
|
||
msg = msg,
|
||
result = apiOutput.result
|
||
};
|
||
return output;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 项目管理-定时同步工艺路线到SAP
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[ApiDescriptionSettings(Name = "TimingSyncToSAPProcessRoute"), HttpGet]
|
||
[DisplayName("项目管理-定时同步工艺路线到SAP")]
|
||
public async Task<List<SapOutput>> TimingSyncToSAPProcessRoute()
|
||
{
|
||
using var serviceScope = _scopeFactory.CreateScope();
|
||
var db = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("启威星 1.94.4.74").CopyNew();
|
||
|
||
var sapOutputList = new List<SapOutput>();
|
||
var sapUserName = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName);
|
||
// 配置
|
||
|
||
//查询需要同步的产品
|
||
var materialData = await db.CopyNew().Queryable<Obj109>()
|
||
.Where(x => (x.CheckedStatus == 0 || x.CheckedStatus == 1) && x.deleted == false && x.IsLatestVersion == true && x.fld005040 == "发布" && x.fld004510 == "N" && x.fld004509 == "成功" && (x.fld004514 == "A" || x.fld004514 == "M"))
|
||
.ToListAsync();
|
||
//分组查询最大版本的物料
|
||
var groupedData = materialData.GroupBy(item => item.RecordGuid)
|
||
.Select(group => group.OrderByDescending(item => item.VersionIndex).First())
|
||
.ToList();
|
||
|
||
foreach (var item in groupedData)
|
||
{
|
||
// 获取版本号
|
||
var versionIndex = item.VersionIndex;
|
||
// 查询 BOM
|
||
var processRouteData = await db.CopyNew().Queryable<ConfigurationData>()
|
||
.Where(x => x.ConfigId == 5 && x.ParentGuid == item.RecordGuid && x.isDeleted == false && x.ParentVersion == versionIndex).ToListAsync();
|
||
if (processRouteData.Count == 0)
|
||
{
|
||
continue;
|
||
}
|
||
var itemDataList = new List<SapProcessRouteItemData>();
|
||
|
||
foreach (var processRouteItem in processRouteData)
|
||
{
|
||
var verification = await _dataValidationService.VerificationMaterial(processRouteItem.ChildObjID, processRouteItem.PartNumber, processRouteItem.ChildGuid);
|
||
if (verification == "不存在")
|
||
{
|
||
continue;
|
||
}
|
||
//获取工序描述
|
||
var procedureDescription = await db.CopyNew().Queryable<Obj122>().Where(x => x.RecordGuid == processRouteItem.ChildGuid).ToListAsync();
|
||
//获取工作中心
|
||
var workCenter = await db.CopyNew().Queryable<Obj121>().Where(x => x.RecordGuid == procedureDescription[0].fld005059_Rec).ToListAsync();
|
||
var itemData = new SapProcessRouteItemData()
|
||
{
|
||
VORNR = processRouteItem.Marker,
|
||
LTXA1 = procedureDescription[0]._System_ObjDescription,
|
||
ARBPL = workCenter[0]._System_objNBS,
|
||
VGW01 = processRouteItem.fld004994.ToString(),
|
||
VGE01 = processRouteItem.fld004995,
|
||
STEUS = processRouteItem.fld004996,
|
||
BMSCH = processRouteItem.fld005296.ToString()
|
||
|
||
};
|
||
itemDataList.Add(itemData);
|
||
}
|
||
//获取时间戳精确到毫秒,sap要求每次调用生成不重复guid
|
||
string millisecondTimestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
|
||
Random random = new Random();
|
||
// 生成1000到9999之间的随机数
|
||
string randomNumber = random.Next(1000, 10000).ToString();
|
||
millisecondTimestamp = millisecondTimestamp + randomNumber;
|
||
|
||
var Datuv = item.fld004949.ToString();
|
||
|
||
if (!string.IsNullOrEmpty(Datuv))
|
||
{
|
||
Datuv = item.fld004949.ToDateTime().ToString("yyyy-MM-dd");
|
||
}
|
||
var isreq = new SapProcessRouteIS_REQ()
|
||
{
|
||
ReqKeyId = "",
|
||
BusinessId = "",
|
||
MessageId = "",
|
||
SndPrn = "PLM",
|
||
RcvPrn = "SAP",
|
||
ReqUser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName),
|
||
Note1 = "",
|
||
Note2 = "",
|
||
Note3 = "",
|
||
Zwbid = millisecondTimestamp,
|
||
Matnr = item._System_objNBS,
|
||
Werks = item.fld004522,
|
||
Datuv = Datuv,
|
||
Plnal = "",
|
||
|
||
ItemList = itemDataList
|
||
};
|
||
|
||
var apiOutput = await _sapService.SapProcessRouteApi(isreq);
|
||
string codeVal = apiOutput.code == "S" ? "成功" : "失败";
|
||
db.CopyNew().Updateable<Obj109>()
|
||
.SetColumns(it => new Obj109
|
||
{
|
||
fld004518 = DateTime.Now,
|
||
fld004515 = codeVal,
|
||
fld004517 = "N",
|
||
fld004516 = apiOutput.msg
|
||
})
|
||
.Where(it => it.idRecord == item.idRecord)
|
||
.ExecuteCommand();
|
||
var msg = apiOutput.msg;
|
||
if (apiOutput.msg == "")
|
||
{
|
||
msg = "同步成功";
|
||
}
|
||
var output = new SapOutput()
|
||
{
|
||
materialCode = item._System_objNBS,
|
||
parameter = apiOutput.parameter,
|
||
code = codeVal,
|
||
msg = msg,
|
||
result = apiOutput.result
|
||
};
|
||
|
||
sapOutputList.Add(output);
|
||
}
|
||
return sapOutputList;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 向SAP创建WBS
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public async Task<List<SapOutput>> WbsInSapCreate()
|
||
{
|
||
using var serviceScope = _scopeFactory.CreateScope();
|
||
var db = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("启威星 1.94.4.74").CopyNew();
|
||
var syncData = await db.CopyNew().Queryable<Obj109>()
|
||
.InnerJoin<CasesStagesMain>((x, y) => x.RecordGuid == y.RecordGuid)
|
||
.InnerJoin<Obj126>((x, y, z) => y.ChildRecordGuid == z.RecordGuid)
|
||
.Where((x, y) => x.deleted == false && x.fld006774 == "A" && (x.fld006993 == "" || x.fld006993 == null) && (x.CheckedStatus == 0 || x.CheckedStatus == 1) && y.indentLevel < 4)
|
||
//&& SqlFunc.Subqueryable<Obj109>().Where(x=>x.RecordGuid==x.RecordGuid).Max(s=>s.idRecord)==x.idRecord) (x.fld006776 == "" || x.fld006776 == null)
|
||
.Select((x, y, z) => new WbsInput
|
||
{
|
||
projectIdRecord = x.idRecord,
|
||
CheckedStatus = x.CheckedStatus,
|
||
RecordGuid = x.RecordGuid,
|
||
indentLevel = y.indentLevel,
|
||
OrderIndex = y.OrderIndex,
|
||
Description = y.Description,
|
||
ChildRecordGuid = y.ChildRecordGuid,
|
||
fld006745 = z.fld006745,
|
||
_System_objNBS = z._System_objNBS,
|
||
StartDate = z.StartDate,
|
||
EndDate = z.EndDate,
|
||
fld006934 = z.fld006934,
|
||
fld006746 = z.fld006746,
|
||
fld006770 = z.fld006770,
|
||
stageIdRecord = z.idRecord,
|
||
System_objNBS109 = x._System_objNBS
|
||
|
||
})
|
||
.ToListAsync();
|
||
var syncList = syncData.GroupBy(record => record.RecordGuid)
|
||
.Select(group => new
|
||
{
|
||
WbsData = group.ToList()
|
||
});
|
||
|
||
var syncList2 = syncData.GroupBy(record => record.RecordGuid).ToList();
|
||
List<SapOutput> sapOutputs = new List<SapOutput>();
|
||
foreach (var item in syncList)
|
||
{
|
||
var output = await WbsSapParams(item.WbsData);
|
||
sapOutputs.Add(output);
|
||
}
|
||
return sapOutputs;
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="list"></param>
|
||
/// <returns></returns>
|
||
public async Task<SapOutput> WbsSapParams(List<WbsInput> list)
|
||
{
|
||
var sapInputItem = new List<SapCreateWBSItem>();
|
||
List<long> ints = new List<long>();
|
||
|
||
string hierarchicalCoding1 = "";
|
||
string hierarchicalCoding2 = "";
|
||
string hierarchicalCoding3 = "";
|
||
string hierarchicalCoding4 = "";
|
||
int i = 0;
|
||
long projectIdRecord = 0;
|
||
var sortList = list.OrderBy(x => x.OrderIndex).ToList();
|
||
foreach (var item in sortList)
|
||
{
|
||
projectIdRecord = item.projectIdRecord;
|
||
//if (string.IsNullOrEmpty(item.fld006745))
|
||
//{
|
||
// var errParam = new SapOutput()
|
||
// {
|
||
// materialCode=item.System_objNBS109,
|
||
// code = "失败",
|
||
// msg = "请检查WBS标识",
|
||
// };
|
||
// return errParam;
|
||
//}
|
||
|
||
ints.Add(item.stageIdRecord);
|
||
i++;
|
||
string StartDate = "";
|
||
if (item.StartDate.HasValue)
|
||
{
|
||
StartDate = item.StartDate.ToDateTime().ToString("yyyy-MM-dd");
|
||
}
|
||
string EndDate = "";
|
||
if (item.EndDate.HasValue)
|
||
{
|
||
EndDate = item.EndDate.ToDateTime().ToString("yyyy-MM-dd");
|
||
}
|
||
|
||
string fld006934 = "";
|
||
if (item.fld006934.HasValue)
|
||
{
|
||
fld006934 = item.fld006934.ToDateTime().ToString("yyyy-MM-dd");
|
||
}
|
||
|
||
string fld006746 = "";
|
||
if (item.fld006746.HasValue)
|
||
{
|
||
fld006746 = item.fld006746.ToDateTime().ToString("yyyy-MM-dd");
|
||
}
|
||
string fld006770 = "";
|
||
if (!string.IsNullOrEmpty(item.fld006770))
|
||
{
|
||
string[] parts = item.fld006770.Split('-');
|
||
fld006770 = parts[0];
|
||
}
|
||
|
||
if (item.indentLevel == 0)
|
||
{
|
||
hierarchicalCoding1 = item.fld006745;
|
||
|
||
//var itemData = new SapCreateWBSItem
|
||
//{
|
||
// Zwbid = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() + i.ToString(),
|
||
// Pspid = hierarchicalCoding1,
|
||
// Pspnr = "",
|
||
// Pspnr2 = hierarchicalCoding1,
|
||
// Post1 = item.Description,
|
||
// Pstrt = StartDate,
|
||
// Pende = EndDate,
|
||
// Istrt = fld006934,
|
||
// Iende = fld006746,
|
||
// Usr00 = "",
|
||
// Prart = fld006770,
|
||
// Zresv1 = "",
|
||
// Zresv2 = "",
|
||
// Zresv3 = "",
|
||
// Zresv4 = "",
|
||
// Zresv5 = ""
|
||
//};
|
||
//sapInputItem.Add(itemData);
|
||
|
||
}
|
||
if (item.indentLevel == 1)
|
||
{
|
||
hierarchicalCoding2 = item.fld006745;
|
||
|
||
var itemData = new SapCreateWBSItem
|
||
{
|
||
Zwbid = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() + i.ToString(),
|
||
Pspid = hierarchicalCoding1,
|
||
Pspnr = hierarchicalCoding1,
|
||
Pspnr2 = hierarchicalCoding2,
|
||
Post1 = item.Description,
|
||
Pstrt = StartDate,
|
||
Pende = EndDate,
|
||
Istrt = fld006934,
|
||
Iende = fld006746,
|
||
Usr00 = "",
|
||
Prart = fld006770,
|
||
Zresv1 = "",
|
||
Zresv2 = "",
|
||
Zresv3 = "",
|
||
Zresv4 = "",
|
||
Zresv5 = ""
|
||
};
|
||
if (fld006770 == "6")
|
||
{
|
||
itemData.Pspnr = "";
|
||
}
|
||
|
||
if (!string.IsNullOrEmpty(item.fld006745))
|
||
{
|
||
sapInputItem.Add(itemData);
|
||
}
|
||
}
|
||
if (item.indentLevel == 2)
|
||
{
|
||
hierarchicalCoding3 = item.fld006745;
|
||
var itemData = new SapCreateWBSItem
|
||
{
|
||
Zwbid = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() + i.ToString(),
|
||
Pspid = hierarchicalCoding1,
|
||
Pspnr = hierarchicalCoding2,
|
||
Pspnr2 = hierarchicalCoding3,
|
||
Post1 = item.Description,
|
||
Pstrt = StartDate,
|
||
Pende = EndDate,
|
||
Istrt = fld006934,
|
||
Iende = fld006746,
|
||
Usr00 = "",
|
||
Prart = fld006770,
|
||
Zresv1 = "",
|
||
Zresv2 = "",
|
||
Zresv3 = "",
|
||
Zresv4 = "",
|
||
Zresv5 = ""
|
||
};
|
||
if (fld006770 == "6")
|
||
{
|
||
itemData.Pspnr = "";
|
||
}
|
||
if (!string.IsNullOrEmpty(item.fld006745))
|
||
{
|
||
sapInputItem.Add(itemData);
|
||
}
|
||
}
|
||
if (item.indentLevel == 3)
|
||
{
|
||
hierarchicalCoding4 = item.fld006745;
|
||
var itemData = new SapCreateWBSItem
|
||
{
|
||
Zwbid = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() + i.ToString(),
|
||
Pspid = hierarchicalCoding1,
|
||
Pspnr = hierarchicalCoding3,
|
||
Pspnr2 = hierarchicalCoding4,
|
||
Post1 = item.Description,
|
||
Pstrt = StartDate,
|
||
Pende = EndDate,
|
||
Istrt = fld006934,
|
||
Iende = fld006746,
|
||
Usr00 = "",
|
||
Prart = fld006770,
|
||
Zresv1 = "",
|
||
Zresv2 = "",
|
||
Zresv3 = "",
|
||
Zresv4 = "",
|
||
Zresv5 = ""
|
||
};
|
||
if (fld006770 == "6")
|
||
{
|
||
itemData.Pspnr = "";
|
||
}
|
||
if (!string.IsNullOrEmpty(item.fld006745))
|
||
{
|
||
sapInputItem.Add(itemData);
|
||
}
|
||
}
|
||
}
|
||
var sapInput = new SapCreateWBSInput
|
||
{
|
||
ReqKeyId = "",
|
||
BusinessId = "",
|
||
MessageId = "",
|
||
SndPrn = "PLM",
|
||
RcvPrn = "SAP",
|
||
ReqUser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName),
|
||
Note1 = "",
|
||
Note2 = "",
|
||
Note3 = "",
|
||
SapCreateWBSItem = sapInputItem
|
||
};
|
||
|
||
var output = await _sapService.SapCreateWBS(sapInput);
|
||
output.materialCode = hierarchicalCoding1;
|
||
if (output.code == "S")
|
||
{
|
||
//await _obj126Rep.AsUpdateable()
|
||
// .SetColumns(it => it.fld006772 == DateTime.Now && it.fld006771 == "N" && it.fld006773 == output.msg && it.fld006990 == "成功")
|
||
// .Where(it => ints.Contains(it.idRecord))
|
||
// .ExecuteCommandAsync();
|
||
//await _obj109Rep.AsUpdateable()
|
||
// .SetColumns(it => it.fld006775 == DateTime.Now && it.fld006774 == "N" && it.fld006776 == output.msg && it.fld006993 == "成功")
|
||
// .Where(it => it.idRecord == projectIdRecord)
|
||
// .ExecuteCommandAsync();
|
||
|
||
foreach (var item in ints)
|
||
{
|
||
await UpdateObj126(item, output.msg, "创建成功");
|
||
}
|
||
await UpdateObj109(projectIdRecord, output.msg, "创建成功");
|
||
}
|
||
else
|
||
{
|
||
//await _obj109Rep.AsUpdateable()
|
||
// .SetColumns(it => it.fld006775 == DateTime.Now && it.fld006774 == "N" && it.fld006776 == output.msg)
|
||
// .Where(it => it.idRecord == projectIdRecord)
|
||
// .ExecuteCommandAsync();
|
||
await UpdateObj109(projectIdRecord, output.msg, "创建失败");
|
||
}
|
||
|
||
|
||
return output;
|
||
|
||
}
|
||
private async Task UpdateObj109(long idRecord, string msg, string creationState)
|
||
{
|
||
await Task.Delay(0);
|
||
using var serviceScope = _scopeFactory.CreateScope();
|
||
var db = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("启威星 1.94.4.74").CopyNew();
|
||
|
||
if (creationState == "创建成功")
|
||
{
|
||
db.CopyNew().Updateable<Obj109>()
|
||
.SetColumns(it => new Obj109
|
||
{
|
||
fld006775 = DateTime.Now,
|
||
fld006774 = "N",
|
||
fld006776 = msg,
|
||
fld006993 = "成功"
|
||
})
|
||
.Where(it => it.idRecord == idRecord)
|
||
.ExecuteCommand();
|
||
}
|
||
if (creationState == "修改成功" || creationState == "创建失败" || creationState == "修改失败")
|
||
{
|
||
db.CopyNew().Updateable<Obj109>()
|
||
.SetColumns(it => new Obj109
|
||
{
|
||
fld006775 = DateTime.Now,
|
||
fld006774 = "N",
|
||
fld006776 = msg
|
||
})
|
||
.Where(it => it.idRecord == idRecord)
|
||
.ExecuteCommand();
|
||
}
|
||
|
||
}
|
||
|
||
private async Task UpdateObj126(long idRecord, string msg, string creationState)
|
||
{
|
||
await Task.Delay(0);
|
||
using var serviceScope = _scopeFactory.CreateScope();
|
||
var db = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("启威星 1.94.4.74").CopyNew();
|
||
|
||
if (creationState == "创建成功")
|
||
{
|
||
db.CopyNew().Updateable<Obj126>()
|
||
.SetColumns(it => new Obj126
|
||
{
|
||
fld006772 = DateTime.Now,
|
||
fld006771 = "N",
|
||
fld006773 = msg,
|
||
fld006990 = creationState
|
||
})
|
||
.Where(it => it.idRecord == idRecord)
|
||
.ExecuteCommand();
|
||
}
|
||
if (creationState == "创建失败" || creationState == "修改成功"|| creationState == "修改失败")
|
||
{
|
||
db.CopyNew().Updateable<Obj126>()
|
||
.SetColumns(it => new Obj126
|
||
{
|
||
fld006772 = DateTime.Now,
|
||
fld006771 = "N",
|
||
fld006773 = msg
|
||
})
|
||
.Where(it => it.idRecord == idRecord)
|
||
.ExecuteCommand();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 向SAP更新WBS
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public async Task<List<SapOutput>> WbsInSapUpdate()
|
||
{
|
||
using var serviceScope = _scopeFactory.CreateScope();
|
||
var db = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("启威星 1.94.4.74").CopyNew();
|
||
var syncData = await db.CopyNew().Queryable<Obj109>()
|
||
.InnerJoin<CasesStagesMain>((x, y) => x.RecordGuid == y.RecordGuid)
|
||
.InnerJoin<Obj126>((x, y, z) => y.ChildRecordGuid == z.RecordGuid)
|
||
.Where((x, y) => x.deleted == false && x.fld006774 == "A" && (x.CheckedStatus == 0 || x.CheckedStatus == 1) && x.fld006993 == "成功" && y.indentLevel < 4) //&& (x.fld006776 == "" || x.fld006776 == null)
|
||
.Select((x, y, z) => new WbsInput
|
||
{
|
||
projectIdRecord = x.idRecord,
|
||
CheckedStatus = x.CheckedStatus,
|
||
RecordGuid = x.RecordGuid,
|
||
indentLevel = y.indentLevel,
|
||
OrderIndex = y.OrderIndex,
|
||
Description = y.Description,
|
||
ChildRecordGuid = y.ChildRecordGuid,
|
||
fld006745 = z.fld006745,
|
||
_System_objNBS = z._System_objNBS,
|
||
StartDate = z.StartDate,
|
||
EndDate = z.EndDate,
|
||
fld006934 = z.fld006934,
|
||
fld006746 = z.fld006746,
|
||
fld006770 = z.fld006770,
|
||
stageIdRecord = z.idRecord,
|
||
fld004502 = x.fld004502,
|
||
System_objNBS109 = x._System_objNBS,
|
||
fld004506 = x.fld004506,
|
||
fld006747 = z.fld006747,
|
||
fld006771=z.fld006771
|
||
|
||
})
|
||
.ToListAsync();
|
||
var syncList = syncData.GroupBy(record => record.RecordGuid)
|
||
.Select(group => new
|
||
{
|
||
WbsData = group.ToList()
|
||
});
|
||
|
||
var syncList2 = syncData.GroupBy(record => record.RecordGuid).ToList();
|
||
|
||
List<SapOutput> sapOutputs = new List<SapOutput>();
|
||
foreach (var item in syncList)
|
||
{
|
||
List<SapOutput> output = await WbsSapUpdateParams(item.WbsData);
|
||
sapOutputs.AddRange(output);
|
||
}
|
||
return sapOutputs;
|
||
|
||
}
|
||
|
||
public async Task<List<SapOutput>> WbsSapUpdateParams(List<WbsInput> list)
|
||
{
|
||
var sapOutput = new List<SapOutput>();
|
||
var sapUpdateInputItem = new List<SapUpdateWBSItem>();
|
||
var sapCreateInputItem = new List<SapCreateWBSItem>();
|
||
List<long> intsCreate = new List<long>();
|
||
List<long> intsUpdate = new List<long>();
|
||
|
||
|
||
string hierarchicalCoding1 = "";
|
||
string hierarchicalCoding2 = "";
|
||
string hierarchicalCoding3 = "";
|
||
string hierarchicalCoding4 = "";
|
||
int i = 0;
|
||
long projectIdRecord = 0;
|
||
string materialCode = "";
|
||
var sortList = list.OrderBy(x => x.OrderIndex).ToList();
|
||
foreach (var item in sortList)
|
||
{
|
||
projectIdRecord = item.projectIdRecord;
|
||
materialCode = item.System_objNBS109;
|
||
//if (string.IsNullOrEmpty(item.fld006745))
|
||
//{
|
||
// var errParam = new SapOutput()
|
||
// {
|
||
// materialCode=item.System_objNBS109,
|
||
// code = "失败",
|
||
// msg = "请检查WBS标识",
|
||
// };
|
||
// sapOutput.Add(errParam);
|
||
// return sapOutput;
|
||
//}
|
||
|
||
//if (item.fld006771 == "M")
|
||
//{
|
||
// intsUpdate.Add(item.stageIdRecord);
|
||
//}
|
||
//else
|
||
//{
|
||
// intsCreate.Add(item.stageIdRecord);
|
||
//}
|
||
i++;
|
||
string StartDate = "";
|
||
if (item.StartDate.HasValue)
|
||
{
|
||
StartDate = item.StartDate.ToDateTime().ToString("yyyy-MM-dd");
|
||
}
|
||
string EndDate = "";
|
||
if (item.EndDate.HasValue)
|
||
{
|
||
EndDate = item.EndDate.ToDateTime().ToString("yyyy-MM-dd");
|
||
}
|
||
|
||
string fld006934 = "";
|
||
if (item.fld006934.HasValue)
|
||
{
|
||
fld006934 = item.fld006934.ToDateTime().ToString("yyyy-MM-dd");
|
||
}
|
||
|
||
string fld006746 = "";
|
||
if (item.fld006746.HasValue)
|
||
{
|
||
fld006746 = item.fld006746.ToDateTime().ToString("yyyy-MM-dd");
|
||
}
|
||
string fld006770 = "";
|
||
if (!string.IsNullOrEmpty(item.fld006770))
|
||
{
|
||
string[] parts = item.fld006770.Split('-');
|
||
fld006770 = parts[0];
|
||
}
|
||
string fld004506 = "";
|
||
if (!string.IsNullOrEmpty(item.fld004506))
|
||
{
|
||
fld004506 = await _dataValidationService.ProjProcStatus(item.fld004506);
|
||
}
|
||
string fld006747 = "";
|
||
if (!string.IsNullOrEmpty(item.fld006747))
|
||
{
|
||
fld006747 = await _dataValidationService.ProjProcStatus(item.fld006747);
|
||
}
|
||
string System_objNBS109 = item.System_objNBS109;
|
||
if (item.indentLevel == 0)
|
||
{
|
||
hierarchicalCoding1 = item.fld006745;
|
||
if (item.fld006771 == "M")
|
||
{
|
||
intsUpdate.Add(item.stageIdRecord);
|
||
var itemData = new SapUpdateWBSItem
|
||
{
|
||
Zwbid = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() + i.ToString(),
|
||
Pspid = System_objNBS109,
|
||
Post1Proj = item.fld004502,
|
||
Pspnr = hierarchicalCoding1,
|
||
Post1 = item.Description,
|
||
Pstrt = StartDate,
|
||
Pende = EndDate,
|
||
Istrt = fld006934,
|
||
Iende = fld006746,
|
||
Usr00 = "",
|
||
Prart = fld006770,
|
||
SystemStatus = fld004506,
|
||
SystemStatus2 = fld006747,
|
||
Zresv1 = "",
|
||
Zresv2 = "",
|
||
Zresv3 = "",
|
||
Zresv4 = "",
|
||
Zresv5 = ""
|
||
};
|
||
sapUpdateInputItem.Add(itemData);
|
||
}
|
||
//if (item.fld006771 == "" || item.fld006771 ==null)
|
||
//{
|
||
// var itemCreateData = new SapCreateWBSItem
|
||
// {
|
||
// Zwbid = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() + i.ToString(),
|
||
// Pspid = System_objNBS109,
|
||
// Pspnr = "",
|
||
// Pspnr2 = hierarchicalCoding1,
|
||
// Post1 = item.Description,
|
||
// Pstrt = StartDate,
|
||
// Pende = EndDate,
|
||
// Istrt = fld006934,
|
||
// Iende = fld006746,
|
||
// Usr00 = "",
|
||
// Prart = fld006770,
|
||
// Zresv1 = "",
|
||
// Zresv2 = "",
|
||
// Zresv3 = "",
|
||
// Zresv4 = "",
|
||
// Zresv5 = ""
|
||
// };
|
||
// sapCreateInputItem.Add(itemCreateData);
|
||
//}
|
||
|
||
}
|
||
if (item.indentLevel == 1)
|
||
{
|
||
hierarchicalCoding2 = item.fld006745;
|
||
if (item.fld006771 == "M")
|
||
{
|
||
intsUpdate.Add(item.stageIdRecord);
|
||
var itemData = new SapUpdateWBSItem
|
||
{
|
||
Zwbid = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() + i.ToString(),
|
||
Pspid = System_objNBS109,
|
||
Post1Proj = item.fld004502,
|
||
Pspnr = hierarchicalCoding2,
|
||
Post1 = item.Description,
|
||
Pstrt = StartDate,
|
||
Pende = EndDate,
|
||
Istrt = fld006934,
|
||
Iende = fld006746,
|
||
Usr00 = "",
|
||
Prart = fld006770,
|
||
SystemStatus = fld004506,
|
||
SystemStatus2 = fld006747,
|
||
Zresv1 = "",
|
||
Zresv2 = "",
|
||
Zresv3 = "",
|
||
Zresv4 = "",
|
||
Zresv5 = ""
|
||
};
|
||
sapUpdateInputItem.Add(itemData);
|
||
}
|
||
if (item.fld006771 == "" || item.fld006771 == null)
|
||
{
|
||
var itemData = new SapCreateWBSItem
|
||
{
|
||
Zwbid = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() + i.ToString(),
|
||
Pspid = System_objNBS109,
|
||
Pspnr = hierarchicalCoding1,
|
||
Pspnr2 = hierarchicalCoding2,
|
||
Post1 = item.Description,
|
||
Pstrt = StartDate,
|
||
Pende = EndDate,
|
||
Istrt = fld006934,
|
||
Iende = fld006746,
|
||
Usr00 = "",
|
||
Prart = fld006770,
|
||
Zresv1 = "",
|
||
Zresv2 = "",
|
||
Zresv3 = "",
|
||
Zresv4 = "",
|
||
Zresv5 = ""
|
||
};
|
||
if (fld006770 == "6")
|
||
{
|
||
itemData.Pspnr = "";
|
||
}
|
||
if (!string.IsNullOrEmpty(item.fld006745))
|
||
{
|
||
intsCreate.Add(item.stageIdRecord);
|
||
sapCreateInputItem.Add(itemData);
|
||
}
|
||
|
||
}
|
||
}
|
||
if (item.indentLevel == 2)
|
||
{
|
||
hierarchicalCoding3 = item.fld006745;
|
||
if (item.fld006771 == "M")
|
||
{
|
||
intsUpdate.Add(item.stageIdRecord);
|
||
var itemData = new SapUpdateWBSItem
|
||
{
|
||
Zwbid = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() + i.ToString(),
|
||
Pspid = System_objNBS109,
|
||
Post1Proj = item.fld004502,
|
||
Pspnr = hierarchicalCoding3,
|
||
Post1 = item.Description,
|
||
Pstrt = StartDate,
|
||
Pende = EndDate,
|
||
Istrt = fld006934,
|
||
Iende = fld006746,
|
||
Usr00 = "",
|
||
Prart = fld006770,
|
||
SystemStatus = fld004506,
|
||
SystemStatus2 = fld006747,
|
||
Zresv1 = "",
|
||
Zresv2 = "",
|
||
Zresv3 = "",
|
||
Zresv4 = "",
|
||
Zresv5 = ""
|
||
};
|
||
sapUpdateInputItem.Add(itemData);
|
||
}
|
||
if (item.fld006771 == "" || item.fld006771 == null)
|
||
{
|
||
var itemData = new SapCreateWBSItem
|
||
{
|
||
Zwbid = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() + i.ToString(),
|
||
Pspid = System_objNBS109,
|
||
Pspnr = hierarchicalCoding2,
|
||
Pspnr2 = hierarchicalCoding3,
|
||
Post1 = item.Description,
|
||
Pstrt = StartDate,
|
||
Pende = EndDate,
|
||
Istrt = fld006934,
|
||
Iende = fld006746,
|
||
Usr00 = "",
|
||
Prart = fld006770,
|
||
Zresv1 = "",
|
||
Zresv2 = "",
|
||
Zresv3 = "",
|
||
Zresv4 = "",
|
||
Zresv5 = ""
|
||
};
|
||
if (fld006770 == "6")
|
||
{
|
||
itemData.Pspnr = "";
|
||
}
|
||
if (!string.IsNullOrEmpty(item.fld006745))
|
||
{
|
||
intsCreate.Add(item.stageIdRecord);
|
||
sapCreateInputItem.Add(itemData);
|
||
}
|
||
}
|
||
|
||
|
||
}
|
||
if (item.indentLevel == 3)
|
||
{
|
||
hierarchicalCoding4 = item.fld006745;
|
||
if (item.fld006771 == "M")
|
||
{
|
||
intsUpdate.Add(item.stageIdRecord);
|
||
var itemData = new SapUpdateWBSItem
|
||
{
|
||
Zwbid = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() + i.ToString(),
|
||
Pspid = System_objNBS109,
|
||
Post1Proj = item.fld004502,
|
||
Pspnr = hierarchicalCoding4,
|
||
Post1 = item.Description,
|
||
Pstrt = StartDate,
|
||
Pende = EndDate,
|
||
Istrt = fld006934,
|
||
Iende = fld006746,
|
||
Usr00 = "",
|
||
Prart = fld006770,
|
||
SystemStatus = fld004506,
|
||
SystemStatus2 = fld006747,
|
||
Zresv1 = "",
|
||
Zresv2 = "",
|
||
Zresv3 = "",
|
||
Zresv4 = "",
|
||
Zresv5 = ""
|
||
};
|
||
sapUpdateInputItem.Add(itemData);
|
||
}
|
||
if (item.fld006771 == "" || item.fld006771 == null)
|
||
{
|
||
var itemData = new SapCreateWBSItem
|
||
{
|
||
Zwbid = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() + i.ToString(),
|
||
Pspid = System_objNBS109,
|
||
Pspnr = hierarchicalCoding3,
|
||
Pspnr2 = hierarchicalCoding4,
|
||
Post1 = item.Description,
|
||
Pstrt = StartDate,
|
||
Pende = EndDate,
|
||
Istrt = fld006934,
|
||
Iende = fld006746,
|
||
Usr00 = "",
|
||
Prart = fld006770,
|
||
Zresv1 = "",
|
||
Zresv2 = "",
|
||
Zresv3 = "",
|
||
Zresv4 = "",
|
||
Zresv5 = ""
|
||
};
|
||
if (fld006770 == "6")
|
||
{
|
||
itemData.Pspnr = "";
|
||
}
|
||
if (!string.IsNullOrEmpty(item.fld006745))
|
||
{
|
||
intsCreate.Add(item.stageIdRecord);
|
||
sapCreateInputItem.Add(itemData);
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|
||
if (sapCreateInputItem.Count > 0)
|
||
{
|
||
var sapInput = new SapCreateWBSInput
|
||
{
|
||
ReqKeyId = "",
|
||
BusinessId = "",
|
||
MessageId = "",
|
||
SndPrn = "PLM",
|
||
RcvPrn = "SAP",
|
||
ReqUser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName),
|
||
Note1 = "",
|
||
Note2 = "",
|
||
Note3 = "",
|
||
SapCreateWBSItem = sapCreateInputItem
|
||
};
|
||
var output = await _sapService.SapCreateWBS(sapInput);
|
||
sapOutput.Add(output);
|
||
if (output.code == "S")
|
||
{
|
||
//await _obj126Rep.AsUpdateable()
|
||
// .SetColumns(it => it.fld006772 == DateTime.Now && it.fld006771 == "N" && it.fld006773 == output.msg && it.fld006990 == "成功")
|
||
// .Where(it => intsCreate.Contains(it.idRecord))
|
||
// .ExecuteCommandAsync();
|
||
//await _obj109Rep.AsUpdateable().SetColumns(it => it.fld006775 == DateTime.Now && it.fld006774 == "N" && it.fld006776 == output.msg).Where(it => it.idRecord == projectIdRecord).ExecuteCommandAsync();
|
||
|
||
foreach (var item in intsCreate)
|
||
{
|
||
await UpdateObj126(item, output.msg, "创建成功");
|
||
}
|
||
await UpdateObj109(projectIdRecord, output.msg, "修改成功");
|
||
}
|
||
else
|
||
{
|
||
foreach (var item in intsCreate)
|
||
{
|
||
await UpdateObj126(item, output.msg, "修改失败");
|
||
}
|
||
await UpdateObj109(projectIdRecord, output.msg, "创建失败");
|
||
}
|
||
//await _obj109Rep.AsUpdateable().SetColumns(it => it.fld006775 == DateTime.Now && it.fld006774 == "N" && it.fld006776 == output.msg).Where(it => it.idRecord == projectIdRecord).ExecuteCommandAsync();
|
||
}
|
||
if (sapUpdateInputItem.Count > 0)
|
||
{
|
||
var sapInput = new SapUpdateWBSInput
|
||
{
|
||
ReqKeyId = "",
|
||
BusinessId = "",
|
||
MessageId = "",
|
||
SndPrn = "PLM",
|
||
RcvPrn = "SAP",
|
||
ReqUser = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName),
|
||
Note1 = "",
|
||
Note2 = "",
|
||
Note3 = "",
|
||
SapUpdateWBSItem = sapUpdateInputItem
|
||
};
|
||
var output = await _sapService.SapUpdateWBS(sapInput);
|
||
output.materialCode = materialCode;
|
||
sapOutput.Add(output);
|
||
if (output.code == "S")
|
||
{
|
||
//await _obj126Rep.AsUpdateable()
|
||
// .SetColumns(it => it.fld006772 == DateTime.Now && it.fld006771 == "N" && it.fld006773 == output.msg && it.fld006990 == "成功")
|
||
// .Where(it => intsUpdate.Contains(it.idRecord))
|
||
// .ExecuteCommandAsync();
|
||
//await _obj109Rep.AsUpdateable().SetColumns(it=>it.fld006775==DateTime.Now&&it.fld006774=="N"&&it.fld006776== output.msg).Where(it=>it.idRecord== projectIdRecord).ExecuteCommandAsync();
|
||
|
||
foreach (var item in intsUpdate)
|
||
{
|
||
await UpdateObj126(item, output.msg, "修改成功");
|
||
}
|
||
await UpdateObj109(projectIdRecord, output.msg, "修改成功");
|
||
}
|
||
else
|
||
{
|
||
foreach (var item in intsUpdate)
|
||
{
|
||
await UpdateObj126(item, output.msg, "修改失败");
|
||
}
|
||
await UpdateObj109(projectIdRecord, output.msg, "修改失败");
|
||
}
|
||
//await _obj109Rep.AsUpdateable().SetColumns(it => it.fld006775 == DateTime.Now && it.fld006774 == "N" && it.fld006776 == output.msg).Where(it => it.idRecord == projectIdRecord).ExecuteCommandAsync();
|
||
}
|
||
return sapOutput;
|
||
|
||
}
|
||
|
||
}
|