예제 #1
0
  /**
   * 创建直播
   *
   * @param url
   * @param currUser
   * @param sourceId
   * @param groupName
   * @param groupLogoUrl
   * @return
   * @throws XueWenServiceException
   */
  public Live create(
      String url, User currUser, String sourceId, String groupName, String groupLogoUrl)
      throws XueWenServiceException {
    List<JSONObject> groupList = new ArrayList<JSONObject>();
    JSONObject group = new JSONObject();
    group.put("groupId", sourceId);
    group.put("groupName", groupName);
    group.put("groupLogoUrl", groupLogoUrl);
    groupList.add(group);
    if (!this.exiseByUrl(url)) {
      if (!StringUtil.isBlank(url)) {
        // 判断此url是否已经被创建
        if (url.contains(Config.LIVE_URL_VHSTART)) {
          try {
            return this.createVhLive(url, groupList, currUser);
          } catch (Exception e) {
            throw new XueWenServiceException(Config.STATUS_201, "创建直播错误", null);
          }
        }
      }
    } else {
      Live l = this.findByLiveUrl(url);
      List<JSONObject> groups = l.getGroup();
      for (JSONObject g : groups) {
        if (sourceId.equals(g.getString("groupId"))) {
          throw new XueWenServiceException(Config.STATUS_201, "此直播已存在", null);
        }
      }
      groups.addAll(groupList);
      return liveRepo.save(l);
    }

    throw new XueWenServiceException(Config.STATUS_201, "创建直播失败", null);
  }
예제 #2
0
  /**
   * 分享直播
   *
   * @param liveId
   * @param group
   * @param currUser
   * @return
   * @throws XueWenServiceException
   */
  public boolean share(String liveId, String source, User currUser) throws XueWenServiceException {
    Live liveResult = liveRepo.findOne(liveId);
    if (liveResult == null) {
      throw new XueWenServiceException(Config.STATUS_201, Config.MSG_NODATA_201, null);
    }
    List<JSONObject> newAddGroups = new ArrayList<JSONObject>();
    if (!StringUtil.isBlank(source)) {
      List<JSONObject> groupList = JSON2ObjUtil.getDTOList(source, JSONObject.class);
      newAddGroups.addAll(groupList);
      List<JSONObject> oldGroup = liveResult.getGroup();
      // 取新增的群组
      newAddGroups.removeAll(oldGroup);
      liveResult.getGroup().addAll(newAddGroups);
    }

    liveRepo.save(liveResult);
    for (JSONObject obj : newAddGroups) {
      try {
        // 创建群组动态
        this.createGroupDynamic(liveResult, obj.getString("groupId"));
      } catch (Exception e) {
        l.error("======创建活动群组动态失败:========" + e);
      }
    }
    return true;
  }
예제 #3
0
 /**
  * 创建动态
  *
  * @param a
  * @param groupId
  * @throws XueWenServiceException
  */
 private void createGroupDynamic(Live a, String groupId) throws XueWenServiceException {
   if (a != null && !StringUtil.isBlank(groupId)) {
     groupDynamicService.addGroupDynamic(
         groupId,
         "",
         "",
         a.getId(),
         a.getTitle(),
         a.getIntro(),
         "",
         a.getImages(),
         a.getCreateUser(),
         a.getCreateUserName(),
         a.getCreateUserLogoUrl(),
         Config.TYPE_LIVE_GROUP,
         a.getCtime());
   }
 }
예제 #4
0
  /**
   * 删除直播
   *
   * @param liveId
   * @param groupId
   * @param currUser
   * @return
   * @throws XueWenServiceException
   */
  public boolean delete(String liveId, String groupId, User currUser)
      throws XueWenServiceException {
    Live live = liveRepo.findOne(liveId);
    if (StringUtil.isBlank(groupId)) { // 创建者删除
      if (currUser.getId().equals(live.getCreateUser())) {
        liveRepo.delete(live);
        for (JSONObject obj : live.getGroup()) {
          try {
            // 删除群组动态
            this.deleteByGroupIdAndSourceId(obj.getString("groupId"), live.getId());
          } catch (Exception e) {
            l.error("======创建活动群组动态失败:========" + e);
          }
        }
        return true;
      } else {
        throw new XueWenServiceException(Config.STATUS_201, Config.MSG_NOACESS_201, null);
      }

    } else { // 从小组里删除直播
      XueWenGroup group = groupService.findByid(groupId);
      if (group != null) {
        if (group.getOwner().contains(currUser.getId())) {
          JSONObject[] str = new JSONObject[3];
          str[0] = JSONObject.fromObject(groupId);
          ;
          str[1] = JSONObject.fromObject(group.getGroupName());
          str[2] = JSONObject.fromObject(group.getLogoUrl());
          List<JSONObject> stooges = Arrays.asList(str);
          List<JSONObject> newAddGroups = live.getGroup();
          newAddGroups.removeAll(stooges);
          live.setGroup(newAddGroups);
          // 删除去掉的群组动态
          for (JSONObject obj : stooges) {
            try {
              this.deleteByGroupIdAndSourceId(obj.getString("groupId"), live.getId());
            } catch (Exception e) {
              l.error("======创建活动群组动态失败:========" + e);
            }
          }
        }
      }
    }

    liveRepo.save(live);
    return true;
  }
예제 #5
0
  /**
   * 修改直播课
   *
   * @param activityId
   * @param currUser
   * @param live
   * @return
   */
  public Live update(String liveId, User currUser, Live live, String image, String group)
      throws XueWenServiceException {
    Live liveResult = liveRepo.findOne(liveId);
    if (liveResult == null) {
      throw new XueWenServiceException(Config.STATUS_201, Config.MSG_NODATA_201, null);
    }
    if (!StringUtil.isBlank(image)) { // 如果图片不为空
      List<Images> imageList = JSON2ObjUtil.getDTOList(image, Images.class);
      liveResult.setImages(imageList);
    }
    // 去掉的群组
    List<JSONObject> removeGroup = new ArrayList<JSONObject>(); // 去掉的群组列表
    List<JSONObject> addGroup = new ArrayList<JSONObject>(); // 新增的群组列表

    if (!StringUtil.isBlank(group)) { // 如果分享的群不为空
      List<JSONObject> groupList = JSON2ObjUtil.getDTOList(group, JSONObject.class);
      List<JSONObject> oldGroupList = liveResult.getGroup(); // 原有的群组列表

      addGroup.addAll(groupList); // 修改后的群组列表
      addGroup.removeAll(oldGroupList); // 新增的群组
      removeGroup.addAll(oldGroupList); // 以前有的群组列表
      removeGroup.removeAll(groupList); // 删除的群组列表

      liveResult.setGroup(groupList);
    }
    if (!StringUtil.isBlank(live.getIntro())) {
      liveResult.setIntro(live.getIntro());
    }
    if (!StringUtil.isBlank(live.getTitle())) {
      liveResult.setTitle(live.getTitle());
    }
    if (live.getLiveEndTime() != 0) {
      liveResult.setLiveEndTime(live.getLiveEndTime());
    }
    if (live.getLiveStartTime() != 0) {
      liveResult.setLiveStartTime(live.getLiveStartTime());
    }
    live = liveRepo.save(liveResult);
    /** 新增的群组添加动态 */
    for (JSONObject obj : addGroup) {
      try {
        // 创建群组动态
        this.createGroupDynamic(liveResult, obj.getString("groupId"));
      } catch (Exception e) {
        l.error("======创建活动群组动态失败:========" + e);
      }
    }
    // 删除去掉的群组动态
    for (JSONObject obj : removeGroup) {
      try {
        // 创建群组动态
        this.deleteByGroupIdAndSourceId(obj.getString("groupId"), liveResult.getId());
      } catch (Exception e) {
        l.error("======创建活动群组动态失败:========" + e);
      }
    }
    return live;
  }