1
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"knowledge/api/model"
|
||||
"knowledge/utils"
|
||||
)
|
||||
|
||||
// AdminUserDto 后台-用户表
|
||||
type AdminUserDto struct {
|
||||
UserId string `json:"user_id"` // 主键id
|
||||
Access string `json:"access"` // 账号
|
||||
Password string `json:"password"` // 密码
|
||||
Salt string `json:"salt"` // 密码掩码
|
||||
NickName string `json:"nick_name"` // 昵称
|
||||
Status int `json:"status"` // 状态(1:正常 2:审核中 3:审核失败)
|
||||
IsDeleted int `json:"is_deleted"` // 是否被删除(0:否 1:是)
|
||||
IsDisabled int `json:"is_disabled"` // 是否被禁用(0:否 1:是)
|
||||
Phone string `json:"phone"` // 手机号
|
||||
Avatar string `json:"avatar"` // 头像
|
||||
Sex int `json:"sex"` // 性别(1:男 2:女)
|
||||
Email string `json:"email"` // 邮箱
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
|
||||
Token string `json:"token"` // token
|
||||
}
|
||||
|
||||
func LoginDto(m *model.AdminUser) *AdminUserDto {
|
||||
return &AdminUserDto{
|
||||
UserId: fmt.Sprintf("%d", m.UserId),
|
||||
Access: m.Access,
|
||||
Status: m.Status,
|
||||
NickName: m.NickName,
|
||||
Avatar: utils.AddOssDomain(m.Avatar),
|
||||
Sex: m.Sex,
|
||||
Email: m.Email,
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
// LoadUserDoctor 加载token
|
||||
func (r *AdminUserDto) LoadUserDoctor(t string) *AdminUserDto {
|
||||
if t != "" {
|
||||
r.Token = t
|
||||
}
|
||||
return r
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"knowledge/api/model"
|
||||
)
|
||||
|
||||
// LabelDto 标签表
|
||||
type LabelDto struct {
|
||||
LabelId string `json:"label_id"` // 主键id
|
||||
LabelName string `json:"label_name"` // 标签名称
|
||||
ParentId string `json:"parent_id"` // 父级ID(0表示一级)
|
||||
LabelLevel int `json:"label_level"` // 级别(1:1级 2:2级 3:3级)
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
|
||||
}
|
||||
|
||||
// GetLabelDto 标签详情
|
||||
func GetLabelDto(m *model.Label) *LabelDto {
|
||||
return &LabelDto{
|
||||
LabelId: fmt.Sprintf("%d", m.LabelId),
|
||||
LabelName: m.LabelName,
|
||||
ParentId: fmt.Sprintf("%d", m.ParentId),
|
||||
LabelLevel: m.LabelLevel,
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
// GetLabelListDto 标签列表
|
||||
func GetLabelListDto(m []*model.Label) []*LabelDto {
|
||||
// 处理返回值
|
||||
responses := make([]*LabelDto, len(m))
|
||||
|
||||
if len(m) > 0 {
|
||||
for i, v := range m {
|
||||
response := &LabelDto{
|
||||
LabelId: fmt.Sprintf("%d", v.LabelId),
|
||||
LabelName: v.LabelName,
|
||||
ParentId: fmt.Sprintf("%d", v.ParentId),
|
||||
LabelLevel: v.LabelLevel,
|
||||
CreatedAt: v.CreatedAt,
|
||||
UpdatedAt: v.UpdatedAt,
|
||||
}
|
||||
|
||||
// 将转换后的结构体添加到新切片中
|
||||
responses[i] = response
|
||||
}
|
||||
}
|
||||
|
||||
return responses
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"knowledge/api/model"
|
||||
)
|
||||
|
||||
// QuestionDto 题目表(单选-多选-问答-判断)
|
||||
type QuestionDto struct {
|
||||
QuestionId string `json:"question_id"` // 主键id
|
||||
QuestionName string `json:"question_name"` // 题目名称
|
||||
QuestionType int `json:"question_type"` // 题目类型(1:单选 2:多选 3:问答 4:判断)
|
||||
QuestionStatus int `json:"question_status"` // 状态(1:正常 2:禁用)
|
||||
IsDelete int `json:"is_delete"` // 是否删除(0:否 1:是)
|
||||
QuestionSource int `json:"question_source"` // 题目来源(1:本题库 2:外部数据)
|
||||
QuestionImage []string `json:"question_image"` // 题目图片(逗号分隔)
|
||||
QuestionAnswer string `json:"question_answer"` // 答案
|
||||
QuestionAnalysis string `json:"question_analysis"` // 解析
|
||||
Difficulty int `json:"difficulty"` // 难度(0:未知 1:低 2:中 3:高)
|
||||
FirstLabelId string `json:"first_label_id"` // 一级标签id
|
||||
SecondLabelId string `json:"second_label_id"` // 二级标签id
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
|
||||
FirstLabel *LabelDto `json:"first_label"` // 一级标签
|
||||
SecondLabel *LabelDto `json:"second_label"` // 二级标签
|
||||
}
|
||||
|
||||
// GetQuestionDto 题目详情
|
||||
func GetQuestionDto(m *model.Question) *QuestionDto {
|
||||
return &QuestionDto{
|
||||
QuestionId: fmt.Sprintf("%d", m.QuestionId),
|
||||
QuestionName: m.QuestionName,
|
||||
QuestionType: m.QuestionType,
|
||||
QuestionStatus: m.QuestionStatus,
|
||||
IsDelete: m.IsDelete,
|
||||
QuestionSource: m.QuestionSource,
|
||||
QuestionAnswer: m.QuestionAnswer,
|
||||
QuestionAnalysis: m.QuestionAnalysis,
|
||||
Difficulty: m.Difficulty,
|
||||
FirstLabelId: fmt.Sprintf("%d", *m.FirstLabelId),
|
||||
SecondLabelId: fmt.Sprintf("%d", *m.SecondLabelId),
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
// GetQuestionListDto 题目列表
|
||||
func GetQuestionListDto(m []*model.Question) []*QuestionDto {
|
||||
// 处理返回值
|
||||
responses := make([]*QuestionDto, len(m))
|
||||
|
||||
if len(m) > 0 {
|
||||
for i, v := range m {
|
||||
response := &QuestionDto{
|
||||
QuestionId: fmt.Sprintf("%d", v.QuestionId),
|
||||
QuestionName: v.QuestionName,
|
||||
QuestionType: v.QuestionType,
|
||||
QuestionStatus: v.QuestionStatus,
|
||||
IsDelete: v.IsDelete,
|
||||
QuestionSource: v.QuestionSource,
|
||||
QuestionAnswer: v.QuestionAnswer,
|
||||
QuestionAnalysis: v.QuestionAnalysis,
|
||||
Difficulty: v.Difficulty,
|
||||
FirstLabelId: fmt.Sprintf("%d", *v.FirstLabelId),
|
||||
SecondLabelId: fmt.Sprintf("%d", *v.SecondLabelId),
|
||||
CreatedAt: v.CreatedAt,
|
||||
UpdatedAt: v.UpdatedAt,
|
||||
}
|
||||
|
||||
// 加载一级标签
|
||||
if v.FirstLabel != nil {
|
||||
response = response.LoadFirstLabel(v.FirstLabel)
|
||||
}
|
||||
|
||||
fmt.Println(v.SecondLabel)
|
||||
// 加载二级标签
|
||||
if v.SecondLabel != nil {
|
||||
response = response.LoadSecondLabel(v.SecondLabel)
|
||||
}
|
||||
|
||||
// 将转换后的结构体添加到新切片中
|
||||
responses[i] = response
|
||||
}
|
||||
}
|
||||
|
||||
return responses
|
||||
}
|
||||
|
||||
// LoadFirstLabel 加载一级标签
|
||||
func (r *QuestionDto) LoadFirstLabel(m *model.Label) *QuestionDto {
|
||||
if m != nil {
|
||||
r.FirstLabel = GetLabelDto(m)
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// LoadSecondLabel 加载二级标签
|
||||
func (r *QuestionDto) LoadSecondLabel(m *model.Label) *QuestionDto {
|
||||
if m != nil {
|
||||
r.SecondLabel = GetLabelDto(m)
|
||||
}
|
||||
return r
|
||||
}
|
||||
Reference in New Issue
Block a user