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.

218 lines
12 KiB

2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
  1. using Quartz;
  2. using Quartz.Xml.JobSchedulingData20;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Configuration;
  6. using System.Data;
  7. using System.Data.Linq.Mapping;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Net;
  11. using System.Reflection;
  12. using System.Runtime.Remoting.Messaging;
  13. using System.Text;
  14. using System.Text.RegularExpressions;
  15. using System.Threading.Tasks;
  16. using System.Web.UI;
  17. using System.Xml.Linq;
  18. using System.Xml.Serialization;
  19. namespace ICSSoft.FromERP
  20. {
  21. /// <summary>
  22. /// 营业务税金及附加明细账
  23. /// </summary>
  24. public class YERP_005 : IJob
  25. {
  26. private static object key = new object();
  27. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  28. public void Execute(IJobExecutionContext context)
  29. {
  30. try
  31. {
  32. lock (key)
  33. {
  34. log.Info("开始……………………………………………………………………");
  35. Execute();
  36. log.Info("结束……………………………………………………………………");
  37. }
  38. }
  39. catch (Exception ex)
  40. {
  41. log.Error(ex.ToString());
  42. }
  43. }
  44. public async void Execute()
  45. {
  46. try
  47. {
  48. Configuration config = GetConfig();
  49. //string url = config.ConnectionStrings.ConnectionStrings["APIAddStdWorkHour"].ConnectionString.ToString();
  50. var Dates = DateTime.Now;
  51. //log.Info("获取创建定额工时接口 " + url);
  52. //if (string.IsNullOrEmpty(url))
  53. //{
  54. // return;
  55. //}
  56. string conStr = ICSHelper.GetConnectString();
  57. //PdfDocument doc = new PdfDocument();
  58. //doc.LoadFromFile(@"C:\Users\andyxin\Desktop\日常文档\TS3400series_5200.pdf");//选择Microsoft XPS Document Writer打印机
  59. //doc.PrintSettings.PrinterName = "Canon TS3400 series";//打印PDF文档到XPS格式
  60. ////doc.PrintSettings.PrintToFile(filename + ".pdf");
  61. //doc.Print();
  62. ////log.Info("打印成功: " + path);
  63. //Dictionary<string, string> dParam = new Dictionary<string, string>();
  64. //dParam.Add("RCARD", "123456");
  65. //dParam.Add("INVSTD", "654321");
  66. //dParam.Add("DEFINE", "测试OK");
  67. //BTPrint(@"D:\汇川27x7mm2排1.btw", "Microsoft Print to PDF", dParam);
  68. //string aa = " < soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns: yerp = \"http://skch.com/YERP_005_TAX_VAT\" > " + @"
  69. // < soapenv:Header />
  70. // < soapenv:Body >
  71. // < yerp:YERP_005_OA1_MT >
  72. // < !--1 or more repetitions: -->
  73. // < TAX_SURTAX >
  74. // < SBJ_CD > 1 </ SBJ_CD >
  75. // < SBJ_NM > 1 </ SBJ_NM >
  76. // < YYYY >?</ YYYY >
  77. // < MM >?</ MM >
  78. // < DD >?</ DD >
  79. // < SPTDOC >?</ SPTDOC >
  80. // < SMR >?</ SMR >
  81. // < ODR_ACC >?</ ODR_ACC >
  82. // < !--Optional : -->
  83. // < DBTO_AMT >?</ DBTO_AMT >
  84. // < !--Optional : -->
  85. // < CRDTO_AMT >?</ CRDTO_AMT >
  86. // < !--Optional : -->
  87. // < DBTO_CRDTO_DVSN ></ DBTO_CRDTO_DVSN >
  88. // < !--Optional : -->
  89. // < BLNC >?</ BLNC >
  90. // </ TAX_SURTAX >
  91. // </ yerp : YERP_005_OA1_MT >
  92. // </ soapenv : Body >
  93. // </ soapenv : Envelope >";
  94. //<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:yerp="http://skch.com/YERP_005_TAX_VAT">
  95. // <soapenv:Header/>
  96. // <soapenv:Body>
  97. // <yerp:YERP_005_OA1_MT>
  98. // <TAX_SURTAX>
  99. // <Created_Year>?</Created_Year>
  100. // <Created_Month>?</Created_Month>
  101. // <SBJ_CD>?</SBJ_CD>
  102. // <SBJ_NM>?</SBJ_NM>
  103. // <YYYY>?</YYYY>
  104. // <MM>?</MM>
  105. // <DD>?</DD>
  106. // <SPTDOC>?</SPTDOC>
  107. // <SMR>?</SMR>
  108. // <ODR_ACC>?</ODR_ACC>
  109. // <DBTO_AMT>?</DBTO_AMT>
  110. // <CRDTO_AMT>?</CRDTO_AMT>
  111. // <DBTO_CRDTO_DVSN>?</DBTO_CRDTO_DVSN>
  112. // <BLNC>?</BLNC>
  113. // </TAX_SURTAX>
  114. // </yerp:YERP_005_OA1_MT>
  115. // </soapenv:Body>
  116. //</soapenv:Envelope>
  117. // 202404
  118. // 过滤时间为上个月
  119. string Date = Dates.ToString("yyyy");
  120. string beginMuoth = Dates.AddMonths(-1).ToString("MM");
  121. //string endMuoth = Dates.ToString("MM");
  122. string Day = Dates.ToString("dd");
  123. var beginPeriod = Date + beginMuoth ; //Date + beginMuoth;// "200001";
  124. var endPeriod = Date + beginMuoth; //Date + endMuoth;
  125. string sqls = @"begin transaction
  126. exec GL_Ledger @tblname=N'yysjmxz',@KmCode=N'6403',@beginPeriod='{0}',@endPeriod='{1}',@bVouch=0,@bequal=1,@sum=0,@bMJ=1,@swhere=N'',@sAuth=N'',@ReportID=N'GL13',@ReportType=0,@iUnite=0
  127. select iyear Created_Year,imonth Created_Month,autoid,cCode SBJ_CD,ccode_name SBJ_NM,iyear YYYY,imonth MM,iday DD,csign_no SPTDOC,cDigest SMR,cDCode ODR_ACC,md DBTO_AMT,mc CRDTO_AMT,(case when ibook is null then '平' else (case when ibook ='1' then '贷' else '借' end) end) DBTO_CRDTO_DVSN,tmpme,
  128. (Select Sum(tmpme) from tempdb..yysjmxz where autoid<=a.autoid) BLNC from tempdb..yysjmxz a
  129. rollback transaction";
  130. sqls = string.Format(sqls, beginPeriod, endPeriod);
  131. log.Info("YERP_005 sql:" + sqls);
  132. DataTable vbsdt = ICSHelper.ExecuteTable(conStr, sqls);
  133. log.Info("sql结果数量"+vbsdt.Rows.Count);
  134. if (vbsdt.Rows.Count > 0)
  135. {
  136. StringBuilder soapRequestData = new StringBuilder();
  137. soapRequestData.Append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:yerp=\"http://skch.com/YERP_005_TAX_VAT\">");
  138. soapRequestData.Append("<soapenv:Header/>");
  139. soapRequestData.Append("<soapenv:Body>");
  140. soapRequestData.Append("<yerp:YERP_005_OA1_MT>");
  141. //循环数据
  142. foreach (DataRow itemRow in vbsdt.Rows)
  143. {
  144. //原循环部分 begin
  145. soapRequestData.Append("<TAX_SURTAX>");
  146. soapRequestData.Append(itemRow["Created_Year"] != null ? "<Created_Year>" + itemRow["Created_Year"].ToString() + "</Created_Year>" : "<Created_Year>" + "</Created_Year>");
  147. soapRequestData.Append(itemRow["Created_Month"] != null ? "<Created_Month>" + itemRow["Created_Month"].ToString() + "</Created_Month>" : "<Created_Month>" + "</Created_Month>");
  148. soapRequestData.Append(itemRow["SBJ_CD"] != null ? "<SBJ_CD>" + itemRow["SBJ_CD"].ToString() + "</SBJ_CD>" : "<SBJ_CD>" + "</SBJ_CD>");
  149. soapRequestData.Append(itemRow["SBJ_NM"] != null ? "<SBJ_NM>" + itemRow["SBJ_NM"].ToString() + "</SBJ_NM>" : "<SBJ_NM>" + "</SBJ_NM>");
  150. soapRequestData.Append(itemRow["YYYY"] != null ? "<YYYY>" + itemRow["YYYY"].ToString() + "</YYYY>" : "<YYYY>" + "</YYYY>");
  151. soapRequestData.Append(itemRow["MM"] != null ? "<MM>" + itemRow["MM"].ToString() + "</MM>" : "<MM>" + "</MM>");
  152. soapRequestData.Append(itemRow["DD"] != null ? "<DD>" + itemRow["DD"].ToString() + "</DD>" : "<DD>" + "</DD>");
  153. soapRequestData.Append(itemRow["SPTDOC"] != null ? "<SPTDOC>" + itemRow["SPTDOC"].ToString() + "</SPTDOC>" : "<SPTDOC>" + "</SPTDOC>");
  154. soapRequestData.Append(itemRow["SMR"] != null ? "<SMR>" + itemRow["SMR"].ToString() + "</SMR>" : "<SMR>" + "</SMR>");
  155. soapRequestData.Append(itemRow["ODR_ACC"] != null ? "<ODR_ACC>" + itemRow["ODR_ACC"].ToString() + "</ODR_ACC>" : "<ODR_ACC>" + "</ODR_ACC>");
  156. soapRequestData.Append(itemRow["DBTO_AMT"] != null ? "<DBTO_AMT>" + itemRow["DBTO_AMT"].ToString() + "</DBTO_AMT>" : "<DBTO_AMT>" + "</DBTO_AMT>");
  157. soapRequestData.Append(itemRow["CRDTO_AMT"] != null ? "<CRDTO_AMT>" + itemRow["CRDTO_AMT"].ToString() + "</CRDTO_AMT>" : "<CRDTO_AMT>" + "</CRDTO_AMT>");
  158. soapRequestData.Append(itemRow["DBTO_CRDTO_DVSN"] != null ? "<DBTO_CRDTO_DVSN>" + itemRow["DBTO_CRDTO_DVSN"].ToString() + "</DBTO_CRDTO_DVSN>" : "<DBTO_CRDTO_DVSN>" + "</DBTO_CRDTO_DVSN>");
  159. soapRequestData.Append(itemRow["BLNC"] != null ? "<BLNC>" + itemRow["BLNC"].ToString() + "</BLNC>" : "<BLNC>" + "</BLNC>");
  160. soapRequestData.Append("</TAX_SURTAX>");
  161. //原循环部分 end
  162. }
  163. soapRequestData.Append("</yerp:YERP_005_OA1_MT>");
  164. soapRequestData.Append("</soapenv:Body>");
  165. soapRequestData.Append("</soapenv:Envelope>");
  166. string postData = soapRequestData.ToString();
  167. log.Info("YERP_005 xmlRequest:" + postData);
  168. string statusCode;
  169. string resultContent;
  170. ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;
  171. RestOpHelper rop = new RestOpHelper();
  172. rop.Clientp12path = @"C:\Users\Administrator\Desktop\yonyou-cert\wildcard.pfx";
  173. rop.Clientp12PassWord = "Yonyou2024!";
  174. rop.Url = @"https://yerp-proxy-sap-prod.skchemicals.com/XISOAPAdapter/MessageServlet?senderParty=&senderService=YERP_P&receiverParty=&receiverService=&interface=YERP_005_OA1_SI&interfaceNamespace=http://skch.com/YERP_005_TAX_VAT";
  175. rop.RequestSAP(rop.Url, 10000, postData, "IF_YERP", "Kfiw282082", out statusCode, out resultContent);
  176. log.Info("YERP_005 statusCode:" + statusCode + "\r\n" + "resultContent:" + resultContent);
  177. }
  178. }
  179. catch (Exception ex)
  180. {
  181. log.Error(ex.ToString());
  182. }
  183. }
  184. public static Configuration GetConfig()
  185. {
  186. Assembly assembly = Assembly.GetCallingAssembly();
  187. string path = string.Format("{0}.config", assembly.Location);
  188. if (!File.Exists(path))
  189. {
  190. throw new FileNotFoundException(path + "路径下的文件未找到!");
  191. }
  192. try
  193. {
  194. ExeConfigurationFileMap configFile = new ExeConfigurationFileMap();
  195. configFile.ExeConfigFilename = path;
  196. Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFile, ConfigurationUserLevel.None);
  197. return config;
  198. }
  199. catch (Exception)
  200. {
  201. throw;
  202. }
  203. }
  204. }
  205. }