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.

228 lines
15 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.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace ICSSoft.FromERP
{
/// <summary>
/// 销售发票列表
/// </summary>
public class YERP_002 : 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();
//string url = config.ConnectionStrings.ConnectionStrings["APIAddStdWorkHour"].ConnectionString.ToString();
var Dates = DateTime.Now;
string conStr = ICSHelper.GetConnectString();
// 202404
// 过滤时间为上个月
string Date = Dates.ToString("yyyy");
string Muoth = Dates.AddMonths(-1).ToString("MM");
string Day = Dates.ToString("dd");
//<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:yerp="http://skch.com/YERP_002_SALES_INVOICE">
// <soapenv:Header/>
// <soapenv:Body>
// <yerp:YERP_002_OA1_MT>
// <!--1 or more repetitions:-->
// <SLS_INVC>
// <!--Optional:-->
// <P_ORDER_NUM>?</P_ORDER_NUM>
// <BIZ_TYP>?</BIZ_TYP>
// <SL_TYP>?</SL_TYP>
// <INVC_NO>?</INVC_NO>
// <INVC_DE>?</INVC_DE>
// <DO_NO>?</DO_NO>
// <CUST_CD>?</CUST_CD>
// <CUST_NM>?</CUST_NM>
// <CUR>?</CUR>
// <ER>?</ER>
// <!--Optional:-->
// <SL_TEAM>?</SL_TEAM>
// <!--Optional:-->
// <SL_PIC>?</SL_PIC>
// <WH>?</WH>
// <INVT_CD>?</INVT_CD>
// <INVT_NM>?</INVT_NM>
// <!--Optional:-->
// <STDD_MDL>?</STDD_MDL>
// <QTY>?</QTY>
// <!--Optional:-->
// <STMT>?</STMT>
// <PRTX_UPRC>?</PRTX_UPRC>
// <FRTX_UPRC>?</FRTX_UPRC>
// <FRTX_AMT>?</FRTX_AMT>
// <TXRTO>?</TXRTO>
// <TX_AMT>?</TX_AMT>
// <PRTX_AMT>?</PRTX_AMT>
// <!--Optional:-->
// <DISRTO1>?</DISRTO1>
// <!--Optional:-->
// <DISRTO2>?</DISRTO2>
// <!--Optional:-->
// <DIS_AMT>?</DIS_AMT>
// <CRTR>?</CRTR>
// <REVR>?</REVR>
// <!--Optional:-->
// <STTL_TYP_CD>?</STTL_TYP_CD>
// <!--Optional:-->
// <DLVR_TYP_CD>?</DLVR_TYP_CD>
// <!--Optional:-->
// <DLVR_TYP>?</DLVR_TYP>
// <!--Optional:-->
// <STTL_TYP>?</STTL_TYP>
// <OUTST_AMT>?</OUTST_AMT>
// <OUTST_LCUR>?</OUTST_LCUR>
// </SLS_INVC>
// </yerp:YERP_002_OA1_MT>
// </soapenv:Body>
//</soapenv:Envelope>
var beginPeriod = "2023-07-01";// Dates.AddMonths(-1).AddDays(-Dates.Day + 1).ToString("yyyy-MM-dd");//"2023-06-01";
var endPeriod = "2023-08-01";// Dates.AddDays(-Dates.Day + 1).ToString("yyyy-MM-dd");//"2023-07-01";
string sqls = @"
select b.cSOCode P_ORDER_NUM,cBusType BIZ_TYP,cSTName SL_TYP,cSBVCode INVC_NO,dDate INVC_DE,cDLCode DO_NO,cCusCode CUST_CD,cCusName CUST_NM,cexch_name CUR,iExchRate ER,
cDepName SL_TEAM, cPsn_Name SL_PIC,cWhCode WH, b.cInvCode INVT_CD, c.cInvAddCode INVT_ACD, c.cInvName INVT_NM, c.cInvStd STDD_MDL, b.iQuantity QTY, b.iQuotedPrice STMT, iTaxUnitPrice PRTX_UPRC,
iUnitPrice FRTX_UPRC, iMoney FRTX_AMT,b.iTaxRate TXRTO, iTax TX_AMT,iSum PRTX_AMT, KL DISRTO1,KL2 DISRTO2, iDisCount DIS_AMT,cMaker CRTR, cChecker REVR,a.csscode STTL_TYP_CD, a.cSCCode DLVR_TYP_CD,
d.cSCName DLVR_TYP, cSSName STTL_TYP,
iSum - iExchSum OUTST_AMT, --原币价税合计 - 累计原币收款金额
iNatSum - iMoneySum OUTST_LCUR, --本币价税合计-累计本币收款金额
0 Printnum,a.dDate
from dbo.SaleBillVouch a left join dbo.SaleBillVouchs b on A.SBVID = B.SBVID
left join dbo.Inventory c on b.cInvCode = c.cInvCode
left join dbo.ShippingChoice d on a.cSCCode = d.cSCCode
left join dbo.SettleStyle e on a.csscode = e.cSSCode
left join dbo.SaleType f on a.cSTCode = f.cSTCode
left join dbo.hr_hi_person h on a.cPersonCode = h.cPsn_Num
left join dbo.Department j on j.cDepCode = a.cDepCode WHERE 1 = 1 and a.dDate >= '{0}' and a.dDate <= '{1}'";
sqls = string.Format(sqls, beginPeriod, endPeriod);
log.Info("YERP_002 sql:" + sqls);
DataTable vbsdt = ICSHelper.ExecuteTable(conStr, sqls);
log.Info("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_002_SALES_INVOICE\">");
soapRequestData.Append("<soapenv:Header/>");
soapRequestData.Append("<soapenv:Body>");
soapRequestData.Append("<yerp:YERP_002_OA1_MT>");
//循环数据
foreach (DataRow itemRow in vbsdt.Rows)
{
//原循环部分 begin
soapRequestData.Append("<SLS_INVC>");
soapRequestData.Append(itemRow["P_ORDER_NUM"] != null ? "<P_ORDER_NUM>" + itemRow["P_ORDER_NUM"].ToString() + "</P_ORDER_NUM>" : "<P_ORDER_NUM>" + "</P_ORDER_NUM>");
soapRequestData.Append(itemRow["BIZ_TYP"] != null ? "<BIZ_TYP>" + itemRow["BIZ_TYP"].ToString() + "</BIZ_TYP>" : "<BIZ_TYP>" + "</BIZ_TYP>");
soapRequestData.Append(itemRow["SL_TYP"] != null ? "<SL_TYP>" + itemRow["SL_TYP"].ToString() + "</SL_TYP>" : "<SL_TYP>" + "</SL_TYP>");
soapRequestData.Append(itemRow["INVC_NO"] != null ? "<INVC_NO>" + itemRow["INVC_NO"].ToString() + "</INVC_NO>" : "<INVC_NO>" + "</INVC_NO>");
soapRequestData.Append(itemRow["INVC_DE"] != null ? "<INVC_DE>" + itemRow["INVC_DE"].ToString() + "</INVC_DE>" : "<INVC_DE>" + "</INVC_DE>");
soapRequestData.Append(itemRow["DO_NO"] != null ? "<DO_NO>" + itemRow["DO_NO"].ToString() + "</DO_NO>" : "<DO_NO>" + "</DO_NO>");
soapRequestData.Append(itemRow["CUST_CD"] != null ? "<CUST_CD>" + itemRow["CUST_CD"].ToString() + "</CUST_CD>" : "<CUST_CD>" + "</CUST_CD>");
soapRequestData.Append(itemRow["CUST_NM"] != null ? "<CUST_NM>" + itemRow["CUST_NM"].ToString() + "</CUST_NM>" : "<CUST_NM>" + "</CUST_NM>");
soapRequestData.Append(itemRow["CUR"] != null ? "<CUR>" + itemRow["CUR"].ToString() + "</CUR>" : "<CUR>" + "</CUR>");
soapRequestData.Append(itemRow["ER"] != null ? "<ER>" + itemRow["ER"].ToString() + "</ER>" : "<ER>" + "</ER>");
soapRequestData.Append(itemRow["SL_TEAM"] != null ? "<SL_TEAM>" + itemRow["SL_TEAM"].ToString() + "</SL_TEAM>" : "<SL_TEAM>" + "</SL_TEAM>");
soapRequestData.Append(itemRow["SL_PIC"] != null ? "<SL_PIC>" + itemRow["SL_PIC"].ToString() + "</SL_PIC>" : "<SL_PIC>" + "</SL_PIC>");
soapRequestData.Append(itemRow["WH"] != null ? "<WH>" + itemRow["WH"].ToString() + "</WH>" : "<WH>" + "</WH>");
soapRequestData.Append(itemRow["INVT_CD"] != null ? "<INVT_CD>" + itemRow["INVT_CD"].ToString() + "</INVT_CD>" : "<INVT_CD>" + "</INVT_CD>");
soapRequestData.Append(itemRow["INVT_NM"] != null ? "<INVT_NM>" + itemRow["INVT_NM"].ToString() + "</INVT_NM>" : "<INVT_NM>" + "</INVT_NM>");
soapRequestData.Append(itemRow["STDD_MDL"] != null ? "<STDD_MDL>" + Regex.Replace(itemRow["STDD_MDL"].ToString(), @"[^0-9]+", "") + "</STDD_MDL>" : "<STDD_MDL>" + "</STDD_MDL>");
soapRequestData.Append(itemRow["QTY"] != null ? "<QTY>" + itemRow["QTY"].ToString() + "</QTY>" : "<QTY>" + "</QTY>");
soapRequestData.Append(itemRow["STMT"] != null ? "<STMT>" + itemRow["STMT"].ToString() + "</STMT>" : "<STMT>" + "</STMT>");
soapRequestData.Append(itemRow["PRTX_UPRC"] != null ? "<PRTX_UPRC>" + itemRow["PRTX_UPRC"].ToString() + "</PRTX_UPRC>" : "<PRTX_UPRC>" + "</PRTX_UPRC>");
soapRequestData.Append(itemRow["FRTX_UPRC"] != null ? "<FRTX_UPRC>" + itemRow["FRTX_UPRC"].ToString() + "</FRTX_UPRC>" : "<FRTX_UPRC>" + "</FRTX_UPRC>");
soapRequestData.Append(itemRow["FRTX_AMT"] != null ? "<FRTX_AMT>" + itemRow["FRTX_AMT"].ToString() + "</FRTX_AMT>" : "<FRTX_AMT>" + "</FRTX_AMT>");
soapRequestData.Append(itemRow["TXRTO"] != null ? "<TXRTO>" + itemRow["TXRTO"].ToString() + "</TXRTO>" : "<TXRTO>" + "</TXRTO>");
soapRequestData.Append(itemRow["TX_AMT"] != null ? "<TX_AMT>" + itemRow["TX_AMT"].ToString() + "</TX_AMT>" : "<TX_AMT>" + "</TX_AMT>");
soapRequestData.Append(itemRow["PRTX_AMT"] != null ? "<PRTX_AMT>" + itemRow["PRTX_AMT"].ToString() + "</PRTX_AMT>" : "<PRTX_AMT>" + "</PRTX_AMT>");
soapRequestData.Append(itemRow["DISRTO1"] != null ? "<DISRTO1>" + itemRow["DISRTO1"].ToString() + "</DISRTO1>" : "<DISRTO1>" + "</DISRTO1>");
soapRequestData.Append(itemRow["DISRTO2"] != null ? "<DISRTO2>" + itemRow["DISRTO2"].ToString() + "</DISRTO2>" : "<DISRTO2>" + "</DISRTO2>");
soapRequestData.Append(itemRow["DIS_AMT"] != null ? "<DIS_AMT>" + itemRow["DIS_AMT"].ToString() + "</DIS_AMT>" : "<DIS_AMT>" + "</DIS_AMT>");
soapRequestData.Append(itemRow["CRTR"] != null ? "<CRTR>" + itemRow["CRTR"].ToString() + "</CRTR>" : "<CRTR>" + "</CRTR>");
soapRequestData.Append(itemRow["REVR"] != null ? "<REVR>" + itemRow["REVR"].ToString() + "</REVR>" : "<REVR>" + "</REVR>");
soapRequestData.Append(itemRow["STTL_TYP_CD"] != null ? "<STTL_TYP_CD>" + itemRow["STTL_TYP_CD"].ToString() + "</STTL_TYP_CD>" : "<STTL_TYP_CD>" + "</STTL_TYP_CD>");
soapRequestData.Append(itemRow["DLVR_TYP_CD"] != null ? "<DLVR_TYP_CD>" + itemRow["DLVR_TYP_CD"].ToString() + "</DLVR_TYP_CD>" : "<DLVR_TYP_CD>" + "</DLVR_TYP_CD>");
soapRequestData.Append(itemRow["DLVR_TYP"] != null ? "<DLVR_TYP>" + itemRow["DLVR_TYP"].ToString() + "</DLVR_TYP>" : "<DLVR_TYP>" + "</DLVR_TYP>");
soapRequestData.Append(itemRow["STTL_TYP"] != null ? "<STTL_TYP>" + itemRow["STTL_TYP"].ToString() + "</STTL_TYP>" : "<STTL_TYP>" + "</STTL_TYP>");
soapRequestData.Append(itemRow["OUTST_AMT"] != null ? "<OUTST_AMT>" + itemRow["OUTST_AMT"].ToString() + "</OUTST_AMT>" : "<OUTST_AMT>" + "</OUTST_AMT>");
soapRequestData.Append(itemRow["OUTST_LCUR"] != null ? "<OUTST_LCUR>" + itemRow["OUTST_LCUR"].ToString() + "</OUTST_LCUR>" : "<OUTST_LCUR>" + "</OUTST_LCUR>");
soapRequestData.Append("</SLS_INVC>");
//原循环部分 end
}
soapRequestData.Append("</yerp:YERP_002_OA1_MT>");
soapRequestData.Append("</soapenv:Body>");
soapRequestData.Append("</soapenv:Envelope>");
string postData = soapRequestData.ToString();
log.Info("YERP_002 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_002_OA1_SI&interfaceNamespace=http://skch.com/YERP_002_SALES_INVOICE";
rop.RequestSAP(rop.Url, 10000, postData, "IF_YERP", "Xtxc355860", out statusCode, out resultContent);
log.Info("YERP_002 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;
}
}
}
}