/** * 修改直播课 * * @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; }
/** * 创建动态 * * @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()); } }