InvokeDllCenter.cs 9.8 KB

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