refactor: 使用 CollUtils 替代部分 Stream 操作,提高代码的可读性,减少代码行数(缺点:方法写起来不如流式代码舒爽)

This commit is contained in:
2025-07-17 23:05:59 +08:00
parent 08f45b5f4d
commit 33d89431cf
25 changed files with 79 additions and 69 deletions

View File

@@ -33,6 +33,7 @@ import org.springframework.util.AntPathMatcher;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import top.continew.starter.apidoc.autoconfigure.SpringDocExtensionProperties; import top.continew.starter.apidoc.autoconfigure.SpringDocExtensionProperties;
import top.continew.starter.auth.satoken.autoconfigure.SaTokenExtensionProperties; import top.continew.starter.auth.satoken.autoconfigure.SaTokenExtensionProperties;
import top.continew.starter.core.util.CollUtils;
import top.continew.starter.extension.crud.annotation.CrudRequestMapping; import top.continew.starter.extension.crud.annotation.CrudRequestMapping;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@@ -103,7 +104,7 @@ public class GlobalAuthenticationCustomizer implements GlobalOpenApiCustomizer {
return; return;
} }
Map<String, SecurityScheme> securitySchemes = components.getSecuritySchemes(); Map<String, SecurityScheme> securitySchemes = components.getSecuritySchemes();
List<String> schemeNames = securitySchemes.values().stream().map(SecurityScheme::getName).toList(); List<String> schemeNames = CollUtils.mapToList(securitySchemes.values(), SecurityScheme::getName);
pathItem.readOperations().forEach(operation -> { pathItem.readOperations().forEach(operation -> {
SecurityRequirement securityRequirement = new SecurityRequirement(); SecurityRequirement securityRequirement = new SecurityRequirement();
schemeNames.forEach(securityRequirement::addList); schemeNames.forEach(securityRequirement::addList);

View File

@@ -19,13 +19,12 @@ package top.continew.admin.common.config.mybatis;
import cn.hutool.core.convert.Convert; import cn.hutool.core.convert.Convert;
import top.continew.admin.common.context.UserContext; import top.continew.admin.common.context.UserContext;
import top.continew.admin.common.context.UserContextHolder; import top.continew.admin.common.context.UserContextHolder;
import top.continew.starter.core.util.CollUtils;
import top.continew.starter.extension.datapermission.enums.DataScope; import top.continew.starter.extension.datapermission.enums.DataScope;
import top.continew.starter.extension.datapermission.filter.DataPermissionUserDataProvider; import top.continew.starter.extension.datapermission.filter.DataPermissionUserDataProvider;
import top.continew.starter.extension.datapermission.model.RoleData; import top.continew.starter.extension.datapermission.model.RoleData;
import top.continew.starter.extension.datapermission.model.UserData; import top.continew.starter.extension.datapermission.model.UserData;
import java.util.stream.Collectors;
/** /**
* 数据权限用户数据提供者 * 数据权限用户数据提供者
* *
@@ -45,10 +44,8 @@ public class DefaultDataPermissionUserDataProvider implements DataPermissionUser
UserData userData = new UserData(); UserData userData = new UserData();
userData.setUserId(Convert.toStr(userContext.getId())); userData.setUserId(Convert.toStr(userContext.getId()));
userData.setDeptId(Convert.toStr(userContext.getDeptId())); userData.setDeptId(Convert.toStr(userContext.getDeptId()));
userData.setRoles(userContext.getRoles() userData.setRoles(CollUtils.mapToSet(userContext.getRoles(), r -> new RoleData(Convert.toStr(r
.stream() .getId()), DataScope.valueOf(r.getDataScope().name()))));
.map(r -> new RoleData(Convert.toStr(r.getId()), DataScope.valueOf(r.getDataScope().name())))
.collect(Collectors.toSet()));
return userData; return userData;
} }
} }

View File

@@ -20,12 +20,12 @@ import cn.hutool.core.collection.CollUtil;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import top.continew.admin.common.constant.SysConstants; import top.continew.admin.common.constant.SysConstants;
import top.continew.starter.core.util.CollUtils;
import java.io.Serial; import java.io.Serial;
import java.io.Serializable; import java.io.Serializable;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors;
/** /**
* 用户上下文 * 用户上下文
@@ -103,7 +103,7 @@ public class UserContext implements Serializable {
public void setRoles(Set<RoleContext> roles) { public void setRoles(Set<RoleContext> roles) {
this.roles = roles; this.roles = roles;
this.roleCodes = roles.stream().map(RoleContext::getCode).collect(Collectors.toSet()); this.roleCodes = CollUtils.mapToSet(roles, RoleContext::getCode);
} }
/** /**

View File

@@ -22,13 +22,13 @@ import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.extra.spring.SpringUtil; import cn.hutool.extra.spring.SpringUtil;
import top.continew.admin.common.config.RsaProperties; import top.continew.admin.common.config.RsaProperties;
import top.continew.starter.core.exception.BusinessException; import top.continew.starter.core.exception.BusinessException;
import top.continew.starter.core.util.CollUtils;
import top.continew.starter.core.util.validation.ValidationUtils; import top.continew.starter.core.util.validation.ValidationUtils;
import top.continew.starter.security.crypto.autoconfigure.CryptoProperties; import top.continew.starter.security.crypto.autoconfigure.CryptoProperties;
import top.continew.starter.security.crypto.encryptor.AesEncryptor; import top.continew.starter.security.crypto.encryptor.AesEncryptor;
import top.continew.starter.security.crypto.encryptor.IEncryptor; import top.continew.starter.security.crypto.encryptor.IEncryptor;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* 加密/解密工具类 * 加密/解密工具类
@@ -96,12 +96,12 @@ public class SecureUtils {
public static List<String> encryptFieldByAes(List<String> values) { public static List<String> encryptFieldByAes(List<String> values) {
IEncryptor encryptor = new AesEncryptor(); IEncryptor encryptor = new AesEncryptor();
CryptoProperties properties = SpringUtil.getBean(CryptoProperties.class); CryptoProperties properties = SpringUtil.getBean(CryptoProperties.class);
return values.stream().map(value -> { return CollUtils.mapToList(values, value -> {
try { try {
return encryptor.encrypt(value, properties.getPassword(), properties.getPublicKey()); return encryptor.encrypt(value, properties.getPassword(), properties.getPublicKey());
} catch (Exception e) { } catch (Exception e) {
throw new BusinessException("字段加密异常"); throw new BusinessException("字段加密异常");
} }
}).collect(Collectors.toList()); });
} }
} }

View File

@@ -57,6 +57,7 @@ import top.continew.starter.core.autoconfigure.application.ApplicationProperties
import top.continew.starter.core.constant.StringConstants; import top.continew.starter.core.constant.StringConstants;
import top.continew.starter.core.enums.BaseEnum; import top.continew.starter.core.enums.BaseEnum;
import top.continew.starter.core.exception.BusinessException; import top.continew.starter.core.exception.BusinessException;
import top.continew.starter.core.util.CollUtils;
import top.continew.starter.core.util.validation.CheckUtils; import top.continew.starter.core.util.validation.CheckUtils;
import top.continew.starter.data.enums.DatabaseType; import top.continew.starter.data.enums.DatabaseType;
import top.continew.starter.data.util.MetaUtils; import top.continew.starter.data.util.MetaUtils;
@@ -296,9 +297,8 @@ public class GeneratorServiceImpl implements GeneratorService {
InnerGenConfigDO innerGenConfig = new InnerGenConfigDO(genConfig); InnerGenConfigDO innerGenConfig = new InnerGenConfigDO(genConfig);
List<String> imports = new ArrayList<>(); List<String> imports = new ArrayList<>();
// 处理枚举字段 // 处理枚举字段
List<FieldConfigDO> fieldConfigRecords = fieldConfigList.stream() List<FieldConfigDO> fieldConfigRecords = CollUtils
.map(s -> convertToFieldConfigDO(s, imports)) .mapToList(fieldConfigList, s -> convertToFieldConfigDO(s, imports));
.toList();
innerGenConfig.setImports(imports); innerGenConfig.setImports(imports);
// 渲染代码 // 渲染代码

View File

@@ -35,6 +35,7 @@ import top.continew.admin.system.mapper.user.UserMapper;
import top.continew.admin.system.mapper.user.UserPasswordHistoryMapper; import top.continew.admin.system.mapper.user.UserPasswordHistoryMapper;
import top.continew.admin.system.mapper.user.UserSocialMapper; import top.continew.admin.system.mapper.user.UserSocialMapper;
import top.continew.admin.system.model.entity.DeptDO; import top.continew.admin.system.model.entity.DeptDO;
import top.continew.admin.system.model.entity.FileDO;
import top.continew.admin.system.model.entity.MenuDO; import top.continew.admin.system.model.entity.MenuDO;
import top.continew.admin.system.model.entity.RoleDO; import top.continew.admin.system.model.entity.RoleDO;
import top.continew.admin.system.model.entity.user.UserDO; import top.continew.admin.system.model.entity.user.UserDO;
@@ -47,6 +48,7 @@ import top.continew.admin.tenant.model.entity.TenantDO;
import top.continew.admin.tenant.model.req.TenantReq; import top.continew.admin.tenant.model.req.TenantReq;
import top.continew.admin.tenant.service.PackageMenuService; import top.continew.admin.tenant.service.PackageMenuService;
import top.continew.starter.cache.redisson.util.RedisUtils; import top.continew.starter.cache.redisson.util.RedisUtils;
import top.continew.starter.core.util.CollUtils;
import top.continew.starter.core.util.ExceptionUtils; import top.continew.starter.core.util.ExceptionUtils;
import top.continew.starter.core.util.validation.ValidationUtils; import top.continew.starter.core.util.validation.ValidationUtils;
import top.continew.starter.extension.crud.model.entity.BaseIdDO; import top.continew.starter.extension.crud.model.entity.BaseIdDO;
@@ -121,7 +123,7 @@ public class TenantDataHandlerForSystem implements TenantDataHandler {
// 部门清除 // 部门清除
deptMapper.delete(dw); deptMapper.delete(dw);
// 文件清除 // 文件清除
List<Long> fileIds = fileService.list().stream().map(BaseIdDO::getId).toList(); List<Long> fileIds = CollUtils.mapToList(fileService.list(), FileDO::getId);
if (!fileIds.isEmpty()) { if (!fileIds.isEmpty()) {
fileService.delete(fileIds); fileService.delete(fileIds);
} }

View File

@@ -23,6 +23,7 @@ import org.springframework.transaction.annotation.Transactional;
import top.continew.admin.tenant.mapper.PackageMenuMapper; import top.continew.admin.tenant.mapper.PackageMenuMapper;
import top.continew.admin.tenant.model.entity.PackageMenuDO; import top.continew.admin.tenant.model.entity.PackageMenuDO;
import top.continew.admin.tenant.service.PackageMenuService; import top.continew.admin.tenant.service.PackageMenuService;
import top.continew.starter.core.util.CollUtils;
import java.util.List; import java.util.List;
@@ -55,7 +56,7 @@ public class PackageMenuServiceImpl implements PackageMenuService {
// 删除原有关联 // 删除原有关联
baseMapper.lambdaUpdate().eq(PackageMenuDO::getPackageId, packageId).remove(); baseMapper.lambdaUpdate().eq(PackageMenuDO::getPackageId, packageId).remove();
// 保存最新关联 // 保存最新关联
List<PackageMenuDO> newList = menuIds.stream().map(menuId -> new PackageMenuDO(packageId, menuId)).toList(); List<PackageMenuDO> newList = CollUtils.mapToList(menuIds, menuId -> new PackageMenuDO(packageId, menuId));
return baseMapper.insertBatch(newList); return baseMapper.insertBatch(newList);
} }

View File

@@ -33,6 +33,7 @@ import top.continew.admin.system.mapper.NoticeMapper;
import top.continew.admin.system.model.entity.NoticeDO; import top.continew.admin.system.model.entity.NoticeDO;
import top.continew.admin.system.service.NoticeService; import top.continew.admin.system.service.NoticeService;
import top.continew.starter.core.constant.PropertiesConstants; import top.continew.starter.core.constant.PropertiesConstants;
import top.continew.starter.core.util.CollUtils;
import top.continew.starter.extension.tenant.annotation.TenantIgnore; import top.continew.starter.extension.tenant.annotation.TenantIgnore;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@@ -109,7 +110,7 @@ public class NoticePublishJob {
// 更新状态 // 更新状态
noticeMapper.lambdaUpdate() noticeMapper.lambdaUpdate()
.set(NoticeDO::getStatus, NoticeStatusEnum.PUBLISHED) .set(NoticeDO::getStatus, NoticeStatusEnum.PUBLISHED)
.in(NoticeDO::getId, list.stream().map(NoticeDO::getId).toList()) .in(NoticeDO::getId, CollUtils.mapToList(list, NoticeDO::getId))
.update(); .update();
} }
} }

View File

@@ -34,6 +34,10 @@ public class AuthConfiguration {
*/ */
@Bean @Bean
public GroupedOpenApi authApi() { public GroupedOpenApi authApi() {
return GroupedOpenApi.builder().group("auth").displayName("系统认证").pathsToMatch("/auth/**", "/monitor/online/**").build(); return GroupedOpenApi.builder()
.group("auth")
.displayName("系统认证")
.pathsToMatch("/auth/**", "/monitor/online/**")
.build();
} }
} }

View File

@@ -32,6 +32,7 @@ import top.continew.admin.system.mapper.StorageMapper;
import top.continew.admin.system.model.entity.FileDO; import top.continew.admin.system.model.entity.FileDO;
import top.continew.admin.system.model.entity.StorageDO; import top.continew.admin.system.model.entity.StorageDO;
import top.continew.starter.core.constant.StringConstants; import top.continew.starter.core.constant.StringConstants;
import top.continew.starter.core.util.CollUtils;
import top.continew.starter.core.util.URLUtils; import top.continew.starter.core.util.URLUtils;
import java.util.List; import java.util.List;
@@ -128,7 +129,7 @@ public class FileRecorderImpl implements FileRecorder {
return list.get(0); return list.get(0);
} }
// 结合存储配置进行匹配 // 结合存储配置进行匹配
List<StorageDO> storageList = storageMapper.selectByIds(list.stream().map(FileDO::getStorageId).toList()); List<StorageDO> storageList = storageMapper.selectByIds(CollUtils.mapToList(list, FileDO::getStorageId));
Map<Long, StorageDO> storageMap = storageList.stream() Map<Long, StorageDO> storageMap = storageList.stream()
.collect(Collectors.toMap(StorageDO::getId, storage -> storage)); .collect(Collectors.toMap(StorageDO::getId, storage -> storage));
return list.stream().filter(file -> { return list.stream().filter(file -> {

View File

@@ -27,6 +27,7 @@ import top.continew.admin.common.enums.DisEnableStatusEnum;
import top.continew.admin.system.model.query.SmsConfigQuery; import top.continew.admin.system.model.query.SmsConfigQuery;
import top.continew.admin.system.model.resp.SmsConfigResp; import top.continew.admin.system.model.resp.SmsConfigResp;
import top.continew.admin.system.service.SmsConfigService; import top.continew.admin.system.service.SmsConfigService;
import top.continew.starter.core.util.CollUtils;
import java.util.List; import java.util.List;
@@ -61,6 +62,6 @@ public class SmsReadConfigDatabaseImpl implements SmsReadConfig {
if (CollUtil.isEmpty(list)) { if (CollUtil.isEmpty(list)) {
return List.of(); return List.of();
} }
return list.stream().map(SmsConfigUtil::from).toList(); return CollUtils.mapToList(list, SmsConfigUtil::from);
} }
} }

View File

@@ -48,6 +48,7 @@ import top.continew.admin.system.service.UserService;
import top.continew.admin.system.service.UserSocialService; import top.continew.admin.system.service.UserSocialService;
import top.continew.starter.cache.redisson.util.RedisUtils; import top.continew.starter.cache.redisson.util.RedisUtils;
import top.continew.starter.core.exception.BadRequestException; import top.continew.starter.core.exception.BadRequestException;
import top.continew.starter.core.util.CollUtils;
import top.continew.starter.core.util.ExceptionUtils; import top.continew.starter.core.util.ExceptionUtils;
import top.continew.starter.core.util.validation.ValidationUtils; import top.continew.starter.core.util.validation.ValidationUtils;
@@ -131,13 +132,13 @@ public class UserProfileController {
@GetMapping("/social") @GetMapping("/social")
public List<UserSocialBindResp> listSocialBind() { public List<UserSocialBindResp> listSocialBind() {
List<UserSocialDO> userSocialList = userSocialService.listByUserId(UserContextHolder.getUserId()); List<UserSocialDO> userSocialList = userSocialService.listByUserId(UserContextHolder.getUserId());
return userSocialList.stream().map(userSocial -> { return CollUtils.mapToList(userSocialList, userSocial -> {
String source = userSocial.getSource(); String source = userSocial.getSource();
UserSocialBindResp userSocialBind = new UserSocialBindResp(); UserSocialBindResp userSocialBind = new UserSocialBindResp();
userSocialBind.setSource(source); userSocialBind.setSource(source);
userSocialBind.setDescription(SocialSourceEnum.valueOf(source).getDescription()); userSocialBind.setDescription(SocialSourceEnum.valueOf(source).getDescription());
return userSocialBind; return userSocialBind;
}).toList(); });
} }
@Operation(summary = "绑定三方账号", description = "绑定三方账号") @Operation(summary = "绑定三方账号", description = "绑定三方账号")

View File

@@ -37,6 +37,7 @@ import top.continew.admin.system.model.resp.dashboard.DashboardOverviewCommonRes
import top.continew.admin.system.service.DashboardService; import top.continew.admin.system.service.DashboardService;
import top.continew.admin.system.service.NoticeService; import top.continew.admin.system.service.NoticeService;
import top.continew.starter.core.constant.StringConstants; import top.continew.starter.core.constant.StringConstants;
import top.continew.starter.core.util.CollUtils;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
@@ -95,10 +96,10 @@ public class DashboardServiceImpl implements DashboardService {
// 获取省份数据 // 获取省份数据
String chinaJson = IoUtil.readUtf8(new ClassPathResource("china.json").getInputStream()); String chinaJson = IoUtil.readUtf8(new ClassPathResource("china.json").getInputStream());
JSONArray jsonArr = JSONUtil.parseObj(chinaJson).getJSONArray("children"); JSONArray jsonArr = JSONUtil.parseObj(chinaJson).getJSONArray("children");
List<String> provinceList = jsonArr.stream().map(item -> { List<String> provinceList = CollUtils.mapToList(jsonArr, item -> {
JSONObject itemJsonObj = JSONUtil.parseObj(item); JSONObject itemJsonObj = JSONUtil.parseObj(item);
return "%s:%s".formatted(itemJsonObj.getStr("name"), itemJsonObj.getStr("fullname")); return "%s:%s".formatted(itemJsonObj.getStr("name"), itemJsonObj.getStr("fullname"));
}).toList(); });
// 汇总各省份访问数据 // 汇总各省份访问数据
for (String province : provinceList) { for (String province : provinceList) {
String[] split = province.split(StringConstants.COLON); String[] split = province.split(StringConstants.COLON);
@@ -124,10 +125,9 @@ public class DashboardServiceImpl implements DashboardService {
.stream() .stream()
.map(date -> date.toString(DatePattern.NORM_DATE_FORMAT)) .map(date -> date.toString(DatePattern.NORM_DATE_FORMAT))
.toList(); .toList();
Collection<String> missings = CollUtil.disjunction(all, list.stream() Collection<String> missings = CollUtil.disjunction(all, CollUtils
.map(DashboardAccessTrendResp::getDate) .mapToList(list, DashboardAccessTrendResp::getDate));
.toList()); list.addAll(CollUtils.mapToList(missings, missing -> new DashboardAccessTrendResp(missing, 0L, 0L)));
list.addAll(missings.stream().map(missing -> new DashboardAccessTrendResp(missing, 0L, 0L)).toList());
list.sort(Comparator.comparing(DashboardAccessTrendResp::getDate)); list.sort(Comparator.comparing(DashboardAccessTrendResp::getDate));
} }
return list; return list;
@@ -200,10 +200,9 @@ public class DashboardServiceImpl implements DashboardService {
* @param list 待填充数据 * @param list 待填充数据
*/ */
private void fillMissingDateData(List<String> all, List<DashboardChartCommonResp> list) { private void fillMissingDateData(List<String> all, List<DashboardChartCommonResp> list) {
Collection<String> missings = CollUtil.disjunction(all, list.stream() Collection<String> missings = CollUtil.disjunction(all, CollUtils
.map(DashboardChartCommonResp::getName) .mapToList(list, DashboardChartCommonResp::getName));
.toList()); list.addAll(CollUtils.mapToList(missings, missing -> new DashboardChartCommonResp(missing, 0L)));
list.addAll(missings.stream().map(missing -> new DashboardChartCommonResp(missing, 0L)).toList());
list.sort(Comparator.comparing(DashboardChartCommonResp::getName)); list.sort(Comparator.comparing(DashboardChartCommonResp::getName));
} }

View File

@@ -26,6 +26,7 @@ import top.continew.admin.system.model.req.DictReq;
import top.continew.admin.system.model.resp.DictResp; import top.continew.admin.system.model.resp.DictResp;
import top.continew.admin.system.service.DictItemService; import top.continew.admin.system.service.DictItemService;
import top.continew.admin.system.service.DictService; import top.continew.admin.system.service.DictService;
import top.continew.starter.core.util.CollUtils;
import top.continew.starter.core.util.validation.CheckUtils; import top.continew.starter.core.util.validation.CheckUtils;
import top.continew.starter.extension.crud.model.resp.LabelValueResp; import top.continew.starter.extension.crud.model.resp.LabelValueResp;
@@ -75,7 +76,7 @@ public class DictServiceImpl extends BaseServiceImpl<DictMapper, DictDO, DictRes
@Override @Override
public List<LabelValueResp> listEnumDict() { public List<LabelValueResp> listEnumDict() {
List<String> enumDictNameList = dictItemService.listEnumDictNames(); List<String> enumDictNameList = dictItemService.listEnumDictNames();
return enumDictNameList.stream().map(name -> new LabelValueResp(name, name)).toList(); return CollUtils.mapToList(enumDictNameList, name -> new LabelValueResp(name, name));
} }
/** /**

View File

@@ -22,6 +22,7 @@ import org.springframework.stereotype.Service;
import top.continew.admin.system.mapper.MessageLogMapper; import top.continew.admin.system.mapper.MessageLogMapper;
import top.continew.admin.system.model.entity.MessageLogDO; import top.continew.admin.system.model.entity.MessageLogDO;
import top.continew.admin.system.service.MessageLogService; import top.continew.admin.system.service.MessageLogService;
import top.continew.starter.core.util.CollUtils;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
@@ -44,9 +45,8 @@ public class MessageLogServiceImpl implements MessageLogService {
if (CollUtil.isEmpty(messageIds)) { if (CollUtil.isEmpty(messageIds)) {
return; return;
} }
List<MessageLogDO> list = messageIds.stream() List<MessageLogDO> list = CollUtils
.map(messageId -> new MessageLogDO(messageId, userId, LocalDateTime.now())) .mapToList(messageIds, messageId -> new MessageLogDO(messageId, userId, LocalDateTime.now()));
.toList();
baseMapper.insert(list); baseMapper.insert(list);
} }

View File

@@ -37,6 +37,7 @@ import top.continew.admin.system.model.resp.message.MessageTypeUnreadResp;
import top.continew.admin.system.model.resp.message.MessageUnreadResp; import top.continew.admin.system.model.resp.message.MessageUnreadResp;
import top.continew.admin.system.service.MessageLogService; import top.continew.admin.system.service.MessageLogService;
import top.continew.admin.system.service.MessageService; import top.continew.admin.system.service.MessageService;
import top.continew.starter.core.util.CollUtils;
import top.continew.starter.extension.crud.model.query.PageQuery; import top.continew.starter.extension.crud.model.query.PageQuery;
import top.continew.starter.extension.crud.model.resp.PageResp; import top.continew.starter.extension.crud.model.resp.PageResp;
import top.continew.starter.messaging.websocket.util.WebSocketUtils; import top.continew.starter.messaging.websocket.util.WebSocketUtils;
@@ -75,7 +76,7 @@ public class MessageServiceImpl implements MessageService {
public void readMessage(List<Long> ids, Long userId) { public void readMessage(List<Long> ids, Long userId) {
// 查询当前用户的未读消息 // 查询当前用户的未读消息
List<MessageDO> list = baseMapper.selectUnreadListByUserId(userId); List<MessageDO> list = baseMapper.selectUnreadListByUserId(userId);
List<Long> unreadIds = list.stream().map(MessageDO::getId).toList(); List<Long> unreadIds = CollUtils.mapToList(list, MessageDO::getId);
messageLogService.addWithUserId(CollUtil.isNotEmpty(ids) messageLogService.addWithUserId(CollUtil.isNotEmpty(ids)
? CollUtil.intersection(unreadIds, ids).stream().toList() ? CollUtil.intersection(unreadIds, ids).stream().toList()
: unreadIds, userId); : unreadIds, userId);

View File

@@ -23,6 +23,7 @@ import org.springframework.transaction.annotation.Transactional;
import top.continew.admin.system.mapper.NoticeLogMapper; import top.continew.admin.system.mapper.NoticeLogMapper;
import top.continew.admin.system.model.entity.NoticeLogDO; import top.continew.admin.system.model.entity.NoticeLogDO;
import top.continew.admin.system.service.NoticeLogService; import top.continew.admin.system.service.NoticeLogService;
import top.continew.starter.core.util.CollUtils;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Collection; import java.util.Collection;
@@ -57,7 +58,7 @@ public class NoticeLogServiceImpl implements NoticeLogService {
} }
// 新增没有关联的 // 新增没有关联的
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
List<NoticeLogDO> list = subtract.stream().map(userId -> new NoticeLogDO(noticeId, userId, now)).toList(); List<NoticeLogDO> list = CollUtils.mapToList(subtract, userId -> new NoticeLogDO(noticeId, userId, now));
return baseMapper.insertBatch(list); return baseMapper.insertBatch(list);
} }

View File

@@ -37,6 +37,7 @@ import top.continew.admin.system.model.resp.OptionResp;
import top.continew.admin.system.service.OptionService; import top.continew.admin.system.service.OptionService;
import top.continew.starter.cache.redisson.util.RedisUtils; import top.continew.starter.cache.redisson.util.RedisUtils;
import top.continew.starter.core.constant.StringConstants; import top.continew.starter.core.constant.StringConstants;
import top.continew.starter.core.util.CollUtils;
import top.continew.starter.core.util.validation.CheckUtils; import top.continew.starter.core.util.validation.CheckUtils;
import top.continew.starter.core.util.validation.ValidationUtils; import top.continew.starter.core.util.validation.ValidationUtils;
import top.continew.starter.data.util.QueryWrapperHelper; import top.continew.starter.data.util.QueryWrapperHelper;
@@ -75,7 +76,7 @@ public class OptionServiceImpl implements OptionService {
@Override @Override
public void update(List<OptionReq> options) { public void update(List<OptionReq> options) {
// 非空校验 // 非空校验
List<Long> idList = options.stream().map(OptionReq::getId).toList(); List<Long> idList = CollUtils.mapToList(options, OptionReq::getId);
List<OptionDO> optionList = baseMapper.selectByIds(idList); List<OptionDO> optionList = baseMapper.selectByIds(idList);
Map<String, OptionDO> optionMap = optionList.stream() Map<String, OptionDO> optionMap = optionList.stream()
.collect(Collectors.toMap(OptionDO::getCode, Function.identity(), (existing, replacement) -> existing)); .collect(Collectors.toMap(OptionDO::getCode, Function.identity(), (existing, replacement) -> existing));

View File

@@ -23,6 +23,7 @@ import org.springframework.transaction.annotation.Transactional;
import top.continew.admin.system.mapper.RoleDeptMapper; import top.continew.admin.system.mapper.RoleDeptMapper;
import top.continew.admin.system.model.entity.RoleDeptDO; import top.continew.admin.system.model.entity.RoleDeptDO;
import top.continew.admin.system.service.RoleDeptService; import top.continew.admin.system.service.RoleDeptService;
import top.continew.starter.core.util.CollUtils;
import java.util.List; import java.util.List;
@@ -55,7 +56,7 @@ public class RoleDeptServiceImpl implements RoleDeptService {
// 删除原有关联 // 删除原有关联
baseMapper.lambdaUpdate().eq(RoleDeptDO::getRoleId, roleId).remove(); baseMapper.lambdaUpdate().eq(RoleDeptDO::getRoleId, roleId).remove();
// 保存最新关联 // 保存最新关联
List<RoleDeptDO> roleDeptList = deptIds.stream().map(deptId -> new RoleDeptDO(roleId, deptId)).toList(); List<RoleDeptDO> roleDeptList = CollUtils.mapToList(deptIds, deptId -> new RoleDeptDO(roleId, deptId));
return baseMapper.insertBatch(roleDeptList); return baseMapper.insertBatch(roleDeptList);
} }

View File

@@ -23,6 +23,7 @@ import org.springframework.transaction.annotation.Transactional;
import top.continew.admin.system.mapper.RoleMenuMapper; import top.continew.admin.system.mapper.RoleMenuMapper;
import top.continew.admin.system.model.entity.RoleMenuDO; import top.continew.admin.system.model.entity.RoleMenuDO;
import top.continew.admin.system.service.RoleMenuService; import top.continew.admin.system.service.RoleMenuService;
import top.continew.starter.core.util.CollUtils;
import top.continew.starter.data.service.impl.ServiceImpl; import top.continew.starter.data.service.impl.ServiceImpl;
import java.util.ArrayList; import java.util.ArrayList;
@@ -58,7 +59,7 @@ public class RoleMenuServiceImpl extends ServiceImpl<RoleMenuMapper, RoleMenuDO>
// 删除原有关联 // 删除原有关联
baseMapper.lambdaUpdate().eq(RoleMenuDO::getRoleId, roleId).remove(); baseMapper.lambdaUpdate().eq(RoleMenuDO::getRoleId, roleId).remove();
// 保存最新关联 // 保存最新关联
List<RoleMenuDO> roleMenuList = menuIds.stream().map(menuId -> new RoleMenuDO(roleId, menuId)).toList(); List<RoleMenuDO> roleMenuList = CollUtils.mapToList(menuIds, menuId -> new RoleMenuDO(roleId, menuId));
return baseMapper.insertBatch(roleMenuList); return baseMapper.insertBatch(roleMenuList);
} }

View File

@@ -39,13 +39,13 @@ import top.continew.admin.system.model.resp.MenuResp;
import top.continew.admin.system.model.resp.role.RoleDetailResp; import top.continew.admin.system.model.resp.role.RoleDetailResp;
import top.continew.admin.system.model.resp.role.RoleResp; import top.continew.admin.system.model.resp.role.RoleResp;
import top.continew.admin.system.service.*; import top.continew.admin.system.service.*;
import top.continew.starter.core.util.CollUtils;
import top.continew.starter.core.util.validation.CheckUtils; import top.continew.starter.core.util.validation.CheckUtils;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors;
/** /**
* 角色业务实现 * 角色业务实现
@@ -150,7 +150,7 @@ public class RoleServiceImpl extends BaseServiceImpl<RoleMapper, RoleDO, RoleRes
if (obj instanceof RoleDetailResp detail) { if (obj instanceof RoleDetailResp detail) {
Long roleId = detail.getId(); Long roleId = detail.getId();
List<MenuResp> list = menuService.listByRoleId(roleId); List<MenuResp> list = menuService.listByRoleId(roleId);
List<Long> menuIds = list.stream().map(MenuResp::getId).toList(); List<Long> menuIds = CollUtils.mapToList(list, MenuResp::getId);
detail.setMenuIds(menuIds); detail.setMenuIds(menuIds);
} }
} }
@@ -172,7 +172,7 @@ public class RoleServiceImpl extends BaseServiceImpl<RoleMapper, RoleDO, RoleRes
return Collections.emptySet(); return Collections.emptySet();
} }
List<RoleDO> roleList = baseMapper.lambdaQuery().select(RoleDO::getCode).in(RoleDO::getId, roleIdList).list(); List<RoleDO> roleList = baseMapper.lambdaQuery().select(RoleDO::getCode).in(RoleDO::getId, roleIdList).list();
return roleList.stream().map(RoleDO::getCode).collect(Collectors.toSet()); return CollUtils.mapToSet(roleList, RoleDO::getCode);
} }
@Override @Override
@@ -185,9 +185,7 @@ public class RoleServiceImpl extends BaseServiceImpl<RoleMapper, RoleDO, RoleRes
.select(RoleDO::getId, RoleDO::getCode, RoleDO::getDataScope) .select(RoleDO::getId, RoleDO::getCode, RoleDO::getDataScope)
.in(RoleDO::getId, roleIdList) .in(RoleDO::getId, roleIdList)
.list(); .list();
return roleList.stream() return CollUtils.mapToSet(roleList, r -> new RoleContext(r.getId(), r.getCode(), r.getDataScope()));
.map(r -> new RoleContext(r.getId(), r.getCode(), r.getDataScope()))
.collect(Collectors.toSet());
} }
@Override @Override

View File

@@ -25,6 +25,7 @@ import org.springframework.transaction.annotation.Transactional;
import top.continew.admin.system.mapper.user.UserPasswordHistoryMapper; import top.continew.admin.system.mapper.user.UserPasswordHistoryMapper;
import top.continew.admin.system.model.entity.user.UserPasswordHistoryDO; import top.continew.admin.system.model.entity.user.UserPasswordHistoryDO;
import top.continew.admin.system.service.UserPasswordHistoryService; import top.continew.admin.system.service.UserPasswordHistoryService;
import top.continew.starter.core.util.CollUtils;
import java.util.List; import java.util.List;
@@ -73,7 +74,7 @@ public class UserPasswordHistoryServiceImpl implements UserPasswordHistoryServic
return false; return false;
} }
// 校验是否重复使用历史密码 // 校验是否重复使用历史密码
List<String> passwordList = list.stream().map(UserPasswordHistoryDO::getPassword).toList(); List<String> passwordList = CollUtils.mapToList(list, UserPasswordHistoryDO::getPassword);
return passwordList.stream().anyMatch(p -> passwordEncoder.matches(password, p)); return passwordList.stream().anyMatch(p -> passwordEncoder.matches(password, p));
} }
} }

View File

@@ -31,6 +31,7 @@ import top.continew.admin.system.model.entity.UserRoleDO;
import top.continew.admin.system.model.query.RoleUserQuery; import top.continew.admin.system.model.query.RoleUserQuery;
import top.continew.admin.system.model.resp.role.RoleUserResp; import top.continew.admin.system.model.resp.role.RoleUserResp;
import top.continew.admin.system.service.UserRoleService; import top.continew.admin.system.service.UserRoleService;
import top.continew.starter.core.util.CollUtils;
import top.continew.starter.core.util.validation.CheckUtils; import top.continew.starter.core.util.validation.CheckUtils;
import top.continew.starter.data.util.QueryWrapperHelper; import top.continew.starter.data.util.QueryWrapperHelper;
import top.continew.starter.extension.crud.model.query.PageQuery; import top.continew.starter.extension.crud.model.query.PageQuery;
@@ -85,13 +86,13 @@ public class UserRoleServiceImpl implements UserRoleService {
// 删除原有关联 // 删除原有关联
baseMapper.lambdaUpdate().eq(UserRoleDO::getUserId, userId).remove(); baseMapper.lambdaUpdate().eq(UserRoleDO::getUserId, userId).remove();
// 保存最新关联 // 保存最新关联
List<UserRoleDO> userRoleList = roleIds.stream().map(roleId -> new UserRoleDO(userId, roleId)).toList(); List<UserRoleDO> userRoleList = CollUtils.mapToList(roleIds, roleId -> new UserRoleDO(userId, roleId));
return baseMapper.insertBatch(userRoleList); return baseMapper.insertBatch(userRoleList);
} }
@Override @Override
public boolean assignRoleToUsers(Long roleId, List<Long> userIds) { public boolean assignRoleToUsers(Long roleId, List<Long> userIds) {
List<UserRoleDO> userRoleList = userIds.stream().map(userId -> new UserRoleDO(userId, roleId)).toList(); List<UserRoleDO> userRoleList = CollUtils.mapToList(userIds, userId -> new UserRoleDO(userId, roleId));
return baseMapper.insertBatch(userRoleList); return baseMapper.insertBatch(userRoleList);
} }

View File

@@ -80,6 +80,7 @@ import top.continew.admin.system.service.*;
import top.continew.starter.cache.redisson.util.RedisUtils; import top.continew.starter.cache.redisson.util.RedisUtils;
import top.continew.starter.core.constant.StringConstants; import top.continew.starter.core.constant.StringConstants;
import top.continew.starter.core.exception.BusinessException; import top.continew.starter.core.exception.BusinessException;
import top.continew.starter.core.util.CollUtils;
import top.continew.starter.core.util.FileUploadUtils; import top.continew.starter.core.util.FileUploadUtils;
import top.continew.starter.core.util.validation.CheckUtils; import top.continew.starter.core.util.validation.CheckUtils;
import top.continew.starter.extension.crud.model.query.PageQuery; import top.continew.starter.extension.crud.model.query.PageQuery;
@@ -202,7 +203,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserRes
.select(UserDO::getId, UserDO::getNickname, UserDO::getIsSystem) .select(UserDO::getId, UserDO::getNickname, UserDO::getIsSystem)
.in(UserDO::getId, ids) .in(UserDO::getId, ids)
.list(); .list();
List<Long> idList = list.stream().map(UserDO::getId).toList(); List<Long> idList = CollUtils.mapToList(list, UserDO::getId);
Collection<Long> subtractIds = CollUtil.subtract(ids, idList); Collection<Long> subtractIds = CollUtil.subtract(ids, idList);
CheckUtils.throwIfNotEmpty(subtractIds, "所选用户 [{}] 不存在", CollUtil.join(subtractIds, StringConstants.COMMA)); CheckUtils.throwIfNotEmpty(subtractIds, "所选用户 [{}] 不存在", CollUtil.join(subtractIds, StringConstants.COMMA));
Optional<UserDO> isSystemData = list.stream().filter(UserDO::getIsSystem).findFirst(); Optional<UserDO> isSystemData = list.stream().filter(UserDO::getIsSystem).findFirst();
@@ -278,7 +279,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserRes
int existRoleCount = roleService.countByNames(roleNames); int existRoleCount = roleService.countByNames(roleNames);
CheckUtils.throwIf(existRoleCount < roleNames.size(), "存在无效角色,请检查数据"); CheckUtils.throwIf(existRoleCount < roleNames.size(), "存在无效角色,请检查数据");
// 校验是否存在无效部门 // 校验是否存在无效部门
List<String> deptNames = validRowList.stream().map(UserImportRowReq::getDeptName).distinct().toList(); List<String> deptNames = CollUtils.mapToList(validRowList, UserImportRowReq::getDeptName);
int existDeptCount = deptService.countByNames(deptNames); int existDeptCount = deptService.countByNames(deptNames);
CheckUtils.throwIf(existDeptCount < deptNames.size(), "存在无效部门,请检查数据"); CheckUtils.throwIf(existDeptCount < deptNames.size(), "存在无效部门,请检查数据");
@@ -316,11 +317,9 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserRes
// 已存在数据查询 // 已存在数据查询
List<String> existEmails = listExistByField(importUserList, UserImportRowReq::getEmail, UserDO::getEmail); List<String> existEmails = listExistByField(importUserList, UserImportRowReq::getEmail, UserDO::getEmail);
List<String> existPhones = listExistByField(importUserList, UserImportRowReq::getPhone, UserDO::getPhone); List<String> existPhones = listExistByField(importUserList, UserImportRowReq::getPhone, UserDO::getPhone);
List<UserDO> existUserList = listByUsernames(importUserList.stream() List<UserDO> existUserList = listByUsernames(CollUtils
.map(UserImportRowReq::getUsername) .mapToList(importUserList, UserImportRowReq::getUsername));
.filter(Objects::nonNull) List<String> existUsernames = CollUtils.mapToList(existUserList, UserDO::getUsername);
.toList());
List<String> existUsernames = existUserList.stream().map(UserDO::getUsername).toList();
CheckUtils CheckUtils
.throwIf(isExitImportUser(req, importUserList, existUsernames, existEmails, existPhones), "数据不符合导入策略,已退出导入"); .throwIf(isExitImportUser(req, importUserList, existUsernames, existEmails, existPhones), "数据不符合导入策略,已退出导入");
@@ -519,10 +518,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserRes
.between(CollUtil.isNotEmpty(createTimeList), "t1.create_time", CollUtil.getFirst(createTimeList), CollUtil .between(CollUtil.isNotEmpty(createTimeList), "t1.create_time", CollUtil.getFirst(createTimeList), CollUtil
.getLast(createTimeList)) .getLast(createTimeList))
.and(deptId != null && !SysConstants.SUPER_DEPT_ID.equals(deptId), q -> { .and(deptId != null && !SysConstants.SUPER_DEPT_ID.equals(deptId), q -> {
List<Long> deptIdList = deptService.listChildren(deptId) List<Long> deptIdList = CollUtils.mapToList(deptService.listChildren(deptId), DeptDO::getId);
.stream()
.map(DeptDO::getId)
.collect(Collectors.toList());
deptIdList.add(deptId); deptIdList.add(deptId);
q.in("t1.dept_id", deptIdList); q.in("t1.dept_id", deptIdList);
}) })
@@ -543,7 +539,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserRes
} }
if (CollUtil.isNotEmpty(updateList)) { if (CollUtil.isNotEmpty(updateList)) {
baseMapper.updateBatchById(updateList); baseMapper.updateBatchById(updateList);
userRoleService.deleteByUserIds(updateList.stream().map(UserDO::getId).toList()); userRoleService.deleteByUserIds(CollUtils.mapToList(updateList, UserDO::getId));
} }
if (CollUtil.isNotEmpty(userRoleDOList)) { if (CollUtil.isNotEmpty(userRoleDOList)) {
userRoleService.saveBatch(userRoleDOList); userRoleService.saveBatch(userRoleDOList);
@@ -603,7 +599,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserRes
Function<UserImportRowReq, String> rowField, Function<UserImportRowReq, String> rowField,
SFunction<UserDO, ?> dbField, SFunction<UserDO, ?> dbField,
boolean fieldEncrypt) { boolean fieldEncrypt) {
List<String> fieldValues = userRowList.stream().map(rowField).filter(Objects::nonNull).toList(); List<String> fieldValues = CollUtils.mapToList(userRowList, rowField);
if (fieldValues.isEmpty()) { if (fieldValues.isEmpty()) {
return 0; return 0;
} }
@@ -622,14 +618,14 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserRes
private List<String> listExistByField(List<UserImportRowReq> userRowList, private List<String> listExistByField(List<UserImportRowReq> userRowList,
Function<UserImportRowReq, String> rowField, Function<UserImportRowReq, String> rowField,
SFunction<UserDO, String> dbField) { SFunction<UserDO, String> dbField) {
List<String> fieldValues = userRowList.stream().map(rowField).filter(Objects::nonNull).toList(); List<String> fieldValues = CollUtils.mapToList(userRowList, rowField);
if (fieldValues.isEmpty()) { if (fieldValues.isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
} }
List<UserDO> userDOList = baseMapper.selectList(Wrappers.<UserDO>lambdaQuery() List<UserDO> userList = baseMapper.selectList(Wrappers.<UserDO>lambdaQuery()
.in(dbField, SecureUtils.encryptFieldByAes(fieldValues)) .in(dbField, SecureUtils.encryptFieldByAes(fieldValues))
.select(dbField)); .select(dbField));
return userDOList.stream().map(dbField).filter(Objects::nonNull).toList(); return CollUtils.mapToList(userList, dbField);
} }
/** /**

View File

@@ -25,12 +25,12 @@ import top.continew.admin.system.enums.SocialSourceEnum;
import top.continew.admin.system.mapper.user.UserSocialMapper; import top.continew.admin.system.mapper.user.UserSocialMapper;
import top.continew.admin.system.model.entity.user.UserSocialDO; import top.continew.admin.system.model.entity.user.UserSocialDO;
import top.continew.admin.system.service.UserSocialService; import top.continew.admin.system.service.UserSocialService;
import top.continew.starter.core.util.CollUtils;
import top.continew.starter.core.util.validation.CheckUtils; import top.continew.starter.core.util.validation.CheckUtils;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors;
/** /**
* 用户社会化关联业务实现 * 用户社会化关联业务实现
@@ -73,7 +73,7 @@ public class UserSocialServiceImpl implements UserSocialService {
String source = authUser.getSource(); String source = authUser.getSource();
String openId = authUser.getUuid(); String openId = authUser.getUuid();
List<UserSocialDO> userSocialList = this.listByUserId(userId); List<UserSocialDO> userSocialList = this.listByUserId(userId);
Set<String> boundSocialSet = userSocialList.stream().map(UserSocialDO::getSource).collect(Collectors.toSet()); Set<String> boundSocialSet = CollUtils.mapToSet(userSocialList, UserSocialDO::getSource);
String description = SocialSourceEnum.valueOf(source).getDescription(); String description = SocialSourceEnum.valueOf(source).getDescription();
CheckUtils.throwIf(boundSocialSet.contains(source), "您已经绑定过了 [{}] 平台,请先解绑", description); CheckUtils.throwIf(boundSocialSet.contains(source), "您已经绑定过了 [{}] 平台,请先解绑", description);
UserSocialDO userSocial = this.getBySourceAndOpenId(source, openId); UserSocialDO userSocial = this.getBySourceAndOpenId(source, openId);