NationalMatchService.java 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. package thyyxxk.webserver.service.dictionary;
  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 lombok.extern.slf4j.Slf4j;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.stereotype.Service;
  9. import thyyxxk.webserver.config.exception.ExceptionEnum;
  10. import thyyxxk.webserver.constants.Capacity;
  11. import thyyxxk.webserver.constants.NationalMatchType;
  12. import thyyxxk.webserver.constants.sidicts.SiFunction;
  13. import thyyxxk.webserver.dao.his.dictionary.NationalMatchDao;
  14. import thyyxxk.webserver.entity.ResultVo;
  15. import thyyxxk.webserver.entity.dictionary.ChargeItemMatch;
  16. import thyyxxk.webserver.entity.nationalmatch.*;
  17. import thyyxxk.webserver.service.medicalinsurance.ExecService;
  18. import thyyxxk.webserver.utils.DateUtil;
  19. import thyyxxk.webserver.utils.ResultVoUtil;
  20. import thyyxxk.webserver.utils.StringUtil;
  21. import thyyxxk.webserver.utils.TokenUtil;
  22. import java.util.Date;
  23. import java.util.HashMap;
  24. import java.util.List;
  25. import java.util.Map;
  26. /**
  27. * @description: 新医保国家目录匹配Service
  28. * @author: DingJie
  29. * @create: 2021-06-10 14:50:27
  30. **/
  31. @Slf4j
  32. @Service
  33. public class NationalMatchService {
  34. private final ExecService exec;
  35. private final NationalMatchDao dao;
  36. @Autowired
  37. public NationalMatchService(ExecService exec, NationalMatchDao dao) {
  38. this.exec = exec;
  39. this.dao = dao;
  40. }
  41. public ResultVo<Map<String, Object>> selectLocalItems(QueryParam param) {
  42. log.info("是否导出:{}", param.getExport());
  43. IPage<StandardLocalItem> iPage = param.getExport() ? new Page<>(1, -1) :
  44. new Page<>(param.getCurrentPage(), param.getPageSize());
  45. String code = param.getCode();
  46. code = StringUtil.isBlank(code) ? "%%" : code.trim().toUpperCase();
  47. String name = param.getName();
  48. name = StringUtil.isBlank(name) ? "%%" : "%" + name.trim() + "%";
  49. if (param.getType() == NationalMatchType.MEDICINE) {
  50. iPage = dao.selectLocalMedicines(iPage, code, name, param.getType(), param.getDelFlag(), param.getStatus());
  51. } else if(param.getType() == NationalMatchType.HERBAL) {
  52. iPage = dao.selectLocalHerbals(iPage, code, name, param.getType(), param.getDelFlag(), param.getStatus());
  53. } else if (param.getType() == NationalMatchType.SERVICE) {
  54. iPage = dao.selectLocalServices(iPage, code, name, param.getType(), param.getDelFlag(), param.getStatus());
  55. } else {
  56. iPage = dao.selectLocalSupplies(iPage, code, name, param.getType(), param.getDelFlag(), param.getStatus());
  57. }
  58. if (iPage.getRecords().size() == 0) {
  59. return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有符合条件的数据。");
  60. }
  61. Map<String, Object> map = new HashMap<>(Capacity.TWO);
  62. map.put("total", iPage.getTotal());
  63. map.put("list", iPage.getRecords());
  64. return ResultVoUtil.success(map);
  65. }
  66. public ResultVo<String> asyncNewNameForServicesOrItems() {
  67. dao.asyncNewNameForServices();
  68. return ResultVoUtil.success("同步成功。");
  69. }
  70. public ResultVo<List> selectNationalItems(StandardLocalItem param) {
  71. int type = param.getType();
  72. if (type == NationalMatchType.MEDICINE) {
  73. String approve = param.getApprovalNumber();
  74. approve = StringUtil.isBlank(approve) ? "%%" : "%" + approve.replace("国药准字", "") + "%";
  75. List<SiCentralMedicine> list = dao.selectNationalMedicines(param.getFuzzyName(), approve);
  76. if (null == list || list.isEmpty()) {
  77. list = dao.selectNationalMedicines(param.getFuzzyName(), "%%");
  78. if (null == list || list.isEmpty()) {
  79. return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有符合条件的国家目录。");
  80. }
  81. }
  82. return ResultVoUtil.success(list);
  83. } else if (type == NationalMatchType.HERBAL){
  84. String name = param.getFuzzyName();
  85. if (name.contains("颗粒")) {
  86. String[] splits = param.getFuzzyName().split("(");
  87. splits = splits[0].split("\\(");
  88. name = splits[0].replaceAll("颗粒", "");
  89. }
  90. name = "%" + name.trim() + "%";
  91. List<SiCentralHerbal> list = dao.selectNationalHerbals(name);
  92. if (null == list || list.isEmpty()) {
  93. return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有符合条件的国家目录。");
  94. }
  95. return ResultVoUtil.success(list);
  96. } else if (type == NationalMatchType.SERVICE) {
  97. String[] splits = param.getFuzzyName().split("外送");
  98. String name;
  99. if (splits.length == 1) {
  100. name = splits[0];
  101. } else {
  102. name = splits[0].substring(0, splits[0].length() - 1);
  103. }
  104. name = "%" + name + "%";
  105. List<SiCentralServices> list = dao.selectNationalServices(name);
  106. if (null == list || list.isEmpty()) {
  107. return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有符合条件的国家目录。");
  108. }
  109. return ResultVoUtil.success(list);
  110. } else {
  111. List<SiCentralSuppliesMini> list;
  112. if (StringUtil.notBlank(param.getNationalCode())) {
  113. list = dao.selectNationalSuppliesByCondition("code", param.getNationalCode().trim());
  114. } else if (StringUtil.notBlank(param.getApprovalNumber())) {
  115. list = dao.selectNationalSuppliesByCondition("registration_record_no", param.getApprovalNumber().trim());
  116. } else {
  117. String name = "%" + param.getFuzzyName() + "%";
  118. list = dao.selectNationalSupplies(name);
  119. }
  120. if (null == list || list.isEmpty()) {
  121. return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有符合条件的国家目录。");
  122. }
  123. return ResultVoUtil.success(list);
  124. }
  125. }
  126. public ResultVo<String> executeMatch(StandardLocalItem param) {
  127. String staffId = TokenUtil.getTokenUserId();
  128. String selfpayProp = queryPsnPayProp(param.getNationalCode());
  129. if (param.getType() < NationalMatchType.SERVICE) {
  130. dao.matchMedicineAndHerbal(param.getCode(), staffId, param.getNationalCode(), param.getNationalName(), selfpayProp);
  131. } else {
  132. ChargeItemMatch chargeItemMatch = dao.selectServiceAbout(param.getNationalCode());
  133. if (null == chargeItemMatch) {
  134. chargeItemMatch = new ChargeItemMatch();
  135. chargeItemMatch.setNationalCode(param.getNationalCode());
  136. }
  137. chargeItemMatch.setHisCode(param.getCode());
  138. chargeItemMatch.setStaffId(staffId);
  139. chargeItemMatch.setNationalName(param.getNationalName());
  140. chargeItemMatch.setSelfpayProp(selfpayProp);
  141. dao.matchServcieAndSupply(chargeItemMatch);
  142. }
  143. log.info("【操作员:{}】匹配国家目录:{}", staffId, param);
  144. return ResultVoUtil.success("匹配成功。");
  145. }
  146. public ResultVo<String> cancelMatch(StandardLocalItem param) {
  147. String staffId = TokenUtil.getTokenUserId();
  148. if (param.getType() < NationalMatchType.SERVICE) {
  149. dao.cancelMatchYp(param.getCode(), param.getSerial(), staffId);
  150. } else {
  151. dao.cancelMatchXm(param.getCode(), staffId);
  152. }
  153. log.info("【操作员:{}】取消匹配国家目录:{}", staffId, param);
  154. return ResultVoUtil.success("取消匹配成功。");
  155. }
  156. public ResultVo<String> updateLocalItem(StandardLocalItem param) {
  157. String staffId = TokenUtil.getTokenUserId();
  158. if (param.getType() < NationalMatchType.SERVICE) {
  159. dao.updateMedicine(param.getName(), staffId, param.getCode());
  160. } else if (param.getType() == NationalMatchType.SERVICE) {
  161. dao.updateServiceItem(param.getName(), param.getUnit(), param.getPrice(), staffId,
  162. param.getStandardCode(), param.getDiscription(), param.getCode());
  163. } else {
  164. dao.updateSupply(param.getName(), staffId, param.getFactory(), param.getSpecification(), param.getCode());
  165. }
  166. log.info("【操作员:{}】修改项目:{}", staffId, param);
  167. return ResultVoUtil.success("修改成功。");
  168. }
  169. public String queryPsnPayProp(String hilistCode) {
  170. JSONObject input = exec.makeTradeHeader(SiFunction.DOWNLOAD_MEDICAL_INSURANCE_PAY_FIRST_CATALOGUE);
  171. JSONObject data = new JSONObject();
  172. data.put("hilist_code", hilistCode);
  173. data.put("selfpay_prop_psn_type", "310");
  174. data.put("updt_time", "2018-01-01 00:00:00");
  175. data.put("page_num", 1);
  176. data.put("page_size", 100);
  177. input.getJSONObject("input").put("data", data);
  178. JSONObject result = exec.executeTrade(input, SiFunction.DOWNLOAD_MEDICAL_INSURANCE_PAY_FIRST_CATALOGUE);
  179. log.info("查询自付比例:\n参数:{}\n结果:{}", input, result);
  180. if (null == result || null == result.getInteger("infcode")) {
  181. return null;
  182. }
  183. String psnPayProp = null;
  184. if (result.getIntValue("infcode") == 0) {
  185. JSONObject output = result.getJSONObject("output");
  186. JSONArray array = output.getJSONArray("data");
  187. String nowdate = DateUtil.formatDatetime(new Date());
  188. for (int i = 0; i < array.size(); i++) {
  189. JSONObject item = array.getJSONObject(i);
  190. String enddate = item.getString("enddate");
  191. if (DateUtil.shiJianDaXiao(nowdate, enddate, "<")) {
  192. nowdate = enddate;
  193. psnPayProp = item.getString("selfpay_prop");
  194. }
  195. }
  196. }
  197. return psnPayProp;
  198. }
  199. }