int 数组的值总和可能大于 int 的最大值,使用 long 类型的变量存储其结果。

pull/1/head
ZhouXY108 2023-03-17 18:42:43 +08:00
parent cc3c4be8de
commit 78cdded667
5 changed files with 8 additions and 8 deletions

View File

@ -86,18 +86,18 @@ public abstract class PlusoneJdbcDaoSupport {
return update(sql, new MapSqlParameterSource(paramName, value)); return update(sql, new MapSqlParameterSource(paramName, value));
} }
protected final int batchUpdate(String sql, SqlParameterSource[] batchArgs) { protected final long batchUpdate(String sql, SqlParameterSource[] batchArgs) {
int[] i = this.jdbc.batchUpdate(sql, batchArgs); int[] i = this.jdbc.batchUpdate(sql, batchArgs);
return NumberUtil.sum(i); return NumberUtil.sum(i);
} }
protected final <T> int batchUpdate(String sql, Stream<T> c, protected final <T> long batchUpdate(String sql, Stream<T> c,
@Nonnull Function<T, SqlParameterSource> paramSourceBuilder) { @Nonnull Function<T, SqlParameterSource> paramSourceBuilder) {
int[] i = this.jdbc.batchUpdate(sql, buildSqlParameterSourceArray(c, paramSourceBuilder)); int[] i = this.jdbc.batchUpdate(sql, buildSqlParameterSourceArray(c, paramSourceBuilder));
return NumberUtil.sum(i); return NumberUtil.sum(i);
} }
protected final <T> int batchUpdate(String sql, Collection<T> c, protected final <T> long batchUpdate(String sql, Collection<T> c,
@Nonnull Function<T, SqlParameterSource> paramSourceBuilder) { @Nonnull Function<T, SqlParameterSource> paramSourceBuilder) {
int[] i = this.jdbc.batchUpdate(sql, buildSqlParameterSourceArray(c, paramSourceBuilder)); int[] i = this.jdbc.batchUpdate(sql, buildSqlParameterSourceArray(c, paramSourceBuilder));
return NumberUtil.sum(i); return NumberUtil.sum(i);

View File

@ -31,7 +31,7 @@ class AccountRoleRefDAO extends PlusoneJdbcDaoSupport {
} }
void insertAccountRoleRefs(Long accountId, Set<Long> roleRefs) { void insertAccountRoleRefs(Long accountId, Set<Long> roleRefs) {
int i = batchUpdate( long i = batchUpdate(
"INSERT INTO sys_account_role (account_id, role_id) VALUES (:accountId, :roleId)", "INSERT INTO sys_account_role (account_id, role_id) VALUES (:accountId, :roleId)",
roleRefs, roleRefs,
(Long roleId) -> new MapSqlParameterSource() (Long roleId) -> new MapSqlParameterSource()

View File

@ -21,11 +21,11 @@ class DictValueDAO extends PlusoneJdbcDaoSupport {
void updateDictValues(Dict entity) { void updateDictValues(Dict entity) {
update("DELETE FROM sys_dict_value WHERE dict_type = :dictType", update("DELETE FROM sys_dict_value WHERE dict_type = :dictType",
"dictType", entity.getId().orElseThrow()); "dictType", entity.getId().orElseThrow());
int i = insertDictValues(entity.getId().orElseThrow(), entity); long i = insertDictValues(entity.getId().orElseThrow(), entity);
assertResultEquals(i, entity.count()); assertResultEquals(i, entity.count());
} }
int insertDictValues(Long dictId, Dict entity) { long insertDictValues(Long dictId, Dict entity) {
if (Objects.isNull(dictId) || Objects.isNull(entity) || CollectionUtils.isEmpty(entity.getValues())) { if (Objects.isNull(dictId) || Objects.isNull(entity) || CollectionUtils.isEmpty(entity.getValues())) {
return 0; return 0;
} }

View File

@ -29,7 +29,7 @@ class RoleMenuRefDAO extends PlusoneJdbcDaoSupport {
} }
void saveRoleMenuRefs(Long roleId, Role entity) { void saveRoleMenuRefs(Long roleId, Role entity) {
int i = batchUpdate( long i = batchUpdate(
"INSERT INTO sys_role_menu(role_id, menu_id) VALUES (:roleId, :menuId)", "INSERT INTO sys_role_menu(role_id, menu_id) VALUES (:roleId, :menuId)",
entity.getMenus(), entity.getMenus(),
menuRef -> new MapSqlParameterSource() menuRef -> new MapSqlParameterSource()

View File

@ -30,7 +30,7 @@ class RolePermissionRefDAO extends PlusoneJdbcDaoSupport {
} }
void saveRolePermissionRefs(Long roleId, Role entity) { void saveRolePermissionRefs(Long roleId, Role entity) {
int i = batchUpdate( long i = batchUpdate(
"INSERT INTO sys_role_permission(role_id, permission_id) VALUES (:roleId, :permissionId)", "INSERT INTO sys_role_permission(role_id, permission_id) VALUES (:roleId, :permissionId)",
entity.getPermissions(), entity.getPermissions(),
actionRef -> new MapSqlParameterSource() actionRef -> new MapSqlParameterSource()