|
|
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.Text; using System.Text.RegularExpressions; using System.Threading.Tasks;
namespace ICSSoft.FromERP { /// <summary>
/// Sales performance(销售业绩)
/// </summary>
public class YERP_012 : 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_012_IF_SALES_ACT">
// <soapenv:Header/>
// <soapenv:Body>
// <yerp:YERP_012_OA1_MT>
// <!--Zero or more repetitions:-->
// <IF_ACT_SALES>
// <IF_STD_DATE>?</IF_STD_DATE>
// <INVOICE_DATE>?</INVOICE_DATE>
// <ITEM_CD>2</ITEM_CD>
// <ITEM_NM>3</ITEM_NM>
// <SKU_PAYMT_QTY>3</SKU_PAYMT_QTY>
// <SKU_PAYMT_QTY_UOM>4</SKU_PAYMT_QTY_UOM>
// <PAYMT_PRICE>5</PAYMT_PRICE>
// <SALES_SITE_CD>5</SALES_SITE_CD>
// <SALES_SITE_NM>5</SALES_SITE_NM>
// <!--Optional:-->
// <CREATE_BY>?</CREATE_BY>
// <GEN_ROW_CNT>?</GEN_ROW_CNT>
// </IF_ACT_SALES>
// </yerp:YERP_012_OA1_MT>
// </soapenv:Body>
//</soapenv:Envelope>
// 过滤时间为上个月
var beginPeriod = Dates.AddDays(-1).ToString("yyyy-MM-dd");//"2023-06-01";
var endPeriod = Dates.ToString("yyyy-MM-dd");//"2023-06-30";
string sqls = @"select
IF_STD_DATE,INVOICE_DATE,ITEM_CD,ITEM_NM,SKU_PAYMT_QTY_UOM,SALES_SITE_CD,SALES_SITE_NM,CREATE_BY,COUNT(*) OVER (PARTITION BY getdate()) GEN_ROW_CNT ,SUM(SKU_PAYMT_QTY) SKU_PAYMT_QTY,SUM(PAYMT_PRICE) PAYMT_PRICE from ( select convert(nvarchar(10),getdate(),112) IF_STD_DATE, convert(nvarchar(10),a.dDate,111) INVOICE_DATE, b.cInvCode ITEM_CD, c.cInvName ITEM_NM, CAST(iQuantity AS INT) SKU_PAYMT_QTY, d.cComUnitName SKU_PAYMT_QTY_UOM, a.cCusCode SALES_SITE_CD, e.cCusName SALES_SITE_NM, dcreatesystime CREATE_DTTM, b.iNatSum PAYMT_PRICE, cMaker CREATE_BY, dmodifysystime MODIFY_DTTM from dbo.SO_SOMain a left join dbo.SO_SODetails b on a.ID=b.ID left join dbo.Inventory c on b.cInvCode=c.cInvCode left join dbo.ComputationUnit d on c.cComUnitCode=d.cComunitCode left join dbo.Customer e on a.cCusCode=e.cCusCode WHERE 1 = 1 and dcreatesystime >= '{0}' and dcreatesystime < '{1}' ) a group by IF_STD_DATE,INVOICE_DATE,ITEM_CD,ITEM_NM,SKU_PAYMT_QTY_UOM,SALES_SITE_CD,SALES_SITE_NM,CREATE_BY";//
sqls = string.Format(sqls, beginPeriod, endPeriod); log.Info("YERP_012 sql:" + sqls); DataTable vbsdt = ICSHelper.ExecuteTable(conStr, sqls); log.Info("YERP_012 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_012_IF_SALES_ACT\">"); soapRequestData.Append("<soapenv:Header/>"); soapRequestData.Append("<soapenv:Body>"); soapRequestData.Append("<yerp:YERP_012_OA1_MT>"); //循环数据 PAYMT_PRICE INVOICE_DATE GEN_ROW_CNT
foreach (DataRow itemRow in vbsdt.Rows) { soapRequestData.Append("<!--Zero or more repetitions: -->"); soapRequestData.Append("<IF_ACT_SALES>"); 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["INVOICE_DATE"] != null ? "<INVOICE_DATE>" + itemRow["INVOICE_DATE"].ToString() + "</INVOICE_DATE>" : "<INVOICE_DATE>" + "</INVOICE_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["SKU_PAYMT_QTY"] != null ? "<SKU_PAYMT_QTY>" + itemRow["SKU_PAYMT_QTY"].ToString() + "</SKU_PAYMT_QTY>" : "<SKU_PAYMT_QTY>" + "</SKU_PAYMT_QTY>"); soapRequestData.Append("<!--Optional:-->"); soapRequestData.Append(itemRow["SKU_PAYMT_QTY_UOM"] != null ? "<SKU_PAYMT_QTY_UOM>" + itemRow["SKU_PAYMT_QTY_UOM"].ToString() + "</SKU_PAYMT_QTY_UOM>" : "<SKU_PAYMT_QTY_UOM>" + "</SKU_PAYMT_QTY_UOM>"); soapRequestData.Append("<!--Optional:-->"); soapRequestData.Append(itemRow["SALES_SITE_CD"] != null ? "<SALES_SITE_CD>" + itemRow["SALES_SITE_CD"].ToString() + "</SALES_SITE_CD>" : "<SALES_SITE_CD>" + "</SALES_SITE_CD>"); soapRequestData.Append("<!--Optional:-->"); soapRequestData.Append(itemRow["SALES_SITE_NM"] != null ? "<SALES_SITE_NM>" + itemRow["SALES_SITE_NM"].ToString() + "</SALES_SITE_NM>" : "<SALES_SITE_NM>" + "</SALES_SITE_NM>"); soapRequestData.Append("<!--Optional:-->"); soapRequestData.Append(itemRow["PAYMT_PRICE"] != null ? "<PAYMT_PRICE>" + itemRow["PAYMT_PRICE"].ToString() + "</PAYMT_PRICE>" : "<PAYMT_PRICE>" + "</PAYMT_PRICE>"); 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["GEN_ROW_CNT"] != null ? "<GEN_ROW_CNT>" + itemRow["GEN_ROW_CNT"].ToString() + "</GEN_ROW_CNT>" : "<GEN_ROW_CNT>" + "</GEN_ROW_CNT>"); soapRequestData.Append("</IF_ACT_SALES>"); }
soapRequestData.Append("</yerp:YERP_012_OA1_MT>"); soapRequestData.Append("</soapenv:Body>"); soapRequestData.Append("</soapenv:Envelope>"); string postData = soapRequestData.ToString(); log.Info("YERP_012 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-prod.skchemicals.com/XISOAPAdapter/MessageServlet?senderParty=&senderService=YERP_P&receiverParty=&receiverService=&interface=YERP_012_OA1_SI&interfaceNamespace=http://skch.com/YERP_012_IF_SALES_ACT"; rop.RequestSAP(rop.Url, 10000, postData, "IF_YERP", "Kfiw282082", out statusCode, out resultContent);
log.Info("YERP_012 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; } } } }
|