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.

252 lines
13 KiB

2 weeks ago
2 days ago
2 weeks ago
2 days ago
2 weeks ago
2 days ago
2 weeks 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_007_gz : 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.GetConfigString("SysConnectionString_gz");
  45. if (string.IsNullOrEmpty(conStr))
  46. {
  47. log.Info("YERP_006 conStr未找到。");
  48. return;
  49. }
  50. //<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:yerp="http://skch.com/YERP_007_TAX_FOR_FIN_EXPENSE">
  51. // <soapenv:Header/>
  52. // <soapenv:Body>
  53. // <yerp:YERP_007_OA1_MT>
  54. // <!--1 or more repetitions:-->
  55. // <FIN_CST_SPTDOC>
  56. // <YYYY>?</YYYY>
  57. // <MM>1</MM>
  58. // <DD>?</DD>
  59. // <SPTDOC>?</SPTDOC>
  60. // <SMR>?</SMR>
  61. // <DBTO>?</DBTO>
  62. // <CRDTO>?</CRDTO>
  63. // <DBTO_CRDTO_DVSN>?</DBTO_CRDTO_DVSN>
  64. // <BLNC>?</BLNC>
  65. // <!--Optional:-->
  66. // <DBTO_CMSN>?</DBTO_CMSN>
  67. // <!--Optional:-->
  68. // <DBTO_IENS>?</DBTO_IENS>
  69. // <!--Optional:-->
  70. // <DBTO_XCH_PC>?</DBTO_XCH_PC>
  71. // </FIN_CST_SPTDOC>
  72. // </yerp:YERP_007_OA1_MT>
  73. // </soapenv:Body>
  74. //</soapenv:Envelope>
  75. // 过滤时间为上个月
  76. string Date = Dates.ToString("yyyy");
  77. string beginMuoth = Dates.AddMonths(-1).ToString("MM");
  78. string endMuoth = Dates.ToString("MM");
  79. var beginPeriod = "200001";//Date + beginMuoth
  80. var endPeriod = "206001";//Date + endMuoth
  81. string sqlsgz = @"
  82. begin transaction
  83. exec GL_Ledger @tblname=N'cwfymxz',@KmCode=N'5603',@beginPeriod='{0}',@endPeriod='{1}',@bVouch=0,@bequal=1,@sum=0,@bMJ=1,@swhere=N'',@sAuth=N'',@ReportID=N'GL13',@ReportType=0,@iUnite=0
  84. --select * from tempdb..cwfymxz
  85. select autoid,a.iyear YYYY,imonth MM,iday DD,csign_no SPTDOC,cDigest SMR,cDCode ODR_ACC,a.md DBTO_AMT,a.mc CRDTO_AMT,tmpme tmpme,b.cbegind_c
  86. into #test
  87. from tempdb..cwfymxz a
  88. join GL_accsum b on a.cCode = b.ccode and a.iyear = b.iyear and b.iperiod=1
  89. select SPTDOC,YYYY,MM,DD,sum(DBTO_AMT) DBTO_AMT,sum(CRDTO_AMT) CRDTO_AMT,sum(isnull(tmpme,0)) tmpme,cbegind_c
  90. into #test2
  91. from #test a
  92. where SPTDOC is not null and DD IS NOT NULL
  93. group by SPTDOC,YYYY,MM,DD,cbegind_c
  94. order by SPTDOC
  95. update a set DBTO_AMT=b.DBTO_AMT,a.CRDTO_AMT=b.CRDTO_AMT,a.tmpme=b.tmpme from #test a
  96. left join #test2 b on a.SPTDOC=b.SPTDOC and a.MM=b.MM and a.DD=b.DD
  97. where a.sptdoc is not null
  98. select autoid,sptdoc,YYYY,MM,DD into #test3 from #test where sptdoc is not null
  99. select s.* into #test4 from (select *,ROW_NUMBER() over (partition by sptdoc+CAST(MM AS VARCHAR(255))+CAST(DD AS VARCHAR(255)) order by autoid) as group_idx from #test3)s where s.group_idx>1
  100. delete a from #test a
  101. left join #test4 b on a.autoid=b.autoid
  102. where b.autoid is not null
  103. select *,(case when (Select Sum(-tmpme) from #test where autoid<=a.autoid) =0 then '平' else (case when (Select Sum(-tmpme) from #test where autoid<=a.autoid) >0 then '贷' else '借' end) end) INVT,
  104. (case when (Select Sum(-tmpme) from #test where autoid<=a.autoid)<0 then -(Select Sum(-tmpme) from #test where autoid<=a.autoid) else (Select Sum(-tmpme) from #test where autoid<=a.autoid) end) BLNC
  105. into #test5
  106. from #test a
  107. select cCode SBJ_CD,ccode_name SBJ_NM,imonth,iday,csign_no SPTDOC,sum(md) DBTO_AMT
  108. into #test6
  109. from tempdb..cwfymxz a
  110. where csign_no is not null
  111. group by ccode_name,csign_no,cCode,imonth,iday
  112. order by csign_no,imonth,iday
  113. select DISTINCT sptdoc,imonth,iday into #test7 from #test6
  114. select *,ROW_NUMBER() over (order by sptdoc,imonth,iday) rownumber into #test8 from #test7
  115. declare @k int
  116. set @k=1
  117. while @k<=(select COUNT(*) from #test7)
  118. begin
  119. declare @i int
  120. set @i=0
  121. while @i<1
  122. begin
  123. insert into #test6 (SBJ_CD,SBJ_NM,imonth,iday,SPTDOC,DBTO_AMT)
  124. select a.ccode,a.ccode_name,(select imonth from #test8 where rownumber=@k),(select iday from #test8 where rownumber=@k),(select SPTDOC from #test8 where rownumber=@k),0
  125. from code a left join #test6 b on b.SPTDOC=(select SPTDOC from #test8 where rownumber=@k) and imonth=(select imonth from #test8 where rownumber=@k) and iday=(select iday from #test8 where rownumber=@k) and SBJ_NM=ccode_name
  126. where a.iYear=2024 and ( bclose=0 and ( ccode like N'6603%' or ccode_name like N'6603%' or ccode_engl like N'6603%' or chelp like N'6603%' )) and ccode <>'6603' and len(ccode)=6
  127. and b.SPTDOC is null
  128. set @i=@i +1
  129. end
  130. set @k=@k +1
  131. end
  132. SELECT
  133. SPTDOC,imonth,iday,
  134. SUM(CASE WHEN SBJ_CD = '660301' THEN DBTO_AMT ELSE 0 END) DBTO_CMSN,
  135. SUM(CASE WHEN SBJ_CD = '660302' THEN DBTO_AMT ELSE 0 END) DBTO_IENS,
  136. SUM(CASE WHEN SBJ_CD = '660303' THEN DBTO_AMT ELSE 0 END) DBTO_XCH_PC
  137. into #test9
  138. FROM
  139. #test6
  140. GROUP BY
  141. SPTDOC,imonth,iday
  142. select YYYY,MM,DD,A.SPTDOC,SMR,DBTO_AMT DBTO,CRDTO_AMT CRDTO,INVT,BLNC,DBTO_CMSN,DBTO_IENS,DBTO_XCH_PC,'' DBTO_CRDTO_DVSN,cbegind_c
  143. from #test5 a left join #test9 b on a.SPTDOC=b.SPTDOC and a.MM=b.imonth and a.DD=b.iday order by MM
  144. rollback transaction";//and dInvCreateDatetime > '{0}' and dInvCreateDatetime < '{1}'
  145. sqlsgz = string.Format(sqlsgz, beginPeriod, endPeriod);
  146. log.Info("YERP_007_gz sql:" + sqlsgz);
  147. DataTable vbsgzdt = ICSHelper.ExecuteTable(conStr, sqlsgz);
  148. log.Info("YERP_007_gz sql结果数量" + vbsgzdt.Rows.Count);
  149. if (vbsgzdt.Rows.Count > 0)
  150. {
  151. StringBuilder soapRequestData = new StringBuilder();
  152. soapRequestData.Append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:yerp=\"http://skch.com/YERP_007_TAX_FOR_FIN_EXPENSE\">");
  153. soapRequestData.Append("<soapenv:Header/>");
  154. soapRequestData.Append("<soapenv:Body>");
  155. soapRequestData.Append("<yerp:YERP_007_OA1_MT>");
  156. //循环数据 DBTO_CRDTO_DVSN
  157. foreach (DataRow itemRow in vbsgzdt.Rows)
  158. {
  159. soapRequestData.Append("<!--Zero or more repetitions: -->");
  160. soapRequestData.Append("<FIN_CST_SPTDOC>");
  161. soapRequestData.Append(itemRow["YYYY"] != null ? "<YYYY>" + itemRow["YYYY"].ToString() + "</YYYY>" : "<YYYY>" + "</YYYY>");
  162. soapRequestData.Append(itemRow["MM"] != null ? "<MM>" + itemRow["MM"].ToString() + "</MM>" : "<MM>" + "</MM>");
  163. soapRequestData.Append(itemRow["DD"] != null ? "<DD>" + itemRow["DD"].ToString() + "</DD>" : "<DD>" + "</DD>");
  164. soapRequestData.Append(itemRow["SPTDOC"] != null ? "<SPTDOC>" + itemRow["SPTDOC"].ToString() + "</SPTDOC>" : "<SPTDOC>" + "</SPTDOC>");
  165. soapRequestData.Append(itemRow["SMR"] != null ? "<SMR>" + itemRow["SMR"].ToString() + "</SMR>" : "<SMR>" + "</SMR>");
  166. soapRequestData.Append(itemRow["DBTO"] != null ? "<DBTO>" + itemRow["DBTO"].ToString() + "</DBTO>" : "<DBTO>" + "</DBTO>");
  167. soapRequestData.Append(itemRow["CRDTO"] != null ? "<CRDTO>" + itemRow["CRDTO"].ToString() + "</CRDTO>" : "<CRDTO>" + "</CRDTO>");
  168. soapRequestData.Append(itemRow["DBTO_CRDTO_DVSN"] != null ? "<DBTO_CRDTO_DVSN>" + itemRow["DBTO_CRDTO_DVSN"].ToString() + "</DBTO_CRDTO_DVSN>" : "<DBTO_CRDTO_DVSN>" + "</DBTO_CRDTO_DVSN>");
  169. soapRequestData.Append(itemRow["BLNC"] != null ? "<BLNC>" + itemRow["BLNC"].ToString() + "</BLNC>" : "<BLNC>" + "</BLNC>");
  170. soapRequestData.Append(itemRow["DBTO_CMSN"] != null ? "<DBTO_CMSN>" + itemRow["DBTO_CMSN"].ToString() + "</DBTO_CMSN>" : "<DBTO_CMSN>" + "</DBTO_CMSN>");
  171. soapRequestData.Append(itemRow["DBTO_IENS"] != null ? "<DBTO_IENS>" + itemRow["DBTO_IENS"].ToString() + "</DBTO_IENS>" : "<DBTO_IENS>" + "</DBTO_IENS>");
  172. soapRequestData.Append(itemRow["DBTO_XCH_PC"] != null ? "<DBTO_XCH_PC>" + itemRow["DBTO_XCH_PC"].ToString() + "</DBTO_XCH_PC>" : "<DBTO_XCH_PC>" + "</DBTO_XCH_PC>");
  173. soapRequestData.Append("</FIN_CST_SPTDOC>");
  174. }
  175. soapRequestData.Append("</yerp:YERP_007_OA1_MT>");
  176. soapRequestData.Append("</soapenv:Body>");
  177. soapRequestData.Append("</soapenv:Envelope>");
  178. string postData = soapRequestData.ToString();
  179. log.Info("YERP_007 xmlRequest:" + postData);
  180. string statusCode;
  181. string resultContent;
  182. ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;
  183. RestOpHelper rop = new RestOpHelper();
  184. rop.Clientp12path = @"C:\Users\Administrator\Desktop\yonyou-cert\wildcard.pfx";
  185. rop.Clientp12PassWord = "Yonyou2024!";
  186. rop.Url = @"https://yerp-proxy-sap-dev.skchemicals.com/XISOAPAdapter/MessageServlet?senderParty=&senderService=YERP_D&receiverParty=&receiverService=&interface=YERP_007_OA1_SI&interfaceNamespace=http://skch.com/YERP_007_TAX_FOR_FIN_EXPENSE";
  187. rop.RequestSAP(rop.Url, 10000, postData, "IF_YERP", "Xtxc355860", out statusCode, out resultContent);
  188. log.Info("YERP_007 statusCode:" + statusCode + "\r\n" + "resultContent:" + resultContent);
  189. }
  190. }
  191. catch (Exception ex)
  192. {
  193. log.Error(ex.ToString());
  194. }
  195. }
  196. public static Configuration GetConfig()
  197. {
  198. Assembly assembly = Assembly.GetCallingAssembly();
  199. string path = string.Format("{0}.config", assembly.Location);
  200. if (!File.Exists(path))
  201. {
  202. throw new FileNotFoundException(path + "路径下的文件未找到!");
  203. }
  204. try
  205. {
  206. ExeConfigurationFileMap configFile = new ExeConfigurationFileMap();
  207. configFile.ExeConfigFilename = path;
  208. Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFile, ConfigurationUserLevel.None);
  209. return config;
  210. }
  211. catch (Exception)
  212. {
  213. throw;
  214. }
  215. }
  216. }
  217. }