SiDownloadService.java 53 KB

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