优化导入效率
This commit is contained in:
parent
8a70b649a2
commit
79c420a64f
@ -31,4 +31,30 @@ pnpm dev
|
||||
|
||||
5. 构建生产版本
|
||||
```bash
|
||||
pnpm build
|
||||
pnpm build
|
||||
|
||||
|
||||
部署tongweb
|
||||
|
||||
1、cd dist
|
||||
|
||||
2、mkdir WEB-INF
|
||||
|
||||
3、touch web.xml
|
||||
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
|
||||
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
|
||||
version="3.1" metadata-complete="true">
|
||||
<display-name>Router for Tomcat</display-name>
|
||||
<error-page>
|
||||
<error-code>404</error-code>
|
||||
<location>/index.html</location>
|
||||
</error-page>
|
||||
</web-app>
|
||||
|
||||
|
||||
4、jar -cvf mps-vue.war *
|
||||
5、将war复制到tongweb安装目录
|
@ -77,9 +77,11 @@ spring:
|
||||
servlet:
|
||||
multipart:
|
||||
# 单个文件大小
|
||||
max-file-size: 10MB
|
||||
max-file-size: 50MB
|
||||
# 设置总上传的文件大小
|
||||
max-request-size: 20MB
|
||||
max-request-size: 100MB
|
||||
#指定上传文件的临时目录,必须带,否则tongweb会报错
|
||||
location: /data/upload_tmp
|
||||
mvc:
|
||||
# 设置静态资源路径 防止所有请求都去查静态资源
|
||||
static-path-pattern: /static/**
|
||||
|
@ -10,6 +10,8 @@ import org.apache.ibatis.annotations.Param;
|
||||
import org.dromara.common.mybatis.annotation.DataColumn;
|
||||
import org.dromara.common.mybatis.annotation.DataPermission;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* ${functionName}Mapper接口
|
||||
*
|
||||
@ -33,4 +35,7 @@ public interface ${ClassName}Mapper extends BaseMapperPlus<${ClassName}, ${Class
|
||||
//})
|
||||
// List<SysUserExportVo> select${ClassName}ExportList(@Param(Constants.WRAPPER) Wrapper<${ClassName}> queryWrapper);
|
||||
|
||||
// 批量插入
|
||||
void batchInsert(@Param("list") Collection<${ClassName}> list);
|
||||
|
||||
}
|
||||
|
@ -50,7 +50,30 @@ public class ${ClassName}ServiceImpl implements I${ClassName}Service {
|
||||
if (isUpdateSupport) {
|
||||
baseMapper.insertOrUpdateBatch(list);
|
||||
} else {
|
||||
baseMapper.insertBatch(list);
|
||||
//baseMapper.insertBatch(list);
|
||||
|
||||
/**
|
||||
* 多笔写入方式有循环写入、开启数据库batch模式、sql拼接后多笔入库以及mapper foreach多笔写入模式
|
||||
* 经对比验证,foreach方式效率最高
|
||||
*
|
||||
* **/
|
||||
|
||||
//由于mybatis的批量方法为伪批量,以下优化为真批量
|
||||
//SqlHelper与service的注解事务管理冲突,所以此处自行写分批
|
||||
int batchSize = 1000;//每批1000条
|
||||
List<${ClassName}> batchList = new ArrayList<>(batchSize);
|
||||
for (${ClassName} item : list) {
|
||||
batchList.add(item);
|
||||
if (batchList.size() == batchSize) {
|
||||
baseMapper.batchInsert(batchList);
|
||||
batchList.clear();
|
||||
}
|
||||
}
|
||||
|
||||
// 处理最后一批不满batchSize的数据
|
||||
if (!batchList.isEmpty()) {
|
||||
baseMapper.batchInsert(batchList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,4 +4,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="${packageName}.mapper.${ClassName}Mapper">
|
||||
|
||||
<!--mysql写法,达梦兼容-->
|
||||
<insert id="batchInsert">
|
||||
INSERT INTO ${tableName}
|
||||
(
|
||||
#foreach($column in $columns)
|
||||
$column.columnName#if($foreach.count != $columns.size()),#end
|
||||
#end
|
||||
)
|
||||
VALUES
|
||||
<foreach collection="list" item="item" separator=",">
|
||||
(
|
||||
#foreach($column in $columns)
|
||||
#{item.$column.javaField}#if($foreach.count != $columns.size()),#end
|
||||
#end
|
||||
)
|
||||
</foreach>
|
||||
</insert>
|
||||
</mapper>
|
||||
|
@ -10,6 +10,8 @@ import org.apache.ibatis.annotations.Param;
|
||||
import org.dromara.common.mybatis.annotation.DataColumn;
|
||||
import org.dromara.common.mybatis.annotation.DataPermission;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* 个人手机银行签约明细Mapper接口
|
||||
*
|
||||
@ -33,4 +35,6 @@ public interface OriginalMobileBankSignupMapper extends BaseMapperPlus<OriginalM
|
||||
//})
|
||||
// List<SysUserExportVo> selectOriginalMobileBankSignupExportList(@Param(Constants.WRAPPER) Wrapper<OriginalMobileBankSignup> queryWrapper);
|
||||
|
||||
// 批量插入(MySQL多值语法)
|
||||
void batchInsert(@Param("list") Collection<OriginalMobileBankSignup> list);
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package org.dromara.original.service.impl;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import org.dromara.common.core.utils.MapstructUtils;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
@ -20,6 +19,7 @@ import org.dromara.original.service.IOriginalMobileBankSignupService;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 个人手机银行签约明细Service业务层处理
|
||||
@ -48,7 +48,22 @@ public class OriginalMobileBankSignupServiceImpl implements IOriginalMobileBankS
|
||||
if (isUpdateSupport) {
|
||||
baseMapper.insertOrUpdateBatch(list);
|
||||
} else {
|
||||
baseMapper.insertBatch(list);
|
||||
//由于mybatis的批量方法为伪批量,以下优化为真批量
|
||||
//SqlHelper与service的注解事务管理冲突,所以此处自行写分批
|
||||
int batchSize = 1000;//每批1000条
|
||||
List<OriginalMobileBankSignup> batchList = new ArrayList<>(batchSize);
|
||||
for (OriginalMobileBankSignup item : list) {
|
||||
batchList.add(item);
|
||||
if (batchList.size() == batchSize) {
|
||||
baseMapper.batchInsert(batchList);
|
||||
batchList.clear();
|
||||
}
|
||||
}
|
||||
|
||||
// 处理最后一批不满batchSize的数据
|
||||
if (!batchList.isEmpty()) {
|
||||
baseMapper.batchInsert(batchList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,4 +4,36 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.dromara.original.mapper.OriginalMobileBankSignupMapper">
|
||||
|
||||
<!--mysql写法,达梦兼容-->
|
||||
<insert id="batchInsert">
|
||||
INSERT INTO original_mobile_bank_signup
|
||||
(
|
||||
branch_name,
|
||||
branch_code,
|
||||
customer_name,
|
||||
id_type,
|
||||
id_number,
|
||||
main_account,
|
||||
signup_date,
|
||||
auth_method,
|
||||
serial_number,
|
||||
teller
|
||||
)
|
||||
VALUES
|
||||
<foreach collection="list" item="item" separator=",">
|
||||
(
|
||||
#{item.branchName},
|
||||
#{item.branchCode},
|
||||
#{item.customerName},
|
||||
#{item.idType},
|
||||
#{item.idNumber},
|
||||
#{item.mainAccount},
|
||||
#{item.signupDate},
|
||||
#{item.authMethod},
|
||||
#{item.serialNumber},
|
||||
#{item.teller}
|
||||
)
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
</mapper>
|
||||
|
Loading…
Reference in New Issue
Block a user