|
|
@@ -2,6 +2,7 @@ package org.thyy.thirdpartapi.inspection.inspectionImpl;
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
+import com.alibaba.fastjson2.JSONArray;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -10,7 +11,13 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
import org.thyy.thirdpartapi.inspection.InspectionInterface;
|
|
|
import org.thyy.thirdpartapi.inspection.config.InspectionApi;
|
|
|
+import org.thyy.thirdpartapi.inspection.dao.InspectionDao;
|
|
|
+import org.thyy.thirdpartapi.inspection.request.ReportDetailInquiry;
|
|
|
+import org.thyy.thirdpartapi.inspection.request.ReportIndexInquiry;
|
|
|
+import org.thyy.thirdpartapi.inspection.response.bl.BlIndexResponse;
|
|
|
+import org.thyy.thirdpartapi.inspection.response.jc.JcIndexResponse;
|
|
|
import org.thyy.thirdpartapi.inspection.response.jy.*;
|
|
|
+import org.thyy.thirdpartapi.inspection.response.xd.XdIndexResponse;
|
|
|
import org.thyy.utils.exception.BizException;
|
|
|
import org.thyy.utils.exception.ExceptionEnum;
|
|
|
|
|
|
@@ -21,29 +28,40 @@ import java.util.List;
|
|
|
@Service
|
|
|
@ConditionalOnProperty(prefix = "thyy.inspection", name = "service", havingValue = "shanghaihaotai", matchIfMissing = true)
|
|
|
public class ThyyInspectionImpl implements InspectionInterface {
|
|
|
- private String api;
|
|
|
- private final RestTemplate restTemplate;
|
|
|
- private final InspectionApi inspectionApiConfig;
|
|
|
+ private final RestTemplate template;
|
|
|
+ private final InspectionDao dao;
|
|
|
+ private final InspectionApi apiConfig;
|
|
|
|
|
|
@Autowired
|
|
|
- public ThyyInspectionImpl(RestTemplate restTemplate, InspectionApi inspectionApiConfig) {
|
|
|
- this.restTemplate = restTemplate;
|
|
|
- this.inspectionApiConfig = inspectionApiConfig;
|
|
|
- init();
|
|
|
+ public ThyyInspectionImpl(RestTemplate template, InspectionDao dao, InspectionApi apiConfig) {
|
|
|
+ this.template = template;
|
|
|
+ this.dao = dao;
|
|
|
+ this.apiConfig = apiConfig;
|
|
|
}
|
|
|
|
|
|
- public void init() {
|
|
|
- this.api = inspectionApiConfig.getJy();
|
|
|
- log.info("检验检查模块初始化完成");
|
|
|
+ @Override
|
|
|
+ public List<JyIndexResponse> queryJyIndex(ReportIndexInquiry request) {
|
|
|
+ if (StrUtil.isBlank(apiConfig.getJy())) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ JSONObject response = template.postForObject(apiConfig.getJy() + "/self", request, JSONObject.class);
|
|
|
+ JSONObject data = getJyJsonData(response);
|
|
|
+ String items = JSON.toJSONString(data.getJSONArray("items"));
|
|
|
+ return JSON.parseArray(items, JyIndexResponse.class);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<JyIndexResponse> queryExamIndex(JSONObject request) {
|
|
|
- if (StrUtil.isBlank(api)) {
|
|
|
- return new ArrayList<>();
|
|
|
+ public JyDetailResponse queryJyDetail(ReportIndexInquiry request) {
|
|
|
+ if (StrUtil.isBlank(apiConfig.getJy())) {
|
|
|
+ return null;
|
|
|
}
|
|
|
+ JSONObject response = new RestTemplate().postForObject(
|
|
|
+ apiConfig.getJy() + "/detail", request, JSONObject.class);
|
|
|
+ JSONObject data = getJyJsonData(response);
|
|
|
+ return JSON.parseObject(JSON.toJSONString(data), JyDetailResponse.class);
|
|
|
+ }
|
|
|
|
|
|
- JSONObject response = restTemplate.postForObject(api + "/self", request, JSONObject.class);
|
|
|
+ private JSONObject getJyJsonData(JSONObject response) {
|
|
|
if (null == response) {
|
|
|
throw new BizException(ExceptionEnum.NETWORK_ERROR);
|
|
|
}
|
|
|
@@ -51,26 +69,78 @@ public class ThyyInspectionImpl implements InspectionInterface {
|
|
|
if (null == code || !code) {
|
|
|
throw new BizException(ExceptionEnum.API_ERROR, response.getString("message"));
|
|
|
}
|
|
|
- JSONObject data = response.getJSONObject("data");
|
|
|
- String items = JSON.toJSONString(data.getJSONArray("items"));
|
|
|
- return JSON.parseArray(items, JyIndexResponse.class);
|
|
|
+ return response.getJSONObject("data");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public JyDetailResponse queryExamDetail(JSONObject request) {
|
|
|
- if (StrUtil.isBlank(api)) {
|
|
|
- return null;
|
|
|
+ public List<JcIndexResponse> queryJcIndex(ReportIndexInquiry request) {
|
|
|
+ return dao.selectJctIndex(request);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public JcIndexResponse queryJcDetail(ReportDetailInquiry request) {
|
|
|
+ JcIndexResponse result = dao.selectJcReport(request.getReportId());
|
|
|
+ result.setExaminationSee(
|
|
|
+ result.getExaminationSee()
|
|
|
+ .replaceAll("\r\n", "<br/>")
|
|
|
+ .replaceAll("\n", "<br/>")
|
|
|
+ );
|
|
|
+ result.setExaminationreSult(
|
|
|
+ result.getExaminationreSult()
|
|
|
+ .replaceAll("\r\n", "<br/>")
|
|
|
+ .replaceAll("\n", "<br/>")
|
|
|
+ );
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<BlIndexResponse> queryBlIndex(ReportIndexInquiry request) {
|
|
|
+ String url = apiConfig.getBl() +
|
|
|
+ "?beginTime=" + request.getReqStartTime() +
|
|
|
+ "&endTime=" + request.getReqEndTime() +
|
|
|
+ "&patientId=" + request.getSocialNo();
|
|
|
+
|
|
|
+ List<BlIndexResponse> blIndexList = new ArrayList<>();
|
|
|
+ JSONObject response = template.getForObject(url, JSONObject.class);
|
|
|
+ JSONArray rows = getIndexRows(response);
|
|
|
+ if (null != rows && !rows.isEmpty()) {
|
|
|
+ for (int i = 0; i < rows.size(); i++) {
|
|
|
+ JSONObject row = rows.getJSONObject(i);
|
|
|
+ BlIndexResponse blIndex = JSON.to(BlIndexResponse.class, row);
|
|
|
+ blIndexList.add(blIndex);
|
|
|
+ }
|
|
|
}
|
|
|
- JSONObject response = new RestTemplate().postForObject(
|
|
|
- api + "/detail", request, JSONObject.class);
|
|
|
+ return blIndexList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<XdIndexResponse> queryXdIndex(ReportIndexInquiry request) {
|
|
|
+ String url = apiConfig.getXd() +
|
|
|
+ "?id=" + request.getSocialNo() +
|
|
|
+ "&startTime=" + request.getReqStartTime() +
|
|
|
+ "&endTime=" + request.getReqEndTime();
|
|
|
+
|
|
|
+ List<XdIndexResponse> xdIndexList = new ArrayList<>();
|
|
|
+ JSONObject response = new RestTemplate().getForObject(url, JSONObject.class);
|
|
|
+ JSONArray rows = getIndexRows(response);
|
|
|
+ if (null != rows && !rows.isEmpty()) {
|
|
|
+ for (int i = 0; i < rows.size(); i++) {
|
|
|
+ JSONObject row = rows.getJSONObject(i);
|
|
|
+ XdIndexResponse xdIndex = JSON.to(XdIndexResponse.class, row);
|
|
|
+ xdIndexList.add(xdIndex);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return xdIndexList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private JSONArray getIndexRows(JSONObject response) {
|
|
|
if (null == response) {
|
|
|
throw new BizException(ExceptionEnum.NETWORK_ERROR);
|
|
|
}
|
|
|
- Boolean code = response.getBoolean("code");
|
|
|
- if (null == code || !code) {
|
|
|
+ int code = response.getIntValue("code");
|
|
|
+ if (code != 1) {
|
|
|
throw new BizException(ExceptionEnum.API_ERROR, response.getString("message"));
|
|
|
}
|
|
|
- JSONObject data = response.getJSONObject("data");
|
|
|
- return JSON.parseObject(JSON.toJSONString(data), JyDetailResponse.class);
|
|
|
+ return response.getJSONArray("data");
|
|
|
}
|
|
|
}
|