公会审核加锁

This commit is contained in:
2025-06-10 11:39:55 +08:00
parent f6482c5471
commit 36c3555832
2 changed files with 49 additions and 36 deletions

View File

@@ -5,10 +5,12 @@ import com.accompany.admin.model.AdminUser;
import com.accompany.admin.service.system.AdminUserService;
import com.accompany.admin.vo.guild.GuildApplyAuditVo;
import com.accompany.business.model.give.GiveUser;
import com.accompany.business.model.guild.Guild;
import com.accompany.business.model.guild.GuildApply;
import com.accompany.business.service.BaseSendService;
import com.accompany.business.service.give.GiveUserService;
import com.accompany.business.service.guild.GuildApplyService;
import com.accompany.business.service.guild.GuildService;
import com.accompany.business.service.user.UsersService;
import com.accompany.common.constant.Constant;
import com.accompany.common.redis.RedisKey;
@@ -54,6 +56,8 @@ public class GuildApplyAdminService {
private RedissonClient redissonClient;
@Autowired
private GiveUserService giveUserService;
@Autowired
private GuildService guildService;
public void existNotAuditByApplyUidCheck4Admin(Long applyUid, String erbanNo) {
GuildApply existNotAuditByApplyUid = guildApplyService.getExistNotAuditByApplyUid(applyUid);
@@ -155,16 +159,7 @@ public class GuildApplyAdminService {
return BusiResult.success(pageResult);
}
@Transactional(rollbackFor = Exception.class)
public BusiResult<Void> audit(Integer id, Byte auditStatus, Integer admindId){
GuildApply applyServiceById = guildApplyService.getById(id);
if (applyServiceById == null) {
throw new AdminServiceException("记录不存在");
}
if (!Constant.CommonAuditStatus.wait.equals(applyServiceById.getAuditStatus())) {
throw new AdminServiceException("已操作,请重新刷新页面");
}
public BusiResult<Void> auditOpt(Integer id, Byte auditStatus, Integer admindId) {
String lockKey = RedisKey.guild_apply_audit.getKey(id.toString());
RLock lock = redissonClient.getLock(lockKey);
try {
@@ -172,39 +167,57 @@ public class GuildApplyAdminService {
if (!lock.isLocked()) {
throw new AdminServiceException(BusiStatus.SERVERBUSY);
}
Users users = usersService.getUsersByUid(applyServiceById.getApplyUid());
if (Constant.CommonAuditStatus.reject.equals(auditStatus)) {
applyServiceById.setAuditStatus(Constant.CommonAuditStatus.reject);
applyServiceById.setApplyTime(new Date());
applyServiceById.setAdminId(admindId);
boolean b = guildApplyService.updateById(applyServiceById);
if (b) {
String rejectSys = I18NMessageSourceUtil.getMessage(I18nAlertEnum.GUILD_APPLY_REJECT, users.getPartitionId());
baseSendService.sendSystemMsg(users.getUid().toString(), rejectSys);
}
return BusiResult.success();
} else if (Constant.CommonAuditStatus.pass.equals(auditStatus)) {
applyServiceById.setAuditStatus(Constant.CommonAuditStatus.pass);
applyServiceById.setApplyTime(new Date());
applyServiceById.setAdminId(admindId);
boolean b = guildApplyService.updateById(applyServiceById);
if (b) {
Integer guildId = guildManageAdminService.addGuildInfo(users, applyServiceById.getApplyTime(), admindId, null, null, applyServiceById.getInviteUid(), applyServiceById);
applyServiceById.setGuildId(guildId);
guildApplyService.updateById(applyServiceById);
String rejectSys = I18NMessageSourceUtil.getMessage(I18nAlertEnum.GUILD_APPLY_PASS, users.getPartitionId());
baseSendService.sendSystemMsg(users.getUid().toString(), rejectSys);
}
return BusiResult.success();
GuildApply applyServiceById = guildApplyService.getById(id);
if (applyServiceById == null) {
throw new AdminServiceException("记录不存在");
}
if (!Constant.CommonAuditStatus.wait.equals(applyServiceById.getAuditStatus())) {
throw new AdminServiceException("已操作,请重新刷新页面");
}
Guild vaildGuildByOwnerUid = guildService.getVaildGuildByOwnerUid(applyServiceById.getApplyUid());
if (vaildGuildByOwnerUid != null) {
throw new AdminServiceException("已操作,请重新刷新页面(公会存在)");
}
this.audit(auditStatus, admindId, applyServiceById);
} catch (InterruptedException e) {
log.error("GuildApplyAdminService.audit={},e={}", JSONObject.toJSONString(applyServiceById), e.getMessage(),e);
log.error("GuildApplyAdminService.id={},e={}", id, e.getMessage(),e);
throw new AdminServiceException(e.getMessage());
} finally {
if (lock.isLocked()) {
lock.unlock();
}
}
return BusiResult.success();
}
@Transactional(rollbackFor = Exception.class)
public BusiResult<Void> audit(Byte auditStatus, Integer admindId, GuildApply applyServiceById){
Users users = usersService.getUsersByUid(applyServiceById.getApplyUid());
if (Constant.CommonAuditStatus.reject.equals(auditStatus)) {
applyServiceById.setAuditStatus(Constant.CommonAuditStatus.reject);
applyServiceById.setApplyTime(new Date());
applyServiceById.setAdminId(admindId);
boolean b = guildApplyService.updateById(applyServiceById);
if (b) {
String rejectSys = I18NMessageSourceUtil.getMessage(I18nAlertEnum.GUILD_APPLY_REJECT, users.getPartitionId());
baseSendService.sendSystemMsg(users.getUid().toString(), rejectSys);
}
return BusiResult.success();
} else if (Constant.CommonAuditStatus.pass.equals(auditStatus)) {
applyServiceById.setAuditStatus(Constant.CommonAuditStatus.pass);
applyServiceById.setApplyTime(new Date());
applyServiceById.setAdminId(admindId);
boolean b = guildApplyService.updateById(applyServiceById);
if (b) {
Integer guildId = guildManageAdminService.addGuildInfo(users, applyServiceById.getApplyTime(), admindId, null, null, applyServiceById.getInviteUid(), applyServiceById);
applyServiceById.setGuildId(guildId);
guildApplyService.updateById(applyServiceById);
String rejectSys = I18NMessageSourceUtil.getMessage(I18nAlertEnum.GUILD_APPLY_PASS, users.getPartitionId());
baseSendService.sendSystemMsg(users.getUid().toString(), rejectSys);
}
return BusiResult.success();
}
return BusiResult.fail("审核失败");
}
}

View File

@@ -41,6 +41,6 @@ public class GuildApplyAdminController extends BaseController {
@ApiOperation(value = "审核", httpMethod = "POST")
@PostMapping("/audit")
public BusiResult<Void> audit(Integer id, Byte auditStatus) {
return guildApplyAdminService.audit(id, auditStatus, getAdminId());
return guildApplyAdminService.auditOpt(id, auditStatus, getAdminId());
}
}