InvokeDllCenter.cs 8.8 KB

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