北京经济技术开发区经开区虚拟城市项目-【后端】-服务,Poi,企业,地块等定制接口
13693261870
2023-10-05 e60b6c9cdc11fd436a0bcae225d1789db04c9504
测试数据入库功能
已修改7个文件
97 ■■■■■ 文件已修改
pom.xml 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/smartearth/poiexcel/config/InitConfig.java 18 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/smartearth/poiexcel/controller/EntController.java 38 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/smartearth/poiexcel/entity/EntEntity.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/smartearth/poiexcel/service/EntService.java 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/application.properties 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mybatis.xml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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>
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();
    }
}
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);
        }
    }
}
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;
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请求(Rest)
     */
    public <T> T getForRest(String url, Class<T> clazz) {
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
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 利用本地缓存机制(Local Cache)防止循环引用(circular references)和加速联复嵌套査询。-->
        <setting name="localCacheScope" value="SESSION"/>
        <!--当没有为参数提供特定的 JDBC 类型时,为空值指定 JDBC 类型-->
@@ -29,7 +29,7 @@
        <!--指定当结果集中值为 null 时,是否调用映射对象的 setter(map 对象时为 put)方法-->
        <setting name="callSettersOnNulls" value="true"/>
        <!--指定 MyBatis 所用日志的具体实现:LOG4J/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"/>