Bläddra i källkod

Merge branch 'dev' of http://121.4.140.159:10880/378402801/ruoyi-community into dev

king 2 månader sedan
förälder
incheckning
7724c8babb

+ 73 - 4
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunityArticleController.java

@@ -28,9 +28,8 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.bind.annotation.*;
 
 
 import java.text.ParseException;
 import java.text.ParseException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Objects;
+import java.util.*;
+import java.util.stream.Collectors;
 
 
 /**
 /**
  * 社区文章管理
  * 社区文章管理
@@ -189,7 +188,7 @@ public class CommunityArticleController extends BaseController {
             if (isSensitiveContent) {
             if (isSensitiveContent) {
                 return AjaxResult.error(MessageUtils.message("article.content.error"));
                 return AjaxResult.error(MessageUtils.message("article.content.error"));
             }
             }
-            
+
             communityArticleService.insertCommunityArticle(communityArticle);
             communityArticleService.insertCommunityArticle(communityArticle);
         } catch (Exception e) {
         } catch (Exception e) {
             System.out.println(e.getMessage());
             System.out.println(e.getMessage());
@@ -1335,4 +1334,74 @@ public class CommunityArticleController extends BaseController {
         return AjaxResult.success(communityArticleAt);
         return AjaxResult.success(communityArticleAt);
     }
     }
 
 
+    /**
+     * 置顶文章
+     */
+    @ApiOperation("置顶文章")
+    @PostMapping("/articleTop")
+    @Anonymous
+    public AjaxResult articleTop(@RequestBody CommunityArticle communityArticle) {
+        if (Objects.isNull(communityArticle.getId())) {
+            return AjaxResult.error("文章ID不能为空");
+        }
+        //先拿前端传的ID
+        Long userId = communityArticle.getUserId();
+        if (Objects.isNull(communityArticle.getUserId())) {
+            userId = SecurityUtils.getUserId();
+        }
+        String msg = "";
+        try {
+            CommunityArticle toparticle = communityArticleMapper.selectOne(new QueryWrapper<CommunityArticle>()
+                    .eq("user_id", userId)
+                    .eq("id", communityArticle.getId())
+                    .and((wrapper) -> {
+                        wrapper.ne("is_delete", 1).or().isNull("is_delete");
+                    }));
+            //如果没有找到数据置顶该文章 说明不是当前用户
+            if (Objects.isNull(toparticle) || Objects.isNull(toparticle.getId())) {
+                return AjaxResult.success("文章不属于当前用户,无法置顶");
+            }
+            Boolean isTop = toparticle.getIsTop();
+            if (!isTop){
+                communityArticleService.update(new UpdateWrapper<CommunityArticle>()
+                        .set("is_top", true)
+                        .set("top_time", DateUtils.parseDate(DateUtils.getTime()))
+                        .eq("id", communityArticle.getId()));
+                msg = "已置顶";
+            }else {
+                communityArticleService.update(new UpdateWrapper<CommunityArticle>()
+                        .set("is_top", false)
+                        .set("top_time", DateUtils.parseDate(DateUtils.getTime()))
+                        .eq("id", communityArticle.getId()));
+                msg = "已取消置顶";
+            }
+            //每个人只能有三条置顶数据,如果有第四条或者第五条数据,则按时间排序找到离当前时间最近的第三条数据更新掉小于当前时间的所有数据为false
+            List<CommunityArticle> communityArticles = communityArticleMapper.selectList(new QueryWrapper<CommunityArticle>()
+                    .eq("user_id", userId)
+                    .eq("is_top", 1)
+                    .and((wrapper) -> {
+                        wrapper.ne("is_delete", 1).or().isNull("is_delete");
+                    }));
+            if (communityArticles.size() > 3) {
+               //大于三条则 排序
+                communityArticles = communityArticles.stream()
+                        .sorted(Comparator.comparing(CommunityArticle::getTopTime).reversed()) // 降序排列(最新文章排在前面)
+                        .limit(3)
+                        .collect(Collectors.toList());
+
+                //最早文章的 is_top 更新为 false
+                UpdateWrapper<CommunityArticle> updateWrapper = new UpdateWrapper<>();
+                updateWrapper.eq("user_id", userId)
+                        .eq("is_top", 1)
+                        .notIn("id", communityArticles.stream().map(CommunityArticle::getId).collect(Collectors.toList()))
+                        .set("is_top", false); // 将 is_top 设置为 false
+                communityArticleMapper.update(null, updateWrapper);
+            }
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return AjaxResult.success(msg);
+    }
+
 }
 }

+ 33 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/VersionController.java

@@ -0,0 +1,33 @@
+package com.ruoyi.generator.controller;
+
+import com.ruoyi.common.annotation.Anonymous;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.generator.domain.Community.Version;
+import com.ruoyi.generator.service.IVersionService;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+
+@RestController
+@RequestMapping("/api/version")
+public class VersionController {
+
+    @Resource
+    private IVersionService versionService;
+
+    @GetMapping("/check")
+    @ApiOperation("获取最新版本信息")
+    @Anonymous
+    public AjaxResult checkVersion(Integer versionSort) {
+        // 查询数据库或配置中的最新版本信息
+        Version latestVersion = versionService.getLatestVersion();
+        boolean hasUpdate = latestVersion.getVersionSort() > versionSort;
+        return AjaxResult.success()
+                .put("hasUpdate", hasUpdate)
+                .put("downloadUrl", latestVersion.getDownloadUrl())
+                .put("releaseNotes", latestVersion.getDescription());
+    }
+}

+ 13 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/domain/Community/CommunityArticle.java

@@ -210,4 +210,17 @@ public class CommunityArticle implements Serializable {
      */
      */
     @ApiModelProperty("文章类型")
     @ApiModelProperty("文章类型")
     private Integer articleType;
     private Integer articleType;
+
+    /**
+     * 置顶标识
+     */
+    @ApiModelProperty("文章类型")
+    private Boolean isTop;
+
+
+    /**
+     * 置顶时间
+     */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date topTime;
 }
 }

+ 61 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/domain/Community/Version.java

@@ -0,0 +1,61 @@
+package com.ruoyi.generator.domain.Community;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import javax.validation.constraints.NotNull;
+import java.util.Date;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@TableName("version")
+public class Version {
+    @NotNull(message = "[版本id]不能为空")
+    @ApiModelProperty("版本id")
+    @TableId(value = "id", type = IdType.AUTO)
+    @JsonSerialize(using = ToStringSerializer.class)
+    private Long id;
+
+    /**
+     * 版本排序
+     */
+    @ApiModelProperty("版本排序")
+    private Integer versionSort;
+
+    /**
+     * 版本号
+     */
+    @ApiModelProperty("版本号")
+    private String versionCode;
+
+    /**
+     * 下载地址
+     */
+    @ApiModelProperty("下载地址")
+    private String downloadUrl;
+
+    /**
+     * 描述
+     */
+    @ApiModelProperty("描述")
+    private String description;
+
+    /**
+     * 创建时间
+     */
+    @ApiModelProperty("创建时间")
+    private Date createTime;
+    /**
+     * 创建人
+     */
+    @ApiModelProperty("创建人")
+    private Long createBy;
+}

+ 9 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/mapper/community/VersionMapper.java

@@ -0,0 +1,9 @@
+package com.ruoyi.generator.mapper.community;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.ruoyi.generator.domain.Community.Version;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface VersionMapper extends BaseMapper<Version> {
+}

+ 8 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/IVersionService.java

@@ -0,0 +1,8 @@
+package com.ruoyi.generator.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.ruoyi.generator.domain.Community.Version;
+
+public interface IVersionService extends IService<Version> {
+    Version getLatestVersion();
+}

+ 25 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/VersionServiceImpl.java

@@ -0,0 +1,25 @@
+package com.ruoyi.generator.service;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.generator.domain.Community.Version;
+import com.ruoyi.generator.mapper.community.VersionMapper;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+
+@Service
+public class VersionServiceImpl extends ServiceImpl<VersionMapper, Version> implements IVersionService {
+
+    @Resource
+    private VersionMapper versionMapper;
+
+    @Override
+    public Version getLatestVersion() {
+        Version version = versionMapper.selectOne(new QueryWrapper<Version>()
+                .eq("status", false)
+                .orderByDesc("version_sort")
+                .last("limit 1"));
+        return version;
+    }
+}

+ 142 - 0
ruoyi-generator/src/main/java/generator/domain/Version.java

@@ -0,0 +1,142 @@
+package generator.domain;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.Size;
+import javax.validation.constraints.NotNull;
+
+import java.io.Serializable;
+
+import java.util.Date;
+import io.swagger.annotations.ApiModelProperty;
+import org.hibernate.validator.constraints.Length;
+
+/**
+* 版本
+* @TableName version
+*/
+public class Version implements Serializable {
+
+    /**
+    * 唯一id
+    */
+    @NotNull(message="[唯一id]不能为空")
+    @ApiModelProperty("唯一id")
+    private Long id;
+    /**
+    * 版本号
+    */
+    @Size(max= 255,message="编码长度不能超过255")
+    @ApiModelProperty("版本号")
+    @Length(max= 255,message="编码长度不能超过255")
+    private String versionCode;
+    /**
+    * 下载地址
+    */
+    @Size(max= -1,message="编码长度不能超过-1")
+    @ApiModelProperty("下载地址")
+    @Length(max= -1,message="编码长度不能超过-1")
+    private String downloadUrl;
+    /**
+    * 描述
+    */
+    @Size(max= -1,message="编码长度不能超过-1")
+    @ApiModelProperty("描述")
+    @Length(max= -1,message="编码长度不能超过-1")
+    private String description;
+    /**
+    * 创建时间
+    */
+    @ApiModelProperty("创建时间")
+    private Date createTime;
+    /**
+    * 创建人
+    */
+    @ApiModelProperty("创建人")
+    private Long createBy;
+
+    /**
+    * 唯一id
+    */
+    private void setId(Long id){
+    this.id = id;
+    }
+
+    /**
+    * 版本号
+    */
+    private void setVersionCode(String versionCode){
+    this.versionCode = versionCode;
+    }
+
+    /**
+    * 下载地址
+    */
+    private void setDownloadUrl(String downloadUrl){
+    this.downloadUrl = downloadUrl;
+    }
+
+    /**
+    * 描述
+    */
+    private void setDescription(String description){
+    this.description = description;
+    }
+
+    /**
+    * 创建时间
+    */
+    private void setCreateTime(Date createTime){
+    this.createTime = createTime;
+    }
+
+    /**
+    * 创建人
+    */
+    private void setCreateBy(Long createBy){
+    this.createBy = createBy;
+    }
+
+
+    /**
+    * 唯一id
+    */
+    private Long getId(){
+    return this.id;
+    }
+
+    /**
+    * 版本号
+    */
+    private String getVersionCode(){
+    return this.versionCode;
+    }
+
+    /**
+    * 下载地址
+    */
+    private String getDownloadUrl(){
+    return this.downloadUrl;
+    }
+
+    /**
+    * 描述
+    */
+    private String getDescription(){
+    return this.description;
+    }
+
+    /**
+    * 创建时间
+    */
+    private Date getCreateTime(){
+    return this.createTime;
+    }
+
+    /**
+    * 创建人
+    */
+    private Long getCreateBy(){
+    return this.createBy;
+    }
+
+}