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.

166 lines
8.8 KiB

3 months ago
  1. using Quartz;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Configuration;
  5. using System.Data;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Net;
  9. using System.Reflection;
  10. using System.Text;
  11. using System.Text.RegularExpressions;
  12. using System.Threading.Tasks;
  13. namespace ICSSoft.FromERP
  14. {
  15. /// <summary>
  16. /// 主营业务收入明细账
  17. /// </summary>
  18. public class YERP_003 : IJob
  19. {
  20. private static object key = new object();
  21. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  22. public void Execute(IJobExecutionContext context)
  23. {
  24. try
  25. {
  26. lock (key)
  27. {
  28. log.Info("开始……………………………………………………………………");
  29. Execute();
  30. log.Info("结束……………………………………………………………………");
  31. }
  32. }
  33. catch (Exception ex)
  34. {
  35. log.Error(ex.ToString());
  36. }
  37. }
  38. public async void Execute()
  39. {
  40. try
  41. {
  42. Configuration config = GetConfig();
  43. //string url = config.ConnectionStrings.ConnectionStrings["APIAddStdWorkHour"].ConnectionString.ToString();
  44. var Dates = DateTime.Now;
  45. string conStr = ICSHelper.GetConnectString();
  46. // 202404
  47. // 过滤时间为上个月
  48. string Date = Dates.ToString("yyyy");
  49. string Muoth = Dates.AddMonths(-1).ToString("MM");
  50. string Day = Dates.ToString("dd");
  51. //<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:yerp="http://skch.com/YERP_003_CORP_COMMISSION">
  52. // <soapenv:Header/>
  53. // <soapenv:Body>
  54. // <yerp:YERP_003_OA1_MT>
  55. // <!--1 or more repetitions:-->
  56. // <CORP_CMISN>
  57. // <SBJ_CD>?</SBJ_CD>
  58. // <SBJ_NM>?</SBJ_NM>
  59. // <YYYY>?</YYYY>
  60. // <MM>?</MM>
  61. // <DD>?</DD>
  62. // <SPTDOC>?</SPTDOC>
  63. // <SMR>?</SMR>
  64. // <ODR_ACC>?</ODR_ACC>
  65. // <!--Optional:-->
  66. // <DBTO_AMT>?</DBTO_AMT>
  67. // <!--Optional:-->
  68. // <CRDTO_AMT>?</CRDTO_AMT>
  69. // <DBTO_CRDTO_DVSN>?</DBTO_CRDTO_DVSN>
  70. // <BLNC>?</BLNC>
  71. // </CORP_CMISN>
  72. // </yerp:YERP_003_OA1_MT>
  73. // </soapenv:Body>
  74. //</soapenv:Envelope>
  75. var beginPeriod = "202301";//Date + Muoth;
  76. var endPeriod = "202302";//Date + Muoth;
  77. string sqls = @"
  78. begin transaction
  79. exec GL_Ledger @tblname=N'zyywsrmxz',@KmCode=N'6001',@beginPeriod={0},@endPeriod={1},@bVouch=0,@bequal=1,@sum=0,@bMJ=1,@swhere=N'',@sAuth=N'',@ReportID=N'GL13',@ReportType=0,@iUnite=0
  80. select autoid,cCode SBJ_CD,ccode_name SBJ_NM,iyear YYYY,imonth MM,iday DD,csign_no SPTDOC,cDigest SMR,cDCode ODR_ACC,md DBTO_AMT,mc CRDTO_AMT,(case when ibook is null then '平' else (case when ibook ='1' then '贷' else '借' end) end) DBTO_CRDTO_DVSN,tmpme,
  81. (Select Sum(-tmpme) from tempdb..zyywsrmxz where autoid<=a.autoid) BLNC from tempdb..zyywsrmxz a
  82. rollback transaction";
  83. sqls = string.Format(sqls, beginPeriod, endPeriod);
  84. log.Info("YERP_003 sql:" + sqls);
  85. DataTable vbsdt = ICSHelper.ExecuteTable(conStr, sqls);
  86. log.Info("sql结果数量" + vbsdt.Rows.Count);
  87. if (vbsdt.Rows.Count > 0)
  88. {
  89. StringBuilder soapRequestData = new StringBuilder();
  90. soapRequestData.Append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:yerp=\"http://skch.com/YERP_003_CORP_COMMISSION\">");
  91. soapRequestData.Append("<soapenv:Header/>");
  92. soapRequestData.Append("<soapenv:Body>");
  93. soapRequestData.Append("<yerp:YERP_003_OA1_MT>");
  94. //循环数据
  95. foreach (DataRow itemRow in vbsdt.Rows)
  96. {
  97. //原循环部分 begin
  98. soapRequestData.Append("<CORP_CMISN>");
  99. soapRequestData.Append(itemRow["SBJ_CD"] != null ? "<SBJ_CD>" + itemRow["SBJ_CD"].ToString() + "</SBJ_CD>" : "<SBJ_CD>" + "</SBJ_CD>");
  100. soapRequestData.Append(itemRow["SBJ_NM"] != null ? "<SBJ_NM>" + itemRow["SBJ_NM"].ToString() + "</SBJ_NM>" : "<SBJ_NM>" + "</SBJ_NM>");
  101. soapRequestData.Append(itemRow["YYYY"] != null ? "<YYYY>" + itemRow["YYYY"].ToString() + "</YYYY>" : "<YYYY>" + "</YYYY>");
  102. soapRequestData.Append(itemRow["MM"] != null ? "<MM>" + itemRow["MM"].ToString() + "</MM>" : "<MM>" + "</MM>");
  103. soapRequestData.Append(itemRow["DD"] != null ? "<DD>" + itemRow["DD"].ToString() + "</DD>" : "<DD>" + "</DD>");
  104. soapRequestData.Append(itemRow["SPTDOC"] != null ? "<SPTDOC>" + itemRow["SPTDOC"].ToString() + "</SPTDOC>" : "<SPTDOC>" + "</SPTDOC>");
  105. soapRequestData.Append(itemRow["SMR"] != null ? "<SMR>" + itemRow["SMR"].ToString() + "</SMR>" : "<SMR>" + "</SMR>");
  106. soapRequestData.Append(itemRow["ODR_ACC"] != null ? "<ODR_ACC>" + itemRow["ODR_ACC"].ToString() + "</ODR_ACC>" : "<ODR_ACC>" + "</ODR_ACC>");
  107. soapRequestData.Append(itemRow["DBTO_AMT"] != null ? "<DBTO_AMT>" + itemRow["DBTO_AMT"].ToString() + "</DBTO_AMT>" : "<DBTO_AMT>" + "</DBTO_AMT>");
  108. soapRequestData.Append(itemRow["CRDTO_AMT"] != null ? "<CRDTO_AMT>" + itemRow["CRDTO_AMT"].ToString() + "</CRDTO_AMT>" : "<CRDTO_AMT>" + "</CRDTO_AMT>");
  109. soapRequestData.Append(itemRow["DBTO_CRDTO_DVSN"] != null ? "<DBTO_CRDTO_DVSN>" + itemRow["DBTO_CRDTO_DVSN"].ToString() + "</DBTO_CRDTO_DVSN>" : "<DBTO_CRDTO_DVSN>" + "</DBTO_CRDTO_DVSN>");
  110. soapRequestData.Append(itemRow["BLNC"] != null ? "<BLNC>" + itemRow["BLNC"].ToString() + "</BLNC>" : "<BLNC>" + "</BLNC>");
  111. soapRequestData.Append("</CORP_CMISN>");
  112. //原循环部分 end
  113. }
  114. soapRequestData.Append("</yerp:YERP_003_OA1_MT>");
  115. soapRequestData.Append("</soapenv:Body>");
  116. soapRequestData.Append("</soapenv:Envelope>");
  117. string postData = soapRequestData.ToString();
  118. log.Info("YERP_003 xmlRequest:" + postData);
  119. string statusCode;
  120. string resultContent;
  121. ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;
  122. RestOpHelper rop = new RestOpHelper();
  123. rop.Clientp12path = @"C:\Users\Administrator\Desktop\yonyou-cert\wildcard.pfx";
  124. rop.Clientp12PassWord = "Yonyou2024!";
  125. rop.Url = @"https://yerp-proxy-sap-dev.skchemicals.com/XISOAPAdapter/MessageServlet?senderParty=&senderService=YERP_D&receiverParty=&receiverService=&interface=YERP_003_OA1_SI&interfaceNamespace=http://skch.com/YERP_003_CORP_COMMISSION";
  126. rop.RequestSAP(rop.Url, 10000, postData, "IF_YERP", "Xtxc355860", out statusCode, out resultContent);
  127. log.Info("YERP_003 statusCode:" + statusCode + "\r\n" + "resultContent:" + resultContent);
  128. }
  129. }
  130. catch (Exception ex)
  131. {
  132. log.Error(ex.ToString());
  133. }
  134. }
  135. public static Configuration GetConfig()
  136. {
  137. Assembly assembly = Assembly.GetCallingAssembly();
  138. string path = string.Format("{0}.config", assembly.Location);
  139. if (!File.Exists(path))
  140. {
  141. throw new FileNotFoundException(path + "路径下的文件未找到!");
  142. }
  143. try
  144. {
  145. ExeConfigurationFileMap configFile = new ExeConfigurationFileMap();
  146. configFile.ExeConfigFilename = path;
  147. Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFile, ConfigurationUserLevel.None);
  148. return config;
  149. }
  150. catch (Exception)
  151. {
  152. throw;
  153. }
  154. }
  155. }
  156. }