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.

180 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 = Dates.AddDays(-1).ToString("yyyy-MM-dd");//"2023-06-01";
  69. var endPeriod = Dates.ToString("yyyy-MM-dd");//"2023-06-30";
  70. string sqls = @"select
  71. IF_STD_DATE,INVOICE_DATE,ITEM_CD,ITEM_NM,SKU_PAYMT_QTY_UOM,SALES_SITE_CD,SALES_SITE_NM,CREATE_BY,COUNT(*) OVER (PARTITION BY getdate()) GEN_ROW_CNT
  72. ,SUM(SKU_PAYMT_QTY) SKU_PAYMT_QTY,SUM(PAYMT_PRICE) PAYMT_PRICE
  73. from (
  74. select convert(nvarchar(10),getdate(),112) IF_STD_DATE,
  75. convert(nvarchar(10),a.dDate,111) INVOICE_DATE,
  76. b.cInvCode ITEM_CD,
  77. c.cInvName ITEM_NM,
  78. CAST(iQuantity AS INT) SKU_PAYMT_QTY,
  79. d.cComUnitName SKU_PAYMT_QTY_UOM,
  80. a.cCusCode SALES_SITE_CD,
  81. e.cCusName SALES_SITE_NM,
  82. dcreatesystime CREATE_DTTM,
  83. b.iNatSum PAYMT_PRICE,
  84. cMaker CREATE_BY,
  85. dmodifysystime MODIFY_DTTM
  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. ) a
  92. group by IF_STD_DATE,INVOICE_DATE,ITEM_CD,ITEM_NM,SKU_PAYMT_QTY_UOM,SALES_SITE_CD,SALES_SITE_NM,CREATE_BY";//
  93. sqls = string.Format(sqls, beginPeriod, endPeriod);
  94. log.Info("YERP_012 sql:" + sqls);
  95. DataTable vbsdt = ICSHelper.ExecuteTable(conStr, sqls);
  96. log.Info("YERP_012 sql结果数量" + vbsdt.Rows.Count);
  97. if (vbsdt.Rows.Count > 0)
  98. {
  99. StringBuilder soapRequestData = new StringBuilder();
  100. soapRequestData.Append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:yerp=\"http://skch.com/YERP_012_IF_SALES_ACT\">");
  101. soapRequestData.Append("<soapenv:Header/>");
  102. soapRequestData.Append("<soapenv:Body>");
  103. soapRequestData.Append("<yerp:YERP_012_OA1_MT>");
  104. //循环数据 PAYMT_PRICE INVOICE_DATE GEN_ROW_CNT
  105. foreach (DataRow itemRow in vbsdt.Rows)
  106. {
  107. soapRequestData.Append("<!--Zero or more repetitions: -->");
  108. soapRequestData.Append("<IF_ACT_SALES>");
  109. soapRequestData.Append(itemRow["IF_STD_DATE"] != null ? "<IF_STD_DATE>" + itemRow["IF_STD_DATE"].ToString() + "</IF_STD_DATE>" : "<IF_STD_DATE>" + "</IF_STD_DATE>");
  110. soapRequestData.Append(itemRow["INVOICE_DATE"] != null ? "<INVOICE_DATE>" + itemRow["INVOICE_DATE"].ToString() + "</INVOICE_DATE>" : "<INVOICE_DATE>" + "</INVOICE_DATE>");
  111. soapRequestData.Append(itemRow["ITEM_CD"] != null ? "<ITEM_CD>" + itemRow["ITEM_CD"].ToString() + "</ITEM_CD>" : "<ITEM_CD>" + "</ITEM_CD>");
  112. soapRequestData.Append(itemRow["ITEM_NM"] != null ? "<ITEM_NM>" + itemRow["ITEM_NM"].ToString() + "</ITEM_NM>" : "<ITEM_NM>" + "</ITEM_NM>");
  113. soapRequestData.Append("<!--Optional:-->");
  114. soapRequestData.Append(itemRow["SKU_PAYMT_QTY"] != null ? "<SKU_PAYMT_QTY>" + itemRow["SKU_PAYMT_QTY"].ToString() + "</SKU_PAYMT_QTY>" : "<SKU_PAYMT_QTY>" + "</SKU_PAYMT_QTY>");
  115. soapRequestData.Append("<!--Optional:-->");
  116. 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>");
  117. soapRequestData.Append("<!--Optional:-->");
  118. soapRequestData.Append(itemRow["SALES_SITE_CD"] != null ? "<SALES_SITE_CD>" + itemRow["SALES_SITE_CD"].ToString() + "</SALES_SITE_CD>" : "<SALES_SITE_CD>" + "</SALES_SITE_CD>");
  119. soapRequestData.Append("<!--Optional:-->");
  120. soapRequestData.Append(itemRow["SALES_SITE_NM"] != null ? "<SALES_SITE_NM>" + itemRow["SALES_SITE_NM"].ToString() + "</SALES_SITE_NM>" : "<SALES_SITE_NM>" + "</SALES_SITE_NM>");
  121. soapRequestData.Append("<!--Optional:-->");
  122. soapRequestData.Append(itemRow["PAYMT_PRICE"] != null ? "<PAYMT_PRICE>" + itemRow["PAYMT_PRICE"].ToString() + "</PAYMT_PRICE>" : "<PAYMT_PRICE>" + "</PAYMT_PRICE>");
  123. soapRequestData.Append("<!--Optional:-->");
  124. soapRequestData.Append(itemRow["CREATE_BY"] != null ? "<CREATE_BY>" + itemRow["CREATE_BY"].ToString() + "</CREATE_BY>" : "<CREATE_BY>" + "</CREATE_BY>");
  125. soapRequestData.Append("<!--Optional:-->");
  126. soapRequestData.Append(itemRow["GEN_ROW_CNT"] != null ? "<GEN_ROW_CNT>" + itemRow["GEN_ROW_CNT"].ToString() + "</GEN_ROW_CNT>" : "<GEN_ROW_CNT>" + "</GEN_ROW_CNT>");
  127. soapRequestData.Append("</IF_ACT_SALES>");
  128. }
  129. soapRequestData.Append("</yerp:YERP_012_OA1_MT>");
  130. soapRequestData.Append("</soapenv:Body>");
  131. soapRequestData.Append("</soapenv:Envelope>");
  132. string postData = soapRequestData.ToString();
  133. log.Info("YERP_012 xmlRequest:" + postData);
  134. string statusCode;
  135. string resultContent;
  136. ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;
  137. RestOpHelper rop = new RestOpHelper();
  138. rop.Clientp12path = @"C:\Users\Administrator\Desktop\yonyou-cert\wildcard.pfx";
  139. rop.Clientp12PassWord = "Yonyou2024!";
  140. rop.Url = @"https://yerp-proxy-sap-prod.skchemicals.com/XISOAPAdapter/MessageServlet?senderParty=&senderService=YERP_P&receiverParty=&receiverService=&interface=YERP_012_OA1_SI&interfaceNamespace=http://skch.com/YERP_012_IF_SALES_ACT";
  141. rop.RequestSAP(rop.Url, 10000, postData, "IF_YERP", "Kfiw282082", out statusCode, out resultContent);
  142. log.Info("YERP_012 statusCode:" + statusCode + "\r\n" + "resultContent:" + resultContent);
  143. }
  144. }
  145. catch (Exception ex)
  146. {
  147. log.Error(ex.ToString());
  148. }
  149. }
  150. public static Configuration GetConfig()
  151. {
  152. Assembly assembly = Assembly.GetCallingAssembly();
  153. string path = string.Format("{0}.config", assembly.Location);
  154. if (!File.Exists(path))
  155. {
  156. throw new FileNotFoundException(path + "路径下的文件未找到!");
  157. }
  158. try
  159. {
  160. ExeConfigurationFileMap configFile = new ExeConfigurationFileMap();
  161. configFile.ExeConfigFilename = path;
  162. Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFile, ConfigurationUserLevel.None);
  163. return config;
  164. }
  165. catch (Exception)
  166. {
  167. throw;
  168. }
  169. }
  170. }
  171. }