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.

194 lines
10 KiB

3 months ago
3 months ago
2 months ago
3 months ago
2 months ago
3 months ago
2 months ago
3 months ago
2 months ago
3 months ago
2 months ago
3 months ago
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 beginMuoth = Dates.AddMonths(-1).ToString("MM");
  50. string endMuoth = Dates.ToString("MM");
  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. //<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:yerp="http://skch.com/YERP_003_CORP_COMMISSION">
  76. // <soapenv:Header/>
  77. // <soapenv:Body>
  78. // <yerp:YERP_003_OA1_MT>
  79. // <!--1 or more repetitions:-->
  80. // <CORP_CMISN>
  81. // <Created_Year>?</Created_Year>
  82. // <Created_Month>?</Created_Month>
  83. // <SBJ_CD>?</SBJ_CD>
  84. // <SBJ_NM>?</SBJ_NM>
  85. // <YYYY>?</YYYY>
  86. // <MM>?</MM>
  87. // <DD>?</DD>
  88. // <SPTDOC>?</SPTDOC>
  89. // <SMR>?</SMR>
  90. // <ODR_ACC>?</ODR_ACC>
  91. // <DBTO_AMT>?</DBTO_AMT>
  92. // <CRDTO_AMT>?</CRDTO_AMT>
  93. // <DBTO_CRDTO_DVSN>?</DBTO_CRDTO_DVSN>
  94. // <BLNC>?</BLNC>
  95. // </CORP_CMISN>
  96. // </yerp:YERP_003_OA1_MT>
  97. // </soapenv:Body>
  98. //</soapenv:Envelope>
  99. var beginPeriod = Date + beginMuoth; //"202407";//Date + beginMuoth;
  100. var endPeriod = Date + endMuoth;// "202407";//Date + endMuoth;
  101. string sqls = @"
  102. begin transaction
  103. 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
  104. select iyear Created_Year,imonth Created_Month,autoid,cCode SBJ_CD,ccode_name SBJ_NM,iyear YYYY,imonth MM,iday DD,csign_no SPTDOC,cDigest SMR,case when len(cDCode) >= 120 then '' else cDCode end 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,
  105. (Select Sum(-tmpme) from tempdb..zyywsrmxz where autoid<=a.autoid) BLNC from tempdb..zyywsrmxz a
  106. where CHARINDEX('CHEMICALS CO.,LTD', cDigest) > 0
  107. rollback transaction";
  108. sqls = string.Format(sqls, beginPeriod, endPeriod);
  109. log.Info("YERP_003 sql:" + sqls);
  110. DataTable vbsdt = ICSHelper.ExecuteTable(conStr, sqls);
  111. log.Info("sql结果数量" + vbsdt.Rows.Count);
  112. if (vbsdt.Rows.Count > 0)
  113. {
  114. StringBuilder soapRequestData = new StringBuilder();
  115. soapRequestData.Append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:yerp=\"http://skch.com/YERP_003_CORP_COMMISSION\">");
  116. soapRequestData.Append("<soapenv:Header/>");
  117. soapRequestData.Append("<soapenv:Body>");
  118. soapRequestData.Append("<yerp:YERP_003_OA1_MT>");
  119. //循环数据
  120. foreach (DataRow itemRow in vbsdt.Rows)
  121. {
  122. //原循环部分 begin
  123. soapRequestData.Append("<CORP_CMISN>");
  124. soapRequestData.Append(itemRow["Created_Year"] != null ? "<Created_Year>" + itemRow["Created_Year"].ToString() + "</Created_Year>" : "<Created_Year>" + "</Created_Year>");
  125. soapRequestData.Append(itemRow["Created_Month"] != null ? "<Created_Month>" + itemRow["Created_Month"].ToString() + "</Created_Month>" : "<Created_Month>" + "</Created_Month>");
  126. soapRequestData.Append(itemRow["SBJ_CD"] != null ? "<SBJ_CD>" + itemRow["SBJ_CD"].ToString() + "</SBJ_CD>" : "<SBJ_CD>" + "</SBJ_CD>");
  127. soapRequestData.Append(itemRow["SBJ_NM"] != null ? "<SBJ_NM>" + itemRow["SBJ_NM"].ToString() + "</SBJ_NM>" : "<SBJ_NM>" + "</SBJ_NM>");
  128. soapRequestData.Append(itemRow["YYYY"] != null ? "<YYYY>" + itemRow["YYYY"].ToString() + "</YYYY>" : "<YYYY>" + "</YYYY>");
  129. soapRequestData.Append(itemRow["MM"] != null ? "<MM>" + itemRow["MM"].ToString() + "</MM>" : "<MM>" + "</MM>");
  130. soapRequestData.Append(itemRow["DD"] != null ? "<DD>" + itemRow["DD"].ToString() + "</DD>" : "<DD>" + "</DD>");
  131. soapRequestData.Append(itemRow["SPTDOC"] != null ? "<SPTDOC>" + itemRow["SPTDOC"].ToString() + "</SPTDOC>" : "<SPTDOC>" + "</SPTDOC>");
  132. soapRequestData.Append(itemRow["SMR"] != null ? "<SMR>" + itemRow["SMR"].ToString() + "</SMR>" : "<SMR>" + "</SMR>");
  133. soapRequestData.Append(itemRow["ODR_ACC"] != null ? "<ODR_ACC>" + itemRow["ODR_ACC"].ToString() + "</ODR_ACC>" : "<ODR_ACC>" + "</ODR_ACC>");
  134. soapRequestData.Append(itemRow["DBTO_AMT"] != null ? "<DBTO_AMT>" + itemRow["DBTO_AMT"].ToString() + "</DBTO_AMT>" : "<DBTO_AMT>" + "</DBTO_AMT>");
  135. soapRequestData.Append(itemRow["CRDTO_AMT"] != null ? "<CRDTO_AMT>" + itemRow["CRDTO_AMT"].ToString() + "</CRDTO_AMT>" : "<CRDTO_AMT>" + "</CRDTO_AMT>");
  136. soapRequestData.Append(itemRow["DBTO_CRDTO_DVSN"] != null ? "<DBTO_CRDTO_DVSN>" + itemRow["DBTO_CRDTO_DVSN"].ToString() + "</DBTO_CRDTO_DVSN>" : "<DBTO_CRDTO_DVSN>" + "</DBTO_CRDTO_DVSN>");
  137. soapRequestData.Append(itemRow["BLNC"] != null ? "<BLNC>" + itemRow["BLNC"].ToString() + "</BLNC>" : "<BLNC>" + "</BLNC>");
  138. soapRequestData.Append("</CORP_CMISN>");
  139. //原循环部分 end
  140. }
  141. soapRequestData.Append("</yerp:YERP_003_OA1_MT>");
  142. soapRequestData.Append("</soapenv:Body>");
  143. soapRequestData.Append("</soapenv:Envelope>");
  144. string postData = soapRequestData.ToString();
  145. log.Info("YERP_003 xmlRequest:" + postData);
  146. string statusCode;
  147. string resultContent;
  148. ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;
  149. RestOpHelper rop = new RestOpHelper();
  150. rop.Clientp12path = @"C:\Users\Administrator\Desktop\yonyou-cert\wildcard.pfx";
  151. rop.Clientp12PassWord = "Yonyou2024!";
  152. rop.Url = @"https://yerp-proxy-sap-prod.skchemicals.com/XISOAPAdapter/MessageServlet?senderParty=&senderService=YERP_P&receiverParty=&receiverService=&interface=YERP_003_OA1_SI&interfaceNamespace=http://skch.com/YERP_003_CORP_COMMISSION";
  153. rop.RequestSAP(rop.Url, 10000, postData, "IF_YERP", "Kfiw282082", out statusCode, out resultContent);
  154. log.Info("YERP_003 statusCode:" + statusCode + "\r\n" + "resultContent:" + resultContent);
  155. }
  156. }
  157. catch (Exception ex)
  158. {
  159. log.Error(ex.ToString());
  160. }
  161. }
  162. public static Configuration GetConfig()
  163. {
  164. Assembly assembly = Assembly.GetCallingAssembly();
  165. string path = string.Format("{0}.config", assembly.Location);
  166. if (!File.Exists(path))
  167. {
  168. throw new FileNotFoundException(path + "路径下的文件未找到!");
  169. }
  170. try
  171. {
  172. ExeConfigurationFileMap configFile = new ExeConfigurationFileMap();
  173. configFile.ExeConfigFilename = path;
  174. Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFile, ConfigurationUserLevel.None);
  175. return config;
  176. }
  177. catch (Exception)
  178. {
  179. throw;
  180. }
  181. }
  182. }
  183. }