Skip to content

Commit

Permalink
Merge pull request #93 from GodLikeZeal/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
GodLikeZeal authored Feb 23, 2022
2 parents c5b3bf7 + 79bf640 commit 42d018e
Show file tree
Hide file tree
Showing 20 changed files with 149 additions and 128 deletions.
19 changes: 16 additions & 3 deletions src/main/java/com/zeal/zealsay/config/RedisConfig.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.zeal.zealsay.config;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.interceptor.KeyGenerator;
Expand All @@ -11,7 +15,10 @@
import org.springframework.data.redis.cache.RedisCacheWriter;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.*;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializationContext;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

import java.lang.reflect.Method;
import java.time.Duration;
Expand All @@ -21,6 +28,9 @@
@EnableCaching // spring中注解驱动的缓存管理功能
public class RedisConfig {

@Autowired
ObjectMapper objectMapper;

@Bean
public KeyGenerator KeyGenerator() {
return new KeyGenerator() {
Expand Down Expand Up @@ -71,7 +81,6 @@ public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connec
// jackson2JsonRedisSerializer.setObjectMapper(objectMapper);

// 使用StringRedisSerializer来序列化和反序列化redis的key值
RedisSerializer redisSerializer = new StringRedisSerializer();
// key
redisTemplate.setKeySerializer(keySerializer());
redisTemplate.setHashKeySerializer(keySerializer());
Expand Down Expand Up @@ -100,7 +109,11 @@ public CacheManager cacheManager(RedisConnectionFactory redisConnectionFactory)

// 使用Jackson序列化器
private RedisSerializer<Object> valueSerializer() {
return new GenericJackson2JsonRedisSerializer();
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
jackson2JsonRedisSerializer.setObjectMapper(objectMapper);
return jackson2JsonRedisSerializer;
// return new GenericJackson2JsonRedisSerializer();
}

private RedisSerializer<String> keySerializer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public Result<Map<String, Object>> getUserData(@PathVariable Long id) throws Exe
log.info("👕用户中心信息获取中...");
//获取当前用户信息
User userInfo = userService.getById(id);
UserResponse user = null;
UserResponse user = new UserResponse();
if (Objects.nonNull(userInfo)) {
BeanUtils.copyProperties(userInfo,user);
}
Expand Down
213 changes: 107 additions & 106 deletions src/main/java/com/zeal/zealsay/controller/RoleController.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,127 +29,128 @@
/**
* 角色模块接口入口.
*
* @author zhanglei
* @author zhanglei
* @date 2018/11/23 6:01 PM
*/
@Slf4j
@RestController
@RequestMapping("/api/v1/role")
public class RoleController {

@Autowired
RoleService roleService;
@Autowired
RoleHelper roleHelper;
@Autowired
RoleService roleService;
@Autowired
RoleHelper roleHelper;

/**
* 根据id来查询.
*
* @author zhanglei
* @date 2018/9/7 下午6:00
*/
@GetMapping("/{id}")
public Result<RoleResponse> getById(@PathVariable String id) {
log.info("开始查询角色id为 '{}' 的角色详情信息", id);
Role role = roleService.getById(id);
if (Objects.isNull(role)) {
return Result.of(null);
/**
* 根据id来查询.
*
* @author zhanglei
* @date 2018/9/7 下午6:00
*/
@GetMapping("/{id}")
public Result<RoleResponse> getById(@PathVariable String id) {
log.info("开始查询角色id为 '{}' 的角色详情信息", id);
Role role = roleService.getById(id);
if (Objects.isNull(role)) {
return Result.of(null);
}
RoleResponse response = new RoleResponse();
BeanUtils.copyProperties(role, response);
return Result.of(response);
}
RoleResponse response = new RoleResponse();
BeanUtils.copyProperties(role,response);
return Result.of(response);
}
/**
* 根据id来查询.
*
* @author zhanglei
* @date 2018/9/7 下午6:00
*/
@GetMapping("")
public Result<RoleResponse> getByList() {
log.info("开始查询角色列表");
List<Role> list = roleService.list(new QueryWrapper<Role>());
if (CollectionUtils.isEmpty(list)) {
return Result.of(null);

/**
* 根据id来查询.
*
* @author zhanglei
* @date 2018/9/7 下午6:00
*/
@GetMapping("")
public Result<RoleResponse> getByList() {
log.info("开始查询角色列表");
List<Role> list = roleService.list(new QueryWrapper<Role>());
if (CollectionUtils.isEmpty(list)) {
return Result.of(null);
}
List<RoleResponse> responses = list.stream().map(s -> {
RoleResponse response = new RoleResponse();
BeanUtils.copyProperties(s, response);
return response;
}).collect(Collectors.toList());
return Result.of(responses);
}
List<RoleResponse> responses = list.stream().map(s -> {
RoleResponse response = new RoleResponse();
BeanUtils.copyProperties(s, response);
return response;
}).collect(Collectors.toList());
return Result.of(responses);
}

/**
* 分页查询.
*
* @author zhanglei
* @date 2018/9/7 下午6:00
*/
@GetMapping("/page")
public Result<PageInfo<RoleResponse>> getByPaginate(@Value("1") Long pageNumber,
@Value("10") Long pageSize,
RolePageRequest rolePageRequest) {
log.info("开始进行分页查询角色列表,查询参数为 '{}' ", rolePageRequest);
Role role = null;
if (Objects.nonNull(rolePageRequest)) {
BeanUtils.copyProperties(rolePageRequest,role);
/**
* 分页查询.
*
* @author zhanglei
* @date 2018/9/7 下午6:00
*/
@GetMapping("/page")
public Result<PageInfo<RoleResponse>> getByPaginate(@Value("1") Long pageNumber,
@Value("10") Long pageSize,
RolePageRequest rolePageRequest) {
log.info("开始进行分页查询角色列表,查询参数为 '{}' ", rolePageRequest);
Role role = new Role();
if (Objects.nonNull(rolePageRequest)) {
BeanUtils.copyProperties(rolePageRequest, role);
}
Page<Role> rolePage = (Page<Role>) roleService
.page(new Page<>(pageNumber, pageSize), new QueryWrapper(role));
return Result.of(roleHelper.toPageInfo(rolePage));
}
Page<Role> rolePage = (Page<Role>) roleService
.page(new Page<>(pageNumber, pageSize), new QueryWrapper(role));
return Result.of(roleHelper.toPageInfo(rolePage));
}

/**
* 新增角色.
*
* @author zhanglei
* @date 2018/11/23 5:43 PM
*/
@PreAuthorize("hasAnyRole('ROLE_ADMIN')")
@PostMapping("")
public Result<Boolean> addRole(@RequestBody @Validated RoleAddResquest roleAddResquest) {
log.info("开始进行新增角色,新增参数为 '{}' ", roleAddResquest);
return Result.of(roleService.addRole(roleAddResquest));
}
/**
* 新增角色.
*
* @author zhanglei
* @date 2018/11/23 5:43 PM
*/
@PreAuthorize("hasAnyRole('ROLE_ADMIN')")
@PostMapping("")
public Result<Boolean> addRole(@RequestBody @Validated RoleAddResquest roleAddResquest) {
log.info("开始进行新增角色,新增参数为 '{}' ", roleAddResquest);
return Result.of(roleService.addRole(roleAddResquest));
}

/**
* 修改角色数据.
*
* @author zhanglei
* @date 2018/11/23 5:47 PM
*/
@PreAuthorize("hasAnyRole('ROLE_ADMIN')")
@PutMapping("")
public Result<Boolean> updateRole(@RequestBody @Validated RoleUpdateRequest roleUpdateRequest) {
log.info("开始进行分新增角色,新增参数为 '{}' ", roleUpdateRequest);
return Result.of(roleService.updateRole(roleUpdateRequest));
}
/**
* 修改角色数据.
*
* @author zhanglei
* @date 2018/11/23 5:47 PM
*/
@PreAuthorize("hasAnyRole('ROLE_ADMIN')")
@PutMapping("")
public Result<Boolean> updateRole(@RequestBody @Validated RoleUpdateRequest roleUpdateRequest) {
log.info("开始进行分新增角色,新增参数为 '{}' ", roleUpdateRequest);
return Result.of(roleService.updateRole(roleUpdateRequest));
}

/**
* 根据id删除角色.
*
* @author zhanglei
* @date 2018/11/23 5:47 PM
*/
@PreAuthorize("hasAnyRole('ROLE_ADMIN')")
@DeleteMapping("/{id}")
public Result<Boolean> deleteRole(@PathVariable Long id) {
log.info("开始删除id为 '{}' 的角色信息", id);
return Result.of(roleService.removeById(id));
}
/**
* 根据id删除角色.
*
* @author zhanglei
* @date 2018/11/23 5:47 PM
*/
@PreAuthorize("hasAnyRole('ROLE_ADMIN')")
@DeleteMapping("/{id}")
public Result<Boolean> deleteRole(@PathVariable Long id) {
log.info("开始删除id为 '{}' 的角色信息", id);
return Result.of(roleService.removeById(id));
}

/**
* 根据id列表批量删除角色.
*
* @author zhanglei
* @date 2018/11/23 5:47 PM
*/
@PreAuthorize("hasAnyRole('ROLE_ADMIN')")
@DeleteMapping("/batch")
public Result<Boolean> deleteRoleBatch(@RequestBody Collection<String> ids) {
log.info("开始批量删除id在 '{}' 的角色信息", ids.toString());
return Result.of(roleService.removeByIds(ids));
}
/**
* 根据id列表批量删除角色.
*
* @author zhanglei
* @date 2018/11/23 5:47 PM
*/
@PreAuthorize("hasAnyRole('ROLE_ADMIN')")
@DeleteMapping("/batch")
public Result<Boolean> deleteRoleBatch(@RequestBody Collection<String> ids) {
log.info("开始批量删除id在 '{}' 的角色信息", ids.toString());
return Result.of(roleService.removeByIds(ids));
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public Result<PageInfo<UserResponse>> getByPaginate(@RequestParam(defaultValue =
@RequestParam(defaultValue = "10") Long pageSize,
UserPageRequest userPageRequest) {
log.info("开始进行分页查询用户列表,查询参数为 '{}' ", userPageRequest);
User user = null;
User user = new User();
if (Objects.nonNull(userPageRequest)) {
BeanUtils.copyProperties(userPageRequest,user);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @author zhanglei
* @since 2018-12-29
*/
@CacheNamespace(implementation= MybatisRedisCache.class,eviction=MybatisRedisCache.class)
//@CacheNamespace(implementation= MybatisRedisCache.class,eviction=MybatisRedisCache.class)
public interface ArticleCategoryMapper extends BaseMapper<ArticleCategory> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @author zhanglei
* @since 2019-05-16
*/
@CacheNamespace(implementation= MybatisRedisCache.class,eviction= MybatisRedisCache.class)
//@CacheNamespace(implementation= MybatisRedisCache.class,eviction= MybatisRedisCache.class)
public interface ArticleLabelMapper extends BaseMapper<ArticleLabel> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @author zhanglei
* @since 2019-05-16
*/
@CacheNamespace(implementation= MybatisRedisCache.class,eviction= MybatisRedisCache.class)
//@CacheNamespace(implementation= MybatisRedisCache.class,eviction= MybatisRedisCache.class)
public interface ArticleLikeMapper extends BaseMapper<ArticleLike> {

}
2 changes: 1 addition & 1 deletion src/main/java/com/zeal/zealsay/mapper/ArticleMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @author zhanglei
* @since 2018-11-28
*/
@CacheNamespace(implementation= MybatisRedisCache.class,eviction= MybatisRedisCache.class)
//@CacheNamespace(implementation= MybatisRedisCache.class,eviction= MybatisRedisCache.class)
public interface ArticleMapper extends BaseMapper<Article> {

}
2 changes: 1 addition & 1 deletion src/main/java/com/zeal/zealsay/mapper/AuthUserMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @author zhanglei
* @since 2019-09-12
*/
@CacheNamespace(implementation= MybatisRedisCache.class,eviction= MybatisRedisCache.class)
//@CacheNamespace(implementation= MybatisRedisCache.class,eviction= MybatisRedisCache.class)
public interface AuthUserMapper extends BaseMapper<AuthUser> {

}
2 changes: 1 addition & 1 deletion src/main/java/com/zeal/zealsay/mapper/BlockLogMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @author zhanglei
* @since 2019-03-16
*/
@CacheNamespace(implementation= MybatisRedisCache.class,eviction= MybatisRedisCache.class)
//@CacheNamespace(implementation= MybatisRedisCache.class,eviction= MybatisRedisCache.class)
public interface BlockLogMapper extends BaseMapper<BlockLog> {

}
2 changes: 1 addition & 1 deletion src/main/java/com/zeal/zealsay/mapper/CommentMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @author zhanglei
* @date 2020/6/16 4:57 下午
*/
@CacheNamespace(implementation= MybatisRedisCache.class,eviction= MybatisRedisCache.class)
//@CacheNamespace(implementation= MybatisRedisCache.class,eviction= MybatisRedisCache.class)
public interface CommentMapper extends BaseMapper<Comment> {

}
2 changes: 1 addition & 1 deletion src/main/java/com/zeal/zealsay/mapper/DictMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @author zhanglei
* @since 2019-03-27
*/
@CacheNamespace(implementation= MybatisRedisCache.class,eviction= MybatisRedisCache.class)
//@CacheNamespace(implementation= MybatisRedisCache.class,eviction= MybatisRedisCache.class)
public interface DictMapper extends BaseMapper<Dict> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @author zhanglei
* @since 2019-07-31
*/
@CacheNamespace(implementation= MybatisRedisCache.class,eviction= MybatisRedisCache.class)
//@CacheNamespace(implementation= MybatisRedisCache.class,eviction= MybatisRedisCache.class)
public interface FriendLinkMapper extends BaseMapper<FriendLink> {

}
2 changes: 1 addition & 1 deletion src/main/java/com/zeal/zealsay/mapper/LoginLogMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @author zhanglei
* @since 2019-03-16
*/
@CacheNamespace(implementation= MybatisRedisCache.class,eviction= MybatisRedisCache.class)
//@CacheNamespace(implementation= MybatisRedisCache.class,eviction= MybatisRedisCache.class)
public interface LoginLogMapper extends BaseMapper<LoginLog> {

}
Loading

0 comments on commit 42d018e

Please sign in to comment.