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.
261 lines
14 KiB
261 lines
14 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.Threading.Tasks;
|
|
|
|
namespace ICSSoft.FromERP
|
|
{
|
|
/// <summary>
|
|
/// 销售费用明细账
|
|
/// </summary>
|
|
public class YERP_004 : 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 beginMuoth = Dates.AddMonths(-1).ToString("MM");
|
|
string endMuoth = Dates.ToString("MM");
|
|
//<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:yerp="http://skch.com/YERP_004_SALES_COST_STMT">
|
|
// <soapenv:Header/>
|
|
// <soapenv:Body>
|
|
// <yerp:YERP_004_OA1_MT>
|
|
// <!--1 or more repetitions:-->
|
|
// <SL_CST_SPTDOC>
|
|
// <YYYY>?</YYYY>
|
|
// <MM>?</MM>
|
|
// <DD>?</DD>
|
|
// <SPTDOC>?</SPTDOC>
|
|
// <SMR>?</SMR>
|
|
// <!--Optional:-->
|
|
// <DBTO>?</DBTO>
|
|
// <!--Optional:-->
|
|
// <CRDTO>?</CRDTO>
|
|
// <INVT>?</INVT>
|
|
// <BLNC>?</BLNC>
|
|
// <!--Optional:-->
|
|
// <WH_CST>?</WH_CST>
|
|
// <!--Optional:-->
|
|
// <TRNSF_CST>?</TRNSF_CST>
|
|
// <!--Optional:-->
|
|
// <XBT_CST>?</XBT_CST>
|
|
// <!--Optional:-->
|
|
// <NLD_CST>?</NLD_CST>
|
|
// <!--Optional:-->
|
|
// <SMPL_CST>?</SMPL_CST>
|
|
// <!--Optional:-->
|
|
// <TRNSF_AGNC_CST>?</TRNSF_AGNC_CST>
|
|
// <!--Optional:-->
|
|
// <ADTV>?</ADTV>
|
|
// <!--Optional:-->
|
|
// <NCLSN_CST>?</NCLSN_CST>
|
|
// <!--Optional:-->
|
|
// <SVC_CST>?</SVC_CST>
|
|
// </SL_CST_SPTDOC>
|
|
// </yerp:YERP_004_OA1_MT>
|
|
// </soapenv:Body>
|
|
// </soapenv:Envelope>
|
|
var beginPeriod = Date + beginMuoth;
|
|
var endPeriod = Date + endMuoth;
|
|
string sqls = @"
|
|
begin transaction
|
|
|
|
exec GL_Ledger @tblname=N'zyywsrmxz',@KmCode=N'6601',@beginPeriod='{0}',@endPeriod='{1}',@bVouch=0,@bequal=1,@sum=0,@bMJ=1,@swhere=N'',@sAuth=N'',@ReportID=N'GL13',@ReportType=0,@iUnite=0
|
|
|
|
select autoid,iyear YYYY,imonth MM,iday DD,csign_no SPTDOC,cDigest SMR,cDCode ODR_ACC,md DBTO_AMT,mc CRDTO_AMT,tmpme tmpme
|
|
into #test from tempdb..zyywsrmxz a
|
|
|
|
select YYYY,SPTDOC,MM,DD,sum(DBTO_AMT) DBTO_AMT,sum(CRDTO_AMT) CRDTO_AMT,sum(isnull(tmpme,0)) tmpme
|
|
into #test2
|
|
from #test a
|
|
where SPTDOC is not null and DD IS NOT NULL
|
|
group by SPTDOC,YYYY,MM,DD
|
|
order by SPTDOC
|
|
|
|
update a set DBTO_AMT=b.DBTO_AMT,a.CRDTO_AMT=b.CRDTO_AMT,a.tmpme=b.tmpme from #test a
|
|
left join #test2 b on a.SPTDOC=b.SPTDOC and a.MM=b.MM and a.DD=b.DD
|
|
where a.sptdoc is not null
|
|
|
|
select autoid,sptdoc,YYYY,MM,DD into #test3 from #test where sptdoc is not null
|
|
|
|
select s.* into #test4 from (select *,ROW_NUMBER() over (partition by sptdoc+CAST(MM AS VARCHAR(255))+CAST(DD AS VARCHAR(255)) order by autoid) as group_idx from #test3)s where s.group_idx>1
|
|
|
|
delete a from #test a
|
|
left join #test4 b on a.autoid=b.autoid
|
|
where b.autoid is not null
|
|
|
|
select *,(case when (Select Sum(-tmpme) from #test where autoid<=a.autoid) =0 then '平' else (case when (Select Sum(-tmpme) from #test where autoid<=a.autoid) >0 then '贷' else '借' end) end) INVT,
|
|
(case when (Select Sum(-tmpme) from #test where autoid<=a.autoid)<0 then -(Select Sum(-tmpme) from #test where autoid<=a.autoid) else (Select Sum(-tmpme) from #test where autoid<=a.autoid) end) BLNC into #test5 from #test a
|
|
|
|
select cCode SBJ_CD,ccode_name SBJ_NM,imonth,iday,csign_no SPTDOC,sum(md) DBTO_AMT
|
|
into #test6
|
|
from tempdb..zyywsrmxz a
|
|
where csign_no is not null
|
|
group by ccode_name,csign_no,cCode,imonth,iday
|
|
order by csign_no,imonth,iday
|
|
|
|
select DISTINCT sptdoc,imonth,iday into #test7 from #test6
|
|
select *,ROW_NUMBER() over (order by sptdoc,imonth,iday) rownumber into #test8 from #test7
|
|
|
|
|
|
declare @k int
|
|
set @k=1
|
|
while @k<=(select COUNT(*) from #test7)
|
|
begin
|
|
declare @i int
|
|
set @i=0
|
|
while @i<1
|
|
begin
|
|
|
|
insert into #test6 (SBJ_CD,SBJ_NM,imonth,iday,SPTDOC,DBTO_AMT)
|
|
select a.ccode,a.ccode_name,(select imonth from #test8 where rownumber=@k),(select iday from #test8 where rownumber=@k),(select SPTDOC from #test8 where rownumber=@k),0
|
|
from code a left join #test6 b on b.SPTDOC=(select SPTDOC from #test8 where rownumber=@k) and imonth=(select imonth from #test8 where rownumber=@k) and iday=(select iday from #test8 where rownumber=@k) and SBJ_NM=ccode_name
|
|
where a.iYear=2024 and ( bclose=0 and ( ccode like N'6601%' or ccode_name like N'6601%' or ccode_engl like N'6601%' or chelp like N'6601%' )) and ccode <>'6601' and b.SPTDOC is null
|
|
set @i=@i +1
|
|
end
|
|
|
|
|
|
set @k=@k +1
|
|
end
|
|
|
|
|
|
SELECT
|
|
SPTDOC,imonth,iday,
|
|
SUM(CASE WHEN SBJ_CD = '660101' THEN DBTO_AMT ELSE 0 END) WH_CST,
|
|
SUM(CASE WHEN SBJ_CD = '660102' THEN DBTO_AMT ELSE 0 END) TRNSF_CST,
|
|
SUM(CASE WHEN SBJ_CD = '660103' THEN DBTO_AMT ELSE 0 END) XBT_CST,
|
|
SUM(CASE WHEN SBJ_CD = '660104' THEN DBTO_AMT ELSE 0 END) NLD_CST,
|
|
SUM(CASE WHEN SBJ_CD = '660105' THEN DBTO_AMT ELSE 0 END) SMPL_CST,
|
|
SUM(CASE WHEN SBJ_CD = '660106' THEN DBTO_AMT ELSE 0 END) TRNSF_AGNC_CST,
|
|
SUM(CASE WHEN SBJ_CD = '660107' THEN DBTO_AMT ELSE 0 END) ADTV,
|
|
SUM(CASE WHEN SBJ_CD = '660108' THEN DBTO_AMT ELSE 0 END) NCLSN_CST,
|
|
SUM(CASE WHEN SBJ_CD = '660109' THEN DBTO_AMT ELSE 0 END) SVC_CST
|
|
into #test9
|
|
FROM
|
|
#test6
|
|
GROUP BY
|
|
SPTDOC,imonth,iday
|
|
|
|
|
|
select YYYY,MM,DD,A.SPTDOC,SMR,DBTO_AMT DBTO,CRDTO_AMT CRDTO,INVT,BLNC,WH_CST,TRNSF_CST,XBT_CST,NLD_CST,SMPL_CST,TRNSF_AGNC_CST,ADTV,NCLSN_CST,SVC_CST from #test5 a left join #test9 b on a.SPTDOC=b.SPTDOC and a.MM=b.imonth and a.DD=b.iday
|
|
|
|
rollback transaction
|
|
";
|
|
sqls = string.Format(sqls, beginPeriod, endPeriod);
|
|
log.Info("YERP_004 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_004_SALES_COST_STMT\">");
|
|
soapRequestData.Append("<soapenv:Header/>");
|
|
soapRequestData.Append("<soapenv:Body>");
|
|
soapRequestData.Append("<yerp:YERP_004_OA1_MT>");
|
|
//循环数据
|
|
foreach (DataRow itemRow in vbsdt.Rows)
|
|
{
|
|
//原循环部分 begin
|
|
soapRequestData.Append("<SL_CST_SPTDOC>");
|
|
soapRequestData.Append(itemRow["YYYY"] != null ? "<YYYY>" + itemRow["YYYY"].ToString() + "</YYYY>" : "<YYYY>" + "</YYYY>");
|
|
soapRequestData.Append(itemRow["MM"] != null ? "<MM>" + itemRow["MM"].ToString() + "</MM>" : "<MM>" + "</MM>");
|
|
soapRequestData.Append(itemRow["DD"] != null ? "<DD>" + itemRow["DD"].ToString() + "</DD>" : "<DD>" + "</DD>");
|
|
soapRequestData.Append(itemRow["SPTDOC"] != null ? "<SPTDOC>" + itemRow["SPTDOC"].ToString() + "</SPTDOC>" : "<SPTDOC>" + "</SPTDOC>");
|
|
soapRequestData.Append(itemRow["SMR"] != null ? "<SMR>" + itemRow["SMR"].ToString() + "</SMR>" : "<SMR>" + "</SMR>");
|
|
soapRequestData.Append(itemRow["DBTO"] != null ? "<DBTO>" + itemRow["DBTO"].ToString() + "</DBTO>" : "<DBTO>" + "</DBTO>");
|
|
soapRequestData.Append(itemRow["CRDTO"] != null ? "<CRDTO>" + itemRow["CRDTO"].ToString() + "</CRDTO>" : "<CRDTO>" + "</CRDTO>");
|
|
soapRequestData.Append(itemRow["INVT"] != null ? "<INVT>" + itemRow["INVT"].ToString() + "</INVT>" : "<INVT>" + "</INVT>");
|
|
soapRequestData.Append(itemRow["BLNC"] != null ? "<BLNC>" + itemRow["BLNC"].ToString() + "</BLNC>" : "<BLNC>" + "</BLNC>");
|
|
soapRequestData.Append(itemRow["WH_CST"] != null ? "<WH_CST>" + itemRow["WH_CST"].ToString() + "</WH_CST>" : "<WH_CST>" + "</WH_CST>");
|
|
soapRequestData.Append(itemRow["TRNSF_CST"] != null ? "<TRNSF_CST>" + itemRow["TRNSF_CST"].ToString() + "</TRNSF_CST>" : "<TRNSF_CST>" + "</TRNSF_CST>");
|
|
soapRequestData.Append(itemRow["XBT_CST"] != null ? "<XBT_CST>" + itemRow["XBT_CST"].ToString() + "</XBT_CST>" : "<XBT_CST>" + "</XBT_CST>");
|
|
soapRequestData.Append(itemRow["NLD_CST"] != null ? "<NLD_CST>" + itemRow["NLD_CST"].ToString() + "</NLD_CST>" : "<NLD_CST>" + "</NLD_CST>");
|
|
//soapRequestData.Append(itemRow["SMPL_CST"] != null ? "<SMPL_CST>" + itemRow["SMPL_CST"].ToString() + "</SMPL_CST>" : "<SMPL_CST>" + "</SMPL_CST>");
|
|
soapRequestData.Append(itemRow["TRNSF_AGNC_CST"] != null ? "<TRNSF_AGNC_CST>" + itemRow["TRNSF_AGNC_CST"].ToString() + "</TRNSF_AGNC_CST>" : "<TRNSF_AGNC_CST>" + "</TRNSF_AGNC_CST>");
|
|
soapRequestData.Append(itemRow["ADTV"] != null ? "<ADTV>" + itemRow["ADTV"].ToString() + "</ADTV>" : "<ADTV>" + "</ADTV>");
|
|
soapRequestData.Append(itemRow["NCLSN_CST"] != null ? "<NCLSN_CST>" + itemRow["NCLSN_CST"].ToString() + "</NCLSN_CST>" : "<NCLSN_CST>" + "</NCLSN_CST>");
|
|
soapRequestData.Append(itemRow["SVC_CST"] != null ? "<SVC_CST>" + itemRow["SVC_CST"].ToString() + "</SVC_CST>" : "<SVC_CST>" + "</SVC_CST>");
|
|
soapRequestData.Append("</SL_CST_SPTDOC>");
|
|
//原循环部分 end
|
|
}
|
|
soapRequestData.Append("</yerp:YERP_004_OA1_MT>");
|
|
soapRequestData.Append("</soapenv:Body>");
|
|
soapRequestData.Append("</soapenv:Envelope>");
|
|
string postData = soapRequestData.ToString();
|
|
log.Info("YERP_004 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_004_OA1_SI&interfaceNamespace=http://skch.com/YERP_004_SALES_COST_STMT";
|
|
rop.RequestSAP(rop.Url, 10000, postData, "IF_YERP", "Xtxc355860", out statusCode, out resultContent);
|
|
|
|
log.Info("YERP_004 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;
|
|
}
|
|
}
|
|
}
|
|
}
|