comtroller层开启线程:
new Thread(() -> oracleQueryService.findOfficeList(oracleListRequestModel)).start();
service执行查询和插入操作
public ResultModel findOfficeList(OracleListRequestModel oracleListRequestModel) {
ResultModel resultModel = new ResultModel();
try {
int subSize = migrationConfig.getSubsize();// 引配置文件 临时10个测试
resultModel.setSuccess(true);
List<OfficeCustomerEntity> officeList = oracleQueryRepository.findOfficeList(oracleListRequestModel);
int size = officeList.size();
logger.info("本次官网帐号迁移数量:" + size + " 起始时间:" + oracleListRequestModel.getStartDate() + " 截止时间:" + oracleListRequestModel.getEndDate());
int length;
if (size % subSize == 0) {
length = size / subSize;
} else {
length = size / subSize + 1;
}
int start = 0;
int end = 0;
for (int i = 0; i < length; i++) {
List<OfficeCustomerEntity> newOfficeList;
if (i * subSize + subSize <= size) {
newOfficeList = officeList.subList(i * subSize, i * subSize + subSize);
start = i * subSize;
end = i * subSize + subSize;
} else {
newOfficeList = officeList.subList(i * subSize, size);
start = i * subSize;
end = size;
}
migExecutorPool.officeMigBatch(newOfficeList, start, end, oracleListRequestModel.getStartDate(), oracleListRequestModel.getEndDate());
}
} catch (Exception e) {
logger.error("迁移出错:" + e.getMessage(), e);
resultModel.setMessage("迁移出错:" + e + " " + e.getMessage());
return resultModel;
}