jpa fetch -> load

This commit is contained in:
administrator 2020-09-25 17:20:58 +08:00
parent 0da00b9837
commit 0dfbee487a
23 changed files with 136 additions and 26 deletions

13
pom.xml
View File

@ -28,8 +28,9 @@
<commons.fileupload.version>1.3.3</commons.fileupload.version> <commons.fileupload.version>1.3.3</commons.fileupload.version>
<poi.version>3.17</poi.version> <poi.version>3.17</poi.version>
<velocity.version>1.7</velocity.version> <velocity.version>1.7</velocity.version>
<querydsl.version>4.2.1</querydsl.version> <querydsl.version>4.4.0</querydsl.version>
<jaxb.version>2.3.0.1</jaxb.version> <jaxb.version>2.3.0.1</jaxb.version>
<jna.version>5.6.0</jna.version>
</properties> </properties>
<!-- 依赖声明 --> <!-- 依赖声明 -->
@ -40,7 +41,15 @@
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId> <artifactId>spring-boot-dependencies</artifactId>
<version>2.1.1.RELEASE</version> <version>2.3.4.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava-bom</artifactId>
<version>29.0-jre</version>
<type>pom</type> <type>pom</type>
<scope>import</scope> <scope>import</scope>
</dependency> </dependency>

View File

@ -88,7 +88,7 @@
<dependency> <dependency>
<groupId>com.fasterxml.jackson.datatype</groupId> <groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-hibernate5</artifactId> <artifactId>jackson-datatype-hibernate5</artifactId>
<version>2.10.1</version> <version>2.11.2</version>
</dependency> </dependency>
<dependency> <dependency>
@ -120,6 +120,11 @@
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -3,6 +3,7 @@ package com.ruoyi;
import org.springframework.boot.CommandLineRunner; import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@ -13,7 +14,7 @@ import org.springframework.context.annotation.Bean;
* *
* @author ruoyi * @author ruoyi
*/ */
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, CacheAutoConfiguration.class})
public class RuoYiApplication extends SpringBootServletInitializer { public class RuoYiApplication extends SpringBootServletInitializer {
public static void main(String[] args) { public static void main(String[] args) {
// System.setProperty("spring.devtools.restart.enabled", "false"); // System.setProperty("spring.devtools.restart.enabled", "false");

View File

@ -69,15 +69,30 @@ spring:
use-new-id-generator-mappings: true use-new-id-generator-mappings: true
show-sql: true show-sql: true
database-platform: org.hibernate.dialect.MySQL55Dialect database-platform: org.hibernate.dialect.MySQL55Dialect
open-in-view: false
properties: properties:
hibernate: hibernate:
format_sql: false format_sql: false
open-in-view: false
cache: cache:
type: jcache type: redis
jcache: redis:
provider: org.ehcache.jsr107.EhcacheCachingProvider use-key-prefix: true
cache-null-values: true
key-prefix: ${spring.application.name}
redis:
database: 2
host: localhost
port: 6379
ssl: false
timeout: 3000
password:
lettuce:
pool:
max-active: 8
max-idle: 8
min-idle: 2
max-wait: -1
# Shiro # Shiro
shiro: shiro:
user: user:
@ -127,3 +142,14 @@ xss:
swagger: swagger:
# 是否开启swagger # 是否开启swagger
enabled: true enabled: true
cache:
names:
sys_dict_type:
ttl: PT1M
sys_user:
ttl: PT1M
sys_post:
ttl: PT1M
sys_role:
ttl: PT1M

View File

@ -0,0 +1,8 @@
package com.ruoyi;
public class Tesst {
public static void main(String[] args) {
System.out.println(System.getProperty("java.io.tmpdir"));
}
}

View File

@ -123,6 +123,20 @@
<artifactId>spring-boot-configuration-processor</artifactId> <artifactId>spring-boot-configuration-processor</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -1,5 +1,8 @@
package com.ruoyi.common.base; package com.ruoyi.common.base;
import com.querydsl.core.types.Constant;
import com.querydsl.core.types.Expression;
import com.querydsl.core.types.Predicate;
import com.querydsl.core.types.dsl.*; import com.querydsl.core.types.dsl.*;
import com.ruoyi.common.core.text.Convert; import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.querydsl.ExpressionUtils; import com.ruoyi.common.utils.querydsl.ExpressionUtils;
@ -39,6 +42,11 @@ public class BaseService {
return ExpressionUtils.notStartWith(path, value); return ExpressionUtils.notStartWith(path, value);
} }
protected Predicate alwaysTrue(){
Constant<Boolean> expression = (Constant<Boolean>) com.querydsl.core.types.ExpressionUtils.toExpression(Boolean.TRUE);
return com.querydsl.core.types.ExpressionUtils.eqConst(expression, true);
}
public static Collection<Long> toLongIterable(String str){ public static Collection<Long> toLongIterable(String str){
return Arrays.stream(Convert.toStrArray(str)) return Arrays.stream(Convert.toStrArray(str))
.map(Long::parseLong) .map(Long::parseLong)

View File

@ -1,6 +1,8 @@
package com.ruoyi.common.properties; package com.ruoyi.common.properties;
import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString; import lombok.ToString;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -17,8 +19,12 @@ public class CacheProperties {
private Map<String, Config> names = new HashMap<>(); private Map<String, Config> names = new HashMap<>();
private Config defaultConfig = new Config(Duration.ofMinutes(1));
@ToString @ToString
@Data @Data
@AllArgsConstructor
@NoArgsConstructor
public static class Config{ public static class Config{
private Duration ttl; private Duration ttl;
} }

View File

@ -75,11 +75,13 @@
<dependency> <dependency>
<groupId>net.java.dev.jna</groupId> <groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId> <artifactId>jna</artifactId>
<version>${jna.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.java.dev.jna</groupId> <groupId>net.java.dev.jna</groupId>
<artifactId>jna-platform</artifactId> <artifactId>jna-platform</artifactId>
<version>${jna.version}</version>
</dependency> </dependency>
<!-- 系统模块--> <!-- 系统模块-->

View File

@ -8,11 +8,12 @@ import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.ruoyi.common.properties.CacheProperties; import com.ruoyi.common.properties.CacheProperties;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.cache.CacheManager; import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.data.redis.cache.RedisCacheConfiguration; import org.springframework.data.redis.cache.RedisCacheConfiguration;
import org.springframework.data.redis.cache.RedisCacheManager; import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.cache.RedisCacheWriter; import org.springframework.data.redis.cache.RedisCacheWriter;
@ -23,10 +24,9 @@ import org.springframework.data.redis.serializer.RedisSerializationContext;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ConditionalOnClass(name = "org.springframework.data.redis.connection.RedisConnectionFactory")
@EnableCaching @EnableCaching
@Configuration @Configuration
@AutoConfigureAfter(CacheProperties.class) @Order(Ordered.HIGHEST_PRECEDENCE)
public class CacheConfig { public class CacheConfig {
@Autowired @Autowired
@ -43,6 +43,11 @@ public class CacheConfig {
@Bean @Bean
public CacheManager cacheManager() { public CacheManager cacheManager() {
RedisCacheConfiguration defaultConfiguration = RedisCacheConfiguration.defaultCacheConfig()
.disableCachingNullValues()
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(genericJackson2JsonRedisSerializer))
.entryTtl(cacheProperties.getDefaultConfig().getTtl());
Map<String, RedisCacheConfiguration> configurationMap = new HashMap<>(); Map<String, RedisCacheConfiguration> configurationMap = new HashMap<>();
for(String key : cacheProperties.getNames().keySet()){ for(String key : cacheProperties.getNames().keySet()){
configurationMap.put(key, RedisCacheConfiguration.defaultCacheConfig() configurationMap.put(key, RedisCacheConfiguration.defaultCacheConfig()
@ -53,6 +58,7 @@ public class CacheConfig {
return RedisCacheManager.builder(factory) return RedisCacheManager.builder(factory)
.initialCacheNames(cacheProperties.getNames().keySet()) .initialCacheNames(cacheProperties.getNames().keySet())
.withInitialCacheConfigurations(configurationMap) .withInitialCacheConfigurations(configurationMap)
.cacheDefaults(defaultConfiguration)
.build(); .build();
} }
@ -66,4 +72,4 @@ public class CacheConfig {
objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY); objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL, JsonTypeInfo.As.PROPERTY);
return new GenericJackson2JsonRedisSerializer(objectMapper); return new GenericJackson2JsonRedisSerializer(objectMapper);
} }
} }

View File

@ -26,7 +26,7 @@ public class MyJCacheRegionFactory extends JCacheRegionFactory {
final CachingProvider cachingProvider = getCachingProvider( properties ); final CachingProvider cachingProvider = getCachingProvider( properties );
final CacheManager cacheManager; final CacheManager cacheManager;
final URI cacheManagerUri = getUri( properties ); final URI cacheManagerUri = getUri( settings, properties);
// ***** begin patch ****** // ***** begin patch ******
URI uri = cacheManagerUri; URI uri = cacheManagerUri;
URL url = null; URL url = null;

View File

@ -66,6 +66,7 @@ public class SysJobServiceImpl extends BaseService implements ISysJobService {
private Predicate getPredicate(SysJob job){ private Predicate getPredicate(SysJob job){
QSysJob qSysJob = QSysJob.sysJob; QSysJob qSysJob = QSysJob.sysJob;
List<Predicate> predicates = new ArrayList<>(); List<Predicate> predicates = new ArrayList<>();
predicates.add(alwaysTrue());
if(StringUtils.isNotEmpty(job.getJobName())){ if(StringUtils.isNotEmpty(job.getJobName())){
predicates.add(buildLike(qSysJob.jobName, job.getJobName())); predicates.add(buildLike(qSysJob.jobName, job.getJobName()));
} }

View File

@ -125,7 +125,7 @@ public class SysUser extends BaseEntity implements Principal {
@Excel(name = "部门名称", targetAttr = "deptName", type = Type.EXPORT), @Excel(name = "部门名称", targetAttr = "deptName", type = Type.EXPORT),
@Excel(name = "部门负责人", targetAttr = "leader", type = Type.EXPORT) @Excel(name = "部门负责人", targetAttr = "leader", type = Type.EXPORT)
}) })
@ManyToOne @ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "dept_id", referencedColumnName = "deptId") @JoinColumn(name = "dept_id", referencedColumnName = "deptId")
@ForeignKey(name = "none") @ForeignKey(name = "none")
private SysDept dept; private SysDept dept;
@ -144,8 +144,6 @@ public class SysUser extends BaseEntity implements Principal {
@org.hibernate.annotations.ForeignKey(name = "none") @org.hibernate.annotations.ForeignKey(name = "none")
private Set<SysPost> posts = new HashSet<>(); private Set<SysPost> posts = new HashSet<>();
public SysUser() { public SysUser() {
} }

View File

@ -21,6 +21,6 @@ public interface SysRoleRepository extends BaseRepository<SysRole, Long> {
@Modifying @Modifying
void updateStatus(String status, Long roleId); void updateStatus(String status, Long roleId);
@EntityGraph(attributePaths = {"depts", "menus"}) @EntityGraph(attributePaths = {"depts", "menus"}, type = EntityGraph.EntityGraphType.LOAD )
SysRole findByRoleId(Long roleId); SysRole findByRoleId(Long roleId);
} }

View File

@ -13,31 +13,31 @@ import org.springframework.stereotype.Repository;
@Repository @Repository
public interface SysUserRepository extends BaseRepository<SysUser, Long> { public interface SysUserRepository extends BaseRepository<SysUser, Long> {
@EntityGraph(attributePaths = {"roles", "posts"}) @EntityGraph(attributePaths = {"roles", "posts"}, type= EntityGraph.EntityGraphType.LOAD )
SysUser findFirstByDelFlagAndLoginName(String delFlag, String loginName); SysUser findFirstByDelFlagAndLoginName(String delFlag, String loginName);
@EntityGraph(attributePaths = {"roles", "posts"}) @EntityGraph(attributePaths = {"roles", "posts"}, type= EntityGraph.EntityGraphType.LOAD)
SysUser findFirstByDelFlagAndAndPhonenumber(String delFlag, String phone); SysUser findFirstByDelFlagAndPhonenumber(String delFlag, String phone);
@EntityGraph(attributePaths = {"roles", "posts"}) @EntityGraph(attributePaths = {"roles", "posts"}, type= EntityGraph.EntityGraphType.LOAD)
SysUser findFirstByDelFlagAndEmail(String delFlag, String email); SysUser findFirstByDelFlagAndEmail(String delFlag, String email);
int countByDelFlagAndDept(String delFlag, SysDept dept); int countByDelFlagAndDept(String delFlag, SysDept dept);
int countByDelFlagAndPostsContaining(String delFlag, SysPost sysPost); int countByDelFlagAndPostsContaining(String delFlag, SysPost sysPost);
@EntityGraph(attributePaths = {"roles", "posts"}) @EntityGraph(attributePaths = {"roles", "posts"}, type= EntityGraph.EntityGraphType.LOAD)
SysUser findSysUserByDelFlagAndUserId(String delFlag, Long userId); SysUser findSysUserByDelFlagAndUserId(String delFlag, Long userId);
int countByLoginName(String loginName); int countByLoginName(String loginName);
@EntityGraph(attributePaths = {"roles", "posts"}) @EntityGraph(attributePaths = {"roles", "posts"}, type= EntityGraph.EntityGraphType.LOAD)
SysUser findFirstByPhonenumber(String phone); SysUser findFirstByPhonenumber(String phone);
@EntityGraph(attributePaths = {"roles", "posts"}) @EntityGraph(attributePaths = {"roles", "posts"}, type= EntityGraph.EntityGraphType.LOAD)
SysUser findFirstByEmail(String email); SysUser findFirstByEmail(String email);
@EntityGraph(attributePaths = {"roles", "posts"}) @EntityGraph(attributePaths = {"roles", "posts"}, type= EntityGraph.EntityGraphType.LOAD)
SysUser findFirstByLoginName(String loginName); SysUser findFirstByLoginName(String loginName);
@Modifying @Modifying

View File

@ -68,6 +68,7 @@ public class SysConfigServiceImpl extends BaseService implements ISysConfigServi
private Predicate getPredicate(SysConfig config){ private Predicate getPredicate(SysConfig config){
QSysConfig qSysConfig = QSysConfig.sysConfig; QSysConfig qSysConfig = QSysConfig.sysConfig;
List<Predicate> predicates = new ArrayList<>(); List<Predicate> predicates = new ArrayList<>();
predicates.add(alwaysTrue());
if(StringUtils.isNotEmpty(config.getConfigName())){ if(StringUtils.isNotEmpty(config.getConfigName())){
predicates.add(buildLike(qSysConfig.configName, config.getConfigName())); predicates.add(buildLike(qSysConfig.configName, config.getConfigName()));
} }

View File

@ -13,8 +13,11 @@ import com.ruoyi.system.domain.SysDictType;
import com.ruoyi.system.repository.SysDictDataRepository; import com.ruoyi.system.repository.SysDictDataRepository;
import com.ruoyi.system.repository.SysDictTypeRepository; import com.ruoyi.system.repository.SysDictTypeRepository;
import com.ruoyi.system.service.ISysDictTypeService; import com.ruoyi.system.service.ISysDictTypeService;
import org.hibernate.query.criteria.internal.predicate.BooleanExpressionPredicate;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -29,6 +32,7 @@ import java.util.List;
* @author ruoyi * @author ruoyi
*/ */
@Service @Service
@CacheConfig(cacheNames = "sys_dict_type")
public class SysDictTypeServiceImpl extends BaseService implements ISysDictTypeService { public class SysDictTypeServiceImpl extends BaseService implements ISysDictTypeService {
@Autowired @Autowired
private SysDictTypeRepository sysDictTypeRepository; private SysDictTypeRepository sysDictTypeRepository;
@ -41,6 +45,7 @@ public class SysDictTypeServiceImpl extends BaseService implements ISysDictTypeS
* @param dictType 字典类型信息 * @param dictType 字典类型信息
* @return 字典类型集合信息 * @return 字典类型集合信息
*/ */
@Cacheable
@Override @Override
public Page<SysDictType> selectDictTypeList(SysDictType dictType, Pageable pageable) { public Page<SysDictType> selectDictTypeList(SysDictType dictType, Pageable pageable) {
return sysDictTypeRepository.findAll(getPredicate(dictType), pageable); return sysDictTypeRepository.findAll(getPredicate(dictType), pageable);
@ -49,6 +54,7 @@ public class SysDictTypeServiceImpl extends BaseService implements ISysDictTypeS
private Predicate getPredicate(SysDictType sysDictType){ private Predicate getPredicate(SysDictType sysDictType){
QSysDictType qSysDictType = QSysDictType.sysDictType; QSysDictType qSysDictType = QSysDictType.sysDictType;
List<Predicate> predicates = new ArrayList<>(); List<Predicate> predicates = new ArrayList<>();
predicates.add(alwaysTrue());
if(StringUtils.isNotEmpty(sysDictType.getDictName())){ if(StringUtils.isNotEmpty(sysDictType.getDictName())){
predicates.add(buildLike(qSysDictType.dictName, sysDictType.getDictName())); predicates.add(buildLike(qSysDictType.dictName, sysDictType.getDictName()));
} }

View File

@ -58,6 +58,7 @@ public class SysLogininforServiceImpl extends BaseService implements ISysLoginin
private Predicate getPredicate(SysLogininfor logininfor){ private Predicate getPredicate(SysLogininfor logininfor){
QSysLogininfor qSysLogininfor = QSysLogininfor.sysLogininfor; QSysLogininfor qSysLogininfor = QSysLogininfor.sysLogininfor;
List<Predicate> predicates = new ArrayList<>(); List<Predicate> predicates = new ArrayList<>();
predicates.add(alwaysTrue());
if(StringUtils.isNotEmpty(logininfor.getIpaddr())){ if(StringUtils.isNotEmpty(logininfor.getIpaddr())){
predicates.add(buildLike(qSysLogininfor.ipaddr, logininfor.getIpaddr())); predicates.add(buildLike(qSysLogininfor.ipaddr, logininfor.getIpaddr()));
} }

View File

@ -55,6 +55,7 @@ public class SysNoticeServiceImpl extends BaseService implements ISysNoticeServi
private Predicate getPredicate(SysNotice sysNotice){ private Predicate getPredicate(SysNotice sysNotice){
QSysNotice qSysNotice = QSysNotice.sysNotice; QSysNotice qSysNotice = QSysNotice.sysNotice;
List<Predicate> predicates = new ArrayList<>(); List<Predicate> predicates = new ArrayList<>();
predicates.add(alwaysTrue());
if(StringUtils.isNotEmpty(sysNotice.getNoticeTitle())){ if(StringUtils.isNotEmpty(sysNotice.getNoticeTitle())){
predicates.add(buildLike(qSysNotice.noticeTitle, sysNotice.getNoticeTitle())); predicates.add(buildLike(qSysNotice.noticeTitle, sysNotice.getNoticeTitle()));
} }

View File

@ -56,6 +56,7 @@ public class SysOperLogServiceImpl extends BaseService implements ISysOperLogSer
private Predicate getPredicate(SysOperLog operLog){ private Predicate getPredicate(SysOperLog operLog){
QSysOperLog qSysOperLog = QSysOperLog.sysOperLog; QSysOperLog qSysOperLog = QSysOperLog.sysOperLog;
List<Predicate> predicates = new ArrayList<>(); List<Predicate> predicates = new ArrayList<>();
predicates.add(alwaysTrue());
if(StringUtils.isNotEmpty(operLog.getTitle())){ if(StringUtils.isNotEmpty(operLog.getTitle())){
predicates.add(buildLike(qSysOperLog.title, operLog.getTitle())); predicates.add(buildLike(qSysOperLog.title, operLog.getTitle()));
} }

View File

@ -11,6 +11,8 @@ import com.ruoyi.system.repository.SysPostRepository;
import com.ruoyi.system.repository.SysUserRepository; import com.ruoyi.system.repository.SysUserRepository;
import com.ruoyi.system.service.ISysPostService; import com.ruoyi.system.service.ISysPostService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.domain.Specification;
@ -30,6 +32,7 @@ import java.util.List;
* @author ruoyi * @author ruoyi
*/ */
@Service @Service
@CacheConfig(cacheNames = "sys_post")
public class SysPostServiceImpl extends BaseService implements ISysPostService { public class SysPostServiceImpl extends BaseService implements ISysPostService {
@Autowired @Autowired
@ -44,6 +47,7 @@ public class SysPostServiceImpl extends BaseService implements ISysPostService {
* @param pageRequest * @param pageRequest
* @return 岗位信息集合 * @return 岗位信息集合
*/ */
@Cacheable
@Override @Override
public Page<SysPost> selectPostList(SysPost post, Pageable pageRequest) { public Page<SysPost> selectPostList(SysPost post, Pageable pageRequest) {
return sysPostRepository.findAll(getSpecification(post), pageRequest); return sysPostRepository.findAll(getSpecification(post), pageRequest);

View File

@ -16,6 +16,8 @@ import com.ruoyi.system.repository.SysUserRepository;
import com.ruoyi.system.service.ISysRoleService; import com.ruoyi.system.service.ISysRoleService;
import com.ruoyi.system.service.base.BusinessService; import com.ruoyi.system.service.base.BusinessService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -29,6 +31,7 @@ import java.util.*;
* @author ruoyi * @author ruoyi
*/ */
@Service @Service
@CacheConfig(cacheNames = "sys_role")
public class SysRoleServiceImpl extends BusinessService implements ISysRoleService { public class SysRoleServiceImpl extends BusinessService implements ISysRoleService {
@Autowired @Autowired
@ -43,6 +46,7 @@ public class SysRoleServiceImpl extends BusinessService implements ISysRoleServi
* @param user * @param user
* @return 角色数据集合信息 * @return 角色数据集合信息
*/ */
@Cacheable
@Override @Override
public Page<SysRole> selectRoleList(SysRole role, Pageable pageable, SysUser user) { public Page<SysRole> selectRoleList(SysRole role, Pageable pageable, SysUser user) {
return sysRoleRepository.findAll(getPredicate(role, user), pageable); return sysRoleRepository.findAll(getPredicate(role, user), pageable);

View File

@ -20,6 +20,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.domain.Specification;
@ -39,6 +42,7 @@ import java.util.stream.Collectors;
* @author ruoyi * @author ruoyi
*/ */
@Service @Service
@CacheConfig(cacheNames = "sys_user")
public class SysUserServiceImpl extends BaseService implements ISysUserService { public class SysUserServiceImpl extends BaseService implements ISysUserService {
private static final Logger log = LoggerFactory.getLogger(SysUserServiceImpl.class); private static final Logger log = LoggerFactory.getLogger(SysUserServiceImpl.class);
@ -56,6 +60,7 @@ public class SysUserServiceImpl extends BaseService implements ISysUserService {
* @param pageRequest * @param pageRequest
* @return 用户信息集合信息 * @return 用户信息集合信息
*/ */
@Cacheable
@Override @Override
public Page<SysUser> selectUserList(SysUser user, Pageable pageRequest) { public Page<SysUser> selectUserList(SysUser user, Pageable pageRequest) {
return sysUserRepository.findAll(getPredicate(user), pageRequest); return sysUserRepository.findAll(getPredicate(user), pageRequest);
@ -169,6 +174,7 @@ public class SysUserServiceImpl extends BaseService implements ISysUserService {
* @param userName 用户名 * @param userName 用户名
* @return 用户对象信息 * @return 用户对象信息
*/ */
@Cacheable
@Override @Override
public SysUser selectUserByLoginName(String userName) { public SysUser selectUserByLoginName(String userName) {
return sysUserRepository.findFirstByDelFlagAndLoginName(BaseEntity.NOT_DELETED, userName); return sysUserRepository.findFirstByDelFlagAndLoginName(BaseEntity.NOT_DELETED, userName);
@ -182,7 +188,7 @@ public class SysUserServiceImpl extends BaseService implements ISysUserService {
*/ */
@Override @Override
public SysUser selectUserByPhoneNumber(String phoneNumber) { public SysUser selectUserByPhoneNumber(String phoneNumber) {
return sysUserRepository.findFirstByDelFlagAndAndPhonenumber(BaseEntity.NOT_DELETED, phoneNumber); return sysUserRepository.findFirstByDelFlagAndPhonenumber(BaseEntity.NOT_DELETED, phoneNumber);
} }
/** /**
@ -231,6 +237,7 @@ public class SysUserServiceImpl extends BaseService implements ISysUserService {
* @param ids 需要删除的数据ID * @param ids 需要删除的数据ID
* @return 结果 * @return 结果
*/ */
@CacheEvict(allEntries = true)
@Transactional @Transactional
@Override @Override
public int deleteUserByIds(String ids) throws BusinessException { public int deleteUserByIds(String ids) throws BusinessException {
@ -427,6 +434,7 @@ public class SysUserServiceImpl extends BaseService implements ISysUserService {
return depts; return depts;
} }
@Cacheable(key = "#user.userId", unless = "#result == null ")
@Override @Override
public SysUser registerUser(SysUser user) { public SysUser registerUser(SysUser user) {
user.setUserType(UserConstants.REGISTER_USER_TYPE); user.setUserType(UserConstants.REGISTER_USER_TYPE);