From 7809d3861ba70b8751f739d1ddaca3a60109fe1a Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期四, 05 十月 2023 15:19:27 +0800
Subject: [PATCH] 添加获取令牌、获取企业信息接口

---
 src/main/java/com/smartearth/poiexcel/service/EntService.java |   60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 56 insertions(+), 4 deletions(-)

diff --git a/src/main/java/com/smartearth/poiexcel/service/EntService.java b/src/main/java/com/smartearth/poiexcel/service/EntService.java
index 2e66ae3..94165f8 100644
--- a/src/main/java/com/smartearth/poiexcel/service/EntService.java
+++ b/src/main/java/com/smartearth/poiexcel/service/EntService.java
@@ -1,5 +1,7 @@
 package com.smartearth.poiexcel.service;
 
+import com.alibaba.fastjson.JSONObject;
+import com.smartearth.poiexcel.entity.*;
 import com.smartearth.poiexcel.mapper.EntMapper;
 import com.smartearth.poiexcel.utils.RestHelper;
 import org.apache.commons.logging.Log;
@@ -12,6 +14,7 @@
 import javax.annotation.Resource;
 import java.lang.reflect.Field;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -37,17 +40,27 @@
 
     private final static String generateToken = "%s/yqfwg/app/generateToken";
 
-    private final static String getEntBaseInfo = "%s/yqfwg/api/project/getEntBaseInfoForOtherSysListPage?ctoken=%s&buildDate_startdate=%s&buildDate_enddate=%s&qylabel=%s&showCount=%d&currentPage=%d";
+    private final static String getEntBaseInfo = "%s/yqfwg/api/project/getEntBaseInfoForOtherSysListPage?ctoken=%s&showCount=%d&currentPage=%d";
 
-    public String getToken() {
+    /**
+     * 鑾峰彇浠ょ墝
+     */
+    public String selectToken() {
         try {
             String url = String.format(generateToken, host);
 
-            Map<String, String> map = new HashMap<>(2);
+            Map<String, Object> map = new HashMap<>(2);
             map.put("userName", user);
             map.put("passWord", pwd);
 
-            return null;
+            Result rs = postForRest(url, map, Result.class);
+            if (null == rs || StaticData.I200 != rs.getCode()) {
+                return null;
+            }
+
+            TokenResult tr = JSONObject.parseObject(rs.getData(), TokenResult.class);
+
+            return tr.getCtoken();
         } catch (Exception ex) {
             log.error(ex.getMessage(), ex);
             return null;
@@ -55,6 +68,45 @@
     }
 
     /**
+     * 鏌ヨ浼佷笟
+     */
+    public List<EntEntity> selectEnts(String token, String startDate, String endDate, String qylabel, Integer showCount, Integer currentPage) {
+        try {
+            String url = String.format(getEntBaseInfo, host, token, showCount, currentPage);
+            if (null != startDate) {
+                url += "&buildDate_startdate=" + startDate;
+            }
+            if (null != endDate) {
+                url += "&buildDate_enddate=" + endDate;
+            }
+            if (null != qylabel) {
+                url += "&qylabel=" + qylabel;
+            }
+
+            Result rs = getForRest(url, Result.class);
+            if (null == rs || StaticData.I200 != rs.getCode()) {
+                return null;
+            }
+
+            EntResult er = JSONObject.parseObject(rs.getData(), EntResult.class);
+
+            return er.getPd().getList();
+        } catch (Exception ex) {
+            log.error(ex.getMessage(), ex);
+            return null;
+        }
+    }
+
+    /**
+     * get璇锋眰锛圧est锛�
+     */
+    public <T> T getForRest(String url, Class<T> clazz) {
+        RestTemplate rest = RestHelper.getRestTemplate();
+
+        return rest.getForObject(url, clazz);
+    }
+
+    /**
      * post璇锋眰锛圧est锛�
      */
     public <T> T postForRest(String url, Map<String, Object> map, Class<T> clazz) {

--
Gitblit v1.9.3