InvokeDllCenter.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. using Newtonsoft.Json.Linq;
  2. using PTMedicalInsurance.Variables;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Runtime.InteropServices;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace PTMedicalInsurance.Helper
  11. {
  12. class InvokeDllCenter : IInvokeCenter
  13. {
  14. public int Business(string inputData, ref string outputData, ref string pErrMsg)
  15. {
  16. pErrMsg = "";
  17. outputData = "";
  18. try
  19. {
  20. inputData = inputData.Replace("\n", "").Replace("\t", "").Replace("\r", "");
  21. //调用业务函数
  22. StringBuilder sbOut = new StringBuilder(40960);
  23. int pRtn = BusinessHandle(inputData, sbOut);
  24. outputData = sbOut.ToString();
  25. return pRtn;
  26. }
  27. catch (Exception ex)
  28. {
  29. pErrMsg = "invokeByDLL.BusinessHandle 异常:" + ex.Message;
  30. return -1;
  31. }
  32. finally
  33. {
  34. Global.writeLog("invokeByDLL.BusinessHandle医保动态库通用业务函数", inputData, outputData);
  35. }
  36. }
  37. public int BusinessExt(string inputData, ref string outputData, ref string pErrMsg)
  38. {
  39. pErrMsg = "";
  40. outputData = "";
  41. try
  42. {
  43. //inputData = inputData.Replace("\n", "").Replace("\t", "").Replace("\r", "");
  44. StringBuilder errmsgSb = new StringBuilder(4096);
  45. StringBuilder outSb = new StringBuilder(40960);
  46. StringBuilder sbHospitalNO = new StringBuilder(Global.inf.hospitalNO);
  47. StringBuilder sbCreditID = new StringBuilder(Global.inf.CreditID);
  48. StringBuilder sbBusinessID = new StringBuilder(Global.inf.BusinessID);
  49. StringBuilder sbInput = new StringBuilder(inputData);
  50. //调用业务函数
  51. int pRtn = 0; // BusinessHandleW(sbHospitalNO, sbCreditID, sbBusinessID, sbInput, outSb, errmsgSb);
  52. if (pRtn != 0)
  53. {
  54. outputData = outSb.ToString();
  55. pErrMsg = errmsgSb.ToString();
  56. return -1;
  57. }
  58. else
  59. {
  60. outputData = outSb.ToString();
  61. return 0;
  62. }
  63. }
  64. catch (Exception ex)
  65. {
  66. pErrMsg = "invokeInitByDLL.BusinessHandle 异常:" + ex.Message;
  67. return -1;
  68. }
  69. finally
  70. {
  71. Global.writeLog("CreditID12", Global.inf.CreditID, Global.inf.BusinessID);
  72. Global.writeLog("invokeInitByDLL.BusinessHandleW医保动态库通用业务函数", inputData, outputData);
  73. }
  74. }
  75. public int DownloadFile(string inputData, ref string outputData)
  76. {
  77. outputData = "";
  78. string error = string.Empty; int errorCode = 0;
  79. try
  80. {
  81. JObject jsonInParam = JObject.Parse(inputData);
  82. string fileName = (string)jsonInParam["input"]["fsDownloadIn"]["filename"];
  83. string filePath = Global.curEvt.path + "\\YBDLOAD\\" + fileName;
  84. //如果不存在目录,则创建目录
  85. if (!Directory.Exists(Global.curEvt.path + "\\YBDLOAD"))
  86. {
  87. //创建文件夹
  88. DirectoryInfo dirInfo = Directory.CreateDirectory(Global.curEvt.path + "\\YBDLOAD");
  89. }
  90. if (File.Exists(filePath))
  91. {
  92. File.Delete(filePath);
  93. }
  94. int iRes = Business(inputData, ref outputData,ref error);
  95. Global.writeLog("DLL下载文件返回:["+iRes+"]",inputData,outputData);
  96. if (iRes == 0)
  97. {
  98. dynamic joReturn = new JObject();
  99. joReturn.errorCode = errorCode;
  100. joReturn.errorMessage = error;
  101. joReturn.filePath = filePath;
  102. outputData = joReturn.ToString();
  103. }
  104. else
  105. {
  106. errorCode = -100;
  107. dynamic joReturn = new JObject();
  108. joReturn.errorCode = errorCode;
  109. joReturn.errorMessage = error;
  110. outputData = joReturn.ToString();
  111. return -1;
  112. }
  113. }
  114. catch (Exception ex)
  115. {
  116. errorCode = -100;
  117. error = ex.Message;
  118. dynamic joReturn = new JObject();
  119. joReturn.errorCode = errorCode;
  120. joReturn.errorMessage = error;
  121. outputData = joReturn.ToString();
  122. return -1;
  123. }
  124. finally
  125. {
  126. Global.writeLog("DownloadCenterFile" + "(" + Global.curEvt.URL + ")", inputData, outputData);
  127. }
  128. return 0;
  129. }
  130. public int Init(ref string pErrMsg)
  131. {
  132. int pRtn = -1;
  133. pErrMsg = "";
  134. JObject joRtn = new JObject();
  135. try
  136. {
  137. StringBuilder sbOut = new StringBuilder(40960);
  138. pRtn = Init(sbOut);
  139. pErrMsg = sbOut.ToString();
  140. Global.writeLog("DLL返回:"+pErrMsg);
  141. return pRtn;
  142. }
  143. catch (Exception ex)
  144. {
  145. pErrMsg = "invokeInitByDLL.Init 异常:" + ex.Message;
  146. return -1;
  147. }
  148. finally
  149. {
  150. Global.writeLog("InvokeInitByDLL(" + Global.inf.centerURL + ")", Global.inf.CreditID + ":" + Global.inf.BusinessID, pRtn.ToString() + pErrMsg);
  151. }
  152. }
  153. public int UploadFile(string inputData, ref string outputData, ref string pErrMsg)
  154. {
  155. pErrMsg = "";
  156. outputData = "";
  157. JObject joRtn = new JObject();
  158. try
  159. {
  160. inputData = inputData.Replace("\n", "").Replace("\t", "").Replace("\r", "");
  161. StringBuilder errmsgSb = new StringBuilder(4096);
  162. StringBuilder outSb = new StringBuilder(40960);
  163. //调用业务函数
  164. int pRtn = 0; // UploadFile(Global.inf.hospitalNO, Global.inf.CreditID, Global.inf.BusinessID, Global.inf.fileName, inputData, outSb, errmsgSb);
  165. if (pRtn != 0)
  166. {
  167. outputData = outSb.ToString();
  168. pErrMsg = errmsgSb.ToString();
  169. return -1;
  170. }
  171. else
  172. {
  173. outputData = outSb.ToString();
  174. return 0;
  175. }
  176. }
  177. catch (Exception ex)
  178. {
  179. pErrMsg = "invokeUploadFileByDLL.UploadFile 异常:" + ex.Message;
  180. return -1;
  181. }
  182. finally
  183. {
  184. Global.writeLog("invokeUploadFileByDLL.UploadFile医保动态库上传业务函数", inputData, outputData);
  185. }
  186. }
  187. /// <summary>
  188. /// 初始化函数
  189. /// </summary>
  190. /// <param name="pErrMsg"></param>
  191. /// <returns></returns>
  192. [DllImport("SiInterface_hsf.dll", EntryPoint = "INIT", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
  193. static extern int Init(StringBuilder pErrMsg);
  194. /// <summary>
  195. /// 通用业务函数
  196. /// </summary>
  197. /// <param name="inputData"></param>
  198. /// <param name="outputData"></param>
  199. /// <returns></returns>
  200. [DllImport("SiInterface_hsf.dll", EntryPoint = "BUSINESS_HANDLE", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
  201. static extern int BusinessHandle(string inputData, StringBuilder outputData);
  202. }
  203. }