fangqing 2 месяцев назад
Родитель
Сommit
e805f46f06

+ 4 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysProfileController.java

@@ -88,6 +88,8 @@ public class SysProfileController extends BaseController {
         currentUser.setSex(user.getSex());
         currentUser.setProfile(user.getProfile());
         currentUser.setAvatar(user.getAvatar());
+        currentUser.setClassId(user.getClassId());
+
         if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(currentUser)) {
             return error("修改用户'" + loginUser.getUsername() + "'失败,手机号码已存在");
         }
@@ -116,6 +118,8 @@ public class SysProfileController extends BaseController {
             communityUserInfo.setUpdateBy(currentUser.getUserId());
             communityUserInfo.setUpdateTime(DateUtils.parseDate(DateUtils.getTime()));
             communityUserInfo.setBackImage(user.getBackImage());
+            communityUserInfo.setClassId(currentUser.getClassId());
+
             //更新前端用户的个人简介信息
             communityUserInfoMapper.updateById(communityUserInfo);
 

+ 16 - 0
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysUser.java

@@ -165,6 +165,13 @@ public class SysUser extends BaseEntity {
      */
     private Long roleId;
 
+    /**
+     * 板块排序
+     */
+    @Excel(name = "板块排序")
+    @TableField(exist = false)
+    private String classId;
+
     public SysUser() {
 
     }
@@ -373,6 +380,14 @@ public class SysUser extends BaseEntity {
         this.backImage = backImage;
     }
 
+    public String getClassId() {
+        return classId;
+    }
+
+    public void setClassId(String classId) {
+        this.classId = classId;
+    }
+
 
     /** unionId */
     private String unionId;
@@ -396,6 +411,7 @@ public class SysUser extends BaseEntity {
         this.openId = openId;
     }
 
+
     @Override
     public String toString() {
         return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)

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

@@ -275,16 +275,56 @@ public class CommunityArticleController extends BaseController {
     @ApiOperation("获取文章分类列表")
     //@Anonymous
     public AjaxResult getClassList() {
+
         List<CommunityClass> communityClasses = null;
+        //获取用户信息
+        CommunityUserInfoVo communityUserInfoVo = null;
         try {
-            communityClasses = communityClassMapper.selectList(new QueryWrapper<CommunityClass>().orderByAsc("sort"));
+            Long userId = SecurityUtils.getLoginUser().getUserId();
+            String classId = communityArticleService.selectCommunityUserInfoById(userId, true).getClassId();
+
+            if (classId.length() != 0 ){
+                List<Long> sortOrder = Arrays.stream(classId.split(","))
+                        .map(String::trim)
+                        .map(Long::parseLong)
+                        .collect(Collectors.toList());
+
+                // 假设 allCommunityClasses 是从数据库查询出来的结果
+                List<CommunityClass> allCommunityClasses = communityClassMapper.selectList(new QueryWrapper<CommunityClass>().orderByAsc("sort"));
+
+                // 将 allCommunityClasses 按照 sortOrder 分组并排序
+
+                Map<Long, CommunityClass> classMap = allCommunityClasses.stream().collect(Collectors.toMap(CommunityClass::getId, c -> c));
+
+                List<CommunityClass> sortedCommunityClasses = new ArrayList<>();
+                // 按 sortOrder 先添加在列表中的元素
+                for (Long order : sortOrder) {
+                    System.out.println(order);
+                    if (classMap.containsKey(order)) {
+                        sortedCommunityClasses.add(classMap.get(order));
+                    }
+                }
+                // 保持原有顺序添加不在 sortOrder 中的元素
+                List<CommunityClass> remainingClasses = allCommunityClasses.stream()
+                        .filter(c -> !sortOrder.contains(c.getId()))
+                        .collect(Collectors.toList());
+
+                sortedCommunityClasses.addAll(remainingClasses);
+                return AjaxResult.success(sortedCommunityClasses);
+            }else {
+                communityClasses = communityClassMapper.selectList(new QueryWrapper<CommunityClass>().orderByAsc("sort"));
+
+            }
         } catch (Exception e) {
+            //e.printStackTrace();
             System.out.println(e.getMessage());
             throw new ProjectException();
         }
         return AjaxResult.success(communityClasses);
     }
 
+
+
     @GetMapping("/circleList")
     @ApiOperation("获取文章圈子列表")
     //@Anonymous

+ 8 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/domain/Community/CommunityUserInfo.java

@@ -73,4 +73,12 @@ public class CommunityUserInfo {
      */
     @ApiModelProperty("更新时间")
     private Date updateTime;
+
+    /**
+     * 板块排序
+     */
+    @ApiModelProperty("板块排序")
+    private String classId;
+
+
 }

+ 8 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/vo/CommunityUserInfoVo.java

@@ -120,4 +120,12 @@ public class CommunityUserInfoVo implements Serializable {
      */
     @ApiModelProperty("地址")
     private String address;
+
+    /**
+     * 板块排序
+     */
+    @ApiModelProperty("板块排序")
+    private String classId;
+
+
 }