Authored by Lixiaodi

微信抽奖代码提交

... ... @@ -74,8 +74,10 @@
<select id="selectOrderRecordIds" resultType="java.lang.Integer">
select id
from lottery_record_${shardFactor}
where lottery_id = #{lotteryId,jdbcType=INTEGER}
and uid = #{userId,jdbcType=INTEGER}
where uid = #{userId,jdbcType=INTEGER}
<if test="lotteryId != null">
and lottery_id = #{lotteryId,jdbcType=INTEGER}
</if>
<if test="orderCode != null and orderCode !=''">
and flag = #{orderCode,jdbcType=INTEGER}
</if>
... ...
... ... @@ -60,9 +60,16 @@ public class LotteryServiceImpl implements ILotteryService , ApplicationContextA
private static final int STATE_USE_HAVA_PRIZE = 1;
/** 已抽奖:未中奖. */
private static final int STATE_USE_NO_PRIZE = 2;
/** 用户抽奖不能多个客户端一起抽奖. */
private static final int STATE_MULTI = 3;
/** 不符合抽奖条件. */
private static final int STATE_NOT = 3;
private static final String MSG_NO_PRIZE = "差一点就中奖啦!";
private static final String MSG_HAVE_PRIZE = "恭喜您,中奖啦!";
private static final String MSG_MULTI = "用户抽奖不能多个客户端一起抽奖!";
private static final String MSG_NOT = "不符合抽奖条件";
private ThreadPoolExecutor executor = new ThreadPoolExecutor(12, 24, 0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>());
... ... @@ -166,9 +173,13 @@ public class LotteryServiceImpl implements ILotteryService , ApplicationContextA
@Override
public LotteryRespData lucky(Integer lotteryId, Integer userId, String orderCode) {
logger.info("用户{}的订单{}进行抽奖!", userId, orderCode);
boolean isIn = yhValueOperations.setIfAbsent(userId.toString(), "IN");
if(!isIn) {
boolean isIn = yhValueOperations.setIfAbsent("yh:activity:lucky:uid:"+userId.toString(), "IN");
if (!isIn) {
logger.info("用户{}的抽奖不能多个客户端一起抽奖!", userId);
LotteryRespData state = new LotteryRespData();
state.setOrderLotteryCode(STATE_MULTI);
state.setOrderLotteryMessage(MSG_MULTI);
return state;
}
... ... @@ -186,7 +197,10 @@ public class LotteryServiceImpl implements ILotteryService , ApplicationContextA
Map<String, LotteryRecord> recordMap = orderLotteryState.getLotteryRecordMap();
if (recordMap.containsKey(orderCode)) {
logger.info("用户{}的订单{}不符合抽奖条件!", userId, orderCode);
return orderLotteryState;
LotteryRespData state = new LotteryRespData();
state.setOrderLotteryCode(STATE_NOT);
state.setOrderLotteryMessage(MSG_NOT);
return state;
}
// 本活动中奖次数
// int lotteryCount = lotteryRecordMapper.selectUserLotteryPrizeCount(lotteryId, userId, userId % 10);
... ...