派生自 projectDept/qhighschool

Administrator
2022-12-14 1c38c12ef967b754dcbcfed69c8d7739003a69ca
src/main/java/com/qxueyou/scc/operation/topic/service/impl/TopicService.java
@@ -143,7 +143,7 @@
        save(commentObject);
        TopicInfo topic = this.read(TopicInfo.class, topicId);
        String[] classIds = topic.getClassId().split(",");
        Map<String, Object> argsMap = new HashMap<String, Object>(1);
        argsMap.put("classIds", classIds);
        List<Map<String, Object>> classMapLst = findListWithMapByHql(
@@ -155,7 +155,7 @@
        List<Map<String, Object>> commentIdLst = findListWithMapByHql(findPeopleCountByHql,CollectionUtils.newObjectMap("topicId", topicId));
        int peopleCount = commentIdLst.size();// 参与人数
        return new Result(true, "success",
                CollectionUtils.newObjectMap("topicId", topicId,"topicType", topic.getTopicType(), "createTime", topic.getCreateTime(), "topicName", topic.getTopicName(), "issuer",
                        topic.getCreator(), "issuerId", topic.getCreateId(), "deadline", topic.getEndTime(),
@@ -175,8 +175,11 @@
        topicInfo.setDeleteFlag(false);
        topicInfo.setOrgId(ClientUtils.getOrgId());
        TraceUtils.setCreateTrace(topicInfo);
        if(topicInfo.getStartTime() == null){
            topicInfo.setStartTime(new Date());
        }
        save(topicInfo);
        if(StringUtils.isNotEmpty(classId)){
           String[] classIds = classId.split(",");
            TopicClassRe topicClassRe = null;
@@ -188,7 +191,7 @@
                save(topicClassRe);// 保存到中间表
            }
        }
        CommentObject commentObject = new CommentObject();
        commentObject.setCommentObjectUid(topicInfo.getTopicId());
        commentObject.setCommentObjectName(topicInfo.getTopicName());
@@ -378,51 +381,51 @@
        return new Result(true, "success",
                CollectionUtils.newObjectMap("commentLst", commentLst, "commentCount", commentCount));
    }
    @Override
    public Result appMyComment(String userId, Pager pager) {
       QSnsMyComment qSnsMyComment = QSnsMyComment.snsMyComment;
       JPAQuery<SnsMyComment> query = this.getQueryFactory().
             selectFrom(qSnsMyComment).where(qSnsMyComment.createId.eq(userId));
       List<SnsMyComment> lstSnsMyComment = query.orderBy(qSnsMyComment.commentTime.desc())
             .offset(pager.getOffset()).limit(pager.getPageSize()).fetch();
       long commentCount = query.fetchCount();
        return new Result(true, "success",
                CollectionUtils.newObjectMap("dataList", lstSnsMyComment, "count", commentCount));
    }
    @Override
    public Result commentToMe(String userId, Pager pager) {
       QSnsCommentToMe qSnsCommentToMe = QSnsCommentToMe.snsCommentToMe;
      JPAQuery<SnsCommentToMe> query = this.getQueryFactory().
            selectFrom(qSnsCommentToMe).where(qSnsCommentToMe.createId.eq(userId));
      List<SnsCommentToMe> lstSnsMyComment = query.orderBy(qSnsCommentToMe.commentTime.desc())
            .offset(pager.getOffset()).limit(pager.getPageSize()).fetch();
      long commentCount = query.fetchCount();
       return new Result(true, "success",
               CollectionUtils.newObjectMap("dataList", lstSnsMyComment, "count", commentCount));
    }
    @Override
    public Result praiseToMe(String userId, Pager pager) {
       QSnsPraiseToMe qSnsPraiseToMe = QSnsPraiseToMe.snsPraiseToMe;
       JPAQuery<SnsPraiseToMe> query = this.getQueryFactory().
             selectFrom(qSnsPraiseToMe).where(qSnsPraiseToMe.createId.eq(userId));
       List<SnsPraiseToMe> lstSnsMyComment = query.orderBy(qSnsPraiseToMe.praiseTime.desc())
             .offset(pager.getOffset()).limit(pager.getPageSize()).fetch();
       long commentCount = query.fetchCount();
        return new Result(true, "success",
                CollectionUtils.newObjectMap("dataList", lstSnsMyComment, "count", commentCount));
    }
@@ -431,19 +434,19 @@
    @Override
    public Result appMyPraise(String userId, Pager pager) {
       QSnsMyPraise qSnsMyPraise = QSnsMyPraise.snsMyPraise;
       JPAQuery<SnsMyPraise> query = this.getQueryFactory().
             selectFrom(qSnsMyPraise).where(qSnsMyPraise.createId.eq(userId));
       List<SnsMyPraise> lstSnsMyComment = query.orderBy(qSnsMyPraise.praiseTime.desc())
             .offset(pager.getOffset()).limit(pager.getPageSize()).fetch();
       long commentCount = query.fetchCount();
        return new Result(true, "success",
                CollectionUtils.newObjectMap("dataList", lstSnsMyComment, "count", commentCount));
    }
    @Override
    public Result deleteMycomment(String commentId) {
        Comment comment = read(Comment.class, commentId);
@@ -534,7 +537,7 @@
            save(topicInfo);
        } else {
            comment.setCommentParentId(commentParentId);
            this.bulkUpdate("update Comment set commentCount = commentCount + 1 where commentId = ?", new Object[] {commentParentId});
        }
        save(comment);
@@ -556,7 +559,7 @@
        }else {
           this.bulkUpdate("update Comment set commentPraiseCount = commentPraiseCount + 1 where commentId = ?", new Object[] {commentId});
        }
        CommentPraise commentPraise = new CommentPraise();
        commentPraise.setCommentId(commentId);
        commentPraise.setCommentObjectId(commentObjectId);
@@ -565,7 +568,7 @@
        commentPraise.setCommentter(ClientUtils.getUserName());
        TraceUtils.setCreateTrace(commentPraise);
        save(commentPraise);// 保存到点赞表
        return new Result(true, "success");
    }
@@ -576,7 +579,7 @@
        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))
@@ -588,7 +591,7 @@
                  .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())
@@ -689,7 +692,7 @@
    @Override
    public Result updateTopicInfo(TopicInfo editTopicInfo) {
//       if(editTopicInfo.getTopicType()==TopicInfo.TOPIC_TYPE_CLS && StringUtils.isEmpty(editTopicInfo.getClassId())) {
       if(StringUtils.isEmpty(editTopicInfo.getClassId())) {
          return new Result(false, "请选择关联班级!");
@@ -706,7 +709,7 @@
        topicInfo.setDeleteFlag(false);
        TraceUtils.setUpdateTrace(topicInfo);
        save(topicInfo);
        if(StringUtils.isNotEmpty(topicInfo.getClassId())){
           String[] classIds = topicInfo.getClassId().split(",");
            TopicClassRe topicClassRe = null;
@@ -758,10 +761,10 @@
                CollectionUtils.newObjectMap("topicLst", topicLst, "topicCount", topicCount));
    }
    /**
     * 获取班级讨论数量
     *
     *
     * @param classId
     * @return
     */
@@ -769,13 +772,13 @@
       if(StringUtils.isEmpty(classId)){
          return 0L;
       }
       QTopicInfo qTopicInfo = QTopicInfo.topicInfo;
      QTopicClassRe qTopicClassRe = QTopicClassRe.topicClassRe;
      QCommentObject qCommentObject = QCommentObject.commentObject;
      QClsClass qClsClass = QClsClass.clsClass;
      QUser qUser = QUser.user;
       JPAQuery<Long> query = this.getQueryFactory().select(qTopicInfo.topicId.countDistinct()).from(qTopicInfo, qTopicClassRe, qCommentObject, qClsClass, qUser )
            .where(qTopicInfo.deleteFlag.isFalse().and(qTopicClassRe.deleteFlag.isFalse()).and(qUser.userId.eq(qTopicInfo.createId))
                  .and(qCommentObject.deleteFlag.isFalse()).and(qTopicClassRe.topicId.eq(qTopicInfo.topicId))
@@ -784,16 +787,16 @@
                  .and(qCommentObject.commentObjectUid.eq(qTopicInfo.topicId)).and(
                        qTopicInfo.createTime.after(new Date(new Date().getTime() - 1000L * 60 * 60 * 24 * 30 * 12)))
                  .and(qCommentObject.commentObjectType.eq(CommentObject.COMMENT_TYPE_INTERACT))).groupBy(qTopicInfo.topicId);
       return query.fetchCount();
    }
    /**
     * 获取热门话题列表
     *
     *
     * type 1热门,2最近
     * scope 1班级,2机构
     *
     *
     */
    @CachePut(value = "topic_list", key = "#classId+#keyword+#limit+#pageNum+#type+#scope")
   public Map<String, Object> getHotTopicLst(String classId, String keyword, Integer limit, Integer pageNum, int type, int scope){
@@ -805,15 +808,15 @@
      //热门取最近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);
      JPAQuery<Tuple> query = this.getQueryFactory().select(qTopicInfo, qCommentObject, qClsClass, qUser).from(qTopicInfo, qTopicClassRe, qCommentObject, qClsClass, qUser )
            .where(qTopicInfo.deleteFlag.isFalse().and(qTopicClassRe.deleteFlag.isFalse()).and(qUser.userId.eq(qTopicInfo.createId))
                  .and(qCommentObject.deleteFlag.isFalse()).and(qTopicClassRe.topicId.eq(qTopicInfo.topicId)).and(qClsClass.deleteFlag.isFalse())
@@ -822,9 +825,9 @@
                  .and(qCommentObject.commentObjectUid.eq(qTopicInfo.topicId).and(
                        qTopicInfo.createTime.after(new Date(new Date().getTime() - time))))
                  .and(qCommentObject.commentObjectType.eq(CommentObject.COMMENT_TYPE_INTERACT))).groupBy(qTopicInfo.topicId);
      long count = query.fetchCount();
      return CollectionUtils.newObjectMap("count", count, "listData", query.offset(pageNum).limit(limit)
            .orderBy(order, qTopicInfo.createTime.desc()).fetch().stream()
            .map(tuple -> {
@@ -846,8 +849,8 @@
               map.put("commentPraiseCount", tuple.get(qCommentObject).getCommentPraiseCount());
               map.put("className", tuple.get(qClsClass).getName());
               return map;
            }).collect(Collectors.toList()));
            }).collect(Collectors.toList()));
   }
}