feat: 优化项目结构

This commit is contained in:
bunny 2024-10-17 15:06:31 +08:00
parent 7fb81488f9
commit 74cba9e7cf
30 changed files with 263 additions and 207 deletions

View File

@ -3,11 +3,11 @@ package cn.bunny.common.generator.generator;
import cn.bunny.common.generator.entity.BaseField;
import cn.bunny.common.generator.entity.BaseResultMap;
import cn.bunny.common.generator.utils.GeneratorCodeUtils;
import cn.bunny.dao.dto.schedulers.SchedulersGroupAddDto;
import cn.bunny.dao.dto.schedulers.SchedulersGroupDto;
import cn.bunny.dao.dto.schedulers.SchedulersGroupUpdateDto;
import cn.bunny.dao.entity.schedulers.SchedulersGroup;
import cn.bunny.dao.vo.schedulers.SchedulersGroupVo;
import cn.bunny.dao.dto.quartz.SchedulersGroupAddDto;
import cn.bunny.dao.dto.quartz.SchedulersGroupDto;
import cn.bunny.dao.dto.quartz.SchedulersGroupUpdateDto;
import cn.bunny.dao.entity.quartz.SchedulersGroup;
import cn.bunny.dao.vo.quartz.SchedulersGroupVo;
import com.baomidou.mybatisplus.annotation.TableName;
import com.google.common.base.CaseFormat;
import io.swagger.v3.oas.annotations.media.Schema;

View File

@ -57,7 +57,8 @@ public class RedisConfiguration {
}
/**
* * 配置Redis过期时间30天
* * 配置Redis过期时间
* 一个月
* 解决cache(@Cacheable)把数据缓存到redis中的value是乱码问题
*/
@Bean
@ -74,19 +75,20 @@ public class RedisConfiguration {
}
/**
* * 配置redis过期时间3分钟
* * 配置redis过期时间
* 半个月
*
* @param factory
* @return
*/
@Bean
@SuppressWarnings("all")
public CacheManager cacheManagerWithMinutes(RedisConnectionFactory factory) {
public CacheManager cacheManagerWithHalfOfMouth(RedisConnectionFactory factory) {
// 配置序列化
RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig()
.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer()))
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(jsonRedisSerializer()))
.entryTtl(Duration.ofMinutes(3));
.entryTtl(Duration.ofDays(15));
return RedisCacheManager.builder(factory).cacheDefaults(config).build();
}
@ -113,18 +115,23 @@ public class RedisConfiguration {
* 指定的日期模式
*/
public Jackson2JsonRedisSerializer<Object> jsonRedisSerializer() {
ObjectMapper mapper = new ObjectMapper();
// 设置ObjectMapper访问权限
mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
// 记录序列化之后的数据类型方便反序列化
mapper.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.NON_FINAL);
// LocalDatetime序列化默认不兼容jdk8日期序列化
JavaTimeModule timeModule = new JavaTimeModule();
timeModule.addDeserializer(LocalDate.class, new LocalDateDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
timeModule.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
timeModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
timeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
// 对象序列化
ObjectMapper mapper = new ObjectMapper();
// 设置ObjectMapper访问权限
mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
// 记录序列化之后的数据类型方便反序列化
// mapper.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.NON_FINAL);
mapper.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.EVERYTHING);
// 关闭默认的日期格式化方式默认UTC日期格式 yyyy-MM-ddTHH:mm:ss.SSS
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
mapper.registerModule(timeModule);

View File

@ -1,4 +1,4 @@
package cn.bunny.dao.dto.schedulers;
package cn.bunny.dao.dto.quartz;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;

View File

@ -1,4 +1,4 @@
package cn.bunny.dao.dto.schedulers;
package cn.bunny.dao.dto.quartz;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;

View File

@ -1,4 +1,4 @@
package cn.bunny.dao.dto.schedulers;
package cn.bunny.dao.dto.quartz;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;

View File

@ -1,4 +1,4 @@
package cn.bunny.dao.dto.schedulers;
package cn.bunny.dao.dto.quartz;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;

View File

@ -1,4 +1,4 @@
package cn.bunny.dao.dto.schedulers;
package cn.bunny.dao.dto.quartz;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;

View File

@ -1,4 +1,4 @@
package cn.bunny.dao.dto.schedulers;
package cn.bunny.dao.dto.quartz;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;

View File

@ -1,4 +1,4 @@
package cn.bunny.dao.dto.schedulers;
package cn.bunny.dao.dto.quartz;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;

View File

@ -1,4 +1,4 @@
package cn.bunny.dao.entity.schedulers;
package cn.bunny.dao.entity.quartz;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.v3.oas.annotations.media.Schema;
@ -19,7 +19,7 @@ import java.io.Serializable;
@Getter
@Setter
@Accessors(chain = true)
@TableName("qrtz_view_schedulers")
@TableName("view_qrtz_schedulers")
@Schema(name = "Schedulers对象", title = "Schedulers视图", description = "Schedulers视图")
public class Schedulers implements Serializable {

View File

@ -1,4 +1,4 @@
package cn.bunny.dao.entity.schedulers;
package cn.bunny.dao.entity.quartz;
import cn.bunny.dao.entity.BaseEntity;
import com.baomidou.mybatisplus.annotation.TableName;
@ -18,7 +18,7 @@ import lombok.experimental.Accessors;
@Getter
@Setter
@Accessors(chain = true)
@TableName("sys_schedulers_group")
@TableName("qrtz_schedulers_group")
@Schema(name = "SchedulersGroup对象", title = "任务调度分组", description = "任务调度分组")
public class SchedulersGroup extends BaseEntity {

View File

@ -1,4 +1,4 @@
package cn.bunny.dao.vo.schedulers;
package cn.bunny.dao.vo.quartz;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;

View File

@ -1,4 +1,4 @@
package cn.bunny.dao.vo.schedulers;
package cn.bunny.dao.vo.quartz;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;

View File

@ -49,6 +49,13 @@ public class RoleController {
return Mono.just(Result.success(pageResult));
}
@Operation(summary = "获取所有角色", description = "获取所有角色")
@GetMapping("getAllRoles")
public Mono<Result<List<RoleVo>>> getAllRoles() {
List<RoleVo> roleVoList = roleService.getAllRoles();
return Mono.just(Result.success(roleVoList));
}
@Operation(summary = "添加角色", description = "添加角色")
@PostMapping("addRole")
public Mono<Result<String>> addRole(@Valid @RequestBody RoleAddDto dto) {
@ -69,11 +76,4 @@ public class RoleController {
roleService.deleteRole(ids);
return Mono.just(Result.success(ResultCodeEnum.DELETE_SUCCESS));
}
@Operation(summary = "获取所有角色", description = "获取所有角色")
@GetMapping("getAllRoles")
public Mono<Result<List<RoleVo>>> getAllRoles() {
List<RoleVo> roleVoList = roleService.getAllRoles();
return Mono.just(Result.success(roleVoList));
}
}

View File

@ -1,13 +1,13 @@
package cn.bunny.services.controller;
import cn.bunny.dao.dto.schedulers.SchedulersAddDto;
import cn.bunny.dao.dto.schedulers.SchedulersDto;
import cn.bunny.dao.dto.schedulers.SchedulersOperationDto;
import cn.bunny.dao.entity.schedulers.Schedulers;
import cn.bunny.dao.dto.quartz.SchedulersAddDto;
import cn.bunny.dao.dto.quartz.SchedulersDto;
import cn.bunny.dao.dto.quartz.SchedulersOperationDto;
import cn.bunny.dao.entity.quartz.Schedulers;
import cn.bunny.dao.pojo.result.PageResult;
import cn.bunny.dao.pojo.result.Result;
import cn.bunny.dao.pojo.result.ResultCodeEnum;
import cn.bunny.dao.vo.schedulers.SchedulersVo;
import cn.bunny.dao.vo.quartz.SchedulersVo;
import cn.bunny.services.service.SchedulersService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;

View File

@ -1,13 +1,13 @@
package cn.bunny.services.controller;
import cn.bunny.dao.dto.schedulers.SchedulersGroupAddDto;
import cn.bunny.dao.dto.schedulers.SchedulersGroupDto;
import cn.bunny.dao.dto.schedulers.SchedulersGroupUpdateDto;
import cn.bunny.dao.entity.schedulers.SchedulersGroup;
import cn.bunny.dao.dto.quartz.SchedulersGroupAddDto;
import cn.bunny.dao.dto.quartz.SchedulersGroupDto;
import cn.bunny.dao.dto.quartz.SchedulersGroupUpdateDto;
import cn.bunny.dao.entity.quartz.SchedulersGroup;
import cn.bunny.dao.pojo.result.PageResult;
import cn.bunny.dao.pojo.result.Result;
import cn.bunny.dao.pojo.result.ResultCodeEnum;
import cn.bunny.dao.vo.schedulers.SchedulersGroupVo;
import cn.bunny.dao.vo.quartz.SchedulersGroupVo;
import cn.bunny.services.service.SchedulersGroupService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;

View File

@ -1,7 +1,7 @@
package cn.bunny.services.mapper;
import cn.bunny.dao.dto.schedulers.SchedulersGroupDto;
import cn.bunny.dao.entity.schedulers.SchedulersGroup;
import cn.bunny.dao.dto.quartz.SchedulersGroupDto;
import cn.bunny.dao.entity.quartz.SchedulersGroup;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

View File

@ -1,7 +1,7 @@
package cn.bunny.services.mapper;
import cn.bunny.dao.dto.schedulers.SchedulersDto;
import cn.bunny.dao.entity.schedulers.Schedulers;
import cn.bunny.dao.dto.quartz.SchedulersDto;
import cn.bunny.dao.entity.quartz.Schedulers;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

View File

@ -1,11 +1,11 @@
package cn.bunny.services.service;
import cn.bunny.dao.dto.schedulers.SchedulersGroupAddDto;
import cn.bunny.dao.dto.schedulers.SchedulersGroupDto;
import cn.bunny.dao.dto.schedulers.SchedulersGroupUpdateDto;
import cn.bunny.dao.entity.schedulers.SchedulersGroup;
import cn.bunny.dao.dto.quartz.SchedulersGroupAddDto;
import cn.bunny.dao.dto.quartz.SchedulersGroupDto;
import cn.bunny.dao.dto.quartz.SchedulersGroupUpdateDto;
import cn.bunny.dao.entity.quartz.SchedulersGroup;
import cn.bunny.dao.pojo.result.PageResult;
import cn.bunny.dao.vo.schedulers.SchedulersGroupVo;
import cn.bunny.dao.vo.quartz.SchedulersGroupVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import jakarta.validation.Valid;

View File

@ -1,11 +1,11 @@
package cn.bunny.services.service;
import cn.bunny.dao.dto.schedulers.SchedulersAddDto;
import cn.bunny.dao.dto.schedulers.SchedulersDto;
import cn.bunny.dao.dto.schedulers.SchedulersOperationDto;
import cn.bunny.dao.entity.schedulers.Schedulers;
import cn.bunny.dao.dto.quartz.SchedulersAddDto;
import cn.bunny.dao.dto.quartz.SchedulersDto;
import cn.bunny.dao.dto.quartz.SchedulersOperationDto;
import cn.bunny.dao.entity.quartz.Schedulers;
import cn.bunny.dao.pojo.result.PageResult;
import cn.bunny.dao.vo.schedulers.SchedulersVo;
import cn.bunny.dao.vo.quartz.SchedulersVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import jakarta.validation.Valid;

View File

@ -16,6 +16,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -68,12 +70,28 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements De
.build();
}
/**
* * 获取所有部门
*
* @return 所有部门列表
*/
@Override
@Cacheable(cacheNames = "dept", key = "'allDept'", cacheManager = "cacheManagerWithMouth")
public List<DeptVo> getAllDeptList() {
return list().stream().map(dept -> {
DeptVo deptVo = new DeptVo();
BeanUtils.copyProperties(dept, deptVo);
return deptVo;
}).toList();
}
/**
* 添加部门
*
* @param dto 部门添加
*/
@Override
@CacheEvict(cacheNames = "dept", key = "'allDept'", beforeInvocation = true)
public void addDept(DeptAddDto dto) {
// 整理管理者人员
String mangerList = dto.getManager().stream().map(String::trim).collect(Collectors.joining(","));
@ -92,6 +110,7 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements De
* @param dto 部门更新
*/
@Override
@CacheEvict(cacheNames = "dept", key = "'allDept'", beforeInvocation = true)
public void updateDept(DeptUpdateDto dto) {
// 判断所更新的部门是否存在
String mangerList = dto.getManager().stream().map(String::trim).collect(Collectors.joining(","));
@ -111,6 +130,7 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements De
* @param ids 删除id列表
*/
@Override
@CacheEvict(cacheNames = "dept", key = "'allDept'", beforeInvocation = true)
public void deleteDept(List<Long> ids) {
// 判断数据请求是否为空
if (ids.isEmpty()) throw new BunnyException(ResultCodeEnum.REQUEST_IS_EMPTY);
@ -122,17 +142,4 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements De
userDeptMapper.deleteBatchIdsByDeptIdWithPhysics(ids);
}
/**
* * 获取所有部门
*
* @return 所有部门列表
*/
@Override
public List<DeptVo> getAllDeptList() {
return list().stream().map(dept -> {
DeptVo deptVo = new DeptVo();
BeanUtils.copyProperties(dept, deptVo);
return deptVo;
}).toList();
}
}

View File

@ -19,6 +19,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.validation.Valid;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -49,6 +51,7 @@ public class I18nServiceImpl extends ServiceImpl<I18nMapper, I18n> implements I1
* @return 多语言返回内容
*/
@Override
@Cacheable(cacheNames = "i18n", key = "'i18n'", cacheManager = "cacheManagerWithMouth")
public HashMap<String, Object> getI18n() {
// 查找默认语言内容
I18nType i18nType = i18nTypeMapper.selectOne(Wrappers.<I18nType>lambdaQuery().eq(I18nType::getIsDefault, true));
@ -94,6 +97,7 @@ public class I18nServiceImpl extends ServiceImpl<I18nMapper, I18n> implements I1
* @param dto 添加表单
*/
@Override
@CacheEvict(cacheNames = "i18n", key = "'i18n'", beforeInvocation = true)
public void addI18n(@Valid I18nAddDto dto) {
String keyName = dto.getKeyName();
String typeName = dto.getTypeName();
@ -114,6 +118,7 @@ public class I18nServiceImpl extends ServiceImpl<I18nMapper, I18n> implements I1
* @param dto 更新表单
*/
@Override
@CacheEvict(cacheNames = "i18n", key = "'i18n'", beforeInvocation = true)
public void updateI18n(@Valid I18nUpdateDto dto) {
Long id = dto.getId();
@ -133,10 +138,11 @@ public class I18nServiceImpl extends ServiceImpl<I18nMapper, I18n> implements I1
* @param ids 删除id列表
*/
@Override
@CacheEvict(cacheNames = "i18n", key = "'i18n'", beforeInvocation = true)
public void deleteI18n(List<Long> ids) {
// 判断数据请求是否为空
if (ids.isEmpty()) throw new BunnyException(ResultCodeEnum.REQUEST_IS_EMPTY);
baseMapper.deleteBatchIdsWithPhysics(ids);
}
}

View File

@ -11,6 +11,8 @@ import cn.bunny.services.service.I18nTypeService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -34,6 +36,7 @@ public class I18nTypeServiceImpl extends ServiceImpl<I18nTypeMapper, I18nType> i
* @return 多语言类型列表
*/
@Override
@Cacheable(cacheNames = "i18n", key = "'i18nType'", cacheManager = "cacheManagerWithMouth")
public List<I18nTypeVo> getI18nTypeList() {
return list().stream().map(i18nType -> {
I18nTypeVo i18nTypeVo = new I18nTypeVo();
@ -48,6 +51,7 @@ public class I18nTypeServiceImpl extends ServiceImpl<I18nTypeMapper, I18nType> i
* @param dto 多语言类型添加
*/
@Override
@CacheEvict(cacheNames = "i18n", key = "'i18nType'", beforeInvocation = true)
public void addI18nType(I18nTypeAddDto dto) {
String typeName = dto.getTypeName();
Boolean isDefault = dto.getIsDefault();
@ -75,6 +79,7 @@ public class I18nTypeServiceImpl extends ServiceImpl<I18nTypeMapper, I18nType> i
* @param dto 多语言类型更新
*/
@Override
@CacheEvict(cacheNames = "i18n", key = "'i18nType'", beforeInvocation = true)
public void updateI18nType(I18nTypeUpdateDto dto) {
Long id = dto.getId();
Boolean isDefault = dto.getIsDefault();
@ -102,6 +107,7 @@ public class I18nTypeServiceImpl extends ServiceImpl<I18nTypeMapper, I18nType> i
* @param ids 删除id列表
*/
@Override
@CacheEvict(cacheNames = "i18n", key = "'i18nType'", beforeInvocation = true)
public void deleteI18nType(List<Long> ids) {
// 判断数据请求是否为空
if (ids.isEmpty()) throw new BunnyException(ResultCodeEnum.REQUEST_IS_EMPTY);

View File

@ -16,6 +16,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.validation.Valid;
import org.springframework.beans.BeanUtils;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
@ -59,45 +61,6 @@ public class MenuIconServiceImpl extends ServiceImpl<MenuIconMapper, MenuIcon> i
.build();
}
/**
* 添加系统菜单图标
*
* @param dto 系统菜单图标添加
*/
@Override
public void addMenuIcon(MenuIconAddDto dto) {
// 保存数据
MenuIcon menuIcon = new MenuIcon();
BeanUtils.copyProperties(dto, menuIcon);
save(menuIcon);
}
/**
* 更新系统菜单图标
*
* @param dto 系统菜单图标更新
*/
@Override
public void updateMenuIcon(@Valid MenuIconUpdateDto dto) {
// 更新内容
MenuIcon menuIcon = new MenuIcon();
BeanUtils.copyProperties(dto, menuIcon);
updateById(menuIcon);
}
/**
* 删除|批量删除系统菜单图标
*
* @param ids 删除id列表
*/
@Override
public void deleteMenuIcon(List<Long> ids) {
// 判断数据请求是否为空
if (ids.isEmpty()) throw new BunnyException(ResultCodeEnum.REQUEST_IS_EMPTY);
baseMapper.deleteBatchIdsWithPhysics(ids);
}
/**
* * 获取查询图标名称列表
*
@ -105,6 +68,7 @@ public class MenuIconServiceImpl extends ServiceImpl<MenuIconMapper, MenuIcon> i
* @return 图标返回列表
*/
@Override
@Cacheable(cacheNames = "menuIcon", key = "'menuIconList'", cacheManager = "cacheManagerWithMouth")
public List<MenuIconVo> getIconNameList(String iconName) {
return list(Wrappers.<MenuIcon>lambdaQuery().like(MenuIcon::getIconName, iconName))
.stream().map(menuIcon -> {
@ -120,4 +84,46 @@ public class MenuIconServiceImpl extends ServiceImpl<MenuIconMapper, MenuIcon> i
map -> new ArrayList<>(map.values())
));
}
/**
* 添加系统菜单图标
*
* @param dto 系统菜单图标添加
*/
@Override
@CacheEvict(cacheNames = "menuIcon", key = "'menuIconList'", beforeInvocation = true)
public void addMenuIcon(MenuIconAddDto dto) {
// 保存数据
MenuIcon menuIcon = new MenuIcon();
BeanUtils.copyProperties(dto, menuIcon);
save(menuIcon);
}
/**
* 更新系统菜单图标
*
* @param dto 系统菜单图标更新
*/
@Override
@CacheEvict(cacheNames = "menuIcon", key = "'menuIconList'", beforeInvocation = true)
public void updateMenuIcon(@Valid MenuIconUpdateDto dto) {
// 更新内容
MenuIcon menuIcon = new MenuIcon();
BeanUtils.copyProperties(dto, menuIcon);
updateById(menuIcon);
}
/**
* 删除|批量删除系统菜单图标
*
* @param ids 删除id列表
*/
@Override
@CacheEvict(cacheNames = "menuIcon", key = "'menuIconList'", beforeInvocation = true)
public void deleteMenuIcon(List<Long> ids) {
// 判断数据请求是否为空
if (ids.isEmpty()) throw new BunnyException(ResultCodeEnum.REQUEST_IS_EMPTY);
baseMapper.deleteBatchIdsWithPhysics(ids);
}
}

View File

@ -20,6 +20,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.validation.Valid;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -66,12 +68,29 @@ public class PowerServiceImpl extends ServiceImpl<PowerMapper, Power> implements
.build();
}
/**
* * 获取所有权限
*
* @return 所有权限列表
*/
@Override
@Cacheable(cacheNames = "power", key = "'allPower'", cacheManager = "cacheManagerWithMouth")
public List<PowerVo> getAllPowers() {
List<Power> powerList = list();
return powerList.stream().map(power -> {
PowerVo powerVo = new PowerVo();
BeanUtils.copyProperties(power, powerVo);
return powerVo;
}).toList();
}
/**
* 添加权限
*
* @param dto 权限添加
*/
@Override
@CacheEvict(cacheNames = "power", key = "'allPower'", beforeInvocation = true)
public void addPower(@Valid PowerAddDto dto) {
// 添加权限时确保权限码和请求地址是唯一的
LambdaQueryWrapper<Power> wrapper = new LambdaQueryWrapper<>();
@ -95,6 +114,7 @@ public class PowerServiceImpl extends ServiceImpl<PowerMapper, Power> implements
* @param dto 权限更新
*/
@Override
@CacheEvict(cacheNames = "power", key = "'allPower'", beforeInvocation = true)
public void updatePower(@Valid PowerUpdateDto dto) {
Long id = dto.getId();
List<Power> powerList = list(Wrappers.<Power>lambdaQuery().eq(Power::getId, id));
@ -113,6 +133,7 @@ public class PowerServiceImpl extends ServiceImpl<PowerMapper, Power> implements
* @param ids 删除id列表
*/
@Override
@CacheEvict(cacheNames = "power", key = "'allPower'", beforeInvocation = true)
public void deletePower(List<Long> ids) {
// 判断数据请求是否为空
if (ids.isEmpty()) throw new BunnyException(ResultCodeEnum.REQUEST_IS_EMPTY);
@ -124,27 +145,13 @@ public class PowerServiceImpl extends ServiceImpl<PowerMapper, Power> implements
rolePowerMapper.deleteBatchPowerIdsWithPhysics(ids);
}
/**
* * 获取所有权限
*
* @return 所有权限列表
*/
@Override
public List<PowerVo> getAllPowers() {
List<Power> powerList = list();
return powerList.stream().map(power -> {
PowerVo powerVo = new PowerVo();
BeanUtils.copyProperties(power, powerVo);
return powerVo;
}).toList();
}
/**
* * 批量修改权限父级
*
* @param dto 批量修改权限表单
*/
@Override
@CacheEvict(cacheNames = "power", key = "'allPower'", beforeInvocation = true)
public void updateBatchByPowerWithParentId(PowerUpdateBatchByParentIdDto dto) {
List<Power> powerList = dto.getIds().stream().map(id -> {
Power power = new Power();

View File

@ -20,6 +20,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.validation.Valid;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import java.util.List;
@ -71,12 +73,28 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
.build();
}
/**
* * 获取所有角色
*
* @return 所有角色列表
*/
@Override
@Cacheable(cacheNames = "role", key = "'allRole'", cacheManager = "cacheManagerWithMouth")
public List<RoleVo> getAllRoles() {
return list().stream().map(role -> {
RoleVo roleVo = new RoleVo();
BeanUtils.copyProperties(role, roleVo);
return roleVo;
}).toList();
}
/**
* 添加角色
*
* @param dto 角色添加
*/
@Override
@CacheEvict(cacheNames = "role", key = "'allRole'", beforeInvocation = true)
public void addRole(@Valid RoleAddDto dto) {
// 判断角色码是否被添加过
List<Role> roleList = list(Wrappers.<Role>lambdaQuery().eq(Role::getRoleCode, dto.getRoleCode()));
@ -94,6 +112,7 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
* @param dto 角色更新
*/
@Override
@CacheEvict(cacheNames = "role", key = "'allRole'", beforeInvocation = true)
public void updateRole(@Valid RoleUpdateDto dto) {
// 查询更新的角色是否存在
List<Role> roleList = list(Wrappers.<Role>lambdaQuery().eq(Role::getId, dto.getId()));
@ -111,6 +130,7 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
* @param ids 删除id列表
*/
@Override
@CacheEvict(cacheNames = "role", key = "'allRole'", beforeInvocation = true)
public void deleteRole(List<Long> ids) {
// 判断数据请求是否为空
if (ids.isEmpty()) throw new BunnyException(ResultCodeEnum.REQUEST_IS_EMPTY);
@ -128,18 +148,4 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
routerRoleMapper.deleteBatchIdsByRoleIdsWithPhysics(ids);
}
/**
* * 获取所有角色
*
* @return 所有角色列表
*/
@Override
public List<RoleVo> getAllRoles() {
return list().stream().map(role -> {
RoleVo roleVo = new RoleVo();
BeanUtils.copyProperties(role, roleVo);
return roleVo;
}).toList();
}
}

View File

@ -1,11 +1,11 @@
package cn.bunny.services.service.impl;
import cn.bunny.dao.dto.schedulers.SchedulersGroupAddDto;
import cn.bunny.dao.dto.schedulers.SchedulersGroupDto;
import cn.bunny.dao.dto.schedulers.SchedulersGroupUpdateDto;
import cn.bunny.dao.entity.schedulers.SchedulersGroup;
import cn.bunny.dao.dto.quartz.SchedulersGroupAddDto;
import cn.bunny.dao.dto.quartz.SchedulersGroupDto;
import cn.bunny.dao.dto.quartz.SchedulersGroupUpdateDto;
import cn.bunny.dao.entity.quartz.SchedulersGroup;
import cn.bunny.dao.pojo.result.PageResult;
import cn.bunny.dao.vo.schedulers.SchedulersGroupVo;
import cn.bunny.dao.vo.quartz.SchedulersGroupVo;
import cn.bunny.services.mapper.SchedulersGroupMapper;
import cn.bunny.services.service.SchedulersGroupService;
import com.baomidou.mybatisplus.core.metadata.IPage;
@ -13,6 +13,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.validation.Valid;
import org.springframework.beans.BeanUtils;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import java.util.List;
@ -54,12 +56,28 @@ public class SchedulersGroupServiceImpl extends ServiceImpl<SchedulersGroupMappe
.build();
}
/**
* * 获取所有任务调度分组
*
* @return 获取所有任务分组
*/
@Override
@Cacheable(cacheNames = "schedulers", key = "'allSchedulersGroup'", cacheManager = "cacheManagerWithMouth")
public List<SchedulersGroupVo> getAllSchedulersGroup() {
return list().stream().map(schedulersGroup -> {
SchedulersGroupVo schedulersGroupVo = new SchedulersGroupVo();
BeanUtils.copyProperties(schedulersGroup, schedulersGroupVo);
return schedulersGroupVo;
}).toList();
}
/**
* 添加任务调度分组
*
* @param dto 任务调度分组添加
*/
@Override
@CacheEvict(cacheNames = "schedulers", key = "'allSchedulersGroup'", beforeInvocation = true)
public void addSchedulersGroup(@Valid SchedulersGroupAddDto dto) {
// 保存数据
SchedulersGroup schedulersGroup = new SchedulersGroup();
@ -73,6 +91,7 @@ public class SchedulersGroupServiceImpl extends ServiceImpl<SchedulersGroupMappe
* @param dto 任务调度分组更新
*/
@Override
@CacheEvict(cacheNames = "schedulers", key = "'allSchedulersGroup'", beforeInvocation = true)
public void updateSchedulersGroup(@Valid SchedulersGroupUpdateDto dto) {
// 更新内容
SchedulersGroup schedulersGroup = new SchedulersGroup();
@ -86,21 +105,8 @@ public class SchedulersGroupServiceImpl extends ServiceImpl<SchedulersGroupMappe
* @param ids 删除id列表
*/
@Override
@CacheEvict(cacheNames = "schedulers", key = "'allSchedulersGroup'", beforeInvocation = true)
public void deleteSchedulersGroup(List<Long> ids) {
baseMapper.deleteBatchIdsWithPhysics(ids);
}
/**
* * 获取所有任务调度分组
*
* @return 获取所有任务分组
*/
@Override
public List<SchedulersGroupVo> getAllSchedulersGroup() {
return list().stream().map(schedulersGroup -> {
SchedulersGroupVo schedulersGroupVo = new SchedulersGroupVo();
BeanUtils.copyProperties(schedulersGroup, schedulersGroupVo);
return schedulersGroupVo;
}).toList();
}
}

View File

@ -1,12 +1,12 @@
package cn.bunny.services.service.impl;
import cn.bunny.common.service.exception.BunnyException;
import cn.bunny.dao.dto.schedulers.SchedulersAddDto;
import cn.bunny.dao.dto.schedulers.SchedulersDto;
import cn.bunny.dao.dto.schedulers.SchedulersOperationDto;
import cn.bunny.dao.entity.schedulers.Schedulers;
import cn.bunny.dao.dto.quartz.SchedulersAddDto;
import cn.bunny.dao.dto.quartz.SchedulersDto;
import cn.bunny.dao.dto.quartz.SchedulersOperationDto;
import cn.bunny.dao.entity.quartz.Schedulers;
import cn.bunny.dao.pojo.result.PageResult;
import cn.bunny.dao.vo.schedulers.SchedulersVo;
import cn.bunny.dao.vo.quartz.SchedulersVo;
import cn.bunny.services.aop.AnnotationScanner;
import cn.bunny.services.aop.annotation.QuartzSchedulers;
import cn.bunny.services.mapper.SchedulersMapper;
@ -18,6 +18,8 @@ import jakarta.validation.Valid;
import org.quartz.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import java.util.HashMap;
@ -68,6 +70,29 @@ public class SchedulersServiceImpl extends ServiceImpl<SchedulersMapper, Schedul
.build();
}
/**
* * 获取所有可用调度任务
*
* @return 所有调度任务内容
*/
@Override
@Cacheable(cacheNames = "schedulers", key = "'allSchedulers'", cacheManager = "cacheManagerWithMouth")
public List<Map<String, String>> getAllScheduleJobList() {
Set<Class<?>> classesWithAnnotation = annotationScanner.getClassesWithAnnotation(QuartzSchedulers.class);
return classesWithAnnotation.stream().map(cls -> {
Map<String, String> hashMap = new HashMap<>();
// 调度器引用路径
String classReference = cls.getName();
// 调度器详情
String description = cls.getAnnotation(QuartzSchedulers.class).description();
hashMap.put("value", classReference);
hashMap.put("label", description);
return hashMap;
}).toList();
}
/**
* 添加Schedulers视图
*
@ -75,6 +100,7 @@ public class SchedulersServiceImpl extends ServiceImpl<SchedulersMapper, Schedul
*/
@SuppressWarnings("unchecked")
@Override
@CacheEvict(cacheNames = "schedulers", key = "'allSchedulers'", beforeInvocation = true)
public void addSchedulers(@Valid SchedulersAddDto dto) {
try {
// 动态创建Class对象
@ -139,6 +165,7 @@ public class SchedulersServiceImpl extends ServiceImpl<SchedulersMapper, Schedul
* @param dto Schedulers公共操作表单
*/
@Override
@CacheEvict(cacheNames = "schedulers", key = "'allSchedulers'", beforeInvocation = true)
public void deleteSchedulers(SchedulersOperationDto dto) {
try {
String jobGroup = dto.getJobGroup();
@ -152,26 +179,4 @@ public class SchedulersServiceImpl extends ServiceImpl<SchedulersMapper, Schedul
throw new BunnyException(exception.getMessage());
}
}
/**
* * 获取所有可用调度任务
*
* @return 所有调度任务内容
*/
@Override
public List<Map<String, String>> getAllScheduleJobList() {
Set<Class<?>> classesWithAnnotation = annotationScanner.getClassesWithAnnotation(QuartzSchedulers.class);
return classesWithAnnotation.stream().map(cls -> {
Map<String, String> hashMap = new HashMap<>();
// 调度器引用路径
String classReference = cls.getName();
// 调度器详情
String description = cls.getAnnotation(QuartzSchedulers.class).description();
hashMap.put("value", classReference);
hashMap.put("label", description);
return hashMap;
}).toList();
}
}

View File

@ -3,15 +3,15 @@
<mapper namespace="cn.bunny.services.mapper.SchedulersGroupMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="cn.bunny.dao.entity.schedulers.SchedulersGroup">
<id column="id" property="id"/>
<id column="create_time" property="createTime"/>
<id column="update_time" property="updateTime"/>
<id column="create_user" property="createUser"/>
<id column="update_user" property="updateUser"/>
<id column="is_deleted" property="isDeleted"/>
<id column="group_name" property="groupName"/>
<id column="description" property="description"/>
<resultMap id="BaseResultMap" type="cn.bunny.dao.entity.quartz.SchedulersGroup">
<id column="id" property="id"/>
<id column="create_time" property="createTime"/>
<id column="update_time" property="updateTime"/>
<id column="create_user" property="createUser"/>
<id column="update_user" property="updateUser"/>
<id column="is_deleted" property="isDeleted"/>
<id column="group_name" property="groupName"/>
<id column="description" property="description"/>
</resultMap>
<!-- 通用查询结果列 -->
@ -20,17 +20,17 @@
</sql>
<!-- 分页查询任务调度分组内容 -->
<select id="selectListByPage" resultType="cn.bunny.dao.entity.schedulers.SchedulersGroup">
<select id="selectListByPage" resultType="cn.bunny.dao.entity.quartz.SchedulersGroup">
select
<include refid="Base_Column_List"/>
from sys_schedulers_group
from qrtz_schedulers_group
<where>
<if test="dto.groupName != null and dto.groupName != ''">
and group_name like CONCAT('%',#{dto.groupName},'%')
</if>
<if test="dto.description != null and dto.description != ''">
and description like CONCAT('%',#{dto.description},'%')
</if>
<if test="dto.groupName != null and dto.groupName != ''">
and group_name like CONCAT('%',#{dto.groupName},'%')
</if>
<if test="dto.description != null and dto.description != ''">
and description like CONCAT('%',#{dto.description},'%')
</if>
</where>
order by update_time desc
</select>

View File

@ -3,7 +3,7 @@
<mapper namespace="cn.bunny.services.mapper.SchedulersMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="cn.bunny.dao.entity.schedulers.Schedulers">
<resultMap id="BaseResultMap" type="cn.bunny.dao.entity.quartz.Schedulers">
<id column="job_name" property="jobName"/>
<id column="job_group" property="jobGroup"/>
<id column="description" property="description"/>
@ -19,10 +19,10 @@
</sql>
<!-- 分页查询Schedulers视图内容 -->
<select id="selectListByPage" resultType="cn.bunny.dao.entity.schedulers.Schedulers">
<select id="selectListByPage" resultType="cn.bunny.dao.entity.quartz.Schedulers">
select
<include refid="Base_Column_List"/>
from qrtz_view_schedulers
from view_qrtz_schedulers
<where>
<if test="dto.jobName != null and dto.jobName != ''">
and job_name like CONCAT('%',#{dto.jobName},'%')