refactor(mybatis-plus): 将 selectBatchIds 方法替换为 selectByIds

- 在多个模块中,将 baseMapper.selectBatchIds 替换为 baseMapper.selectByIds- 在多个模块中,将 removeByDsId 中的 deleteBatchIds 替换为 deleteByIds- 在多个模块中,将 list 方法中的 in 条件的参数从数组转换为列表
This commit is contained in:
曼陀罗 committed 2025-03-11 17:59:33 +08:00
1 parent 5b5aac37d0
commit a825de905a
20 files changed
+41 -32

No files matched your search

@@ -208,7 +208,7 @@ public class AppUserServiceImpl extends ServiceImpl<AppUserMapper, AppUser> impl
@Override
public Boolean deleteAppUserByIds(Long[] ids) {
Cache cache = cacheManager.getCache(CacheConstants.USER_DETAILS_MINI);
for (AppUser appUser : baseMapper.selectBatchIds(CollUtil.toList(ids))) {
for (AppUser appUser : baseMapper.selectByIds(CollUtil.toList(ids))) {
cache.evict(appUser.getUsername());
}
// 删除用户关联表
@@ -129,7 +129,7 @@ public class SysAreaController {
@HasPermission("sys_sysArea_export")
public List<SysAreaEntity> export(SysAreaEntity sysArea, Long[] ids) {
return sysAreaService
.list(Wrappers.lambdaQuery(sysArea).in(ArrayUtil.isNotEmpty(ids), SysAreaEntity::getId, ids));
.list(Wrappers.lambdaQuery(sysArea).in(ArrayUtil.isNotEmpty(ids), SysAreaEntity::getId, CollUtil.toList(ids)));
}
}
@@ -111,7 +111,6 @@ public class SysAuditLogController {
@HasPermission("sys_audit_export")
public List<SysAuditLog> export(SysAuditLog sysAuditLog, Long[] ids) {
return sysAuditLogService
.list(Wrappers.lambdaQuery(sysAuditLog).in(ArrayUtil.isNotEmpty(ids), SysAuditLog::getId, ids));
.list(Wrappers.lambdaQuery(sysAuditLog).in(ArrayUtil.isNotEmpty(ids), SysAuditLog::getId, CollUtil.toList(ids)));
}
}
@@ -142,7 +142,7 @@ public class SysI18nController {
@HasPermission("sys_i18n_export")
public List<SysI18nEntity> export(SysI18nEntity sysI18n, Long[] ids) {
return sysI18nService
.list(Wrappers.lambdaQuery(sysI18n).in(ArrayUtil.isNotEmpty(ids), SysI18nEntity::getId, ids));
.list(Wrappers.lambdaQuery(sysI18n).in(ArrayUtil.isNotEmpty(ids), SysI18nEntity::getId, CollUtil.toList(ids)));
}
/**
@@ -119,7 +119,7 @@ public class SysLogController {
@GetMapping("/export")
@HasPermission("sys_log_export")
public List<SysLog> export(SysLog sysLog, Long[] ids) {
return sysLogService.list(Wrappers.lambdaQuery(sysLog).in(Objects.nonNull(ids), SysLog::getId, ids));
return sysLogService.list(Wrappers.lambdaQuery(sysLog).in(Objects.nonNull(ids), SysLog::getId, CollUtil.toList(ids)));
}
}
@@ -126,7 +126,7 @@ public class SysMessageController {
@HasPermission("sys_message_export")
public List<SysMessageEntity> export(SysMessageEntity sysMessage, Long[] ids) {
return sysMessageService
.list(Wrappers.lambdaQuery(sysMessage).in(ArrayUtil.isNotEmpty(ids), SysMessageEntity::getId, ids));
.list(Wrappers.lambdaQuery(sysMessage).in(ArrayUtil.isNotEmpty(ids), SysMessageEntity::getId, CollUtil.toList(ids)));
}
/**
@@ -17,8 +17,19 @@
package com.pig4cloud.pigx.admin.controller;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import java.util.List;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -29,15 +40,14 @@ import com.pig4cloud.pigx.common.excel.annotation.ResponseExcel;
import com.pig4cloud.pigx.common.log.annotation.SysLog;
import com.pig4cloud.pigx.common.security.annotation.HasPermission;
import com.pig4cloud.pigx.common.security.annotation.Inner;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 公共参数
@@ -162,7 +172,7 @@ public class SysPublicParamController {
@HasPermission("sys_syspublicparam_edit")
public List<SysPublicParam> export(SysPublicParam param, Long[] ids) {
return sysPublicParamService
.list(Wrappers.lambdaQuery(param).in(ArrayUtil.isNotEmpty(ids), SysPublicParam::getPublicId, ids));
.list(Wrappers.lambdaQuery(param).in(ArrayUtil.isNotEmpty(ids), SysPublicParam::getPublicId, CollUtil.toList(ids)));
}
/**
@@ -154,7 +154,7 @@ public class SysSensitiveWordController {
@GetMapping("/export")
@HasPermission("admin_sysSensitiveWord_export")
public List<SysSensitiveWordEntity> export(SysSensitiveWordEntity sysSensitiveWord, Long[] ids) {
return sysSensitiveWordService.list(Wrappers.lambdaQuery(sysSensitiveWord).in(ArrayUtil.isNotEmpty(ids), SysSensitiveWordEntity::getSensitiveId, ids));
return sysSensitiveWordService.list(Wrappers.lambdaQuery(sysSensitiveWord).in(ArrayUtil.isNotEmpty(ids), SysSensitiveWordEntity::getSensitiveId, CollUtil.toList(ids)));
}
/**
@@ -156,7 +156,7 @@ public class SysSocialDetailsController {
@GetMapping("/export")
public List<SysSocialDetails> export(SysSocialDetails sysSocialDetails, Long[] ids) {
return sysSocialDetailsService
.list(Wrappers.lambdaQuery(sysSocialDetails).in(ArrayUtil.isNotEmpty(ids), SysSocialDetails::getId, ids));
.list(Wrappers.lambdaQuery(sysSocialDetails).in(ArrayUtil.isNotEmpty(ids), SysSocialDetails::getId, CollUtil.toList(ids)));
}
}
@@ -117,6 +117,6 @@ public class SysSystemConfigController {
@GetMapping("/export")
@HasPermission("sys_message_export")
public List<SysSystemConfigEntity> export(SysSystemConfigEntity sysSystemConfig, Long[] ids) {
return sysSystemConfigService.list(Wrappers.lambdaQuery(sysSystemConfig).in(ArrayUtil.isNotEmpty(ids), SysSystemConfigEntity::getId, ids));
return sysSystemConfigService.list(Wrappers.lambdaQuery(sysSystemConfig).in(ArrayUtil.isNotEmpty(ids), SysSystemConfigEntity::getId, CollUtil.toList(ids)));
}
}
@@ -160,7 +160,7 @@ public class SysTenantController {
@HasPermission("sys_systenant_export")
public List<SysTenant> export(SysTenant sysTenant, Long[] ids) {
return sysTenantService
.list(Wrappers.lambdaQuery(sysTenant).in(ArrayUtil.isNotEmpty(ids), SysTenant::getId, ids));
.list(Wrappers.lambdaQuery(sysTenant).in(ArrayUtil.isNotEmpty(ids), SysTenant::getId, CollUtil.toList(ids)));
}
@GetMapping(value = "/tree/menu")
@@ -59,13 +59,13 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> impl
@CacheEvict(value = CacheConstants.DICT_DETAILS, allEntries = true)
public R removeDictByIds(Long[] ids) {
List<Long> dictIdList = baseMapper.selectBatchIds(CollUtil.toList(ids))
List<Long> dictIdList = baseMapper.selectByIds(CollUtil.toList(ids))
.stream()
.filter(sysDict -> !sysDict.getSystemFlag().equals(DictTypeEnum.SYSTEM.getType()))// 系统内置类型不删除
.map(SysDict::getId)
.collect(Collectors.toList());
baseMapper.deleteBatchIds(dictIdList);
baseMapper.deleteByIds(dictIdList);
dictItemMapper.delete(Wrappers.<SysDictItem>lambdaQuery().in(SysDictItem::getDictId, dictIdList));
return R.ok();
@@ -209,7 +209,7 @@ public class SysFileServiceImpl extends ServiceImpl<SysFileMapper, SysFile> impl
file.setGroupId(fileGroupDTO.getGroupId());
// 根据IDS更新对应的SysFile记录
baseMapper.update(file, Wrappers.<SysFile>lambdaQuery().in(SysFile::getId, fileGroupDTO.getIds()));
baseMapper.update(file, Wrappers.<SysFile>lambdaQuery().in(SysFile::getId, CollUtil.toList(fileGroupDTO.getIds())));
return Boolean.TRUE;
}
@@ -217,7 +217,7 @@ public class SysMessageServiceImpl extends ServiceImpl<SysMessageMapper, SysMess
List<Long> userIdList = relationMapper.selectList(Wrappers.<SysMessageRelationEntity>lambdaQuery().eq(SysMessageRelationEntity::getMsgId, id)).stream().map(SysMessageRelationEntity::getUserId).collect(Collectors.toList());
if (CollUtil.isNotEmpty(userIdList)) {
List<OrgTreeVO> orgNodeUserVoList = userMapper.selectBatchIds(userIdList).stream().map(user -> {
List<OrgTreeVO> orgNodeUserVoList = userMapper.selectByIds(userIdList).stream().map(user -> {
OrgTreeVO nodeUserVo = new OrgTreeVO();
nodeUserVo.setId(user.getUserId());
nodeUserVo.setAvatar(user.getAvatar());
@@ -95,7 +95,7 @@ public class SysPostServiceImpl extends ServiceImpl<SysPostMapper, SysPost> impl
@Override
public List<PostExcelVO> listPost(SysPost query, Long[] ids) {
List<SysPost> postList = this
.list(Wrappers.lambdaQuery(query).in(ArrayUtil.isNotEmpty(ids), SysPost::getPostId, ids));
.list(Wrappers.lambdaQuery(query).in(ArrayUtil.isNotEmpty(ids), SysPost::getPostId, CollUtil.toList(ids)));
// 转换成execl 对象输出
return postList.stream().map(post -> {
PostExcelVO postExcelVO = new PostExcelVO();
@@ -69,7 +69,7 @@ public class SysPublicParamServiceImpl extends ServiceImpl<SysPublicParamMapper,
@Override
public Map<String, Object> getSysPublicParamsKeyToValue(String[] keys) {
List<SysPublicParam> paramList = this.baseMapper
.selectList(Wrappers.<SysPublicParam>lambdaQuery().in(SysPublicParam::getPublicKey, keys));
.selectList(Wrappers.<SysPublicParam>lambdaQuery().in(SysPublicParam::getPublicKey, CollUtil.toList(keys)));
Map<String, Object> result = new HashMap<>(8);
paramList.forEach(param -> result.put(param.getPublicKey(), param.getPublicValue()));
return result;
@@ -99,7 +99,7 @@ public class SysPublicParamServiceImpl extends ServiceImpl<SysPublicParamMapper,
@Override
@CacheEvict(value = CacheConstants.PARAMS_DETAILS, allEntries = true)
public R removeParamByIds(Long[] publicIds) {
List<Long> idList = this.baseMapper.selectBatchIds(CollUtil.toList(publicIds))
List<Long> idList = this.baseMapper.selectByIds(CollUtil.toList(publicIds))
.stream()
.filter(p -> !p.getSystemFlag().equals(DictTypeEnum.SYSTEM.getType()))// 系统内置的跳过不能删除
.map(SysPublicParam::getPublicId)
@@ -80,7 +80,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
@Override
@Cacheable(value = CacheConstants.ROLE_DETAILS, key = "#key", unless = "#result.isEmpty()")
public List<SysRole> findRolesByRoleIds(List<Long> roleIdList, String key) {
return baseMapper.selectBatchIds(roleIdList);
return baseMapper.selectByIds(roleIdList);
}
/**
@@ -155,7 +155,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
@Override
public List<RoleExcelVO> listRole(SysRole sysRole, Long[] ids) {
List<SysRole> roleList = this
.list(Wrappers.lambdaQuery(sysRole).in(ArrayUtil.isNotEmpty(ids), SysRole::getRoleId, ids));
.list(Wrappers.lambdaQuery(sysRole).in(ArrayUtil.isNotEmpty(ids), SysRole::getRoleId, CollUtil.toList(ids)));
// 转换成execl 对象输出
return roleList.stream().map(role -> {
RoleExcelVO roleExcelVO = new RoleExcelVO();
@@ -204,7 +204,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
@Transactional(rollbackFor = Exception.class)
public Boolean deleteUserByIds(Long[] ids) {
// 删除 spring cache
List<SysUser> userList = baseMapper.selectBatchIds(CollUtil.toList(ids));
List<SysUser> userList = baseMapper.selectByIds(CollUtil.toList(ids));
Cache cache = cacheManager.getCache(CacheConstants.USER_DETAILS);
for (SysUser sysUser : userList) {
cache.evict(sysUser.getUsername());
@@ -109,9 +109,9 @@ public class GenDatasourceConfServiceImpl extends ServiceImpl<GenDatasourceConfM
@Override
public Boolean removeByDsId(Long[] dsIds) {
DynamicRoutingDataSource dynamicRoutingDataSource = SpringContextHolder.getBean(DynamicRoutingDataSource.class);
this.baseMapper.selectBatchIds(CollUtil.toList(dsIds))
this.baseMapper.selectByIds(CollUtil.toList(dsIds))
.forEach(ds -> dynamicRoutingDataSource.removeDataSource(ds.getName()));
this.baseMapper.deleteBatchIds(CollUtil.toList(dsIds));
this.baseMapper.deleteByIds(CollUtil.toList(dsIds));
return Boolean.TRUE;
}
@@ -78,7 +78,7 @@ public class GenGroupServiceImpl extends ServiceImpl<GenGroupMapper, GenGroupEnt
this.removeBatchByIds(CollUtil.toList(ids));
// 删除关系
genTemplateGroupService
.remove(Wrappers.<GenTemplateGroupEntity>lambdaQuery().in(GenTemplateGroupEntity::getGroupId, ids));
.remove(Wrappers.<GenTemplateGroupEntity>lambdaQuery().in(GenTemplateGroupEntity::getGroupId, CollUtil.toList(ids)));
}
/**