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

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

LostFoundAdmin add redis info

parent 9b61cc87
...@@ -55,4 +55,13 @@ public interface ISweetLostFoundAdminService extends IService<SweetLostFoundAdmi ...@@ -55,4 +55,13 @@ public interface ISweetLostFoundAdminService extends IService<SweetLostFoundAdmi
*/ */
List<SweetLostFoundAdminVo> getAdminList(String performanceId); 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 { ...@@ -60,4 +60,12 @@ public class SweetLostFoundAdminController {
public ResponseDto<List<SweetLostFoundAdminVo>> getAdminList(@ApiParam("演出ID") @PathVariable String performanceId) { public ResponseDto<List<SweetLostFoundAdminVo>> getAdminList(@ApiParam("演出ID") @PathVariable String performanceId) {
return ResponseDto.success(sweetLostFoundAdminService.getAdminList(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; ...@@ -7,8 +7,10 @@ import com.liquidnet.service.sweet.entity.SweetLostFoundAdmin;
import com.liquidnet.service.sweet.mapper.SweetLostFoundAdminMapper; import com.liquidnet.service.sweet.mapper.SweetLostFoundAdminMapper;
import com.liquidnet.service.sweet.param.SweetLostFoundAdminParam; import com.liquidnet.service.sweet.param.SweetLostFoundAdminParam;
import com.liquidnet.service.sweet.service.ISweetLostFoundAdminService; import com.liquidnet.service.sweet.service.ISweetLostFoundAdminService;
import com.liquidnet.service.sweet.utils.LostFoundRedisUtils;
import com.liquidnet.service.sweet.vo.SweetLostFoundAdminVo; import com.liquidnet.service.sweet.vo.SweetLostFoundAdminVo;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
...@@ -23,6 +25,9 @@ import java.util.stream.Collectors; ...@@ -23,6 +25,9 @@ import java.util.stream.Collectors;
@Service @Service
public class SweetLostFoundAdminServiceImpl extends ServiceImpl<SweetLostFoundAdminMapper, SweetLostFoundAdmin> implements ISweetLostFoundAdminService { public class SweetLostFoundAdminServiceImpl extends ServiceImpl<SweetLostFoundAdminMapper, SweetLostFoundAdmin> implements ISweetLostFoundAdminService {
@Autowired
private LostFoundRedisUtils lostFoundRedisUtils;
@Override @Override
public boolean addAdmin(SweetLostFoundAdminParam admin) { public boolean addAdmin(SweetLostFoundAdminParam admin) {
SweetLostFoundAdmin foundAdmin = SweetLostFoundAdmin.getNew(); SweetLostFoundAdmin foundAdmin = SweetLostFoundAdmin.getNew();
...@@ -81,16 +86,11 @@ public class SweetLostFoundAdminServiceImpl extends ServiceImpl<SweetLostFoundAd ...@@ -81,16 +86,11 @@ public class SweetLostFoundAdminServiceImpl extends ServiceImpl<SweetLostFoundAd
queryWrapper.eq("is_deleted", 0); queryWrapper.eq("is_deleted", 0);
// 查询条件:performanceId = 指定演出ID OR authScope = 2(全站) // 查询条件:performanceId = 指定演出ID OR authScope = 2(全站)
if (performanceId != null && !performanceId.trim().isEmpty()) {
queryWrapper.and(wrapper -> queryWrapper.and(wrapper ->
wrapper.eq("performance_id", performanceId.trim()) wrapper.eq("performance_id", performanceId.trim())
.or() .or()
.eq("auth_scope", 2) .eq("auth_scope", 2)
); );
} else {
// 如果没有performanceId,只查authScope=2的全站管理员
queryWrapper.eq("auth_scope", 2);
}
// 默认按创建时间降序 // 默认按创建时间降序
queryWrapper.orderByDesc("create_time"); queryWrapper.orderByDesc("create_time");
...@@ -109,4 +109,25 @@ public class SweetLostFoundAdminServiceImpl extends ServiceImpl<SweetLostFoundAd ...@@ -109,4 +109,25 @@ public class SweetLostFoundAdminServiceImpl extends ServiceImpl<SweetLostFoundAd
return voList; 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; package com.liquidnet.service.sweet.utils;
import com.liquidnet.common.cache.redis.util.RedisUtil; import com.liquidnet.common.cache.redis.util.RedisUtil;
import com.liquidnet.service.sweet.vo.SweetLostFoundAdminVo;
import com.liquidnet.service.sweet.vo.SweetLostFoundItemVo; import com.liquidnet.service.sweet.vo.SweetLostFoundItemVo;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -26,7 +27,7 @@ public class LostFoundRedisUtils { ...@@ -26,7 +27,7 @@ public class LostFoundRedisUtils {
private static final String LOST_FOUND_KEY_PREFIX = "sweet:lost_found:"; 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_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 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天 private static final long LIST_EXPIRE_TIME = 432000; // 5天
...@@ -159,14 +160,17 @@ public class LostFoundRedisUtils { ...@@ -159,14 +160,17 @@ public class LostFoundRedisUtils {
* @param performanceId 演出ID * @param performanceId 演出ID
* @return 是否存在 * @return 是否存在
*/ */
public boolean isAdminExists(String phone, String performanceId) { public SweetLostFoundAdminVo getAdminCache(String phone, String performanceId) {
try { try {
String key = ADMIN_LIST_KEY + phone + ":" + performanceId; String key = ADMIN_DETAIL_KEY + phone + ":" + performanceId;
return redisUtil.hasKey(key); Object cachedValue = redisUtil.get(key);
if (cachedValue != null) {
return (SweetLostFoundAdminVo) cachedValue;
}
} catch (Exception e) { } catch (Exception e) {
log.error("检查管理员缓存失败", e); log.error("检查管理员缓存失败", e);
return false;
} }
return null;
} }
/** /**
...@@ -174,12 +178,12 @@ public class LostFoundRedisUtils { ...@@ -174,12 +178,12 @@ public class LostFoundRedisUtils {
* *
* @param phone 手机号 * @param phone 手机号
* @param performanceId 演出ID * @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 { try {
String key = ADMIN_LIST_KEY + phone + ":" + performanceId; String key = ADMIN_DETAIL_KEY + phone + ":" + performanceId;
redisUtil.set(key, isAdmin, 1800); // 30分钟 redisUtil.set(key, vo, DETAIL_EXPIRE_TIME);
} catch (Exception e) { } catch (Exception e) {
log.error("设置管理员缓存失败", 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