派生自 projectDept/qhighschool

EricsHu
2022-12-05 068fc7f2e81178e55fa191a13709af64b1a163f6
src/main/java/com/qxueyou/scc/operation/topic/service/impl/TopicService.java
@@ -50,7 +50,7 @@
import com.qxueyou.scc.user.service.IUserService;
/**
 * 话题服务层
 * 话题服务层
 *
 * @author chenjunliang
 */
@@ -92,7 +92,7 @@
                    + " c.commentObjectId =o.commentObjectId and o.commentObjectType = 5";
            List<Map<String, Object>> commentIdLst = findListWithMapByHql(findPeopleCountByHql,
                    CollectionUtils.newObjectMap("topicId", topicId));
            int peopleCount = commentIdLst.size();// 参与人数
            int peopleCount = commentIdLst.size();// 参与人数
            map.put("peopleCount", peopleCount);
        }
        return new Result(true, "success",
@@ -136,7 +136,7 @@
        String hql = "from CommentObject where deleteFlag is false and commentObjectUid = ? and commentObjectType = 5";
        CommentObject commentObject = findUnique(hql, CollectionUtils.newList(topicId), CommentObject.class);
        BigInteger viewCount = commentObject.getViewCount();
        commentObject.setViewCount(viewCount.add(new BigInteger("1")));// 查看条数+1
        commentObject.setViewCount(viewCount.add(new BigInteger("1")));// 查看条数+1
        BigInteger viewCount2Json = commentObject.getViewCount();
        BigInteger commentPraiseCount = commentObject.getCommentPraiseCount();
        TraceUtils.setUpdateTrace(commentObject);
@@ -154,7 +154,7 @@
                + " c.commentObjectId =o.commentObjectId and o.commentObjectType = 5";
        List<Map<String, Object>> commentIdLst = findListWithMapByHql(findPeopleCountByHql,CollectionUtils.newObjectMap("topicId", topicId));
        int peopleCount = commentIdLst.size();// 参与人数
        int peopleCount = commentIdLst.size();// 参与人数
        
        return new Result(true, "success",
                CollectionUtils.newObjectMap("topicId", topicId,"topicType", topic.getTopicType(), "createTime", topic.getCreateTime(), "topicName", topic.getTopicName(), "issuer",
@@ -168,7 +168,7 @@
    public Result addTopicInfo(TopicInfo topicInfo) {
//       if(topicInfo.getTopicType()==TopicInfo.TOPIC_TYPE_CLS && StringUtils.isEmpty(topicInfo.getClassId())) {
       if(StringUtils.isEmpty(topicInfo.getClassId())) {
          return new Result(false, "请选择关联班级!");
          return new Result(false, "请选择关联班级!");
       }
       String classId = topicInfo.getClassId();
       topicInfo.setTopicId(null);
@@ -185,7 +185,7 @@
                topicClassRe.setClassId(classIds[i]);
                topicClassRe.setTopicId(topicInfo.getTopicId());
                TraceUtils.setCreateTrace(topicClassRe);
                save(topicClassRe);// 保存到中间表
                save(topicClassRe);// 保存到中间表
            }
        }
        
@@ -199,7 +199,7 @@
        commentObject.setCommentCount(initParam);
        commentObject.setCommentPraiseCount(initParam);
        commentObject.setViewCount(initParam);
        save(commentObject);// 创建评论对象
        save(commentObject);// 创建评论对象
        return new Result(true, "add success");
    }
@@ -267,23 +267,23 @@
        Map<String, Object> mapJson = new HashMap<String, Object>();
        String name = clsClass.getName();
        String imgPath = clsClass.getImgPath();
        int topicCount = findCountByComplexHql(// 获取话题条数
        int topicCount = findCountByComplexHql(// 获取话题条数
                "select count(1) from TopicClassRe r  where deleteFlag is false and classId =:classId",
                CollectionUtils.newObjectMap("classId", classId));
        String findTopicIdLst = "select topicId as topicId from TopicClassRe where deleteFlag is false and classId=:classId";
        List<Map<String, Object>> topicIdLst = findListWithMapByHql(findTopicIdLst, // 获取班级所有话题的id
        List<Map<String, Object>> topicIdLst = findListWithMapByHql(findTopicIdLst, // 获取班级所有话题的id
                CollectionUtils.newObjectMap("classId", classId));
        int commentCount = 0;
        int studentCommentCount = 0;
        for (Map<String, Object> map : topicIdLst) {
            String topicId = (String) map.get("topicId");
            CommentObject commentObject = findUnique(// 获取话题的评论条数
            CommentObject commentObject = findUnique(// 获取话题的评论条数
                    "from CommentObject where deleteFlag is false and commentObjectUid = ? and commentObjectType = 5",
                    CollectionUtils.newList(topicId), CommentObject.class);
            BigInteger BigcommentCount = commentObject.getCommentCount();
            int count = BigcommentCount.intValue();
            commentCount += count;
            List<Map<String, Object>> lstCommentId = findListWithMapByHql(// 获取回复话题的评论人数
            List<Map<String, Object>> lstCommentId = findListWithMapByHql(// 获取回复话题的评论人数
                    "select distinct c.commentterId as  commentterId from CommentObject o,Comment c where o.deleteFlag is false and o.commentObjectUid =:topicId and"
                            + " c.commentObjectId =o.commentObjectId and o.commentObjectType = 5",
                    CollectionUtils.newObjectMap("topicId", topicId));
@@ -305,7 +305,7 @@
                + " and c.commentObjectId=o.commentObjectId and o.commentObjectUid =:topicId order by c.createTime desc";
        List<Map<String, Object>> commentLst = findListWithMapByHql(hql,
                CollectionUtils.newObjectMap("topicId", topicId), new Pager(pageSize, pageNum));
        int commentCount = findCountByComplexHql(// 获取总条数
        int commentCount = findCountByComplexHql(// 获取总条数
                "select count(1) from Comment c ,CommentObject o where c.deleteFlag is false and o.deleteFlag is false"
                + "  and c.commentObjectId=o.commentObjectId and o.commentObjectUid =:topicId and o.commentObjectType = 5",
                CollectionUtils.newObjectMap("topicId", topicId));
@@ -317,14 +317,14 @@
            User user = read(User.class, userId);
            String imgPath = user.getImgPath();
            map.put("imgPath", imgPath);
            // 获取每条评论的点赞数 ;
            // 获取每条评论的点赞数 ;
            String findPraiseCountByHql = "select count(1) from CommentPraise where deleteFlag is false and commentId =:commentId";
            int praiseCount = findCountByComplexHql(findPraiseCountByHql,
                    CollectionUtils.newObjectMap("commentId", commentId));
            map.put("praiseCount", praiseCount);
            map.put("commentCount", findCountByComplexHql("select count(1) from Comment where deleteFlag is false and commentParentId =:commentId",
                    CollectionUtils.newObjectMap("commentId", commentId)));
            // 获取回复这个评论的自评论内容
            // 获取回复这个评论的自评论内容
            String findSubCommentDetailByhql = "select commentter as commentter ,content as commentContent ,createTime as commentTime from  Comment "
                    + " where deleteFlag is false and  commentId =:commentParentId ";
            List<Map<String, Object>> subCommentDetail = findListWithMapByHql(findSubCommentDetailByhql,
@@ -448,14 +448,14 @@
    public Result deleteMycomment(String commentId) {
        Comment comment = read(Comment.class, commentId);
        if(!comment.getCreateId().equals(ClientUtils.getUserId())) {
           return new Result(false, "只能删除自己发布的信息");
           return new Result(false, "只能删除自己发布的信息");
        }
        comment.setDeleteFlag(true);
        TraceUtils.setCreateTrace(comment);
        save(comment);// 删除评论表的
        save(comment);// 删除评论表的
        String[] commentIds = commentId.split(",");
        this.bulkUpdateInLoop("update CommentPraise set deleteFlag = true where commentId = ?", commentIds);// 删除对应的点赞
        this.bulkUpdateInLoop("update CommentPraise set deleteFlag = true where commentId = ?", commentIds);// 删除对应的点赞
        return new Result(true, "success");
    }
@@ -512,7 +512,7 @@
        String hql = "from CommentObject where commentObjectUid=? and deleteFlag is false and commentObjectType = 5";
        CommentObject commentObject = findUnique(hql, CollectionUtils.newList(commentObjectId), CommentObject.class);
        BigInteger commentCount = commentObject.getCommentCount();
        commentObject.setCommentCount(commentCount.add(new BigInteger("1")));// 评论+1;
        commentObject.setCommentCount(commentCount.add(new BigInteger("1")));// 评论+1;
        TraceUtils.setUpdateTrace(commentObject);
        save(commentObject);
        Comment comment = new Comment();
@@ -543,13 +543,13 @@
    @Override
    public Result addPraise(String commentId, String commentObjectId) {
        if (StringUtils.isBlank(commentId)) {// 点赞话题
        if (StringUtils.isBlank(commentId)) {// 点赞话题
            String hql = "from CommentObject where deleteFlag is false and commentObjectUid = ? and commentObjectType = 5";
            CommentObject commentObject = findUnique(hql, CollectionUtils.newList(commentObjectId),
                    CommentObject.class);
            BigInteger commentPraiseCount = commentObject.getCommentPraiseCount();
            BigInteger one = new BigInteger("1");
            commentObject.setCommentPraiseCount(commentPraiseCount.add(one));// 点赞数+1
            commentObject.setCommentPraiseCount(commentPraiseCount.add(one));// 点赞数+1
            TraceUtils.setCreateTrace(commentObject);
            save(commentObject);
@@ -564,7 +564,7 @@
        commentPraise.setCommentterId(ClientUtils.getUserId());
        commentPraise.setCommentter(ClientUtils.getUserName());
        TraceUtils.setCreateTrace(commentPraise);
        save(commentPraise);// 保存到点赞表
        save(commentPraise);// 保存到点赞表
        
        return new Result(true, "success");
    }
@@ -574,51 +574,51 @@
        QCommentObject qCommentObject = QCommentObject.commentObject;
        QComment qComment = QComment.comment;
        QCommentPraise qCommentPraise = QCommentPraise.commentPraise;
        //我发的讨论数量
        //我发的讨论数量
        long topicCount = this.getQueryFactory().selectFrom(qTopicInfo).where(qTopicInfo.deleteFlag.isFalse().and(qTopicInfo.createId.eq(userId))).fetchCount();
        
        //我发的讨论的评论数
        //我发的讨论的评论数
      long topicCommentToMeCount = this.getQueryFactory().select(qCommentObject.commentCount.sum()).from(qCommentObject)
            .where(qCommentObject.deleteFlag.isFalse().and(qCommentObject.createId.eq(userId))
                  .and(qCommentObject.commentObjectType.eq(CommentObject.COMMENT_TYPE_INTERACT)))
            .fetchCount();
      //我发的评论的评论数
      //我发的评论的评论数
      long commentToMeCount = this.getQueryFactory().selectDistinct(qComment.commentId).from(qCommentObject, qComment)
            .where(qComment.deleteFlag.isFalse().and(qCommentObject.deleteFlag.isFalse())
                  .and(qCommentObject.createId.eq(userId)).and(qCommentObject.commentObjectUid.eq(qComment.commentObjectId))
                  .and(qCommentObject.commentObjectType.eq(CommentObject.COMMENT_TYPE_INTERACT)).and(qComment.commentParentId.isNotNull()))
            .fetchCount();
      
      //我评论的讨论的评论数
      //我评论的讨论的评论数
      long topicCommentCount = this.getQueryFactory().selectDistinct(qComment.commentId).from(qCommentObject, qComment)
            .where(qComment.deleteFlag.isFalse().and(qCommentObject.deleteFlag.isFalse())
                  .and(qComment.createId.eq(userId)).and(qCommentObject.commentObjectUid.eq(qComment.commentObjectId))
                  .and(qCommentObject.commentObjectType.eq(CommentObject.COMMENT_TYPE_INTERACT)).and(qComment.commentParentId.isNotNull()))
            .fetchCount();
      //我评论的数
      //我评论的数
      long commentCount = this.getQueryFactory().selectDistinct(qComment.commentId).from(qCommentObject, qComment)
            .where(qComment.deleteFlag.isFalse().and(qCommentObject.deleteFlag.isFalse())
                  .and(qComment.createId.eq(userId)).and(qCommentObject.commentObjectUid.eq(qComment.commentObjectId))
                  .and(qCommentObject.commentObjectType.eq(CommentObject.COMMENT_TYPE_INTERACT)).and(qComment.commentParentId.isNotNull()))
            .fetchCount();
      //我对讨论的点赞数
      //我对讨论的点赞数
      long topicPraise = this.getQueryFactory().selectDistinct(qCommentPraise.commentPraiseId).from(qCommentObject, qCommentPraise)
            .where(qCommentObject.deleteFlag.isFalse().and(qCommentPraise.createId.eq(userId))
                  .and(qCommentPraise.commentObjectId.eq(qCommentObject.commentObjectId)).and(qCommentPraise.deleteFlag.isFalse())
                  .and(qCommentObject.commentObjectType.eq(CommentObject.COMMENT_TYPE_INTERACT)))
            .fetchCount();
        //我对评论的点赞数
        //我对评论的点赞数
        long commentPraise = this.getQueryFactory().selectDistinct(qCommentPraise.commentPraiseId).from(qCommentObject, qComment, qCommentPraise)
            .where(qComment.deleteFlag.isFalse().and(qCommentObject.deleteFlag.isFalse()).and(qCommentPraise.commentId.eq(qComment.commentId))
                  .and(qCommentPraise.createId.eq(userId)).and(qCommentObject.commentObjectUid.eq(qComment.commentObjectId)).and(qCommentPraise.deleteFlag.isFalse())
                  .and(qCommentObject.commentObjectType.eq(CommentObject.COMMENT_TYPE_INTERACT)))
            .fetchCount();
        //我的讨论的点赞数
        //我的讨论的点赞数
        long topicPraiseToMe = this.getQueryFactory().select(qCommentObject.commentPraiseCount.sum()).from(qCommentObject)
            .where(qCommentObject.deleteFlag.isFalse().and(qCommentObject.createId.eq(userId))
                  .and(qCommentObject.commentObjectType.eq(CommentObject.COMMENT_TYPE_INTERACT)))
            .fetchCount();
        //我的讨论的点赞数
        //我的讨论的点赞数
        long commentPraiseToMe = this.getQueryFactory().selectDistinct(qCommentPraise.commentPraiseId).from(qCommentObject, qComment, qCommentPraise)
            .where(qComment.deleteFlag.isFalse().and(qCommentObject.deleteFlag.isFalse()).and(qCommentPraise.commentId.eq(qComment.commentId))
                  .and(qComment.createId.eq(userId)).and(qCommentObject.commentObjectUid.eq(qComment.commentObjectId)).and(qCommentPraise.deleteFlag.isFalse())
@@ -645,9 +645,9 @@
            save(topicInfo);
        }
        bulkUpdateInLoop("update Comment set deleteFlag = true where commentId = ?", topicIds);// 删除话题对应的评论;
        bulkUpdateInLoop("update Comment set deleteFlag = true where commentId = ?", topicIds);// 删除话题对应的评论;
        bulkUpdateInLoop("update TopicClassRe set deleteFlag = true where topicId = ?", topicIds);// 删除话题对应的班级;
        bulkUpdateInLoop("update TopicClassRe set deleteFlag = true where topicId = ?", topicIds);// 删除话题对应的班级;
        return new Result(true, "success");
    }
@@ -680,7 +680,7 @@
                    + " c.commentObjectId =o.commentObjectId and o.commentObjectType = 5";
            List<Map<String, Object>> commentIdLst = findListWithMapByHql(findPeopleCountByHql,
                    CollectionUtils.newObjectMap("topicId", topicId));
            int peopleCount = commentIdLst.size();// 参与人数
            int peopleCount = commentIdLst.size();// 参与人数
            map.put("peopleCount", peopleCount);
        }
        return new Result(true, "success",
@@ -692,11 +692,11 @@
       
//       if(editTopicInfo.getTopicType()==TopicInfo.TOPIC_TYPE_CLS && StringUtils.isEmpty(editTopicInfo.getClassId())) {
       if(StringUtils.isEmpty(editTopicInfo.getClassId())) {
          return new Result(false, "请选择关联班级!");
          return new Result(false, "请选择关联班级!");
       }
        TopicInfo topicInfo = read(TopicInfo.class, editTopicInfo.getTopicId());
        this.bulkUpdate("update TopicClassRe set deleteFlag = true where topicId = ?", new Object[] {topicInfo.getTopicId()});// 删除对应的中间表数据
        this.bulkUpdate("update TopicClassRe set deleteFlag = true where topicId = ?", new Object[] {topicInfo.getTopicId()});// 删除对应的中间表数据
        topicInfo.setTopicName(editTopicInfo.getTopicName());
        topicInfo.setTopicType(editTopicInfo.getTopicType());
        topicInfo.setTopicDesc(editTopicInfo.getTopicDesc());
@@ -715,7 +715,7 @@
                topicClassRe.setClassId(classIds[i]);
                topicClassRe.setTopicId(editTopicInfo.getTopicId());
                TraceUtils.setCreateTrace(topicClassRe);
                save(topicClassRe);// 保存到中间表
                save(topicClassRe);// 保存到中间表
            }
        }
        return new Result(true, "success");
@@ -751,7 +751,7 @@
                    + " c.commentObjectId =o.commentObjectId and o.commentObjectType = 5";
            List<Map<String, Object>> commentIdLst = findListWithMapByHql(findPeopleCountByHql,
                    CollectionUtils.newObjectMap("topicId", topicId));
            int peopleCount = commentIdLst.size();// 参与人数
            int peopleCount = commentIdLst.size();// 参与人数
            map.put("peopleCount", peopleCount);
        }
        return new Result(true, "success",
@@ -760,7 +760,7 @@
    }
    
    /**
     * 获取班级讨论数量
     * 获取班级讨论数量
     * 
     * @param classId
     * @return
@@ -789,10 +789,10 @@
    }
    
    /**
     * 获取热门话题列表
     * 获取热门话题列表
     * 
     * type 1热门,2最近
     * scope 1班级,2机构
     * type 1热门,2最近
     * scope 1班级,2机构
     * 
     */
    @CachePut(value = "topic_list", key = "#classId+#keyword+#limit+#pageNum+#type+#scope")
@@ -803,14 +803,14 @@
      QClsClass qClsClass = QClsClass.clsClass;
      QUser qUser = QUser.user;
      //热门取最近30天内,否则取1年内
      //热门取最近30天内,否则取1年内
      long time = type == 1 ? 1000L * 60 * 60 * 24 * 30 : 1000L * 60 * 60 * 24 * 30 * 12;
      
      //讨论的范围
      //讨论的范围
      Predicate scopeRight = scope == 1?qClsClass.classId.eq(classId):qClsClass.orgId.eq(ClientUtils.getOrgId());
      
      @SuppressWarnings("rawtypes")
      //排序方式
      //排序方式
      OrderSpecifier order = type == 1?new OrderSpecifier<BigInteger>(Order.DESC, qCommentObject.commentCount.add(qCommentObject.commentPraiseCount)):
         new OrderSpecifier<Date>(Order.DESC, qTopicInfo.createTime);