diff --git a/pom.xml b/pom.xml index e08a7a2..28fe6b6 100644 --- a/pom.xml +++ b/pom.xml @@ -164,6 +164,11 @@ flyway-mysql ${flyway.version} + + com.talanlabs + avatar-generator + 1.1.0 + diff --git a/src/main/kotlin/top/fatweb/api/controller/permission/UserController.kt b/src/main/kotlin/top/fatweb/api/controller/permission/UserController.kt index 26ad1d3..54f7a1c 100644 --- a/src/main/kotlin/top/fatweb/api/controller/permission/UserController.kt +++ b/src/main/kotlin/top/fatweb/api/controller/permission/UserController.kt @@ -6,7 +6,7 @@ import org.springframework.web.bind.annotation.RestController import top.fatweb.api.converter.UserConverter import top.fatweb.api.entity.common.ResponseResult import top.fatweb.api.service.permission.IUserService -import top.fatweb.api.vo.authentication.UserInfoVo +import top.fatweb.api.vo.authentication.UserWithInfoVo /** *

@@ -22,7 +22,7 @@ class UserController( private val userService: IUserService ) { @GetMapping("info") - fun getInfo(): ResponseResult { + fun getInfo(): ResponseResult { userService.getInfo()?.let { return ResponseResult.databaseSuccess(data = UserConverter.userToUserInfoVo(it)) } ?: let { return ResponseResult.databaseFail() } diff --git a/src/main/kotlin/top/fatweb/api/converter/UserConverter.kt b/src/main/kotlin/top/fatweb/api/converter/UserConverter.kt index d481e0f..aa6aac3 100644 --- a/src/main/kotlin/top/fatweb/api/converter/UserConverter.kt +++ b/src/main/kotlin/top/fatweb/api/converter/UserConverter.kt @@ -14,7 +14,7 @@ object UserConverter { return user } - fun userToUserInfoVo(user: User) = UserInfoVo( + fun userToUserInfoVo(user: User) = UserWithInfoVo( id = user.id, username = user.username, locking = user.locking?.let { it == 1 }, diff --git a/src/main/kotlin/top/fatweb/api/entity/permission/UserInfo.kt b/src/main/kotlin/top/fatweb/api/entity/permission/UserInfo.kt new file mode 100644 index 0000000..2921d95 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/entity/permission/UserInfo.kt @@ -0,0 +1,62 @@ +package top.fatweb.api.entity.permission + +import com.baomidou.mybatisplus.annotation.* +import java.io.Serializable +import java.time.LocalDateTime + +/** + *

+ * 用户信息表 + *

+ * + * @author FatttSnake + * @since 2023-10-30 + */ +@TableName("t_user_info") +class UserInfo : Serializable { + + @TableId("id") + var id: Long? = null + + /** + * 昵称 + */ + @TableField("nick_name") + var nickName: String? = null + + /** + * 头像 + */ + @TableField("avatar") + var avatar: String? = null + + /** + * 邮箱 + */ + @TableField("email") + var email: String? = null + + /** + * 创建时间 + */ + @TableField("create_time", fill = FieldFill.INSERT) + var createTime: LocalDateTime? = null + + /** + * 修改时间 + */ + @TableField("update_time", fill = FieldFill.INSERT_UPDATE) + var updateTime: LocalDateTime? = null + + @TableField("deleted") + @TableLogic + var deleted: Long? = null + + @TableField("version") + @Version + var version: Int? = null + + override fun toString(): String { + return "UserInfo(id=$id, nickName=$nickName, avatar=$avatar, email=$email, createTime=$createTime, updateTime=$updateTime, deleted=$deleted, version=$version)" + } +} diff --git a/src/main/kotlin/top/fatweb/api/handler/DataMetaObjectHandler.kt b/src/main/kotlin/top/fatweb/api/handler/DataMetaObjectHandler.kt new file mode 100644 index 0000000..b4b87a8 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/handler/DataMetaObjectHandler.kt @@ -0,0 +1,19 @@ +package top.fatweb.api.handler + +import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler +import org.apache.ibatis.reflection.MetaObject +import org.springframework.stereotype.Component +import java.time.LocalDateTime +import java.time.ZoneOffset + +@Component +class DataMetaObjectHandler : MetaObjectHandler { + override fun insertFill(metaObject: MetaObject?) { + this.strictInsertFill(metaObject, "createTime", LocalDateTime::class.java, LocalDateTime.now(ZoneOffset.UTC)) + this.strictInsertFill(metaObject, "updateTime", LocalDateTime::class.java, LocalDateTime.now(ZoneOffset.UTC)) + } + + override fun updateFill(metaObject: MetaObject?) { + this.strictUpdateFill(metaObject, "updateTime", LocalDateTime::class.java, LocalDateTime.now(ZoneOffset.UTC)) + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/fatweb/api/mapper/permission/UserInfoMapper.kt b/src/main/kotlin/top/fatweb/api/mapper/permission/UserInfoMapper.kt new file mode 100644 index 0000000..3d254f4 --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/mapper/permission/UserInfoMapper.kt @@ -0,0 +1,16 @@ +package top.fatweb.api.mapper.permission + +import com.baomidou.mybatisplus.core.mapper.BaseMapper +import org.apache.ibatis.annotations.Mapper +import top.fatweb.api.entity.permission.UserInfo + +/** + *

+ * 用户信息表 Mapper 接口 + *

+ * + * @author FatttSnake + * @since 2023-10-30 + */ +@Mapper +interface UserInfoMapper : BaseMapper diff --git a/src/main/kotlin/top/fatweb/api/service/permission/IUserInfoService.kt b/src/main/kotlin/top/fatweb/api/service/permission/IUserInfoService.kt new file mode 100644 index 0000000..674c0be --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/service/permission/IUserInfoService.kt @@ -0,0 +1,14 @@ +package top.fatweb.api.service.permission + +import com.baomidou.mybatisplus.extension.service.IService +import top.fatweb.api.entity.permission.UserInfo + +/** + *

+ * 用户信息表 服务类 + *

+ * + * @author FatttSnake + * @since 2023-10-30 + */ +interface IUserInfoService : IService diff --git a/src/main/kotlin/top/fatweb/api/service/permission/impl/UserInfoServiceImpl.kt b/src/main/kotlin/top/fatweb/api/service/permission/impl/UserInfoServiceImpl.kt new file mode 100644 index 0000000..7120b5d --- /dev/null +++ b/src/main/kotlin/top/fatweb/api/service/permission/impl/UserInfoServiceImpl.kt @@ -0,0 +1,18 @@ +package top.fatweb.api.service.permission.impl + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl +import org.springframework.stereotype.Service +import top.fatweb.api.entity.permission.UserInfo +import top.fatweb.api.mapper.permission.UserInfoMapper +import top.fatweb.api.service.permission.IUserInfoService + +/** + *

+ * 用户信息表 服务实现类 + *

+ * + * @author FatttSnake + * @since 2023-10-30 + */ +@Service +class UserInfoServiceImpl : ServiceImpl(), IUserInfoService diff --git a/src/main/kotlin/top/fatweb/api/vo/authentication/UserInfoVo.kt b/src/main/kotlin/top/fatweb/api/vo/authentication/UserWithInfoVo.kt similarity index 89% rename from src/main/kotlin/top/fatweb/api/vo/authentication/UserInfoVo.kt rename to src/main/kotlin/top/fatweb/api/vo/authentication/UserWithInfoVo.kt index e6c059d..ad6ac2f 100644 --- a/src/main/kotlin/top/fatweb/api/vo/authentication/UserInfoVo.kt +++ b/src/main/kotlin/top/fatweb/api/vo/authentication/UserWithInfoVo.kt @@ -1,10 +1,13 @@ package top.fatweb.api.vo.authentication +import com.fasterxml.jackson.databind.annotation.JsonSerialize +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer import io.swagger.v3.oas.annotations.media.Schema import java.time.LocalDateTime @Schema(description = "获取用户信息返回参数") -data class UserInfoVo( +data class UserWithInfoVo( + @JsonSerialize(using = ToStringSerializer::class) val id: Long?, @Schema(description = "用户名", example = "User") diff --git a/src/main/resources/db/migration/V1_0_0_231104__Add_table_'t_user_info'.sql b/src/main/resources/db/migration/V1_0_0_231104__Add_table_'t_user_info'.sql new file mode 100644 index 0000000..dd2311f --- /dev/null +++ b/src/main/resources/db/migration/V1_0_0_231104__Add_table_'t_user_info'.sql @@ -0,0 +1,13 @@ +drop table if exists t_user_info; + +create table if not exists t_user_info +( + id bigint not null primary key, + nick_name varchar(50) null comment '昵称', + avatar varchar(500) null comment '头像', + email varchar(100) null comment '邮箱', + create_time datetime not null default (utc_timestamp()) comment '创建时间', + update_time datetime not null default (utc_timestamp()) comment '修改时间', + deleted bigint not null default 0, + version int not null default 0 +) comment '用户信息表'; \ No newline at end of file diff --git a/src/main/resources/mapper/permission/UserInfoMapper.xml b/src/main/resources/mapper/permission/UserInfoMapper.xml new file mode 100644 index 0000000..6ad303b --- /dev/null +++ b/src/main/resources/mapper/permission/UserInfoMapper.xml @@ -0,0 +1,5 @@ + + + + +