DirectoryMapService.cs 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202
  1. using Newtonsoft.Json;
  2. using Newtonsoft.Json.Linq;
  3. using PTMedicalInsurance.Business;
  4. using PTMedicalInsurance.Common;
  5. using PTMedicalInsurance.Helper;
  6. using PTMedicalInsurance.Variables;
  7. using Sunny.UI;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.ComponentModel;
  11. using System.Data;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using System.Windows.Forms;
  16. using Global = PTMedicalInsurance.Variables.Global;
  17. namespace PTMedicalInsurance.Forms.BasicDatas.services
  18. {
  19. class DirectoryMapService
  20. {
  21. private string errMsg;
  22. CenterBusiness cBus = new CenterBusiness();
  23. HisMainBusiness hBus = new HisMainBusiness();
  24. HisIrisServices hIS = new HisIrisServices();
  25. MIIrisServices mIS = new MIIrisServices();
  26. InvokeHelper invoker = new InvokeHelper();
  27. private GridViewSetter gvdSetter = new GridViewSetter();
  28. private DataGridViewHeaderSetService dataGridViewHeaderSetService = new DataGridViewHeaderSetService();
  29. private Func<JObject, OutParamWrapper, int> action;
  30. //private DataLoader.MyFunc<string> updateDelegate;
  31. private System.Data.DataTable dtAllMapped;
  32. TradeEnum trade;
  33. int iTotalCount = 0;
  34. int currentPageIndex = 0;
  35. #region 界面标题设置
  36. /// <summary>
  37. /// 设置DataGridView标题
  38. /// </summary>
  39. public void SetDgvDirectoryHeader(int directoryType, DataGridView dgv)
  40. {
  41. switch (directoryType)
  42. {
  43. case 1://药品
  44. {
  45. gvdSetter.SetHeaderTextOfDrug(dgv);
  46. break;
  47. }
  48. case 2://诊疗
  49. {
  50. gvdSetter.SetHeaderTextOfMedicalService(dgv);
  51. break;
  52. }
  53. case 3://材料
  54. {
  55. gvdSetter.SetHeaderTextOfMaterials(dgv);
  56. break;
  57. }
  58. }
  59. }
  60. public int SetDgvDirectoryHeader( string fileName, DataGridView dgv,out string err)
  61. {
  62. return dataGridViewHeaderSetService.SetHeaderText(fileName, dgv, out err);
  63. }
  64. #endregion
  65. #region 获取入参
  66. public JObject GetHisDiRInput(DataFilter filter)
  67. {
  68. errMsg = "";
  69. int currentPage = 1; int pageSize = 50;
  70. JArray jaPagination = new JArray();
  71. JArray jaParams = new JArray();
  72. string directoryType = string.Empty;
  73. switch ((int)filter.hisDirectoryCategory)
  74. {
  75. case 0:
  76. {
  77. directoryType = "drugs";
  78. break;
  79. }
  80. case 1:
  81. {
  82. directoryType = "diagnosi";
  83. break;
  84. }
  85. case 2:
  86. {
  87. directoryType = "consumables";
  88. break;
  89. }
  90. }
  91. if (filter.mapFlag == MapFlagEnum.All)
  92. {
  93. dynamic joParam = new JObject();
  94. joParam.code = "";
  95. joParam.descripts = "";
  96. joParam.FindType = new JArray();
  97. joParam.TypeID = "";
  98. joParam.alias = filter.HisCodeOrName;
  99. joParam.include = "Hosp";
  100. joParam.groupID = "324";
  101. joParam.hospID = Global.inf.hisHospitalDr;
  102. joParam.interfaceDr = Global.inf.interfaceDr;
  103. joParam.type = directoryType;
  104. joParam.flag = "ALL";
  105. joParam.specInput = filter.Spec;
  106. jaParams.Add(joParam);
  107. dynamic joPagination = new JObject();
  108. joPagination.pageSize = pageSize;
  109. //joPagination.pageSize = 2;
  110. joPagination.currentPage = currentPage;
  111. joPagination.sortColumn = "Code";
  112. joPagination.sortOrder = "asc";
  113. jaPagination.Add(joPagination);
  114. }
  115. //已对照是先调云医保,然后再匹配HIS
  116. if (filter.mapFlag == MapFlagEnum.Mapped)
  117. {
  118. dynamic joParam = new JObject();
  119. joParam.alias = filter.HisCodeOrName;
  120. joParam.HospitalDr = Global.inf.hospitalDr;
  121. joParam.InterfaceDr = Global.inf.interfaceDr;
  122. joParam.hisType = directoryType;
  123. jaParams.Add(joParam);
  124. dynamic joPagination = new JObject();
  125. joPagination.pageSize = pageSize;
  126. joPagination.currentPage = currentPage;
  127. joPagination.sortColumn = "HisCode";
  128. joPagination.sortOrder = "asc";
  129. jaPagination.Add(joPagination);
  130. //传给HIS,进行匹配
  131. joParam = new JObject();
  132. joParam.TotalCount = 0;
  133. joParam.type = directoryType;
  134. joParam.flag = "Maped";
  135. joParam.hospID = Global.inf.hisHospitalDr;
  136. joParam.interfaceDr = Global.inf.interfaceDr;
  137. joParam.alias = filter.HisCodeOrName;
  138. joParam.include = "Hosp";
  139. joParam.groupID = "324";
  140. joParam.compareArr = new JArray();
  141. jaParams = new JArray();
  142. jaParams.Add(joParam);
  143. }
  144. if (filter.mapFlag == MapFlagEnum.NoMapped)
  145. {
  146. dynamic joParam = new JObject();
  147. joParam.code = "";
  148. joParam.descripts = "";
  149. joParam.FindType = new JArray();
  150. joParam.TypeID = "";
  151. joParam.alias = filter.HisCodeOrName;
  152. joParam.include = "Hosp";
  153. joParam.groupID = "324";
  154. joParam.hospID = Global.inf.hisHospitalDr;
  155. joParam.interfaceDr = Global.inf.interfaceDr;
  156. joParam.type = directoryType;
  157. joParam.flag = "ALL";
  158. joParam.specInput = "";
  159. jaParams.Add(joParam);
  160. dynamic joPagination = new JObject();
  161. joPagination.pageSize = pageSize;
  162. //joPagination.pageSize = 2;
  163. joPagination.currentPage = currentPage;
  164. joPagination.sortColumn = "Code";
  165. joPagination.sortOrder = "asc";
  166. jaPagination.Add(joPagination);
  167. }
  168. JObject joIn = new JObject();
  169. joIn.Add("pagination", jaPagination);
  170. joIn.Add("params", jaParams);
  171. return joIn;
  172. }
  173. #endregion
  174. #region 查询目录以及导出数据
  175. /// <summary>
  176. /// 查询His和平台的对照目录,分全部,已对照,未对照三种情况
  177. /// </summary>
  178. /// <param name="input"></param>
  179. /// <param name="mapFlag"></param>
  180. /// <returns></returns>
  181. public JObject QueryDirectory(JObject input,MapFlagEnum mapFlag)
  182. {
  183. JArray jaPagination = JArray.FromObject(input["pagination"]);
  184. JArray jaParams = JArray.FromObject(input["params"]);
  185. JObject joRtn = new JObject();
  186. JObject joHisRtn;
  187. joRtn.Add("errorCode",-1);
  188. joRtn.Add("errorMessage", "");
  189. switch (mapFlag)
  190. {
  191. case MapFlagEnum.None:
  192. return null;
  193. case MapFlagEnum.All:
  194. //全部是先调HIS,然后再匹配医保平台的对照关系
  195. if (hIS.getHISDir(jaPagination, jaParams, out joHisRtn, out errMsg) != 0)
  196. {
  197. joRtn["errorCode"] = -1;
  198. joRtn["errorMessage"] = errMsg;
  199. return joRtn;
  200. }
  201. joRtn = mIS.ConvertHISDir(joHisRtn);
  202. break;
  203. case MapFlagEnum.Mapped:
  204. JArray jaTmp = (JArray)jaParams.DeepClone();
  205. ((JObject)jaTmp[0]).Remove("code");
  206. ((JObject)jaTmp[0]).Remove("descripts");
  207. ((JObject)jaTmp[0]).Remove("FindType");
  208. ((JObject)jaTmp[0]).Remove("TypeID");
  209. ((JObject)jaTmp[0]).Remove("include");
  210. ((JObject)jaTmp[0]).Remove("groupID");
  211. ((JObject)jaTmp[0]).Remove("hospID");
  212. ((JObject)jaTmp[0]).Add("hisType", ((JObject)jaTmp[0])["type"]);
  213. ((JObject)jaTmp[0]).Add("HospitalDr", Global.inf.hospitalDr);
  214. ((JObject)jaTmp[0]).Add("InterfaceDr", ((JObject)jaTmp[0])["interfaceDr"]);
  215. ((JObject)jaTmp[0]).Remove("type");
  216. ((JObject)jaTmp[0]).Remove("flag");
  217. ((JObject)jaTmp[0]).Remove("specInput");
  218. ((JObject)jaTmp[0]).Remove("interfaceDr");
  219. JObject joMiRtn = mIS.GetMappedHISDir(jaPagination, jaTmp);
  220. if (JsonHelper.parseIrisRtnValue(joMiRtn, out errMsg) != 0)
  221. {
  222. joRtn["errorCode"] = -1;
  223. joRtn["errorMessage"] = errMsg;
  224. return joRtn;
  225. }
  226. ((JObject)jaParams[0]).Add("TotalCount", joMiRtn["result"]["TotalCount"]);
  227. jaParams[0]["compareArr"] = joMiRtn["result"]["Data"];
  228. if (hIS.getHISDir(jaPagination, jaParams, out joRtn, out errMsg) != 0)
  229. {
  230. joRtn["errorCode"] = -1;
  231. joRtn["errorMessage"] = errMsg;
  232. return joRtn;
  233. }
  234. break;
  235. case MapFlagEnum.NoMapped:
  236. //1.获取全部HIS目录
  237. if (hIS.getHISDir(jaPagination, jaParams, out joHisRtn, out errMsg) != 0)
  238. {
  239. joRtn["errorCode"] = -1;
  240. joRtn["errorMessage"] = errMsg;
  241. return joRtn;
  242. }
  243. //2.获取当前目录的最大值后再次获取目录
  244. int totalCount = int.Parse(joHisRtn["result"]["TotalCount"].ToString());
  245. jaPagination[0]["pageSize"] = totalCount;
  246. if (hIS.getHISDir(jaPagination, jaParams, out joHisRtn, out errMsg) != 0)
  247. {
  248. joRtn["errorCode"] = -1;
  249. joRtn["errorMessage"] = errMsg;
  250. return joRtn;
  251. }
  252. //3.获取医保平台数据并匹配未对照数据
  253. joRtn = mIS.GetNoMappHISDir(joHisRtn);
  254. if (JsonHelper.parseIrisRtnValue(joRtn, out errMsg) != 0)
  255. {
  256. joRtn["errorCode"] = -1;
  257. joRtn["errorMessage"] = errMsg;
  258. }
  259. break;
  260. default:
  261. return null;
  262. }
  263. return joRtn;
  264. }
  265. /// <summary>
  266. /// 查询医保平台存储的中心目录
  267. /// </summary>
  268. /// <param name="input"></param>
  269. /// <returns></returns>
  270. public JObject QueryMiDirectory(JObject input)
  271. {
  272. return mIS.getMIDirectoryByPagination(input);
  273. }
  274. public JObject QueryExportData(JObject input, MapFlagEnum mapFlag)
  275. {
  276. Global.writeLog($"QueryExportData_INPUT:{input}");
  277. JArray jaPagination = JArray.FromObject(input["pagination"]);
  278. JArray jaParams = JArray.FromObject(input["params"]);
  279. JObject joRtn = new JObject();
  280. //假设默认每次取得条数为1000,主要是IRIS服务如果没有走流模式,会有一个字符串最大限制,导致服务无法正常返回
  281. int defaultPageSize = 1000;
  282. int currentPage = 1;
  283. jaPagination[0]["pageSize"] = defaultPageSize;
  284. jaPagination[0]["currentPage"] = currentPage;
  285. JObject joHisRtn;
  286. joRtn.Add("errorCode", -1);
  287. joRtn.Add("errorMessage", "");
  288. switch (mapFlag)
  289. {
  290. case MapFlagEnum.None:
  291. return null;
  292. case MapFlagEnum.All:
  293. //全部是先调HIS,然后再匹配医保平台的对照关系
  294. if (hIS.getHISDir(jaPagination, jaParams, out joHisRtn, out errMsg) != 0)
  295. {
  296. joRtn["errorCode"] = -1;
  297. joRtn["errorMessage"] = errMsg;
  298. return joRtn;
  299. }
  300. JArray jaData = null;
  301. //获取HIS返回的总行数。这里其实应该根据默认行数跟总行数进行匹配
  302. int totalCount = int.Parse(JsonHelper.getDestValue(joHisRtn, "result.TotalCount"));
  303. if (totalCount > defaultPageSize)
  304. {
  305. while (currentPage <= (int)(totalCount / defaultPageSize))
  306. {
  307. currentPage++;
  308. jaPagination[0]["currentPage"] = currentPage;
  309. if (hIS.getHISDir(jaPagination, jaParams, out joHisRtn, out errMsg) != 0)
  310. {
  311. joRtn["errorCode"] = -1;
  312. joRtn["errorMessage"] = errMsg;
  313. return joRtn;
  314. }
  315. else
  316. {
  317. JObject joConvertDirRtn = mIS.ConvertHISDir(joHisRtn);
  318. joRtn = (JObject)joConvertDirRtn.DeepClone();
  319. JArray jaTmp = JArray.FromObject(joConvertDirRtn["result"]["Data"]);
  320. if (jaData == null)
  321. {
  322. jaData = jaTmp;
  323. }
  324. else
  325. {
  326. jaData.Merge(jaTmp);
  327. }
  328. }
  329. }
  330. joRtn["result"]["Data"] = jaData;
  331. }
  332. else
  333. {
  334. joRtn = mIS.ConvertHISDir(joHisRtn);
  335. }
  336. break;
  337. case MapFlagEnum.Mapped:
  338. JObject joMiRtn = mIS.GetMappedHISDir(jaPagination, jaParams);
  339. if (JsonHelper.parseIrisRtnValue(joMiRtn, out errMsg) != 0)
  340. {
  341. joRtn["errorCode"] = -1;
  342. joRtn["errorMessage"] = errMsg;
  343. }
  344. jaData = null;
  345. //获取HIS返回的总行数。这里其实应该根据默认行数跟总行数进行匹配
  346. totalCount = int.Parse(JsonHelper.getDestValue(joMiRtn, "result.TotalCount"));
  347. if (totalCount > defaultPageSize)
  348. {
  349. while (currentPage <= (int)(totalCount / defaultPageSize))
  350. {
  351. currentPage++;
  352. jaPagination[0]["currentPage"] = currentPage;
  353. joMiRtn = mIS.GetMappedHISDir(jaPagination, jaParams);
  354. if (JsonHelper.parseIrisRtnValue(joMiRtn, out errMsg) != 0)
  355. {
  356. joRtn["errorCode"] = -1;
  357. joRtn["errorMessage"] = errMsg;
  358. return joRtn;
  359. }
  360. jaParams[0]["compareArr"] = joMiRtn["result"]["Data"];
  361. if (hIS.getHISDir(jaPagination, jaParams, out joRtn, out errMsg) != 0)
  362. {
  363. joRtn["errorCode"] = -1;
  364. joRtn["errorMessage"] = errMsg;
  365. return joRtn;
  366. }
  367. JArray jaTmp = JArray.FromObject(joRtn["result"]["Data"]);
  368. if (jaData == null)
  369. {
  370. jaData = jaTmp;
  371. }
  372. else
  373. {
  374. jaData.Merge(jaTmp);
  375. }
  376. }
  377. joRtn["result"]["Data"] = jaData;
  378. }
  379. else
  380. {
  381. jaParams[0]["compareArr"] = joMiRtn["result"]["Data"];
  382. if (hIS.getHISDir(jaPagination, jaParams, out joRtn, out errMsg) != 0)
  383. {
  384. joRtn["errorCode"] = -1;
  385. joRtn["errorMessage"] = errMsg;
  386. }
  387. }
  388. break;
  389. case MapFlagEnum.NoMapped:
  390. //1.获取全部HIS目录
  391. if (hIS.getHISDir(jaPagination, jaParams, out joHisRtn, out errMsg) != 0)
  392. {
  393. joRtn["errorCode"] = -1;
  394. joRtn["errorMessage"] = errMsg;
  395. return joRtn;
  396. }
  397. jaData = null;
  398. //获取HIS返回的总行数。这里其实应该根据默认行数跟总行数进行匹配
  399. totalCount = int.Parse(JsonHelper.getDestValue(joHisRtn, "result.TotalCount"));
  400. if (totalCount > defaultPageSize)
  401. {
  402. while (currentPage <= (int)(totalCount / defaultPageSize))
  403. {
  404. currentPage++;
  405. jaPagination[0]["currentPage"] = currentPage;
  406. if (hIS.getHISDir(jaPagination, jaParams, out joHisRtn, out errMsg) != 0)
  407. {
  408. joRtn["errorCode"] = -1;
  409. joRtn["errorMessage"] = errMsg;
  410. return joRtn;
  411. }
  412. joRtn = mIS.GetNoMappHISDir(joHisRtn);
  413. if (JsonHelper.parseIrisRtnValue(joRtn, out errMsg) != 0)
  414. {
  415. joRtn["errorCode"] = -1;
  416. joRtn["errorMessage"] = errMsg;
  417. return joRtn;
  418. }
  419. JArray jaTmp = JArray.FromObject(joRtn["result"]["Data"]);
  420. if (jaData == null)
  421. {
  422. jaData = jaTmp;
  423. }
  424. else
  425. {
  426. jaData.Merge(jaTmp);
  427. }
  428. }
  429. joRtn["result"]["Data"] = jaData;
  430. }
  431. else
  432. {
  433. joRtn = mIS.GetNoMappHISDir(joHisRtn);
  434. if (JsonHelper.parseIrisRtnValue(joRtn, out errMsg) != 0)
  435. {
  436. joRtn["errorCode"] = -1;
  437. joRtn["errorMessage"] = errMsg;
  438. }
  439. }
  440. break;
  441. default:
  442. return null;
  443. }
  444. return joRtn;
  445. }
  446. #endregion
  447. #region 新版导出匹配
  448. private JArray FetchAllPages(
  449. JArray pagination,
  450. JArray @params,
  451. Func<JArray, JArray, (int code, JObject result, string msg)> fetchData)
  452. {
  453. var allData = new JArray();
  454. int pageSize = 1000;
  455. int currentPage = 1;
  456. int totalCount = 0;
  457. do
  458. {
  459. pagination[0]["pageSize"] = pageSize;
  460. pagination[0]["currentPage"] = currentPage;
  461. var (code, result, errMsg) = fetchData(pagination, @params);
  462. if (code != 0)
  463. {
  464. throw new Exception($"分页请求失败: {errMsg}");
  465. }
  466. if (currentPage == 1)
  467. {
  468. totalCount = int.TryParse(JsonHelper.getDestValue(result, "result.TotalCount"), out var cnt) ? cnt : 0;
  469. }
  470. var data = result["result"]?["Data"] as JArray;
  471. if (data != null)
  472. {
  473. allData.Add(data);
  474. }
  475. currentPage++;
  476. } while (currentPage * pageSize <= totalCount); // 或 currentPage <= (totalCount + pageSize - 1) / pageSize
  477. return allData;
  478. }
  479. public JObject QueryExportDataNew(JObject input, MapFlagEnum mapFlag)
  480. {
  481. var pagination = JArray.FromObject(input["pagination"]);
  482. var @params = JArray.FromObject(input["params"]);
  483. var result = new JObject();
  484. try
  485. {
  486. switch (mapFlag)
  487. {
  488. case MapFlagEnum.All:
  489. var hisDataAll = FetchAllPages(pagination, @params, (p, pr) => hIS.getHISDir(p, pr, out var r, out var m) == 0 ? (0, r, m) : (-1, null, m));
  490. var converted = mIS.ConvertHISDir(new JObject { ["result"] = new JObject { ["Data"] = hisDataAll } });
  491. return converted;
  492. case MapFlagEnum.Mapped:
  493. var mappedDir = mIS.GetMappedHISDir(pagination, @params);
  494. if (JsonHelper.parseIrisRtnValue(mappedDir, out var errMsg) != 0)
  495. return CreateError(-1, errMsg);
  496. var compareArr = mappedDir["result"]?["Data"] as JArray ?? new JArray();
  497. var clonedParams = (JArray)@params.DeepClone();
  498. clonedParams[0]["compareArr"] = compareArr;
  499. var hisMappedData = FetchAllPages(pagination, clonedParams, (p, pr) => hIS.getHISDir(p, pr, out var r, out var m) == 0 ? (0, r, m) : (-1, r, m));
  500. result["result"] = new JObject { ["Data"] = hisMappedData };
  501. result["errorCode"] = 0;
  502. result["errorMessage"] = "";
  503. return result;
  504. case MapFlagEnum.NoMapped:
  505. var hisRawData = FetchAllPages(pagination, @params, (p, pr) => hIS.getHISDir(p, pr, out var r, out var m) == 0 ? (0, r, m) : (-1, r, m));
  506. var noMapped = mIS.GetNoMappHISDir(new JObject { ["result"] = new JObject { ["Data"] = hisRawData } });
  507. if (JsonHelper.parseIrisRtnValue(noMapped, out errMsg) != 0)
  508. return CreateError(-1, errMsg);
  509. return noMapped;
  510. default:
  511. return null;
  512. }
  513. }
  514. catch (Exception ex)
  515. {
  516. return CreateError(-1, "系统异常: " + ex.Message);
  517. }
  518. }
  519. private JObject CreateError(int code, string msg)
  520. {
  521. return new JObject
  522. {
  523. ["errorCode"] = code,
  524. ["errorMessage"] = msg
  525. };
  526. }
  527. /// <summary>
  528. /// 导出对照数据
  529. /// </summary>
  530. /// <param name="context"></param>
  531. /// <param name="errMsg"></param>
  532. /// <returns></returns>
  533. private int exportMapData(DataLoaderContext context, out string errMsg)
  534. {
  535. int iFalse = 0;
  536. int iCount = 0;
  537. List<string> errList = new List<string>();
  538. //入参强制转换未JObject
  539. JObject joIn = (JObject)context.args[0];
  540. //获取iTotalCount
  541. int total = int.Parse(JsonHelper.getDestValue(joIn, "total"));
  542. //获取表数据
  543. DataTable dt = (DataTable)joIn["data"].ToObject(typeof(DataTable));
  544. //设置总进度数
  545. if (context.setProgressMaximum != null)
  546. {
  547. context.setProgressMaximum(total);
  548. }
  549. JObject joCondition = JObject.FromObject(joIn["condition"]);
  550. //遍历
  551. foreach (DataRow dr in dt.Rows)
  552. {
  553. if (joCondition.ContainsKey("hilist_code"))
  554. {
  555. joCondition["hilist_code"] = dr["InsuCode"].ToString();
  556. }
  557. else
  558. {
  559. errMsg = "未检测到相应字段";
  560. return -1; // 或者其他表示取消的返回值
  561. }
  562. joCondition["code"] = dr["InsuCode"].ToString();
  563. joCondition["HisType"] = dr["HisType"].ToString();
  564. OutParamWrapper outParWarp = new OutParamWrapper();
  565. if (action(joCondition, outParWarp) != 0)
  566. {
  567. iFalse++;
  568. errList.Add($"医保编码:【{dr["InsuCode"]}】,医保名称:【{dr["InsuName"]}】,HIS编码:【{dr["HISCode"]}】提示:{outParWarp.Value}");
  569. }
  570. iCount++;
  571. // 检查是否应取消操作
  572. if (context.Worker.CancellationPending)
  573. {
  574. errMsg = "操作取消!";
  575. return -1; // 或者其他表示取消的返回值
  576. }
  577. if (context.reportProgress != null)
  578. {
  579. context.reportProgress(iCount);
  580. }
  581. }
  582. if (iFalse != 0)
  583. {
  584. errMsg = ($"总共{iCount}条数据更新完成,但有{iFalse}条更新发生错误!");
  585. Global.writeLog($"{errMsg}\r\n{string.Join("\r\n", errList)}");
  586. }
  587. else
  588. {
  589. errMsg = ($"全部数据({iCount}条)更新完成");
  590. }
  591. return iFalse;
  592. }
  593. #endregion
  594. #region 更新目录附属信息
  595. public string getDataRowValue(DataRow dr, string columnName)
  596. {
  597. if (!dr.Table.Columns.Contains(columnName))
  598. {
  599. return "";
  600. }
  601. else
  602. {
  603. return dr[columnName].ToString();
  604. }
  605. }
  606. private int updateMappedInsuInfo(DataLoaderContext context, out string errMsg)
  607. {
  608. int iFalse = 0;
  609. int iCount = 0;
  610. List<string> errList = new List<string>();
  611. //入参强制转换未JObject
  612. JObject joIn = (JObject)context.args[0];
  613. //获取iTotalCount
  614. int total = int.Parse(JsonHelper.getDestValue(joIn,"total"));
  615. //获取表数据
  616. DataTable dt = (DataTable)joIn["data"].ToObject(typeof(DataTable));
  617. //设置总进度数
  618. if (context.setProgressMaximum != null)
  619. {
  620. context.setProgressMaximum(total);
  621. }
  622. JObject joCondition = JObject.FromObject(joIn["condition"]);
  623. //遍历
  624. foreach (DataRow dr in dt.Rows)
  625. {
  626. if (joCondition.ContainsKey("hilist_code"))
  627. {
  628. joCondition["hilist_code"] = dr["InsuCode"].ToString();
  629. }
  630. else
  631. {
  632. errMsg = "未检测到相应字段";
  633. return -1; // 或者其他表示取消的返回值
  634. }
  635. joCondition["code"] = dr["InsuCode"].ToString();
  636. joCondition["HisType"] = dr["HisType"].ToString();
  637. OutParamWrapper outParWarp = new OutParamWrapper();
  638. if (action(joCondition, outParWarp) != 0)
  639. {
  640. iFalse++;
  641. errList.Add( $"医保编码:【{dr["InsuCode"]}】,医保名称:【{dr["InsuName"]}】,HIS编码:【{dr["HISCode"]}】提示:{outParWarp.Value}");
  642. }
  643. iCount++;
  644. // 检查是否应取消操作
  645. if (context.Worker.CancellationPending)
  646. {
  647. errMsg = "操作取消!";
  648. return -1; // 或者其他表示取消的返回值
  649. }
  650. if (context.reportProgress != null)
  651. {
  652. context.reportProgress(iCount);
  653. }
  654. }
  655. if (iFalse != 0)
  656. {
  657. errMsg = ($"总共{iCount}条数据更新完成,但有{iFalse}条更新发生错误!");
  658. Global.writeLog($"{errMsg}\r\n{string.Join("\r\n", errList)}");
  659. }
  660. else
  661. {
  662. errMsg = ($"全部数据({iCount}条)更新完成");
  663. }
  664. return iFalse;
  665. }
  666. public void batchUpdateMappedInsuInfo(JObject joIn, Form frm)
  667. {
  668. //条件
  669. JObject joCondition = (JObject)joIn["condition"].DeepClone();
  670. switch (joCondition["funno"].ToString())
  671. {
  672. case "1312":
  673. action = updateAuxInfoWrapper;
  674. trade = trade.GetByCode("1312");
  675. Global.writeLog("updateAuxInfoWrapper");
  676. break;
  677. case "1315":
  678. action = updateSelfRatioWrapper;
  679. trade = trade.GetByCode("1319");
  680. Global.writeLog("updateSelfRatioWrapper");
  681. break;
  682. case "1318":
  683. action = updateCellPriceWrapper;
  684. trade = trade.GetByCode("1318");
  685. Global.writeLog("updateCellPriceWrapper");
  686. break;
  687. default:
  688. break;
  689. }
  690. ProgressWrapper _dataLoader;
  691. _dataLoader = new ProgressWrapper(updateMappedInsuInfo, frm);
  692. _dataLoader.SetProgressBar(ProgressBarStyle.Continuous, "正在更新...", 50);
  693. _dataLoader.Start(new object[] {joIn }, (result, errMsg) =>
  694. {
  695. // 在这里处理结果和错误信息
  696. if (result == 0)
  697. {
  698. MessageBox.Show(errMsg);
  699. }
  700. else
  701. {
  702. MessageBox.Show(errMsg);
  703. }
  704. });
  705. }
  706. public void batchUpdateMappedInsuInfo(Func<JObject, OutParamWrapper, int> _action,Form frm)
  707. {
  708. action = _action;
  709. string sqlStr = $"select * from HB_MedInsuMapRelation where Interface_Dr='{Global.inf.interfaceDr}' and Hospital_Dr ='{Global.inf.hospitalDr}'";
  710. JObject joSqlstr = new JObject();
  711. joSqlstr.Add("sqlStr", sqlStr);
  712. JObject joRtn = mIS.QueryMappedData(joSqlstr, "查询所有已对照数据");
  713. iTotalCount = int.Parse(joRtn["result"]["total"].ToString());
  714. dtAllMapped = (DataTable)joRtn["result"]["data"].ToObject(typeof(DataTable));
  715. ProgressWrapper _dataLoader;
  716. _dataLoader = new ProgressWrapper(updateMappedInsuInfo, frm);
  717. _dataLoader.SetProgressBar(ProgressBarStyle.Continuous, "正在更新...", 50);
  718. _dataLoader.Start(new object[] { iTotalCount }, (result, errMsg) =>
  719. {
  720. // 在这里处理结果和错误信息
  721. if (result == 0)
  722. {
  723. MessageBox.Show(errMsg);
  724. }
  725. else
  726. {
  727. MessageBox.Show(errMsg);
  728. }
  729. });
  730. }
  731. public int updateCellPriceWrapper(JObject jo, OutParamWrapper outParamWrapper)
  732. {
  733. string err;
  734. int iresult = updateCellingPrice(jo, out err);
  735. outParamWrapper.Value = err;
  736. return iresult;
  737. }
  738. private int updateCellingPrice(DataLoaderContext context, out string err)
  739. {
  740. if (context.setProgressMaximum != null)
  741. {
  742. context.setProgressMaximum(iTotalCount);
  743. }
  744. JObject jo = new JObject();
  745. dynamic joData = null;
  746. JObject joRtn = cBus.InvokeMedicalInsuranceInquiry(trade.GetCode(), joData);
  747. if (joRtn["infcode"].ToString() == "0")
  748. {
  749. DataTable dtAuxInfo = (DataTable)joRtn["output"]["data"].ToObject(typeof(DataTable));
  750. DateTime dtToday = DateTime.Today;
  751. string cellingPrice = "";
  752. string begndate = "";
  753. string enddate = "";
  754. int iAdpater = 0;
  755. foreach (DataRow dr in dtAuxInfo.Rows)
  756. {
  757. DateTime dtBegin = getDataRowValue(dr, "begndate") == "" ? Convert.ToDateTime("2000-01-01 00:00:00") : Convert.ToDateTime(getDataRowValue(dr, "begndate"));
  758. DateTime dtEnd = getDataRowValue(dr, "enddate") == "" ? Convert.ToDateTime("2099-01-01 00:00:00") : Convert.ToDateTime(getDataRowValue(dr, "enddate"));
  759. if ((dtBegin < dtToday) && (dtToday < dtEnd))
  760. {
  761. iAdpater++;
  762. cellingPrice = dr["hilist_pric_uplmt_amt"].ToString();
  763. begndate = dr["begndate"].ToString();
  764. enddate = dr["enddate"].ToString();
  765. }
  766. }
  767. //有且只能有一条数据符合
  768. if (iAdpater == 1)
  769. {
  770. JObject joPamam = new JObject();
  771. joPamam.Add("Code", JsonHelper.getDestValue(jo, "code"));
  772. joPamam.Add("HisType", JsonHelper.getDestValue(jo, "HisType"));
  773. joPamam.Add("StartDate", begndate);
  774. joPamam.Add("EndDate", enddate);
  775. joPamam.Add("CeilingPrice", cellingPrice);
  776. JObject joUpdateRtn = mIS.UpdateDirectoryBySelf(joPamam);
  777. string error = "";
  778. if (JsonHelper.parseIrisRtnValue(joUpdateRtn, out error) != 0)
  779. {
  780. err = "修改失败:" + error;
  781. return -1;
  782. }
  783. else
  784. {
  785. err = "修改成功";
  786. return 0;
  787. }
  788. }
  789. else
  790. {
  791. err = "中心返回符合条数的记录不唯一或者为空,请检查!";
  792. return -1;
  793. }
  794. }
  795. else
  796. {
  797. err = "查询中心数据出错,请检查!";
  798. return -1;
  799. }
  800. }
  801. public int updateCellingPrice(JObject joData, out string err)
  802. {
  803. err = "";
  804. //dynamic joData = (JObject)jo.DeepClone();
  805. JObject joRtn = cBus.InvokeMedicalInsuranceInquiry(TradeEnum.InsuPriceLimitDirectory.GetCode(), joData);
  806. if (joRtn["infcode"].ToString() == "0")
  807. {
  808. DataTable dtAuxInfo = (DataTable)joRtn["output"]["data"].ToObject(typeof(DataTable));
  809. DateTime dtToday = DateTime.Today;
  810. string cellingPrice = "";
  811. string begndate = "";
  812. string enddate = "";
  813. int iAdpater = 0;
  814. foreach (DataRow dr in dtAuxInfo.Rows)
  815. {
  816. DateTime dtBegin = getDataRowValue(dr, "begndate") == "" ? Convert.ToDateTime("2000-01-01 00:00:00") : Convert.ToDateTime(getDataRowValue(dr, "begndate"));
  817. DateTime dtEnd = getDataRowValue(dr, "enddate") == "" ? Convert.ToDateTime("2099-01-01 00:00:00") : Convert.ToDateTime(getDataRowValue(dr, "enddate"));
  818. if ((dtBegin < dtToday) && (dtToday < dtEnd))
  819. {
  820. iAdpater++;
  821. cellingPrice = dr["hilist_pric_uplmt_amt"].ToString();
  822. begndate = dr["begndate"].ToString();
  823. enddate = dr["enddate"].ToString();
  824. }
  825. }
  826. //有且只能有一条数据符合
  827. if (iAdpater == 1)
  828. {
  829. JObject joPamam = new JObject();
  830. joPamam.Add("Code", JsonHelper.getDestValue(joData, "code"));
  831. joPamam.Add("HisType", JsonHelper.getDestValue(joData, "HisType"));
  832. joPamam.Add("StartDate", begndate);
  833. joPamam.Add("EndDate", enddate);
  834. joPamam.Add("CeilingPrice", cellingPrice);
  835. JObject joUpdateRtn = mIS.UpdateDirectoryBySelf(joPamam);
  836. string error = "";
  837. if (JsonHelper.parseIrisRtnValue(joUpdateRtn, out error) != 0)
  838. {
  839. err = "修改失败:" + error;
  840. return -1;
  841. }
  842. else
  843. {
  844. err = "修改成功";
  845. return 0;
  846. }
  847. }
  848. else
  849. {
  850. err = "中心返回符合条数的记录不唯一或者为空,请检查!";
  851. return -1;
  852. }
  853. }
  854. else
  855. {
  856. err = "查询中心数据出错,请检查!";
  857. return -1;
  858. }
  859. }
  860. private int updateSelfRatioWrapper(JObject jo, OutParamWrapper outParamWrapper)
  861. {
  862. string err;
  863. int iresult = updateSelfRatioInfo(jo, out err);
  864. outParamWrapper.Value = err;
  865. return iresult;
  866. }
  867. public int updateSelfRatioInfo(JObject jo, out string err)
  868. {
  869. err = "";
  870. dynamic joData = (JObject)jo.DeepClone();
  871. JObject joRtn = cBus.InvokeMedicalInsuranceInquiry(TradeEnum.PrepayPercentDirectory.GetCode(), joData);
  872. if (joRtn["infcode"].ToString() == "0")
  873. {
  874. DataTable dtRatioInfo = (DataTable)joRtn["output"]["data"].ToObject(typeof(DataTable));
  875. DateTime dtToday = DateTime.Today;
  876. string cellingPrice = "";
  877. string begndate = "";
  878. string enddate = "";
  879. int iAdpater = 0;
  880. var dataArray = JArray.FromObject(joRtn["output"]["data"]);
  881. DateTime today = DateTime.Today;
  882. var groupedResult = dataArray
  883. .Where(item =>
  884. {
  885. if (DateTime.TryParse(item["enddate"]?.ToString(), out var endDate))
  886. {
  887. return endDate.Date >= today.Date;
  888. }
  889. return false;
  890. })
  891. .GroupBy(item => item["selfpay_prop_psn_type"]?.ToString());
  892. JArray joArray = new JArray();
  893. foreach (var group in groupedResult)
  894. {
  895. foreach (var item in group)
  896. {
  897. // 将 JsonNode 转换为 JObject
  898. JObject jObj = JObject.Parse(item.ToString());
  899. dynamic joTmp = new JObject();
  900. joTmp.HospitalDr = Global.inf.hospitalDr;
  901. joTmp.InterfaceDr = Global.inf.interfaceDr;
  902. joTmp.updateUserID = Global.user.ID;
  903. joTmp.Code = jObj["hilist_code"];
  904. joTmp.PersonnelType = jObj["selfpay_prop_psn_type"];
  905. joTmp.ProportionType = jObj["selfpay_prop_type"];
  906. joTmp.Proportion = jObj["selfpay_prop"];
  907. joTmp.BeginDate = jObj["begndate"];
  908. joTmp.EndDate = jObj["enddate"];
  909. joTmp.InsuranceAreaCode = jObj["insu_admdvs"];
  910. joTmp.PoolAreaNO = jObj["poolarea_no"];
  911. joTmp.ValidFlag = jObj["vali_flag"];
  912. joTmp.RequiredID = jObj["rid"];
  913. joArray.Add(joTmp);
  914. }
  915. }
  916. string errMsg = "";
  917. InvokeHelper invoker = new InvokeHelper();
  918. joRtn = invoker.invokeInsuService(JsonHelper.setIrisInpar("09010085", joArray).ToString(), "设置自费比例");
  919. if (JsonHelper.parseIrisRtnValue(joRtn, out errMsg) != 0)
  920. {
  921. err = errMsg;
  922. return -1;
  923. }
  924. else
  925. {
  926. err = ("更新成功!");
  927. return 0;
  928. }
  929. }
  930. else
  931. {
  932. err = "查询中心数据出错,请检查!";
  933. return -1;
  934. }
  935. }
  936. private int updateAuxInfoWrapper(JObject jo, OutParamWrapper outParamWrapper)
  937. {
  938. string err;
  939. int iresult = updateAuxInfo(jo, out err);
  940. outParamWrapper.Value = err;
  941. return iresult;
  942. }
  943. public int updateAuxInfo(JObject jo, out string err)
  944. {
  945. err = "";
  946. dynamic joData = (JObject)jo.DeepClone();
  947. JObject joRtn = cBus.InvokeMedicalInsuranceInquiry(TradeEnum.InsuDirectory.GetCode(), joData);
  948. if (joRtn["infcode"].ToString() == "0")
  949. {
  950. DataTable dtAuxInfo = (DataTable)joRtn["output"]["data"].ToObject(typeof(DataTable));
  951. DateTime dtToday = DateTime.Today;
  952. string chrgitm_lv = "";
  953. string begndate = "";
  954. string enddate = "";
  955. string list_type = "";
  956. string med_chrgitm_type = "";
  957. int iAdpater = 0;
  958. foreach (DataRow dr in dtAuxInfo.Rows)
  959. {
  960. DateTime dtBegin = getDataRowValue(dr, "begndate") == "" ? Convert.ToDateTime("2000-01-01 00:00:00") : Convert.ToDateTime(getDataRowValue(dr, "begndate"));
  961. DateTime dtEnd = getDataRowValue(dr, "enddate") == "" ? Convert.ToDateTime("2099-01-01 00:00:00") : Convert.ToDateTime(getDataRowValue(dr, "enddate"));
  962. if ((dtBegin < dtToday) && (dtToday < dtEnd))
  963. {
  964. iAdpater++;
  965. chrgitm_lv = dr["chrgitm_lv"].ToString();
  966. begndate = dtBegin.ToString("yyyy-MM-dd");
  967. enddate = dtEnd.ToString("yyyy-MM-dd");
  968. list_type = dr["list_type"].ToString();
  969. med_chrgitm_type = dr["med_chrgitm_type"].ToString();
  970. Global.writeLog($"符合--rid:{dr["rid"]},begndate:{dtBegin},enddate:{dtEnd}");
  971. }
  972. else
  973. {
  974. Global.writeLog($"不符合--rid:{dr["rid"]},begndate:{dtBegin},enddate:{dtEnd}");
  975. }
  976. }
  977. //有且只能有一条数据符合
  978. if (iAdpater == 1)
  979. {
  980. JObject joPamam = new JObject();
  981. joPamam.Add("Code", JsonHelper.getDestValue(jo, "code"));
  982. joPamam.Add("HisType", JsonHelper.getDestValue(jo, "HisType"));
  983. joPamam.Add("StartDate", begndate);
  984. joPamam.Add("EndDate", enddate);
  985. joPamam.Add("ChargeItemLevel", chrgitm_lv);
  986. joPamam.Add("ListType", list_type);
  987. joPamam.Add("ChargeItemType", med_chrgitm_type);
  988. JObject joUpdateRtn = mIS.UpdateDirectoryBySelf(joPamam);
  989. string error = "";
  990. if (JsonHelper.parseIrisRtnValue(joUpdateRtn, out error) != 0)
  991. {
  992. err = "修改失败:" + error;
  993. return -1;
  994. }
  995. else
  996. {
  997. err = "修改成功";
  998. return 0;
  999. }
  1000. }
  1001. else
  1002. {
  1003. err = "中心返回符合条数的记录不唯一或者为空,请检查!";
  1004. return -1;
  1005. }
  1006. }
  1007. else
  1008. {
  1009. err = "查询中心数据出错,请检查!";
  1010. return -1;
  1011. }
  1012. }
  1013. public int updateAuxAndCellPrice(JObject jo, out string error)
  1014. {
  1015. string err = "";
  1016. int iResult = 0;
  1017. error = "";
  1018. if (updateAuxInfo(jo, out err) != 0)
  1019. {
  1020. error = $"更新目录信息失败{err}";
  1021. iResult--;
  1022. }
  1023. //err = "";
  1024. //if (updateCellingPrice(jo, out err) != 0)
  1025. //{
  1026. // error = $"{error};更新限价信息失败{err}";
  1027. // iResult--;
  1028. //}
  1029. return iResult;
  1030. }
  1031. #endregion
  1032. #region 导入
  1033. #endregion
  1034. #region 处理DataError
  1035. public void dataGridView_DataError(object sender, DataGridViewDataErrorEventArgs e)
  1036. {
  1037. // 🔴 关键:阻止异常继续抛出,程序不会崩溃
  1038. e.ThrowException = false;
  1039. //// 可选:记录日志(用于调试)
  1040. //System.Diagnostics.Debug.WriteLine($"[DataError] Context: {e.Context}, Error: {e.Exception.Message}");
  1041. //// 可选:根据需要清理单元格
  1042. //if (e.Context == DataGridViewDataErrorContexts.Parsing)
  1043. //{
  1044. // // 解析失败时,可以清空单元格或设置默认值
  1045. // DataGridView dgv = (DataGridView)sender;
  1046. // dgv[e.ColumnIndex, e.RowIndex].Value = null; // 或其他默认值
  1047. //}
  1048. }
  1049. #endregion
  1050. }
  1051. public class DataFilter
  1052. {
  1053. public string HisCodeOrName { get; set; }
  1054. public string Spec { get; set; }
  1055. public string InsuCodeOrName { get; set; }
  1056. public HisDirectoryCategoryEnum hisDirectoryCategory { get; set; }
  1057. public MapFlagEnum mapFlag { get; set; }
  1058. }
  1059. }