/**
   * @param rebateModel
   * @return
   */
  public int doAwardItemOwnerWithBuy(DcRebateModel rebateModel) {
    if (rebateModel.getItemOwnerUserId() == null
        || rebateModel.isPgcOwner()
        || rebateModel.isUserSelf()) {
      return 0;
    }
    int integral = (int) (rebateModel.getIntegralCount() * 0.1);
    integral = integral > 20 ? 20 : integral;
    DcUserIntegralDetailDTO integralDetail = new DcUserIntegralDetailDTO();
    integralDetail.setUserId(rebateModel.getItemOwnerUserId());
    integralDetail.setIntegralCount(integral);
    integralDetail.setSource(DcIntegralSourceEnums.BUY_UGC);
    DcIntegralDesc desc = new DcIntegralDesc();
    desc.setFromObjId(rebateModel.getItemId());
    desc.setFromObjName(rebateModel.getItemTitle());
    desc.setToObjId(rebateModel.getItemOwnerUserId());
    try {
      DcUserDTO user = dcUserService.getUser(rebateModel.getItemOwnerUserId());
      if (user != null) {
        desc.setToObjName(user.getNick());
      }
    } catch (Exception e) {

    }
    integralDetail.setIntegralDesc(desc);
    try {
      _doWithIntegral(integralDetail);
      return integral;
    } catch (Exception e) {
      logger.error(e);
      return 0;
    }
  }
 /**
  * 是否有足够的积分
  *
  * @param userId
  * @param integralCount
  * @return
  */
 public boolean hasEnoughIntegral(long userId, DcIntegralSourceEnums source) {
   int integralCount = source.getAwardIntegral();
   if (integralCount >= 0) {
     return true;
   }
   DcUserDTO user = dcUserService.getUser(userId);
   int userIntegral = IntegerUtils.parseInt(user.getIntegralCount());
   if (userIntegral >= Math.abs(integralCount)) {
     return true;
   }
   return false;
 }
 private boolean _doWithIntegral(DcUserIntegralDetailDTO detail)
     throws IntegralNotEnoughException {
   if (detail == null) {
     return false;
   }
   int effectCount = 0;
   int integralCount = IntegerUtils.parseInt(detail.getIntegralCount());
   // 竞拍成功前不消耗用户积分.
   if (detail.getSourceEnum() != DcIntegralSourceEnums.AUCTION_BID) {
     if (integralCount > 0) {
       effectCount = dcUserService.incrIntegralByUser(detail.getUserId(), Math.abs(integralCount));
     } else if (integralCount < 0) {
       DcIntegralSourceEnums source = detail.getSourceEnum();
       if (!hasEnoughIntegral(detail.getUserId(), source)) {
         throw new IntegralNotEnoughException();
       }
       effectCount = dcUserService.decrIntegralByUser(detail.getUserId(), Math.abs(integralCount));
     }
   }
   if (detail.getSourceEnum() != DcIntegralSourceEnums.WINNER_GANE) {
     dcMessageService.addIntegralMessage(detail, true);
   }
   return true;
 }
  /**
   * 更新审核状态
   *
   * @return
   */
  public String updateReviewStatus() {

    if (IDUtils.isNotCorrect(id)) {
      json.setCode(JsonModel.CODE_ILL_ARGS);
      json.setDetail("dcome.promotion.award.id.required");
      return SUCCESS;
    }

    DcPromotionAwardReviewStatusEnums statusEnums =
        DcPromotionAwardReviewStatusEnums.getInstance(status);

    if (statusEnums == DcPromotionAwardReviewStatusEnums.UNKNOWN) {
      json.setCode(JsonModel.CODE_ILL_ARGS);
      json.setDetail("dcome.promotion.award.status.required");
      return SUCCESS;
    }
    try {
      int effectCount = dcPromotionAwardService.updateReviewStatusById(id, statusEnums);
      if (effectCount > 0) {
        // 更新该会员的未读消息
        DcPromotionAwardDTO awardDO = dcPromotionAwardService.getAwardById(id);
        if (awardDO != null) {
          Long userId = awardDO.getUserId();
          if (IDUtils.isCorrect(userId)) {
            dcUserService.incrUnreadMsgCountByUser(userId, 1); // 添加一条未读消息
          }
        }
      }
      json.setCode(JsonModel.CODE_SUCCESS);
    } catch (Exception e) {
      log.error(e.getMessage(), e);
      json.setCode(JsonModel.CODE_FAIL);
      json.setDetail(e.getMessage());
    }

    return SUCCESS;
  }
  @Override
  public String execute() throws Exception {

    DcUserDTO user = dcAuthz.getUser();

    if (user == null) {
      json.setCode(JsonModel.CODE_ILL_ARGS);
      json.setDetail("dcome.user.notLogin");
      return SUCCESS;
    }

    Long userId = user.getUserId();

    List<DcWinnerGameConfigDTO> configList = dcWinnerGameConfigService.getConfigs();

    // 没有配置
    if (CollectionUtils.isEmpty(configList)) {
      json.setCode(JsonModel.CODE_ILL_ARGS);
      json.setDetail("dcome.winner.config.error");
      return SUCCESS;
    }

    // 今天是不是已经玩了太多次 ,每天最多玩10次// TODO 需要优化。目前是直接COUNT
    if (!dcUserFilterService.isWhiteListUser(userId)) {
      int todayPlayCount = dcWinnerGamePlayDetailService.countTodayPlayDetaiByUser(userId);

      if (todayPlayCount > 10) {
        json.setCode(JsonModel.CODE_ILL_ARGS);
        json.setDetail("dcome.winner.play.limit");
        return SUCCESS;
      }
    }

    List<KeyValuePair> betParamList = DcWinnerGameUtils.parseBetParam(betParam);
    if (CollectionUtils.isEmpty(betParamList)) {
      // 没有下注
      json.setCode(JsonModel.CODE_ILL_ARGS);
      json.setDetail("dcome.winner.config.betParam.error");
      return SUCCESS;
    }

    // 计算要消耗多少积分
    int needIntegralCount = DcWinnerGameUtils.calcIntegral(betParamList);

    try {

      // 生成随机数
      int randomNum = RandomUtils.nextInt(new Random(System.currentTimeMillis()), 10000);

      DcWinnerGameConfigParser configParser = new DcWinnerGameConfigParser(configList);

      DcWinnerGameConfigDTO winConfig = configParser.win(randomNum);

      if (winConfig == null) {
        json.setCode(JsonModel.CODE_ILL_ARGS);
        json.setDetail("dcome.winner.config.error");
        return SUCCESS;
      }

      // 把分数加到积分
      dcUserService.updateWinnerScoreToIntegralByUser(userId);

      // kou扣除积分
      int comsumeIntegral = dcUserIntegralBO.doWinnerGame(userId, -needIntegralCount);

      DcWinnerGameResultModel resultModel = new DcWinnerGameResultModel();
      resultModel.setBetParamList(betParamList);
      resultModel.setWinCardName(winConfig.getCardName());
      resultModel.setWinCardScore(winConfig.getScore());

      int totalScore = DcWinnerGameUtils.calcTotalWinScore(betParamList, winConfig);

      dcUserService.incrWinnerScoreByUser(userId, totalScore);

      resultModel.setWinScore(totalScore);

      DcUserDTO userdto = dcUserService.getUser(userId);
      int integral = userdto.getIntegralCount();
      resultModel.setUserIntegralCount(integral);

      // 插入detail
      DcWinnerGamePlayDetailDO detail = new DcWinnerGamePlayDetailDO();
      detail.setBetParam(JacksonHelper.toJSON(betParamList));
      detail.setUserId(userId);
      detail.setUserNick(user.getNick());
      detail.setWinScore(totalScore);
      detail.setResult(JacksonHelper.toJSON(resultModel));
      detail.setBetIntegral(Math.abs(comsumeIntegral));
      dcWinnerGamePlayDetailService.insertPlayDetail(detail);

      json.setCode(JsonModel.CODE_SUCCESS);
      json.setData(resultModel);

    } catch (IntegralNotEnoughException e) {
      // 积分不足
      json.setCode(JsonModel.CODE_ILL_ARGS);
      json.setDetail("dcome.winner.user.integral.notEnough");
      return SUCCESS;
    } catch (Exception e) {
      json.setCode(JsonModel.CODE_FAIL);
      return SUCCESS;
    }

    return SUCCESS;
  }