From e60b6c9cdc11fd436a0bcae225d1789db04c9504 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期四, 05 十月 2023 16:37:11 +0800
Subject: [PATCH] 测试数据入库功能

---
 src/main/java/com/smartearth/poiexcel/service/EntService.java       |   24 ++++++++++++
 src/main/resources/application.properties                           |    4 +-
 src/main/resources/mybatis.xml                                      |    4 +-
 src/main/java/com/smartearth/poiexcel/controller/EntController.java |   38 +++++++++++++++++++
 pom.xml                                                             |    6 ++
 src/main/java/com/smartearth/poiexcel/config/InitConfig.java        |   18 ++++++++-
 src/main/java/com/smartearth/poiexcel/entity/EntEntity.java         |    3 +
 7 files changed, 90 insertions(+), 7 deletions(-)

diff --git a/pom.xml b/pom.xml
index a1ea8d8..218eef6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,12 +10,15 @@
     </parent>
     <groupId>com.smartearth</groupId>
     <artifactId>poiExcel</artifactId>
-    <version>0.0.1</version>
+    <version>0.1</version>
     <name>poiExcel</name>
+    <packaging>jar</packaging>
     <description>poiExcel</description>
+
     <properties>
         <java.version>1.8</java.version>
     </properties>
+
     <dependencies>
         <dependency>
             <groupId>org.springframework.boot</groupId>
@@ -138,6 +141,7 @@
         <dependency>
             <groupId>mysql</groupId>
             <artifactId>mysql-connector-java</artifactId>
+            <version>8.0.21</version>
         </dependency>
         <!--jdbc-->
         <dependency>
diff --git a/src/main/java/com/smartearth/poiexcel/config/InitConfig.java b/src/main/java/com/smartearth/poiexcel/config/InitConfig.java
index b71c821..24c0e11 100644
--- a/src/main/java/com/smartearth/poiexcel/config/InitConfig.java
+++ b/src/main/java/com/smartearth/poiexcel/config/InitConfig.java
@@ -2,16 +2,20 @@
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.smartearth.poiexcel.entity.EntEntity;
 import com.smartearth.poiexcel.entity.EntResult;
 import com.smartearth.poiexcel.entity.Result;
 import com.smartearth.poiexcel.entity.TokenResult;
+import com.smartearth.poiexcel.mapper.EntMapper;
+import com.smartearth.poiexcel.service.EntService;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.springframework.boot.ApplicationArguments;
 import org.springframework.boot.ApplicationRunner;
 import org.springframework.stereotype.Component;
 
+import javax.annotation.Resource;
 import java.util.List;
 
 /**
@@ -20,15 +24,21 @@
  */
 @Component
 public class InitConfig implements ApplicationRunner {
+    @Resource
+    EntService entService;
+
+    @Resource
+    EntMapper entMapper;
+
     private final static Log log = LogFactory.getLog(InitConfig.class);
 
     @Override
     public void run(ApplicationArguments args) {
         // noinspection AlibabaRemoveCommentedCode
         try {
-            //test();
-
             log.info("***************** 绯荤粺鍚姩瀹屾瘯 *****************" + "\n");
+
+            test();
         } catch (Exception ex) {
             log.error(ex.getMessage(), ex);
         }
@@ -38,6 +48,8 @@
      * 娴嬭瘯
      */
     private void test() {
+        List<EntEntity> list = entMapper.selectList(new QueryWrapper<>());
+
         String tokenJson = "{\"success\":true,\"code\":200,\"message\":\"鎴愬姛\",\"data\":{\"ctoken\":\"ZmYxZTgyN2QxZTYyNDMxMDhjZjgzNDNiNDZiN2RjMDVAYTc3ZmFlOGE5ZGM0OGQ1Y2ZmODY4ZTFmNWYwZTEzM2E=\",\"userInfo\":{\"loginLogId\":\"1ab1675c3632428a84dc0ebe579cd66f\",\"phoneNumber\":\"\",\"displayName\":\"鏃剁┖涓�寮犲浘\",\"userMail\":\"\",\"departLevel\":\"5-1\",\"id\":\"ff1e827d1e6243108cf8343b46b7dc05\",\"userID\":\"shikong001\",\"uniqueID\":\"\",\"departName\":\"姹借溅鍜屾櫤鑳藉埗閫犱骇涓氫笓鐝璡"},\"expires\":3600,\"roles\":[]}}";
         Result rsToken = JSON.parseObject(tokenJson, Result.class);
         // TokenResult tr = JSON.parseObject(rs.getData().toJSONString(), TokenResult.class)
@@ -49,6 +61,8 @@
         EntResult er = JSONObject.parseObject(rsEnt.getData(), EntResult.class);
         List<EntEntity> entList = er.getPd().getList();
 
+        int rows = entService.insertEnts(entList);
+
         int len = tokenJson.length();
     }
 }
diff --git a/src/main/java/com/smartearth/poiexcel/controller/EntController.java b/src/main/java/com/smartearth/poiexcel/controller/EntController.java
index 450d4ac..f1baa5b 100644
--- a/src/main/java/com/smartearth/poiexcel/controller/EntController.java
+++ b/src/main/java/com/smartearth/poiexcel/controller/EntController.java
@@ -71,4 +71,42 @@
             return fail(ex, -1);
         }
     }
+
+    @ApiOperation(value = "鎻掑叆浼佷笟")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "token", value = "浠ょ墝", dataType = "String", paramType = "query", example = ""),
+            @ApiImplicitParam(name = "startDate", value = "寮�濮嬫棩鏈�", dataType = "String", paramType = "query", example = "2023-06-29"),
+            @ApiImplicitParam(name = "endDate", value = "缁撴潫鏃ユ湡", dataType = "String", paramType = "query", example = "2023-06-30"),
+            @ApiImplicitParam(name = "qylabel", value = "鏍囩", dataType = "Integer", paramType = "query", example = "寮�涓�"),
+            @ApiImplicitParam(name = "showCount", value = "鏄剧ず璁板綍鏁�", dataType = "Integer", paramType = "query", example = "10"),
+            @ApiImplicitParam(name = "currentPage", value = "褰撳墠鍒嗛〉鏁�", dataType = "Integer", paramType = "query", example = "1")
+    })
+    @GetMapping({"/insertEnts"})
+    public ResponseMsg<Object> insertEnts(String token, String startDate, String endDate, String qylabel, Integer showCount, Integer currentPage) {
+        try {
+            if (StringHelper.isEmpty(token)) {
+                token = entService.selectToken();
+            }
+            if (StringHelper.isEmpty(token)) {
+                return fail("鏌ヨ浠ょ墝澶辫触");
+            }
+            if (null == showCount || showCount < 1) {
+                showCount = 10;
+            }
+            if (null == currentPage || currentPage < 1) {
+                currentPage = 1;
+            }
+
+            List<EntEntity> list = entService.selectEnts(token, startDate, endDate, qylabel, showCount, currentPage);
+            if (null == list || list.isEmpty()) {
+                return fail("鏌ヨ浼佷笟涓虹┖");
+            }
+
+            Integer rows = entService.insertEnts(list);
+
+            return success(rows);
+        } catch (Exception ex) {
+            return fail(ex, -1);
+        }
+    }
 }
diff --git a/src/main/java/com/smartearth/poiexcel/entity/EntEntity.java b/src/main/java/com/smartearth/poiexcel/entity/EntEntity.java
index dc39763..a900eb5 100644
--- a/src/main/java/com/smartearth/poiexcel/entity/EntEntity.java
+++ b/src/main/java/com/smartearth/poiexcel/entity/EntEntity.java
@@ -1,5 +1,7 @@
 package com.smartearth.poiexcel.entity;
 
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.AllArgsConstructor;
 import lombok.Data;
@@ -20,6 +22,7 @@
 public class EntEntity implements Serializable {
     private static final long serialVersionUID = -8624235184539814990L;
 
+    @TableId(type = IdType.AUTO)
     private Long id;
 
     private String entName;
diff --git a/src/main/java/com/smartearth/poiexcel/service/EntService.java b/src/main/java/com/smartearth/poiexcel/service/EntService.java
index 94165f8..24b5270 100644
--- a/src/main/java/com/smartearth/poiexcel/service/EntService.java
+++ b/src/main/java/com/smartearth/poiexcel/service/EntService.java
@@ -1,7 +1,9 @@
 package com.smartearth.poiexcel.service;
 
 import com.alibaba.fastjson.JSONObject;
+import com.google.common.collect.Lists;
 import com.smartearth.poiexcel.entity.*;
+import com.smartearth.poiexcel.mapper.BasicMapper;
 import com.smartearth.poiexcel.mapper.EntMapper;
 import com.smartearth.poiexcel.utils.RestHelper;
 import org.apache.commons.logging.Log;
@@ -98,6 +100,28 @@
     }
 
     /**
+     * 鎻掑叆浼佷笟
+     */
+    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;
+        }
+    }
+
+    /**
      * get璇锋眰锛圧est锛�
      */
     public <T> T getForRest(String url, Class<T> clazz) {
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index bb5afb2..8517f64 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -8,8 +8,8 @@
 
 # 数据源配置
 spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
-spring.datasource.driverClassName=com.mysql.jdbc.Driver
-spring.datasource.url=jdbc:mysql://127.0.0.1:3306/yssh?useUnicode=true&rewriteBatchedStatements=true&characterEncoding=utf-8&useSSL=true&serverTimezone=GMT%2B8
+spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
+spring.datasource.url=jdbc:mysql://127.0.0.1:3306/smart_earth?useUnicode=true&rewriteBatchedStatements=true&characterEncoding=utf-8&useSSL=true&serverTimezone=GMT%2B8
 spring.datasource.username=root
 spring.datasource.password=mysql
 
diff --git a/src/main/resources/mybatis.xml b/src/main/resources/mybatis.xml
index 754cee0..f5d64a8 100644
--- a/src/main/resources/mybatis.xml
+++ b/src/main/resources/mybatis.xml
@@ -19,7 +19,7 @@
         <!--榛樿杩斿洖鐨勬潯鏁伴檺鍒�-->
         <setting name="defaultFetchSize" value="1000"/>
         <!--鏄惁寮�鍚嚜鍔ㄩ┘宄板懡鍚嶈鍒欐槧灏勶紝鍗充粠缁忓吀鏁版嵁搴撳垪鍚� A_COLUMN 鍒扮粡鍏� Java 灞炴�у悕 aColumn 鐨勭被浼兼槧灏�-->
-        <setting name="mapUnderscoreToCamelCase" value="true"/>
+        <setting name="mapUnderscoreToCamelCase" value="false"/>
         <!--MyBatis 鍒╃敤鏈湴缂撳瓨鏈哄埗锛圠ocal Cache锛夐槻姝㈠惊鐜紩鐢紙circular references锛夊拰鍔犻�熻仈澶嶅祵濂楁熁璇€��-->
         <setting name="localCacheScope" value="SESSION"/>
         <!--褰撴病鏈変负鍙傛暟鎻愪緵鐗瑰畾鐨� JDBC 绫诲瀷鏃讹紝涓虹┖鍊兼寚瀹� JDBC 绫诲瀷-->
@@ -29,7 +29,7 @@
         <!--鎸囧畾褰撶粨鏋滈泦涓�间负 null 鏃讹紝鏄惁璋冪敤鏄犲皠瀵硅薄鐨� setter锛坢ap 瀵硅薄鏃朵负 put锛夋柟娉�-->
         <setting name="callSettersOnNulls" value="true"/>
         <!--鎸囧畾 MyBatis 鎵�鐢ㄦ棩蹇楃殑鍏蜂綋瀹炵幇锛歀OG4J/LOG4J2/SLF4J/STDOUT_LOGGING/NO_LOGGING-->
-        <setting name="logImpl" value="NO_LOGGING" />
+        <setting name="logImpl" value="STDOUT_LOGGING" />
     </settings>
     <typeAliases>
         <package name="com.smartearth.poiexcel.entity"/>

--
Gitblit v1.9.3