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.

279 lines
18 KiB

3 months ago
2 months ago
2 months ago
3 months ago
2 months ago
3 months ago
2 months ago
3 months ago
3 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_002 : 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. string conStr = ICSHelper.GetConnectString();
  46. // 202404
  47. // 过滤时间为上个月
  48. string Date = Dates.ToString("yyyy");
  49. string Muoth = Dates.AddMonths(-1).ToString("MM");
  50. string Day = Dates.ToString("dd");
  51. //<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:yerp="http://skch.com/YERP_002_SALES_INVOICE">
  52. // <soapenv:Header/>
  53. // <soapenv:Body>
  54. // <yerp:YERP_002_OA1_MT>
  55. // <!--1 or more repetitions:-->
  56. // <SLS_INVC>
  57. // <!--Optional:-->
  58. // <P_ORDER_NUM>?</P_ORDER_NUM>
  59. // <BIZ_TYP>?</BIZ_TYP>
  60. // <SL_TYP>?</SL_TYP>
  61. // <INVC_NO>?</INVC_NO>
  62. // <INVC_DE>?</INVC_DE>
  63. // <DO_NO>?</DO_NO>
  64. // <CUST_CD>?</CUST_CD>
  65. // <CUST_NM>?</CUST_NM>
  66. // <CUR>?</CUR>
  67. // <ER>?</ER>
  68. // <!--Optional:-->
  69. // <SL_TEAM>?</SL_TEAM>
  70. // <!--Optional:-->
  71. // <SL_PIC>?</SL_PIC>
  72. // <WH>?</WH>
  73. // <INVT_CD>?</INVT_CD>
  74. // <INVT_NM>?</INVT_NM>
  75. // <!--Optional:-->
  76. // <STDD_MDL>?</STDD_MDL>
  77. // <QTY>?</QTY>
  78. // <!--Optional:-->
  79. // <STMT>?</STMT>
  80. // <PRTX_UPRC>?</PRTX_UPRC>
  81. // <FRTX_UPRC>?</FRTX_UPRC>
  82. // <FRTX_AMT>?</FRTX_AMT>
  83. // <TXRTO>?</TXRTO>
  84. // <TX_AMT>?</TX_AMT>
  85. // <PRTX_AMT>?</PRTX_AMT>
  86. // <!--Optional:-->
  87. // <DISRTO1>?</DISRTO1>
  88. // <!--Optional:-->
  89. // <DISRTO2>?</DISRTO2>
  90. // <!--Optional:-->
  91. // <DIS_AMT>?</DIS_AMT>
  92. // <CRTR>?</CRTR>
  93. // <REVR>?</REVR>
  94. // <!--Optional:-->
  95. // <STTL_TYP_CD>?</STTL_TYP_CD>
  96. // <!--Optional:-->
  97. // <DLVR_TYP_CD>?</DLVR_TYP_CD>
  98. // <!--Optional:-->
  99. // <DLVR_TYP>?</DLVR_TYP>
  100. // <!--Optional:-->
  101. // <STTL_TYP>?</STTL_TYP>
  102. // <OUTST_AMT>?</OUTST_AMT>
  103. // <OUTST_LCUR>?</OUTST_LCUR>
  104. // </SLS_INVC>
  105. // </yerp:YERP_002_OA1_MT>
  106. // </soapenv:Body>
  107. //</soapenv:Envelope>
  108. //<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:yerp="http://skch.com/YERP_002_SALES_INVOICE">
  109. // <soapenv:Header/>
  110. // <soapenv:Body>
  111. // <yerp:YERP_002_OA1_MT>
  112. // <!--1 or more repetitions:-->
  113. // <SLS_INVC>
  114. // <Created_Year>?</Created_Year>
  115. // <Created_Month>?</Created_Month>
  116. // <P_ORDER_NUM>?</P_ORDER_NUM>
  117. // <BIZ_TYP>?</BIZ_TYP>
  118. // <SL_TYP>?</SL_TYP>
  119. // <INVC_NO>?</INVC_NO>
  120. // <INVC_DE>?</INVC_DE>
  121. // <DO_NO>?</DO_NO>
  122. // <CUST_CD>?</CUST_CD>
  123. // <CUST_NM>?</CUST_NM>
  124. // <CUR>?</CUR>
  125. // <ER>?</ER>
  126. // <SL_TEAM>?</SL_TEAM>
  127. // <SL_PIC>?</SL_PIC>
  128. // <WH>?</WH>
  129. // <INVT_CD>?</INVT_CD>
  130. // <INVT_NM>?</INVT_NM>
  131. // <STDD_MDL>?</STDD_MDL>
  132. // <QTY>?</QTY>
  133. // <STMT>?</STMT>
  134. // <PRTX_UPRC>?</PRTX_UPRC>
  135. // <FRTX_UPRC>?</FRTX_UPRC>
  136. // <FRTX_AMT>?</FRTX_AMT>
  137. // <TXRTO>?</TXRTO>
  138. // <TX_AMT>?</TX_AMT>
  139. // <PRTX_AMT>?</PRTX_AMT>
  140. // <DISRTO1>?</DISRTO1>
  141. // <DISRTO2>?</DISRTO2>
  142. // <DIS_AMT>?</DIS_AMT>
  143. // <CRTR>?</CRTR>
  144. // <REVR>?</REVR>
  145. // <STTL_TYP_CD>?</STTL_TYP_CD>
  146. // <DLVR_TYP_CD>?</DLVR_TYP_CD>
  147. // <DLVR_TYP>?</DLVR_TYP>
  148. // <STTL_TYP>?</STTL_TYP>
  149. // <OUTST_AMT>?</OUTST_AMT>
  150. // <OUTST_LCUR>?</OUTST_LCUR>
  151. // </SLS_INVC>
  152. // </yerp:YERP_002_OA1_MT>
  153. // </soapenv:Body>
  154. // </soapenv:Envelope>
  155. var beginPeriod = Dates.AddMonths(-1).AddDays(-Dates.Day + 1).ToString("yyyy-MM-dd");//"2023-06-01";
  156. var endPeriod = Dates.AddDays(-Dates.Day).ToString("yyyy-MM-dd");//"2023-07-01";
  157. string sqls = @"
  158. select year(a.dDate) as Created_Year,month(a.dDate) as Created_Month,b.cSOCode P_ORDER_NUM,cBusType BIZ_TYP,cSTName SL_TYP,cSBVCode INVC_NO,convert(nvarchar(10),dDate,112) INVC_DE,cDLCode DO_NO,cCusCode CUST_CD,cCusName CUST_NM,
  159. case when cexch_name = '' then 'CNY' else cexch_name end CUR,iExchRate ER,
  160. cDepName SL_TEAM, cPsn_Name SL_PIC,cWhCode WH, b.cInvCode INVT_CD, c.cInvAddCode INVT_ACD, c.cInvName INVT_NM, c.cInvStd STDD_MDL, b.iQuantity QTY, b.iQuotedPrice STMT, iTaxUnitPrice PRTX_UPRC,
  161. iUnitPrice FRTX_UPRC, iMoney FRTX_AMT,b.iTaxRate TXRTO, iTax TX_AMT,iSum PRTX_AMT, KL DISRTO1,KL2 DISRTO2, iDisCount DIS_AMT,cMaker CRTR, cChecker REVR,a.csscode STTL_TYP_CD, a.cSCCode DLVR_TYP_CD,
  162. d.cSCName DLVR_TYP, cSSName STTL_TYP,
  163. iSum - iExchSum OUTST_AMT, -- -
  164. iNatSum - iMoneySum OUTST_LCUR, ---
  165. 0 Printnum,a.dDate
  166. from dbo.SaleBillVouch a left join dbo.SaleBillVouchs b on A.SBVID = B.SBVID
  167. left join dbo.Inventory c on b.cInvCode = c.cInvCode
  168. left join dbo.ShippingChoice d on a.cSCCode = d.cSCCode
  169. left join dbo.SettleStyle e on a.csscode = e.cSSCode
  170. left join dbo.SaleType f on a.cSTCode = f.cSTCode
  171. left join dbo.hr_hi_person h on a.cPersonCode = h.cPsn_Num
  172. left join dbo.Department j on j.cDepCode = a.cDepCode WHERE 1 = 1 and a.dDate >= '{0}' and a.dDate <= '{1}'";
  173. sqls = string.Format(sqls, beginPeriod, endPeriod);
  174. log.Info("YERP_002 sql:" + sqls);
  175. DataTable vbsdt = ICSHelper.ExecuteTable(conStr, sqls);
  176. log.Info("sql结果数量" + vbsdt.Rows.Count);
  177. if (vbsdt.Rows.Count > 0)
  178. {
  179. StringBuilder soapRequestData = new StringBuilder();
  180. soapRequestData.Append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:yerp=\"http://skch.com/YERP_002_SALES_INVOICE\">");
  181. soapRequestData.Append("<soapenv:Header/>");
  182. soapRequestData.Append("<soapenv:Body>");
  183. soapRequestData.Append("<yerp:YERP_002_OA1_MT>");
  184. //循环数据
  185. foreach (DataRow itemRow in vbsdt.Rows)
  186. {
  187. //原循环部分 begin
  188. soapRequestData.Append("<SLS_INVC>");
  189. soapRequestData.Append(itemRow["Created_Year"] != null ? "<Created_Year>" + itemRow["Created_Year"].ToString() + "</Created_Year>" : "<Created_Year>" + "</Created_Year>");
  190. soapRequestData.Append(itemRow["Created_Month"] != null ? "<Created_Month>" + itemRow["Created_Month"].ToString() + "</Created_Month>" : "<Created_Month>" + "</Created_Month>");
  191. soapRequestData.Append(itemRow["P_ORDER_NUM"] != null ? "<P_ORDER_NUM>" + itemRow["P_ORDER_NUM"].ToString() + "</P_ORDER_NUM>" : "<P_ORDER_NUM>" + "</P_ORDER_NUM>");
  192. soapRequestData.Append(itemRow["BIZ_TYP"] != null ? "<BIZ_TYP>" + itemRow["BIZ_TYP"].ToString() + "</BIZ_TYP>" : "<BIZ_TYP>" + "</BIZ_TYP>");
  193. soapRequestData.Append(itemRow["SL_TYP"] != null ? "<SL_TYP>" + itemRow["SL_TYP"].ToString() + "</SL_TYP>" : "<SL_TYP>" + "</SL_TYP>");
  194. soapRequestData.Append(itemRow["INVC_NO"] != null ? "<INVC_NO>" + itemRow["INVC_NO"].ToString() + "</INVC_NO>" : "<INVC_NO>" + "</INVC_NO>");
  195. soapRequestData.Append(itemRow["INVC_DE"] != null ? "<INVC_DE>" + itemRow["INVC_DE"].ToString() + "</INVC_DE>" : "<INVC_DE>" + "</INVC_DE>");
  196. soapRequestData.Append(itemRow["DO_NO"] != null ? "<DO_NO>" + itemRow["DO_NO"].ToString() + "</DO_NO>" : "<DO_NO>" + "</DO_NO>");
  197. soapRequestData.Append(itemRow["CUST_CD"] != null ? "<CUST_CD>" + itemRow["CUST_CD"].ToString() + "</CUST_CD>" : "<CUST_CD>" + "</CUST_CD>");
  198. soapRequestData.Append(itemRow["CUST_NM"] != null ? "<CUST_NM>" + itemRow["CUST_NM"].ToString() + "</CUST_NM>" : "<CUST_NM>" + "</CUST_NM>");
  199. soapRequestData.Append(itemRow["CUR"] != null ? "<CUR>" + itemRow["CUR"].ToString() + "</CUR>" : "<CUR>" + "</CUR>");
  200. soapRequestData.Append(itemRow["ER"] != null ? "<ER>" + itemRow["ER"].ToString() + "</ER>" : "<ER>" + "</ER>");
  201. soapRequestData.Append(itemRow["SL_TEAM"] != null ? "<SL_TEAM>" + itemRow["SL_TEAM"].ToString() + "</SL_TEAM>" : "<SL_TEAM>" + "</SL_TEAM>");
  202. soapRequestData.Append(itemRow["SL_PIC"] != null ? "<SL_PIC>" + itemRow["SL_PIC"].ToString() + "</SL_PIC>" : "<SL_PIC>" + "</SL_PIC>");
  203. soapRequestData.Append(itemRow["WH"] != null ? "<WH>" + itemRow["WH"].ToString() + "</WH>" : "<WH>" + "</WH>");
  204. soapRequestData.Append(itemRow["INVT_CD"] != null ? "<INVT_CD>" + itemRow["INVT_CD"].ToString() + "</INVT_CD>" : "<INVT_CD>" + "</INVT_CD>");
  205. soapRequestData.Append(itemRow["INVT_NM"] != null ? "<INVT_NM>" + itemRow["INVT_NM"].ToString() + "</INVT_NM>" : "<INVT_NM>" + "</INVT_NM>");
  206. soapRequestData.Append(itemRow["STDD_MDL"] != null ? "<STDD_MDL>" + Regex.Replace(itemRow["STDD_MDL"].ToString(), @"[^0-9]+", "") + "</STDD_MDL>" : "<STDD_MDL>" + "</STDD_MDL>");
  207. soapRequestData.Append(itemRow["QTY"] != null ? "<QTY>" + itemRow["QTY"].ToString() + "</QTY>" : "<QTY>" + "</QTY>");
  208. soapRequestData.Append(itemRow["STMT"] != null ? "<STMT>" + itemRow["STMT"].ToString() + "</STMT>" : "<STMT>" + "</STMT>");
  209. soapRequestData.Append(itemRow["PRTX_UPRC"] != null ? "<PRTX_UPRC>" + itemRow["PRTX_UPRC"].ToString() + "</PRTX_UPRC>" : "<PRTX_UPRC>" + "</PRTX_UPRC>");
  210. soapRequestData.Append(itemRow["FRTX_UPRC"] != null ? "<FRTX_UPRC>" + itemRow["FRTX_UPRC"].ToString() + "</FRTX_UPRC>" : "<FRTX_UPRC>" + "</FRTX_UPRC>");
  211. soapRequestData.Append(itemRow["FRTX_AMT"] != null ? "<FRTX_AMT>" + itemRow["FRTX_AMT"].ToString() + "</FRTX_AMT>" : "<FRTX_AMT>" + "</FRTX_AMT>");
  212. soapRequestData.Append(itemRow["TXRTO"] != null ? "<TXRTO>" + itemRow["TXRTO"].ToString() + "</TXRTO>" : "<TXRTO>" + "</TXRTO>");
  213. soapRequestData.Append(itemRow["TX_AMT"] != null ? "<TX_AMT>" + itemRow["TX_AMT"].ToString() + "</TX_AMT>" : "<TX_AMT>" + "</TX_AMT>");
  214. soapRequestData.Append(itemRow["PRTX_AMT"] != null ? "<PRTX_AMT>" + itemRow["PRTX_AMT"].ToString() + "</PRTX_AMT>" : "<PRTX_AMT>" + "</PRTX_AMT>");
  215. soapRequestData.Append(itemRow["DISRTO1"] != null ? "<DISRTO1>" + itemRow["DISRTO1"].ToString() + "</DISRTO1>" : "<DISRTO1>" + "</DISRTO1>");
  216. soapRequestData.Append(itemRow["DISRTO2"] != null ? "<DISRTO2>" + itemRow["DISRTO2"].ToString() + "</DISRTO2>" : "<DISRTO2>" + "</DISRTO2>");
  217. soapRequestData.Append(itemRow["DIS_AMT"] != null ? "<DIS_AMT>" + itemRow["DIS_AMT"].ToString() + "</DIS_AMT>" : "<DIS_AMT>" + "</DIS_AMT>");
  218. soapRequestData.Append(itemRow["CRTR"] != null ? "<CRTR>" + itemRow["CRTR"].ToString() + "</CRTR>" : "<CRTR>" + "</CRTR>");
  219. soapRequestData.Append(itemRow["REVR"] != null ? "<REVR>" + itemRow["REVR"].ToString() + "</REVR>" : "<REVR>" + "</REVR>");
  220. soapRequestData.Append(itemRow["STTL_TYP_CD"] != null ? "<STTL_TYP_CD>" + itemRow["STTL_TYP_CD"].ToString() + "</STTL_TYP_CD>" : "<STTL_TYP_CD>" + "</STTL_TYP_CD>");
  221. soapRequestData.Append(itemRow["DLVR_TYP_CD"] != null ? "<DLVR_TYP_CD>" + itemRow["DLVR_TYP_CD"].ToString() + "</DLVR_TYP_CD>" : "<DLVR_TYP_CD>" + "</DLVR_TYP_CD>");
  222. soapRequestData.Append(itemRow["DLVR_TYP"] != null ? "<DLVR_TYP>" + itemRow["DLVR_TYP"].ToString() + "</DLVR_TYP>" : "<DLVR_TYP>" + "</DLVR_TYP>");
  223. soapRequestData.Append(itemRow["STTL_TYP"] != null ? "<STTL_TYP>" + itemRow["STTL_TYP"].ToString() + "</STTL_TYP>" : "<STTL_TYP>" + "</STTL_TYP>");
  224. soapRequestData.Append(itemRow["OUTST_AMT"] != null ? "<OUTST_AMT>" + itemRow["OUTST_AMT"].ToString() + "</OUTST_AMT>" : "<OUTST_AMT>" + "</OUTST_AMT>");
  225. soapRequestData.Append(itemRow["OUTST_LCUR"] != null ? "<OUTST_LCUR>" + itemRow["OUTST_LCUR"].ToString() + "</OUTST_LCUR>" : "<OUTST_LCUR>" + "</OUTST_LCUR>");
  226. soapRequestData.Append("</SLS_INVC>");
  227. //原循环部分 end
  228. }
  229. soapRequestData.Append("</yerp:YERP_002_OA1_MT>");
  230. soapRequestData.Append("</soapenv:Body>");
  231. soapRequestData.Append("</soapenv:Envelope>");
  232. string postData = soapRequestData.ToString();
  233. log.Info("YERP_002 xmlRequest:" + postData);
  234. string statusCode;
  235. string resultContent;
  236. ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;
  237. RestOpHelper rop = new RestOpHelper();
  238. rop.Clientp12path = @"C:\Users\Administrator\Desktop\yonyou-cert\wildcard.pfx";
  239. rop.Clientp12PassWord = "Yonyou2024!";
  240. rop.Url = @"https://yerp-proxy-sap-prod.skchemicals.com/XISOAPAdapter/MessageServlet?senderParty=&senderService=YERP_P&receiverParty=&receiverService=&interface=YERP_002_OA1_SI&interfaceNamespace=http://skch.com/YERP_002_SALES_INVOICE";
  241. rop.RequestSAP(rop.Url, 10000, postData, "IF_YERP", "Kfiw282082", out statusCode, out resultContent);
  242. log.Info("YERP_002 statusCode:" + statusCode + "\r\n" + "resultContent:" + resultContent);
  243. }
  244. }
  245. catch (Exception ex)
  246. {
  247. log.Error(ex.ToString());
  248. }
  249. }
  250. public static Configuration GetConfig()
  251. {
  252. Assembly assembly = Assembly.GetCallingAssembly();
  253. string path = string.Format("{0}.config", assembly.Location);
  254. if (!File.Exists(path))
  255. {
  256. throw new FileNotFoundException(path + "路径下的文件未找到!");
  257. }
  258. try
  259. {
  260. ExeConfigurationFileMap configFile = new ExeConfigurationFileMap();
  261. configFile.ExeConfigFilename = path;
  262. Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFile, ConfigurationUserLevel.None);
  263. return config;
  264. }
  265. catch (Exception)
  266. {
  267. throw;
  268. }
  269. }
  270. }
  271. }