DirectoryMapService.cs 43 KB

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