Stories

Detail Return Return

【Spring開發】SpringCloud交友項目實戰第8篇:1.3 設置陌生人問題,1.4 通知設置【附代碼文檔】 - Stories Detail

🏆🏆🏆教程全知識點簡介:1、Dubbo的前世今生 1、項目介紹 1.1、項目背景 1.2、市場分析 1.3、目標用户羣體 1.4、使用場景 1.5、競爭對手分析 1.7、技術方案 2、前後端分離開發思想 3、開發工具與環境搭建 3.1、開發工具 3.2、環境搭建 4、sms_code驗證瑪 4.1 阿里雲短信 4.2 自動裝配 1. 完善用户信息 1.2 百度人臉識別 1.2.1 概述 1.2.2 賬號申請 1.2.4 抽取模板工具 2.2 更新用户資料 2.2.1 接口文檔 2.2.2 代碼實現 3. 統一token處理 3.1.需求分析 3.2 解決方案 攔截器(Interceptor) ThreadLocal MongoDB入門 數據庫以及表的操作 新增數據 更新數據 刪除數據 查詢數據 1.3 設置陌生人問題 1.4 通知設置 1.5 黑名單管理 4. SpringData-Mongo 4.2 完成基本操作 5. 今日佳人 5.1 表結構設計 5.2 服務提供者 5.2.0 導入依賴 5.2.2 RecommendUserApi接口 分片集羣 原理介紹 集羣搭建 2、圈子功能 2.1、功能説明 3、圈子實現 3.2、發佈動態 1. 動態查詢 1.1 查詢好友動態 2. 圈子互動 2.3 動態點贊 2.4.3 喜歡標識 安裝 準備 使用 1. 即時通信 2. 環信 2.1 開發簡介 2.2 環信Console 2.3 環信API介紹 初始化 基礎API 3. 抽取環信組件 3.1 編寫Properties對象 3.2 編寫HuanXinTemplate 3.3 編寫自動配置類 2. MongoDB地理位置檢索 2.1 地理位置索引 Point LineString Polygon 2.2 案例 3. 上報地理位置 4. 搜附近 1. 我的訪客 1.2 記錄訪客數據 tanhua-model tanhua-app-server tanhua-dubbo-interface 1.3 首頁誰看過我 需求分析 3. FastDFS 3.2. 工作原理 3.2.1. 文件的上傳 分佈式文件系統FDFS配置 4. 發佈小視頻 1、用户凍結解凍 1.1 用户凍結 1.3 查詢數據列表 1.4 明日系統修改 2.2 定時任務 3、內容審核 1、瞭解推薦系統 1.1、什麼是推薦系統? 1.3、推薦系統業務流程 1.4、協同過濾推薦算法 1.5、ALS算法 2、好友推薦 2.1、流程 2.2、部署好友推薦服務

<!-- start:bj1 -->

📚📚倉庫code.zip 👉直接-->:   https://gitee.com/xiaoshuai112/Backend/blob/master/Spring/Spr...    🍅🍅

<!-- end:bj1 -->

✨ 本教程項目亮點

🧠 知識體系完整:覆蓋從基礎原理、核心方法到高階應用的全流程內容
💻 全技術鏈覆蓋:完整前後端技術棧,涵蓋開發必備技能
🚀 從零到實戰:適合 0 基礎入門到提升,循序漸進掌握核心能力
📚 豐富文檔與代碼示例:涵蓋多種場景,可運行、可複用
🛠 工作與學習雙參考:不僅適合系統化學習,更可作為日常開發中的查閲手冊
🧩 模塊化知識結構:按知識點分章節,便於快速定位和複習
📈 長期可用的技術積累:不止一次學習,而是能伴隨工作與項目長期參考

🎯🎯🎯全教程總章節


🚀🚀🚀本篇主要內容

1.3 設置陌生人問題

對數據庫表進行操作:如果存在數據,更新數據庫。如果不存在數據,保存數據庫表數據

1.3.1 接口文檔

接口地址:http://192.168.136.160:3000/project/19/interface/api/277

<img src="/img/bVdmsBL" alt="image-20211111180051018" style="zoom:67%;" />

1.3.2 代碼實現

tanhua-app-server

在<font color=red>tanhua-app-server</font>中SettingsControllersettingsService添加方法

SettingsController

SettingsController中定義保存用户陌生人問題的方法

    /**
     * 設置陌生人問題
     */
    @PostMapping("/questions")
    public ResponseEntity questions(@RequestBody Map map) {
        //獲取參數
        String content = (String) map.get("content");
        settingsService.saveQuestion(content);
        return ResponseEntity.ok(null);
    }
SettingsService

SettingsService中編寫保存用户陌生人問題的業務邏輯

    //設置陌生人問題
    public void saveQuestion(String content) {
        //1、獲取當前用户id
        Long userId = UserHolder.getUserId();
        //2、調用api查詢當前用户的陌生人問題
        Question question = questionApi.findByUserId(userId);
        //3、判斷問題是否存在
        if(question == null) {
            //3.1 如果不存在,保存
            question = new Question();
            question.setUserId(userId);
            question.setTxt(content);
            questionApi.save(question);
        }else {
            //3.2 如果存在,更新
            question.setTxt(content);
            questionApi.update(question);
        }
    }
tanhua-dubbo-interface

在<font color=red>tanhua-dubbo-interface</font>模塊的QuestionApi中定義保存和更新陌生人問題的方法

//保存
void save(Question question);

//更新
void update(Question question);
tanhua-dubbo-db

在<font color=red>tanhua-dubbo-db</font>模塊的QuestionApiImpl實現保存和更新陌生人問題的方法

//保存問題
public void save(Question question) {
    questionMapper.insert(question);
}

//更新問題
public void update(Question question) {
    questionMapper.updateById(question);
}

1.4 通知設置

1.4.1 接口文檔

通知管理:對通知進行保存或者更新的操作

http://192.168.136.160:3000/project/19/interface/api/280

1.4.2 代碼實現

tanhua-app-server

在<font color=red>tanhua-app-server</font>中SettingsControllersettingsService添加方法

SettingsController

SettingsController中定義保存用户通知設置的方法

    /**
     * 通知設置
     */
    @PostMapping("/notifications/setting")
    public ResponseEntity notifications(@RequestBody Map map) {
        //獲取參數
        settingsService.saveSettings(map);
        return ResponseEntity.ok(null);
    }
settingsService

SettingsService中編寫保存用户通知的業務邏輯

Spring WebFlux 文檔

    //通知設置
    public void saveSettings(Map map) {
        boolean likeNotification = (Boolean) map.get("likeNotification");
        boolean pinglunNotification = (Boolean) map.get("pinglunNotification");
        boolean gonggaoNotification = (Boolean)  map.get("gonggaoNotification");
        //1、獲取當前用户id
        Long userId = UserHolder.getUserId();
        //2、根據用户id,查詢用户的通知設置
        Settings settings = settingsApi.findByUserId(userId);
        //3、判斷
        if(settings == null) {
            //保存
            settings = new Settings();
            settings.setUserId(userId);
            settings.setPinglunNotification(pinglunNotification);
            settings.setLikeNotification(likeNotification);
            settings.setGonggaoNotification(gonggaoNotification);
            settingsApi.save(settings);
        }else {
            settings.setPinglunNotification(pinglunNotification);
            settings.setLikeNotification(likeNotification);
            settings.setGonggaoNotification(gonggaoNotification);
            settingsApi.update(settings);
        }
    }
tanhua-dubbo-interface

在<font color=red>tanhua-dubbo-interface</font>模塊的SettingsApi中定義保存和更新通知設置的API接口方法

//保存
void save(Settings settings);

//更新
void update(Settings settings);
tanhua-dubbo-db

在<font color=red>tanhua-dubbo-db</font>模塊的SettingsApiImpl中實現保存和更新通知設置的API接口方法

//保存通知設置
public void save(Settings settings) {
    settingsMapper.insert(settings);
}

//更新通知設置
public void update(Settings settings) {
    settingsMapper.updateById(settings);
}

1.5 黑名單管理

1.5.1 查詢黑名單列表

接口文檔

接口地址:http://192.168.136.160:3000/project/19/interface/api/286

vo對象

tanhua-model工程中配置分頁vo對象

package com.tanhua.domain.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class PageResult implements Serializable {

    private Integer counts = 0;//總記錄數
    private Integer pagesize;//頁大小
    private Integer pages = 0;//總頁數
    private Integer page;//當前頁碼
    private List<?> items = Collections.emptyList(); //列表

    public PageResult(Integer page,Integer pagesize,int counts,List list) {
        this.page = page;
        this.pagesize = pagesize;
        this.items = list;
        this.counts = counts;
        this.pages = counts % pagesize == 0 ? counts / pagesize : counts / pagesize + 1;
    }
}

Leiningen 文檔

tanhua-app-server

在<font color=red>tanhua-app-server</font>中SettingsControllersettingsService添加方法

SettingsController

SettingsController中定義查詢用户黑名單列表的方法

    /**
     * 分頁查詢黑名單列表
     */
    @GetMapping("/blacklist")
    public ResponseEntity blacklist(
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int size) {
        //1、調用service查詢
        PageResult pr = settingsService.blacklist(page,size);
        //2、構造返回
        return ResponseEntity.ok(pr);
    }
settingsService

SettingsService中定義查詢用户黑名單列表的方法 , 編寫查詢用户黑名單列表的業務邏輯

    //分頁查詢黑名單列表
    public PageResult blacklist(int page, int size) {
        //1、獲取當前用户的id
        Long userId = UserHolder.getUserId();
        //2、調用API查詢用户的黑名單分頁列表  Ipage對象
        IPage<UserInfo> iPage = blackListApi.findByUserId(userId,page,size);
        //3、對象轉化,將查詢的Ipage對象的內容封裝到PageResult中
        PageResult pr = new PageResult(page,size,iPage.getTotal(),iPage.getRecords());
        //4、返回
        return pr;
    }
tanhua-dubbo-interface

在<font color=red>`tanhua

Add a new Comments

Some HTML is okay.