|
@@ -12,6 +12,8 @@ import com.ym.mec.biz.service.TempLittleArtistTrainingCampService;
|
|
|
import com.ym.mec.biz.service.TempLittleArtistTrainingCampUserRelationService;
|
|
|
import com.ym.mec.common.exception.BizException;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.redisson.api.RBucket;
|
|
|
+import org.redisson.api.RedissonClient;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -20,6 +22,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.Objects;
|
|
|
import java.util.Optional;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
import java.util.function.Consumer;
|
|
|
|
|
|
/**
|
|
@@ -38,6 +41,8 @@ public class TempLittleArtistTrainingCampUserRelationServiceImpl extends Service
|
|
|
private SysConfigService sysConfigService;
|
|
|
@Autowired
|
|
|
private TempLittleArtistTrainingCampService tempLittleArtistTrainingCampService;
|
|
|
+ @Autowired
|
|
|
+ private RedissonClient redissonClient;
|
|
|
|
|
|
@Override
|
|
|
public TempLittleArtistTrainingCampUserRelationDao getDao() {
|
|
@@ -53,15 +58,20 @@ public class TempLittleArtistTrainingCampUserRelationServiceImpl extends Service
|
|
|
@Override
|
|
|
public void add(Integer campId) {
|
|
|
SysUser user = getUser();
|
|
|
+ RBucket<Object> addCamp = redissonClient.getBucket("TEMP:CAMP_ADD:" + user.getId());
|
|
|
+ if (!addCamp.trySet(1,10, TimeUnit.SECONDS)) {
|
|
|
+ throw new BizException("正在登记训练营,请勿重复提交");
|
|
|
+ }
|
|
|
TempLittleArtistTrainingCampUserRelation one = this.getOne(Wrappers.<TempLittleArtistTrainingCampUserRelation>lambdaQuery()
|
|
|
- .eq(TempLittleArtistTrainingCampUserRelation::getUserId, user.getId()));
|
|
|
- if (Objects.nonNull(one) && Objects.nonNull(one.getActivityId())) {
|
|
|
+ .eq(TempLittleArtistTrainingCampUserRelation::getUserId, user.getId())
|
|
|
+ .isNotNull(TempLittleArtistTrainingCampUserRelation::getActivityId));
|
|
|
+ if (Objects.nonNull(one)) {
|
|
|
throw new BizException("您已登记训练营!");
|
|
|
}
|
|
|
int count = this.count(Wrappers.<TempLittleArtistTrainingCampUserRelation>lambdaUpdate()
|
|
|
- .set(TempLittleArtistTrainingCampUserRelation::getActivityId, campId));
|
|
|
+ .eq(TempLittleArtistTrainingCampUserRelation::getActivityId, campId));
|
|
|
int maxNum = 2000;
|
|
|
- if (count == maxNum) {
|
|
|
+ if (count >= maxNum) {
|
|
|
throw new BizException("人数已报满!");
|
|
|
}
|
|
|
//修改训练营人数,小于2000人
|
|
@@ -73,6 +83,7 @@ public class TempLittleArtistTrainingCampUserRelationServiceImpl extends Service
|
|
|
.set(TempLittleArtistTrainingCampUserRelation::getActivityId, campId)
|
|
|
.set(TempLittleArtistTrainingCampUserRelation::getState, TempLittleArtistTrainingCampUserRelation.APPLY)
|
|
|
.eq(TempLittleArtistTrainingCampUserRelation::getUserId, user.getId()));
|
|
|
+ addCamp.delete();
|
|
|
}
|
|
|
|
|
|
/**
|