201 lines
8.2 KiB
C#
201 lines
8.2 KiB
C#
// Admin.NET 项目的版权、商标、专利和其他相关权利均受相应法律法规的保护。使用本项目应遵守相关法律法规和许可证的要求。
|
|
//
|
|
// 本项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。许可证位于源代码树根目录中的 LICENSE-MIT 和 LICENSE-APACHE 文件。
|
|
//
|
|
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
|
|
|
|
using Admin.NET.Core;
|
|
using Admin.NET.Core.Service;
|
|
using Furion.DependencyInjection;
|
|
using Furion.DynamicApiController;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using NewLife.Xml;
|
|
using SqlSugar;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
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.Util;
|
|
using static Org.BouncyCastle.Math.Primes;
|
|
|
|
namespace Vistar.Application.Service.PurchasingRequisition;
|
|
|
|
/// <summary>
|
|
/// 研发采购申请服务
|
|
/// </summary>
|
|
[ApiDescriptionSettings(ApplicationConst.GroupName, Name = "PurchasingRequisition", Order = 100)]
|
|
public class PurchasingRequisitionService : IDynamicApiController, ITransient
|
|
{
|
|
private readonly SqlSugarRepository<Obj119> _obj119Rep;
|
|
private readonly SqlSugarRepository<Obj109> _obj109Rep;
|
|
private readonly SqlSugarRepository<Configurations> _configurationsRep;
|
|
private readonly SysConfigService _sysConfigService;
|
|
private readonly SqlSugarRepository<ConfigurationData> _configurationDataRep;
|
|
public SapService.SapService _sapService;
|
|
public SqlSugarRepository<Obj118> _obj118Rep;
|
|
public Common.DataValidationService _dataValidationService;
|
|
public SqlSugarRepository<Obj122> _obj122Rep;
|
|
public SqlSugarRepository<Obj121> _obj121Rep;
|
|
public SqlSugarRepository<Obj81> _obj81Rep;
|
|
private readonly IServiceScopeFactory _scopeFactory;
|
|
|
|
public PurchasingRequisitionService(
|
|
SqlSugarRepository<Obj119> obj119Rep,
|
|
SqlSugarRepository<Configurations> configurationsRep,
|
|
SysConfigService sysConfigService,
|
|
SqlSugarRepository<ConfigurationData> configurationDataRep,
|
|
SapService.SapService sapService,
|
|
SqlSugarRepository<Obj118> obj118Rep,
|
|
DataValidationService dataValidationService,
|
|
SqlSugarRepository<Obj122> obj122Rep,
|
|
SqlSugarRepository<Obj121> obj121Rep,
|
|
SqlSugarRepository<Obj109> obj109Rep,
|
|
SqlSugarRepository<Obj81> obj81Rep,
|
|
IServiceScopeFactory scopeFactory
|
|
|
|
)
|
|
{
|
|
_obj119Rep = obj119Rep;
|
|
_configurationsRep = configurationsRep;
|
|
_sysConfigService = sysConfigService;
|
|
_configurationDataRep = configurationDataRep;
|
|
_sapService = sapService;
|
|
_obj118Rep = obj118Rep;
|
|
_dataValidationService = dataValidationService;
|
|
_obj122Rep = obj122Rep;
|
|
_obj121Rep = obj121Rep;
|
|
_obj109Rep = obj109Rep;
|
|
_obj81Rep = obj81Rep;
|
|
_scopeFactory = scopeFactory;
|
|
}
|
|
/// <summary>
|
|
/// 创建研发采购申请
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<List<SapOutput>> TimingSyncToSAPPurchasingRequisition()
|
|
{
|
|
using var serviceScope = _scopeFactory.CreateScope();
|
|
var db = serviceScope.ServiceProvider.GetRequiredService<ISqlSugarClient>().AsTenant().GetConnectionScope("启威星 1.94.4.74").CopyNew();
|
|
|
|
var sapOutputList = new List<SapOutput>();
|
|
//获取Sap用户名
|
|
var sapUserName = await _sysConfigService.GetConfigValueByCode<string>(ConfigConst.SapUserName);
|
|
|
|
// 配置ID 数据库Configurations表
|
|
var configid = 10;
|
|
|
|
// 获取符合条件的采购申请单
|
|
var PurchasingRequisitionList = await db.CopyNew().Queryable<Obj119>().Where(x => x.fld006416 == "A" && x.deleted == false && x.CheckedStatus == false && x._System_CurrentStage == "结束").ToListAsync();
|
|
|
|
foreach (var item in PurchasingRequisitionList)
|
|
{
|
|
var itemList = new List<SapPurchasingRequisitionItem>();
|
|
var SapPurchasingRequisition = new SapPurchasingRequisitionInput
|
|
{
|
|
Reqkeyid = "",
|
|
Businessid = "",
|
|
Messageid = "",
|
|
Sndprn = "PLM",
|
|
Rcvprn = "SAP",
|
|
Requser = sapUserName,
|
|
Note1 = "",
|
|
Note2 = "",
|
|
Note3 = "",
|
|
Zwbid = item._System_objNBS,
|
|
Banfn = item.fld006138,
|
|
Bsart = "Z002",
|
|
Zoperate = item.fld006139,
|
|
Zttby1 = item.fld006311,
|
|
Zttby2 = item.fld006312,
|
|
Zttby3 = item.fld006313,
|
|
Item = itemList
|
|
};
|
|
|
|
//查询BOM
|
|
var bomData = await db.CopyNew().Queryable<ConfigurationData>().Where(x => x.ConfigId == configid && x.ParentGuid == item.RecordGuid && x.isDeleted == false && x.ParentVersion == item.VersionIndex).ToListAsync();
|
|
var project = await db.CopyNew().Queryable<Obj119>().Where(x => x.RecordGuid == item.fld004639_Rec && x.deleted == false).OrderByDescending(x => x.VersionIndex).FirstAsync();
|
|
foreach (var bomItem in bomData)
|
|
{
|
|
var unit = await _dataValidationService.GetUnit(bomItem.ChildObjID, bomItem.ChildGuid);
|
|
var Item = new SapPurchasingRequisitionItem
|
|
{
|
|
Bnfpo = bomItem.Marker,
|
|
Zzjjbs = bomItem.fld006140,
|
|
Knttp = bomItem.fld006142,
|
|
Pstyp = bomItem.fld006143,
|
|
Matnr = bomItem.PartNumber,
|
|
Txz01 = "",
|
|
Menge = bomItem.Quantity.ToString(),
|
|
Meins = unit,
|
|
Lfdat = bomItem.fld006144.ToString("yyyy-MM-dd"),
|
|
Matkl = "",
|
|
Werks = bomItem.fld006145,
|
|
Lgort = bomItem.fld006146,
|
|
Ekgrp = "",
|
|
Ekorg = bomItem.fld006147,
|
|
Zzpspnr = project._System_objNBS,
|
|
Afnam = item.fld006125,
|
|
Loekz = bomItem.fld006141,
|
|
Ztext = item.fld007052
|
|
|
|
};
|
|
itemList.Add(Item);
|
|
}
|
|
var sapOutput = await _sapService.SapPurchasingRequisitionApi(SapPurchasingRequisition);
|
|
|
|
string codeVal = sapOutput.code == "S" ? "成功" : "失败";
|
|
string msg = sapOutput.msg;
|
|
|
|
if (sapOutput.msg == "")
|
|
{
|
|
msg = "同步成功";
|
|
}
|
|
if (item.fld006139 == "I")
|
|
{
|
|
db.CopyNew().Updateable<Obj119>()
|
|
.SetColumns(it => new Obj119
|
|
{
|
|
fld005934 = DateTime.Now,//同步日期
|
|
fld005933 = codeVal,//同步状态
|
|
fld006416 = "N",//同步标识
|
|
fld005935 = msg,//同步信息
|
|
fld006138 = sapOutput.banfn//采购申请编号
|
|
})
|
|
.Where(it => it.idRecord == item.idRecord)
|
|
.ExecuteCommand();
|
|
}
|
|
if (item.fld006139 == "U")
|
|
{
|
|
db.CopyNew().Updateable<Obj119>()
|
|
.SetColumns(it => new Obj119
|
|
{
|
|
fld005934 = DateTime.Now,//同步日期
|
|
fld005933 = codeVal,//同步状态
|
|
fld006416 = "N",//同步标识
|
|
fld005935 = msg//同步信息
|
|
})
|
|
.Where(it => it.idRecord == item.idRecord)
|
|
.ExecuteCommand();
|
|
}
|
|
var output = new SapOutput()
|
|
{
|
|
parameter = sapOutput.parameter,
|
|
materialCode = item._System_objNBS,
|
|
code = codeVal,
|
|
msg = msg,
|
|
result = sapOutput.result
|
|
};
|
|
sapOutputList.Add(output);
|
|
}
|
|
|
|
return sapOutputList;
|
|
}
|
|
}
|