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.

146 lines
7.2 KiB

  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.Threading.Tasks;
  12. namespace ICSSoft.FromERP
  13. {
  14. /// <summary>
  15. /// Account master(交易商主数据)
  16. /// </summary>
  17. public class YERP_011 : IJob
  18. {
  19. private static object key = new object();
  20. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  21. public void Execute(IJobExecutionContext context)
  22. {
  23. try
  24. {
  25. lock (key)
  26. {
  27. log.Info("开始……………………………………………………………………");
  28. Execute();
  29. log.Info("结束……………………………………………………………………");
  30. }
  31. }
  32. catch (Exception ex)
  33. {
  34. log.Error(ex.ToString());
  35. }
  36. }
  37. public async void Execute()
  38. {
  39. try
  40. {
  41. Configuration config = GetConfig();
  42. var Dates = DateTime.Now;
  43. string conStr = ICSHelper.GetConnectString();
  44. //<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:yerp="http://skch.com/YERP_011_IF_ACNT_INFO">
  45. // <soapenv:Header/>
  46. // <soapenv:Body>
  47. // <yerp:YERP_011_OA1_MT>
  48. // <!--Zero or more repetitions:-->
  49. // <IF_ACNT_MST>
  50. // <IF_STD_DATE>2</IF_STD_DATE>
  51. // <ACNT_CD>2</ACNT_CD>
  52. // <ACNT_NM>2</ACNT_NM>
  53. // <!--Optional:-->
  54. // <MODIFY_DTTM>2</MODIFY_DTTM>
  55. // <GEN_ROW_CNT>2</GEN_ROW_CNT>
  56. // </IF_ACNT_MST>
  57. // </yerp:YERP_011_OA1_MT>
  58. // </soapenv:Body>
  59. //</soapenv:Envelope>
  60. // 过滤时间为上个月
  61. var beginPeriod = "2000-06-01";// Dates.AddMonths(-1).AddDays(-Dates.Day + 1).ToString("yyyy-MM-dd");//"2023-06-01";
  62. var endPeriod = "2090-06-01";// Dates.AddDays(-Dates.Day + 1).ToString("yyyy-MM-dd");//"2023-07-01";
  63. string sqls = @"select convert(nvarchar(10),getdate(),112) IF_STD_DATE,
  64. cCusCode ACNT_CD,
  65. cCusName ACNT_NM,
  66. (case when dEndDate is null then '否' else '是' end) DEL_YN,
  67. dCusCreateDatetime CREATE_DTTM,
  68. cCreatePerson CREATE_BY,
  69. dModifyDate MODIFY_DTTM,
  70. cModifyPerson MODIFY_BY,
  71. COUNT(*) OVER (PARTITION BY getdate()) GEN_ROW_CNT
  72. from dbo.Customer a WHERE 1 = 1 and dCusCreateDatetime >= '{0}' and dCusCreateDatetime < '{1}'";
  73. sqls = string.Format(sqls, beginPeriod, endPeriod);
  74. log.Info("YERP_011 sql:"+sqls);
  75. DataTable vbsdt = ICSHelper.ExecuteTable(conStr, sqls);
  76. log.Info("YERP_011 sql结果数量" + vbsdt.Rows.Count);
  77. if (vbsdt.Rows.Count > 0)
  78. {
  79. StringBuilder soapRequestData = new StringBuilder();
  80. soapRequestData.Append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:yerp=\"http://skch.com/YERP_011_IF_ACNT_INFO\">");
  81. soapRequestData.Append("<soapenv:Header/>");
  82. soapRequestData.Append("<soapenv:Body>");
  83. soapRequestData.Append("<yerp:YERP_011_OA1_MT>");
  84. //循环数据
  85. foreach (DataRow itemRow in vbsdt.Rows)
  86. {
  87. soapRequestData.Append("<!--Zero or more repetitions: -->");
  88. soapRequestData.Append("<IF_ACNT_MST>");
  89. soapRequestData.Append(itemRow["IF_STD_DATE"] != null ? "<IF_STD_DATE>" + itemRow["IF_STD_DATE"].ToString() + "</IF_STD_DATE>" : "<IF_STD_DATE>" + "</IF_STD_DATE>");
  90. soapRequestData.Append(itemRow["ACNT_CD"] != null ? "<ACNT_CD>" + itemRow["ACNT_CD"].ToString() + "</ACNT_CD>" : "<ACNT_CD>" + "</ACNT_CD>");
  91. soapRequestData.Append(itemRow["ACNT_NM"] != null ? "<ACNT_NM>" + itemRow["ACNT_NM"].ToString() + "</ACNT_NM>" : "<ACNT_NM>" + "</ACNT_NM>");
  92. soapRequestData.Append("<!--Optional:-->");
  93. soapRequestData.Append(itemRow["MODIFY_DTTM"] != null ? "<MODIFY_DTTM>" + itemRow["MODIFY_DTTM"].ToString() + "</MODIFY_DTTM>" : "<MODIFY_DTTM>" + "</MODIFY_DTTM>");
  94. soapRequestData.Append("<!--Optional:-->");
  95. soapRequestData.Append(itemRow["GEN_ROW_CNT"] != null ? "<GEN_ROW_CNT>" + itemRow["GEN_ROW_CNT"].ToString() + "</GEN_ROW_CNT>" : "<GEN_ROW_CNT>" + "</GEN_ROW_CNT>");
  96. soapRequestData.Append("</IF_ACNT_MST>");
  97. }
  98. soapRequestData.Append("</yerp:YERP_011_OA1_MT>");
  99. soapRequestData.Append("</soapenv:Body>");
  100. soapRequestData.Append("</soapenv:Envelope>");
  101. string postData = soapRequestData.ToString();
  102. log.Info("YERP_011 xmlRequest:" + postData);
  103. string statusCode;
  104. string resultContent;
  105. ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;
  106. RestOpHelper rop = new RestOpHelper();
  107. rop.Clientp12path = @"C:\Users\Administrator\Desktop\yonyou-cert\wildcard.pfx";
  108. rop.Clientp12PassWord = "Yonyou2024!";
  109. rop.Url = @"https://yerp-proxy-sap-dev.skchemicals.com/XISOAPAdapter/MessageServlet?senderParty=&senderService=YERP_D&receiverParty=&receiverService=&interface=YERP_011_OA1_SI&interfaceNamespace=http://skch.com/YERP_011_IF_ACNT_INFO";
  110. rop.RequestSAP(rop.Url, 10000, postData, "IF_YERP", "Xtxc355860", out statusCode, out resultContent);
  111. log.Info("YERP_011 statusCode:" + statusCode + "\r\n" + "resultContent:" + resultContent);
  112. }
  113. }
  114. catch (Exception ex)
  115. {
  116. log.Error(ex.ToString());
  117. }
  118. }
  119. public static Configuration GetConfig()
  120. {
  121. Assembly assembly = Assembly.GetCallingAssembly();
  122. string path = string.Format("{0}.config", assembly.Location);
  123. if (!File.Exists(path))
  124. {
  125. throw new FileNotFoundException(path + "路径下的文件未找到!");
  126. }
  127. try
  128. {
  129. ExeConfigurationFileMap configFile = new ExeConfigurationFileMap();
  130. configFile.ExeConfigFilename = path;
  131. Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFile, ConfigurationUserLevel.None);
  132. return config;
  133. }
  134. catch (Exception)
  135. {
  136. throw;
  137. }
  138. }
  139. }
  140. }