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.

214 lines
12 KiB

  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. // < !--1 or more repetitions: -->
  99. // < TAX_SURTAX >
  100. // < SBJ_CD > 6403 </ SBJ_CD >
  101. // < SBJ_NM > 营业税金及附加 </ SBJ_NM >
  102. // < !--Optional : -->
  103. // < YYYY > 2024 </ YYYY >
  104. // < !--Optional : -->
  105. // < MM > 7 </ MM >
  106. // < !--Optional : -->
  107. // < SMR > 期初余额 </ SMR >
  108. // < !--Optional : -->
  109. // < DBTO_CRDTO_DVSN > 平 </ DBTO_CRDTO_DVSN >
  110. // < !--Optional : -->
  111. // < BLNC > 0.00000000 </ BLNC >
  112. // </ TAX_SURTAX >
  113. // </ yerp : YERP_005_OA1_MT >
  114. // </ soapenv : Body >
  115. // </ soapenv : Envelope >
  116. // 202404
  117. // 过滤时间为上个月
  118. string Date = Dates.ToString("yyyy");
  119. string beginMuoth = Dates.AddMonths(-1).ToString("MM");
  120. string endMuoth = Dates.ToString("MM");
  121. string Day = Dates.ToString("dd");
  122. var beginPeriod =Date + beginMuoth;// "200001";
  123. var endPeriod = Date + endMuoth;
  124. string sqls = @"begin transaction
  125. 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
  126. select 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,
  127. (Select Sum(tmpme) from tempdb..yysjmxz where autoid<=a.autoid) BLNC from tempdb..yysjmxz a
  128. rollback transaction";
  129. sqls = string.Format(sqls, beginPeriod, endPeriod);
  130. log.Info("YERP_005 sql:" + sqls);
  131. DataTable vbsdt = ICSHelper.ExecuteTable(conStr, sqls);
  132. log.Info("sql结果数量"+vbsdt.Rows.Count);
  133. if (vbsdt.Rows.Count > 0)
  134. {
  135. StringBuilder soapRequestData = new StringBuilder();
  136. soapRequestData.Append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:yerp=\"http://skch.com/YERP_005_TAX_VAT\">");
  137. soapRequestData.Append("<soapenv:Header/>");
  138. soapRequestData.Append("<soapenv:Body>");
  139. soapRequestData.Append("<yerp:YERP_005_OA1_MT>");
  140. //循环数据
  141. foreach (DataRow itemRow in vbsdt.Rows)
  142. {
  143. //原循环部分 begin
  144. soapRequestData.Append("<TAX_SURTAX>");
  145. soapRequestData.Append(itemRow["SBJ_CD"] != null ? "<SBJ_CD>" + itemRow["SBJ_CD"].ToString() + "</SBJ_CD>" : "<SBJ_CD>" + "</SBJ_CD>");
  146. soapRequestData.Append(itemRow["SBJ_NM"] != null ? "<SBJ_NM>" + itemRow["SBJ_NM"].ToString() + "</SBJ_NM>" : "<SBJ_NM>" + "</SBJ_NM>");
  147. soapRequestData.Append(itemRow["YYYY"] != null ? "<YYYY>" + itemRow["YYYY"].ToString() + "</YYYY>" : "<YYYY>" + "</YYYY>");
  148. soapRequestData.Append(itemRow["MM"] != null ? "<MM>" + itemRow["MM"].ToString() + "</MM>" : "<MM>" + "</MM>");
  149. soapRequestData.Append(itemRow["DD"] != null ? "<DD>" + itemRow["DD"].ToString() + "</DD>" : "<DD>" + "</DD>");
  150. soapRequestData.Append(itemRow["SPTDOC"] != null ? "<SPTDOC>" + itemRow["SPTDOC"].ToString() + "</SPTDOC>" : "<SPTDOC>" + "</SPTDOC>");
  151. soapRequestData.Append(itemRow["SMR"] != null ? "<SMR>" + itemRow["SMR"].ToString() + "</SMR>" : "<SMR>" + "</SMR>");
  152. soapRequestData.Append(itemRow["ODR_ACC"] != null ? "<ODR_ACC>" + itemRow["ODR_ACC"].ToString() + "</ODR_ACC>" : "<ODR_ACC>" + "</ODR_ACC>");
  153. soapRequestData.Append(itemRow["DBTO_AMT"] != null ? "<DBTO_AMT>" + itemRow["DBTO_AMT"].ToString() + "</DBTO_AMT>" : "<DBTO_AMT>" + "</DBTO_AMT>");
  154. soapRequestData.Append(itemRow["CRDTO_AMT"] != null ? "<CRDTO_AMT>" + itemRow["CRDTO_AMT"].ToString() + "</CRDTO_AMT>" : "<CRDTO_AMT>" + "</CRDTO_AMT>");
  155. soapRequestData.Append(itemRow["DBTO_CRDTO_DVSN"] != null ? "<DBTO_CRDTO_DVSN>" + itemRow["DBTO_CRDTO_DVSN"].ToString() + "</DBTO_CRDTO_DVSN>" : "<DBTO_CRDTO_DVSN>" + "</DBTO_CRDTO_DVSN>");
  156. soapRequestData.Append(itemRow["BLNC"] != null ? "<BLNC>" + itemRow["BLNC"].ToString() + "</BLNC>" : "<BLNC>" + "</BLNC>");
  157. soapRequestData.Append("</TAX_SURTAX>");
  158. //原循环部分 end
  159. }
  160. soapRequestData.Append("</yerp:YERP_005_OA1_MT>");
  161. soapRequestData.Append("</soapenv:Body>");
  162. soapRequestData.Append("</soapenv:Envelope>");
  163. string postData = soapRequestData.ToString();
  164. log.Info("YERP_005 xmlRequest:" + postData);
  165. string statusCode;
  166. string resultContent;
  167. ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;
  168. RestOpHelper rop = new RestOpHelper();
  169. rop.Clientp12path = @"C:\Users\Administrator\Desktop\yonyou-cert\wildcard.pfx";
  170. rop.Clientp12PassWord = "Yonyou2024!";
  171. rop.Url = @"https://yerp-proxy-sap-dev.skchemicals.com/XISOAPAdapter/MessageServlet?senderParty=&senderService=YERP_D&receiverParty=&receiverService=&interface=YERP_005_OA1_SI&interfaceNamespace=http://skch.com/YERP_005_TAX_VAT";
  172. rop.RequestSAP(rop.Url, 10000, postData, "IF_YERP", "Xtxc355860", out statusCode, out resultContent);
  173. log.Info("YERP_005 statusCode:" + statusCode + "\r\n" + "resultContent:" + resultContent);
  174. }
  175. }
  176. catch (Exception ex)
  177. {
  178. log.Error(ex.ToString());
  179. }
  180. }
  181. public static Configuration GetConfig()
  182. {
  183. Assembly assembly = Assembly.GetCallingAssembly();
  184. string path = string.Format("{0}.config", assembly.Location);
  185. if (!File.Exists(path))
  186. {
  187. throw new FileNotFoundException(path + "路径下的文件未找到!");
  188. }
  189. try
  190. {
  191. ExeConfigurationFileMap configFile = new ExeConfigurationFileMap();
  192. configFile.ExeConfigFilename = path;
  193. Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFile, ConfigurationUserLevel.None);
  194. return config;
  195. }
  196. catch (Exception)
  197. {
  198. throw;
  199. }
  200. }
  201. }
  202. }