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.

501 lines
29 KiB

2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months 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.Threading.Tasks;
  12. namespace ICSSoft.FromERP
  13. {
  14. /// <summary>
  15. /// 管理费用明细账
  16. /// </summary>
  17. public class YERP_006_gz : IJob
  18. {
  19. private static object key = new object();
  20. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  21. public void Execute(IJobExecutionContext context)
  22. {
  23. try
  24. {
  25. lock (key)
  26. {
  27. log.Info("开始……………………………………………………………………");
  28. Execute();
  29. log.Info("结束……………………………………………………………………");
  30. }
  31. }
  32. catch (Exception ex)
  33. {
  34. log.Error(ex.ToString());
  35. }
  36. }
  37. public async void Execute()
  38. {
  39. try
  40. {
  41. Configuration config = GetConfig();
  42. //string url = config.ConnectionStrings.ConnectionStrings["APIAddStdWorkHour"].ConnectionString.ToString();
  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_006_MATN_COST">
  51. // <soapenv:Header/>
  52. // <soapenv:Body>
  53. // <yerp:YERP_006_OA1_MT>
  54. // <!--1 or more repetitions:-->
  55. // <MGMT_CST>
  56. // <YYYY>?</YYYY>
  57. // <MM>?</MM>
  58. // <DD>?</DD>
  59. // <SPTDOC_NO>?</SPTDOC_NO>
  60. // <SMR>?</SMR>
  61. // <DBTO>?</DBTO>
  62. // <CRDTO>?</CRDTO>
  63. // <DBTO_CRDTO_DVSN>?</DBTO_CRDTO_DVSN>
  64. // <BLNC>?</BLNC>
  65. // <!--Optional:-->
  66. // <OFC_OPRT_CST>?</OFC_OPRT_CST>
  67. // <!--Optional:-->
  68. // <BZTRP_CST>?</BZTRP_CST>
  69. // <!--Optional:-->
  70. // <TRSF_CST>?</TRSF_CST>
  71. // <!--Optional:-->
  72. // <BNFT_CST>?</BNFT_CST>
  73. // <!--Optional:-->
  74. // <NTTN_CST>?</NTTN_CST>
  75. // <!--Optional:-->
  76. // <SCLISRC>?</SCLISRC>
  77. // <!--Optional:-->
  78. // <DDTN>?</DDTN>
  79. // <!--Optional:-->
  80. // <NTRR_CST>?</NTRR_CST>
  81. // <!--Optional:-->
  82. // <VEHS_OPRT_CST>?</VEHS_OPRT_CST>
  83. // <!--Optional:-->
  84. // <SVC_CST>?</SVC_CST>
  85. // <!--Optional:-->
  86. // <VEHS_RNTL_CST>?</VEHS_RNTL_CST>
  87. // <!--Optional:-->
  88. // <OFC_RNTL_CST>?</OFC_RNTL_CST>
  89. // <!--Optional:-->
  90. // <PRPT_MGMT_CST>?</PRPT_MGMT_CST>
  91. // <!--Optional:-->
  92. // <WTNELCT_CST>?</WTNELCT_CST>
  93. // <!--Optional:-->
  94. // <NWK_CST>?</NWK_CST>
  95. // <!--Optional:-->
  96. // <TELE_CST>?</TELE_CST>
  97. // <!--Optional:-->
  98. // <MEET_CST>?</MEET_CST>
  99. // <!--Optional:-->
  100. // <PCL_CST>?</PCL_CST>
  101. // <!--Optional:-->
  102. // <PNCST>?</PNCST>
  103. // <!--Optional:-->
  104. // <CUN_CST>?</CUN_CST>
  105. // <!--Optional:-->
  106. // <DPRCT_CST>?</DPRCT_CST>
  107. // <!--Optional:-->
  108. // <EDU_CST>?</EDU_CST>
  109. // <!--Optional:-->
  110. // <RPR_CST>?</RPR_CST>
  111. // <!--Optional:-->
  112. // <LBPRTT_CST>?</LBPRTT_CST>
  113. // <!--Optional:-->
  114. // <BZ_PRMT_CST>?</BZ_PRMT_CST>
  115. // <!--Optional:-->
  116. // <TEST_CST>?</TEST_CST>
  117. // <!--Optional:-->
  118. // <BK_CST>?</BK_CST>
  119. // <!--Optional:-->
  120. // <RCRT_CST>?</RCRT_CST>
  121. // <!--Optional:-->
  122. // <XBT_CST>?</XBT_CST>
  123. // <!--Optional:-->
  124. // <RSNB_LOS>?</RSNB_LOS>
  125. // </MGMT_CST>
  126. // </yerp:YERP_006_OA1_MT>
  127. // </soapenv:Body>
  128. //</soapenv:Envelope>
  129. // 202404
  130. // 过滤时间为上个月
  131. string Date = Dates.ToString("yyyy");
  132. string beginMuoth = Dates.AddMonths(-1).ToString("MM");
  133. string endMuoth = Dates.ToString("MM");
  134. var beginPeriod = "200001";//Date + beginMuoth
  135. var endPeriod = "206001";//Date + endMuoth
  136. string sqlsgz04 = @"
  137. begin transaction
  138. exec GL_Ledger @tblname=N'zyywsrmxz',@KmCode=N'6601',@beginPeriod='{0}',@endPeriod='{1}',@bVouch=0,@bequal=1,@sum=0,@bMJ=1,@swhere=N'',@sAuth=N'',@ReportID=N'GL13',@ReportType=0,@iUnite=0
  139. select autoid,iyear YYYY,imonth MM,iday DD,csign_no SPTDOC,cDigest SMR,cDCode ODR_ACC,md DBTO_AMT,mc CRDTO_AMT,tmpme tmpme
  140. into #test from tempdb..zyywsrmxz a
  141. select YYYY,SPTDOC,MM,DD,sum(DBTO_AMT) DBTO_AMT,sum(CRDTO_AMT) CRDTO_AMT,sum(isnull(tmpme,0)) tmpme
  142. into #test2
  143. from #test a
  144. where SPTDOC is not null and DD IS NOT NULL
  145. group by SPTDOC,YYYY,MM,DD
  146. order by SPTDOC
  147. update a set DBTO_AMT=b.DBTO_AMT,a.CRDTO_AMT=b.CRDTO_AMT,a.tmpme=b.tmpme from #test a
  148. left join #test2 b on a.SPTDOC=b.SPTDOC and a.MM=b.MM and a.DD=b.DD
  149. where a.sptdoc is not null
  150. select autoid,sptdoc,YYYY,MM,DD into #test3 from #test where sptdoc is not null
  151. 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
  152. delete a from #test a
  153. left join #test4 b on a.autoid=b.autoid
  154. where b.autoid is not null
  155. 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,
  156. (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 into #test5 from #test a
  157. select cCode SBJ_CD,ccode_name SBJ_NM,imonth,iday,csign_no SPTDOC,sum(md) DBTO_AMT
  158. into #test6
  159. from tempdb..zyywsrmxz a
  160. where csign_no is not null
  161. group by ccode_name,csign_no,cCode,imonth,iday
  162. order by csign_no,imonth,iday
  163. select DISTINCT sptdoc,imonth,iday into #test7 from #test6
  164. select *,ROW_NUMBER() over (order by sptdoc,imonth,iday) rownumber into #test8 from #test7
  165. declare @k int
  166. set @k=1
  167. while @k<=(select COUNT(*) from #test7)
  168. begin
  169. declare @i int
  170. set @i=0
  171. while @i<1
  172. begin
  173. insert into #test6 (SBJ_CD,SBJ_NM,imonth,iday,SPTDOC,DBTO_AMT)
  174. 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
  175. 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
  176. where a.iYear=2024 and ( bclose=0 and ( ccode like N'6601%' or ccode_name like N'6601%' or ccode_engl like N'6601%' or chelp like N'6601%' )) and ccode <>'6601' and b.SPTDOC is null
  177. set @i=@i +1
  178. end
  179. set @k=@k +1
  180. end
  181. SELECT
  182. SPTDOC,imonth,iday,
  183. SUM(CASE WHEN SBJ_CD = '660101' THEN DBTO_AMT ELSE 0 END) WH_CST,
  184. SUM(CASE WHEN SBJ_CD = '660102' THEN DBTO_AMT ELSE 0 END) TRNSF_CST,
  185. SUM(CASE WHEN SBJ_CD = '660103' THEN DBTO_AMT ELSE 0 END) XBT_CST,
  186. SUM(CASE WHEN SBJ_CD = '660104' THEN DBTO_AMT ELSE 0 END) NLD_CST,
  187. SUM(CASE WHEN SBJ_CD = '660105' THEN DBTO_AMT ELSE 0 END) SMPL_CST,
  188. SUM(CASE WHEN SBJ_CD = '660106' THEN DBTO_AMT ELSE 0 END) TRNSF_AGNC_CST,
  189. SUM(CASE WHEN SBJ_CD = '660107' THEN DBTO_AMT ELSE 0 END) ADTV,
  190. SUM(CASE WHEN SBJ_CD = '660108' THEN DBTO_AMT ELSE 0 END) NCLSN_CST,
  191. SUM(CASE WHEN SBJ_CD = '660109' THEN DBTO_AMT ELSE 0 END) SVC_CST
  192. into #test9
  193. FROM
  194. #test6
  195. GROUP BY
  196. SPTDOC,imonth,iday
  197. select YYYY,MM,DD,A.SPTDOC as SPTDOC_NO,SMR,DBTO_AMT DBTO,CRDTO_AMT CRDTO,INVT,BLNC,WH_CST,TRNSF_CST,XBT_CST,NLD_CST,SMPL_CST,TRNSF_AGNC_CST,ADTV,NCLSN_CST,SVC_CST from #test5 a left join #test9 b on a.SPTDOC=b.SPTDOC and a.MM=b.imonth and a.DD=b.iday
  198. rollback transaction
  199. ";
  200. sqlsgz04 = string.Format(sqlsgz04, beginPeriod, endPeriod);
  201. log.Info("YERP_006_004查询 sql:" + sqlsgz04);
  202. DataTable vbsgz04dt = ICSHelper.ExecuteTable(conStr, sqlsgz04);
  203. log.Info("YERP_006_004查询 sql结果数量" + vbsgz04dt.Rows.Count);
  204. string sqlsgz = @"begin transaction
  205. exec GL_Ledger @tblname=N'glfymxz',@KmCode=N'5602',@beginPeriod='{0}',@endPeriod='{1}',@bVouch=0,@bequal=1,@sum=0,@bMJ=1,@swhere=N'',@sAuth=N'',@ReportID=N'GL13',@ReportType=0,@iUnite=0
  206. select autoid,iyear YYYY,imonth MM,iday DD,csign_no SPTDOC,cDigest SMR,cDCode ODR_ACC,md DBTO_AMT,mc CRDTO_AMT,tmpme tmpme
  207. into #test from tempdb..glfymxz a
  208. select SPTDOC,MM,DD,sum(DBTO_AMT) DBTO_AMT,sum(CRDTO_AMT) CRDTO_AMT,sum(isnull(tmpme,0)) tmpme
  209. into #test2
  210. from #test a
  211. where SPTDOC is not null and DD IS NOT NULL
  212. group by SPTDOC,MM,DD
  213. order by SPTDOC
  214. update a set DBTO_AMT=b.DBTO_AMT,a.CRDTO_AMT=b.CRDTO_AMT,a.tmpme=b.tmpme from #test a
  215. left join #test2 b on a.SPTDOC=b.SPTDOC and a.MM=b.MM and a.DD=b.DD
  216. where a.sptdoc is not null
  217. select autoid,sptdoc,YYYY,MM,DD into #test3 from #test where sptdoc is not null
  218. 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
  219. delete a from #test a
  220. left join #test4 b on a.autoid=b.autoid
  221. where b.autoid is not null
  222. 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,
  223. (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 into #test5 from #test a
  224. select cCode SBJ_CD,ccode_name SBJ_NM,imonth,iday,csign_no SPTDOC,sum(md) DBTO_AMT
  225. into #test6
  226. from tempdb..glfymxz a
  227. where csign_no is not null
  228. group by ccode_name,csign_no,cCode,imonth,iday
  229. order by csign_no,imonth,iday
  230. select DISTINCT sptdoc,imonth,iday into #test7 from #test6
  231. select *,ROW_NUMBER() over (order by sptdoc,imonth,iday) rownumber into #test8 from #test7
  232. declare @k int
  233. set @k=1
  234. while @k<=(select COUNT(*) from #test7)
  235. begin
  236. declare @i int
  237. set @i=0
  238. while @i<1
  239. begin
  240. insert into #test6 (SBJ_CD,SBJ_NM,imonth,iday,SPTDOC,DBTO_AMT)
  241. 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
  242. 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
  243. where a.iYear=2024 and ( bclose=0 and ( ccode like N'6602%' or ccode_name like N'6602%' or ccode_engl like N'6602%' or chelp like N'6602%' )) and ccode <>'6602' and len(ccode)=6
  244. and b.SPTDOC is null
  245. set @i=@i +1
  246. end
  247. set @k=@k +1
  248. end
  249. SELECT
  250. SPTDOC,imonth,iday,
  251. SUM(CASE WHEN SBJ_CD = '660201' THEN DBTO_AMT ELSE 0 END) OFC_OPRT_CST,
  252. SUM(CASE WHEN SBJ_CD = '660202' THEN DBTO_AMT ELSE 0 END) BZTRP_CST,
  253. SUM(CASE WHEN SBJ_CD = '660203' THEN DBTO_AMT ELSE 0 END) TRSF_CST,
  254. SUM(CASE WHEN SBJ_CD = '660204' THEN DBTO_AMT ELSE 0 END) BNFT_CST,
  255. SUM(CASE WHEN SBJ_CD = '660205' THEN DBTO_AMT ELSE 0 END) NTTN_CST,
  256. SUM(CASE WHEN SBJ_CD = '660206' THEN DBTO_AMT ELSE 0 END) SCLISRC,
  257. SUM(CASE WHEN SBJ_CD = '660207' THEN DBTO_AMT ELSE 0 END) DDTN,
  258. SUM(CASE WHEN SBJ_CD = '660208' THEN DBTO_AMT ELSE 0 END) NTRR_CST,
  259. SUM(CASE WHEN SBJ_CD = '660209' THEN DBTO_AMT ELSE 0 END) VEHS_OPRT_CST,
  260. SUM(CASE WHEN SBJ_CD = '660210' THEN DBTO_AMT ELSE 0 END) SVC_CST,
  261. SUM(CASE WHEN SBJ_CD = '660211' THEN DBTO_AMT ELSE 0 END) VEHS_RNTL_CST,
  262. SUM(CASE WHEN SBJ_CD = '660212' THEN DBTO_AMT ELSE 0 END) OFC_RNTL_CST,
  263. SUM(CASE WHEN SBJ_CD = '660213' THEN DBTO_AMT ELSE 0 END) PRPT_MGMT_CST,
  264. SUM(CASE WHEN SBJ_CD = '660214' THEN DBTO_AMT ELSE 0 END) WTNELCT_CST,
  265. SUM(CASE WHEN SBJ_CD = '660215' THEN DBTO_AMT ELSE 0 END) NWK_CST,
  266. SUM(CASE WHEN SBJ_CD = '660216' THEN DBTO_AMT ELSE 0 END) TELE_CST,
  267. SUM(CASE WHEN SBJ_CD = '660217' THEN DBTO_AMT ELSE 0 END) MEET_CST,
  268. SUM(CASE WHEN SBJ_CD = '660218' THEN DBTO_AMT ELSE 0 END) PCL_CST,
  269. SUM(CASE WHEN SBJ_CD = '660219' THEN DBTO_AMT ELSE 0 END) PNCST,
  270. SUM(CASE WHEN SBJ_CD = '660220' THEN DBTO_AMT ELSE 0 END) CUN_CST,
  271. SUM(CASE WHEN SBJ_CD = '660221' THEN DBTO_AMT ELSE 0 END) DPRCT_CST,
  272. SUM(CASE WHEN SBJ_CD = '660222' THEN DBTO_AMT ELSE 0 END) EDU_CST,
  273. SUM(CASE WHEN SBJ_CD = '660223' THEN DBTO_AMT ELSE 0 END) RPR_CST,
  274. SUM(CASE WHEN SBJ_CD = '660224' THEN DBTO_AMT ELSE 0 END) LBPRTT_CST,
  275. SUM(CASE WHEN SBJ_CD = '660225' THEN DBTO_AMT ELSE 0 END) BZ_PRMT_CST,
  276. SUM(CASE WHEN SBJ_CD = '660226' THEN DBTO_AMT ELSE 0 END) TEST_CST,
  277. SUM(CASE WHEN SBJ_CD = '660227' THEN DBTO_AMT ELSE 0 END) BK_CST,
  278. SUM(CASE WHEN SBJ_CD = '660228' THEN DBTO_AMT ELSE 0 END) RCRT_CST,
  279. SUM(CASE WHEN SBJ_CD = '660229' THEN DBTO_AMT ELSE 0 END) XBT_CST,
  280. SUM(CASE WHEN SBJ_CD = '660230' THEN DBTO_AMT ELSE 0 END) RSNB_LOS
  281. into #test9
  282. FROM
  283. #test6
  284. GROUP BY
  285. SPTDOC,imonth,iday
  286. select YYYY,MM,DD,A.SPTDOC as SPTDOC_NO,SMR,DBTO_AMT DBTO,CRDTO_AMT CRDTO,INVT as DBTO_CRDTO_DVSN,BLNC,OFC_OPRT_CST,BZTRP_CST,TRSF_CST,BNFT_CST,NTTN_CST,SCLISRC,DDTN,NTRR_CST,VEHS_OPRT_CST,SVC_CST,VEHS_RNTL_CST,
  287. OFC_RNTL_CST,PRPT_MGMT_CST,WTNELCT_CST,NWK_CST,TELE_CST,MEET_CST,PCL_CST,PNCST,CUN_CST,DPRCT_CST,EDU_CST,RPR_CST,LBPRTT_CST,BZ_PRMT_CST,TEST_CST,BK_CST,RCRT_CST,XBT_CST,RSNB_LOS
  288. 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
  289. rollback transaction
  290. ";
  291. sqlsgz = string.Format(sqlsgz, beginPeriod, endPeriod);
  292. log.Info("YERP_006_gz sql:" + sqlsgz);
  293. DataTable vbsdtgz = ICSHelper.ExecuteTable(conStr, sqlsgz);
  294. log.Info("YERP_006_gz sql结果数量" + vbsdtgz.Rows.Count);
  295. if (vbsdtgz.Rows.Count > 0)
  296. {
  297. var datarows = new List<TempDatas>();
  298. StringBuilder soapRequestData = new StringBuilder();
  299. soapRequestData.Append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:yerp=\"http://skch.com/YERP_006_MATN_COST\">");
  300. soapRequestData.Append("<soapenv:Header/>");
  301. soapRequestData.Append("<soapenv:Body>");
  302. soapRequestData.Append("<yerp:YERP_006_OA1_MT>");
  303. //循环数据
  304. foreach (DataRow itemRow in vbsdtgz.Rows)
  305. {
  306. //原循环部分 begin
  307. soapRequestData.Append("<MGMT_CST>");
  308. soapRequestData.Append(itemRow["YYYY"] != null ? "<YYYY>" + itemRow["YYYY"].ToString() + "</YYYY>" : "<YYYY>" + "</YYYY>");
  309. soapRequestData.Append(itemRow["MM"] != null ? "<MM>" + itemRow["MM"].ToString() + "</MM>" : "<MM>" + "</MM>");
  310. soapRequestData.Append(itemRow["DD"] != null ? "<DD>" + itemRow["DD"].ToString() + "</DD>" : "<DD>" + "</DD>");
  311. soapRequestData.Append(itemRow["SPTDOC_NO"] != null ? "<SPTDOC_NO>" + itemRow["SPTDOC_NO"].ToString() + "</SPTDOC_NO>" : "<SPTDOC_NO>" + "</SPTDOC_NO>");
  312. soapRequestData.Append(itemRow["SMR"] != null ? "<SMR>" + itemRow["SMR"].ToString() + "</SMR>" : "<SMR>" + "</SMR>");
  313. soapRequestData.Append(itemRow["DBTO"] != null ? "<DBTO>" + itemRow["DBTO"].ToString() + "</DBTO>" : "<DBTO>" + "</DBTO>");
  314. soapRequestData.Append(itemRow["CRDTO"] != null ? "<CRDTO>" + itemRow["CRDTO"].ToString() + "</CRDTO>" : "<CRDTO>" + "</CRDTO>");
  315. soapRequestData.Append(itemRow["DBTO_CRDTO_DVSN"] != null ? "<DBTO_CRDTO_DVSN>" + itemRow["DBTO_CRDTO_DVSN"].ToString() + "</DBTO_CRDTO_DVSN>" : "<DBTO_CRDTO_DVSN>" + "</DBTO_CRDTO_DVSN>");
  316. soapRequestData.Append(itemRow["BLNC"] != null ? "<BLNC>" + itemRow["BLNC"].ToString() + "</BLNC>" : "<BLNC>" + "</BLNC>");
  317. soapRequestData.Append(itemRow["OFC_OPRT_CST"] != null ? "<OFC_OPRT_CST>" + itemRow["OFC_OPRT_CST"].ToString() + "</OFC_OPRT_CST>" : "<OFC_OPRT_CST>" + "</OFC_OPRT_CST>");
  318. soapRequestData.Append(itemRow["BZTRP_CST"] != null ? "<BZTRP_CST>" + itemRow["BZTRP_CST"].ToString() + "</BZTRP_CST>" : "<BZTRP_CST>" + "</BZTRP_CST>");
  319. soapRequestData.Append(itemRow["TRSF_CST"] != null ? "<TRSF_CST>" + itemRow["TRSF_CST"].ToString() + "</TRSF_CST>" : "<TRSF_CST>" + "</TRSF_CST>");
  320. soapRequestData.Append(itemRow["BNFT_CST"] != null ? "<BNFT_CST>" + itemRow["BNFT_CST"].ToString() + "</BNFT_CST>" : "<BNFT_CST>" + "</BNFT_CST>");
  321. soapRequestData.Append(itemRow["NTTN_CST"] != null ? "<NTTN_CST>" + itemRow["NTTN_CST"].ToString() + "</NTTN_CST>" : "<NTTN_CST>" + "</NTTN_CST>");
  322. soapRequestData.Append(itemRow["SCLISRC"] != null ? "<SCLISRC>" + itemRow["SCLISRC"].ToString() + "</SCLISRC>" : "<SCLISRC>" + "</SCLISRC>");
  323. soapRequestData.Append(itemRow["DDTN"] != null ? "<DDTN>" + itemRow["DDTN"].ToString() + "</DDTN>" : "<DDTN>" + "</DDTN>");
  324. soapRequestData.Append(itemRow["NTRR_CST"] != null ? "<NTRR_CST>" + itemRow["NTRR_CST"].ToString() + "</NTRR_CST>" : "<NTRR_CST>" + "</NTRR_CST>");
  325. soapRequestData.Append(itemRow["VEHS_OPRT_CST"] != null ? "<VEHS_OPRT_CST>" + itemRow["VEHS_OPRT_CST"].ToString() + "</VEHS_OPRT_CST>" : "<VEHS_OPRT_CST>" + "</VEHS_OPRT_CST>");
  326. soapRequestData.Append(itemRow["SVC_CST"] != null ? "<SVC_CST>" + itemRow["SVC_CST"].ToString() + "</SVC_CST>" : "<SVC_CST>" + "</SVC_CST>");
  327. soapRequestData.Append(itemRow["VEHS_RNTL_CST"] != null ? "<VEHS_RNTL_CST>" + itemRow["VEHS_RNTL_CST"].ToString() + "</VEHS_RNTL_CST>" : "<VEHS_RNTL_CST>" + "</VEHS_RNTL_CST>");
  328. soapRequestData.Append(itemRow["OFC_RNTL_CST"] != null ? "<OFC_RNTL_CST>" + itemRow["OFC_RNTL_CST"].ToString() + "</OFC_RNTL_CST>" : "<OFC_RNTL_CST>" + "</OFC_RNTL_CST>");
  329. soapRequestData.Append(itemRow["PRPT_MGMT_CST"] != null ? "<PRPT_MGMT_CST>" + itemRow["PRPT_MGMT_CST"].ToString() + "</PRPT_MGMT_CST>" : "<PRPT_MGMT_CST>" + "</PRPT_MGMT_CST>");
  330. soapRequestData.Append(itemRow["WTNELCT_CST"] != null ? "<WTNELCT_CST>" + itemRow["WTNELCT_CST"].ToString() + "</WTNELCT_CST>" : "<WTNELCT_CST>" + "</WTNELCT_CST>");
  331. soapRequestData.Append(itemRow["NWK_CST"] != null ? "<NWK_CST>" + itemRow["NWK_CST"].ToString() + "</NWK_CST>" : "<NWK_CST>" + "</NWK_CST>");
  332. soapRequestData.Append(itemRow["TELE_CST"] != null ? "<TELE_CST>" + itemRow["TELE_CST"].ToString() + "</TELE_CST>" : "<TELE_CST>" + "</TELE_CST>");
  333. soapRequestData.Append(itemRow["MEET_CST"] != null ? "<MEET_CST>" + itemRow["MEET_CST"].ToString() + "</MEET_CST>" : "<MEET_CST>" + "</MEET_CST>");
  334. soapRequestData.Append(itemRow["PCL_CST"] != null ? "<PCL_CST>" + itemRow["PCL_CST"].ToString() + "</PCL_CST>" : "<PCL_CST>" + "</PCL_CST>");
  335. soapRequestData.Append(itemRow["PNCST"] != null ? "<PNCST>" + itemRow["PNCST"].ToString() + "</PNCST>" : "<PNCST>" + "</PNCST>");
  336. soapRequestData.Append(itemRow["CUN_CST"] != null ? "<CUN_CST>" + itemRow["CUN_CST"].ToString() + "</CUN_CST>" : "<CUN_CST>" + "</CUN_CST>");
  337. soapRequestData.Append(itemRow["DPRCT_CST"] != null ? "<DPRCT_CST>" + itemRow["DPRCT_CST"].ToString() + "</DPRCT_CST>" : "<DPRCT_CST>" + "</DPRCT_CST>");
  338. soapRequestData.Append(itemRow["EDU_CST"] != null ? "<EDU_CST>" + itemRow["EDU_CST"].ToString() + "</EDU_CST>" : "<EDU_CST>" + "</EDU_CST>");
  339. soapRequestData.Append(itemRow["RPR_CST"] != null ? "<RPR_CST>" + itemRow["RPR_CST"].ToString() + "</RPR_CST>" : "<RPR_CST>" + "</RPR_CST>");
  340. soapRequestData.Append(itemRow["LBPRTT_CST"] != null ? "<LBPRTT_CST>" + itemRow["LBPRTT_CST"].ToString() + "</LBPRTT_CST>" : "<LBPRTT_CST>" + "</LBPRTT_CST>");
  341. soapRequestData.Append(itemRow["BZ_PRMT_CST"] != null ? "<BZ_PRMT_CST>" + itemRow["BZ_PRMT_CST"].ToString() + "</BZ_PRMT_CST>" : "<BZ_PRMT_CST>" + "</BZ_PRMT_CST>");
  342. soapRequestData.Append(itemRow["TEST_CST"] != null ? "<TEST_CST>" + itemRow["TEST_CST"].ToString() + "</TEST_CST>" : "<TEST_CST>" + "</TEST_CST>");
  343. soapRequestData.Append(itemRow["BK_CST"] != null ? "<BK_CST>" + itemRow["BK_CST"].ToString() + "</BK_CST>" : "<BK_CST>" + "</BK_CST>");
  344. soapRequestData.Append(itemRow["RCRT_CST"] != null ? "<RCRT_CST>" + itemRow["RCRT_CST"].ToString() + "</RCRT_CST>" : "<RCRT_CST>" + "</RCRT_CST>");
  345. soapRequestData.Append(itemRow["XBT_CST"] != null ? "<XBT_CST>" + itemRow["XBT_CST"].ToString() + "</XBT_CST>" : "<XBT_CST>" + "</XBT_CST>");
  346. soapRequestData.Append(itemRow["RSNB_LOS"] != null ? "<RSNB_LOS>" + itemRow["RSNB_LOS"].ToString() + "</RSNB_LOS>" : "<RSNB_LOS>" + "</RSNB_LOS>");
  347. // 根据年月日凭证号关联SMPL_CST
  348. if (vbsgz04dt.Rows.Count > 0 && !string.IsNullOrEmpty(itemRow["SPTDOC_NO"].ToString()))
  349. {
  350. var SMPL_CST = vbsgz04dt.Select("YYYY='" + itemRow["YYYY"].ToString() + "' and MM='" + itemRow["MM"].ToString() + "' and DD='" + itemRow["DD"].ToString() + "' and SPTDOC_NO='" + itemRow["SPTDOC_NO"].ToString() + "'");
  351. if (SMPL_CST.Length > 0)
  352. {
  353. var vbs04row = SMPL_CST.FirstOrDefault();
  354. soapRequestData.Append(vbs04row["SMPL_CST"] != null ? "<SMPL_CST>" + vbs04row["SMPL_CST"].ToString() + "</SMPL_CST>" : "<SMPL_CST>" + "</SMPL_CST>");
  355. var datatemp = new TempDatas
  356. {
  357. YYYY = itemRow["YYYY"].ToString(),
  358. MM = itemRow["MM"].ToString(),
  359. DD = itemRow["DD"].ToString(),
  360. SPTDOC_NO = itemRow["SPTDOC_NO"].ToString(),
  361. };
  362. datarows.Add(datatemp);
  363. }
  364. }
  365. soapRequestData.Append("</MGMT_CST>");
  366. //原循环部分 end
  367. }
  368. log.Info("原本006gz数据已录入" + soapRequestData.Length + "条。");
  369. log.Info("datarows关联到" + datarows.Count + "条。");
  370. // 若有未关联的数据,拼接在数据后面
  371. if (vbsgz04dt.Rows.Count > 0)
  372. {
  373. foreach (DataRow item in vbsgz04dt.Rows)
  374. {
  375. if (datarows.Count > 0)
  376. {
  377. var exists = datarows.Any(q => q.YYYY == item["YYYY"].ToString() && q.MM == item["MM"].ToString() && q.DD == item["DD"].ToString() && q.SPTDOC_NO == item["SPTDOC_NO"].ToString());
  378. log.Info("有关联数据" + datarows.Count + "条,过滤后exists结果为" + exists + "。");
  379. if (!exists)
  380. {
  381. soapRequestData.Append("<MGMT_CST>");
  382. soapRequestData.Append(item["YYYY"] != null ? "<YYYY>" + item["YYYY"].ToString() + "</YYYY>" : "<YYYY>" + "</YYYY>");
  383. soapRequestData.Append(item["MM"] != null ? "<MM>" + item["MM"].ToString() + "</MM>" : "<MM>" + "</MM>");
  384. soapRequestData.Append(item["DD"] != null ? "<DD>" + item["DD"].ToString() + "</DD>" : "<DD>" + "</DD>");
  385. soapRequestData.Append(item["SPTDOC_NO"] != null ? "<SPTDOC_NO>" + item["SPTDOC_NO"].ToString() + "</SPTDOC_NO>" : "<SPTDOC_NO>" + "</SPTDOC_NO>");
  386. soapRequestData.Append(item["SMPL_CST"] != null ? "<SMPL_CST>" + item["SMPL_CST"].ToString() + "</SMPL_CST>" : "<SMPL_CST>" + "</SMPL_CST>");
  387. soapRequestData.Append("</MGMT_CST>");
  388. }
  389. }
  390. else
  391. {
  392. soapRequestData.Append("<MGMT_CST>");
  393. soapRequestData.Append(item["YYYY"] != null ? "<YYYY>" + item["YYYY"].ToString() + "</YYYY>" : "<YYYY>" + "</YYYY>");
  394. soapRequestData.Append(item["MM"] != null ? "<MM>" + item["MM"].ToString() + "</MM>" : "<MM>" + "</MM>");
  395. soapRequestData.Append(item["DD"] != null ? "<DD>" + item["DD"].ToString() + "</DD>" : "<DD>" + "</DD>");
  396. soapRequestData.Append(item["SPTDOC_NO"] != null ? "<SPTDOC_NO>" + item["SPTDOC_NO"].ToString() + "</SPTDOC_NO>" : "<SPTDOC_NO>" + "</SPTDOC_NO>");
  397. soapRequestData.Append(item["SMPL_CST"] != null ? "<SMPL_CST>" + item["SMPL_CST"].ToString() + "</SMPL_CST>" : "<SMPL_CST>" + "</SMPL_CST>");
  398. soapRequestData.Append("</MGMT_CST>");
  399. }
  400. }
  401. }
  402. log.Info("最终006数据录入" + soapRequestData.Length + "条。");
  403. soapRequestData.Append("</yerp:YERP_006_OA1_MT>");
  404. soapRequestData.Append("</soapenv:Body>");
  405. soapRequestData.Append("</soapenv:Envelope>");
  406. string postData = soapRequestData.ToString();
  407. log.Info("YERP_006 xmlRequest:" + postData);
  408. string statusCode;
  409. string resultContent;
  410. ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;
  411. RestOpHelper rop = new RestOpHelper();
  412. rop.Clientp12path = @"C:\Users\Administrator\Desktop\yonyou-cert\wildcard.pfx";
  413. rop.Clientp12PassWord = "Yonyou2024!";
  414. rop.Url = @"https://yerp-proxy-sap-prod.skchemicals.com/XISOAPAdapter/MessageServlet?senderParty=&senderService=YERP_P&receiverParty=&receiverService=&interface=YERP_006_OA1_SI&interfaceNamespace=http://skch.com/YERP_006_MATN_COST";
  415. rop.RequestSAP(rop.Url, 10000, postData, "IF_YERP", "Kfiw282082", out statusCode, out resultContent);
  416. log.Info("YERP_006 statusCode:" + statusCode + "\r\n" + "resultContent:" + resultContent);
  417. }
  418. }
  419. catch (Exception ex)
  420. {
  421. log.Error(ex.ToString());
  422. }
  423. }
  424. public static Configuration GetConfig()
  425. {
  426. Assembly assembly = Assembly.GetCallingAssembly();
  427. string path = string.Format("{0}.config", assembly.Location);
  428. if (!File.Exists(path))
  429. {
  430. throw new FileNotFoundException(path + "路径下的文件未找到!");
  431. }
  432. try
  433. {
  434. ExeConfigurationFileMap configFile = new ExeConfigurationFileMap();
  435. configFile.ExeConfigFilename = path;
  436. Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFile, ConfigurationUserLevel.None);
  437. return config;
  438. }
  439. catch (Exception)
  440. {
  441. throw;
  442. }
  443. }
  444. }
  445. }