| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- package thyyxxk.wxservice_server.service;
- import com.alibaba.fastjson.JSONObject;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.stereotype.Service;
- import org.springframework.web.client.RestTemplate;
- import thyyxxk.wxservice_server.config.exception.ExceptionEnum;
- import thyyxxk.wxservice_server.dao.AppointmentDao;
- import thyyxxk.wxservice_server.entity.ResultVo;
- import thyyxxk.wxservice_server.entity.assessment.CovidQuestionnaire;
- import thyyxxk.wxservice_server.entity.covid.MultipleExamTimeLimit;
- import thyyxxk.wxservice_server.entity.hrgresponse.SaveMzFeeResponse;
- import thyyxxk.wxservice_server.utils.CastUtil;
- import thyyxxk.wxservice_server.utils.ResultVoUtil;
- import thyyxxk.wxservice_server.utils.StringUtil;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.Map;
- /**
- * @author dj
- */
- @Slf4j
- @Service
- public class OrderCovidExamService {
- private final AppointmentDao dao;
- private final MultipleExamTimeLimit timeLimit = new MultipleExamTimeLimit();
- private final SimpleDateFormat timeLimitFormat = new SimpleDateFormat("HHmm");
- @Value("${hrgApiUrl}")
- private String hrgApiUrl;
- @Autowired
- public OrderCovidExamService(AppointmentDao dao) {
- this.dao = dao;
- }
- public ResultVo<String> hasDoneCovidAssessment(String patientId) {
- CovidQuestionnaire covid = dao.validCovidAssessment(patientId);
- if (null == covid) {
- return ResultVoUtil.success("no");
- } else {
- return ResultVoUtil.success("yes");
- }
- }
- public ResultVo<String> savePrescription(String patientId, int type) {
- if (StringUtil.isBlank(timeLimit.getLimitValue())) {
- timeLimitChanged();
- }
- if (type == 2) {
- int nowtime = Integer.parseInt(timeLimitFormat.format(new Date()));
- if (nowtime < timeLimit.getBeginLimit() || nowtime > timeLimit.getEndLimit()) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "混检仅在 " +
- timeLimit.getLimitValueForDisplay() + " 开放。");
- }
- }
- String urlTail = type == 1 ? "/nucleicAcidApplication?patientId=" : "/hybridTestApplication?patientId=";
- RestTemplate restTemplate = new RestTemplate();
- String url = hrgApiUrl + urlTail + patientId;
- SaveMzFeeResponse hrgResponse = restTemplate.getForObject(url, SaveMzFeeResponse.class);
- String typeName = type == 1 ? "单人单管" : "混检";
- log.info("【{}】快速下单核酸检测:患者:{},结果:{}", typeName, patientId, hrgResponse);
- if (null == hrgResponse) {
- return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
- }
- if (0 == hrgResponse.getResultCode()) {
- return ResultVoUtil.success();
- }
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, hrgResponse.getResultMessage());
- }
- public ResultVo<MultipleExamTimeLimit> getMultipleExamTimeLimit() {
- if (StringUtil.isBlank(timeLimit.getLimitValue())) {
- timeLimitChanged();
- }
- return ResultVoUtil.success(timeLimit);
- }
- public String timeLimitChanged() {
- String url = hrgApiUrl + "/getHyBirdTime";
- RestTemplate template = new RestTemplate();
- Map<String, Object> result = template.getForObject(url, HashMap.class);
- log.info("重新获取混检开放时间:{}", result);
- if (null == result) {
- String msg = "获取混检开放时间失败,接口返回空。";
- log.info(msg);
- return msg;
- }
- if ((int) result.get("code") != 0) {
- String msg = result.get("message").toString();
- log.info("获取混检开放时间失败:{}", msg);
- return msg;
- }
- Map<String, String> data = CastUtil.cast(result.get("data"));
- String value = data.get("configValue");
- String[] valuesArr = value.replaceAll(":", "").split("-");
- timeLimit.setLimitValue(value);
- timeLimit.setLimitValueForDisplay(value.replace("-", " - "));
- timeLimit.setBeginLimit(Integer.parseInt(valuesArr[0]));
- timeLimit.setEndLimit(Integer.parseInt(valuesArr[1]));
- return JSONObject.toJSONString(timeLimit);
- }
- public ResultVo<String> yellowHealthCardFreeCovidExam(String patientId) {
- RestTemplate restTemplate = new RestTemplate();
- String url = hrgApiUrl + "/nucleicOnlyYellowAcidApplication?patientId=" + patientId;
- SaveMzFeeResponse hrgResponse = restTemplate.getForObject(url, SaveMzFeeResponse.class);
- log.info("黄码免费核酸检测快速下单:患者:{},结果:{}", patientId, hrgResponse);
- if (null == hrgResponse) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "网络异常,请稍后再试。");
- }
- if (0 == hrgResponse.getResultCode()) {
- return ResultVoUtil.success("黄码免费核酸检测下单成功。");
- }
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, hrgResponse.getResultMessage());
- }
- }
|