InvokeDllCenter.cs 9.4 KB

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