IcsFromERPJob
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

169 lines
9.3 KiB

using Quartz;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Runtime.Remoting.Messaging;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace ICSSoft.FromERP
{
/// <summary>
/// Item Master(物料主数据)
/// </summary>
public class YERP_008 : IJob
{
private static object key = new object();
private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public void Execute(IJobExecutionContext context)
{
try
{
lock (key)
{
log.Info("开始……………………………………………………………………");
Execute();
log.Info("结束……………………………………………………………………");
}
}
catch (Exception ex)
{
log.Error(ex.ToString());
}
}
public async void Execute()
{
try
{
Configuration config = GetConfig();
var Dates = DateTime.Now;
string conStr = ICSHelper.GetConnectString();
//<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:yerp="http://skch.com/YERP_008_ITEM_INFO">
// <soapenv:Header/>
// <soapenv:Body>
// <yerp:YERP_008_OA1_MT>
// <!--Zero or more repetitions: -->
// <IF_ITEM_MST>
// <IF_STD_DATE>20240814</IF_STD_DATE>
// <ITEM_CD>201010</ITEM_CD>
// <ITEM_NM>ECOTRION H1000</ITEM_NM>
// <!--Optional:-->
// <ITEM_PACK_UOM>kg</ITEM_PACK_UOM>
// <!--Optional:-->
// <CREATE_DTTM>20230713</CREATE_DTTM>
// <!--Optional:-->
// <CREATE_BY>21436</CREATE_BY>
// <!--Optional:-->
// <ROW_CNT>1</ROW_CNT>
// </IF_ITEM_MST>
// </yerp:YERP_008_OA1_MT>
// </soapenv:Body>
// </soapenv:Envelope>
// 过滤时间为上个月
var beginPeriod = Dates.AddMonths(-1).AddDays(-Dates.Day + 1).ToString("yyyy-MM-dd");//"2023-06-01";
var endPeriod = Dates.AddDays(-Dates.Day + 1).ToString("yyyy-MM-dd");//"2023-07-01";
string sqls = @"select convert(nvarchar(10),getdate(),112) IF_STD_DATE,
cInvCode ITEM_CD,
d.cInvCName+' '+cInvName ITEM_NM,
a.cInvCCode BRND_CD,
'' GRADE_CD,
d.cInvCName BRND_NM,
cInvName GRADE_NM,
cInvStd ITEM_PACK_UOM,
(case when cInvStd is null then '0' else (CASE WHEN ISNUMERIC(left(cinvstd,3)) = 1 THEN left(cinvstd,3) ELSE (CASE WHEN ISNUMERIC(left(cinvstd,2)) = 1
THEN left(cinvstd,2) ELSE (CASE WHEN ISNUMERIC(left(cinvstd,1)) = 1 THEN left(cinvstd,1) ELSE 0 END) END) END) end) PACK_MIN_QTY,
dInvCreateDatetime CREATE_DTTM,
cCreatePerson CREATE_BY,
dModifyDate MODIFY_DTTM,
cModifyPerson MODIFY_BY,
COUNT(*) OVER (PARTITION BY getdate()) ROW_CNT
from dbo.Inventory a
left join dbo.Inventory_Sub b on a.cInvCode=b.cInvSubCode
left join dbo.ComputationUnit c on a.cComUnitCode=c.cComunitCode
left join dbo.InventoryClass d on a.cInvCCode=d.cInvCCode
WHERE 1 = 1 ";//and dInvCreateDatetime > '{0}' and dInvCreateDatetime < '{1}'
sqls = string.Format(sqls, beginPeriod, endPeriod);
log.Info("YERP_008 sql:"+sqls);
DataTable vbsdt = ICSHelper.ExecuteTable(conStr, sqls);
log.Info("YERP_008 sql结果数量" + vbsdt.Rows.Count);
if (vbsdt.Rows.Count > 0)
{
StringBuilder soapRequestData = new StringBuilder();
soapRequestData.Append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:yerp=\"http://skch.com/YERP_008_ITEM_INFO\">");
soapRequestData.Append("<soapenv:Header/>");
soapRequestData.Append("<soapenv:Body>");
soapRequestData.Append("<yerp:YERP_008_OA1_MT>");
//循环数据
foreach (DataRow itemRow in vbsdt.Rows)
{
soapRequestData.Append("<!--Zero or more repetitions: -->");
soapRequestData.Append("<IF_ITEM_MST>");
soapRequestData.Append(itemRow["IF_STD_DATE"] != null ? "<IF_STD_DATE>" + itemRow["IF_STD_DATE"].ToString() + "</IF_STD_DATE>" : "<IF_STD_DATE>" + "</IF_STD_DATE>");
soapRequestData.Append(itemRow["ITEM_CD"] != null ? "<ITEM_CD>" + itemRow["ITEM_CD"].ToString() + "</ITEM_CD>" : "<ITEM_CD>" + "</ITEM_CD>");
soapRequestData.Append(itemRow["ITEM_NM"] != null ? "<ITEM_NM>" + itemRow["ITEM_NM"].ToString() + "</ITEM_NM>" : "<ITEM_NM>" + "</ITEM_NM>");
soapRequestData.Append("<!--Optional:-->");
soapRequestData.Append(itemRow["ITEM_PACK_UOM"] != null ? "<ITEM_PACK_UOM>" + Regex.Replace(itemRow["ITEM_PACK_UOM"].ToString(), @"[^0-9]+", "") + "</ITEM_PACK_UOM>" : "<ITEM_PACK_UOM>" + "</ITEM_PACK_UOM>");
soapRequestData.Append("<!--Optional:-->");
soapRequestData.Append(itemRow["CREATE_DTTM"] != null ? "<CREATE_DTTM>" + itemRow["CREATE_DTTM"].ToString() + "</CREATE_DTTM>" : "<CREATE_DTTM>" + "</CREATE_DTTM>");
soapRequestData.Append("<!--Optional:-->");
soapRequestData.Append(itemRow["CREATE_BY"] != null ? "<CREATE_BY>" + itemRow["CREATE_BY"].ToString() + "</CREATE_BY>" : "<CREATE_BY>" + "</CREATE_BY>");
soapRequestData.Append("<!--Optional:-->");
soapRequestData.Append(itemRow["ROW_CNT"] != null ? "<ROW_CNT>" + itemRow["ROW_CNT"].ToString() + "</ROW_CNT>" : "<ROW_CNT>" + "</ROW_CNT>");
soapRequestData.Append("</IF_ITEM_MST>");
}
soapRequestData.Append("</yerp:YERP_008_OA1_MT>");
soapRequestData.Append("</soapenv:Body>");
soapRequestData.Append("</soapenv:Envelope>");
string postData = soapRequestData.ToString();
log.Info("YERP_008 xmlRequest:" + postData);
string statusCode;
string resultContent;
ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;
RestOpHelper rop = new RestOpHelper();
rop.Clientp12path = @"C:\Users\Administrator\Desktop\yonyou-cert\wildcard.pfx";
rop.Clientp12PassWord = "Yonyou2024!";
rop.Url = @"https://yerp-proxy-sap-dev.skchemicals.com/XISOAPAdapter/MessageServlet?senderParty=&senderService=YERP_D&receiverParty=&receiverService=&interface=YERP_008_OA1_SI&interfaceNamespace=http://skch.com/YERP_008_ITEM_INFO";
rop.RequestSAP(rop.Url, 10000, postData, "IF_YERP", "Xtxc355860", out statusCode, out resultContent);
log.Info("YERP_008 statusCode:" + statusCode + "\r\n" + "resultContent:" + resultContent);
}
}
catch (Exception ex)
{
log.Error(ex.ToString());
}
}
public static Configuration GetConfig()
{
Assembly assembly = Assembly.GetCallingAssembly();
string path = string.Format("{0}.config", assembly.Location);
if (!File.Exists(path))
{
throw new FileNotFoundException(path + "路径下的文件未找到!");
}
try
{
ExeConfigurationFileMap configFile = new ExeConfigurationFileMap();
configFile.ExeConfigFilename = path;
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFile, ConfigurationUserLevel.None);
return config;
}
catch (Exception)
{
throw;
}
}
}
}