| | |
| | | import com.ks.goldcorn.pojo.DO.*; |
| | | import com.ks.goldcorn.service.GoldCornBalanceManager; |
| | | import com.ks.goldcorn.service.GoldCornRecordManager; |
| | | import com.ks.goldcorn.util.JedisUtil; |
| | | import org.apache.dubbo.config.annotation.Service; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import redis.clients.jedis.Jedis; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.concurrent.TimeUnit; |
| | |
| | | |
| | | @Resource |
| | | private RedisManager redisManager; |
| | | |
| | | @Resource |
| | | private JedisUtil jedisUtil; |
| | | |
| | | /** |
| | | * 验证系统与用户 |
| | |
| | | throw new GoldUserException(GoldTradeException.CODE_NOT_EXIST, "source is not exist"); |
| | | } |
| | | |
| | | |
| | | String key = appCode + "-" + uid + "-" + sourceCode; |
| | | if (!redisTemplate.opsForValue().setIfAbsent(key, 1, 60 * 2, TimeUnit.SECONDS)) { |
| | | try { |
| | | jedisUtil.excute(new JedisUtil.JedisExcuter() { |
| | | @Override |
| | | public void execute(Jedis jedis) throws Exception { |
| | | if (jedis.setnx(key, "1") <= 0) { |
| | | throw new GoldTradeException(GoldTradeException.CODE_FREQUENCY_LIMIT, "请求频率过高,请稍后再试"); |
| | | } |
| | | jedis.expire(key, 60 * 2); |
| | | try { |
| | | int count = redisManager.getGoldCornAddRecordCount(appCode, uid, sourceCode); |
| | | if (count >= source.getMaxDayCount()) { |
| | |
| | | } catch (GoldTradeException e) { |
| | | throw e; |
| | | } catch (Exception e) { |
| | | logger.error("添加金币未知异常:{}", e); |
| | | |
| | | } finally { |
| | | redisTemplate.delete(key); |
| | | jedis.del(key); |
| | | } |
| | | |
| | | } |
| | | }); |
| | | } catch (GoldTradeException e) { |
| | | throw e; |
| | | } catch (GoldUserException e) { |
| | | throw e; |
| | | } catch (Exception e) { |
| | | logger.error("添加金币未知异常:{}", e); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |