InvokeDllCenter.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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 BusinessPresc(string inputData, ref string outputData, ref string pErrMsg)
  73. {
  74. pErrMsg = "";
  75. outputData = "";
  76. string method = Global.curEvt.funNo;
  77. try
  78. {
  79. inputData = inputData.Replace("\n", "").Replace("\t", "").Replace("\r", "");
  80. Global.curEvt.msgid = Global.inf.hospitalNO + DateTime.Now.ToString("yyyyMMddHHmmssffff");
  81. //调用业务函数
  82. //StringBuilder sbOut = new StringBuilder(4096000);
  83. //insuplc_admdvs 社保清算机构(参保地)
  84. string orgCode = Utils.GetInsuCode();
  85. if (!Utils.isOtherCity())
  86. {
  87. //如果是本地人员,除read_card和query_basic_info这两个接口传”000000”之外,其他与参保人相关的交易接口中sbjgbh必须传read_card和query_basic_info接口中返回的sbjgbh值
  88. if (("read_card".Equals(method)) || ("query_basic_info".Equals(method)))
  89. {
  90. orgCode = "000000"; //市内(本地)
  91. }
  92. }
  93. else
  94. {
  95. orgCode = "37000000"; //跨省、省内异地
  96. if (Utils.isOtherProvice() && "read_card".Equals(method))
  97. {
  98. method = "read_card_qgyd"; //全国异地读卡
  99. }
  100. // 省医保
  101. if (Global.inf.interfaceDr == 28)
  102. {
  103. orgCode = Global.pat.insuplc_admdvs; //参保地
  104. }
  105. }
  106. string userCode = Global.user.ID;
  107. string tradeNo = Global.curEvt.msgid;
  108. string hospCode = Utils.GetInsuOrgCode();
  109. int pRtn = 0;
  110. // com调用
  111. //cressWSDLLLib.DWCressCom comCls = new cressWSDLLLib.DWCressCom();
  112. //outputData = comCls.f_invoke_cress_com(orgCode, hospCode, tradeNo, method, inputData, hospCode);
  113. // dll调用
  114. //pRtn = BusinessHandle(orgCode, userCode, tradeNo, method, inputData, hospCode, ref outputData);
  115. //outputData = sbOut.ToString();
  116. return pRtn;
  117. }
  118. catch (Exception ex)
  119. {
  120. pErrMsg = "业务函数[" + method + "]异常:" + ex.Message;
  121. return -1;
  122. }
  123. finally
  124. {
  125. Global.writeLog("业务函数[" + method + "]", inputData, outputData);
  126. }
  127. }
  128. public int BusinessExt(string inputData, ref string outputData, ref string pErrMsg)
  129. {
  130. pErrMsg = "";
  131. outputData = "";
  132. try
  133. {
  134. //inputData = inputData.Replace("\n", "").Replace("\t", "").Replace("\r", "");
  135. StringBuilder errmsgSb = new StringBuilder(4096);
  136. StringBuilder outSb = new StringBuilder(40960);
  137. StringBuilder sbHospitalNO = new StringBuilder(Global.inf.hospitalNO);
  138. StringBuilder sbCreditID = new StringBuilder(Global.inf.CreditID);
  139. StringBuilder sbBusinessID = new StringBuilder(Global.inf.BusinessID);
  140. StringBuilder sbInput = new StringBuilder(inputData);
  141. //调用业务函数
  142. int pRtn = 0; // BusinessHandleW(sbHospitalNO, sbCreditID, sbBusinessID, sbInput, outSb, errmsgSb);
  143. if (pRtn != 0)
  144. {
  145. outputData = outSb.ToString();
  146. pErrMsg = errmsgSb.ToString();
  147. return -1;
  148. }
  149. else
  150. {
  151. outputData = outSb.ToString();
  152. return 0;
  153. }
  154. }
  155. catch (Exception ex)
  156. {
  157. pErrMsg = "invokeInitByDLL.BusinessHandle 异常:" + ex.Message;
  158. return -1;
  159. }
  160. finally
  161. {
  162. Global.writeLog("CreditID12", Global.inf.CreditID, Global.inf.BusinessID);
  163. Global.writeLog("invokeInitByDLL.BusinessHandleW医保动态库通用业务函数", inputData, outputData);
  164. }
  165. }
  166. public int DownloadFile(string inputData, ref string outputData)
  167. {
  168. outputData = "";
  169. string error = string.Empty; int errorCode = 0;
  170. try
  171. {
  172. JObject jsonInParam = JObject.Parse(inputData);
  173. string fileName = (string)jsonInParam["input"]["fsDownloadIn"]["filename"];
  174. string filePath = Global.curEvt.path + "\\YBDLOAD\\" + fileName;
  175. //如果不存在目录,则创建目录
  176. if (!Directory.Exists(Global.curEvt.path + "\\YBDLOAD"))
  177. {
  178. //创建文件夹
  179. DirectoryInfo dirInfo = Directory.CreateDirectory(Global.curEvt.path + "\\YBDLOAD");
  180. }
  181. if (File.Exists(filePath))
  182. {
  183. File.Delete(filePath);
  184. }
  185. int iRes = Business(inputData, ref outputData,ref error);
  186. Global.writeLog("DLL下载文件返回:["+iRes+"]",inputData,outputData);
  187. if (iRes == 0)
  188. {
  189. dynamic joReturn = new JObject();
  190. joReturn.errorCode = errorCode;
  191. joReturn.errorMessage = error;
  192. joReturn.filePath = filePath;
  193. outputData = joReturn.ToString();
  194. }
  195. else
  196. {
  197. errorCode = -100;
  198. dynamic joReturn = new JObject();
  199. joReturn.errorCode = errorCode;
  200. joReturn.errorMessage = error;
  201. outputData = joReturn.ToString();
  202. return -1;
  203. }
  204. }
  205. catch (Exception ex)
  206. {
  207. errorCode = -100;
  208. error = ex.Message;
  209. dynamic joReturn = new JObject();
  210. joReturn.errorCode = errorCode;
  211. joReturn.errorMessage = error;
  212. outputData = joReturn.ToString();
  213. return -1;
  214. }
  215. finally
  216. {
  217. Global.writeLog("DownloadCenterFile" + "(" + Global.curEvt.URL + ")", inputData, outputData);
  218. }
  219. return 0;
  220. }
  221. public int Init(ref string pErrMsg)
  222. {
  223. int pRtn = -1;
  224. pErrMsg = "";
  225. JObject joRtn = new JObject();
  226. try
  227. {
  228. StringBuilder sbOut = new StringBuilder(40960);
  229. pRtn = 0; // Init(sbOut);
  230. pErrMsg = sbOut.ToString();
  231. Global.writeLog("DLL返回:"+pErrMsg);
  232. return pRtn;
  233. }
  234. catch (Exception ex)
  235. {
  236. pErrMsg = "invokeInitByDLL.Init 异常:" + ex.Message;
  237. return -1;
  238. }
  239. finally
  240. {
  241. Global.writeLog("InvokeInitByDLL(" + Global.inf.centerURL + ")", Global.inf.CreditID + ":" + Global.inf.BusinessID, pRtn.ToString() + pErrMsg);
  242. }
  243. }
  244. public int UploadFile(string inputData, ref string outputData, ref string pErrMsg)
  245. {
  246. pErrMsg = "";
  247. outputData = "";
  248. JObject joRtn = new JObject();
  249. try
  250. {
  251. inputData = inputData.Replace("\n", "").Replace("\t", "").Replace("\r", "");
  252. StringBuilder errmsgSb = new StringBuilder(4096);
  253. StringBuilder outSb = new StringBuilder(40960);
  254. //调用业务函数
  255. int pRtn = 0; // UploadFile(Global.inf.hospitalNO, Global.inf.CreditID, Global.inf.BusinessID, Global.inf.fileName, inputData, outSb, errmsgSb);
  256. if (pRtn != 0)
  257. {
  258. outputData = outSb.ToString();
  259. pErrMsg = errmsgSb.ToString();
  260. return -1;
  261. }
  262. else
  263. {
  264. outputData = outSb.ToString();
  265. return 0;
  266. }
  267. }
  268. catch (Exception ex)
  269. {
  270. pErrMsg = "invokeUploadFileByDLL.UploadFile 异常:" + ex.Message;
  271. return -1;
  272. }
  273. finally
  274. {
  275. Global.writeLog("invokeUploadFileByDLL.UploadFile医保动态库上传业务函数", inputData, outputData);
  276. }
  277. }
  278. /// <summary>
  279. /// 初始化函数
  280. /// </summary>
  281. /// <param name="pErrMsg"></param>
  282. /// <returns></returns>
  283. //[DllImport("cressWSDLL.dll", EntryPoint = "INIT", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
  284. //static extern int Init(StringBuilder pErrMsg);
  285. /// <summary>
  286. /// 通用业务函数
  287. /// </summary>
  288. /// <param name="inputData"></param>
  289. /// <param name="outputData"></param>
  290. /// <returns></returns>
  291. [DllImport("cressWSDLL.dll", EntryPoint = "f_invoke_cress", CharSet = CharSet.Ansi, ExactSpelling = false, CallingConvention = CallingConvention.StdCall)]
  292. static extern int BusinessHandle(string sbjgbh, string czybh,string hisjyh,string method,string jsonPara,string yybm, ref string outputData);
  293. }
  294. }