|
|
@@ -0,0 +1,72 @@
|
|
|
+package org.thyy.thirdpartapi.inspection.inspectionImpl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson2.JSONArray;
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+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.response.jy.JyDetailResponse;
|
|
|
+import org.thyy.thirdpartapi.inspection.response.jy.JyIndexResponse;
|
|
|
+import org.thyy.utils.exception.BizException;
|
|
|
+import org.thyy.utils.exception.ExceptionEnum;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service(value = "csth")
|
|
|
+public class ThyyInspectionImpl implements InspectionInterface {
|
|
|
+ private String api;
|
|
|
+ private final RestTemplate restTemplate;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public ThyyInspectionImpl( RestTemplate restTemplate) {
|
|
|
+ this.restTemplate = restTemplate;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void init(InspectionApi inspectionApi, InspectionApi.Config config) {
|
|
|
+ this.api = config.getJy();
|
|
|
+ log.info("检验检查模块初始化: {}", api);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<JyIndexResponse> queryExamIndex(JSONObject request) {
|
|
|
+ JSONObject response = restTemplate.postForObject(api + "/self", request, JSONObject.class);
|
|
|
+ if (null == response) {
|
|
|
+ throw new BizException(ExceptionEnum.NETWORK_ERROR);
|
|
|
+ }
|
|
|
+ Boolean code = response.getBoolean("code");
|
|
|
+ if (null == code || !code) {
|
|
|
+ throw new BizException(ExceptionEnum.API_ERROR, response.getString("message"));
|
|
|
+ }
|
|
|
+ JSONObject data = response.getJSONObject("data");
|
|
|
+ JSONArray items = data.getJSONArray("items");
|
|
|
+ List<JyIndexResponse> examIndexList = new ArrayList<>();
|
|
|
+ for (int i = 0; i < items.size(); i++) {
|
|
|
+ JSONObject item = items.getJSONObject(i);
|
|
|
+ String jsonString = item.toJSONString();
|
|
|
+ JyIndexResponse examIndexResponse = JSONObject.parseObject(jsonString, JyIndexResponse.class);
|
|
|
+ examIndexList.add(examIndexResponse);
|
|
|
+ }
|
|
|
+ return examIndexList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public JyDetailResponse queryExamDetail(JSONObject request) {
|
|
|
+ JSONObject response = new RestTemplate().postForObject(
|
|
|
+ api + "/detail", request, JSONObject.class);
|
|
|
+ if (null == response) {
|
|
|
+ throw new BizException(ExceptionEnum.NETWORK_ERROR);
|
|
|
+ }
|
|
|
+ Boolean code = response.getBoolean("code");
|
|
|
+ if (null == code || !code) {
|
|
|
+ throw new BizException(ExceptionEnum.API_ERROR, response.getString("message"));
|
|
|
+ }
|
|
|
+ String data = response.getJSONObject("data").toJSONString();
|
|
|
+ return JSONObject.parseObject(data, JyDetailResponse.class);
|
|
|
+ }
|
|
|
+}
|