Преглед изворни кода

新增个人陪伴信息功能,半成品

fangqing пре 5 месеци
родитељ
комит
fa77ae146d

+ 19 - 1
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunityArticleController.java

@@ -97,7 +97,8 @@ public class CommunityArticleController extends BaseController {
     private ICommunityCollectionUserService communityCollectionUserService;
 
     @Autowired
-    private CommunityUserPromptMapper communityUserPromptMapper;
+    private ICommunityAccompanyService communityAccompanyService;
+
 
     /**
      * 获取文章列表信息
@@ -1094,4 +1095,21 @@ public class CommunityArticleController extends BaseController {
         return  AjaxResult.success(communityArticleVos);
     }
 
+    @ApiOperation("个人陪伴信息")
+    @GetMapping("/userAccompany")
+    public AjaxResult userAccompany(Long userId) {
+
+        if (Objects.isNull(userId)) {
+            userId = SecurityUtils.getLoginUser().getUserId();
+        }
+
+        CommunityAccompany communityAccompany = null;
+        try {
+            communityAccompany = communityAccompanyService.selectCommunityAccompanyById(userId);
+        } catch (Exception e) {
+           e.printStackTrace();
+        }
+        return  AjaxResult.success(communityAccompany);
+    }
+
 }

+ 85 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/domain/Community/CommunityAccompany.java

@@ -0,0 +1,85 @@
+package com.ruoyi.generator.domain.Community;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * 社区陪伴信息实体类
+ *
+ * @author fangqing
+ * @date 2024/12/30 14:59
+ */
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class CommunityAccompany {
+
+    /**
+     * 陪伴天数
+     */
+    @ApiModelProperty(value = "陪伴天数")
+    private Long accompanyDays;
+
+    /**
+     * 获赞数
+     */
+    @ApiModelProperty(value = "获赞数")
+    private Long like;
+
+    /**
+     * 获赞数百分比
+     */
+    @ApiModelProperty(value = "获赞数百分比")
+    private double likePercent;
+
+    /**
+     * 粉丝数
+     */
+    @ApiModelProperty(value = "粉丝数")
+    private Long fan;
+
+    /**
+     * 粉丝数百分比
+     */
+    @ApiModelProperty(value = "粉丝数百分比")
+    private double fanPercent;
+
+    /**
+     * 评论数
+     */
+    @ApiModelProperty(value = "评论数")
+    private Long comment;
+
+    /**
+     * 评论数百分比
+     */
+    @ApiModelProperty(value = "评论数百分比")
+    private double commentPercent;
+
+    /**
+     * 阅览数
+     */
+    @ApiModelProperty(value = "阅览数")
+    private Long read;
+
+    /**
+     * 阅览数百分比
+     */
+    @ApiModelProperty(value = "阅览数百分比")
+    private double readPercent;
+
+    /**
+     * 创作数
+     */
+    @ApiModelProperty(value = "创作数")
+    private Long creationCount;
+
+    /**
+     * 创作数百分比
+     */
+    @ApiModelProperty(value = "创作数百分比")
+    private double creationCountPercent;
+
+}

+ 128 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/CommunityAccompanyImpl.java

@@ -0,0 +1,128 @@
+package com.ruoyi.generator.service;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.ruoyi.common.core.domain.entity.SysUser;
+import com.ruoyi.generator.domain.Community.CommunityAccompany;
+import com.ruoyi.generator.domain.Community.CommunityArticle;
+import com.ruoyi.generator.domain.Community.CommunityUserLike;
+import com.ruoyi.generator.mapper.community.CommunityArticleMapper;
+import com.ruoyi.generator.mapper.community.CommunityUserLikeMapper;
+import com.ruoyi.generator.vo.CommunityUserLikeVo;
+import com.ruoyi.system.mapper.SysUserMapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.text.DecimalFormat;
+import java.time.LocalDate;
+import java.time.ZoneId;
+import java.time.temporal.ChronoUnit;
+import java.time.temporal.Temporal;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @author fangqing
+ * @date 2024/12/30 15:26
+ */
+@Service
+public class CommunityAccompanyImpl implements ICommunityAccompanyService {
+
+
+    @Autowired
+    private SysUserMapper userMapper;
+
+    @Autowired
+    private CommunityArticleMapper communityArticleMapper;
+
+    @Autowired
+    private CommunityUserLikeMapper communityUserLikeMapper;
+
+    @Override
+    public CommunityAccompany selectCommunityAccompanyById(Long userId) {
+
+        CommunityAccompany communityAccompany = new CommunityAccompany();
+
+        //获取当前用户信息 天数
+        SysUser sysUsers = userMapper.selectOne( new QueryWrapper<SysUser>().select("create_time").eq("user_id", userId).and((wrapper) -> {wrapper.ne("status", true).or().isNull("status");}));
+
+        if (sysUsers == null){
+            return  communityAccompany;
+        }
+        Date createTime = sysUsers.getCreateTime();
+        // 将 Date 对象转换为 LocalDate 对象
+        LocalDate localCreateTime = createTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
+        // 获取当前日期
+        LocalDate today = LocalDate.now();
+        // 计算两个日期之间的天数差
+        long daysDifference = ChronoUnit.DAYS.between(localCreateTime, today);
+        communityAccompany.setAccompanyDays(daysDifference);
+
+        //查询当前用户下文章的数量
+        List<CommunityArticle> communityArticles = communityArticleMapper.selectList(new QueryWrapper<CommunityArticle>()
+                .eq("create_by", userId)
+                .and((wrapper) -> {
+                    wrapper.ne("is_delete", true).or().isNull("is_delete");
+                }));
+        //如果用户文章数量不为空则执行以下的操作
+        if (communityArticles != null){
+            DecimalFormat df = new DecimalFormat("#.00");
+            //设置用户创作数
+            communityAccompany.setCreationCount((long) communityArticles.size());
+
+            //查询当前用户下文章的数量
+            List<CommunityArticle> communityArticlesTotal = communityArticleMapper.selectList(new QueryWrapper<CommunityArticle>()
+                    .and((wrapper) -> {
+                        wrapper.ne("is_delete", true).or().isNull("is_delete");
+                    }));
+            //获取文章总数
+            long articles = communityArticlesTotal.size();
+            //计算百分比
+            //计算创作数的百分比 防止总数取0
+            if (articles != 0) {
+                Double CreationCountPercent = Double.valueOf(df.format((double) communityArticles.size() / articles * 100));
+                communityAccompany.setCreationCountPercent(CreationCountPercent);
+            }
+
+            //获取用户阅览量
+            long read = communityArticles.stream()
+                    .mapToLong(article -> article.getPageViews()).sum();
+
+            if (read != 0  ){
+                communityAccompany.setRead(read);
+            }
+
+            //阅览量百分比
+            long readSUm = communityArticlesTotal.stream()
+                    .mapToLong(article -> article.getPageViews()).sum();
+
+            if (readSUm != 0){
+                Double ReadPercent = Double.valueOf(df.format((double)  read / readSUm * 100));
+                communityAccompany.setReadPercent(ReadPercent);
+            }
+        }
+
+
+        //粉丝数
+        Long fans = communityUserLikeMapper.selectCount(new QueryWrapper<CommunityUserLike>()
+                .eq("like_user_id", userId));
+
+        if (fans != 0 ){
+            communityAccompany.setFan(fans);
+        }
+
+        //粉丝数占比
+        CommunityUserLike communityUserLike = communityUserLikeMapper.selectOne(new QueryWrapper<CommunityUserLike>()
+                .select("like_user_id", "COUNT(1) as count")
+                .groupBy("like_user_id")
+                .orderByDesc("count")
+                .last("LIMIT 1"));
+
+
+        System.out.println(communityUserLike);
+
+
+        return communityAccompany;
+    }
+
+
+}

+ 17 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/ICommunityAccompanyService.java

@@ -0,0 +1,17 @@
+package com.ruoyi.generator.service;
+
+
+import com.ruoyi.generator.domain.Community.CommunityAccompany;
+import com.ruoyi.generator.vo.CommunityUserInfoVo;
+
+/**
+ * 业务 服务层
+ * 个人陪伴信息
+ * @author fangqing
+ */
+public interface ICommunityAccompanyService  {
+
+    CommunityAccompany selectCommunityAccompanyById(Long userId);
+
+
+}