新增DAO批量更新语句,动态ExecutorType指定,新增 defaultBatchSize 批量分批默认大小设定

This commit is contained in:
thinkgem
2022-06-06 23:41:05 +08:00
parent e03991b347
commit 7a4499640c
11 changed files with 76 additions and 99 deletions

View File

@@ -4,17 +4,6 @@
*/
package com.jeesite.modules.msg.service;
import java.util.Date;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.jeesite.common.callback.MethodCallback;
import com.jeesite.common.collect.ListUtils;
import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
@@ -27,17 +16,21 @@ import com.jeesite.modules.msg.dao.MsgInnerRecordDao;
import com.jeesite.modules.msg.entity.MsgInner;
import com.jeesite.modules.msg.entity.MsgInnerRecord;
import com.jeesite.modules.msg.entity.MsgPush;
import com.jeesite.modules.msg.entity.content.AppMsgContent;
import com.jeesite.modules.msg.entity.content.BaseMsgContent;
import com.jeesite.modules.msg.entity.content.EmailMsgContent;
import com.jeesite.modules.msg.entity.content.PcMsgContent;
import com.jeesite.modules.msg.entity.content.SmsMsgContent;
import com.jeesite.modules.msg.entity.content.*;
import com.jeesite.modules.msg.utils.MsgPushUtils;
import com.jeesite.modules.sys.entity.EmpUser;
import com.jeesite.modules.sys.entity.User;
import com.jeesite.modules.sys.service.EmpUserService;
import io.netty.util.concurrent.DefaultThreadFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
* 内部消息Service
@@ -68,8 +61,7 @@ public class MsgInnerService extends CrudService<MsgInnerDao, MsgInner> {
/**
* 查询分页数据
* @param msgInner 查询条件
* @param msgInner.page 分页对象
* @param msgInner 查询条件.page 分页对象
* @return
*/
@Override
@@ -191,12 +183,7 @@ public class MsgInnerService extends CrudService<MsgInnerDao, MsgInner> {
}
}
});
ListUtils.pageList(recordList, 100, new MethodCallback() {
@SuppressWarnings("unchecked")
public Object execute(Object... objs) {
return msgInnerRecordDao.insertBatch((List<MsgInnerRecord>)objs[0]);
}
});
msgInnerRecordDao.insertBatch(recordList, null);
// 手动触发消息推送任务
if (Global.TRUE.equals(Global.getProperty("msg.realtime.enabled"))){
msgPushThreadPool.submit(new Runnable() {

View File

@@ -4,12 +4,6 @@
*/
package com.jeesite.modules.sys.service.support;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.jeesite.common.collect.ListUtils;
import com.jeesite.common.service.TreeService;
import com.jeesite.modules.sys.dao.CompanyDao;
@@ -19,6 +13,11 @@ import com.jeesite.modules.sys.entity.CompanyOffice;
import com.jeesite.modules.sys.service.CompanyService;
import com.jeesite.modules.sys.service.DataScopeService;
import com.jeesite.modules.sys.utils.EmpUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* 公司管理Service
@@ -85,7 +84,7 @@ public class CompanyServiceSupport extends TreeService<CompanyDao, Company>
list.forEach(e -> {
e.setCompanyCode(company.getCompanyCode());
});
companyOfficeDao.insertBatch(list);
companyOfficeDao.insertBatch(list, null);
}
// 清理公司相关缓存
clearCompanyCache();

View File

@@ -4,16 +4,6 @@
*/
package com.jeesite.modules.sys.service.support;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.idgen.IdGen;
@@ -33,6 +23,14 @@ import com.jeesite.modules.sys.service.EmployeeService;
import com.jeesite.modules.sys.service.UserService;
import com.jeesite.modules.sys.utils.EmpUtils;
import com.jeesite.modules.sys.utils.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.PostConstruct;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import java.util.List;
/**
* 员工管理Service
@@ -164,7 +162,7 @@ public class EmpUserServiceSupport extends CrudService<EmpUserDao, EmpUser>
employeeOffice.setId(IdGen.nextId());
employeeOffice.setEmpCode(employee.getEmpCode());
});
employeeOfficeDao.insertBatch(employee.getEmployeeOfficeList());
employeeOfficeDao.insertBatch(employee.getEmployeeOfficeList(), null);
}
}

View File

@@ -4,11 +4,6 @@
*/
package com.jeesite.modules.sys.service.support;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.jeesite.common.collect.ListUtils;
import com.jeesite.common.entity.Page;
import com.jeesite.common.service.CrudService;
@@ -19,6 +14,10 @@ import com.jeesite.modules.sys.entity.Employee;
import com.jeesite.modules.sys.entity.EmployeeOffice;
import com.jeesite.modules.sys.entity.EmployeePost;
import com.jeesite.modules.sys.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* 员工管理Service
@@ -80,7 +79,7 @@ public class EmployeeServiceSupport extends CrudService<EmployeeDao, Employee>
for (EmployeePost e : employee.getEmployeePostList()){
e.setEmpCode(employee.getEmpCode());
}
employeePostDao.insertBatch(employee.getEmployeePostList());
employeePostDao.insertBatch(employee.getEmployeePostList(), null);
}
}

View File

@@ -537,6 +537,9 @@ mybatis:
# 是否开启 JDBC 管理事务,默认 Spring 管理事务 v4.2.3
jdbcTransaction: false
# 批量插入和更新的分批默认大小防止库一次性接受不了太大的sql语句
defaultBatchSize: 500
# Mapper文件刷新线程
mapper:

View File

@@ -25,13 +25,13 @@
<!-- 指定 MyBatis 如何自动映射 数据基表的列 NONE不映射 PARTIAL:部分 FULL:全部 -->
<setting name="autoMappingBehavior" value="PARTIAL"/>
<!-- 这是默认的执行类型 SIMPLE: 简单; REUSE: 执行器可能重复使用prepared statements语句BATCH: 执行器可以重复执行语句和批量更新) -->
<!-- 这是默认的执行类型SIMPLE: 简单REUSE: 执行器可能重复使用prepared statements语句BATCH: 执行器可以重复执行语句和批量更新) -->
<setting name="defaultExecutorType" value="SIMPLE"/>
<!-- 使用驼峰命名法转换字段。 -->
<setting name="mapUnderscoreToCamelCase" value="true"/>
<!-- 设置本地缓存范围 session:就会有数据的共享 statement:语句范围 (这样就不会有数据的共享 ) defalut:session -->
<!-- 设置本地缓存范围 session:就会有数据的共享 statement:语句范围 (这样就不会有数据的共享 ) defalut:session -->
<setting name="localCacheScope" value="SESSION"/>
<!-- 设置但JDBC类型为空时,某些驱动程序 要指定值,default:OTHER插入空值时不需要指定类型 -->