|
@@ -0,0 +1,120 @@
|
|
|
+package thyyxxk.wxservice_server.service;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+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.entity.ResultVo;
|
|
|
+import thyyxxk.wxservice_server.utils.DateUtil;
|
|
|
+import thyyxxk.wxservice_server.utils.ResultVoUtil;
|
|
|
+
|
|
|
+import java.util.Comparator;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class PowersiPhysicalCheckService {
|
|
|
+ @Value("${physicalCheck}")
|
|
|
+ private String physicalCheckUrl;
|
|
|
+
|
|
|
+ public ResultVo<JSONObject> getPhysicalCheckResult(String tjid) {
|
|
|
+ ResultVo<JSONObject> summary = getSummary(tjid);
|
|
|
+ if (summary.getCode() != ExceptionEnum.SUCCESS.getCode()) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, summary.getMessage());
|
|
|
+ }
|
|
|
+ ResultVo<List<JSONObject>> checkItems = getExamItems(tjid);
|
|
|
+ if (checkItems.getCode() != ExceptionEnum.SUCCESS.getCode()) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, checkItems.getMessage());
|
|
|
+ }
|
|
|
+ ResultVo<JSONObject> examResult = getExamResult(tjid);
|
|
|
+ if (examResult.getCode() != ExceptionEnum.SUCCESS.getCode()) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, examResult.getMessage());
|
|
|
+ }
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+ result.put("summary", summary.getData());
|
|
|
+ List<JSONObject> itemdata = checkItems.getData();
|
|
|
+ itemdata.removeIf(item -> !examResult.getData().containsKey(item.getString("体检单元名称")));
|
|
|
+ result.put("checkItems", itemdata);
|
|
|
+ result.put("examResult", examResult.getData());
|
|
|
+ return ResultVoUtil.success(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ private ResultVo<JSONObject> getSummary(String tjid) {
|
|
|
+ RestTemplate template = new RestTemplate();
|
|
|
+ JSONObject rawdata = template.getForObject(physicalCheckUrl + "7033a7386d0e45d295b7a13dd079704e?tjid=" + tjid, JSONObject.class);
|
|
|
+ if (null == rawdata) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
|
|
|
+ }
|
|
|
+ JSONObject resultCode = rawdata.getJSONObject("result");
|
|
|
+ if (null == resultCode) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
|
|
|
+ }
|
|
|
+ if (resultCode.getInteger("code") == 0) {
|
|
|
+ JSONArray rows = rawdata.getJSONArray("rows");
|
|
|
+ if (null != rows && rows.size() > 0) {
|
|
|
+ return ResultVoUtil.success(rows.getJSONObject(0));
|
|
|
+ }
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST);
|
|
|
+ }
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, resultCode.getString("message"));
|
|
|
+ }
|
|
|
+
|
|
|
+ private ResultVo<List<JSONObject>> getExamItems(String tjid) {
|
|
|
+ RestTemplate template = new RestTemplate();
|
|
|
+ JSONObject rawdata = template.getForObject(physicalCheckUrl + "f9c6ad55fa1b43b8a6f9e44cc7e126b9?tjid=" + tjid, JSONObject.class);
|
|
|
+ if (null == rawdata) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
|
|
|
+ }
|
|
|
+ JSONObject resultCode = rawdata.getJSONObject("result");
|
|
|
+ if (null == resultCode) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
|
|
|
+ }
|
|
|
+ if (resultCode.getInteger("code") == 0) {
|
|
|
+ JSONArray rows = rawdata.getJSONArray("rows");
|
|
|
+ if (null != rows && rows.size() > 0) {
|
|
|
+ List<JSONObject> list = JSONArray.parseArray(rows.toJSONString(), JSONObject.class);
|
|
|
+ list.sort(Comparator.comparing(obj -> ((JSONObject) obj).getLong("检查日期")));
|
|
|
+ for (JSONObject item : list) {
|
|
|
+ item.put("name", item.getString("体检单元名称"));
|
|
|
+ item.put("checkTime", DateUtil.parseTimestamp(item.getLong("检查日期")));
|
|
|
+ }
|
|
|
+ return ResultVoUtil.success(list);
|
|
|
+ }
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST);
|
|
|
+ }
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, resultCode.getString("message"));
|
|
|
+ }
|
|
|
+
|
|
|
+ private ResultVo<JSONObject> getExamResult(String tjid) {
|
|
|
+ RestTemplate template = new RestTemplate();
|
|
|
+ JSONObject rawdata = template.getForObject(physicalCheckUrl + "92eef45c69974df4869b3eed05f5234f?tjid=" + tjid, JSONObject.class);
|
|
|
+ if (null == rawdata) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
|
|
|
+ }
|
|
|
+ JSONObject resultCode = rawdata.getJSONObject("result");
|
|
|
+ if (null == resultCode) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
|
|
|
+ }
|
|
|
+ if (resultCode.getInteger("code") == 0) {
|
|
|
+ JSONArray rows = rawdata.getJSONArray("rows");
|
|
|
+ if (null != rows && rows.size() > 0) {
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+ for (int i = 0; i < rows.size(); i++) {
|
|
|
+ JSONObject item = rows.getJSONObject(i);
|
|
|
+ String key = item.getString("检查单元C");
|
|
|
+ if (result.containsKey(key)) {
|
|
|
+ result.getJSONArray(key).add(item);
|
|
|
+ } else {
|
|
|
+ JSONArray array = new JSONArray();
|
|
|
+ array.add(item);
|
|
|
+ result.put(key, array);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ResultVoUtil.success(result);
|
|
|
+ }
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST);
|
|
|
+ }
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, resultCode.getString("message"));
|
|
|
+ }
|
|
|
+}
|