记得上下班打卡 | git大法好,push需谨慎

Commit 174aa13c authored by 姜秀龙's avatar 姜秀龙

LostFoundAdmin add redis info

parent 9b61cc87
......@@ -55,4 +55,13 @@ public interface ISweetLostFoundAdminService extends IService<SweetLostFoundAdmi
*/
List<SweetLostFoundAdminVo> getAdminList(String performanceId);
/**
* 检查是否有管理员权限
*
* @param phone 手机号
* @param performanceId 演出ID
* @return 权限详情信息
*/
SweetLostFoundAdminVo hasPermission(String phone, String performanceId);
}
\ No newline at end of file
......@@ -60,4 +60,12 @@ public class SweetLostFoundAdminController {
public ResponseDto<List<SweetLostFoundAdminVo>> getAdminList(@ApiParam("演出ID") @PathVariable String performanceId) {
return ResponseDto.success(sweetLostFoundAdminService.getAdminList(performanceId));
}
@GetMapping("/permission/{phone}/{performanceId}")
@ApiOperation("获取权限")
public ResponseDto<SweetLostFoundAdminVo> getPermission(
@ApiParam("手机号") @PathVariable String phone,
@ApiParam("演出ID") @PathVariable String performanceId) {
return ResponseDto.success(sweetLostFoundAdminService.hasPermission(phone, performanceId));
}
}
\ No newline at end of file
......@@ -7,8 +7,10 @@ import com.liquidnet.service.sweet.entity.SweetLostFoundAdmin;
import com.liquidnet.service.sweet.mapper.SweetLostFoundAdminMapper;
import com.liquidnet.service.sweet.param.SweetLostFoundAdminParam;
import com.liquidnet.service.sweet.service.ISweetLostFoundAdminService;
import com.liquidnet.service.sweet.utils.LostFoundRedisUtils;
import com.liquidnet.service.sweet.vo.SweetLostFoundAdminVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
......@@ -23,6 +25,9 @@ import java.util.stream.Collectors;
@Service
public class SweetLostFoundAdminServiceImpl extends ServiceImpl<SweetLostFoundAdminMapper, SweetLostFoundAdmin> implements ISweetLostFoundAdminService {
@Autowired
private LostFoundRedisUtils lostFoundRedisUtils;
@Override
public boolean addAdmin(SweetLostFoundAdminParam admin) {
SweetLostFoundAdmin foundAdmin = SweetLostFoundAdmin.getNew();
......@@ -81,16 +86,11 @@ public class SweetLostFoundAdminServiceImpl extends ServiceImpl<SweetLostFoundAd
queryWrapper.eq("is_deleted", 0);
// 查询条件:performanceId = 指定演出ID OR authScope = 2(全站)
if (performanceId != null && !performanceId.trim().isEmpty()) {
queryWrapper.and(wrapper ->
wrapper.eq("performance_id", performanceId.trim())
.or()
.eq("auth_scope", 2)
);
} else {
// 如果没有performanceId,只查authScope=2的全站管理员
queryWrapper.eq("auth_scope", 2);
}
queryWrapper.and(wrapper ->
wrapper.eq("performance_id", performanceId.trim())
.or()
.eq("auth_scope", 2)
);
// 默认按创建时间降序
queryWrapper.orderByDesc("create_time");
......@@ -109,4 +109,25 @@ public class SweetLostFoundAdminServiceImpl extends ServiceImpl<SweetLostFoundAd
return voList;
}
@Override
public SweetLostFoundAdminVo hasPermission(String phone, String performanceId) {
SweetLostFoundAdminVo adminCache = lostFoundRedisUtils.getAdminCache(phone, performanceId);
if (adminCache == null) {
QueryWrapper<SweetLostFoundAdmin> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("phone", phone.trim())
.eq("is_deleted", 0);
queryWrapper.and(wrapper ->
wrapper.eq("performance_id", performanceId.trim())
.or()
.eq("auth_scope", 2)
);
SweetLostFoundAdmin admin = baseMapper.selectOne(queryWrapper);
SweetLostFoundAdminVo vo = new SweetLostFoundAdminVo();
BeanUtils.copyProperties(admin, vo);
lostFoundRedisUtils.setAdminCache(phone, performanceId, vo);
return vo;
}
return adminCache;
}
}
\ No newline at end of file
package com.liquidnet.service.sweet.utils;
import com.liquidnet.common.cache.redis.util.RedisUtil;
import com.liquidnet.service.sweet.vo.SweetLostFoundAdminVo;
import com.liquidnet.service.sweet.vo.SweetLostFoundItemVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -26,7 +27,7 @@ public class LostFoundRedisUtils {
private static final String LOST_FOUND_KEY_PREFIX = "sweet:lost_found:";
private static final String ITEM_LIST_KEY = LOST_FOUND_KEY_PREFIX + "item_list:";
private static final String ITEM_DETAIL_KEY = LOST_FOUND_KEY_PREFIX + "item_detail:";
private static final String ADMIN_LIST_KEY = LOST_FOUND_KEY_PREFIX + "admin_list:";
private static final String ADMIN_DETAIL_KEY = LOST_FOUND_KEY_PREFIX + "admin_detail:";
// 缓存过期时间(秒)
private static final long LIST_EXPIRE_TIME = 432000; // 5天
......@@ -159,14 +160,17 @@ public class LostFoundRedisUtils {
* @param performanceId 演出ID
* @return 是否存在
*/
public boolean isAdminExists(String phone, String performanceId) {
public SweetLostFoundAdminVo getAdminCache(String phone, String performanceId) {
try {
String key = ADMIN_LIST_KEY + phone + ":" + performanceId;
return redisUtil.hasKey(key);
String key = ADMIN_DETAIL_KEY + phone + ":" + performanceId;
Object cachedValue = redisUtil.get(key);
if (cachedValue != null) {
return (SweetLostFoundAdminVo) cachedValue;
}
} catch (Exception e) {
log.error("检查管理员缓存失败", e);
return false;
}
return null;
}
/**
......@@ -174,12 +178,12 @@ public class LostFoundRedisUtils {
*
* @param phone 手机号
* @param performanceId 演出ID
* @param isAdmin 是否是管理员
* @param vo 管理员信息
*/
public void setAdminCache(String phone, String performanceId, boolean isAdmin) {
public void setAdminCache(String phone, String performanceId, SweetLostFoundAdminVo vo) {
try {
String key = ADMIN_LIST_KEY + phone + ":" + performanceId;
redisUtil.set(key, isAdmin, 1800); // 30分钟
String key = ADMIN_DETAIL_KEY + phone + ":" + performanceId;
redisUtil.set(key, vo, DETAIL_EXPIRE_TIME);
} catch (Exception e) {
log.error("设置管理员缓存失败", e);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment