InvokeDllCenter.cs 8.5 KB

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