Authored by Lixiaodi

提交未抽奖service

  1 +/**
  2 + *
  3 + */
  4 +package com.yoho.activity.service.impl;
  5 +
  6 +import java.util.List;
  7 +
  8 +import javax.annotation.Resource;
  9 +
  10 +import org.apache.commons.collections.CollectionUtils;
  11 +import org.slf4j.Logger;
  12 +import org.slf4j.LoggerFactory;
  13 +import org.springframework.stereotype.Service;
  14 +
  15 +import com.alibaba.fastjson.JSON;
  16 +import com.yoho.activity.common.ApiResponse;
  17 +import com.yoho.activity.common.vo.ActVoteResultVO;
  18 +import com.yoho.activity.dal.ActVoteResultMapper;
  19 +import com.yoho.activity.dal.model.ActVoteResult;
  20 +import com.yoho.activity.service.IActVoteResultService;
  21 +import com.yoho.core.common.utils.DateUtil;
  22 +
  23 +/**
  24 + * 描述:
  25 + */
  26 +@Service
  27 +public class LotteryServiceImpl implements IActVoteResultService {
  28 +
  29 + static Logger log = LoggerFactory.getLogger(LotteryServiceImpl.class);
  30 +
  31 + @Resource
  32 + private ActVoteResultMapper actVoteResultMapper;
  33 +
  34 + @Override
  35 + public ApiResponse selectVoteNumByUid(int uid) throws Exception {
  36 + log.info("selectVoteNumByUid with uid={}", uid);
  37 + List<ActVoteResult> votedList = actVoteResultMapper.selectActVoteResultByUid(uid);
  38 + log.info("selectVoteNumByUid success. uid={}", uid);
  39 + return new ApiResponse(votedList);
  40 + }
  41 +
  42 + @Override
  43 + public ApiResponse insertVoteResultInfo(ActVoteResultVO voteResult) throws Exception {
  44 + log.info("insertVoteResultInfo with voteResult={}", voteResult);
  45 +
  46 + List<ActVoteResult> votedList = actVoteResultMapper.selectActVoteResultByUid(voteResult.getUid());
  47 + if (CollectionUtils.isNotEmpty(votedList) && votedList.size() > 0) {
  48 + log.warn("insertVoteResultInfo error voteResult={}", voteResult);
  49 + return new ApiResponse(201, "您已经投过票了");
  50 + }
  51 +
  52 + List<ActVoteResult> actVoteResult = JSON.parseArray(voteResult.getItemIds(), ActVoteResult.class);
  53 + if (actVoteResult.size() == 0) {
  54 + log.warn("insertVoteResultInfo with actVoteResult empty. ");
  55 + return new ApiResponse(201, "您还没有投票");
  56 + }
  57 + for (ActVoteResult act : actVoteResult) {
  58 + act.setCreateTime(DateUtil.getCurrentTimeSecond());
  59 + }
  60 + actVoteResultMapper.insertBatch(actVoteResult);
  61 + log.info("insertVoteResultInfo success. voteResult={}", voteResult);
  62 + return new ApiResponse();
  63 + }
  64 +}