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

  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. /// Stock information 库存信息 月
  17. /// </summary>
  18. public class YERP_010_EOH : 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_010_IF_STCK_HST">
  46. // <soapenv:Header/>
  47. // <soapenv:Body>
  48. // <yerp:YERP_010_OA1_MT>
  49. // <!--Zero or more repetitions:-->
  50. // <IF_STCK_HST>
  51. // <IF_STD_DATE>2024-07-01</IF_STD_DATE>
  52. // <!--Optional:-->
  53. // <STCK_STD_DATE>2024-07-01</STCK_STD_DATE>
  54. // <!--Optional:-->
  55. // <WRHS_CD>?</WRHS_CD>
  56. // <ITEM_CD>?</ITEM_CD>
  57. // <!--Optional:-->
  58. // <PRDT_BTCH_NO>?</PRDT_BTCH_NO>
  59. // <STCK_TYPE_CD>?</STCK_TYPE_CD>
  60. // <!--Optional:-->
  61. // <STCK_QTY>?</STCK_QTY>
  62. // <!--Optional:-->
  63. // <STCK_VALUE_CNW>?</STCK_VALUE_CNW>
  64. // <!--Optional:-->
  65. // <STCK_UOM>?</STCK_UOM>
  66. // <!--Optional:-->
  67. // <PACK_MIN_QTY>?</PACK_MIN_QTY>
  68. // <GEN_ROW_CNT>?</GEN_ROW_CNT>
  69. // </IF_STCK_HST>
  70. // </yerp:YERP_010_OA1_MT>
  71. // </soapenv:Body>
  72. //</soapenv:Envelope>
  73. // 过滤时间为上个月
  74. var beginPeriod = "2023-06-01";// Dates.AddMonths(-1).AddDays(-Dates.Day + 1).ToString("yyyy-MM-dd");//"2023-06-01";
  75. var endPeriod = "2023-07-01";// Dates.AddDays(-Dates.Day + 1).ToString("yyyy-MM-dd");//"2023-07-01";
  76. string sqls = @"
  77. select convert(nvarchar(10),getdate(),112) IF_STD_DATE,
  78. convert(nvarchar(10),getdate(),112) STCK_STD_DATE,
  79. cWhCode WRHS_CD,
  80. a.cInvCode ITEM_CD,
  81. cBatch PRDT_BTCH_NO,
  82. 'EOH' STCK_TYPE_CD,
  83. iQuantity STCK_QTY,
  84. 0 STCK_VALUE_CNW,
  85. '' STCK_VALUE_UOM,
  86. (case when cInvStd is null then null else (CASE WHEN ISNUMERIC(left(cinvstd,3)) = 1 THEN REPLACE(SUBSTRING(cinvstd, 1, CHARINDEX('/', cinvstd) - 1),left(cinvstd,3),'') ELSE (CASE WHEN ISNUMERIC(left(cinvstd,2)) = 1
  87. THEN REPLACE(SUBSTRING(cinvstd, 1, CHARINDEX('/', cinvstd) - 1),left(cinvstd,2),'') ELSE (CASE WHEN ISNUMERIC(left(cinvstd,1)) = 1
  88. THEN REPLACE(SUBSTRING(cinvstd, 1, CHARINDEX('/', cinvstd) - 1),left(cinvstd,1),'') ELSE '' END) END) END) end) STCK_UOM,
  89. cInvStd PACK_MIN_QTY,
  90. COUNT(*) OVER (PARTITION BY getdate()) GEN_ROW_CNT
  91. from CurrentStock a
  92. left join dbo.Inventory c on a.cInvCode=c.cInvCode
  93. where 1 = 1 and iQuantity > 0";//and dInvCreateDatetime > '{0}' and dInvCreateDatetime < '{1}'
  94. sqls = string.Format(sqls, beginPeriod, endPeriod);
  95. log.Info("YERP_010 sql:" + sqls);
  96. DataTable vbsdt = ICSHelper.ExecuteTable(conStr, sqls);
  97. log.Info("YERP_010 sql结果数量" + vbsdt.Rows.Count);
  98. if (vbsdt.Rows.Count > 0)
  99. {
  100. StringBuilder soapRequestData = new StringBuilder();
  101. soapRequestData.Append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:yerp=\"http://skch.com/YERP_010_IF_STCK_HST\">");
  102. soapRequestData.Append("<soapenv:Header/>");
  103. soapRequestData.Append("<soapenv:Body>");
  104. soapRequestData.Append("<yerp:YERP_010_OA1_MT>");
  105. //循环数据 STCK_STD_DATE STCK_TYPE_CD STCK_VALUE_CNW
  106. foreach (DataRow itemRow in vbsdt.Rows)
  107. {
  108. soapRequestData.Append("<!--Zero or more repetitions: -->");
  109. soapRequestData.Append("<IF_STCK_HST>");
  110. soapRequestData.Append(itemRow["IF_STD_DATE"] != null ? "<IF_STD_DATE>" + itemRow["IF_STD_DATE"].ToString() + "</IF_STD_DATE>" : "<IF_STD_DATE>" + "</IF_STD_DATE>");
  111. soapRequestData.Append(itemRow["STCK_STD_DATE"] != null ? "<STCK_STD_DATE>" + itemRow["STCK_STD_DATE"].ToString() + "</STCK_STD_DATE>" : "<STCK_STD_DATE>" + "</STCK_STD_DATE>");
  112. soapRequestData.Append(itemRow["WRHS_CD"] != null ? "<WRHS_CD>" + itemRow["WRHS_CD"].ToString() + "</WRHS_CD>" : "<WRHS_CD>" + "</WRHS_CD>");
  113. soapRequestData.Append(itemRow["ITEM_CD"] != null ? "<ITEM_CD>" + itemRow["ITEM_CD"].ToString() + "</ITEM_CD>" : "<ITEM_CD>" + "</ITEM_CD>");
  114. soapRequestData.Append(itemRow["PRDT_BTCH_NO"] != null ? "<PRDT_BTCH_NO>" + itemRow["PRDT_BTCH_NO"].ToString() + "</PRDT_BTCH_NO>" : "<PRDT_BTCH_NO>" + "</PRDT_BTCH_NO>");
  115. soapRequestData.Append(itemRow["STCK_TYPE_CD"] != null ? "<STCK_TYPE_CD>" + itemRow["STCK_TYPE_CD"].ToString() + "</STCK_TYPE_CD>" : "<STCK_TYPE_CD>" + "</STCK_TYPE_CD>");
  116. soapRequestData.Append(itemRow["STCK_QTY"] != null ? "<STCK_QTY>" + itemRow["STCK_QTY"].ToString() + "</STCK_QTY>" : "<STCK_QTY>" + "</STCK_QTY>");
  117. soapRequestData.Append(itemRow["STCK_VALUE_CNW"] != null ? "<STCK_VALUE_CNW>" + itemRow["STCK_VALUE_CNW"].ToString() + "</STCK_VALUE_CNW>" : "<STCK_VALUE_CNW>" + "</STCK_VALUE_CNW>");
  118. soapRequestData.Append(itemRow["STCK_UOM"] != null ? "<STCK_UOM>" + itemRow["STCK_UOM"].ToString() + "</STCK_UOM>" : "<STCK_UOM>" + "</STCK_UOM>");
  119. soapRequestData.Append("<!--Optional:-->");
  120. soapRequestData.Append(itemRow["PACK_MIN_QTY"] != null ? "<PACK_MIN_QTY>" + Regex.Replace(itemRow["PACK_MIN_QTY"].ToString(), @"[^0-9]+", "") + "</PACK_MIN_QTY>" : "<PACK_MIN_QTY>" + "</PACK_MIN_QTY>");
  121. soapRequestData.Append("<!--Optional:-->");
  122. soapRequestData.Append(itemRow["GEN_ROW_CNT"] != null ? "<GEN_ROW_CNT>" + itemRow["GEN_ROW_CNT"].ToString() + "</GEN_ROW_CNT>" : "<GEN_ROW_CNT>" + "</GEN_ROW_CNT>");
  123. soapRequestData.Append("</IF_STCK_HST>");
  124. }
  125. soapRequestData.Append("</yerp:YERP_010_OA1_MT>");
  126. soapRequestData.Append("</soapenv:Body>");
  127. soapRequestData.Append("</soapenv:Envelope>");
  128. string postData = soapRequestData.ToString();
  129. log.Info("YERP_010 xmlRequest:" + postData);
  130. string statusCode;
  131. string resultContent;
  132. ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;
  133. RestOpHelper rop = new RestOpHelper();
  134. rop.Clientp12path = @"C:\Users\Administrator\Desktop\yonyou-cert\wildcard.pfx";
  135. rop.Clientp12PassWord = "Yonyou2024!";
  136. rop.Url = @"https://yerp-proxy-sap-dev.skchemicals.com/XISOAPAdapter/MessageServlet?senderParty=&senderService=YERP_D&receiverParty=&receiverService=&interface=YERP_010_OA1_SI&interfaceNamespace=http://skch.com/YERP_010_IF_STCK_HST";
  137. rop.RequestSAP(rop.Url, 10000, postData, "IF_YERP", "Xtxc355860", out statusCode, out resultContent);
  138. log.Info("YERP_010 statusCode:" + statusCode + "\r\n" + "resultContent:" + resultContent);
  139. }
  140. }
  141. catch (Exception ex)
  142. {
  143. log.Error(ex.ToString());
  144. }
  145. }
  146. public static Configuration GetConfig()
  147. {
  148. Assembly assembly = Assembly.GetCallingAssembly();
  149. string path = string.Format("{0}.config", assembly.Location);
  150. if (!File.Exists(path))
  151. {
  152. throw new FileNotFoundException(path + "路径下的文件未找到!");
  153. }
  154. try
  155. {
  156. ExeConfigurationFileMap configFile = new ExeConfigurationFileMap();
  157. configFile.ExeConfigFilename = path;
  158. Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFile, ConfigurationUserLevel.None);
  159. return config;
  160. }
  161. catch (Exception)
  162. {
  163. throw;
  164. }
  165. }
  166. }
  167. }