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.

188 lines
11 KiB

3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
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. /// 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. //select
  75. //SUM(ISNULL(iAInPrice,0)) as SumAInPrice,
  76. //SUM(ISNULL(iAOutPrice,0)) as SumAOutPrice,
  77. //sum(ISNULL(iAInQuantity,0)) as SumAInQuantity,
  78. //sum(ISNULL(iAOutQuantity,0)) as SumAOutQuantity
  79. //from IA_Subsidiary a where a.cWhCode = 'CC001' and cInvCode = '103012'
  80. //group by cWhCode,cInvCode
  81. // 过滤时间为截止本月月初
  82. var lastMonth = "2024-01-01";// Dates.AddDays(-Dates.Day + 1).ToString("yyyy-MM-dd");//"2024-01-01";
  83. // 月库存统计:每个月14号,查询上月截止到月末的库存数据累计数量和金额 因为期初数量本来就是统计历史收发数量,所以期初数量+收发数量 = 收发数量总和,金额同理
  84. string sqls = @"
  85. select * from (select cWhCode,a.cInvCode,convert(nvarchar(10),getdate(),112) IF_STD_DATE,
  86. convert(nvarchar(10),getdate(),112) STCK_STD_DATE,
  87. a.cWhCode WRHS_CD,
  88. a.cInvCode ITEM_CD,c.cInvName,
  89. cBatchia PRDT_BTCH_NO,
  90. 'EOH' STCK_TYPE_CD,
  91. SUM(ISNULL(a.iAInQuantity,0)) - SUM(ISNULL(a.iAOutQuantity,0)) STCK_QTY,
  92. SUM(ISNULL(iAInPrice,0)) - SUM(ISNULL(iAOutPrice,0)) STCK_VALUE_CNY,
  93. (case when cInvStd is null then null else (CASE WHEN ISNUMERIC(left(cinvstd,3)) = 1 THEN UPPER(REPLACE(SUBSTRING(cinvstd, 1, CHARINDEX('/', cinvstd) - 1),left(cinvstd,3),'')) ELSE (CASE WHEN ISNUMERIC(left(cinvstd,2)) = 1
  94. THEN UPPER(REPLACE(SUBSTRING(cinvstd, 1, CHARINDEX('/', cinvstd) - 1),left(cinvstd,2),'')) ELSE (CASE WHEN ISNUMERIC(left(cinvstd,1)) = 1
  95. THEN UPPER(REPLACE(SUBSTRING(cinvstd, 1, CHARINDEX('/', cinvstd) - 1),left(cinvstd,1),'')) ELSE '' END) END) END) end) STCK_UOM,
  96. cInvStd PACK_MIN_QTY,
  97. COUNT(*) OVER (PARTITION BY getdate()) GEN_ROW_CNT
  98. from IA_Subsidiary a
  99. left join dbo.Inventory c on a.cInvCode=c.cInvCode
  100. where a.dKeepDate < N'{0}' and a.cVouType<> N'33' and ISNULL(a.iMonth,0)<>0 and ISNULL(a.cBatchia,'') != ''
  101. group by a.cInvCode,a.cWhCode,a.cBatchia,c.cInvName,c.cinvstd) a
  102. where STCK_QTY > 0";
  103. sqls = string.Format(sqls, lastMonth);
  104. log.Info("YERP_010 sql:" + sqls);
  105. DataTable vbsdt = ICSHelper.ExecuteTable(conStr, sqls);
  106. log.Info("YERP_010 sql结果数量" + vbsdt.Rows.Count);
  107. if (vbsdt.Rows.Count > 0)
  108. {
  109. StringBuilder soapRequestData = new StringBuilder();
  110. soapRequestData.Append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:yerp=\"http://skch.com/YERP_010_IF_STCK_HST\">");
  111. soapRequestData.Append("<soapenv:Header/>");
  112. soapRequestData.Append("<soapenv:Body>");
  113. soapRequestData.Append("<yerp:YERP_010_OA1_MT>");
  114. //循环数据 STCK_STD_DATE STCK_TYPE_CD STCK_VALUE_CNW
  115. foreach (DataRow itemRow in vbsdt.Rows)
  116. {
  117. soapRequestData.Append("<!--Zero or more repetitions: -->");
  118. soapRequestData.Append("<IF_STCK_HST>");
  119. soapRequestData.Append(itemRow["IF_STD_DATE"] != null ? "<IF_STD_DATE>" + itemRow["IF_STD_DATE"].ToString() + "</IF_STD_DATE>" : "<IF_STD_DATE>" + "</IF_STD_DATE>");
  120. soapRequestData.Append(itemRow["STCK_STD_DATE"] != null ? "<STCK_STD_DATE>" + itemRow["STCK_STD_DATE"].ToString() + "</STCK_STD_DATE>" : "<STCK_STD_DATE>" + "</STCK_STD_DATE>");
  121. soapRequestData.Append(itemRow["WRHS_CD"] != null ? "<WRHS_CD>" + itemRow["WRHS_CD"].ToString() + "</WRHS_CD>" : "<WRHS_CD>" + "</WRHS_CD>");
  122. soapRequestData.Append(itemRow["ITEM_CD"] != null ? "<ITEM_CD>" + itemRow["ITEM_CD"].ToString() + "</ITEM_CD>" : "<ITEM_CD>" + "</ITEM_CD>");
  123. soapRequestData.Append(itemRow["PRDT_BTCH_NO"] != null ? "<PRDT_BTCH_NO>" + itemRow["PRDT_BTCH_NO"].ToString() + "</PRDT_BTCH_NO>" : "<PRDT_BTCH_NO>" + "</PRDT_BTCH_NO>");
  124. soapRequestData.Append(itemRow["STCK_TYPE_CD"] != null ? "<STCK_TYPE_CD>" + itemRow["STCK_TYPE_CD"].ToString() + "</STCK_TYPE_CD>" : "<STCK_TYPE_CD>" + "</STCK_TYPE_CD>");
  125. soapRequestData.Append(itemRow["STCK_QTY"] != null ? "<STCK_QTY>" + itemRow["STCK_QTY"].ToString() + "</STCK_QTY>" : "<STCK_QTY>" + "</STCK_QTY>");
  126. soapRequestData.Append(itemRow["STCK_VALUE_CNY"] != null ? "<STCK_VALUE_CNY>" + itemRow["STCK_VALUE_CNY"].ToString() + "</STCK_VALUE_CNY>" : "<STCK_VALUE_CNY>" + "</STCK_VALUE_CNY>");
  127. soapRequestData.Append(itemRow["STCK_UOM"] != null ? "<STCK_UOM>" + itemRow["STCK_UOM"].ToString() + "</STCK_UOM>" : "<STCK_UOM>" + "</STCK_UOM>");
  128. soapRequestData.Append("<!--Optional:-->");
  129. 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>");
  130. soapRequestData.Append("<!--Optional:-->");
  131. soapRequestData.Append(itemRow["GEN_ROW_CNT"] != null ? "<GEN_ROW_CNT>" + itemRow["GEN_ROW_CNT"].ToString() + "</GEN_ROW_CNT>" : "<GEN_ROW_CNT>" + "</GEN_ROW_CNT>");
  132. soapRequestData.Append("</IF_STCK_HST>");
  133. }
  134. soapRequestData.Append("</yerp:YERP_010_OA1_MT>");
  135. soapRequestData.Append("</soapenv:Body>");
  136. soapRequestData.Append("</soapenv:Envelope>");
  137. string postData = soapRequestData.ToString();
  138. log.Info("YERP_010 xmlRequest:" + postData);
  139. string statusCode;
  140. string resultContent;
  141. ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;
  142. RestOpHelper rop = new RestOpHelper();
  143. rop.Clientp12path = @"C:\Users\Administrator\Desktop\yonyou-cert\wildcard.pfx";
  144. rop.Clientp12PassWord = "Yonyou2024!";
  145. 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";
  146. rop.RequestSAP(rop.Url, 10000, postData, "IF_YERP", "Xtxc355860", out statusCode, out resultContent);
  147. log.Info("YERP_010 statusCode:" + statusCode + "\r\n" + "resultContent:" + resultContent);
  148. }
  149. }
  150. catch (Exception ex)
  151. {
  152. log.Error(ex.ToString());
  153. }
  154. }
  155. public static Configuration GetConfig()
  156. {
  157. Assembly assembly = Assembly.GetCallingAssembly();
  158. string path = string.Format("{0}.config", assembly.Location);
  159. if (!File.Exists(path))
  160. {
  161. throw new FileNotFoundException(path + "路径下的文件未找到!");
  162. }
  163. try
  164. {
  165. ExeConfigurationFileMap configFile = new ExeConfigurationFileMap();
  166. configFile.ExeConfigFilename = path;
  167. Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFile, ConfigurationUserLevel.None);
  168. return config;
  169. }
  170. catch (Exception)
  171. {
  172. throw;
  173. }
  174. }
  175. }
  176. }