Browse Source

接口调整

Perperon 1 month ago
parent
commit
b6eb36fd88

+ 7 - 4
projects-service/src/main/java/com/rtrh/projects/modules/projects/service/impl/SubRptContServiceImpl.java

@@ -13,6 +13,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import com.google.common.base.CaseFormat;
+import com.rtrh.core.vo.ListMessage;
 import com.rtrh.projects.modules.projects.enums.ProjectStatusEnum;
 import com.rtrh.projects.modules.projects.enums.SubIsHideStatusEnum;
 import com.rtrh.projects.modules.projects.mapper.*;
@@ -25,7 +26,9 @@ import com.rtrh.projects.modules.system.service.SecUserService;
 import com.rtrh.projects.modules.utils.DateUtils;
 import com.rtrh.projects.outapi.vo.SubMonthReportVO;
 import com.rtrh.projects.outapi.vo.report.ListQueryVO;
+import com.rtrh.projects.util.CommonMessage;
 import com.rtrh.projects.util.HttpClientUtil;
+import com.rtrh.projects.util.ResponseRows;
 import com.rtrh.projects.util.TargetDataSource;
 import com.rtrh.projects.vo.RemoteRequestDto;
 import org.apache.commons.collections4.CollectionUtils;
@@ -130,10 +133,10 @@ public class SubRptContServiceImpl implements SubRptContService {
 		RemoteRequestDto requestDto = new RemoteRequestDto();
 		requestDto.setRptVO(queryVO);
 		requestDto.setPage(page);
-		Object o = HttpClientUtil.fgwPostRequest("/outApi/remote/findListQuery", requestDto);
-		List<Map> data = JSONObject.parseArray(o.toString()).toJavaList(Map.class);
-		page.setList(data);
-		page.setTotalCount(queryVO.getOuttotal());
+		Object o = HttpClientUtil.fgwPostRequest("/outApi/remote/findListQuery", requestDto, ResponseRows.COMMONMESSAGE.getType());
+		CommonMessage commonMessage = (CommonMessage)o;
+		page.setList(commonMessage.getRows());
+		page.setTotalCount(commonMessage.getTotal());
 		return page;
 	}
 

+ 91 - 0
projects-service/src/main/java/com/rtrh/projects/util/CommonMessage.java

@@ -0,0 +1,91 @@
+package com.rtrh.projects.util;
+
+/**
+ * @author dupengcheng
+ * @date 2025/3/6
+ * @apiNote
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 通用分页数据封装类
+ */
+public class CommonMessage {
+    private int records;
+    public long total = 0L;
+    private Object data;
+    private List rows;
+    private String message;
+    private boolean success = true;
+
+    public CommonMessage() {
+    }
+
+    public Object getData() {
+        return this.data;
+    }
+
+    public void setData(Object data) {
+        this.data = data;
+    }
+
+    public List getRows() {
+        if (this.rows == null) {
+            this.rows = new ArrayList();
+        }
+
+        return this.rows;
+    }
+
+    public String getMessage() {
+        return this.message;
+    }
+
+    public void setMessage(String message) {
+        this.message = message;
+    }
+
+    public boolean isSuccess() {
+        return this.success;
+    }
+
+    public void setSuccess(boolean success) {
+        this.success = success;
+    }
+
+    public void add(List result) {
+        this.success = true;
+        this.message = "";
+        this.total = (long)result.size();
+        this.rows = result;
+    }
+
+    public void add(List result, long total) {
+        this.success = true;
+        this.total = total;
+        this.message = "";
+        this.records = result.size();
+        this.rows = result;
+    }
+
+    public void add(String errorMessage) {
+        this.success = false;
+        this.setMessage(errorMessage);
+        this.rows = null;
+    }
+
+    public void addSuccess(String message) {
+        this.success = true;
+        this.setMessage(message);
+    }
+
+    public int getRecords() {
+        return this.records;
+    }
+
+    public long getTotal() {
+        return total;
+    }
+}

+ 57 - 0
projects-service/src/main/java/com/rtrh/projects/util/HttpClientUtil.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.SerializationFeature;
 // import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
+import com.rtrh.core.vo.ListMessage;
 import com.rtrh.core.vo.Message;
 import com.rtrh.projects.modules.projects.po.SubPreNew;
 import lombok.extern.slf4j.Slf4j;
@@ -134,6 +135,52 @@ public class HttpClientUtil {
         return null;
     }
 
+    public static Object sendPostRequestPage(String url, Object jsonBody, Map<String, String> headers) {
+        try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
+            // 创建 POST 请求
+            HttpPost request = new HttpPost(url);
+
+            // 设置请求头
+            if (headers != null) {
+                for (Map.Entry<String, String> entry : headers.entrySet()) {
+                    request.addHeader(entry.getKey(), entry.getValue());
+                }
+            }
+
+            ObjectMapper objectMapper = new ObjectMapper();
+            // 注册Java 8日期时间模块
+            // objectMapper.registerModule(new JavaTimeModule());
+            // 禁用时间戳格式,默认改为ISO-8601格式
+            // objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
+            // 自定义日期格式为数据库兼容格式
+            // objectMapper.setDateFormat(new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
+            String jsonBodyStr = objectMapper.writeValueAsString(jsonBody);
+
+            // 设置请求体
+            if (!jsonBodyStr.isEmpty()) {
+                StringEntity entity = new StringEntity(jsonBodyStr, StandardCharsets.UTF_8);
+                entity.setContentType("application/json");
+                request.setEntity(entity);
+            }
+
+            // 发送请求并获取响应
+            try (CloseableHttpResponse response = httpClient.execute(request)) {
+                HttpEntity entity = response.getEntity();
+                if (entity != null) {
+                    String responseBody = EntityUtils.toString(entity, StandardCharsets.UTF_8);
+                    if (!responseBody.isEmpty()){
+                        return JSON.parseObject(responseBody, CommonMessage.class);
+                    }
+                }
+            }catch (Exception e) {
+                e.printStackTrace();
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
     public static Object sendPostRequest(String url, Object jsonBody) {
         return sendPostRequest(url, jsonBody, null);
     }
@@ -143,4 +190,14 @@ public class HttpClientUtil {
         String inUrl = resourceBundle.getString("app.fgw.in.url");
         return sendPostRequest(inUrl + s, jsonBody);
     }
+
+    public static Object fgwPostRequest(String s, Object jsonBody,String type) {
+        ResourceBundle resourceBundle = ResourceBundle.getBundle("config");
+        String inUrl = resourceBundle.getString("app.fgw.in.url");
+        if (ResponseRows.COMMONMESSAGE.getType().equals(type)){
+            return sendPostRequestPage(inUrl + s, jsonBody,null);
+        }else{
+            return sendPostRequest(inUrl + s, jsonBody);
+        }
+    }
 }

+ 21 - 0
projects-service/src/main/java/com/rtrh/projects/util/ResponseRows.java

@@ -0,0 +1,21 @@
+package com.rtrh.projects.util;
+
+/**
+ * @author dupengcheng
+ * @date 2025/3/6
+ * @apiNote
+ */
+public enum ResponseRows {
+    MESSAGE("message"),
+    COMMONMESSAGE("commonMessage");
+
+    private final String type;
+
+    private ResponseRows(String type){
+        this.type= type;
+    }
+
+    public String getType() {
+        return type;
+    }
+}