SiDownloadService.java 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127
  1. package thyyxxk.webserver.service.medicalinsurance;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.baomidou.mybatisplus.core.metadata.IPage;
  5. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  6. import com.dtflys.forest.http.ForestResponse;
  7. import lombok.extern.slf4j.Slf4j;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.stereotype.Service;
  10. import thyyxxk.webserver.config.exception.ExceptionEnum;
  11. import thyyxxk.webserver.constants.Capacity;
  12. import thyyxxk.webserver.constants.sidicts.SiFunction;
  13. import thyyxxk.webserver.dao.his.medicalinsurance.SiDownloadDao;
  14. import thyyxxk.webserver.entity.ResultVo;
  15. import thyyxxk.webserver.entity.medicalinsurance.download.DldDictList;
  16. import thyyxxk.webserver.entity.medicalinsurance.download.*;
  17. import thyyxxk.webserver.service.externalhttp.SiExecSrvc;
  18. import thyyxxk.webserver.utils.*;
  19. import java.nio.file.Files;
  20. import java.nio.file.Paths;
  21. import java.util.*;
  22. /**
  23. * @description: 医保目录下载服务
  24. * @author: DingJie
  25. * @create: 2021-06-23 15:17:03
  26. **/
  27. @Service
  28. @Slf4j
  29. public class SiDownloadService {
  30. private static final String RESULT_CODE = "infcode";
  31. private static final String ERROR_MESSAGE = "err_msg";
  32. private static final String OUTPUT = "output";
  33. private static final String BEGIN_VERSION = "V00";
  34. private final ExecService exec;
  35. private final SiDownloadDao dnlddao;
  36. private final SiExecSrvc execSrvc;
  37. @Autowired
  38. public SiDownloadService(ExecService exec, SiDownloadDao dnlddao, SiExecSrvc execSrvc) {
  39. this.exec = exec;
  40. this.dnlddao = dnlddao;
  41. this.execSrvc = execSrvc;
  42. }
  43. public ResultVo<Map<String, Object>> executeDownload(DwnldPrm prm) {
  44. String v = StringUtil.nullIf(prm.getVersion(), BEGIN_VERSION);
  45. switch (prm.getCode()) {
  46. case "1301":
  47. return downloadPatentAndWesternMedicineCatalogue(v);
  48. case "1302":
  49. return downloadChineseHerbalCatalogue(v);
  50. case "1303":
  51. return downloadHospitalDosage(v);
  52. case "1304":
  53. return downloadEthnicMedicine(prm);
  54. case "1305":
  55. return downloadMedicalServiceItemsCatalogue(v);
  56. case "1306":
  57. return downloadMedicalSuppliesCatalogue(v);
  58. case "1307":
  59. return downloadDiseasesAndDiagnosisCatalogue(v);
  60. case "1308":
  61. return downloadOperationCatalogue(v);
  62. case "1309":
  63. return downloadOutpatientSpecialChronicDiseasesCatalogue(v);
  64. case "1310":
  65. return downloadPayByDiseaseCatalogue(v);
  66. case "1311":
  67. return downloadDaytimeSurgeryDiseasesCatalogue(v);
  68. case "1312":
  69. return downloadMedicalInsuranceCatalogue(prm);
  70. case "1313":
  71. return downloadTumorMorphologyCatalogue(v);
  72. case "1314":
  73. return downloadTraditionalChineseDiseasesCatalogue(v);
  74. case "1315":
  75. return downloadTcmSyndromeCatalogue(v);
  76. case "1316":
  77. return downloadMedicalInsuranceMatchCatalogue(prm);
  78. case "1317":
  79. return downloadMedicalInstitutionMatchCatalogue(prm);
  80. case "1318":
  81. return downloadMedicalInsurancePriceLimitCatalogue(prm);
  82. case "1319":
  83. return downloadMedicalInsurancePayFirstCatalogue(prm);
  84. case "1319_save":
  85. return saveMedicalInsurancePayFirstCatalogue(prm);
  86. case "1901":
  87. return downloadDictionaryList(prm);
  88. }
  89. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有找到此目录下载的功能号。");
  90. }
  91. public ResultVo<Map<String, Object>> queryFromHis(DwnldPrm prm) {
  92. Map<String, Object> map = new HashMap<>(Capacity.TWO);
  93. IPage iPage;
  94. switch (prm.getCode()) {
  95. case "1301":
  96. iPage = new Page<SiDlPtntWstnMdcn>(prm.getPageNum(), prm.getPageSize());
  97. iPage = dnlddao.selectSiDlPtntWstnMdcnPage(iPage);
  98. map.put("totalSize", iPage.getTotal());
  99. map.put("list", iPage.getRecords());
  100. return ResultVoUtil.success(map);
  101. case "1302":
  102. iPage = new Page<SiDlChnsHbl>(prm.getPageNum(), prm.getPageSize());
  103. iPage = dnlddao.selectSiDlChnsHblPage(iPage);
  104. map.put("totalSize", iPage.getTotal());
  105. map.put("list", iPage.getRecords());
  106. return ResultVoUtil.success(map);
  107. case "1303":
  108. iPage = new Page<SiDlInstPrptn>(prm.getPageNum(), prm.getPageSize());
  109. iPage = dnlddao.selectSiDlInstPrptnPage(iPage);
  110. map.put("totalSize", iPage.getTotal());
  111. map.put("list", iPage.getRecords());
  112. return ResultVoUtil.success(map);
  113. case "1305":
  114. iPage = new Page<SiDlMdcnSrvc>(prm.getPageNum(), prm.getPageSize());
  115. iPage = dnlddao.selectSiDlMdcnSrvcPage(iPage);
  116. map.put("totalSize", iPage.getTotal());
  117. map.put("list", iPage.getRecords());
  118. return ResultVoUtil.success(map);
  119. case "1306":
  120. iPage = new Page<SiDlMdcnSply>(prm.getPageNum(), prm.getPageSize());
  121. iPage = dnlddao.selectSiDlMdcnSplyPage(iPage);
  122. map.put("totalSize", iPage.getTotal());
  123. map.put("list", iPage.getRecords());
  124. return ResultVoUtil.success(map);
  125. case "1307":
  126. iPage = new Page<SiDlDssDns>(prm.getPageNum(), prm.getPageSize());
  127. iPage = dnlddao.selectSiDlDssDnsPage(iPage);
  128. map.put("totalSize", iPage.getTotal());
  129. map.put("list", iPage.getRecords());
  130. return ResultVoUtil.success(map);
  131. case "1308":
  132. iPage = new Page<SiDlOprtn>(prm.getPageNum(), prm.getPageSize());
  133. iPage = dnlddao.selectSiDlOprtnPage(iPage);
  134. map.put("totalSize", iPage.getTotal());
  135. map.put("list", iPage.getRecords());
  136. return ResultVoUtil.success(map);
  137. case "1309":
  138. iPage = new Page<SiDlSlwSpcChr>(prm.getPageNum(), prm.getPageSize());
  139. iPage = dnlddao.selectSiDlSlwSpcChrPage(iPage);
  140. map.put("totalSize", iPage.getTotal());
  141. map.put("list", iPage.getRecords());
  142. return ResultVoUtil.success(map);
  143. case "1310":
  144. iPage = new Page<SiDlPayByDss>(prm.getPageNum(), prm.getPageSize());
  145. iPage = dnlddao.selectSiDlPayByDssPage(iPage);
  146. map.put("totalSize", iPage.getTotal());
  147. map.put("list", iPage.getRecords());
  148. return ResultVoUtil.success(map);
  149. case "1311":
  150. iPage = new Page<SiDlDytmSrgyDss>(prm.getPageNum(), prm.getPageSize());
  151. iPage = dnlddao.selectSiDlDytmSrgyDssPage(iPage);
  152. map.put("totalSize", iPage.getTotal());
  153. map.put("list", iPage.getRecords());
  154. return ResultVoUtil.success(map);
  155. case "1313":
  156. iPage = new Page<SiDlTmrMrphlgy>(prm.getPageNum(), prm.getPageSize());
  157. iPage = dnlddao.selectSiDlTmrMrphlgyPage(iPage);
  158. map.put("totalSize", iPage.getTotal());
  159. map.put("list", iPage.getRecords());
  160. return ResultVoUtil.success(map);
  161. case "1314":
  162. iPage = new Page<SiDlTrdtnlChnsDss>(prm.getPageNum(), prm.getPageSize());
  163. iPage = dnlddao.selectSiDlTrdtnlChnsDssPage(iPage);
  164. map.put("totalSize", iPage.getTotal());
  165. map.put("list", iPage.getRecords());
  166. return ResultVoUtil.success(map);
  167. case "1315":
  168. iPage = new Page<SiDlTcmSyndr>(prm.getPageNum(), prm.getPageSize());
  169. iPage = dnlddao.selectSiDlTcmSyndrPage(iPage);
  170. map.put("totalSize", iPage.getTotal());
  171. map.put("list", iPage.getRecords());
  172. return ResultVoUtil.success(map);
  173. }
  174. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有找到此目录下载的功能号。");
  175. }
  176. public ResultVo<Map<String, Object>> downloadPatentAndWesternMedicineCatalogue(String v) {
  177. ResultVo<String> dwnldrslt = dwnldPtntWstnMdcnCtlg(v);
  178. while (dwnldrslt.getCode() == ExceptionEnum.SUCCESS.getCode()) {
  179. dwnldrslt = dwnldPtntWstnMdcnCtlg(dwnldrslt.getData());
  180. }
  181. return ResultVoUtil.success();
  182. }
  183. public ResultVo<String> dwnldPtntWstnMdcnCtlg(String version) {
  184. JSONObject result = getOrdinaryDownloadResult(SiFunction.DOWNLOAD_PATENT_AND_WESTERN_MEDICINE_CATALOGUE, version);
  185. log.info("【操作员:{}】,西药中成药目录下载:版本号:{},结果:{}", TokenUtil.getInstance().getTokenUserId(), version, result);
  186. if (null == result) {
  187. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  188. }
  189. if (null == result.getInteger(RESULT_CODE)) {
  190. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  191. }
  192. String versionName = null;
  193. if (result.getIntValue(RESULT_CODE) == 0) {
  194. JSONObject output = result.getJSONObject(OUTPUT);
  195. String fileQuryNo = output.getString("file_qury_no");
  196. String filename = output.getString("filename");
  197. String filePath = downloadFile(fileQuryNo, filename);
  198. if (null == filePath) {
  199. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR, "网络异常,下载失败!");
  200. }
  201. Queue<String> queue = SiUtil.readTxtFile(filePath);
  202. if (version.equals(BEGIN_VERSION)) {
  203. dnlddao.truncatePtntWstnMdcnTable();
  204. }
  205. List<SiDlPtntWstnMdcn> list = new ArrayList<>();
  206. while (!queue.isEmpty()) {
  207. String tempstr = queue.poll();
  208. list.add(new SiDlPtntWstnMdcn(tempstr));
  209. if (null == versionName) {
  210. versionName = list.get(0).getVersionName();
  211. }
  212. if (list.size() == 20) {
  213. dnlddao.insertPtntWstnMdcnBatch(list);
  214. list.clear();
  215. }
  216. }
  217. if (list.size() > 0) {
  218. dnlddao.insertPtntWstnMdcnBatch(list);
  219. }
  220. if (StringUtil.notBlank(versionName)) {
  221. return ResultVoUtil.success(versionName);
  222. }
  223. }
  224. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  225. }
  226. public ResultVo<Map<String, Object>> downloadChineseHerbalCatalogue(String v) {
  227. ResultVo<String> dwnldrslt = execDwnldChnsHrblCtlg(v);
  228. while (dwnldrslt.getCode() == ExceptionEnum.SUCCESS.getCode()) {
  229. dwnldrslt = execDwnldChnsHrblCtlg(dwnldrslt.getData());
  230. }
  231. return ResultVoUtil.success();
  232. }
  233. public ResultVo<Map<String, Object>> downloadHospitalDosage(String v) {
  234. JSONObject result = getOrdinaryDownloadResult(SiFunction.DOWNLOAD_INSTITUTIONS_PREPARATIONS_CATALOGUE, v);
  235. log.info("【操作员:{}】,医院制剂目录下载:版本号:{},结果:{}", TokenUtil.getInstance().getTokenUserId(), v, result);
  236. if (null == result) {
  237. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  238. }
  239. if (null == result.getInteger(RESULT_CODE)) {
  240. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  241. }
  242. if (result.getIntValue(RESULT_CODE) == 0) {
  243. JSONObject output = result.getJSONObject(OUTPUT);
  244. String fileQuryNo = output.getString("file_qury_no");
  245. String filename = output.getString("filename");
  246. String filePath = downloadFile(fileQuryNo, filename);
  247. if (null == filePath) {
  248. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR, "网络异常,下载失败!");
  249. }
  250. Map<String, Object> obj = new HashMap<>();
  251. obj.put("message", "下载成功");
  252. obj.put("path", filePath);
  253. return ResultVoUtil.success(obj);
  254. }
  255. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  256. }
  257. public ResultVo<String> execDwnldChnsHrblCtlg(String version) {
  258. JSONObject result = getOrdinaryDownloadResult(SiFunction.DOWNLOAD_CHINESE_HERBAL_CATALOGUE, version);
  259. log.info("【操作员:{}】,中药饮片目录下载:版本号:{},结果:{}", TokenUtil.getInstance().getTokenUserId(), version, result);
  260. if (null == result) {
  261. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  262. }
  263. if (null == result.getInteger(RESULT_CODE)) {
  264. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  265. }
  266. String versionName = null;
  267. if (result.getIntValue(RESULT_CODE) == 0) {
  268. JSONObject output = result.getJSONObject(OUTPUT);
  269. String fileQuryNo = output.getString("file_qury_no");
  270. String filename = output.getString("filename");
  271. String filePath = downloadFile(fileQuryNo, filename);
  272. if (null == filePath) {
  273. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR, "网络异常,下载失败!");
  274. }
  275. Queue<String> queue = SiUtil.readTxtFile(filePath);
  276. if (version.equals(BEGIN_VERSION)) {
  277. dnlddao.truncateChnsHblTable();
  278. }
  279. List<SiDlChnsHbl> list = new ArrayList<>();
  280. while (!queue.isEmpty()) {
  281. String tempstr = queue.poll();
  282. list.add(new SiDlChnsHbl(tempstr));
  283. if (null == versionName) {
  284. versionName = list.get(0).getVersionName();
  285. }
  286. if (list.size() == 20) {
  287. try {
  288. dnlddao.insertChnsHblBatch(list);
  289. list.clear();
  290. } catch (Exception e) {
  291. log.info("{}", JSONArray.toJSON(list));
  292. throw e;
  293. }
  294. }
  295. }
  296. if (!list.isEmpty()) {
  297. try {
  298. dnlddao.insertChnsHblBatch(list);
  299. } catch (Exception e) {
  300. log.info("{}", JSONArray.toJSON(list));
  301. throw e;
  302. }
  303. }
  304. if (StringUtil.notBlank(versionName)) {
  305. return ResultVoUtil.success(versionName);
  306. }
  307. }
  308. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  309. }
  310. public ResultVo<Map<String, Object>> downloadEthnicMedicine(DwnldPrm prm) {
  311. JSONObject input = exec.makeTradeHeader(SiFunction.DOWNLOAD_ETHNIC_MEDICINE);
  312. JSONObject data = new JSONObject();
  313. data.put("updt_time", DateUtil.formatDatetime(prm.getUpdtTime()));
  314. data.put("page_num", prm.getPageNum());
  315. data.put("page_size", prm.getPageSize());
  316. input.getJSONObject("input").put("data", data);
  317. JSONObject result = exec.executeTrade(input, SiFunction.DOWNLOAD_ETHNIC_MEDICINE);
  318. log.info("【操作员:{}】,民族药品目录下载:\n参数:{},\n结果:{}", TokenUtil.getInstance().getTokenUserId(), input, result);
  319. return getMapResultVo(result);
  320. }
  321. public ResultVo<Map<String, Object>> downloadMedicalServiceItemsCatalogue(String v) {
  322. ResultVo<String> dwnldrslt = execDwnldMdclSrvcItmsCtlg(v);
  323. while (dwnldrslt.getCode() == ExceptionEnum.SUCCESS.getCode()) {
  324. dwnldrslt = execDwnldMdclSrvcItmsCtlg(dwnldrslt.getData());
  325. }
  326. return ResultVoUtil.success();
  327. }
  328. public ResultVo<String> execDwnldMdclSrvcItmsCtlg(String version) {
  329. JSONObject result = getOrdinaryDownloadResult(SiFunction.DOWNLOAD_MEDICAL_SERVICE_ITEMS_CATALOGUE, version);
  330. log.info("【操作员:{}】,医疗服务项目目录下载:版本号:{},结果:{}", TokenUtil.getInstance().getTokenUserId(), version, result);
  331. if (null == result) {
  332. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  333. }
  334. if (null == result.getInteger(RESULT_CODE)) {
  335. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  336. }
  337. String versionName = null;
  338. if (result.getIntValue(RESULT_CODE) == 0) {
  339. JSONObject output = result.getJSONObject(OUTPUT);
  340. String fileQuryNo = output.getString("file_qury_no");
  341. String filename = output.getString("filename");
  342. String filePath = downloadFile(fileQuryNo, filename);
  343. if (null == filePath) {
  344. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR, "网络异常,下载失败!");
  345. }
  346. Queue<String> queue = SiUtil.readTxtFile(filePath);
  347. if (version.equals(BEGIN_VERSION)) {
  348. dnlddao.truncateMdcnSrvcTable();
  349. }
  350. List<SiDlMdcnSrvc> list = new ArrayList<>();
  351. while (!queue.isEmpty()) {
  352. String tempstr = queue.poll();
  353. list.add(new SiDlMdcnSrvc(tempstr));
  354. if (null == versionName) {
  355. versionName = list.get(0).getVersionName();
  356. }
  357. if (list.size() == 20) {
  358. dnlddao.insertMdcnSrvcBatch(list);
  359. list.clear();
  360. }
  361. }
  362. if (list.size() > 0) {
  363. dnlddao.insertMdcnSrvcBatch(list);
  364. }
  365. if (StringUtil.notBlank(versionName)) {
  366. return ResultVoUtil.success(versionName);
  367. }
  368. }
  369. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  370. }
  371. public ResultVo<Map<String, Object>> downloadMedicalSuppliesCatalogue(String v) {
  372. ResultVo<String> dwnldrslt = execDwnldMdclSpplsCtlg(v);
  373. while (dwnldrslt.getCode() == ExceptionEnum.SUCCESS.getCode()) {
  374. dwnldrslt = execDwnldMdclSpplsCtlg(dwnldrslt.getData());
  375. }
  376. return ResultVoUtil.success();
  377. }
  378. public ResultVo<String> execDwnldMdclSpplsCtlg(String version) {
  379. JSONObject result = getOrdinaryDownloadResult(SiFunction.DOWNLOAD_MEDICAL_SUPPLIES_CATALOGUE, version);
  380. log.info("【操作员:{}】,医用耗材目录下载:版本号:{},结果:{}", TokenUtil.getInstance().getTokenUserId(), version, result);
  381. if (null == result) {
  382. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  383. }
  384. if (null == result.getInteger(RESULT_CODE)) {
  385. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  386. }
  387. if (result.getIntValue(RESULT_CODE) == 0) {
  388. JSONObject output = result.getJSONObject(OUTPUT);
  389. String fileQuryNo = output.getString("file_qury_no");
  390. String filename = output.getString("filename");
  391. String filePath = downloadFile(fileQuryNo, filename);
  392. if (null == filePath) {
  393. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR, "网络异常,下载失败!");
  394. }
  395. Queue<String> queue = SiUtil.readTxtFile(filePath);
  396. if (version.equals(BEGIN_VERSION)) {
  397. dnlddao.truncateMdcnSplyTable();
  398. }
  399. List<SiDlMdcnSply> list = new ArrayList<>();
  400. String versionName = null;
  401. while (!queue.isEmpty()) {
  402. String tempstr = queue.poll();
  403. list.add(new SiDlMdcnSply(tempstr));
  404. if (null == versionName) {
  405. versionName = list.get(0).getVersionName();
  406. }
  407. if (list.size() == 20) {
  408. dnlddao.insertMdcnSplyBatch(list);
  409. list.clear();
  410. }
  411. }
  412. if (list.size() > 0) {
  413. dnlddao.insertMdcnSplyBatch(list);
  414. }
  415. if (StringUtil.notBlank(versionName)) {
  416. return ResultVoUtil.success(versionName);
  417. }
  418. }
  419. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  420. }
  421. public ResultVo<Map<String, Object>> downloadDiseasesAndDiagnosisCatalogue(String v) {
  422. ResultVo<String> dwnldrslt = execDwnldDssDgnssCtlg(v);
  423. while (dwnldrslt.getCode() == ExceptionEnum.SUCCESS.getCode()) {
  424. dwnldrslt = execDwnldDssDgnssCtlg(dwnldrslt.getData());
  425. }
  426. return ResultVoUtil.success();
  427. }
  428. public ResultVo<String> execDwnldDssDgnssCtlg(String version) {
  429. JSONObject result = getOrdinaryDownloadResult(SiFunction.DOWNLOAD_DISEASES_AND_DIAGNOSIS_CATALOGUE, version);
  430. log.info("【操作员:{}】,疾病与诊断目录下载:版本号:{},结果:{}", TokenUtil.getInstance().getTokenUserId(), version, result);
  431. if (null == result) {
  432. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  433. }
  434. if (null == result.getInteger(RESULT_CODE)) {
  435. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  436. }
  437. String versionName = null;
  438. if (result.getIntValue(RESULT_CODE) == 0) {
  439. JSONObject output = result.getJSONObject(OUTPUT);
  440. String fileQuryNo = output.getString("file_qury_no");
  441. String filename = output.getString("filename");
  442. String filePath = downloadFile(fileQuryNo, filename);
  443. if (null == filePath) {
  444. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR, "网络异常,下载失败!");
  445. }
  446. Queue<String> queue = SiUtil.readTxtFile(filePath);
  447. if (version.equals(BEGIN_VERSION)) {
  448. dnlddao.truncateDssDnsTable();
  449. }
  450. List<SiDlDssDns> list = new ArrayList<>();
  451. while (!queue.isEmpty()) {
  452. String tempstr = queue.poll();
  453. list.add(new SiDlDssDns(tempstr));
  454. if (null == versionName) {
  455. versionName = list.get(0).getVersionName();
  456. }
  457. if (list.size() == 20) {
  458. dnlddao.insertDssDnsBatch(list);
  459. list.clear();
  460. }
  461. }
  462. if (list.size() > 0) {
  463. dnlddao.insertDssDnsBatch(list);
  464. }
  465. if (StringUtil.notBlank(versionName)) {
  466. return ResultVoUtil.success(versionName);
  467. }
  468. }
  469. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  470. }
  471. public ResultVo<Map<String, Object>> downloadOperationCatalogue(String v) {
  472. ResultVo<String> dwnldrslt = execDwnldOprtnCtlg(v);
  473. while (dwnldrslt.getCode() == ExceptionEnum.SUCCESS.getCode()) {
  474. dwnldrslt = execDwnldOprtnCtlg(dwnldrslt.getData());
  475. }
  476. return ResultVoUtil.success();
  477. }
  478. public ResultVo<String> execDwnldOprtnCtlg(String version) {
  479. JSONObject result = getOrdinaryDownloadResult(SiFunction.DOWNLOAD_OPERATION_CATALOGUE, version);
  480. log.info("【操作员:{}】,手术操作目录下载:版本号:{},结果:{}", TokenUtil.getInstance().getTokenUserId(), version, result);
  481. if (null == result) {
  482. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  483. }
  484. if (null == result.getInteger(RESULT_CODE)) {
  485. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  486. }
  487. String versionName = null;
  488. if (result.getIntValue(RESULT_CODE) == 0) {
  489. JSONObject output = result.getJSONObject(OUTPUT);
  490. String fileQuryNo = output.getString("file_qury_no");
  491. String filename = output.getString("filename");
  492. String filePath = downloadFile(fileQuryNo, filename);
  493. if (null == filePath) {
  494. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR, "网络异常,下载失败!");
  495. }
  496. Queue<String> queue = SiUtil.readTxtFile(filePath);
  497. if (version.equals(BEGIN_VERSION)) {
  498. dnlddao.truncateOprtnTable();
  499. }
  500. List<SiDlOprtn> list = new ArrayList<>();
  501. while (!queue.isEmpty()) {
  502. String tempstr = queue.poll();
  503. String[] arr = tempstr.split("\t");
  504. if (StringUtil.isBlank(arr[10])) {
  505. continue;
  506. }
  507. list.add(new SiDlOprtn(arr));
  508. if (null == versionName) {
  509. versionName = list.get(0).getVersionName();
  510. }
  511. if (list.size() == 20) {
  512. dnlddao.insertOprtnBatch(list);
  513. list.clear();
  514. }
  515. }
  516. if (list.size() > 0) {
  517. dnlddao.insertOprtnBatch(list);
  518. }
  519. if (StringUtil.notBlank(versionName)) {
  520. return ResultVoUtil.success(versionName);
  521. }
  522. }
  523. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  524. }
  525. public ResultVo<Map<String, Object>> downloadOutpatientSpecialChronicDiseasesCatalogue(String v) {
  526. ResultVo<String> dwnldrslt = execDwnldOutptntSpclChrncDssCtlg(v);
  527. while (dwnldrslt.getCode() == ExceptionEnum.SUCCESS.getCode()) {
  528. dwnldrslt = execDwnldOutptntSpclChrncDssCtlg(dwnldrslt.getData());
  529. }
  530. return ResultVoUtil.success();
  531. }
  532. public ResultVo<String> execDwnldOutptntSpclChrncDssCtlg(String version) {
  533. JSONObject result = getOrdinaryDownloadResult(SiFunction.DOWNLOAD_OUTPATIENT_SPECIAL_CHRONIC_DISEASES_CATALOGUE, version);
  534. log.info("【操作员:{}】,门诊慢特病种目录下载:版本号:{},结果:{}", TokenUtil.getInstance().getTokenUserId(), version, result);
  535. if (null == result) {
  536. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  537. }
  538. if (null == result.getInteger(RESULT_CODE)) {
  539. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  540. }
  541. String versionName = null;
  542. if (result.getIntValue(RESULT_CODE) == 0) {
  543. JSONObject output = result.getJSONObject(OUTPUT);
  544. String fileQuryNo = output.getString("file_qury_no");
  545. String filename = output.getString("filename");
  546. String filePath = downloadFile(fileQuryNo, filename);
  547. if (null == filePath) {
  548. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR, "网络异常,下载失败!");
  549. }
  550. Queue<String> queue = SiUtil.readTxtFile(filePath);
  551. if (version.equals(BEGIN_VERSION)) {
  552. dnlddao.truncateSlwSpcChrTable();
  553. }
  554. List<SiDlSlwSpcChr> list = new ArrayList<>();
  555. while (!queue.isEmpty()) {
  556. String tempstr = queue.poll();
  557. list.add(new SiDlSlwSpcChr(tempstr));
  558. if (null == versionName) {
  559. versionName = list.get(0).getVersionName();
  560. }
  561. if (list.size() == 20) {
  562. dnlddao.insertSlwSpcChrBatch(list);
  563. list.clear();
  564. }
  565. }
  566. if (list.size() > 0) {
  567. dnlddao.insertSlwSpcChrBatch(list);
  568. }
  569. if (StringUtil.notBlank(versionName)) {
  570. return ResultVoUtil.success(versionName);
  571. }
  572. }
  573. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  574. }
  575. public ResultVo<Map<String, Object>> downloadPayByDiseaseCatalogue(String v) {
  576. ResultVo<String> dwnldrslt = execDwnldPayByDssCtlg(v);
  577. while (dwnldrslt.getCode() == ExceptionEnum.SUCCESS.getCode()) {
  578. dwnldrslt = execDwnldPayByDssCtlg(dwnldrslt.getData());
  579. }
  580. return ResultVoUtil.success();
  581. }
  582. public ResultVo<String> execDwnldPayByDssCtlg(String version) {
  583. JSONObject result = getOrdinaryDownloadResult(SiFunction.DOWNLOAD_PAY_BY_DISEASE_CATALOGUE, version);
  584. log.info("【操作员:{}】,按病种付费病种目录下载:版本号:{},结果:{}", TokenUtil.getInstance().getTokenUserId(), version, result);
  585. if (null == result) {
  586. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  587. }
  588. if (null == result.getInteger(RESULT_CODE)) {
  589. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  590. }
  591. String versionName = null;
  592. if (result.getIntValue(RESULT_CODE) == 0) {
  593. JSONObject output = result.getJSONObject(OUTPUT);
  594. String fileQuryNo = output.getString("file_qury_no");
  595. String filename = output.getString("filename");
  596. String filePath = downloadFile(fileQuryNo, filename);
  597. if (null == filePath) {
  598. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR, "网络异常,下载失败!");
  599. }
  600. Queue<String> queue = SiUtil.readTxtFile(filePath);
  601. if (version.equals(BEGIN_VERSION)) {
  602. dnlddao.truncatePayByDssTable();
  603. }
  604. List<SiDlPayByDss> list = new ArrayList<>();
  605. while (!queue.isEmpty()) {
  606. String tempstr = queue.poll();
  607. list.add(new SiDlPayByDss(tempstr));
  608. if (null == versionName) {
  609. versionName = list.get(0).getVersionName();
  610. }
  611. if (list.size() == 20) {
  612. dnlddao.insertPayByDssBatch(list);
  613. list.clear();
  614. }
  615. }
  616. if (list.size() > 0) {
  617. dnlddao.insertPayByDssBatch(list);
  618. }
  619. if (StringUtil.notBlank(versionName)) {
  620. return ResultVoUtil.success(versionName);
  621. }
  622. }
  623. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  624. }
  625. public ResultVo<Map<String, Object>> downloadDaytimeSurgeryDiseasesCatalogue(String v) {
  626. ResultVo<String> dwnldrslt = execDwnldDytmSrgryDssCtlg(v);
  627. while (dwnldrslt.getCode() == ExceptionEnum.SUCCESS.getCode()) {
  628. dwnldrslt = execDwnldDytmSrgryDssCtlg(dwnldrslt.getData());
  629. }
  630. return ResultVoUtil.success();
  631. }
  632. public ResultVo<String> execDwnldDytmSrgryDssCtlg(String version) {
  633. JSONObject result = getOrdinaryDownloadResult(SiFunction.DOWNLOAD_DAYTIME_SURGERY_DISEASES_CATALOGUE, version);
  634. log.info("【操作员:{}】,日间手术治疗病种目录下载:版本号:{},结果:{}", TokenUtil.getInstance().getTokenUserId(), version, result);
  635. if (null == result) {
  636. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  637. }
  638. if (null == result.getInteger(RESULT_CODE)) {
  639. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  640. }
  641. String versionName = null;
  642. if (result.getIntValue(RESULT_CODE) == 0) {
  643. JSONObject output = result.getJSONObject(OUTPUT);
  644. String fileQuryNo = output.getString("file_qury_no");
  645. String filename = output.getString("filename");
  646. String filePath = downloadFile(fileQuryNo, filename);
  647. if (null == filePath) {
  648. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR, "网络异常,下载失败!");
  649. }
  650. Queue<String> queue = SiUtil.readTxtFile(filePath);
  651. if (version.equals(BEGIN_VERSION)) {
  652. dnlddao.truncateDytmSrgyDssTable();
  653. }
  654. List<SiDlDytmSrgyDss> list = new ArrayList<>();
  655. while (!queue.isEmpty()) {
  656. String tempstr = queue.poll();
  657. list.add(new SiDlDytmSrgyDss(tempstr));
  658. if (null == versionName) {
  659. versionName = list.get(0).getVersionName();
  660. }
  661. if (list.size() == 20) {
  662. dnlddao.insertDytmSrgyDssBatch(list);
  663. list.clear();
  664. }
  665. }
  666. if (list.size() > 0) {
  667. dnlddao.insertDytmSrgyDssBatch(list);
  668. }
  669. if (StringUtil.notBlank(versionName)) {
  670. return ResultVoUtil.success(versionName);
  671. }
  672. }
  673. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  674. }
  675. public ResultVo<Map<String, Object>> downloadMedicalInsuranceCatalogue(DwnldPrm prm) {
  676. JSONObject input = exec.makeTradeHeader(SiFunction.DOWNLOAD_MEDICAL_INSURANCE_CATALOGUE);
  677. JSONObject data = new JSONObject();
  678. data.put("updt_time", DateUtil.formatDatetime(prm.getUpdtTime()));
  679. data.put("page_num", prm.getPageNum());
  680. data.put("page_size", prm.getPageSize());
  681. input.getJSONObject("input").put("data", data);
  682. JSONObject result = exec.executeTrade(input, SiFunction.DOWNLOAD_MEDICAL_INSURANCE_CATALOGUE);
  683. log.info("【操作员:{}】,医保目录信息查询:\n参数:{},\n结果:{}", TokenUtil.getInstance().getTokenUserId(), input, result);
  684. return getMapResultVo(result);
  685. }
  686. private ResultVo<Map<String, Object>> getMapResultVo(JSONObject result) {
  687. if (null == result) {
  688. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  689. }
  690. if (null == result.getInteger(RESULT_CODE)) {
  691. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  692. }
  693. if (result.getIntValue(RESULT_CODE) == 0) {
  694. JSONObject output = result.getJSONObject(OUTPUT);
  695. Map<String, Object> map = new HashMap<>(Capacity.TWO);
  696. map.put("totalSize", output.getIntValue("recordCounts"));
  697. map.put("list", output.getJSONArray("data"));
  698. return ResultVoUtil.success(map);
  699. }
  700. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  701. }
  702. public ResultVo<Map<String, Object>> downloadTumorMorphologyCatalogue(String v) {
  703. ResultVo<String> dwnldrslt = execDwnldTmrMrphlgyCtlg(v);
  704. while (dwnldrslt.getCode() == ExceptionEnum.SUCCESS.getCode()) {
  705. dwnldrslt = execDwnldTmrMrphlgyCtlg(dwnldrslt.getData());
  706. }
  707. return ResultVoUtil.success();
  708. }
  709. public ResultVo<String> execDwnldTmrMrphlgyCtlg(String version) {
  710. JSONObject result = getOrdinaryDownloadResult(SiFunction.DOWNLOAD_TUMOR_MORPHOLOGY_CATALOGUE, version);
  711. log.info("【操作员:{}】,肿瘤形态学目录下载:版本号:{},结果:{}", TokenUtil.getInstance().getTokenUserId(), version, result);
  712. if (null == result) {
  713. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  714. }
  715. if (null == result.getInteger(RESULT_CODE)) {
  716. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  717. }
  718. String versionName = null;
  719. if (result.getIntValue(RESULT_CODE) == 0) {
  720. JSONObject output = result.getJSONObject(OUTPUT);
  721. String fileQuryNo = output.getString("file_qury_no");
  722. String filename = output.getString("filename");
  723. String filePath = downloadFile(fileQuryNo, filename);
  724. if (null == filePath) {
  725. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR, "网络异常,下载失败!");
  726. }
  727. Queue<String> queue = SiUtil.readTxtFile(filePath);
  728. if (version.equals(BEGIN_VERSION)) {
  729. dnlddao.truncateTmrMrphlgyTable();
  730. }
  731. List<SiDlTmrMrphlgy> list = new ArrayList<>();
  732. while (!queue.isEmpty()) {
  733. String tempstr = queue.poll();
  734. list.add(new SiDlTmrMrphlgy(tempstr));
  735. if (null == versionName) {
  736. versionName = list.get(0).getVersionName();
  737. }
  738. if (list.size() == 20) {
  739. dnlddao.insertTmrMrphlgyBatch(list);
  740. list.clear();
  741. }
  742. }
  743. if (list.size() > 0) {
  744. dnlddao.insertTmrMrphlgyBatch(list);
  745. }
  746. if (StringUtil.notBlank(versionName)) {
  747. return ResultVoUtil.success(versionName);
  748. }
  749. }
  750. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  751. }
  752. public ResultVo<Map<String, Object>> downloadTraditionalChineseDiseasesCatalogue(String v) {
  753. ResultVo<String> dwnldrslt = execDwnldTrdtnlChnDssCtlg(v);
  754. while (dwnldrslt.getCode() == ExceptionEnum.SUCCESS.getCode()) {
  755. dwnldrslt = execDwnldTrdtnlChnDssCtlg(dwnldrslt.getData());
  756. }
  757. return ResultVoUtil.success();
  758. }
  759. public ResultVo<String> execDwnldTrdtnlChnDssCtlg(String version) {
  760. JSONObject result = getOrdinaryDownloadResult(SiFunction.DOWNLOAD_TRADITIONAL_CHINESE_DISEASES_CATALOGUE, version);
  761. log.info("【操作员:{}】,中医疾病目录下载:版本号:{},结果:{}", TokenUtil.getInstance().getTokenUserId(), version, result);
  762. if (null == result) {
  763. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  764. }
  765. if (null == result.getInteger(RESULT_CODE)) {
  766. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  767. }
  768. String versionName = null;
  769. if (result.getIntValue(RESULT_CODE) == 0) {
  770. JSONObject output = result.getJSONObject(OUTPUT);
  771. String fileQuryNo = output.getString("file_qury_no");
  772. String filename = output.getString("filename");
  773. String filePath = downloadFile(fileQuryNo, filename);
  774. if (null == filePath) {
  775. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR, "网络异常,下载失败!");
  776. }
  777. Queue<String> queue = SiUtil.readTxtFile(filePath);
  778. if (version.equals(BEGIN_VERSION)) {
  779. dnlddao.truncateTrdtnlChnsDssTable();
  780. }
  781. List<SiDlTrdtnlChnsDss> list = new ArrayList<>();
  782. while (!queue.isEmpty()) {
  783. String tempstr = queue.poll();
  784. list.add(new SiDlTrdtnlChnsDss(tempstr));
  785. if (null == versionName) {
  786. versionName = list.get(0).getVersionName();
  787. }
  788. if (list.size() == 20) {
  789. dnlddao.insertTrdtnlChnsDssBatch(list);
  790. list.clear();
  791. }
  792. }
  793. if (list.size() > 0) {
  794. dnlddao.insertTrdtnlChnsDssBatch(list);
  795. }
  796. if (StringUtil.notBlank(versionName)) {
  797. return ResultVoUtil.success(versionName);
  798. }
  799. }
  800. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  801. }
  802. public ResultVo<Map<String, Object>> downloadTcmSyndromeCatalogue(String v) {
  803. ResultVo<String> dwnldrslt = execDwnldTcmSyndrmCtlg(v);
  804. while (dwnldrslt.getCode() == ExceptionEnum.SUCCESS.getCode()) {
  805. dwnldrslt = execDwnldTcmSyndrmCtlg(dwnldrslt.getData());
  806. }
  807. return ResultVoUtil.success();
  808. }
  809. public ResultVo<String> execDwnldTcmSyndrmCtlg(String version) {
  810. JSONObject result = getOrdinaryDownloadResult(SiFunction.DOWNLOAD_TCM_SYNDROME_CATALOGUE, version);
  811. log.info("【操作员:{}】,中医证候目录下载:版本号:{},结果:{}", TokenUtil.getInstance().getTokenUserId(), version, result);
  812. if (null == result) {
  813. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  814. }
  815. if (null == result.getInteger(RESULT_CODE)) {
  816. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  817. }
  818. String versionName = null;
  819. if (result.getIntValue(RESULT_CODE) == 0) {
  820. JSONObject output = result.getJSONObject(OUTPUT);
  821. String fileQuryNo = output.getString("file_qury_no");
  822. String filename = output.getString("filename");
  823. String filePath = downloadFile(fileQuryNo, filename);
  824. if (null == filePath) {
  825. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR, "网络异常,下载失败!");
  826. }
  827. Queue<String> queue = SiUtil.readTxtFile(filePath);
  828. if (version.equals(BEGIN_VERSION)) {
  829. dnlddao.truncateTcmSyndrTable();
  830. }
  831. List<SiDlTcmSyndr> list = new ArrayList<>();
  832. while (!queue.isEmpty()) {
  833. String tempstr = queue.poll();
  834. list.add(new SiDlTcmSyndr(tempstr));
  835. if (null == versionName) {
  836. versionName = list.get(0).getVersionName();
  837. }
  838. if (list.size() == 20) {
  839. dnlddao.insertTcmSyndrBatch(list);
  840. list.clear();
  841. }
  842. }
  843. if (!list.isEmpty()) {
  844. dnlddao.insertTcmSyndrBatch(list);
  845. }
  846. if (StringUtil.notBlank(versionName)) {
  847. return ResultVoUtil.success(versionName);
  848. }
  849. }
  850. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  851. }
  852. public ResultVo<Map<String, Object>> downloadMedicalInsuranceMatchCatalogue(DwnldPrm prm) {
  853. JSONObject input = exec.makeTradeHeader(SiFunction.DOWNLOAD_MEDICAL_INSURANCE_MATCH_CATALOGUE);
  854. JSONObject data = new JSONObject();
  855. data.put("updt_time", DateUtil.formatDatetime(prm.getUpdtTime()));
  856. data.put("page_num", prm.getPageNum());
  857. data.put("page_size", prm.getPageSize());
  858. input.getJSONObject("input").put("data", data);
  859. JSONObject result = exec.executeTrade(input, SiFunction.DOWNLOAD_MEDICAL_INSURANCE_MATCH_CATALOGUE);
  860. log.info("【操作员:{}】,医疗目录与医保目录匹配信息下载:\n参数:{},\n结果:{}", TokenUtil.getInstance().getTokenUserId(), input, result);
  861. return getMapResultVo(result);
  862. }
  863. public ResultVo<Map<String, Object>> downloadMedicalInstitutionMatchCatalogue(DwnldPrm prm) {
  864. JSONObject input = exec.makeTradeHeader(SiFunction.DOWNLOAD_MEDICAL_INSTITUTION_MATCH_CATALOGUE);
  865. JSONObject data = new JSONObject();
  866. data.put("updt_time", DateUtil.formatDatetime(prm.getUpdtTime()));
  867. data.put("page_num", prm.getPageNum());
  868. data.put("page_size", prm.getPageSize());
  869. input.getJSONObject("input").put("data", data);
  870. JSONObject result = exec.executeTrade(input, SiFunction.DOWNLOAD_MEDICAL_INSTITUTION_MATCH_CATALOGUE);
  871. log.info("【操作员:{}】,医药机构目录匹配信息下载:\n参数:{},\n结果:{}", TokenUtil.getInstance().getTokenUserId(), input, result);
  872. return getMapResultVo(result);
  873. }
  874. public ResultVo<Map<String, Object>> downloadMedicalInsurancePriceLimitCatalogue(DwnldPrm prm) {
  875. JSONObject input = exec.makeTradeHeader(SiFunction.DOWNLOAD_MEDICAL_INSURANCE_PRICE_LIMIT_CATALOGUE);
  876. JSONObject data = new JSONObject();
  877. data.put("updt_time", DateUtil.formatDatetime(prm.getUpdtTime()));
  878. data.put("page_num", prm.getPageNum());
  879. data.put("page_size", prm.getPageSize());
  880. input.getJSONObject("input").put("data", data);
  881. JSONObject result = exec.executeTrade(input, SiFunction.DOWNLOAD_MEDICAL_INSURANCE_PRICE_LIMIT_CATALOGUE);
  882. log.info("【操作员:{}】,医保目录限价信息下载:\n参数:{},\n结果:{}", TokenUtil.getInstance().getTokenUserId(), input, result);
  883. return getMapResultVo(result);
  884. }
  885. public ResultVo<Map<String, Object>> downloadMedicalInsurancePayFirstCatalogue(DwnldPrm prm) {
  886. JSONObject input = exec.makeTradeHeader(SiFunction.DOWNLOAD_MEDICAL_INSURANCE_PAY_FIRST_CATALOGUE);
  887. JSONObject data = new JSONObject();
  888. if (StringUtil.notBlank(prm.getMedinsCode())) {
  889. data.put("hilist_code", prm.getMedinsCode());
  890. }
  891. if (StringUtil.notBlank(prm.getInsutype())) {
  892. data.put("selfpay_prop_psn_type", prm.getInsutype());
  893. }
  894. data.put("updt_time", DateUtil.formatDatetime(prm.getUpdtTime()));
  895. data.put("page_num", prm.getPageNum());
  896. data.put("page_size", prm.getPageSize());
  897. input.getJSONObject("input").put("data", data);
  898. JSONObject result = exec.executeTrade(input, SiFunction.DOWNLOAD_MEDICAL_INSURANCE_PAY_FIRST_CATALOGUE);
  899. log.info("【操作员:{}】,医保目录先自付比例信息下载:\n参数:{},\n结果:{}", TokenUtil.getInstance().getTokenUserId(), input, result);
  900. return getMapResultVo(result);
  901. }
  902. public ResultVo<Map<String, Object>> saveMedicalInsurancePayFirstCatalogue(DwnldPrm prm) {
  903. int pageNum = prm.getPageNum();
  904. int recordPages = 0;
  905. JSONObject input = exec.makeTradeHeader(SiFunction.DOWNLOAD_MEDICAL_INSURANCE_PAY_FIRST_CATALOGUE);
  906. JSONObject data = new JSONObject();
  907. data.put("updt_time", DateUtil.formatDatetime(prm.getUpdtTime()));
  908. data.put("page_num", pageNum);
  909. data.put("page_size", prm.getPageSize());
  910. input.getJSONObject("input").put("data", data);
  911. JSONObject result = exec.executeTrade(input, SiFunction.DOWNLOAD_MEDICAL_INSURANCE_PAY_FIRST_CATALOGUE);
  912. if (null == result) {
  913. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  914. }
  915. if (null == result.getInteger(RESULT_CODE)) {
  916. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  917. }
  918. if (result.getIntValue(RESULT_CODE) == 0) {
  919. JSONObject output = result.getJSONObject(OUTPUT);
  920. recordPages = output.getInteger("pages");
  921. List<SelfPayFirstCatalogue> list = JSONArray.parseArray(output.getJSONArray("data").toJSONString(), SelfPayFirstCatalogue.class);
  922. List<SelfPayFirstCatalogue> tempList = new ArrayList<>();
  923. log.info("下载医保目录先自付比例信息并入库:第 {} 页,共 {} 页。", pageNum, recordPages);
  924. if (pageNum == 1) {
  925. dnlddao.truncateSelfPayCatalogue();
  926. }
  927. for (SelfPayFirstCatalogue item : list) {
  928. tempList.add(item);
  929. if (tempList.size() == 100) {
  930. dnlddao.insertSelfPayCatalogue(tempList);
  931. tempList.clear();
  932. }
  933. }
  934. if (tempList.size() > 0) {
  935. dnlddao.insertSelfPayCatalogue(tempList);
  936. }
  937. }
  938. while (pageNum < recordPages) {
  939. pageNum += 1;
  940. data.replace("page_num", pageNum);
  941. input.getJSONObject("input").replace("data", data);
  942. result = exec.executeTrade(input, SiFunction.DOWNLOAD_MEDICAL_INSURANCE_PAY_FIRST_CATALOGUE);
  943. if (null == result) {
  944. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  945. }
  946. if (null == result.getInteger(RESULT_CODE)) {
  947. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  948. }
  949. if (result.getIntValue(RESULT_CODE) == 0) {
  950. JSONObject output = result.getJSONObject(OUTPUT);
  951. List<SelfPayFirstCatalogue> list = JSONArray.parseArray(output.getJSONArray("data").toJSONString(), SelfPayFirstCatalogue.class);
  952. List<SelfPayFirstCatalogue> tempList = new ArrayList<>();
  953. log.info("下载医保目录先自付比例信息并入库:第 {} 页,共 {} 页。", pageNum, recordPages);
  954. for (SelfPayFirstCatalogue item : list) {
  955. tempList.add(item);
  956. if (tempList.size() == 100) {
  957. dnlddao.insertSelfPayCatalogue(tempList);
  958. tempList.clear();
  959. }
  960. }
  961. if (tempList.size() > 0) {
  962. dnlddao.insertSelfPayCatalogue(tempList);
  963. }
  964. }
  965. }
  966. prm.setPageNum(1);
  967. prm.setPageSize(30);
  968. return downloadMedicalInsurancePayFirstCatalogue(prm);
  969. }
  970. public ResultVo<Map<String, Object>> downloadDictionaryList(DwnldPrm prm) {
  971. JSONObject input = exec.makeTradeHeader(SiFunction.DOWNLOAD_DICTIONARY_LIST);
  972. DldDictList data = new DldDictList();
  973. data.setDate(DateUtil.formatDatetime(new Date(), "yyyy-MM-dd"));
  974. data.setAdmdvs(SiUtil.INSTITUTION_AREA);
  975. data.setParentValue(prm.getParentValue());
  976. data.setType(prm.getType());
  977. data.setValiFlag(prm.getValiFlag());
  978. input.getJSONObject("input").put("data", JSONObject.parseObject(JSONObject.toJSONString(data)));
  979. JSONObject result = exec.executeTrade(input, SiFunction.DOWNLOAD_DICTIONARY_LIST);
  980. log.info("【操作员:{}】,字典表下载:\n参数:{},\n结果:{}", TokenUtil.getInstance().getTokenUserId(), input, result);
  981. if (null == result) {
  982. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  983. }
  984. if (null == result.getInteger(RESULT_CODE)) {
  985. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
  986. }
  987. if (result.getIntValue(RESULT_CODE) == 0) {
  988. JSONObject output = result.getJSONObject(OUTPUT);
  989. JSONArray list = output.getJSONArray("list");
  990. Map<String, Object> map = new HashMap<>(Capacity.TWO);
  991. map.put("totalSize", list.size());
  992. map.put("list", list);
  993. return ResultVoUtil.success(map);
  994. }
  995. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
  996. }
  997. public String downloadFile(String fileQuryNo, String filename) {
  998. JSONObject input = exec.makeTradeHeader(SiFunction.DOWNLOAD_FILE);
  999. JSONObject fsDownloadIn = new JSONObject();
  1000. fsDownloadIn.put("file_qury_no", fileQuryNo);
  1001. fsDownloadIn.put("filename", filename);
  1002. fsDownloadIn.put("fixmedins_code", SiUtil.INSTITUTION_ID);
  1003. input.getJSONObject("input").put("fsDownloadIn", fsDownloadIn);
  1004. String targetPath = ZipUtil.DIRECTORY + filename;
  1005. ForestResponse<byte[]> rsp = execSrvc.download(SiUtil.getSiHeaderMap(SiFunction.DOWNLOAD_FILE), input);
  1006. try {
  1007. Files.write(Paths.get(targetPath), Objects.requireNonNull(rsp.getByteArray(),
  1008. "未获取到下载文件"));
  1009. String unZip = ZipUtil.unZip(targetPath);
  1010. log.info("解压缩成功:{}", unZip);
  1011. ZipUtil.deleteFile(targetPath);
  1012. return unZip;
  1013. } catch (Exception e) {
  1014. log.error("从医保中心下载文件出错", e);
  1015. }
  1016. return null;
  1017. }
  1018. private JSONObject getOrdinaryDownloadResult(SiFunction function, String version) {
  1019. JSONObject input = exec.makeTradeHeader(function);
  1020. JSONObject data = new JSONObject();
  1021. data.put("ver", version);
  1022. input.getJSONObject("input").put("data", data);
  1023. return exec.executeTrade(input, function);
  1024. }
  1025. public ResultVo<String> fillPsnPayProp() {
  1026. int countYp = 0;
  1027. List<String> ypList = dnlddao.selectHospitalItems("yp_zd_dict");
  1028. for (String item : ypList) {
  1029. countYp += queryPsnPayProp(item, "yp_zd_dict");
  1030. }
  1031. int countXm = 0;
  1032. List<String> xmList = dnlddao.selectHospitalItems("zd_charge_item");
  1033. for (String item : xmList) {
  1034. countXm += queryPsnPayProp(item, "zd_charge_item");
  1035. }
  1036. String result = String.format("药品共 %d 项,补充 %d 项;项目共 %d 项,补充 %d 项。",
  1037. ypList.size(), countYp, xmList.size(), countXm);
  1038. log.info(result);
  1039. return ResultVoUtil.success(result);
  1040. }
  1041. private int queryPsnPayProp(String hilistCode, String table) {
  1042. JSONObject input = exec.makeTradeHeader(SiFunction.DOWNLOAD_MEDICAL_INSURANCE_PAY_FIRST_CATALOGUE);
  1043. JSONObject data = new JSONObject();
  1044. data.put("hilist_code", hilistCode);
  1045. data.put("selfpay_prop_psn_type", "310");
  1046. data.put("updt_time", "2000-01-01 00:00:00");
  1047. data.put("page_num", 1);
  1048. data.put("page_size", 100);
  1049. input.getJSONObject("input").put("data", data);
  1050. JSONObject result = exec.executeTrade(input, SiFunction.DOWNLOAD_MEDICAL_INSURANCE_PAY_FIRST_CATALOGUE);
  1051. if (null == result || null == result.getInteger(RESULT_CODE)) {
  1052. return 0;
  1053. }
  1054. String psnPayProp = null;
  1055. String nowdate = DateUtil.formatDatetime(new Date());
  1056. if (result.getIntValue(RESULT_CODE) == 0) {
  1057. JSONObject output = result.getJSONObject(OUTPUT);
  1058. JSONArray array = output.getJSONArray("data");
  1059. int recordCounts = output.getIntValue("recordCounts");
  1060. if (recordCounts == 1) {
  1061. JSONObject target = array.getJSONObject(0);
  1062. psnPayProp = target.getString("selfpay_prop");
  1063. } else {
  1064. for (int i = 0; i < recordCounts; i++) {
  1065. JSONObject target = array.getJSONObject(i);
  1066. String enddate = target.getString("enddate");
  1067. if (DateUtil.shiJianDaXiao(nowdate, enddate, "<=")) {
  1068. nowdate = enddate;
  1069. psnPayProp = target.getString("selfpay_prop");
  1070. }
  1071. }
  1072. }
  1073. }
  1074. if (StringUtil.notBlank(psnPayProp)) {
  1075. dnlddao.updatePsnpayProp(table, hilistCode, psnPayProp);
  1076. log.info("补充自费比例:{},{}", hilistCode, psnPayProp);
  1077. return 1;
  1078. }
  1079. return 0;
  1080. }
  1081. }