InvokeDllCenter.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. public int Business(string inputData, ref string outputData, ref string pErrMsg)
  18. {
  19. pErrMsg = "";
  20. outputData = "";
  21. string method = Global.curEvt.funNo;
  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(4096000);
  28. //insuplc_admdvs 社保清算机构(参保地)
  29. string orgCode = Utils.GetInsuCode();
  30. if (!Utils.isOtherCity())
  31. {
  32. //如果是本地人员,除read_card和query_basic_info这两个接口传”000000”之外,其他与参保人相关的交易接口中sbjgbh必须传read_card和query_basic_info接口中返回的sbjgbh值
  33. if (("read_card".Equals(method)) || ("query_basic_info".Equals(method)))
  34. {
  35. orgCode = "000000"; //市内(本地)
  36. }
  37. }
  38. else
  39. {
  40. orgCode = "37000000"; //跨省、省内异地
  41. if (Utils.isOtherProvice() && "read_card".Equals(method) && ("03".Equals(Global.pat.mdtrtcertType))) {
  42. method = "read_card_qgyd"; //全国异地读卡
  43. inputData = "{}";
  44. }
  45. // 省医保
  46. if (Global.inf.interfaceDr == 28)
  47. {
  48. orgCode = Global.pat.insuplc_admdvs; //参保地
  49. }
  50. }
  51. string userCode = Global.user.ID;
  52. string tradeNo = Global.curEvt.msgid;
  53. string hospCode = Utils.GetInsuOrgCode();
  54. int pRtn = 0;
  55. // com调用
  56. cressWSDLLLib.DWCressCom comCls = new cressWSDLLLib.DWCressCom();
  57. outputData = comCls.f_invoke_cress_com(orgCode, hospCode, tradeNo, method, inputData, hospCode);
  58. // dll调用
  59. //pRtn = BusinessHandle(orgCode, userCode, tradeNo, method, inputData, hospCode, ref outputData);
  60. //outputData = sbOut.ToString();
  61. return pRtn;
  62. }
  63. catch (Exception ex)
  64. {
  65. pErrMsg = "业务函数["+method+"]异常:" + ex.Message;
  66. return -1;
  67. }
  68. finally
  69. {
  70. Global.writeLog("业务函数["+method+"]", inputData, outputData);
  71. }
  72. }
  73. public int BusinessExt(string inputData, ref string outputData, ref string pErrMsg)
  74. {
  75. pErrMsg = "";
  76. outputData = "";
  77. try
  78. {
  79. //inputData = inputData.Replace("\n", "").Replace("\t", "").Replace("\r", "");
  80. StringBuilder errmsgSb = new StringBuilder(4096);
  81. StringBuilder outSb = new StringBuilder(40960);
  82. StringBuilder sbHospitalNO = new StringBuilder(Global.inf.hospitalNO);
  83. StringBuilder sbCreditID = new StringBuilder(Global.inf.CreditID);
  84. StringBuilder sbBusinessID = new StringBuilder(Global.inf.BusinessID);
  85. StringBuilder sbInput = new StringBuilder(inputData);
  86. //调用业务函数
  87. int pRtn = 0; // BusinessHandleW(sbHospitalNO, sbCreditID, sbBusinessID, sbInput, outSb, errmsgSb);
  88. if (pRtn != 0)
  89. {
  90. outputData = outSb.ToString();
  91. pErrMsg = errmsgSb.ToString();
  92. return -1;
  93. }
  94. else
  95. {
  96. outputData = outSb.ToString();
  97. return 0;
  98. }
  99. }
  100. catch (Exception ex)
  101. {
  102. pErrMsg = "invokeInitByDLL.BusinessHandle 异常:" + ex.Message;
  103. return -1;
  104. }
  105. finally
  106. {
  107. Global.writeLog("CreditID12", Global.inf.CreditID, Global.inf.BusinessID);
  108. Global.writeLog("invokeInitByDLL.BusinessHandleW医保动态库通用业务函数", inputData, outputData);
  109. }
  110. }
  111. public int DownloadFile(string inputData, ref string outputData)
  112. {
  113. outputData = "";
  114. string error = string.Empty; int errorCode = 0;
  115. try
  116. {
  117. JObject jsonInParam = JObject.Parse(inputData);
  118. string fileName = (string)jsonInParam["input"]["fsDownloadIn"]["filename"];
  119. string filePath = Global.curEvt.path + "\\YBDLOAD\\" + fileName;
  120. //如果不存在目录,则创建目录
  121. if (!Directory.Exists(Global.curEvt.path + "\\YBDLOAD"))
  122. {
  123. //创建文件夹
  124. DirectoryInfo dirInfo = Directory.CreateDirectory(Global.curEvt.path + "\\YBDLOAD");
  125. }
  126. if (File.Exists(filePath))
  127. {
  128. File.Delete(filePath);
  129. }
  130. int iRes = Business(inputData, ref outputData,ref error);
  131. Global.writeLog("DLL下载文件返回:["+iRes+"]",inputData,outputData);
  132. if (iRes == 0)
  133. {
  134. dynamic joReturn = new JObject();
  135. joReturn.errorCode = errorCode;
  136. joReturn.errorMessage = error;
  137. joReturn.filePath = filePath;
  138. outputData = joReturn.ToString();
  139. }
  140. else
  141. {
  142. errorCode = -100;
  143. dynamic joReturn = new JObject();
  144. joReturn.errorCode = errorCode;
  145. joReturn.errorMessage = error;
  146. outputData = joReturn.ToString();
  147. return -1;
  148. }
  149. }
  150. catch (Exception ex)
  151. {
  152. errorCode = -100;
  153. error = ex.Message;
  154. dynamic joReturn = new JObject();
  155. joReturn.errorCode = errorCode;
  156. joReturn.errorMessage = error;
  157. outputData = joReturn.ToString();
  158. return -1;
  159. }
  160. finally
  161. {
  162. Global.writeLog("DownloadCenterFile" + "(" + Global.curEvt.URL + ")", inputData, outputData);
  163. }
  164. return 0;
  165. }
  166. public int Init(ref string pErrMsg)
  167. {
  168. int pRtn = -1;
  169. pErrMsg = "";
  170. JObject joRtn = new JObject();
  171. try
  172. {
  173. StringBuilder sbOut = new StringBuilder(40960);
  174. pRtn = 0; // Init(sbOut);
  175. pErrMsg = sbOut.ToString();
  176. Global.writeLog("DLL返回:"+pErrMsg);
  177. return pRtn;
  178. }
  179. catch (Exception ex)
  180. {
  181. pErrMsg = "invokeInitByDLL.Init 异常:" + ex.Message;
  182. return -1;
  183. }
  184. finally
  185. {
  186. Global.writeLog("InvokeInitByDLL(" + Global.inf.centerURL + ")", Global.inf.CreditID + ":" + Global.inf.BusinessID, pRtn.ToString() + pErrMsg);
  187. }
  188. }
  189. public int UploadFile(string inputData, ref string outputData, ref string pErrMsg)
  190. {
  191. pErrMsg = "";
  192. outputData = "";
  193. JObject joRtn = new JObject();
  194. try
  195. {
  196. inputData = inputData.Replace("\n", "").Replace("\t", "").Replace("\r", "");
  197. StringBuilder errmsgSb = new StringBuilder(4096);
  198. StringBuilder outSb = new StringBuilder(40960);
  199. //调用业务函数
  200. int pRtn = 0; // UploadFile(Global.inf.hospitalNO, Global.inf.CreditID, Global.inf.BusinessID, Global.inf.fileName, inputData, outSb, errmsgSb);
  201. if (pRtn != 0)
  202. {
  203. outputData = outSb.ToString();
  204. pErrMsg = errmsgSb.ToString();
  205. return -1;
  206. }
  207. else
  208. {
  209. outputData = outSb.ToString();
  210. return 0;
  211. }
  212. }
  213. catch (Exception ex)
  214. {
  215. pErrMsg = "invokeUploadFileByDLL.UploadFile 异常:" + ex.Message;
  216. return -1;
  217. }
  218. finally
  219. {
  220. Global.writeLog("invokeUploadFileByDLL.UploadFile医保动态库上传业务函数", inputData, outputData);
  221. }
  222. }
  223. /// <summary>
  224. /// 初始化函数
  225. /// </summary>
  226. /// <param name="pErrMsg"></param>
  227. /// <returns></returns>
  228. //[DllImport("cressWSDLL.dll", EntryPoint = "INIT", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
  229. //static extern int Init(StringBuilder pErrMsg);
  230. /// <summary>
  231. /// 通用业务函数
  232. /// </summary>
  233. /// <param name="inputData"></param>
  234. /// <param name="outputData"></param>
  235. /// <returns></returns>
  236. [DllImport("cressWSDLL.dll", EntryPoint = "f_invoke_cress", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
  237. static extern int BusinessHandle(string sbjgbh, string czybh,string hisjyh,string method,string jsonPara,string yybm, ref string outputData);
  238. }
  239. }