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.

178 lines
10 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. /// Sales performance(销售业绩)
  17. /// </summary>
  18. public class YERP_012 : 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. var Dates = DateTime.Now;
  44. string conStr = ICSHelper.GetConnectString();
  45. //<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:yerp="http://skch.com/YERP_012_IF_SALES_ACT">
  46. // <soapenv:Header/>
  47. // <soapenv:Body>
  48. // <yerp:YERP_012_OA1_MT>
  49. // <!--Zero or more repetitions:-->
  50. // <IF_ACT_SALES>
  51. // <IF_STD_DATE>?</IF_STD_DATE>
  52. // <INVOICE_DATE>?</INVOICE_DATE>
  53. // <ITEM_CD>2</ITEM_CD>
  54. // <ITEM_NM>3</ITEM_NM>
  55. // <SKU_PAYMT_QTY>3</SKU_PAYMT_QTY>
  56. // <SKU_PAYMT_QTY_UOM>4</SKU_PAYMT_QTY_UOM>
  57. // <PAYMT_PRICE>5</PAYMT_PRICE>
  58. // <SALES_SITE_CD>5</SALES_SITE_CD>
  59. // <SALES_SITE_NM>5</SALES_SITE_NM>
  60. // <!--Optional:-->
  61. // <CREATE_BY>?</CREATE_BY>
  62. // <GEN_ROW_CNT>?</GEN_ROW_CNT>
  63. // </IF_ACT_SALES>
  64. // </yerp:YERP_012_OA1_MT>
  65. // </soapenv:Body>
  66. //</soapenv:Envelope>
  67. // 过滤时间为上个月
  68. var beginPeriod = "2023-06-01";// Dates.AddMonths(-1).AddDays(-Dates.Day + 1).ToString("yyyy-MM-dd");//"2023-06-01";
  69. var endPeriod = "2023-07-01";// Dates.AddDays(-Dates.Day + 1).ToString("yyyy-MM-dd");//"2023-07-01";
  70. string sqls = @"select
  71. convert(nvarchar(10),getdate(),112) IF_STD_DATE,
  72. convert(nvarchar(10),a.dDate,111) INVOICE_DATE,
  73. dDate ACNTNG_DATE,
  74. b.cInvCode ITEM_CD,
  75. c.cInvName ITEM_NM,
  76. CAST(iQuantity AS INT) SKU_PAYMT_QTY,
  77. d.cComUnitName SKU_PAYMT_QTY_UOM,
  78. a.cCusCode SALES_SITE_CD,
  79. e.cCusName SALES_SITE_NM,
  80. dcreatesystime CREATE_DTTM,
  81. b.iNatSum PAYMT_PRICE,
  82. cMaker CREATE_BY,
  83. dmodifysystime MODIFY_DTTM,
  84. cmodifier MODIFY_BY,
  85. COUNT(*) OVER (PARTITION BY getdate()) GEN_ROW_CNT
  86. from dbo.SO_SOMain a left join dbo.SO_SODetails b on a.ID=b.ID
  87. left join dbo.Inventory c on b.cInvCode=c.cInvCode
  88. left join dbo.ComputationUnit d on c.cComUnitCode=d.cComunitCode
  89. left join dbo.Customer e on a.cCusCode=e.cCusCode
  90. WHERE 1 = 1 and dcreatesystime > '{0}' and dcreatesystime < '{1}'";//
  91. sqls = string.Format(sqls, beginPeriod, endPeriod);
  92. log.Info("YERP_012 sql:" + sqls);
  93. DataTable vbsdt = ICSHelper.ExecuteTable(conStr, sqls);
  94. log.Info("YERP_012 sql结果数量" + vbsdt.Rows.Count);
  95. if (vbsdt.Rows.Count > 0)
  96. {
  97. StringBuilder soapRequestData = new StringBuilder();
  98. soapRequestData.Append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:yerp=\"http://skch.com/YERP_012_IF_SALES_ACT\">");
  99. soapRequestData.Append("<soapenv:Header/>");
  100. soapRequestData.Append("<soapenv:Body>");
  101. soapRequestData.Append("<yerp:YERP_012_OA1_MT>");
  102. //循环数据 PAYMT_PRICE INVOICE_DATE GEN_ROW_CNT
  103. foreach (DataRow itemRow in vbsdt.Rows)
  104. {
  105. soapRequestData.Append("<!--Zero or more repetitions: -->");
  106. soapRequestData.Append("<IF_ACT_SALES>");
  107. soapRequestData.Append(itemRow["IF_STD_DATE"] != null ? "<IF_STD_DATE>" + itemRow["IF_STD_DATE"].ToString() + "</IF_STD_DATE>" : "<IF_STD_DATE>" + "</IF_STD_DATE>");
  108. soapRequestData.Append(itemRow["INVOICE_DATE"] != null ? "<INVOICE_DATE>" + itemRow["INVOICE_DATE"].ToString() + "</INVOICE_DATE>" : "<INVOICE_DATE>" + "</INVOICE_DATE>");
  109. soapRequestData.Append(itemRow["ITEM_CD"] != null ? "<ITEM_CD>" + itemRow["ITEM_CD"].ToString() + "</ITEM_CD>" : "<ITEM_CD>" + "</ITEM_CD>");
  110. soapRequestData.Append(itemRow["ITEM_NM"] != null ? "<ITEM_NM>" + itemRow["ITEM_NM"].ToString() + "</ITEM_NM>" : "<ITEM_NM>" + "</ITEM_NM>");
  111. soapRequestData.Append("<!--Optional:-->");
  112. soapRequestData.Append(itemRow["SKU_PAYMT_QTY"] != null ? "<SKU_PAYMT_QTY>" + itemRow["SKU_PAYMT_QTY"].ToString() + "</SKU_PAYMT_QTY>" : "<SKU_PAYMT_QTY>" + "</SKU_PAYMT_QTY>");
  113. soapRequestData.Append("<!--Optional:-->");
  114. soapRequestData.Append(itemRow["SKU_PAYMT_QTY_UOM"] != null ? "<SKU_PAYMT_QTY_UOM>" + itemRow["SKU_PAYMT_QTY_UOM"].ToString() + "</SKU_PAYMT_QTY_UOM>" : "<SKU_PAYMT_QTY_UOM>" + "</SKU_PAYMT_QTY_UOM>");
  115. soapRequestData.Append("<!--Optional:-->");
  116. soapRequestData.Append(itemRow["SALES_SITE_CD"] != null ? "<SALES_SITE_CD>" + itemRow["SALES_SITE_CD"].ToString() + "</SALES_SITE_CD>" : "<SALES_SITE_CD>" + "</SALES_SITE_CD>");
  117. soapRequestData.Append("<!--Optional:-->");
  118. soapRequestData.Append(itemRow["SALES_SITE_NM"] != null ? "<SALES_SITE_NM>" + itemRow["SALES_SITE_NM"].ToString() + "</SALES_SITE_NM>" : "<SALES_SITE_NM>" + "</SALES_SITE_NM>");
  119. soapRequestData.Append("<!--Optional:-->");
  120. soapRequestData.Append(itemRow["PAYMT_PRICE"] != null ? "<PAYMT_PRICE>" + itemRow["PAYMT_PRICE"].ToString() + "</PAYMT_PRICE>" : "<PAYMT_PRICE>" + "</PAYMT_PRICE>");
  121. soapRequestData.Append("<!--Optional:-->");
  122. soapRequestData.Append(itemRow["CREATE_BY"] != null ? "<CREATE_BY>" + itemRow["CREATE_BY"].ToString() + "</CREATE_BY>" : "<CREATE_BY>" + "</CREATE_BY>");
  123. soapRequestData.Append("<!--Optional:-->");
  124. soapRequestData.Append(itemRow["GEN_ROW_CNT"] != null ? "<GEN_ROW_CNT>" + itemRow["GEN_ROW_CNT"].ToString() + "</GEN_ROW_CNT>" : "<GEN_ROW_CNT>" + "</GEN_ROW_CNT>");
  125. soapRequestData.Append("</IF_ACT_SALES>");
  126. }
  127. soapRequestData.Append("</yerp:YERP_012_OA1_MT>");
  128. soapRequestData.Append("</soapenv:Body>");
  129. soapRequestData.Append("</soapenv:Envelope>");
  130. string postData = soapRequestData.ToString();
  131. log.Info("YERP_012 xmlRequest:" + postData);
  132. string statusCode;
  133. string resultContent;
  134. ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;
  135. RestOpHelper rop = new RestOpHelper();
  136. rop.Clientp12path = @"C:\Users\Administrator\Desktop\yonyou-cert\wildcard.pfx";
  137. rop.Clientp12PassWord = "Yonyou2024!";
  138. rop.Url = @"https://yerp-proxy-sap-dev.skchemicals.com/XISOAPAdapter/MessageServlet?senderParty=&senderService=YERP_D&receiverParty=&receiverService=&interface=YERP_012_OA1_SI&interfaceNamespace=http://skch.com/YERP_012_IF_SALES_ACT";
  139. rop.RequestSAP(rop.Url, 10000, postData, "IF_YERP", "Xtxc355860", out statusCode, out resultContent);
  140. log.Info("YERP_012 statusCode:" + statusCode + "\r\n" + "resultContent:" + resultContent);
  141. }
  142. }
  143. catch (Exception ex)
  144. {
  145. log.Error(ex.ToString());
  146. }
  147. }
  148. public static Configuration GetConfig()
  149. {
  150. Assembly assembly = Assembly.GetCallingAssembly();
  151. string path = string.Format("{0}.config", assembly.Location);
  152. if (!File.Exists(path))
  153. {
  154. throw new FileNotFoundException(path + "路径下的文件未找到!");
  155. }
  156. try
  157. {
  158. ExeConfigurationFileMap configFile = new ExeConfigurationFileMap();
  159. configFile.ExeConfigFilename = path;
  160. Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFile, ConfigurationUserLevel.None);
  161. return config;
  162. }
  163. catch (Exception)
  164. {
  165. throw;
  166. }
  167. }
  168. }
  169. }