diff --git a/pom.xml b/pom.xml index d994f01..cc48dae 100644 --- a/pom.xml +++ b/pom.xml @@ -38,6 +38,12 @@ + + + org.springframework.boot + spring-boot-starter-cache + + org.springframework.boot spring-boot-starter-web diff --git a/src/main/java/com/huoran/iasf/common/config/MyBatisPlusConfig.java b/src/main/java/com/huoran/iasf/common/config/MyBatisPlusConfig.java index 59f8ea8..8ee5f4b 100644 --- a/src/main/java/com/huoran/iasf/common/config/MyBatisPlusConfig.java +++ b/src/main/java/com/huoran/iasf/common/config/MyBatisPlusConfig.java @@ -18,6 +18,8 @@ public class MyBatisPlusConfig { */ @Bean public PaginationInterceptor paginationInterceptor() { - return new PaginationInterceptor(); + PaginationInterceptor page = new PaginationInterceptor(); + page.setDialectType("mysql"); + return page; } } \ No newline at end of file diff --git a/src/main/java/com/huoran/iasf/common/config/MyCacheConfig.java b/src/main/java/com/huoran/iasf/common/config/MyCacheConfig.java new file mode 100644 index 0000000..42a0ce8 --- /dev/null +++ b/src/main/java/com/huoran/iasf/common/config/MyCacheConfig.java @@ -0,0 +1,48 @@ +package com.huoran.iasf.common.config; + +import org.springframework.boot.autoconfigure.cache.CacheProperties; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.cache.annotation.EnableCaching; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.cache.RedisCacheConfiguration; +import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; +import org.springframework.data.redis.serializer.RedisSerializationContext; +import org.springframework.data.redis.serializer.StringRedisSerializer; + +/** + * @Author chen + * @DATE 2021/12/28 10:42 + * @Version 1.0 + */ +@EnableConfigurationProperties(CacheProperties.class) +@Configuration +@EnableCaching +public class MyCacheConfig { + + @Bean + RedisCacheConfiguration redisCacheConfiguration(CacheProperties cacheProperties){ + RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig(); + //修改缓存key、value的序列化机制,返回json数据格式 + config.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer())); + config.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer())); + //读取redis配置文件 + CacheProperties.Redis redisProperties = cacheProperties.getRedis(); + if (redisProperties.getTimeToLive() != null) { + config = config.entryTtl(redisProperties.getTimeToLive()); + } + + if (redisProperties.getKeyPrefix() != null) { + config = config.prefixKeysWith(redisProperties.getKeyPrefix()); + } + + if (!redisProperties.isCacheNullValues()) { + config = config.disableCachingNullValues(); + } + + if (!redisProperties.isUseKeyPrefix()) { + config = config.disableKeyPrefix(); + } + return config; + } +} diff --git a/src/main/java/com/huoran/iasf/common/config/MyThreadConfig.java b/src/main/java/com/huoran/iasf/common/config/MyThreadConfig.java new file mode 100644 index 0000000..a68425b --- /dev/null +++ b/src/main/java/com/huoran/iasf/common/config/MyThreadConfig.java @@ -0,0 +1,29 @@ +package com.huoran.iasf.common.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.concurrent.Executors; +import java.util.concurrent.LinkedBlockingDeque; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +/** + * @Author chen + * @DATE 2021/12/28 17:48 + * @Version 1.0 + */ +@Configuration +public class MyThreadConfig { + + @Bean + public ThreadPoolExecutor threadPoolExecutor(){ + return new ThreadPoolExecutor(20, + 300, + 10, + TimeUnit.SECONDS, + new LinkedBlockingDeque<>(), + Executors.defaultThreadFactory(), + new ThreadPoolExecutor.AbortPolicy()); + } +} diff --git a/src/main/java/com/huoran/iasf/controller/PermissionController.java b/src/main/java/com/huoran/iasf/controller/PermissionController.java index af4bf09..50adb8e 100644 --- a/src/main/java/com/huoran/iasf/controller/PermissionController.java +++ b/src/main/java/com/huoran/iasf/controller/PermissionController.java @@ -14,7 +14,6 @@ import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; -import javax.validation.Valid; /** * 菜单权限管理 @@ -31,7 +30,7 @@ public class PermissionController { @Resource private PermissionService permissionService; - @PostMapping("/permission") +/* @PostMapping("/permission") @ApiOperation(value = "新增菜单权限接口") @LogAnnotation(title = "菜单权限管理", action = "新增菜单权限") @RequiresPermissions("sys:permission:add") @@ -40,59 +39,15 @@ public class PermissionController { vo.setStatus(1); permissionService.save(vo); return R.success(); - } + }*/ - @DeleteMapping("/permission/{id}") +/* @DeleteMapping("/permission/{id}") @ApiOperation(value = "删除菜单权限接口") @LogAnnotation(title = "菜单权限管理", action = "删除菜单权限") @RequiresPermissions("sys:permission:deleted") public R deleted(@PathVariable("id") String id) { permissionService.deleted(id); return R.success(); - } - -/* @PutMapping("/permission") - @ApiOperation(value = "更新菜单权限接口") - @LogAnnotation(title = "菜单权限管理", action = "更新菜单权限") - @RequiresPermissions("sys:permission:update") - public R updatePermission(@RequestBody @Valid SysPermission vo) { - if (StringUtils.isEmpty(vo.getId())) { - return R.fail("id不能为空"); - } - SysPermission sysPermission = permissionService.getById(vo.getId()); - if (null == sysPermission) { - throw new BusinessException(BaseResponseCode.DATA_ERROR); - } - // 只有类型变更或者所属菜单变更 - if (sysPermission.getType().equals(vo.getType()) || !sysPermission.getPid().equals(vo.getPid())) { - verifyFormPid(vo); - } - permissionService.updatePermission(vo); - return R.success(); - }*/ - -/* @GetMapping("/permission/{id}") - @ApiOperation(value = "查询菜单权限接口") - @LogAnnotation(title = "菜单权限管理", action = "查询菜单权限") - @RequiresPermissions("sys:permission:detail") - public R detailInfo(@PathVariable("id") String id) { - return R.success(permissionService.getById(id)); - }*/ - - /*@GetMapping("/permissions") - @ApiOperation(value = "获取所有菜单权限接口") - @LogAnnotation(title = "菜单权限管理", action = "获取所有菜单权限") - @RequiresPermissions("sys:permission:list") - public R getAllMenusPermission() { - return R.success(permissionService.selectAll()); - }*/ - -/* @GetMapping("/permission/tree") - @ApiOperation(value = "获取所有目录菜单树接口") - @LogAnnotation(title = "菜单权限管理", action = "获取所有目录菜单树") - @RequiresPermissions(value = {"sys:permission:update", "sys:permission:add"}, logical = Logical.OR) - public R getAllMenusPermissionTree(@RequestParam(required = false) String permissionId) { - return R.success(permissionService.selectAllMenuByTree(permissionId)); }*/ @GetMapping("/permission/tree/all") diff --git a/src/main/java/com/huoran/iasf/service/impl/DeptServiceImpl.java b/src/main/java/com/huoran/iasf/service/impl/DeptServiceImpl.java index 59de614..42496f2 100644 --- a/src/main/java/com/huoran/iasf/service/impl/DeptServiceImpl.java +++ b/src/main/java/com/huoran/iasf/service/impl/DeptServiceImpl.java @@ -89,7 +89,7 @@ public class DeptServiceImpl extends ServiceImpl impleme if (!"0".equals(vo.getPid()) && null == parent) { throw new BusinessException(BaseResponseCode.DATA_ERROR); } - SysDept oldParent = sysDeptMapper.selectById(sysDept.getPid()); + /*SysDept oldParent = sysDeptMapper.selectById(sysDept.getPid()); String oldRelationCode; String newRelationCode; //根目录降到其他目录 @@ -102,15 +102,15 @@ public class DeptServiceImpl extends ServiceImpl impleme } else { oldRelationCode = oldParent.getRelationCode(); newRelationCode = parent.getRelationCode(); - } - LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); + }*/ + /*LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(); wrapper.likeLeft(SysDept::getDeptNo, sysDept.getDeptNo()); List list = sysDeptMapper.selectList(wrapper); list.parallelStream().forEach(entity -> { String relationCode = entity.getRelationCode().replace(oldRelationCode, newRelationCode); entity.setRelationCode(relationCode); sysDeptMapper.updateById(entity); - }); + });*/ } } diff --git a/src/main/java/com/huoran/iasf/service/impl/PermissionServiceImpl.java b/src/main/java/com/huoran/iasf/service/impl/PermissionServiceImpl.java index 7bdcee7..a2c55c7 100644 --- a/src/main/java/com/huoran/iasf/service/impl/PermissionServiceImpl.java +++ b/src/main/java/com/huoran/iasf/service/impl/PermissionServiceImpl.java @@ -18,6 +18,7 @@ import com.huoran.iasf.service.UserRoleService; import com.huoran.iasf.vo.resp.PermissionRespNode; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; +import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; @@ -106,7 +107,7 @@ public class PermissionServiceImpl extends ServiceImpl userRoles = userRoleService.list(queryWrapper); String roleIds = ""; - if (ObjectUtil.isNotNull(userRoles)){ + if (ObjectUtil.isNotNull(userRoles)&& userRoles.size()>0){ for (SysUserRole userRole: userRoles) { roleIds += userRole.getRoleId() +","; } @@ -236,11 +237,8 @@ public class PermissionServiceImpl extends ServiceImpl selectAllByTree() { - - // List list = selectAll(); - // return getTree(list, false); - List permissionList = baseMapper.selectList(null); return build(permissionList); } diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 3208f92..b7539ed 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -6,18 +6,11 @@ spring: datasource: master: username: root - password: HuoRan@2021 + password: 123456 driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://139.9.47.170:3306/iasf?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=GMT%2b8 -# hikari: -# connection-timeout: 60000 -# validation-timeout: 3000 -# idle-timeout: 60000 -# login-timeout: 5 -# max-lifetime: 60000 -# maximum-pool-size: 10 -# minimum-idle: 10 -# read-only: false + url: jdbc:mysql://127.0.0.1:3306/iasf?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=GMT%2b8 + cache: + type: redis redis: host: localhost # Redis服务器地址 database: 0 # Redis数据库索引(默认为0) @@ -29,11 +22,15 @@ spring: max-wait: -1ms # 连接池最大阻塞等待时间(使用负值表示没有限制) max-idle: 8 # 连接池中的最大空闲连接 min-idle: 0 # 连接池中的最小空闲连接 - timeout: 3000ms # 连接超时时间(毫秒 + timeout: 3000ms # 连接超时时间(毫秒) + +singleServerConfig: + address: "redis://127.0.0.1:6379" + password: file: #文件上传目录 绝对路径 末尾请加 / - path: D:/files/ #windows + path: C:/files/ #windows #path: /data/files/ #linux #文件预览url url: :10000/iasf/sysFiles/preview/