InvokeDllCenter.cs 9.2 KB

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