OrderCovidExamService.java 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. package thyyxxk.wxservice_server.service;
  2. import com.alibaba.fastjson.JSONObject;
  3. import lombok.extern.slf4j.Slf4j;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.beans.factory.annotation.Value;
  6. import org.springframework.stereotype.Service;
  7. import org.springframework.web.client.RestTemplate;
  8. import thyyxxk.wxservice_server.config.exception.ExceptionEnum;
  9. import thyyxxk.wxservice_server.dao.AppointmentDao;
  10. import thyyxxk.wxservice_server.entity.ResultVo;
  11. import thyyxxk.wxservice_server.entity.assessment.CovidQuestionnaire;
  12. import thyyxxk.wxservice_server.entity.covid.MultipleExamTimeLimit;
  13. import thyyxxk.wxservice_server.entity.hrgresponse.SaveMzFeeResponse;
  14. import thyyxxk.wxservice_server.utils.CastUtil;
  15. import thyyxxk.wxservice_server.utils.ResultVoUtil;
  16. import thyyxxk.wxservice_server.utils.StringUtil;
  17. import java.text.SimpleDateFormat;
  18. import java.util.Date;
  19. import java.util.HashMap;
  20. import java.util.Map;
  21. /**
  22. * @author dj
  23. */
  24. @Slf4j
  25. @Service
  26. public class OrderCovidExamService {
  27. private final AppointmentDao dao;
  28. private final MultipleExamTimeLimit timeLimit = new MultipleExamTimeLimit();
  29. private final SimpleDateFormat timeLimitFormat = new SimpleDateFormat("HHmm");
  30. @Value("${hrgApiUrl}")
  31. private String hrgApiUrl;
  32. @Autowired
  33. public OrderCovidExamService(AppointmentDao dao) {
  34. this.dao = dao;
  35. }
  36. public ResultVo<String> hasDoneCovidAssessment(String patientId) {
  37. CovidQuestionnaire covid = dao.validCovidAssessment(patientId);
  38. if (null == covid) {
  39. return ResultVoUtil.success("no");
  40. } else {
  41. return ResultVoUtil.success("yes");
  42. }
  43. }
  44. public ResultVo<String> savePrescription(String patientId, int type) {
  45. if (StringUtil.isBlank(timeLimit.getLimitValue())) {
  46. timeLimitChanged();
  47. }
  48. if (type == 2) {
  49. int nowtime = Integer.parseInt(timeLimitFormat.format(new Date()));
  50. if (nowtime < timeLimit.getBeginLimit() || nowtime > timeLimit.getEndLimit()) {
  51. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "混检仅在 " +
  52. timeLimit.getLimitValueForDisplay() + " 开放。");
  53. }
  54. }
  55. String urlTail = type == 1 ? "/nucleicAcidApplication?patientId=" : "/hybridTestApplication?patientId=";
  56. RestTemplate restTemplate = new RestTemplate();
  57. String url = hrgApiUrl + urlTail + patientId;
  58. SaveMzFeeResponse hrgResponse = restTemplate.getForObject(url, SaveMzFeeResponse.class);
  59. String typeName = type == 1 ? "单人单管" : "混检";
  60. log.info("【{}】快速下单核酸检测:患者:{},结果:{}", typeName, patientId, hrgResponse);
  61. if (null == hrgResponse) {
  62. return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
  63. }
  64. if (0 == hrgResponse.getResultCode()) {
  65. return ResultVoUtil.success();
  66. }
  67. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, hrgResponse.getResultMessage());
  68. }
  69. public ResultVo<MultipleExamTimeLimit> getMultipleExamTimeLimit() {
  70. if (StringUtil.isBlank(timeLimit.getLimitValue())) {
  71. timeLimitChanged();
  72. }
  73. return ResultVoUtil.success(timeLimit);
  74. }
  75. public String timeLimitChanged() {
  76. String url = hrgApiUrl + "/getHyBirdTime";
  77. RestTemplate template = new RestTemplate();
  78. Map<String, Object> result = template.getForObject(url, HashMap.class);
  79. log.info("重新获取混检开放时间:{}", result);
  80. if (null == result) {
  81. String msg = "获取混检开放时间失败,接口返回空。";
  82. log.info(msg);
  83. return msg;
  84. }
  85. if ((int) result.get("code") != 0) {
  86. String msg = result.get("message").toString();
  87. log.info("获取混检开放时间失败:{}", msg);
  88. return msg;
  89. }
  90. Map<String, String> data = CastUtil.cast(result.get("data"));
  91. String value = data.get("configValue");
  92. String[] valuesArr = value.replaceAll(":", "").split("-");
  93. timeLimit.setLimitValue(value);
  94. timeLimit.setLimitValueForDisplay(value.replace("-", " - "));
  95. timeLimit.setBeginLimit(Integer.parseInt(valuesArr[0]));
  96. timeLimit.setEndLimit(Integer.parseInt(valuesArr[1]));
  97. return JSONObject.toJSONString(timeLimit);
  98. }
  99. public ResultVo<String> yellowHealthCardFreeCovidExam(String patientId) {
  100. RestTemplate restTemplate = new RestTemplate();
  101. String url = hrgApiUrl + "/nucleicOnlyYellowAcidApplication?patientId=" + patientId;
  102. SaveMzFeeResponse hrgResponse = restTemplate.getForObject(url, SaveMzFeeResponse.class);
  103. log.info("黄码免费核酸检测快速下单:患者:{},结果:{}", patientId, hrgResponse);
  104. if (null == hrgResponse) {
  105. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "网络异常,请稍后再试。");
  106. }
  107. if (0 == hrgResponse.getResultCode()) {
  108. return ResultVoUtil.success("黄码免费核酸检测下单成功。");
  109. }
  110. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, hrgResponse.getResultMessage());
  111. }
  112. }