文章目录
- 🌞 Sun Frame:SpringBoot 的轻量级开发框架(个人开源项目推荐)
- 🌟 亮点功能
- 📦 spring cloud模块概览
- 常用工具
- 🔗 更多信息
- 1.easycode生成代码
- 1.配置
- 2.AuthPermissionDao.java剪切到mapper
- 3.AuthPermission.java使用lombok优化
- 4.AuthPermissionDao.java 删除Pageable
- 5.AuthPermissionDao.xml 全局替换为空
- 6.AuthPermissionService.java 删除分页查询接口
- 7.AuthPermissionServiceImpl.java 删除分页查询实现类
- 2.编写DTO和BO
- 1.sun-club-auth-application-controller
- 1.AuthPermissionDTO.java
- 2.AuthPermissionDTOConverter.java
- 2.sun-club-auth-domain
- 1.AuthPermissionBO.java
- 2.AuthPermissionBOConverter.java
- 3.新增权限
- 1.PermissionController.java
- 2.sun-club-auth-domain
- 1.AuthPermissionDomainService.java
- 2.AuthPermissionDomainServiceImpl.java
- 3.sun-club-auth-infra
- 1.AuthPermissionService.java
- 2.AuthPermissionServiceImpl.java
- 4.测试
- 1.接口设计
- 2.测试
- 4.更新权限
- 1.PermissionController.java
- 2.sun-club-auth-domain
- 1.AuthPermissionDomainService.java
- 2.AuthPermissionDomainServiceImpl.java
- 3.sun-club-auth-infra
- 1.AuthPermissionService.java
- 2.AuthPermissionServiceImpl.java
- 3.AuthPermissionDao.xml 注意show是关键字
- 4.测试
- 1.接口设计
- 2.测试
- 5.删除权限
- 1.PermissionController.java
- 2.AuthPermissionDomainService.java
- 3.AuthPermissionDomainServiceImpl.java
- 4.测试
- 1.接口设计
- 2.测试
- 6.权限与角色关联
- 1.easycode生成代码
- 1.配置
- 2.dao层AuthRolePermissionDao.java的移动到mapper层
- 3.AuthRolePermission.java 使用lombok优化
- 4.AuthRolePermissionDao.java 删除Pageable
- 5.AuthRolePermissionDao.xml 全局替换掉, INTEGER之类的
- 6.AuthRolePermissionService.java 删除分页查询接口
- 7.AuthRolePermissionServiceImpl.java 删除分页查询实现类
- 2.编写DTO和BO
- 1.sun-club-auth-application-controller
- 1.AuthRolePermissionDTO.java
- 2.AuthRolePermissionDTOConverter.java
- 2.sun-club-auth-domain
- 1.AuthRolePermissionBO.java
- 2.AuthRolePermissionBOConverter.java
- 3.sun-club-auth-application-controller
- 1.AuthRolePermissionDTO.java 新增permissionIdList字段
- 2.RolePermissionController.java
- 4.sun-club-auth-domain
- 1.AuthRolePermissionDomainService.java
- 2.AuthRolePermissionDomainServiceImpl.java
- 3.AuthRolePermissionBO.java 保持跟DTO一致
- 5.sun-club-auth-infra
- 1.AuthRolePermissionService.java
- 2.AuthRolePermissionServiceImpl.java
- 6.测试
- 1.接口设计
- 2.测试
🌞 Sun Frame:SpringBoot 的轻量级开发框架(个人开源项目推荐)
轻松高效的现代化开发体验
Sun Frame 是我个人开源的一款基于 SpringBoot 的轻量级框架,专为中小型企业设计。它提供了一种快速、简单且易于扩展的开发方式。
我们的开发文档记录了整个项目从0到1的任何细节,实属不易,请给我们一个Star!🌟
您的支持是我们持续改进的动力。
您的支持是我们持续改进的动力。
🌟 亮点功能
- 组件化开发:灵活选择,简化流程。
- 高性能:通过异步日志和 Redis 缓存提升性能。
- 易扩展:支持多种数据库和消息队列。
📦 spring cloud模块概览
- Nacos 服务:高效的服务注册与发现。
- Feign 远程调用:简化服务间通信。
- 强大网关:路由与限流。
常用工具
- 日志管理:异步处理与链路追踪。
- Redis 集成:支持分布式锁与缓存。
- Swagger 文档:便捷的 API 入口。
- 测试支持:SpringBoot-Test 集成。
- EasyCode:自定义EasyCode模板引擎,一键生成CRUD。
🔗 更多信息
- 开源地址:Gitee Sun Frame
- 详细文档:语雀文档
1.easycode生成代码
1.配置
2.AuthPermissionDao.java剪切到mapper
3.AuthPermission.java使用lombok优化
4.AuthPermissionDao.java 删除Pageable
5.AuthPermissionDao.xml 全局替换为空
, VARCHAR
, INTEGER
, TIMESTAMP
6.AuthPermissionService.java 删除分页查询接口
7.AuthPermissionServiceImpl.java 删除分页查询实现类
2.编写DTO和BO
1.sun-club-auth-application-controller
1.AuthPermissionDTO.java
package com.sunxiansheng.auth.application.dto;
import lombok.Data;
import java.io.Serializable;
/**
* (AuthPermission)dto
*
* @author makejava
* @since 2024-06-06 17:16:58
*/
@Data
public class AuthPermissionDTO implements Serializable {
private Long id;
/**
* 权限名称
*/
private String name;
/**
* 父id
*/
private Long parentId;
/**
* 权限类型 0菜单 1操作
*/
private Integer type;
/**
* 菜单路由
*/
private String menuUrl;
/**
* 状态 0启用 1禁用
*/
private Integer status;
/**
* 展示状态 0展示 1隐藏
*/
private Integer show;
/**
* 图标
*/
private String icon;
/**
* 权限唯一标识
*/
private String permissionKey;
/**
* 是否被删除 0为删除 1已删除
*/
private Integer isDeleted;
}
2.AuthPermissionDTOConverter.java
package com.sunxiansheng.auth.application.convert;
import com.sunxiansheng.auth.application.dto.AuthPermissionDTO;
import com.sunxiansheng.auth.domain.entity.AuthPermissionBO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* Description: DTO转换
* @Author sun
* @Create 2024/6/5 15:39
* @Version 1.0
*/
@Mapper
public interface AuthPermissionDTOConverter {
AuthPermissionDTOConverter INSTANCE = Mappers.getMapper(AuthPermissionDTOConverter.class);
// 将DTO转换为BO
AuthPermissionBO convertDTO2BO(AuthPermissionDTO authPermissionDTO);
// 将BO转换为DTO
AuthPermissionDTO convertBO2DTO(AuthPermissionBO authPermissionBO);
// 将DTO集合转换为BO集合
List<AuthPermissionBO> convertDTO2BO(List<AuthPermissionDTO> authPermissionDTOList);
// 将BO集合转换为DTO集合
List<AuthPermissionDTO> convertBO2DTO(List<AuthPermissionBO> authPermissionBOList);
}
2.sun-club-auth-domain
1.AuthPermissionBO.java
package com.sunxiansheng.auth.domain.entity;
import lombok.Data;
import java.io.Serializable;
/**
* (AuthPermission)bo
*
* @author makejava
* @since 2024-06-06 17:16:58
*/
@Data
public class AuthPermissionBO implements Serializable {
private Long id;
/**
* 权限名称
*/
private String name;
/**
* 父id
*/
private Long parentId;
/**
* 权限类型 0菜单 1操作
*/
private Integer type;
/**
* 菜单路由
*/
private String menuUrl;
/**
* 状态 0启用 1禁用
*/
private Integer status;
/**
* 展示状态 0展示 1隐藏
*/
private Integer show;
/**
* 图标
*/
private String icon;
/**
* 权限唯一标识
*/
private String permissionKey;
/**
* 是否被删除 0为删除 1已删除
*/
private Integer isDeleted;
}
2.AuthPermissionBOConverter.java
package com.sunxiansheng.auth.domain.convert;
import com.sunxiansheng.auth.basic.entity.AuthPermission;
import com.sunxiansheng.auth.domain.entity.AuthPermissionBO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* Description: BO转换
* @Author sun
* @Create 2024/5/24 9:18
* @Version 1.0
*/
@Mapper // mapstruct的注解
public interface AuthPermissionBOConverter {
AuthPermissionBOConverter INSTANCE = Mappers.getMapper(AuthPermissionBOConverter.class);
// 将BO转换为Entity
AuthPermission convertBO2Entity(AuthPermissionBO authPermissionBO);
// 将Entity转换为BO
AuthPermissionBO convertEntity2BO(AuthPermission authPermission);
// 将BO集合转换为Entity集合
List<AuthPermission> convertBO2Entity(List<AuthPermissionBO> authPermissionBOList);
// 将Entity集合转换为BO集合
List<AuthPermissionBO> convertEntity2BO(List<AuthPermission> authPermissionList);
}
3.新增权限
1.PermissionController.java
package com.sunxiansheng.auth.application.controller;
import com.alibaba.fastjson.JSON;
import com.google.common.base.Preconditions;
import com.sunxiansheng.auth.application.convert.AuthPermissionDTOConverter;
import com.sunxiansheng.auth.application.dto.AuthPermissionDTO;
import com.sunxiansheng.auth.common.eneity.Result;
import com.sunxiansheng.auth.domain.entity.AuthPermissionBO;
import com.sunxiansheng.auth.domain.service.AuthPermissionDomainService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
/**
* Description:
* @Author sun
* @Create 2024/6/2 17:25
* @Version 1.0
*/
@RestController
@RequestMapping("/permission/")
@Slf4j
public class PermissionController {
@Resource
private AuthPermissionDomainService authPermissionDomainService;
/**
* 新增权限信息
* @param authPermissionDTO
* @return
*/
@RequestMapping("add")
public Result<Boolean> add(@RequestBody AuthPermissionDTO authPermissionDTO) {
try {
// 日志
if (log.isInfoEnabled()) {
log.info("PermissionController add AuthPermissionDTO, authPermissionDTO:{}", JSON.toJSONString(authPermissionDTO));
}
// 参数校验
Preconditions.checkArgument(!StringUtils.isBlank(authPermissionDTO.getName()), "权限名称不能为空");
Preconditions.checkNotNull(authPermissionDTO.getParentId(), "父ID不能为空");
// 转换DTO为BO
AuthPermissionBO authPermissionBO = AuthPermissionDTOConverter.INSTANCE.convertDTO2BO(authPermissionDTO);
// 调用领域服务
// 新增权限信息
Boolean res = authPermissionDomainService.add(authPermissionBO);
return Result.ok(res);
} catch (Exception e) {
// error日志
log.error("PermissionController add error:{}", e.getMessage(), e);
return Result.fail("新增权限信息失败");
}
}
}
2.sun-club-auth-domain
1.AuthPermissionDomainService.java
package com.sunxiansheng.auth.domain.service;
import com.sunxiansheng.auth.domain.entity.AuthPermissionBO;
/**
* Description:
* @Author sun
* @Create 2024/5/24 9:03
* @Version 1.0
*/
public interface AuthPermissionDomainService {
/**
* 添加
* @param authPermissionBO
* @return
*/
Boolean add(AuthPermissionBO authPermissionBO);
}
2.AuthPermissionDomainServiceImpl.java
package com.sunxiansheng.auth.domain.service.impl;
import com.sunxiansheng.auth.basic.entity.AuthPermission;
import com.sunxiansheng.auth.basic.entity.AuthRole;
import com.sunxiansheng.auth.basic.service.AuthPermissionService;
import com.sunxiansheng.auth.common.enums.IsDeleteFlagEnum;
import com.sunxiansheng.auth.domain.convert.AuthPermissionBOConverter;
import com.sunxiansheng.auth.domain.convert.AuthRoleBOConverter;
import com.sunxiansheng.auth.domain.entity.AuthPermissionBO;
import com.sunxiansheng.auth.domain.service.AuthPermissionDomainService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
/**
* Description:
* @Author sun
* @Create 2024/5/24 9:03
* @Version 1.0
*/
@Service
@Slf4j
public class AuthPermissionDomainServiceImpl implements AuthPermissionDomainService {
@Resource
private AuthPermissionService authPermissionService;
@Override
public Boolean add(AuthPermissionBO authPermissionBO) {
// BO转换为Entity
AuthPermission authPermission = AuthPermissionBOConverter.INSTANCE.convertBO2Entity(authPermissionBO);
// 调用基础服务
// 设置逻辑删除
authPermission.setIsDeleted(IsDeleteFlagEnum.UN_DELETED.getCode());
// 新增角色
Integer count = authPermissionService.insert(authPermission);
return count > 0;
}
}
3.sun-club-auth-infra
1.AuthPermissionService.java
/**
* 新增数据
*
* @param authPermission 实例对象
* @return 实例对象
*/
Integer insert(AuthPermission authPermission);
2.AuthPermissionServiceImpl.java
/**
* 新增数据
*
* @param authPermission 实例对象
* @return 实例对象
*/
@Override
public Integer insert(AuthPermission authPermission) {
return this.authPermissionDao.insert(authPermission);
}
4.测试
1.接口设计
2.测试
4.更新权限
1.PermissionController.java
@RequestMapping("update")
public Result<Boolean> update(@RequestBody AuthPermissionDTO authPermissionDTO) {
try {
// 日志
if (log.isInfoEnabled()) {
log.info("PermissionController update AuthPermissionDTO, authPermissionDTO:{}", JSON.toJSONString(authPermissionDTO));
}
// 参数校验
Preconditions.checkNotNull(authPermissionDTO.getId(), "权限ID不能为空");
// 转换DTO为BO
AuthPermissionBO authPermissionBO = AuthPermissionDTOConverter.INSTANCE.convertDTO2BO(authPermissionDTO);
// 调用领域服务
// 修改权限信息
Boolean res = authPermissionDomainService.update(authPermissionBO);
return Result.ok(res);
} catch (Exception e) {
// error日志
log.error("PermissionController update error:{}", e.getMessage(), e);
return Result.fail("修改权限信息失败");
}
}
2.sun-club-auth-domain
1.AuthPermissionDomainService.java
/**
* 修改
* @param authPermissionBO
* @return
*/
Boolean update(AuthPermissionBO authPermissionBO);
2.AuthPermissionDomainServiceImpl.java
@Override
public Boolean update(AuthPermissionBO authPermissionBO) {
// BO转换为Entity
AuthPermission authPermission = AuthPermissionBOConverter.INSTANCE.convertBO2Entity(authPermissionBO);
// 调用基础服务
// 修改权限信息
Integer count = authPermissionService.update(authPermission);
// 有任何的更新,都要与缓存进行同步的修改,要把当前用户的角色和权限都放到redis里
return count > 0;
}
3.sun-club-auth-infra
1.AuthPermissionService.java
/**
* 修改数据
*
* @param authPermission 实例对象
* @return 实例对象
*/
Integer update(AuthPermission authPermission);
2.AuthPermissionServiceImpl.java
/**
* 修改数据
*
* @param authPermission 实例对象
* @return 实例对象
*/
@Override
public Integer update(AuthPermission authPermission) {
return this.authPermissionDao.update(authPermission);
}
3.AuthPermissionDao.xml 注意show是关键字
4.测试
1.接口设计
2.测试
5.删除权限
1.PermissionController.java
/**
* 删除权限信息
* @param authPermissionDTO
* @return
*/
@RequestMapping("delete")
public Result<Boolean> delete(@RequestBody AuthPermissionDTO authPermissionDTO) {
try {
// 日志
if (log.isInfoEnabled()) {
log.info("PermissionController delete AuthPermissionDTO, authPermissionDTO:{}", JSON.toJSONString(authPermissionDTO));
}
// 参数校验
Preconditions.checkNotNull(authPermissionDTO.getId(), "权限ID不能为空");
// 转换DTO为BO
AuthPermissionBO authPermissionBO = AuthPermissionDTOConverter.INSTANCE.convertDTO2BO(authPermissionDTO);
// 调用领域服务
// 删除权限信息
Boolean res = authPermissionDomainService.delete(authPermissionBO);
return Result.ok(res);
} catch (Exception e) {
// error日志
log.error("PermissionController delete error:{}", e.getMessage(), e);
return Result.fail("删除权限信息失败");
}
}
2.AuthPermissionDomainService.java
/**
* 删除
* @param authPermissionBO
* @return
*/
Boolean delete(AuthPermissionBO authPermissionBO);
3.AuthPermissionDomainServiceImpl.java
@Override
public Boolean delete(AuthPermissionBO authPermissionBO) {
// BO转换为Entity
AuthPermission authPermission = AuthPermissionBOConverter.INSTANCE.convertBO2Entity(authPermissionBO);
// 设置逻辑删除
authPermission.setIsDeleted(IsDeleteFlagEnum.DELETED.getCode());
// 更新
Integer count = authPermissionService.update(authPermission);
return count > 0;
}
4.测试
1.接口设计
2.测试
6.权限与角色关联
1.easycode生成代码
1.配置
2.dao层AuthRolePermissionDao.java的移动到mapper层
3.AuthRolePermission.java 使用lombok优化
4.AuthRolePermissionDao.java 删除Pageable
5.AuthRolePermissionDao.xml 全局替换掉, INTEGER之类的
6.AuthRolePermissionService.java 删除分页查询接口
7.AuthRolePermissionServiceImpl.java 删除分页查询实现类
2.编写DTO和BO
1.sun-club-auth-application-controller
1.AuthRolePermissionDTO.java
package com.sunxiansheng.auth.application.dto;
import lombok.Data;
import java.io.Serializable;
/**
* 角色权限关联表(AuthRolePermission)实体类
*
* @author makejava
* @since 2024-06-07 14:11:29
*/
@Data
public class AuthRolePermissionDTO implements Serializable {
private Long id;
/**
* 角色id
*/
private Long roleId;
/**
* 权限id
*/
private Long permissionId;
private Integer isDeleted;
}
2.AuthRolePermissionDTOConverter.java
package com.sunxiansheng.auth.application.convert;
import com.sunxiansheng.auth.application.dto.AuthRolePermissionDTO;
import com.sunxiansheng.auth.domain.entity.AuthRolePermissionBO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* Description: DTO转换
* @Author sun
* @Create 2024/6/5 15:39
* @Version 1.0
*/
@Mapper
public interface AuthRolePermissionDTOConverter {
AuthRolePermissionDTOConverter INSTANCE = Mappers.getMapper(AuthRolePermissionDTOConverter.class);
// 将DTO转换为BO
AuthRolePermissionBO convertDTO2BO(AuthRolePermissionDTO authRolePermissionDTO);
// 将BO转换为DTO
AuthRolePermissionDTO convertBO2DTO(AuthRolePermissionBO authRolePermissionBO);
// 将DTO集合转换为BO集合
List<AuthRolePermissionBO> convertDTOList2BOList(List<AuthRolePermissionDTO> authRolePermissionDTOList);
// 将BO集合转换为DTO集合
List<AuthRolePermissionDTO> convertBOList2DTOList(List<AuthRolePermissionBO> authRolePermissionBOList);
}
2.sun-club-auth-domain
1.AuthRolePermissionBO.java
package com.sunxiansheng.auth.domain.entity;
import lombok.Data;
import java.io.Serializable;
/**
* 角色权限关联表(AuthRolePermission)实体类
*
* @author makejava
* @since 2024-06-07 14:11:29
*/
@Data
public class AuthRolePermissionBO implements Serializable {
private Long id;
/**
* 角色id
*/
private Long roleId;
/**
* 权限id
*/
private Long permissionId;
private Integer isDeleted;
}
2.AuthRolePermissionBOConverter.java
package com.sunxiansheng.auth.domain.convert;
import com.sunxiansheng.auth.basic.entity.AuthRolePermission;
import com.sunxiansheng.auth.domain.entity.AuthRolePermissionBO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* Description: BO转换
* @Author sun
* @Create 2024/5/24 9:18
* @Version 1.0
*/
@Mapper // mapstruct的注解
public interface AuthRolePermissionBOConverter {
AuthRolePermissionBOConverter INSTANCE = Mappers.getMapper(AuthRolePermissionBOConverter.class);
// 将BO转换为Entity
AuthRolePermission convertBO2Entity(AuthRolePermissionBO authRolePermissionBO);
// 将Entity转换为BO
AuthRolePermissionBO convertEntity2BO(AuthRolePermission authRolePermission);
// 将BO集合转换为Entity集合
List<AuthRolePermission> convertBOList2EntityList(List<AuthRolePermissionBO> authRolePermissionBOList);
// 将Entity集合转换为BO集合
List<AuthRolePermissionBO> convertEntityList2BOList(List<AuthRolePermission> authRolePermissionList);
}
3.sun-club-auth-application-controller
1.AuthRolePermissionDTO.java 新增permissionIdList字段
2.RolePermissionController.java
package com.sunxiansheng.auth.application.controller;
import com.alibaba.fastjson.JSON;
import com.google.common.base.Preconditions;
import com.sunxiansheng.auth.application.convert.AuthPermissionDTOConverter;
import com.sunxiansheng.auth.application.convert.AuthRolePermissionDTOConverter;
import com.sunxiansheng.auth.application.dto.AuthPermissionDTO;
import com.sunxiansheng.auth.application.dto.AuthRolePermissionDTO;
import com.sunxiansheng.auth.common.eneity.Result;
import com.sunxiansheng.auth.domain.entity.AuthPermissionBO;
import com.sunxiansheng.auth.domain.entity.AuthRolePermissionBO;
import com.sunxiansheng.auth.domain.service.AuthRolePermissionDomainService;
import com.sunxiansheng.auth.domain.service.impl.AuthRolePermissionDomainServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
/**
* Description:
* @Author sun
* @Create 2024/6/2 17:25
* @Version 1.0
*/
@RestController
@RequestMapping("/rolePermission/")
@Slf4j
public class RolePermissionController {
@Resource
private AuthRolePermissionDomainService authRolePermissionDomainService;
/**
* 新增角色权限信息
* @param authRolePermissionDTO
* @return
*/
@RequestMapping("add")
public Result<Boolean> add(@RequestBody AuthRolePermissionDTO authRolePermissionDTO) {
try {
// 日志
if (log.isInfoEnabled()) {
log.info("RolePermissionController add AuthRolePermissionDTO, authRolePermissionDTO:{}", JSON.toJSONString(authRolePermissionDTO));
}
// 参数校验
Preconditions.checkArgument(!CollectionUtils.isEmpty(authRolePermissionDTO.getPermissionIdList()), "权限ID列表不能为空");
Preconditions.checkNotNull(authRolePermissionDTO.getRoleId(), "角色ID不能为空");
// 转换DTO为BO
AuthRolePermissionBO authRolePermissionBO = AuthRolePermissionDTOConverter.INSTANCE.convertDTO2BO(authRolePermissionDTO);
// 调用领域服务
// 新增权限信息
Boolean res = authRolePermissionDomainService.add(authRolePermissionBO);
return Result.ok(res);
} catch (Exception e) {
// error日志
log.error("RolePermissionController add error:{}", e.getMessage(), e);
return Result.fail("新增角色权限信息失败");
}
}
}
4.sun-club-auth-domain
1.AuthRolePermissionDomainService.java
package com.sunxiansheng.auth.domain.service;
import com.sunxiansheng.auth.domain.entity.AuthRolePermissionBO;
/**
* Description:
* @Author sun
* @Create 2024/5/24 9:03
* @Version 1.0
*/
public interface AuthRolePermissionDomainService {
/**
* 添加
* @param authRolePermissionBO
* @return
*/
Boolean add(AuthRolePermissionBO authRolePermissionBO);
}
2.AuthRolePermissionDomainServiceImpl.java
package com.sunxiansheng.auth.domain.service.impl;
import com.sunxiansheng.auth.basic.entity.AuthRolePermission;
import com.sunxiansheng.auth.basic.service.AuthRolePermissionService;
import com.sunxiansheng.auth.common.enums.IsDeleteFlagEnum;
import com.sunxiansheng.auth.domain.convert.AuthRolePermissionBOConverter;
import com.sunxiansheng.auth.domain.entity.AuthRolePermissionBO;
import com.sunxiansheng.auth.domain.service.AuthRolePermissionDomainService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* Description:
* @Author sun
* @Create 2024/5/24 9:03
* @Version 1.0
*/
@Service
@Slf4j
public class AuthRolePermissionDomainServiceImpl implements AuthRolePermissionDomainService {
@Resource
private AuthRolePermissionService authRolePermissionService;
@Override
public Boolean add(AuthRolePermissionBO authRolePermissionBO) {
// BO转换为Entity
AuthRolePermission authRolePermission = AuthRolePermissionBOConverter.INSTANCE.convertBO2Entity(authRolePermissionBO);
// 得到roleId
Long roleId = authRolePermission.getRoleId();
// 构建一个批量插入的列表
List<AuthRolePermission> entities = authRolePermissionBO.getPermissionIdList().stream().map(
permissionId -> {
// 每一个permissionId都构建一个entity
AuthRolePermission authRolePermission1 = new AuthRolePermission();
authRolePermission1.setRoleId(roleId);
authRolePermission1.setPermissionId(permissionId);
authRolePermission1.setIsDeleted(IsDeleteFlagEnum.UN_DELETED.getCode());
return authRolePermission1;
}
).collect(Collectors.toList());
// 批量插入
int count = authRolePermissionService.insertBatch(entities);
return count > 0;
}
}
3.AuthRolePermissionBO.java 保持跟DTO一致
5.sun-club-auth-infra
1.AuthRolePermissionService.java
/**
* 批量新增数据(MyBatis原生foreach方法)
* @param entities
* @return
*/
public int insertBatch(List<AuthRolePermission> entities);
2.AuthRolePermissionServiceImpl.java
/**
* 批量新增数据(MyBatis原生foreach方法)
*
* @param entities List<AuthRolePermission> 实例对象列表
* @return 影响行数
*/
public int insertBatch(List<AuthRolePermission> entities) {
return authRolePermissionDao.insertBatch(entities);
}