public Boolean extendDetailUser(SalaryAccountingItemParam param){
//获取上期已选人员关联的项目
List<SalaryAccountingItemDetailUser> extendDetailUserList = this.list(Wrappers.<SalaryAccountingItemDetailUser>lambdaQuery()
.eq(SalaryAccountingItemDetailUser::getSalaryAccountingId, param.getLastSalaryAccountingId())
.eq(SalaryAccountingItemDetailUser::getYearMonth, param.getLastYearMonth()));
if (extendDetailUserList.isEmpty()) {
return true; // 如果没有数据,则直接返回 true
}
//大于1000条分批保存
int batchStart = 0;
int batchEnd;
while ((batchEnd = Math.min(batchStart + 1000, extendDetailUserList.size())) > batchStart) {
List<SalaryAccountingItemDetailUser> batch = extendDetailUserList.subList(batchStart, batchEnd);
StringBuilder sqlBuilder = new StringBuilder("INSERT INTO salary_accounting_item_detail_user ( idCard, itemDetailId, yearMonth, salaryAccountingId, userName ) VALUES ");
for (SalaryAccountingItemDetailUser salaryAccountingItemDetailUser : batch){
sqlBuilder.append("('");
sqlBuilder.append(salaryAccountingItemDetailUser.getIdCard());
sqlBuilder.append("',");
sqlBuilder.append(salaryAccountingItemDetailUser.getItemDetailId());
sqlBuilder.append(",'");
sqlBuilder.append(param.getYearMonth());
sqlBuilder.append("',");
sqlBuilder.append(param.getId());
sqlBuilder.append(",'");
sqlBuilder.append(salaryAccountingItemDetailUser.getUserName());
sqlBuilder.append("'),");
}
// 移除最后一个逗号
sqlBuilder.setLength(sqlBuilder.length() - 1);
jdbcTemplate.batchUpdate(sqlBuilder.toString()); // 执行批量操作
batchStart = batchEnd;
}
return true;
}