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.

231 lines
16 KiB

1 month ago
2 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. /// 进销存统计表
  17. /// </summary>
  18. public class YERP_001 : 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. //string url = config.ConnectionStrings.ConnectionStrings["APIAddStdWorkHour"].ConnectionString.ToString();
  44. var Dates = DateTime.Now;
  45. //log.Info("获取创建定额工时接口 " + url);
  46. //if (string.IsNullOrEmpty(url))
  47. //{
  48. // return;
  49. //}
  50. string conStr = ICSHelper.GetConnectString();
  51. //<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:yerp="http://skch.com/YERP_001_INVENTORY_DATA">
  52. // <soapenv:Header/>
  53. // <soapenv:Body>
  54. // <yerp:YERP_001_OA1_MT>
  55. // <!--1 or more repetitions:-->
  56. // <INVT_DATA>
  57. // <Created_Year>?</Created_Year>
  58. // <Created_Month>?</Created_Month>
  59. // <INVT_NM>?</INVT_NM>
  60. // <INVT_CD>?</INVT_CD>
  61. // <BSC_QTY>?</BSC_QTY>
  62. // <BSC_AMT>?</BSC_AMT>
  63. // <PCHS_QTY>?</PCHS_QTY>
  64. // <PCHS_AMT>?</PCHS_AMT>
  65. // <ESTM_QTY>?</ESTM_QTY>
  66. // <ESTM_AMT>?</ESTM_AMT>
  67. // <ETC_WHG_QTY>?</ETC_WHG_QTY>
  68. // <ETC_WHG_AMT>?</ETC_WHG_AMT>
  69. // <ETC_RLS_QTY>?</ETC_RLS_QTY>
  70. // <ETC_RLS_AMT>?</ETC_RLS_AMT>
  71. // <MOVE_QTY>?</MOVE_QTY>
  72. // <MOVE_AMT>?</MOVE_AMT>
  73. // <SL_QTY>?</SL_QTY>
  74. // <SL_RVN>?</SL_RVN>
  75. // <SL_AMT>?</SL_AMT>
  76. // <FRTX_AVRG_PRC>?</FRTX_AVRG_PRC>
  77. // <SMTX_AVRG_PRC>?</SMTX_AVRG_PRC>
  78. // <RLS_QTY>?</RLS_QTY>
  79. // <SL_COST>?</SL_COST>
  80. // <SLS_TOT_GAIN>?</SLS_TOT_GAIN>
  81. // <SLS_TOT_PRTO>?</SLS_TOT_PRTO>
  82. // <TE_QTY>?</TE_QTY>
  83. // <TE_AMT>?</TE_AMT>
  84. // </INVT_DATA>
  85. // </yerp:YERP_001_OA1_MT>
  86. // </soapenv:Body>
  87. //</soapenv:Envelope>
  88. // 202404
  89. // 过滤时间为上个月
  90. string Date = Dates.ToString("yyyy");// 2024;
  91. var beginPeriod = Dates.AddMonths(-1).AddDays(-Dates.Day + 1).ToString("yyyy-MM-dd");// "2024-07-01";
  92. var endPeriod = Dates.AddDays(-Dates.Day + 1).ToString("yyyy-MM-dd");//"2024-07-31";
  93. string sqls = @"
  94. begin transaction
  95. exec Sa_MoveSRMDetail N'JXCASKALL',N' ',N'{0}',N'{1}',N'{2}',N' ',N' ',N' ',N' ',N''
  96. select identity(int,0,1) as baseid,isnull([],'') as [],isnull([],'') as [],isnull([],'') as [],(Convert(Decimal(38,2),SUM([cInvDefine12]))) as [cInvDefine12],(Convert(Decimal(38,2),SUM([cInvDefine11]))) as
  97. [cInvDefine11],Convert(Decimal(38,2),SUM(isnull([],0)+isnull([],0)+isnull([],0)-isnull([],0)-isnull([],0))) as [],Convert(Decimal(38,2),SUM(isnull([],0)+isnull([],0)+isnull([],0)-isnull([],0)-isnull([],0))) as [],(Convert(Decimal(38,4),SUM([]))) as [],(Convert(Decimal(38,4),SUM([]))) as [],Convert(Decimal(38,2),SUM(isnull([],0)-isnull([],0))) as [],(Convert(Decimal(38,2),SUM([]))) as [],(Convert(Decimal(38,4),SUM([]))) as [],(Convert(Decimal(38,4),SUM([]))) as [],(Convert(Decimal(38,2),SUM([]))) as [],(Convert(Decimal(38,2),SUM([]))) as [],(Convert(Decimal(38,2),SUM([]))) as [],(Convert(Decimal(38,2),SUM([]))) as [],(Convert(Decimal(38,2),SUM([]))) as [],(Convert(Decimal(38,2),SUM([]))) as [],(Convert(Decimal(38,2),SUM([]))) as [],(Convert(Decimal(38,2),SUM([]))) as [],(Convert(Decimal(38,2),SUM([]))) as [],(Convert(Decimal(38,2),SUM([]))) as [],(Convert(Decimal(38,2),SUM([]))) as [],(Convert(Decimal(38,2),SUM([]))) as []
  98. into tempdb..JXCASKALL_1 from tempdb..JXCASKALL
  99. where 1 = 1 group by isnull([],''),isnull([],''),isnull([],'')
  100. having isnull(sum([]),0)<> 0 or isnull(sum([]),0)<> 0 or isnull(sum([]),0) <> 0 or isnull(sum([]),0) <> 0 or isnull(sum([] ),0)<> 0 or isnull(sum([]),0)<>0 or isnull(sum([] ),0)<> 0 or isnull(sum([]),0) <> 0 or isnull(sum([]),0) <> 0 or isnull(sum([]),0) <> 0 or isnull(sum([] ),0)<> 0 or isnull(sum([]),0) <> 0 or isnull(sum([] ),0)<> 0 or isnull(sum([]),0) <> 0 or isnull(sum([]),0) <> 0 or isnull(sum([]),0) <> 0 or isnull(sum([]),0) <> 0
  101. select A.* into TEMPDB..JXCASKALLNEW from TEMPDB..JXCASKALL A
  102. inner join TEMPDB..JXCASKALL_1 sum on isnull(A.[],'')=isnull(sum.[],'') and isnull(A.[],'')=isnull(sum.[],'') and isnull(A.[],'')=isnull(sum.[],'')
  103. select sum.* into TEMPDB..JXCASKALLNEW_1 from TEMPDB..JXCASKALL_1 sum
  104. select identity(int,0,1) as index__id,* into tempdb..JXCASKALLNEW_index from
  105. ( select baseid +0 as baseid, [],[],[] from tempdb..JXCASKALLNEW_1)A where 1=0
  106. insert into TEMPDB..JXCASKALLNEW_index
  107. select * from (select top 1000 baseid +0 as baseid, [],[],[]
  108. from TEMPDB..JXCASKALLNEW_1 order by [] asc)a
  109. select B.index__id,a. INVT_NM,a. INVT_CD,a. BSC_QTY,a. BSC_AMT,a. PCHS_QTY,a. PCHS_AMT,a. ESTM_QTY,a. ESTM_AMT,a. ETC_WHG_QTY,
  110. a. ETC_WHG_AMT,a. ETC_RLS_QTY,a. ETC_RLS_AMT,a. MOVE_QTY,a. MOVE_AMT,a. SL_QTY,a. SL_RVN,a. SL_AMT,
  111. '' FRTX_AVRG_PRC,
  112. '' SMTX_AVRG_PRC,
  113. a. RLS_QTY,a. SL_COST,a. SLS_TOT_GAIN,
  114. '' SLS_TOT_PRTO,a. TE_QTY,a. TE_AMT
  115. from TEMPDB..JXCASKALLNEW_1 A inner join
  116. TEMPDB..JXCASKALLNEW_index B on A.baseid=B.baseid
  117. drop table tempdb..JXCASKALL
  118. drop table tempdb..JXCASKALL_1
  119. drop table TEMPDB..JXCASKALLNEW
  120. drop table TEMPDB..JXCASKALLNEW_1
  121. drop table TEMPDB..JXCASKALLNEW_index
  122. rollback transaction";
  123. sqls = string.Format(sqls, Date, beginPeriod, endPeriod);
  124. log.Info("YERP_001 sql:" + sqls);
  125. DataTable vbsdt = ICSHelper.ExecuteTable(conStr, sqls);
  126. log.Info("sql结果数量" + vbsdt.Rows.Count);
  127. if (vbsdt.Rows.Count > 0)
  128. {
  129. StringBuilder soapRequestData = new StringBuilder();
  130. soapRequestData.Append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:yerp=\"http://skch.com/YERP_001_INVENTORY_DATA\">");
  131. soapRequestData.Append("<soapenv:Header/>");
  132. soapRequestData.Append("<soapenv:Body>");
  133. soapRequestData.Append("<yerp:YERP_001_OA1_MT>");
  134. //循环数据
  135. foreach (DataRow itemRow in vbsdt.Rows)
  136. {
  137. //原循环部分 begin
  138. soapRequestData.Append("<INVT_DATA>");
  139. soapRequestData.Append("<Created_Year>" + Dates.AddMonths(-1).ToString("yyyy") + "</Created_Year>");
  140. soapRequestData.Append("<Created_Month>" + Dates.AddMonths(-1).ToString("MM") + "</Created_Month>");
  141. soapRequestData.Append(itemRow["INVT_NM"] != null ? "<INVT_NM>" + itemRow["INVT_NM"].ToString() + "</INVT_NM>" : "<INVT_NM>" + "</INVT_NM>");
  142. soapRequestData.Append(itemRow["INVT_CD"] != null ? "<INVT_CD>" + itemRow["INVT_CD"].ToString() + "</INVT_CD>" : "<INVT_CD>" + "</INVT_CD>");
  143. soapRequestData.Append(itemRow["BSC_QTY"] != null ? "<BSC_QTY>" + itemRow["BSC_QTY"].ToString() + "</BSC_QTY>" : "<BSC_QTY>" + "</BSC_QTY>");
  144. soapRequestData.Append(itemRow["BSC_AMT"] != null ? "<BSC_AMT>" + itemRow["BSC_AMT"].ToString() + "</BSC_AMT>" : "<BSC_AMT>" + "</BSC_AMT>");
  145. soapRequestData.Append(itemRow["PCHS_QTY"] != null ? "<PCHS_QTY>" + itemRow["PCHS_QTY"].ToString() + "</PCHS_QTY>" : "<PCHS_QTY>" + "</PCHS_QTY>");
  146. soapRequestData.Append(itemRow["PCHS_AMT"] != null ? "<PCHS_AMT>" + itemRow["PCHS_AMT"].ToString() + "</PCHS_AMT>" : "<PCHS_AMT>" + "</PCHS_AMT>");
  147. soapRequestData.Append(itemRow["ESTM_QTY"] != null ? "<ESTM_QTY>" + itemRow["ESTM_QTY"].ToString() + "</ESTM_QTY>" : "<ESTM_QTY>" + "</ESTM_QTY>");
  148. soapRequestData.Append(itemRow["ESTM_AMT"] != null ? "<ESTM_AMT>" + itemRow["ESTM_AMT"].ToString() + "</ESTM_AMT>" : "<ESTM_AMT>" + "</ESTM_AMT>");
  149. soapRequestData.Append(itemRow["ETC_WHG_QTY"] != null ? "<ETC_WHG_QTY>" + itemRow["ETC_WHG_QTY"].ToString() + "</ETC_WHG_QTY>" : "<ETC_WHG_QTY>" + "</ETC_WHG_QTY>");
  150. soapRequestData.Append(itemRow["ETC_WHG_AMT"] != null ? "<ETC_WHG_AMT>" + itemRow["ETC_WHG_AMT"].ToString() + "</ETC_WHG_AMT>" : "<ETC_WHG_AMT>" + "</ETC_WHG_AMT>");
  151. soapRequestData.Append(itemRow["ETC_RLS_QTY"] != null ? "<ETC_RLS_QTY>" + itemRow["ETC_RLS_QTY"].ToString() + "</ETC_RLS_QTY>" : "<ETC_RLS_QTY>" + "</ETC_RLS_QTY>");
  152. soapRequestData.Append(itemRow["ETC_RLS_AMT"] != null ? "<ETC_RLS_AMT>" + itemRow["ETC_RLS_AMT"].ToString() + "</ETC_RLS_AMT>" : "<ETC_RLS_AMT>" + "</ETC_RLS_AMT>");
  153. soapRequestData.Append(itemRow["MOVE_QTY"] != null ? "<MOVE_QTY>" + itemRow["MOVE_QTY"].ToString() + "</MOVE_QTY>" : "<MOVE_QTY>" + "</MOVE_QTY>");
  154. soapRequestData.Append(itemRow["MOVE_AMT"] != null ? "<MOVE_AMT>" + itemRow["MOVE_AMT"].ToString() + "</MOVE_AMT>" : "<MOVE_AMT>" + "</MOVE_AMT>");
  155. soapRequestData.Append(itemRow["SL_QTY"] != null ? "<SL_QTY>" + itemRow["SL_QTY"].ToString() + "</SL_QTY>" : "<SL_QTY>" + "</SL_QTY>");
  156. soapRequestData.Append(itemRow["SL_RVN"] != null ? "<SL_RVN>" + itemRow["SL_RVN"].ToString() + "</SL_RVN>" : "<SL_RVN>" + "</SL_RVN>");
  157. soapRequestData.Append(itemRow["SL_AMT"] != null ? "<SL_AMT>" + itemRow["SL_AMT"].ToString() + "</SL_AMT>" : "<SL_AMT>" + "</SL_AMT>");
  158. soapRequestData.Append(itemRow["FRTX_AVRG_PRC"] != null ? "<FRTX_AVRG_PRC>" + itemRow["FRTX_AVRG_PRC"].ToString() + "</FRTX_AVRG_PRC>" : "<FRTX_AVRG_PRC>" + "</FRTX_AVRG_PRC>");
  159. soapRequestData.Append(itemRow["SMTX_AVRG_PRC"] != null ? "<SMTX_AVRG_PRC>" + itemRow["SMTX_AVRG_PRC"].ToString() + "</SMTX_AVRG_PRC>" : "<SMTX_AVRG_PRC>" + "</SMTX_AVRG_PRC>");
  160. soapRequestData.Append(itemRow["RLS_QTY"] != null ? "<RLS_QTY>" + itemRow["RLS_QTY"].ToString() + "</RLS_QTY>" : "<RLS_QTY>" + "</RLS_QTY>");
  161. soapRequestData.Append(itemRow["SL_COST"] != null ? "<SL_COST>" + itemRow["SL_COST"].ToString() + "</SL_COST>" : "<SL_COST>" + "</SL_COST>");
  162. soapRequestData.Append(itemRow["SLS_TOT_GAIN"] != null ? "<SLS_TOT_GAIN>" + itemRow["SLS_TOT_GAIN"].ToString() + "</SLS_TOT_GAIN>" : "<SLS_TOT_GAIN>" + "</SLS_TOT_GAIN>");
  163. soapRequestData.Append(itemRow["SLS_TOT_PRTO"] != null ? "<SLS_TOT_PRTO>" + itemRow["SLS_TOT_PRTO"].ToString() + "</SLS_TOT_PRTO>" : "<SLS_TOT_PRTO>" + "</SLS_TOT_PRTO>");
  164. soapRequestData.Append(itemRow["TE_QTY"] != null ? "<TE_QTY>" + itemRow["TE_QTY"].ToString() + "</TE_QTY>" : "<TE_QTY>" + "</TE_QTY>");
  165. soapRequestData.Append(itemRow["TE_AMT"] != null ? "<TE_AMT>" + itemRow["TE_AMT"].ToString() + "</TE_AMT>" : "<TE_AMT>" + "</TE_AMT>");
  166. soapRequestData.Append("</INVT_DATA>");
  167. //原循环部分 end
  168. }
  169. soapRequestData.Append("</yerp:YERP_001_OA1_MT>");
  170. soapRequestData.Append("</soapenv:Body>");
  171. soapRequestData.Append("</soapenv:Envelope>");
  172. string postData = soapRequestData.ToString();
  173. log.Info("YERP_001 xmlRequest:" + postData);
  174. string statusCode;
  175. string resultContent;
  176. ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;
  177. RestOpHelper rop = new RestOpHelper();
  178. rop.Clientp12path = @"C:\Users\Administrator\Desktop\yonyou-cert\wildcard.pfx";
  179. rop.Clientp12PassWord = "Yonyou2024!";
  180. rop.Url = @"https://yerp-proxy-sap-prod.skchemicals.com/XISOAPAdapter/MessageServlet?senderParty=&senderService=YERP_P&receiverParty=&receiverService=&interface=YERP_001_OA1_SI&interfaceNamespace=http://skch.com/YERP_001_INVENTORY_DATA";
  181. rop.RequestSAP(rop.Url, 10000, postData, "IF_YERP", "Kfiw282082", out statusCode, out resultContent);
  182. log.Info("YERP_001 statusCode:" + statusCode + "\r\n" + "resultContent:" + resultContent);
  183. }
  184. }
  185. catch (Exception ex)
  186. {
  187. log.Error(ex.ToString());
  188. }
  189. }
  190. public static Configuration GetConfig()
  191. {
  192. Assembly assembly = Assembly.GetCallingAssembly();
  193. string path = string.Format("{0}.config", assembly.Location);
  194. if (!File.Exists(path))
  195. {
  196. throw new FileNotFoundException(path + "路径下的文件未找到!");
  197. }
  198. try
  199. {
  200. ExeConfigurationFileMap configFile = new ExeConfigurationFileMap();
  201. configFile.ExeConfigFilename = path;
  202. Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFile, ConfigurationUserLevel.None);
  203. return config;
  204. }
  205. catch (Exception)
  206. {
  207. throw;
  208. }
  209. }
  210. }
  211. }