Vue3+java开发组队功能

Vue3+java开发系统组队功能

需求分析

  1. 创建用户可以创建一个队伍(一个房间队长),设置队伍人数,队伍名称(标题),描述,超时时间。
  2. 搜索
  3. 加入,用户可以加入未满的队伍(其他人,未满,未过期),是否需要队长同意
  4. 分享队伍,邀请人员
  5. 显示队伍人数
  6. 聊天
  7. 修改队伍信息
  8. 退出
  9. 解散

系统(接口)设计

  1. 判断请求参数是否为空
  2. 是否登录,未登录直接跳转到登录,不允许创建
  3. 校验信息
    1. 队伍人数大于1小于20
    2. 队伍名称<=20
    3. 队伍人数<=412
    4. 是否公开(int)不穿默认位0,公开
    5. 如果是加密状态,一定3要有密码,且密码<=32
    6. 超时时间>当前时间
    7. 校验用户最多创建5个队伍
  4. 插入队伍信息到队伍表
  5. 插入用户 => 队伍关系到关系表

实现

1. 库表设计(10min)

  1. 数据库表设计,队伍表,队伍用户表
    -- 队伍表
    create table team
    (id bigint auto_increment comment 'id'primary key,name varchar(256) not null comment '队伍名称',description varchar(1024) null comment '描述',maxNum int default 1 not null comment '最大人数',expireTime datetime null comment '过期时间',userId bigint comment '用户id',status int default 0 not null comment '0 - 公开,1 - 私有,2 - 加密',password varchar(512) null comment '密码',createTime datetime default CURRENT_TIMESTAMP null comment '创建时间',updateTime datetime default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP,isDelete tinyint default 0 not null comment '是否删除'
    )comment '队伍';-- 用户队伍关系表
    create table user_team
    (id bigint auto_increment comment 'id'primary key,userId bigint comment '用户id',teamId bigint comment '队伍id',joinTime datetime null comment '加入时间',createTime datetime default CURRENT_TIMESTAMP null comment '创建时间',updateTime datetime default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP,isDelete tinyint default 0 not null comment '是否删除'
    )comment '用户队伍关系';
    

2. 增删改查代码实现(10min)

  1. 使用mybatisX-generation插件自动生成实体类服务层,持久层代码
  2. 队伍基本增删改查代码编写
    /*** 队伍接口*/
    @RestController
    @RequestMapping("/team")
    @CrossOrigin(origins = {"http://localhost:5173"}, allowCredentials = "true")
    @Slf4j //lombok的注解,可以在类中使用log打日志
    public class TeamController {@Resourceprivate UserService userService;@Resourceprivate TeamService teamService;/*** 增加队伍* @param team* @return*/@PostMapping("/add")public BaseResponse<Long>  addTeam(@RequestBody Team team){//接收前端传来队伍的信息if(team == null){throw new  BusinessException(ErrorCode.PARAMS_ERROR);}boolean save = teamService.save(team);//teamService继承自Iservices的接口,底层实现了serviceImpl//需要返回新生成数据的id,使用mybatis的组件回写if(!save){throw new BusinessException(ErrorCode.SYSTEM_ERROR,"插入失败");}return ResultUtils.success(team.getId());}/*** 删除队伍** @param id* @return*/@PostMapping("/delete")public BaseResponse<Boolean> deleteTeam(@RequestBody long id){//接收前端传来队伍的信息if(id <= 0){throw new  BusinessException(ErrorCode.PARAMS_ERROR);}boolean result = teamService.removeById(id);//teamService继承自Iservices的接口,底层实现了serviceImpl//需要返回新生成数据的id,使用mybatis的组件回写if(!result){throw new BusinessException(ErrorCode.SYSTEM_ERROR,"删除失败");}return ResultUtils.success(true);}/*** 改动队伍** @param team* @return*/@PostMapping("/delete")public BaseResponse<Boolean> updateTeam(@RequestBody Team team){//接收前端传来队伍的信息if(team == null){throw new  BusinessException(ErrorCode.PARAMS_ERROR);}boolean result = teamService.updateById(team);//teamService继承自Iservices的接口,底层实现了serviceImpl//需要返回新生成数据的id,使用mybatis的组件回写if(!result){throw new BusinessException(ErrorCode.SYSTEM_ERROR,"更新失败");}return ResultUtils.success(true);}/*** 查询队伍** @param id* @return*/@GetMapping("/delete")public BaseResponse<Team> getTeamById(@RequestBody long id){//接收前端传来队伍id的信息if(id <= 0){throw new  BusinessException(ErrorCode.PARAMS_ERROR);}Team team = teamService.getById(id);//teamService继承自Iservices的接口,底层实现了serviceImpl//需要返回新生成数据的id,使用mybatis的组件回写if(team == null){throw new BusinessException(ErrorCode.NULL_ERROR,"数据为空!");}return ResultUtils.success(team);}
    }
  3. 查询队伍列表功能实现
    1. 新建TeamQuery业务请求参数封装类作为作为参数
      • 原因:
        1. 请求参数和实体类不一样;
        2. 有些参数用不到;
        3. 多个实体类映射到同一个字段
        4. 有些字段要隐藏不返回到前端
      • 代码实现
        /*** 队伍查询封装类*/
        @EqualsAndHashCode(callSuper = true)
        @Data
        public class TeamQuery extends PageRequest {/*** id*/@TableId(type = IdType.AUTO)private Long id;/*** 队伍名称*/private String name;/*** 描述*/private String description;/*** 最大人数*/private Integer maxNum;/*** 用户id*/private Long userId;/*** 0 - 公开,1 - 私有,2 - 加密*/private Integer status;
        }
        
    2. 实现查询队伍列表
      /*** 查询组队列表* @param teamQuery* @return*/
      @GetMapping("/list")
      //新建teamQuery业务请求参数封装类作为,原因:1.请求参数和实体类不一样;2.有些参数用不到;3.有些字段要隐藏不返回到前端
      public BaseResponse<List<Team>> listTeams(TeamQuery teamQuery){if (teamQuery == null){throw new BusinessException(ErrorCode.PARAMS_ERROR);}Team team = new Team();BeanUtils.copyProperties(team,teamQuery);QueryWrapper<Team> queryWrapper = new QueryWrapper<>();List<Team> teamList = teamService.list(queryWrapper);return ResultUtils.success(teamList);
      }
      
  4. 分页查询队伍列表功能实现
    1. 新建请求分页类
      /*** 分页请求类** @author Erha*/
      @Data
      public class PageRequest implements Serializable {//使对象序列化保持唯一private static final long serialVersionUID = -9075033996918167511L;/*** 页面大小*/protected int pageSize;/*** 当前第几页*/protected int pageNum;
      }
      
    2. 分页查询队伍实现代码
      /*** 分页查询组队列表* @param teamQuery* @return*/
      @GetMapping("/list/page")
      public BaseResponse<Page<Team>> listTeamsByPage(TeamQuery teamQuery){if(teamQuery == null){throw new  BusinessException(ErrorCode.PARAMS_ERROR);}Team team = new Team();BeanUtils.copyProperties(team, teamQuery);//把哪个对象的字段复制到另外一个中Page<Team> page = new Page<>(teamQuery.getPageNum(), teamQuery.getPageSize());QueryWrapper<Team> queryWrapper = new QueryWrapper<>(team);Page<Team> Resultpage = teamService.page(page, queryWrapper);return ResultUtils.success(Resultpage);}
      
  5. 使用Swagger+knif4j文档接口
    在这里插入图片描述

3. 业务逻辑(30min)

  1. 创建队伍业务逻辑实现
    /**
    * @author serendipity
    * @description 针对表【team(队伍)】的数据库操作Service实现
    * @createDate 2023-11-28 19:33:44
    */
    @Service
    public class TeamServiceImpl extends ServiceImpl<TeamMapper, Team>implements TeamService {@Resourceprivate UserTeamService userTeamService;@Override@Transactional(rollbackFor = Exception.class)public long addTeam(Team team, User loginUser) {//1.请求参数是否为空if (team == null) {throw new BusinessException(ErrorCode.PARAMS_ERROR);}//2.是否登录,未登录不允许创建if (loginUser == null) {throw new BusinessException(ErrorCode.NO_AUTH);}final long userId = loginUser.getId();//3.检验信息//(1).队伍人数>1且<=20int maxNum = Optional.ofNullable(team.getMaxNum()).orElse(0);//如果为空,直接赋值为0if (maxNum < 1 || maxNum > 20) {throw new BusinessException(ErrorCode.PARAMS_ERROR, "队伍人数不满足要求");}//(2).队伍标题 <=20String name = team.getName();if (StringUtils.isBlank(name) || name.length() > 20) {throw new BusinessException(ErrorCode.PARAMS_ERROR, "队伍标题不满足要求");}// (3) 描述<= 512String description = team.getDescription();if (StringUtils.isNotBlank(description) && description.length() > 512) {throw new BusinessException(ErrorCode.PARAMS_ERROR, "队伍描述过长");}//(4)status 是否公开,不传默认为0int status = Optional.ofNullable(team.getStatus()).orElse(0);TeamStatusEnum statusEnum = TeamStatusEnum.getEnumByValue(status);if (statusEnum == null) {throw new BusinessException(ErrorCode.PARAMS_ERROR, "队伍状态不满足要求");}//(5)如果status是加密状态,一定要密码 且密码<=32String password = team.getPassword();if (TeamStatusEnum.SECRET.equals(statusEnum)) {if (StringUtils.isBlank(password) || password.length() > 32) {throw new BusinessException(ErrorCode.PARAMS_ERROR, "密码设置不正确");}}//(6)超出时间 > 当前时间Date expireTime = team.getExpireTime();if (new Date().after(expireTime)) {throw new BusinessException(ErrorCode.PARAMS_ERROR, "超出时间 > 当前时间");}//(7)校验用户最多创建5个队伍//todo 有bug。可能同时创建100个队伍QueryWrapper<Team> queryWrapper = new QueryWrapper<>();queryWrapper.eq("userId", userId);long hasTeamNum = this.count(queryWrapper);if (hasTeamNum >= 5) {throw new BusinessException(ErrorCode.PARAMS_ERROR, "用户最多创建5个队伍");}//4.插入队伍消息到队伍表team.setId(null);team.setUserId(userId);boolean result = this.save(team);Long teamId = team.getId();if (!result || teamId == null) {throw new BusinessException(ErrorCode.PARAMS_ERROR, "创建队伍失败");}//5. 插入用户 ==> 队伍关系 到关系表UserTeam userTeam = new UserTeam();userTeam.setUserId(userId);userTeam.setTeamId(teamId);userTeam.setJoinTime(new Date());result = userTeamService.save(userTeam);if (!result) {throw new BusinessException(ErrorCode.PARAMS_ERROR, "创建队伍失败");}return teamId;}
    }
    

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/180475.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

github新建项目

参考链接&#xff1a;Github上建立新项目超详细方法过程 在这里新建一个repositories 接下来就选择相关的信息&#xff1a; 然后create a new就行了 接下来需要创建文件&#xff1a;&#xff08;同时通过upload上传文件&#xff09; 每次最多上传100个文件&#xff0c;然后保…

OpenGL笔记:纹理的初次使用

说明 纹理的代码写完后&#xff0c;一直出不来结果&#xff0c;原因是没有设置GL_TEXTURE_MIN_FILTER&#xff0c; 它的默认值为GL_NEAREST_MIPMAP_LINEAR&#xff0c; 因为这里我还没用到Mipmap&#xff0c;所以使用这个默认值&#xff0c;结果是错误的&#xff0c;关于mipma…

软著项目推荐 深度学习二维码识别

文章目录 0 前言2 二维码基础概念2.1 二维码介绍2.2 QRCode2.3 QRCode 特点 3 机器视觉二维码识别技术3.1 二维码的识别流程3.2 二维码定位3.3 常用的扫描方法 4 深度学习二维码识别4.1 部分关键代码 5 测试结果6 最后 0 前言 &#x1f525; 优质竞赛项目系列&#xff0c;今天…

正点原子linux应用编程——提高篇1

在之前的入门篇学习中&#xff0c;都是直接在Ubuntu中进行验证的&#xff0c;对于嵌入式Linux系统来说&#xff0c;也是可以直接移植的&#xff0c;只需要使用嵌入式硬件平台对应的交叉编译工具编译应用程序即可运行。 在嵌入式Linux系统中&#xff0c;编写的应用程序通常需要…

Prometheus的详细部署

普罗米修斯下载网址: Download | Prometheus 准备两台机器&#xff1a; 192.168.58.152 prometheus 192.168.58.142 node_exporter 关闭防火墙和selinux&#xff1a; [rootlocalhost ~]# setenforce 0 && systemctl stop firewalld[rootlocalhost ~]# seten…

nginx https 一个端口代理多个前端项目

打包修改 &#xff01;&#xff01;&#xff01;注意&#xff1a;第一个location root 调用的项目不用修改 打包路径&#xff0c;直接用 ‘/’&#xff0c;其他项目或者需加 /mobile 路径 worker_processes 1; events {worker_connections 1024; } http {include mime.…

K8S集群中PLEG问题排查

一、背景 k8s集群排障真的很麻烦 今天集群有同事找我&#xff0c;节点报 PLEG is not healthy 集群中有的节点出现了NotReady&#xff0c;这是什么原因呢&#xff1f; 二、kubernetes源码分析 PLEG is not healthy 也是一个经常出现的问题 POD 生命周期事件生成器 先说下PL…

for for in for of 的区别

for是JavaScript中最基本的循环语句&#xff0c;它可以用于遍历数组和对象中的元素&#xff0c;语法如下&#xff1a; for (初始化; 判断条件; 增量) {// 循环体 }其中&#xff0c;初始化是循环开始前执行的语句&#xff0c;判断条件是判断循环是否可以继续的条件&#xff0c;…

Pybullet -------[ 1 ]

1. p.addUserDebugText() 这个函数允许在仿真环境中动态添加文本&#xff0c;用于调试和可视化。你可以指定文本的内容、位置、颜色、大小等属性。 p.addUserDebugText(text, textPosition, textColorRGB[1,1,1], textSize1, lifeTime0, parentObjectUniqueId0,parentLinkInde…

机器视觉双目测宽仪具体有什么优势?

双目测宽仪是机器视觉原来制造而成的智能宽度检测设备&#xff0c;广泛应用于板材类产品的宽度检测。通过测宽仪的使用&#xff0c;实时了解产品宽度品质&#xff0c;进行超差提示&#xff0c;减少废品的生产。 双目测宽仪优势 测量软件界面显示&#xff1a;产品规格、标称宽…

MATLAB算法实战应用案例精讲-【图像处理】FPGA

目录 前言 算法原理 FPGA 是什么 FPGA的定义以及和GPU的类比 FPGA 有什么用 1)通信领域

Android控件全解手册 - 任意View缩放平移工具-源码

Unity3D特效百例案例项目实战源码Android-Unity实战问题汇总游戏脚本-辅助自动化Android控件全解手册再战Android系列Scratch编程案例软考全系列Unity3D学习专栏蓝桥系列ChatGPT和AIGC &#x1f449;关于作者 专注于Android/Unity和各种游戏开发技巧&#xff0c;以及各种资源分…

详细介绍如何使用 PaddleOCR 进行光学字符识别-(含源码及讲解)

阅读巨大的文档可能会非常累并且非常耗时。您一定见过许多软件或应用程序,只需单击图片即可从文档中获取关键信息。这是通过一种称为光学字符识别 (OCR) 的技术来完成的。光学字符识别是近年来人工智能领域的重点研究之一。光学字符识别是通过理解和分析图像的基本模式来识别图…

竞赛选题 题目:基于机器视觉的图像矫正 (以车牌识别为例) - 图像畸变校正

文章目录 0 简介1 思路简介1.1 车牌定位1.2 畸变校正 2 代码实现2.1 车牌定位2.1.1 通过颜色特征选定可疑区域2.1.2 寻找车牌外围轮廓2.1.3 车牌区域定位 2.2 畸变校正2.2.1 畸变后车牌顶点定位2.2.2 校正 7 最后 0 简介 &#x1f525; 优质竞赛项目系列&#xff0c;今天要分享…

yolov8-pose姿势估计,站立识别

系列文章目录 基于yolov8-pose的姿势估计模式,实现站姿,坐姿,伏案睡姿识别,姿态动作识别接口逻辑作参考。本文以学习交流,分享,欢迎留言讨论优化。 yoloPose-姿势动作识别 系列文章目录前言一、环境安装二、使用yolov8-pose1.导入模型,预测图像三.姿势动作识别之站立总…

unity实时保存对象的位姿,重新运行程序时用最后保存的数据给物体赋值

using UnityEngine; using System.IO; // using System.Xml.Serialization; public class SaveCoordinates : MonoBehaviour {public GameObject MainObject;//读取坐标private float x;private float y;private float z;private Quaternion quaternion;private void Start(){/…

如何使用torchrun启动单机多卡DDP并行训练

如何使用torchrun启动单机多卡DDP并行训练 这是一个最近项目中需要使用的方式&#xff0c;新近的数据集大概在40w的规模&#xff0c;而且载入的原始特征都比较大&#xff08;5&#xff5e;7M&#xff09;&#xff0c;所以准备尝试DistributedDataParallel&#xff1b; 主要目…

Qt 自定义标题栏

在Qt中&#xff0c;如果你想要自定义窗口的标题栏&#xff0c;你可以通过覆盖窗口的windowTitleChanged信号来实现。然而&#xff0c;直接修改Qt的标题栏可能会带来一些问题&#xff0c;因为Qt的设计是尽量使窗口系统的行为标准化。 以下是一个基本的示例&#xff0c;如何在Qt…

Java中的集合

Java中的集合 java.util 包中的集合 Java 集合框架提供了各种集合类&#xff0c;用于存储和管理对象。以下是 Java 集合框架中常见的集合类&#xff1a; List 接口表示一个有序的集合&#xff0c;其中的元素可以重复。List 接口有以下实现类&#xff1a; ArrayList&#xff1…

人工智能_机器学习053_支持向量机SVM目标函数推导_SVM条件_公式推导过程---人工智能工作笔记0093

然后我们再来看一下支持向量机SVM的公式推导情况 来看一下支持向量机是如何把现实问题转换成数学问题的. 首先我们来看这里的方程比如说,中间的黑线我们叫做l2 那么上边界线我们叫l1 下边界线叫做l3 如果我们假设l2的方程是上面这个方程WT.x+b = 0 那么这里 我们只要确定w和…