Bläddra i källkod

新增接口 1.获取隐私权限,2.更新隐私权限

fangqing 6 månader sedan
förälder
incheckning
16f46ddd8f

+ 18 - 7
ruoyi-generator/src/main/java/com/ruoyi/generator/controller/CommunitySettingsController.java

@@ -4,8 +4,10 @@ import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.generator.domain.Community.CommunityArticle;
 import com.ruoyi.generator.domain.Community.CommunityUserNotification;
+import com.ruoyi.generator.domain.Community.CommunityUserPrivacy;
 import com.ruoyi.generator.service.ICommunityArticleService;
 import com.ruoyi.generator.service.ICommunityNotificationService;
+import com.ruoyi.generator.service.ICommunityPrivacyService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -25,6 +27,10 @@ public class CommunitySettingsController {
     @Autowired
     private ICommunityNotificationService communityNotificationService;
 
+    @Autowired
+    private ICommunityPrivacyService communityPrivacyService;
+
+
     /**
      * 获取通知权限
      * @param
@@ -48,23 +54,28 @@ public class CommunitySettingsController {
         return AjaxResult.success(communityNotificationService.modifyUserNotification(communityUserNotification));
     }
 
-
-
-
-
     /**
      * 获取隐私权限
      * @param
      * @return 获取隐私权限
      */
-    @ApiOperation("获取通知权限")
+    @ApiOperation("获取隐私权限")
     @GetMapping("/userPrivacy")
     //@Anonymous
     public AjaxResult userPrivacy() {
-        return AjaxResult.success(communityNotificationService.selectUserNotification(SecurityUtils.getLoginUser().getUserId()));
+        return AjaxResult.success(communityPrivacyService.selectUserPrivacy(SecurityUtils.getLoginUser().getUserId()));
     }
 
-
+    /**
+     * 更新隐私权限
+     * @param communityUserPrivacy
+     * @return 返回修改成功的对象
+     */
+    @ApiOperation("更新通知权限")
+    @PostMapping("/modifyUserPrivacy")
+    public AjaxResult modifyUserNotification(@RequestBody CommunityUserPrivacy communityUserPrivacy) {
+        return AjaxResult.success(communityPrivacyService.modifyUserPrivacy(communityUserPrivacy));
+    }
 
 
 

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

@@ -33,48 +33,48 @@ public class CommunityUserPrivacy implements Serializable  {
     private Long userId;
 
     @ApiModelProperty("只允许我关注的人评论我")
-    private Boolean isComment; // 驼峰命名法
+    private Boolean isComment;
 
     /**
      * 只允许我关注的人@我
      */
     @ApiModelProperty("只允许我关注的人@我")
-    private Boolean isCircle; // 驼峰命名法
+    private Boolean isCircle;
 
     /**
      * 我的作品
      */
     @ApiModelProperty("我的作品")
-    private Boolean isWorks; // 驼峰命名法
+    private Boolean isWorks;
 
     /**
      * 我的合集
      */
     @ApiModelProperty("我的合集")
-    private Boolean isCollection; // 驼峰命名法
+    private Boolean isCollection;
 
     /**
      * 我的喜欢
      */
     @ApiModelProperty("我的喜欢")
-    private Boolean isLike; // 驼峰命名法
+    private Boolean isLike;
 
     /**
      * 我的收藏
      */
     @ApiModelProperty("我的收藏")
-    private Boolean isCompilation; // 驼峰命名法
+    private Boolean isCompilation;
 
     /**
      * 账户搜索
      */
     @ApiModelProperty("账户搜索")
-    private Boolean isAccounts; // 驼峰命名法
+    private Boolean isAccounts;
 
     /**
      * 名称搜索
      */
     @ApiModelProperty("名称搜索")
-    private Boolean isNames; // 驼峰命名法
+    private Boolean isNames;
 
 }

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

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

+ 5 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/CommunityNotificationServiceImpl.java

@@ -51,6 +51,11 @@ public class CommunityNotificationServiceImpl extends ServiceImpl<CommunityUserN
             // 如果没有通知权限,插入一条关于 userId 的数据
             CommunityUserNotification newNotification = new CommunityUserNotification();
             newNotification.setUserId(userId);
+            newNotification.setIsCircle(false);
+            newNotification.setIsLetter(false);
+            newNotification.setIsComment(false);
+            newNotification.setIsAddAttention(false);
+            newNotification.setIsPraiseCollection(false);
             // 设置其他必要的默认值,例如:
             // 使用 MyBatis-Plus 执行插入操作
             communityUserNotificationMapper.insert(newNotification);

+ 135 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/CommunityPrivacyServiceImpl.java

@@ -0,0 +1,135 @@
+package com.ruoyi.generator.service;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.common.utils.bean.BeanUtils;
+import com.ruoyi.generator.domain.Community.CommunityUserNotification;
+import com.ruoyi.generator.domain.Community.CommunityUserPrivacy;
+import com.ruoyi.generator.mapper.community.CommunityUserNotificationMapper;
+import com.ruoyi.generator.mapper.community.CommunityUserPrivacyMapper;
+import com.ruoyi.generator.vo.CommunityUserNotificationVo;
+import com.ruoyi.generator.vo.CommunityUserPrivacyVo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 业务 服务层实现
+ *
+ * @author ruoyi
+ */
+@Service
+public class CommunityPrivacyServiceImpl extends ServiceImpl<CommunityUserPrivacyMapper, CommunityUserPrivacy> implements ICommunityPrivacyService  {
+
+
+    @Autowired
+    private CommunityUserPrivacyMapper communityUserPrivacyMapper;
+
+    /**
+     * 获取隐私权限
+     * @param userId
+     * @return 获取隐私权限
+     */
+    @Override
+    public List<CommunityUserPrivacyVo> selectUserPrivacy(Long userId) {
+        // 查询自己的隐私权限
+        List<CommunityUserPrivacy> communityUserPrivacies
+                = communityUserPrivacyMapper
+                .selectList(new QueryWrapper<CommunityUserPrivacy>().eq("user_id", userId));
+        // 创建一个用于存放VO的列表
+        List<CommunityUserPrivacyVo> communityUserPrivacyVos = new ArrayList<>();
+
+        // 遍历查询结果,复制属性到 VO 对象
+        for (CommunityUserPrivacy communityUserPrivacy : communityUserPrivacies) {
+            CommunityUserPrivacyVo communityUserPrivacyVo = new CommunityUserPrivacyVo();
+            BeanUtils.copyProperties(communityUserPrivacy, communityUserPrivacyVo);
+            communityUserPrivacyVos.add(communityUserPrivacyVo);
+        }
+
+        // 判断隐私权限是否为空
+        if (communityUserPrivacyVos.isEmpty()) {
+            // 如果没有隐私权限,插入一条关于 userId 的数据
+            CommunityUserPrivacy newPrivacy = new CommunityUserPrivacy();
+            newPrivacy.setUserId(userId);
+            newPrivacy.setIsComment(false);
+            newPrivacy.setIsCircle(false);
+            newPrivacy.setIsWorks(false);
+            newPrivacy.setIsCollection(false);
+            newPrivacy.setIsLike(false);
+            newPrivacy.setIsCompilation(false);
+            newPrivacy.setIsAccounts(false);
+            newPrivacy.setIsNames(false);
+            // 设置其他必要的默认值,例如:
+            // 使用 MyBatis-Plus 执行插入操作
+            communityUserPrivacyMapper.insert(newPrivacy);
+            // 将新插入的记录转换为 VO 并返回
+            CommunityUserPrivacyVo newPrivacyVo = new CommunityUserPrivacyVo();
+            BeanUtils.copyProperties(newPrivacy, newPrivacyVo);
+            communityUserPrivacyVos.add(newPrivacyVo);
+        }
+
+        return communityUserPrivacyVos;
+    }
+
+    /**
+     * 更新隐私权限
+     * @param communityUserPrivacy
+     * @return 返回修改成功的对象
+     */
+    @Override
+    public List<CommunityUserPrivacyVo> modifyUserPrivacy(CommunityUserPrivacy communityUserPrivacy) {
+        // 获取 userId
+        Long userId = SecurityUtils.getUserId();
+
+        // 创建更新包装器
+        UpdateWrapper<CommunityUserPrivacy> updateWrapper = new UpdateWrapper<>();
+        updateWrapper.eq("user_id", userId); // 根据 userId 条件
+
+        // 更新字段
+        if (communityUserPrivacy.getIsComment() != null) {
+            updateWrapper.set("is_comment", communityUserPrivacy.getIsComment());
+        }
+        if (communityUserPrivacy.getIsCircle() != null) {
+            updateWrapper.set("is_circle", communityUserPrivacy.getIsCircle());
+        }
+        if (communityUserPrivacy.getIsWorks() != null) {
+            updateWrapper.set("is_works", communityUserPrivacy.getIsWorks());
+        }
+        if (communityUserPrivacy.getIsCollection() != null) {
+            updateWrapper.set("is_collection", communityUserPrivacy.getIsCollection());
+        }
+        if (communityUserPrivacy.getIsLike() != null) {
+            updateWrapper.set("is_like", communityUserPrivacy.getIsLike());
+        }
+        if (communityUserPrivacy.getIsCompilation() != null) {
+            updateWrapper.set("is_compilation", communityUserPrivacy.getIsCompilation());
+        }
+        if (communityUserPrivacy.getIsAccounts() != null) {
+            updateWrapper.set("is_accounts", communityUserPrivacy.getIsAccounts());
+        }
+        if (communityUserPrivacy.getIsNames() != null) {
+            updateWrapper.set("is_names", communityUserPrivacy.getIsNames());
+        }
+
+        // 执行更新操作
+        boolean updated = this.update(updateWrapper);
+        if (!updated) {
+            System.out.println("更新失败");
+        }
+
+        // 创建一个用于存放VO的列表
+        List<CommunityUserPrivacyVo> communityUserPrivacyVos = new ArrayList<>();
+        CommunityUserPrivacy updatedUserPrivacy = this.getOne(new UpdateWrapper<CommunityUserPrivacy>().eq("user_id", userId));
+
+        // 将新插入的记录转换为 VO 并返回
+        CommunityUserPrivacyVo newPrivacyVo = new CommunityUserPrivacyVo();
+        BeanUtils.copyProperties(updatedUserPrivacy, newPrivacyVo);
+        communityUserPrivacyVos.add(newPrivacyVo);
+
+        return communityUserPrivacyVos;
+    }
+}

+ 31 - 0
ruoyi-generator/src/main/java/com/ruoyi/generator/service/ICommunityPrivacyService.java

@@ -0,0 +1,31 @@
+package com.ruoyi.generator.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.ruoyi.generator.domain.Community.CommunityUserNotification;
+import com.ruoyi.generator.domain.Community.CommunityUserPrivacy;
+import com.ruoyi.generator.vo.CommunityUserNotificationVo;
+import com.ruoyi.generator.vo.CommunityUserPrivacyVo;
+
+import java.util.List;
+
+/**
+ * 业务 服务层
+ *
+ * @author ruoyi
+ */
+public interface ICommunityPrivacyService extends IService<CommunityUserPrivacy> {
+
+    /**
+     * 获取通知权限
+     * @param userId
+     * @return 获取隐私权限
+     */
+    List<CommunityUserPrivacyVo> selectUserPrivacy(Long userId);
+
+    /**
+     * 更新隐私权限
+     * @param communityUserPrivacy
+     * @return 返回修改成功的对象
+     */
+    List<CommunityUserPrivacyVo> modifyUserPrivacy(CommunityUserPrivacy communityUserPrivacy);
+}