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