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.

169 lines
9.3 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.Runtime.Remoting.Messaging;
  11. using System.Text;
  12. using System.Text.RegularExpressions;
  13. using System.Threading.Tasks;
  14. namespace ICSSoft.FromERP
  15. {
  16. /// <summary>
  17. /// Item Master(物料主数据)
  18. /// </summary>
  19. public class YERP_008 : IJob
  20. {
  21. private static object key = new object();
  22. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  23. public void Execute(IJobExecutionContext context)
  24. {
  25. try
  26. {
  27. lock (key)
  28. {
  29. log.Info("开始……………………………………………………………………");
  30. Execute();
  31. log.Info("结束……………………………………………………………………");
  32. }
  33. }
  34. catch (Exception ex)
  35. {
  36. log.Error(ex.ToString());
  37. }
  38. }
  39. public async void Execute()
  40. {
  41. try
  42. {
  43. Configuration config = GetConfig();
  44. var Dates = DateTime.Now;
  45. string conStr = ICSHelper.GetConnectString();
  46. //<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:yerp="http://skch.com/YERP_008_ITEM_INFO">
  47. // <soapenv:Header/>
  48. // <soapenv:Body>
  49. // <yerp:YERP_008_OA1_MT>
  50. // <!--Zero or more repetitions: -->
  51. // <IF_ITEM_MST>
  52. // <IF_STD_DATE>20240814</IF_STD_DATE>
  53. // <ITEM_CD>201010</ITEM_CD>
  54. // <ITEM_NM>ECOTRION H1000</ITEM_NM>
  55. // <!--Optional:-->
  56. // <ITEM_PACK_UOM>kg</ITEM_PACK_UOM>
  57. // <!--Optional:-->
  58. // <CREATE_DTTM>20230713</CREATE_DTTM>
  59. // <!--Optional:-->
  60. // <CREATE_BY>21436</CREATE_BY>
  61. // <!--Optional:-->
  62. // <ROW_CNT>1</ROW_CNT>
  63. // </IF_ITEM_MST>
  64. // </yerp:YERP_008_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 convert(nvarchar(10),getdate(),112) IF_STD_DATE,
  71. cInvCode ITEM_CD,
  72. d.cInvCName+' '+cInvName ITEM_NM,
  73. a.cInvCCode BRND_CD,
  74. '' GRADE_CD,
  75. d.cInvCName BRND_NM,
  76. cInvName GRADE_NM,
  77. cInvStd ITEM_PACK_UOM,
  78. (case when cInvStd is null then '0' else (CASE WHEN ISNUMERIC(left(cinvstd,3)) = 1 THEN left(cinvstd,3) ELSE (CASE WHEN ISNUMERIC(left(cinvstd,2)) = 1
  79. THEN left(cinvstd,2) ELSE (CASE WHEN ISNUMERIC(left(cinvstd,1)) = 1 THEN left(cinvstd,1) ELSE 0 END) END) END) end) PACK_MIN_QTY,
  80. dInvCreateDatetime CREATE_DTTM,
  81. cCreatePerson CREATE_BY,
  82. dModifyDate MODIFY_DTTM,
  83. cModifyPerson MODIFY_BY,
  84. COUNT(*) OVER (PARTITION BY getdate()) ROW_CNT
  85. from dbo.Inventory a
  86. left join dbo.Inventory_Sub b on a.cInvCode=b.cInvSubCode
  87. left join dbo.ComputationUnit c on a.cComUnitCode=c.cComunitCode
  88. left join dbo.InventoryClass d on a.cInvCCode=d.cInvCCode
  89. WHERE 1 = 1 and dInvCreateDatetime >= '{0}' and dInvCreateDatetime <= '{1}'";//and dInvCreateDatetime > '{0}' and dInvCreateDatetime < '{1}'
  90. sqls = string.Format(sqls, beginPeriod, endPeriod);
  91. log.Info("YERP_008 sql:"+sqls);
  92. DataTable vbsdt = ICSHelper.ExecuteTable(conStr, sqls);
  93. log.Info("YERP_008 sql结果数量" + vbsdt.Rows.Count);
  94. if (vbsdt.Rows.Count > 0)
  95. {
  96. StringBuilder soapRequestData = new StringBuilder();
  97. soapRequestData.Append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:yerp=\"http://skch.com/YERP_008_ITEM_INFO\">");
  98. soapRequestData.Append("<soapenv:Header/>");
  99. soapRequestData.Append("<soapenv:Body>");
  100. soapRequestData.Append("<yerp:YERP_008_OA1_MT>");
  101. //循环数据
  102. foreach (DataRow itemRow in vbsdt.Rows)
  103. {
  104. soapRequestData.Append("<!--Zero or more repetitions: -->");
  105. soapRequestData.Append("<IF_ITEM_MST>");
  106. soapRequestData.Append(itemRow["IF_STD_DATE"] != null ? "<IF_STD_DATE>" + itemRow["IF_STD_DATE"].ToString() + "</IF_STD_DATE>" : "<IF_STD_DATE>" + "</IF_STD_DATE>");
  107. soapRequestData.Append(itemRow["ITEM_CD"] != null ? "<ITEM_CD>" + itemRow["ITEM_CD"].ToString() + "</ITEM_CD>" : "<ITEM_CD>" + "</ITEM_CD>");
  108. soapRequestData.Append(itemRow["ITEM_NM"] != null ? "<ITEM_NM>" + itemRow["ITEM_NM"].ToString() + "</ITEM_NM>" : "<ITEM_NM>" + "</ITEM_NM>");
  109. soapRequestData.Append("<!--Optional:-->");
  110. soapRequestData.Append(itemRow["ITEM_PACK_UOM"] != null ? "<ITEM_PACK_UOM>" + Regex.Replace(itemRow["ITEM_PACK_UOM"].ToString(), @"[^0-9]+", "") + "</ITEM_PACK_UOM>" : "<ITEM_PACK_UOM>" + "</ITEM_PACK_UOM>");
  111. soapRequestData.Append("<!--Optional:-->");
  112. soapRequestData.Append(itemRow["CREATE_DTTM"] != null ? "<CREATE_DTTM>" + itemRow["CREATE_DTTM"].ToString() + "</CREATE_DTTM>" : "<CREATE_DTTM>" + "</CREATE_DTTM>");
  113. soapRequestData.Append("<!--Optional:-->");
  114. soapRequestData.Append(itemRow["CREATE_BY"] != null ? "<CREATE_BY>" + itemRow["CREATE_BY"].ToString() + "</CREATE_BY>" : "<CREATE_BY>" + "</CREATE_BY>");
  115. soapRequestData.Append("<!--Optional:-->");
  116. soapRequestData.Append(itemRow["ROW_CNT"] != null ? "<ROW_CNT>" + itemRow["ROW_CNT"].ToString() + "</ROW_CNT>" : "<ROW_CNT>" + "</ROW_CNT>");
  117. soapRequestData.Append("</IF_ITEM_MST>");
  118. }
  119. soapRequestData.Append("</yerp:YERP_008_OA1_MT>");
  120. soapRequestData.Append("</soapenv:Body>");
  121. soapRequestData.Append("</soapenv:Envelope>");
  122. string postData = soapRequestData.ToString();
  123. log.Info("YERP_008 xmlRequest:" + postData);
  124. string statusCode;
  125. string resultContent;
  126. ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;
  127. RestOpHelper rop = new RestOpHelper();
  128. rop.Clientp12path = @"C:\Users\Administrator\Desktop\yonyou-cert\wildcard.pfx";
  129. rop.Clientp12PassWord = "Yonyou2024!";
  130. rop.Url = @"https://yerp-proxy-sap-prod.skchemicals.com/XISOAPAdapter/MessageServlet?senderParty=&senderService=YERP_P&receiverParty=&receiverService=&interface=YERP_008_OA1_SI&interfaceNamespace=http://skch.com/YERP_008_ITEM_INFO";
  131. rop.RequestSAP(rop.Url, 10000, postData, "IF_YERP", "Kfiw282082", out statusCode, out resultContent);
  132. log.Info("YERP_008 statusCode:" + statusCode + "\r\n" + "resultContent:" + resultContent);
  133. }
  134. }
  135. catch (Exception ex)
  136. {
  137. log.Error(ex.ToString());
  138. }
  139. }
  140. public static Configuration GetConfig()
  141. {
  142. Assembly assembly = Assembly.GetCallingAssembly();
  143. string path = string.Format("{0}.config", assembly.Location);
  144. if (!File.Exists(path))
  145. {
  146. throw new FileNotFoundException(path + "路径下的文件未找到!");
  147. }
  148. try
  149. {
  150. ExeConfigurationFileMap configFile = new ExeConfigurationFileMap();
  151. configFile.ExeConfigFilename = path;
  152. Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFile, ConfigurationUserLevel.None);
  153. return config;
  154. }
  155. catch (Exception)
  156. {
  157. throw;
  158. }
  159. }
  160. }
  161. }