コード例 #1
0
  /**
   * 初始化活动
   *
   * @param pai
   * @return
   */
  private Activity transFormActInfo(XQActivityVO pai) {
    Activity activity = new Activity();
    activity.setId(pai.getActId());
    activity.setName(pai.getActTitle());
    activity.setDetails(pai.getActDesc());
    activity.setApplyDesc(pai.getApplyDesc());
    activity.setCreatedAt(new Date());
    activity.setType(pai.getActType());
    activity.setImg(xq_default_img);
    activity.setBanner(xq_default_banner);
    activity.setUrl(pai.getActUrl());
    activity.setTagImage(pai.getActTagImage());
    activity.setActTagType(pai.getActTagType());
    activity.setCreatorId(pai.getCreateOper());

    // 时间初始化
    if (pai.getActStartTime() != null) {
      activity.setStartTime(new Date(pai.getActStartTime()));
    }

    if (pai.getActEndTime() != null) {
      activity.setEndTime(new Date(pai.getActEndTime()));
    }

    if (pai.getApplyStartTime() != null) {
      activity.setApplyStartTime(new Date(pai.getApplyStartTime()));
    }

    if (pai.getApplyEndTime() != null) {
      activity.setApplyEndTime(new Date(pai.getApplyEndTime()));
    }

    // 活动所属
    if (ActivityChannel.XIANGQU.equals(pai.getActChannel())) {
      activity.setChannel(ActivityChannel.XIANGQU);
    }

    // 活动状态
    if (ActivityType.PUBLIC_FOREVER.equals(pai.getActType())) {
      activity.setStatus(ActivityStatus.IN_PROGRESS);
    } else {
      activity.setStatus(ActivityStatus.NOT_STARTED);
    }

    return activity;
  }
コード例 #2
0
  /**
   * 检查活动是否合法 创建的时候:创建人,活动类型,标题
   *
   * @param pai
   * @param domain
   */
  private void actCreateChk(XQActivityVO pai, String domain) {
    if (pai == null) {
      throw new BizException(GlobalErrorCode.INVALID_ARGUMENT, "活动不能为空");
    }
    domain = StringUtils.defaultIfBlank(domain, "xiangqu");

    // 创建人
    if (StringUtils.isBlank(pai.getCreateOper())) {
      throw new BizException(GlobalErrorCode.INVALID_ARGUMENT, "创建人不能为空");
    } else {
      User user = null;
      if (!StringUtils.isBlank(pai.getExtUid())) {
        user = userService.loadExtUser(domain, pai.getExtUid());
      } else if (!StringUtils.isBlank(pai.getCreateOper())) {
        user = userService.loadExtUser(domain, pai.getCreateOper());
      } else {
        user = userService.loadByAdmin(pai.getCreateOper());
      }

      if (user == null || !domain.equals(user.getPartner())) {
        log.debug("用户不存在");
        throw new BizException(GlobalErrorCode.INVALID_ARGUMENT, "用户不存在");
      }

      if (StringUtils.isBlank(pai.getShopId())) {
        pai.setShopId(user.getShopId());
      }
    }

    if (StringUtils.isBlank(pai.getActId())) {
      // 活动名称
      if (StringUtils.isBlank(pai.getActTitle())) {
        throw new BizException(GlobalErrorCode.THIRDPLANT_BUZERROR, "活动名称不能为空");
      }

      // 活动永久的,不需要时间信息
      if (ActivityType.PUBLIC_FOREVER.equals(pai.getActType())) {
        pai.setActState(ActivityStatus.IN_PROGRESS);
        return;
      }

      pai.setActState(ActivityStatus.NOT_STARTED);
      if (pai.getActStartTime() == null || pai.getActEndTime() == null) {
        throw new BizException(GlobalErrorCode.THIRDPLANT_BUZERROR, "活动开始或结束时间不能为空");
      }

      // 活动报名时间
      if (pai.getApplyEndTime() != null
          && pai.getApplyStartTime() != null
          && pai.getApplyEndTime() > pai.getActStartTime()) {
        throw new BizException(GlobalErrorCode.THIRDPLANT_BUZERROR, "活动报名 截止时间不能大于开始时间");
      }
    }
  }