From ff16d1213d5e43b21d3f72551c83dd007bec2261 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期六, 07 十月 2023 15:41:28 +0800
Subject: [PATCH] 修改Rest帮助类

---
 src/main/java/com/smartearth/poiexcel/service/EntService.java |  122 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 120 insertions(+), 2 deletions(-)

diff --git a/src/main/java/com/smartearth/poiexcel/service/EntService.java b/src/main/java/com/smartearth/poiexcel/service/EntService.java
index 3315d09..8674363 100644
--- a/src/main/java/com/smartearth/poiexcel/service/EntService.java
+++ b/src/main/java/com/smartearth/poiexcel/service/EntService.java
@@ -1,9 +1,19 @@
 package com.smartearth.poiexcel.service;
 
+import com.google.common.collect.Lists;
+import com.smartearth.poiexcel.entity.*;
 import com.smartearth.poiexcel.mapper.EntMapper;
+import com.smartearth.poiexcel.utils.RestHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.http.*;
 import org.springframework.stereotype.Service;
+import org.springframework.util.LinkedMultiValueMap;
+import org.springframework.util.MultiValueMap;
 
 import javax.annotation.Resource;
+import java.util.List;
 
 /**
  * 浼佷笟鏈嶅姟绫�
@@ -11,9 +21,117 @@
  * @date 2023-10-05
  */
 @Service
-public class EntService implements EntMapper {
+@SuppressWarnings("ALL")
+public class EntService {
     @Resource
     EntMapper entMapper;
 
-    //
+    @Value("${qylweb.host}")
+    String host;
+
+    @Value("${qylweb.user}")
+    String user;
+
+    @Value("${qylweb.pwd}")
+    String pwd;
+
+    private final static Log log = LogFactory.getLog(EntService.class);
+
+    private final static String GENERATE_TOKEN = "%s/yqfwg/app/generateToken";
+
+    private final static String GET_ENT_BASE_INFO = "%s/yqfwg/api/project/getEntBaseInfoForOtherSysListPage?ctoken=%s&showCount=%d&currentPage=%d";
+
+    /**
+     * 鑾峰彇浠ょ墝
+     */
+    public String selectToken() {
+        try {
+            String url = String.format(GENERATE_TOKEN, host);
+
+            //Map<String, String> map = new HashMap<>(2);
+            //map.put("userName", user);
+            //map.put("passWord", pwd);
+
+            //String map = "userName=shikong001&passWord=123!@#qwe";
+
+            // 璇锋眰澶翠俊鎭�
+            HttpHeaders headers = new HttpHeaders();
+            headers.setContentType(MediaType.valueOf("application/x-www-form-urlencoded"));
+
+            //璁剧疆涓鸿〃鍗曟彁浜わ紝鎸夐渶姹傚姞
+            headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
+            // 缁勮璇锋眰淇℃伅
+            MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
+            map.add("userName", user);
+            map.add("passWord", pwd);
+            HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>(map, headers);
+
+            // String str = RestHelper.postForRest(url, map)
+            Result rs = RestHelper.postForRest(url, map, Result.class);
+            if (null == rs || StaticData.I200 != rs.getCode()) {
+                return null;
+            }
+
+            // TokenResult tr = JSONObject.parseObject(rs.getData().toJSONString(), TokenResult.class)
+            TokenResult tr = rs.getData().toJavaObject(TokenResult.class);
+
+            return tr.getCtoken();
+        } catch (Exception ex) {
+            log.error(ex.getMessage(), ex);
+            return null;
+        }
+    }
+
+    /**
+     * 鏌ヨ浼佷笟
+     */
+    public List<EntEntity> selectEnts(String token, String startDate, String endDate, String qylabel, Integer showCount, Integer currentPage) {
+        try {
+            String url = String.format(GET_ENT_BASE_INFO, 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 = RestHelper.getForRest(url, Result.class);
+            if (null == rs || StaticData.I200 != rs.getCode()) {
+                return null;
+            }
+
+            // EntResult er = JSONObject.parseObject(rs.getData().toJSONString(), EntResult.class)
+            EntResult er = rs.getData().toJavaObject(EntResult.class);
+
+            return er.getPd().getList();
+        } catch (Exception ex) {
+            log.error(ex.getMessage(), ex);
+            return null;
+        }
+    }
+
+    /**
+     * 鎻掑叆浼佷笟
+     */
+    public Integer insertEnts(List<EntEntity> list) {
+        try {
+            int rows = 0;
+            List<List<EntEntity>> subLists = Lists.partition(list, StaticData.I200);
+            for (List<EntEntity> sub : subLists) {
+                try {
+                    rows += entMapper.insertBatch(sub);
+                } catch (Exception ex) {
+                    log.error(ex);
+                }
+            }
+
+            return rows;
+        } catch (Exception ex) {
+            log.error(ex.getMessage(), ex);
+            return 0;
+        }
+    }
 }

--
Gitblit v1.9.3