Commit 11b26e11 authored by liwei's avatar liwei

修改了发表动态接口

parent 30db737f
......@@ -231,5 +231,11 @@ public class OpmArticle extends CyIdIncreEntity<OpmArticle> {
*/
@TableField(exist = false)
private String wxOpenid;
/**
* 是否付费 1:付费 0:不付费
*/
@TableField(exist = false)
private String isPay;
}
......@@ -31,6 +31,7 @@ import org.rcisoft.sys.dictionary.service.DictionaryService;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
......@@ -67,6 +68,8 @@ public class OpmArticleServiceImpl extends ServiceImpl<OpmArticleRepository, Opm
private CyRedisServiceImpl cyRedisServiceImpl;
@Autowired
private RedissonClient redissonClient;
@Autowired
private StringRedisTemplate redisTemplate;
/**
* 保存 opmArticle管理
* @param opmArticle
......@@ -100,7 +103,7 @@ public class OpmArticleServiceImpl extends ServiceImpl<OpmArticleRepository, Opm
Object redisCount = cyRedisServiceImpl.get(OpmArticleRedisBean.USER_ARTICLE_COUNT + date + ":" + userId);
if (redisCount != null && (int)redisCount >= publishCountAll){
//超出最大数量
throw new CyServiceException(1001,"发布动态已达上限");
throw new CyServiceException(1001,"今日发布动态总次数已达上限");
} else if (redisCount == null){
//当天第一次发布动态
cyRedisServiceImpl.set(OpmArticleRedisBean.USER_ARTICLE_COUNT + date + ":" + userId,1,48*60*60L);
......@@ -109,28 +112,39 @@ public class OpmArticleServiceImpl extends ServiceImpl<OpmArticleRepository, Opm
//判断免费和付费数量
if ((int)redisCount >= publishCount){
//超过免费限制次数 需要付费
//扣除该用户的金币数量
int line = 0;
boolean isGetLock = false;
RLock lock = redissonClient.getLock(OpmArticleRedisBean.USER_ARTICLE_LOCK + userId);
try {
isGetLock = lock.tryLock(Long.parseLong(OpmArticleRedisBean.USER_ARTICLE_LOCK_WAIT_TIME),
Long.parseLong(OpmArticleRedisBean.USER_ARTICLE_LOCK_LEASE_TIME), TimeUnit.SECONDS);
if (isGetLock) {
MemInfo memInfo = memInfoRepository.selectByOpenId(opmArticle.getWxOpenid());
if (memInfo.getGoldCoinsCount() - payCount < 0){
throw new CyServiceException(1003,"金币余额不足,请先充值");
if (opmArticle.getIsPay().equals("1")){
//扣除该用户的金币数量
int line = 0;
boolean isGetLock = false;
RLock lock = redissonClient.getLock(OpmArticleRedisBean.USER_ARTICLE_LOCK + userId);
try {
isGetLock = lock.tryLock(Long.parseLong(OpmArticleRedisBean.USER_ARTICLE_LOCK_WAIT_TIME),
Long.parseLong(OpmArticleRedisBean.USER_ARTICLE_LOCK_LEASE_TIME), TimeUnit.SECONDS);
if (isGetLock) {
MemInfo memInfo = memInfoRepository.selectByOpenId(opmArticle.getWxOpenid());
if (memInfo.getGoldCoinsCount() - payCount < 0){
throw new CyServiceException(1003,"金币余额不足,请先充值");
}
memInfo.setGoldCoinsCount(memInfo.getGoldCoinsCount() - payCount);
memInfoRepository.updateById(memInfo);
//增加操作
redisTemplate.opsForValue().increment(OpmArticleRedisBean.USER_ARTICLE_COUNT + date + ":" + userId,1L);
}
memInfo.setGoldCoinsCount(memInfo.getGoldCoinsCount() - payCount);
memInfoRepository.updateById(memInfo);
lock.unlock();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
lock.unlock();
isGetLock = false;
throw new CyServiceException(1004,"服务器繁忙,请稍后再试");
}
lock.unlock();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
lock.unlock();
isGetLock = false;
throw new CyServiceException(1004,"服务器繁忙,请稍后再试");
} else {
//不进行发表动态
throw new CyServiceException(1002,"今日发表动态免费次数超出限制");
}
} else {
//没超过免费次数限制
//增加操作
redisTemplate.opsForValue().increment(OpmArticleRedisBean.USER_ARTICLE_COUNT + date + ":" + userId,1L);
}
}
//3、进行审核 从redis获取动态审核配置 0:自动审核,1:人工审核
......@@ -164,8 +178,6 @@ public class OpmArticleServiceImpl extends ServiceImpl<OpmArticleRepository, Opm
}
}
//增加操作
cyRedisServiceImpl.incr(OpmArticleRedisBean.USER_ARTICLE_COUNT + date + ":" + userId,1L);
int line = baseMapper.insert(opmArticle);
log.debug(CyUserUtil.getAuthenUsername()+"新增了ID为"+
opmArticle.getBusinessId()+"的opmArticle管理信息");
......
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