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

Commit 371d22d3 authored by 姜秀龙's avatar 姜秀龙

LostFoundAdmin redis del and unq

parent 174aa13c
......@@ -30,25 +30,115 @@ public class SweetLostFoundAdminServiceImpl extends ServiceImpl<SweetLostFoundAd
@Override
public boolean addAdmin(SweetLostFoundAdminParam admin) {
String phone = admin.getPhone().trim();
String performanceId = admin.getPerformanceId().trim();
Integer authScope = admin.getAuthScope();
if (phone == null || phone.trim().isEmpty()) {
throw new IllegalArgumentException("手机号不能为空");
}
if (performanceId == null || performanceId.isEmpty()) {
throw new IllegalArgumentException("演出ID不能为空");
}
// 规则1: 检查在当前演出下是否已创建过管理员
QueryWrapper<SweetLostFoundAdmin> existWrapper = new QueryWrapper<>();
existWrapper.eq("phone", phone)
.eq("performance_id", performanceId)
.eq("is_deleted", 0);
if (baseMapper.selectCount(existWrapper) > 0) {
throw new IllegalStateException("该手机号在当前演出下已存在管理员记录");
}
// 规则2: 如果创建的是全站管理员,检查该手机号是否已在其他演出下创建过全站管理员
if (authScope != null && authScope == 2) {
QueryWrapper<SweetLostFoundAdmin> globalWrapper = new QueryWrapper<>();
globalWrapper.eq("phone", phone)
.eq("auth_scope", 2)
.ne("performance_id", performanceId)
.eq("is_deleted", 0);
if (baseMapper.selectCount(globalWrapper) > 0) {
throw new IllegalStateException("该手机号已作为全站管理员存在,不能再次创建");
}
}
SweetLostFoundAdmin foundAdmin = SweetLostFoundAdmin.getNew();
foundAdmin.setAdminId(IDGenerator.nextSnowId());
foundAdmin.setPhone(admin.getPhone());
foundAdmin.setPhone(phone);
foundAdmin.setName(admin.getName());
foundAdmin.setPermissionType(admin.getPermissionType());
foundAdmin.setAuthScope(admin.getAuthScope());
foundAdmin.setPerformanceId(admin.getPerformanceId());
foundAdmin.setPerformanceId(performanceId);
return baseMapper.insert(foundAdmin) > 0;
}
@Override
public boolean editAdmin(SweetLostFoundAdminParam admin) {
Long id = admin.getId();
String phone = admin.getPhone().trim();
String performanceId = admin.getPerformanceId().trim();
Integer authScope = admin.getAuthScope();
if (id == null) {
throw new IllegalArgumentException("管理员ID不能为空");
}
if (phone == null || phone.isEmpty()) {
throw new IllegalArgumentException("手机号不能为空");
}
if (performanceId == null || performanceId.isEmpty()) {
throw new IllegalArgumentException("演出ID不能为空");
}
// 检查要修改的管理员是否存在
SweetLostFoundAdmin existingAdmin = baseMapper.selectById(id);
if (existingAdmin == null || existingAdmin.getIsDeleted() == 1) {
throw new IllegalStateException("管理员记录不存在或已删除");
}
// 规则1: 检查修改后的手机号在当前演出下是否已存在(排除自身)
QueryWrapper<SweetLostFoundAdmin> existWrapper = new QueryWrapper<>();
existWrapper.eq("phone", phone)
.eq("performance_id", performanceId)
.ne("id", id)
.eq("is_deleted", 0);
if (baseMapper.selectCount(existWrapper) > 0) {
throw new IllegalStateException("该手机号在当前演出下已存在管理员记录");
}
// 规则2: 如果修改为全站管理员,检查该手机号是否已在其他演出下创建过全站管理员(排除自身)
if (authScope != null && authScope == 2) {
QueryWrapper<SweetLostFoundAdmin> globalWrapper = new QueryWrapper<>();
globalWrapper.eq("phone", phone)
.eq("auth_scope", 2)
.ne("id", id)
.ne("performance_id", performanceId)
.eq("is_deleted", 0);
if (baseMapper.selectCount(globalWrapper) > 0) {
throw new IllegalStateException("该手机号已作为全站管理员存在,不能再次创建");
}
}
SweetLostFoundAdmin foundAdmin = SweetLostFoundAdmin.getNew();
foundAdmin.setId(admin.getId());
foundAdmin.setPhone(admin.getPhone());
foundAdmin.setId(id);
foundAdmin.setPhone(phone);
foundAdmin.setName(admin.getName());
foundAdmin.setPermissionType(admin.getPermissionType());
foundAdmin.setAuthScope(admin.getAuthScope());
foundAdmin.setPerformanceId(admin.getPerformanceId());
foundAdmin.setPerformanceId(performanceId);
// 更新缓存
lostFoundRedisUtils.deleteAdminCache(phone, performanceId);
if (!phone.trim().equals(existingAdmin.getPhone())) {
lostFoundRedisUtils.deleteAdminCache(existingAdmin.getPhone(), performanceId);
}
return baseMapper.updateById(foundAdmin) > 0;
}
......@@ -62,6 +152,9 @@ public class SweetLostFoundAdminServiceImpl extends ServiceImpl<SweetLostFoundAd
// 逻辑删除:更新is_deleted字段为1
admin.setIsDeleted(1);
lostFoundRedisUtils.deleteAdminCache(admin.getPhone(), admin.getPerformanceId());
return baseMapper.updateById(admin) > 0;
}
......@@ -123,6 +216,9 @@ public class SweetLostFoundAdminServiceImpl extends ServiceImpl<SweetLostFoundAd
.eq("auth_scope", 2)
);
SweetLostFoundAdmin admin = baseMapper.selectOne(queryWrapper);
if (admin == null) {
return null;
}
SweetLostFoundAdminVo vo = new SweetLostFoundAdminVo();
BeanUtils.copyProperties(admin, vo);
lostFoundRedisUtils.setAdminCache(phone, performanceId, vo);
......
......@@ -188,4 +188,19 @@ public class LostFoundRedisUtils {
log.error("设置管理员缓存失败", e);
}
}
/**
* 删除管理员缓存
*
* @param phone 手机号
* @param performanceId 演出ID
*/
public void deleteAdminCache(String phone, String performanceId) {
try {
String key = ADMIN_DETAIL_KEY + phone + ":" + performanceId;
redisUtil.del(key);
} catch (Exception e) {
log.error("删除管理员缓存失败", e);
}
}
}
\ No newline at end of file
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