han-note项目初始化完毕!

- 注册登录接口,开发40%
This commit is contained in:
Hanserwei
2025-09-30 16:48:48 +08:00
parent 96de704258
commit d2c76be3b8
14 changed files with 316 additions and 19 deletions

View File

@@ -65,6 +65,10 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId> <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency> </dependency>
<dependency>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-redis-jackson</artifactId>
</dependency>
</dependencies> </dependencies>

View File

@@ -2,7 +2,7 @@ package com.hanserwei.hannote.auth.controller;
import com.hanserwei.framework.biz.operationlog.aspect.ApiOperationLog; import com.hanserwei.framework.biz.operationlog.aspect.ApiOperationLog;
import com.hanserwei.framework.common.response.Response; import com.hanserwei.framework.common.response.Response;
import com.hanserwei.hannote.auth.model.vo.SendVerificationCodeReqVO; import com.hanserwei.hannote.auth.model.vo.verificationcode.SendVerificationCodeReqVO;
import com.hanserwei.hannote.auth.service.VerificationCodeService; import com.hanserwei.hannote.auth.service.VerificationCodeService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;

View File

@@ -0,0 +1,104 @@
package com.hanserwei.hannote.auth.domain.dataobject;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
/**
* 用户表
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName(value = "t_user")
public class UserDO {
/**
* 主键ID
*/
@TableId(value = "id", type = IdType.ASSIGN_ID)
private Long id;
/**
* 小哈书号(唯一凭证)
*/
@TableField(value = "han_note_id")
private String hanNoteId;
/**
* 密码
*/
@TableField(value = "`password`")
private String password;
/**
* 昵称
*/
@TableField(value = "nickname")
private String nickname;
/**
* 头像
*/
@TableField(value = "avatar")
private String avatar;
/**
* 生日
*/
@TableField(value = "birthday")
private Date birthday;
/**
* 背景图
*/
@TableField(value = "background_img")
private String backgroundImg;
/**
* 邮箱
*/
@TableField(value = "email")
private String email;
/**
* 性别(0女 1男)
*/
@TableField(value = "sex")
private Byte sex;
/**
* 状态(0启用 1禁用)
*/
@TableField(value = "`status`")
private Byte status;
/**
* 个人简介
*/
@TableField(value = "introduction")
private String introduction;
/**
* 创建时间
*/
@TableField(value = "create_time")
private Date createTime;
/**
* 更新时间
*/
@TableField(value = "update_time")
private Date updateTime;
/**
* 逻辑删除(0未删除 1已删除)
*/
@TableField(value = "is_deleted")
private Boolean isDeleted;
}

View File

@@ -0,0 +1,7 @@
package com.hanserwei.hannote.auth.domain.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hanserwei.hannote.auth.domain.dataobject.UserDO;
public interface UserDOMapper extends BaseMapper<UserDO> {
}

View File

@@ -0,0 +1,27 @@
package com.hanserwei.hannote.auth.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Objects;
@Getter
@AllArgsConstructor
public enum LoginTypeEnum {
// 验证码
VERIFICATION_CODE(1),
// 密码
PASSWORD(2);
private final Integer value;
public static LoginTypeEnum valueOf(Integer code) {
for (LoginTypeEnum loginTypeEnum : LoginTypeEnum.values()) {
if (Objects.equals(code, loginTypeEnum.getValue())) {
return loginTypeEnum;
}
}
return null;
}
}

View File

@@ -15,7 +15,8 @@ public enum ResponseCodeEnum implements BaseExceptionInterface {
// ----------- 业务异常状态码 ----------- // ----------- 业务异常状态码 -----------
VERIFICATION_CODE_SEND_FREQUENTLY("AUTH-20000", "请求太频繁请3分钟后再试"), VERIFICATION_CODE_SEND_FREQUENTLY("AUTH-20000", "请求太频繁请3分钟后再试"),
MAIL_SEND_ERROR("AUTH-20001", "邮件发送失败,请稍后再试"), MAIL_SEND_ERROR("AUTH-20001", "邮件发送失败,请稍后再试"),
TEMPLATE_RENDER_ERROR("AUTH-20002", "模板渲染错误") TEMPLATE_RENDER_ERROR("AUTH-20002", "模板渲染错误"),
USER_NOT_EXIST("AUTH-20003", "用户不存在"),
; ;
// 异常码 // 异常码

View File

@@ -0,0 +1,39 @@
package com.hanserwei.hannote.auth.model.vo.user;
import com.hanserwei.framework.common.validate.EmailNumber;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class UserLoginReqVO {
/**
* 邮箱号
*/
@NotBlank(message = "邮箱不能为空")
@EmailNumber
private String phone;
/**
* 验证码
*/
private String code;
/**
* 密码
*/
private String password;
/**
* 登录类型:邮箱验证码,或者是账号密码
*/
@NotNull(message = "登录类型不能为空")
private Integer type;
}

View File

@@ -1,4 +1,4 @@
package com.hanserwei.hannote.auth.model.vo; package com.hanserwei.hannote.auth.model.vo.verificationcode;
import com.hanserwei.framework.common.validate.EmailNumber; import com.hanserwei.framework.common.validate.EmailNumber;
import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotBlank;

View File

@@ -1,7 +1,7 @@
package com.hanserwei.hannote.auth.service; package com.hanserwei.hannote.auth.service;
import com.hanserwei.framework.common.response.Response; import com.hanserwei.framework.common.response.Response;
import com.hanserwei.hannote.auth.model.vo.SendVerificationCodeReqVO; import com.hanserwei.hannote.auth.model.vo.verificationcode.SendVerificationCodeReqVO;
public interface VerificationCodeService { public interface VerificationCodeService {

View File

@@ -5,7 +5,7 @@ import com.hanserwei.framework.common.exception.ApiException;
import com.hanserwei.framework.common.response.Response; import com.hanserwei.framework.common.response.Response;
import com.hanserwei.hannote.auth.constant.RedisKeyConstants; import com.hanserwei.hannote.auth.constant.RedisKeyConstants;
import com.hanserwei.hannote.auth.enums.ResponseCodeEnum; import com.hanserwei.hannote.auth.enums.ResponseCodeEnum;
import com.hanserwei.hannote.auth.model.vo.SendVerificationCodeReqVO; import com.hanserwei.hannote.auth.model.vo.verificationcode.SendVerificationCodeReqVO;
import com.hanserwei.hannote.auth.service.VerificationCodeService; import com.hanserwei.hannote.auth.service.VerificationCodeService;
import com.hanserwei.hannote.auth.utils.MailHelper; import com.hanserwei.hannote.auth.utils.MailHelper;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hanserwei.hannote.auth.domain.mapper.UserDOMapper">
<resultMap id="BaseResultMap" type="com.hanserwei.hannote.auth.domain.dataobject.UserDO">
<!--@mbg.generated-->
<!--@Table t_user-->
<id column="id" jdbcType="BIGINT" property="id" />
<result column="han_note_id" jdbcType="VARCHAR" property="hanNoteId" />
<result column="password" jdbcType="VARCHAR" property="password" />
<result column="nickname" jdbcType="VARCHAR" property="nickname" />
<result column="avatar" jdbcType="VARCHAR" property="avatar" />
<result column="birthday" jdbcType="DATE" property="birthday" />
<result column="background_img" jdbcType="VARCHAR" property="backgroundImg" />
<result column="email" jdbcType="VARCHAR" property="email" />
<result column="sex" jdbcType="TINYINT" property="sex" />
<result column="status" jdbcType="TINYINT" property="status" />
<result column="introduction" jdbcType="VARCHAR" property="introduction" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
<result column="is_deleted" jdbcType="BIT" property="isDeleted" />
</resultMap>
<sql id="Base_Column_List">
<!--@mbg.generated-->
id, han_note_id, `password`, nickname, avatar, birthday, background_img, email, sex,
`status`, introduction, create_time, update_time, is_deleted
</sql>
</mapper>

View File

@@ -139,6 +139,11 @@
<artifactId>commons-lang3</artifactId> <artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version> <version>${commons-lang3.version}</version>
</dependency> </dependency>
<dependency>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-redis-jackson</artifactId>
<version>${sa-token.version}</version>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>

17
sql/createData.sql Normal file
View File

@@ -0,0 +1,17 @@
INSERT INTO `t_permission` (`id`, `parent_id`, `name`, `type`, `menu_url`, `menu_icon`, `sort`, `permission_key`,
`status`, `create_time`, `update_time`, `is_deleted`)
VALUES (1, 0, '发布笔记', 3, '', '', 1, 'app:note:publish', 0, now(), now(), b'0');
INSERT INTO `t_permission` (`id`, `parent_id`, `name`, `type`, `menu_url`, `menu_icon`, `sort`, `permission_key`,
`status`, `create_time`, `update_time`, `is_deleted`)
VALUES (2, 0, '发布评论', 3, '', '', 2, 'app:comment:publish', 0, now(), now(), b'0');
INSERT INTO `t_role` (`id`, `role_name`, `role_key`, `status`, `sort`, `remark`, `create_time`, `update_time`,
`is_deleted`)
VALUES (1, '普通用户', 'common_user', 0, 1, '', now(), now(), b'0');
INSERT INTO `t_role_permission_rel` (`id`, `role_id`, `permission_id`, `create_time`, `update_time`, `is_deleted`)
VALUES (1, 1, 1, now(), now(), b'0');
INSERT INTO `t_role_permission_rel` (`id`, `role_id`, `permission_id`, `create_time`, `update_time`, `is_deleted`)
VALUES (2, 1, 2, now(), now(), b'0');

View File

@@ -1,20 +1,86 @@
CREATE TABLE `t_user` CREATE TABLE `t_user`
( (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID', `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`han_note_id` varchar(15) NOT NULL COMMENT '小哈书号(唯一凭证)', `han_note_id` varchar(15) NOT NULL COMMENT '小哈书号(唯一凭证)',
`password` varchar(64) DEFAULT NULL COMMENT '密码', `password` varchar(64) DEFAULT NULL COMMENT '密码',
`nickname` varchar(24) NOT NULL COMMENT '昵称', `nickname` varchar(24) NOT NULL COMMENT '昵称',
`avatar` varchar(120) DEFAULT NULL COMMENT '头像', `avatar` varchar(120) DEFAULT NULL COMMENT '头像',
`birthday` date DEFAULT NULL COMMENT '生日', `birthday` date DEFAULT NULL COMMENT '生日',
`background_img` varchar(120) DEFAULT NULL COMMENT '背景图', `background_img` varchar(120) DEFAULT NULL COMMENT '背景图',
`phone` varchar(11) NOT NULL COMMENT '手机号', `phone` varchar(11) NOT NULL COMMENT '手机号',
`sex` tinyint DEFAULT '0' COMMENT '性别(0女 1男)', `sex` tinyint DEFAULT '0' COMMENT '性别(0女 1男)',
`status` tinyint NOT NULL DEFAULT '0' COMMENT '状态(0启用 1禁用)', `status` tinyint NOT NULL DEFAULT '0' COMMENT '状态(0启用 1禁用)',
`introduction` varchar(100) DEFAULT NULL COMMENT '个人简介', `introduction` varchar(100) DEFAULT NULL COMMENT '个人简介',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间', `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间',
`is_deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '逻辑删除(0未删除 1已删除)', `is_deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '逻辑删除(0未删除 1已删除)',
PRIMARY KEY (`id`) USING BTREE, PRIMARY KEY (`id`) USING BTREE,
UNIQUE KEY `uk_han_note_id` (`han_note_id`), UNIQUE KEY `uk_han_note_id` (`han_note_id`),
UNIQUE KEY `uk_phone` (`phone`) UNIQUE KEY `uk_phone` (`phone`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='用户表'; ) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_unicode_ci COMMENT ='用户表';
CREATE TABLE `t_role`
(
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`role_name` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '角色名',
`role_key` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '角色唯一标识',
`status` tinyint NOT NULL DEFAULT '0' COMMENT '状态(0启用 1禁用)',
`sort` int unsigned NOT NULL DEFAULT 0 COMMENT '管理系统中的显示顺序',
`remark` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '备注',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '最后一次更新时间',
`is_deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '逻辑删除(0未删除 1已删除)',
PRIMARY KEY (`id`) USING BTREE,
UNIQUE KEY `uk_role_key` (`role_key`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_unicode_ci COMMENT ='角色表';
CREATE TABLE `t_permission`
(
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`parent_id` bigint unsigned NOT NULL DEFAULT '0' COMMENT '父ID',
`name` varchar(16) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '权限名称',
`type` tinyint unsigned NOT NULL COMMENT '类型(1目录 2菜单 3按钮)',
`menu_url` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '菜单路由',
`menu_icon` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '菜单图标',
`sort` int unsigned NOT NULL DEFAULT 0 COMMENT '管理系统中的显示顺序',
`permission_key` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '权限标识',
`status` tinyint unsigned NOT NULL DEFAULT '0' COMMENT '状态(0启用1禁用)',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间',
`is_deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '逻辑删除(0未删除 1已删除)',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_unicode_ci COMMENT ='权限表';
CREATE TABLE `t_user_role_rel`
(
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`user_id` bigint unsigned NOT NULL COMMENT '用户ID',
`role_id` bigint unsigned NOT NULL COMMENT '角色ID',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间',
`is_deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '逻辑删除(0未删除 1已删除)',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_unicode_ci COMMENT ='用户角色表';
CREATE TABLE `t_role_permission_rel`
(
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`role_id` bigint unsigned NOT NULL COMMENT '角色ID',
`permission_id` bigint unsigned NOT NULL COMMENT '权限ID',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '更新时间',
`is_deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '逻辑删除(0未删除 1已删除)',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_unicode_ci COMMENT ='用户权限表';