Example #1
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;
  }
Example #2
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;
  }