NationalMatchService.java 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. package thyyxxk.webserver.service.nationalmatch;
  2. import com.baomidou.mybatisplus.core.metadata.IPage;
  3. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  4. import lombok.extern.slf4j.Slf4j;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.stereotype.Service;
  7. import thyyxxk.webserver.config.exception.ExceptionEnum;
  8. import thyyxxk.webserver.constants.Capacity;
  9. import thyyxxk.webserver.constants.NationalMatchType;
  10. import thyyxxk.webserver.dao.his.nationalmatch.NationalMatchDao;
  11. import thyyxxk.webserver.entity.ResultVo;
  12. import thyyxxk.webserver.entity.nationalmatch.*;
  13. import thyyxxk.webserver.utils.ResultVoUtil;
  14. import thyyxxk.webserver.utils.StringUtil;
  15. import thyyxxk.webserver.utils.TokenUtil;
  16. import java.util.HashMap;
  17. import java.util.List;
  18. import java.util.Map;
  19. /**
  20. * @description: 新医保国家目录匹配Service
  21. * @author: DingJie
  22. * @create: 2021-06-10 14:50:27
  23. **/
  24. @Slf4j
  25. @Service
  26. public class NationalMatchService {
  27. private final NationalMatchDao dao;
  28. @Autowired
  29. public NationalMatchService(NationalMatchDao dao) {
  30. this.dao = dao;
  31. }
  32. public ResultVo<Map<String, Object>> selectLocalItems(QueryParam param) {
  33. log.info("是否导出:{}", param.getExport());
  34. IPage<StandardLocalItem> iPage = param.getExport() ? new Page<>(1, -1) :
  35. new Page<>(param.getCurrentPage(), param.getPageSize());
  36. String code = param.getCode();
  37. code = StringUtil.isBlank(code) ? "%%" : code.trim().toUpperCase();
  38. String name = param.getName();
  39. name = StringUtil.isBlank(name) ? "%%" : "%" + name.trim() + "%";
  40. if (param.getType() == NationalMatchType.MEDICINE) {
  41. iPage = dao.selectLocalMedicines(iPage, code, name, param.getType(), param.getDelFlag(), param.getStatus());
  42. } else if(param.getType() == NationalMatchType.HERBAL) {
  43. iPage = dao.selectLocalHerbals(iPage, code, name, param.getType(), param.getDelFlag(), param.getStatus());
  44. } else if (param.getType() == NationalMatchType.SERVICE) {
  45. iPage = dao.selectLocalServices(iPage, code, name, param.getType(), param.getDelFlag(), param.getStatus());
  46. } else {
  47. iPage = dao.selectLocalSupplies(iPage, code, name, param.getType(), param.getDelFlag(), param.getStatus());
  48. }
  49. if (iPage.getRecords().size() == 0) {
  50. return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有符合条件的数据。");
  51. }
  52. Map<String, Object> map = new HashMap<>(Capacity.TWO);
  53. map.put("total", iPage.getTotal());
  54. map.put("list", iPage.getRecords());
  55. return ResultVoUtil.success(map);
  56. }
  57. public ResultVo<String> asyncNewNameForServicesOrItems() {
  58. dao.asyncNewNameForServices();
  59. return ResultVoUtil.success("同步成功。");
  60. }
  61. public ResultVo<List> selectNationalItems(StandardLocalItem param) {
  62. int type = param.getType();
  63. if (type == NationalMatchType.MEDICINE) {
  64. String approve = param.getApprovalNumber();
  65. approve = StringUtil.isBlank(approve) ? "%%" : "%" + approve.replace("国药准字", "") + "%";
  66. List<SiCentralMedicine> list = dao.selectNationalMedicines(param.getFuzzyName(), approve);
  67. if (null == list || list.isEmpty()) {
  68. list = dao.selectNationalMedicines(param.getFuzzyName(), "%%");
  69. if (null == list || list.isEmpty()) {
  70. return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有符合条件的国家目录。");
  71. }
  72. }
  73. return ResultVoUtil.success(list);
  74. } else if (type == NationalMatchType.HERBAL){
  75. String name = param.getFuzzyName();
  76. if (name.contains("颗粒")) {
  77. String[] splits = param.getFuzzyName().split("(");
  78. splits = splits[0].split("\\(");
  79. name = splits[0].replaceAll("颗粒", "");
  80. }
  81. name = "%" + name.trim() + "%";
  82. List<SiCentralHerbal> list = dao.selectNationalHerbals(name);
  83. if (null == list || list.isEmpty()) {
  84. return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有符合条件的国家目录。");
  85. }
  86. return ResultVoUtil.success(list);
  87. } else if (type == NationalMatchType.SERVICE) {
  88. String[] splits = param.getFuzzyName().split("外送");
  89. String name;
  90. if (splits.length == 1) {
  91. name = splits[0];
  92. } else {
  93. name = splits[0].substring(0, splits[0].length() - 1);
  94. }
  95. name = "%" + name + "%";
  96. List<SiCentralServices> list = dao.selectNationalServices(name);
  97. if (null == list || list.isEmpty()) {
  98. return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有符合条件的国家目录。");
  99. }
  100. return ResultVoUtil.success(list);
  101. } else {
  102. String name = "%" + param.getFuzzyName() + "%";
  103. List<SiCentralSuppliesMini> list = dao.selectNationalSupplies(name);
  104. if (null == list || list.isEmpty()) {
  105. return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有符合条件的国家目录。");
  106. }
  107. return ResultVoUtil.success(list);
  108. }
  109. }
  110. public ResultVo<String> executeMatch(StandardLocalItem param) {
  111. String staffId = TokenUtil.getTokenUserId();
  112. if (param.getType() < NationalMatchType.SERVICE) {
  113. dao.matchMedicineAndHerbal(param.getCode(), staffId, param.getNationalCode(), param.getNationalName());
  114. } else {
  115. dao.matchServcieAndSupply(param.getCode(), staffId, param.getNationalCode(), param.getNationalName());
  116. }
  117. log.info("【操作员:{}】匹配国家目录:{}", staffId, param);
  118. return ResultVoUtil.success("匹配成功。");
  119. }
  120. public ResultVo<String> cancelMatch(StandardLocalItem param) {
  121. String staffId = TokenUtil.getTokenUserId();
  122. if (param.getType() < NationalMatchType.SERVICE) {
  123. dao.cancelMatchYp(param.getCode(), param.getSerial(), staffId);
  124. } else {
  125. dao.cancelMatchXm(param.getCode(), staffId);
  126. }
  127. log.info("【操作员:{}】取消匹配国家目录:{}", staffId, param);
  128. return ResultVoUtil.success("取消匹配成功。");
  129. }
  130. public ResultVo<String> updateLocalItem(StandardLocalItem param) {
  131. String staffId = TokenUtil.getTokenUserId();
  132. if (param.getType() < NationalMatchType.SERVICE) {
  133. dao.updateMedicine(param.getName(), staffId, param.getCode());
  134. } else if (param.getType() == NationalMatchType.SERVICE) {
  135. dao.updateServiceItem(param.getName(), param.getUnit(), param.getPrice(), staffId,
  136. param.getStandardCode(), param.getDiscription(), param.getCode());
  137. } else {
  138. dao.updateSupply(param.getName(), staffId, param.getFactory(), param.getSpecification(), param.getCode());
  139. }
  140. log.info("【操作员:{}】修改项目:{}", staffId, param);
  141. return ResultVoUtil.success("修改成功。");
  142. }
  143. }