当前位置: 首页 > news >正文

【探花交友】查询通用设置、陌生人问题、黑名单管理

目录

1、通用设置

1.1 需求分析

1.2 查询通用设置

1.2 陌生人问题

1.3 通知设置

1.4 黑名单管理

1、通用设置

1.1 需求分析

1.1.1 需求分析

通用设置,包含探花交友APP基本的软件设置功能。包含:

设置陌生人问题:当平台其他用户想进行在线交流时需要回答陌生人问题。

通用设置:包含一些APP通知设置

黑名单:对于不感兴趣的用户设置黑名单屏蔽骚扰

 

1.1.2 数据库表

通用设置

CREATE TABLE `tb_settings` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `user_id` bigint(20) DEFAULT NULL,
  `like_notification` tinyint(4) DEFAULT '1' COMMENT '推送喜欢通知',
  `pinglun_notification` tinyint(4) DEFAULT '1' COMMENT '推送评论通知',
  `gonggao_notification` tinyint(4) DEFAULT '1' COMMENT '推送公告通知',
  `created` datetime DEFAULT NULL,
  `updated` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='设置表';

问题表

CREATE TABLE `tb_question` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `user_id` bigint(20) DEFAULT NULL COMMENT '用户id',
  `txt` varchar(200) DEFAULT NULL COMMENT '问题内容',
  `created` datetime DEFAULT NULL,
  `updated` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `user_id` (`user_id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8

黑名单

CREATE TABLE `tb_black_list` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `user_id` bigint(20) DEFAULT NULL,
  `black_user_id` bigint(20) DEFAULT NULL,
  `created` datetime DEFAULT NULL,
  `updated` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='黑名单';

1.1.3 搭建提供者环境

实体类

(1) Settings

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Settings extends BasePojo {
​
    private Long id;
    private Long userId;
    private Boolean likeNotification;
    private Boolean pinglunNotification;
    private Boolean gonggaoNotification;
​
}

(2)Question

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Question extends BasePojo {
​
    private Long id;
    private Long userId;
    //问题内容
    private String txt;
​
}

(3)BlackList

@Data
@NoArgsConstructor
@AllArgsConstructor
public class BlackList extends BasePojo {
​
    private Long id;
    private Long userId;
    private Long blackUserId;
}

mapper接口

(1)SettingsMapper

public interface SettingsMapper extends BaseMapper<Settings> {
}

(2)QuestionMapper

public interface QuestionMapper extends BaseMapper<Question> {
​
}

(3)BlackListMapper

public interface BlackListMapper extends BaseMapper<BlackList> {
    
}

api接口

(1) SettingApi

package com.tanhua.dubbo.api;
​
import com.tanhua.domain.db.Settings;
​
public interface SettingsApi {
​
}
​

(2)QuestionApi

package com.tanhua.dubbo.api;
​
import com.tanhua.domain.db.Question;
​
​
public interface QuestionApi {
​
}
​

(3)BlackListApi

package com.tanhua.dubbo.api;
​
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.tanhua.domain.db.UserInfo;
​
public interface BlackListApi {
​
}
​

api服务实现类

(1)SettingServiceImpl

package com.tanhua.dubbo.api;
​
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.domain.db.Settings;
import com.tanhua.dubbo.mapper.SettingsMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
​
@Service
public class SettingsApiImpl implements SettingsApi {
​
    @Autowired
    private SettingsMapper settingsMapper;
​
}
​

(2)QuestionServiceImpl

package com.tanhua.dubbo.api;
​
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.domain.db.Question;
import com.tanhua.dubbo.mapper.QuestionMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
​
@Service
public class QuestionApiImpl implements QuestionApi {
​
    @Autowired
    private QuestionMapper questionMapper;
​
}
​

(3)BlackListServiceImpl

package com.tanhua.dubbo.api;
​
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.domain.db.BlackList;
import com.tanhua.domain.db.UserInfo;
import com.tanhua.dubbo.mapper.BlackListMapper;
import com.tanhua.dubbo.mapper.UserInfoMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
​
@Service
public class BlackListApiImpl implements BlackListApi {
​
    @Autowired
    private BlackListMapper blackListMapper;
}
​

1.2 查询通用设置

1.2.1 接口文档

 

1.2.2 代码实现

vo对象

@Data
@NoArgsConstructor
@AllArgsConstructor
public class SettingsVo implements Serializable {
​
    private Long id;
    private String strangerQuestion = "";
    private String phone;
    private Boolean likeNotification = true;
    private Boolean pinglunNotification = true;
    private Boolean gonggaoNotification = true;
​
}

SettingsController

tanhua-server工程创建SettingsController完成代码编写

@RestController
@RequestMapping("/users")
public class SettingsController {
​
    @Autowired
    private SettingsService settingsService;
​
    /**
     * 查询通用设置
     */
    @GetMapping("/settings")
    public ResponseEntity settings() {
        SettingsVo vo = settingsService.settings();
        return ResponseEntity.ok(vo);
    }
}

SettingService

tanhua-server工程创建SettingService完成代码编写

@Service
public class SettingsService {
​
    @DubboReference
    private QuestionApi questionApi;
​
    @DubboReference
    private SettingsApi settingsApi;
​
    @DubboReference
    private BlackListApi blackListApi;
​
    //查询通用设置
    public SettingsVo settings() {
        SettingsVo vo = new SettingsVo();
        //1、获取用户id
        Long userId = UserHolder.getUserId();
        vo.setId(userId);
        //2、获取用户的手机号码
        vo.setPhone(UserHolder.getMobile());
        //3、获取用户的陌生人问题
        Question question = questionApi.findByUserId(userId);
        String txt = question == null ? "你喜欢java吗?" : question.getTxt();
        vo.setStrangerQuestion(txt);
        //4、获取用户的APP通知开关数据
        Settings settings = settingsApi.findByUserId(userId);
        if(settings != null) {
            vo.setGonggaoNotification(settings.getGonggaoNotification());
            vo.setPinglunNotification(settings.getPinglunNotification());
            vo.setLikeNotification(settings.getLikeNotification());
        }
        return vo;
    }
}

QuestionApi

在tanhua-dubbo中的QuestionApiQuestionApiImpl补充方法

@Override
public Question findByUserId(Long userId) {
    QueryWrapper<Question> qw = new QueryWrapper<>();
    qw.eq("user_id",userId);
    return questionMapper.selectOne(qw);
}

SettingApi

在tanhua-dubbo中的SettingApiSettingApiImpl补充方法

//根据用户id查询
public Settings findByUserId(Long userId) {
    QueryWrapper<Settings> qw = new QueryWrapper<>();
    qw.eq("user_id",userId);
    return settingsMapper.selectOne(qw);
}

1.2 陌生人问题

对数据库表进行操作:如果存在数据,更新数据库。如果不存在数据,保存数据库表数据

1.2.1 接口文档

 

1.2.2 代码实现

SettingsController

/**
 * 设置陌生人问题
 */
@PostMapping("/questions")
public ResponseEntity questions(@RequestBody Map map) {
    //获取参数
    String content = (String) map.get("content");
    settingsService.saveQuestion(content);
    return ResponseEntity.ok(null);
}

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);
    }
}

QuestionApi

tanhua-dubbo工程中的QuestionApiQuestionApiImpl中添加保存和更新方法

@Override
public void save(Question question) {
    questionMapper.insert(question);
}
​
@Override
public void update(Question question) {
    questionMapper.updateById(question);
}

1.3 通知设置

1.3.1 接口文档

通知管理:对通知进行保存或者更新的操作

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

 

1.3.2 代码实现

SettingsController

/**
 * 通知设置
 */
@PostMapping("/notifications/setting")
public ResponseEntity notifications(@RequestBody Map map) {
    //获取参数
    settingsService.saveSettings(map);
    return ResponseEntity.ok(null);
}

SettingsService

//通知设置
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);
    }
}

SettingsApi

tanhua-dubbo工程中的SettingsApiSettingsApiImpl中添加保存和更新方法

@Override
public void save(Settings settings) {
    settingsMapper.insert(settings);
}
​
@Override
public void update(Settings settings) {
    settingsMapper.updateById(settings);
}

1.4 黑名单管理

1.3.1 接口文档

  • 查询黑名单列表

 

 

  • 移除黑名单

 

1.3.2 分页查询

vo对象

tanhua-domain工程的配置分页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;
    }
​
}

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);
}
​
/**
 * 取消黑名单
 */
@DeleteMapping("/blacklist/{uid}")
public ResponseEntity deleteBlackList(@PathVariable("uid") Long blackUserId) {
    settingsService.deleteBlackList(blackUserId);
    return ResponseEntity.ok(null);
}

SettingService

//分页查询黑名单列表
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;
}
​
//取消黑名单
public void deleteBlackList(Long blackUserId) {
    //1、获取当前用户id
    Long userId = UserHolder.getUserId();
    //2、调用api删除
    blackListApi.delete(userId,blackUserId);
}

BlackListApi

@Override
public IPage<UserInfo> findByUserId(Long userId, int page, int size) {
    //1、构建分页参数对象Page
    Page pages = new Page(page,size);
    //2、调用方法分页(自定义编写 分页参数Page,sql条件参数)
    return userInfoMapper.findBlackList(pages,userId);
}
​
@Override
public void delete(Long userId, Long blackUserId) {
    QueryWrapper<BlackList> qw = new QueryWrapper<>();
    qw.eq("user_id",userId);
    qw.eq("black_user_id",blackUserId);
    blackListMapper.delete(qw);
}

UserInfoMapper

public interface UserInfoMapper extends BaseMapper<UserInfo> {
​
    @Select("select * from tb_user_info where id in (\n" +
            "  SELECT black_user_id FROM tb_black_list where user_id=#{userId}\n" +
            ")")
    IPage<UserInfo> findBlackList(@Param("pages") Page pages, @Param("userId") Long userId);
}

MybatisPlusConfig

tanhua-dubbo-db引导类开启mybatis-plus分页插件支持

@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
    MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
    interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
    return interceptor;
}

使用mybatis-plus的分页:

  • 创建分页对象:Page,指定当前页和每页查询条数

  • 基础查询:mapper.selectPage(page,查询条件)

  • 自定义查询:Ipage 方法名称(Page对象,xxx查询条件)

相关文章:

  • 【AUTOSAR-IpduM】-3.1-配置一个发送Tx Dynamic Container PDU(Multiple-PDU)
  • Python编程 pip换源
  • 游戏网页代码 html静态网页设计制作 dw静态网页成品模板素材网页 web前端网页设计与制作 div静态网页设计
  • JavaScript基础(2)
  • (附源码)计算机毕业设计SSM疫情社区管理系统
  • 【MyBatis框架】实现增删改查功能
  • 【算法刷题日记之本手篇】左右最值最大差与顺时针打印矩阵
  • Redis 的安装
  • Netty网络编程实战2,使用Netty开发聊天室功能
  • 一文搞懂CAN总线协议帧格式
  • 使用MATLAB控制笔记本电脑的摄像头,并进行实时人脸检测和识别
  • 微信小程序|基于小程序实现透明背景人像分割
  • React中编写CSS的常见方案
  • 利用HFS软件一分钟搭建好ESP8266基于Arduino开发环境
  • MongoDB必备知识点全面总结
  • 【140天】尚学堂高淇Java300集视频精华笔记(86-87)
  • es6要点
  • ESLint简单操作
  • Intervention/image 图片处理扩展包的安装和使用
  • java8 Stream Pipelines 浅析
  • JavaWeb(学习笔记二)
  • Java小白进阶笔记(3)-初级面向对象
  • Leetcode 27 Remove Element
  • Lucene解析 - 基本概念
  • Mysql5.6主从复制
  • nginx(二):进阶配置介绍--rewrite用法,压缩,https虚拟主机等
  • QQ浏览器x5内核的兼容性问题
  • vagrant 添加本地 box 安装 laravel homestead
  • 阿里中间件开源组件:Sentinel 0.2.0正式发布
  • 飞驰在Mesos的涡轮引擎上
  • 回顾2016
  • 快速体验 Sentinel 集群限流功能,只需简单几步
  • 前端每日实战:61# 视频演示如何用纯 CSS 创作一只咖啡壶
  • 如何打造100亿SDK累计覆盖量的大数据系统
  • 使用 5W1H 写出高可读的 Git Commit Message
  • 小程序滚动组件,左边导航栏与右边内容联动效果实现
  • 400多位云计算专家和开发者,加入了同一个组织 ...
  • 机器人开始自主学习,是人类福祉,还是定时炸弹? ...
  • ​ ​Redis(五)主从复制:主从模式介绍、配置、拓扑(一主一从结构、一主多从结构、树形主从结构)、原理(复制过程、​​​​​​​数据同步psync)、总结
  • $().each和$.each的区别
  • $.ajax()
  • (02)Cartographer源码无死角解析-(03) 新数据运行与地图保存、加载地图启动仅定位模式
  • (4)(4.6) Triducer
  • (附源码)springboot码头作业管理系统 毕业设计 341654
  • (更新)A股上市公司华证ESG评级得分稳健性校验ESG得分年均值中位数(2009-2023年.12)
  • (六)激光线扫描-三维重建
  • (南京观海微电子)——I3C协议介绍
  • (数据结构)顺序表的定义
  • (小白学Java)Java简介和基本配置
  • (一) springboot详细介绍
  • (转)iOS字体
  • (转载)CentOS查看系统信息|CentOS查看命令
  • *上位机的定义
  • .bat文件调用java类的main方法
  • .Net 8.0 新的变化