This commit is contained in:
2024-07-02 17:37:50 +08:00
parent c87c7076df
commit 53e72e1ee2
35 changed files with 1813 additions and 60 deletions
+51 -16
View File
@@ -3,30 +3,44 @@ package dto
import (
"fmt"
"knowledge/api/model"
"knowledge/utils"
"strings"
)
// 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"` // 二级标签
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"` // 二级标签
QuestionOption []*QuestionOptionDto `json:"question_option"` // 选项
}
// GetQuestionDto 题目详情
func GetQuestionDto(m *model.Question) *QuestionDto {
var questionImage []string
if m.QuestionImage != "" {
result := strings.Split(m.QuestionImage, ",")
if len(result) > 0 {
for _, v := range result {
v = utils.AddOssDomain(v)
questionImage = append(questionImage, v)
}
}
}
return &QuestionDto{
QuestionId: fmt.Sprintf("%d", m.QuestionId),
QuestionName: m.QuestionName,
@@ -34,6 +48,7 @@ func GetQuestionDto(m *model.Question) *QuestionDto {
QuestionStatus: m.QuestionStatus,
IsDelete: m.IsDelete,
QuestionSource: m.QuestionSource,
QuestionImage: questionImage,
QuestionAnswer: m.QuestionAnswer,
QuestionAnalysis: m.QuestionAnalysis,
Difficulty: m.Difficulty,
@@ -51,6 +66,17 @@ func GetQuestionListDto(m []*model.Question) []*QuestionDto {
if len(m) > 0 {
for i, v := range m {
var questionImage []string
if v.QuestionImage != "" {
result := strings.Split(v.QuestionImage, ",")
if len(result) > 0 {
for _, v := range result {
v = utils.AddOssDomain(v)
questionImage = append(questionImage, v)
}
}
}
response := &QuestionDto{
QuestionId: fmt.Sprintf("%d", v.QuestionId),
QuestionName: v.QuestionName,
@@ -58,6 +84,7 @@ func GetQuestionListDto(m []*model.Question) []*QuestionDto {
QuestionStatus: v.QuestionStatus,
IsDelete: v.IsDelete,
QuestionSource: v.QuestionSource,
QuestionImage: questionImage,
QuestionAnswer: v.QuestionAnswer,
QuestionAnalysis: v.QuestionAnalysis,
Difficulty: v.Difficulty,
@@ -100,3 +127,11 @@ func (r *QuestionDto) LoadSecondLabel(m *model.Label) *QuestionDto {
}
return r
}
// LoadQuestionOption 加载选项
func (r *QuestionDto) LoadQuestionOption(m []*model.QuestionOption) *QuestionDto {
if len(m) > 0 {
r.QuestionOption = GetQuestionOptionListDto(m)
}
return r
}
+51
View File
@@ -0,0 +1,51 @@
package dto
import (
"fmt"
"knowledge/api/model"
)
// QuestionOptionDto 题目选项表
type QuestionOptionDto struct {
OptionId string `json:"option_id"` // 主键id
QuestionId string `json:"question_id"` // 题目id
OptionValue string `json:"option_value"` // 选项内容
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
}
// GetQuestionOptionDto 题目选项详情
func GetQuestionOptionDto(m *model.QuestionOption) *QuestionOptionDto {
return &QuestionOptionDto{
OptionId: fmt.Sprintf("%d", m.OptionId),
QuestionId: fmt.Sprintf("%d", m.QuestionId),
OptionValue: m.OptionValue,
CreatedAt: m.CreatedAt,
UpdatedAt: m.UpdatedAt,
}
}
// GetQuestionOptionListDto 题目选项列表
func GetQuestionOptionListDto(m []*model.QuestionOption) []*QuestionOptionDto {
// 处理返回值
responses := make([]*QuestionOptionDto, len(m))
if len(m) > 0 {
for i, v := range m {
response := &QuestionOptionDto{
OptionId: fmt.Sprintf("%d", v.OptionId),
QuestionId: fmt.Sprintf("%d", v.QuestionId),
OptionValue: v.OptionValue,
CreatedAt: v.CreatedAt,
UpdatedAt: v.UpdatedAt,
}
// 将转换后的结构体添加到新切片中
responses[i] = response
}
}
return responses
}
+58 -14
View File
@@ -1,25 +1,37 @@
package dto
import (
"encoding/json"
"fmt"
"knowledge/api/model"
"knowledge/utils"
)
// QuestionQaDto 问答题库
type QuestionQaDto struct {
QaId string `json:"qa_id"` // 主键id
QaName string `json:"qa_name"` // 名称
QaQuantity int `json:"qa_quantity"` // 题目数量
QaStatus int `json:"qa_status"` // 状态(1:正常 2:无效)
QaRuleContent string `json:"qa_rule_content"` // 规则解释
QaDisplayType int `json:"qa_display_type"` // 展示类型(1:常规 2:飞花令)
QaExpireTime model.LocalTime `json:"qa_expire_time"` // 过期时间
QaLink string `json:"qa_link"` // 分享链接
QaPassword string `json:"qa_password"` // 分享密码
OpenNumber int `json:"open_number"` // 打开的次数
Image string `json:"image"` // 背景图
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
QaId string `json:"qa_id"` // 主键id
QaName string `json:"qa_name"` // 名称
QaQuantity int `json:"qa_quantity"` // 题目数量
QaStatus int `json:"qa_status"` // 状态(1:正常 2:无效)
QaRuleContent string `json:"qa_rule_content"` // 规则解释
QaDisplayType int `json:"qa_display_type"` // 展示类型(1:常规 2:飞花令)
QaExpireTime model.LocalTime `json:"qa_expire_time"` // 过期时间
QaShareId string `json:"qa_share_id"` // 分享标识
QaPassword string `json:"qa_password"` // 分享密码
OpenNumber int `json:"open_number"` // 打开的次数
Image string `json:"image"` // 背景图
ItemContent []ItemContentDto `json:"item_content"` // 明细选题规则(json
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
}
// ItemContentDto 问答题库-明细选题规则
type ItemContentDto struct {
QuestionType int `json:"question_type"` // 题目类型(1:单选 2:多选 3:问答 4:判断)
FirstLabelId string `json:"first_label_id"` // 一级标签id
SecondLabelId string `json:"second_label_id"` // 二级标签id
Difficulty int `json:"difficulty"` // 难度(0:未知 1:低 2:中 3:高)
Quantity int `json:"quantity"` // 数量
}
// GetQuestionQaListDto 问答题库列表
@@ -37,7 +49,8 @@ func GetQuestionQaListDto(m []*model.QuestionQa) []*QuestionQaDto {
QaRuleContent: v.QaRuleContent,
QaDisplayType: v.QaDisplayType,
QaExpireTime: v.QaExpireTime,
QaLink: v.QaLink,
QaShareId: utils.AddDomain(v.QaShareId),
Image: utils.AddOssDomain(v.Image),
OpenNumber: v.OpenNumber,
CreatedAt: v.CreatedAt,
UpdatedAt: v.UpdatedAt,
@@ -50,3 +63,34 @@ func GetQuestionQaListDto(m []*model.QuestionQa) []*QuestionQaDto {
return responses
}
// GetQuestionQaDto 问答题库详情
func GetQuestionQaDto(m *model.QuestionQa) *QuestionQaDto {
return &QuestionQaDto{
QaId: fmt.Sprintf("%d", m.QaId),
QaName: m.QaName,
QaQuantity: m.QaQuantity,
QaStatus: m.QaStatus,
QaRuleContent: m.QaRuleContent,
QaDisplayType: m.QaDisplayType,
QaExpireTime: m.QaExpireTime,
QaShareId: utils.AddDomain(m.QaShareId),
OpenNumber: m.OpenNumber,
Image: utils.AddOssDomain(m.Image),
CreatedAt: m.CreatedAt,
UpdatedAt: m.UpdatedAt,
}
}
// LoadItemContent 加载明细选题规则
func (r *QuestionQaDto) LoadItemContent(s string) *QuestionQaDto {
if s != "" {
var itemContentDto []ItemContentDto
err := json.Unmarshal([]byte(s), &itemContentDto)
if err == nil {
r.ItemContent = itemContentDto
}
}
return r
}
+94
View File
@@ -0,0 +1,94 @@
package dto
import (
"fmt"
"knowledge/api/model"
)
// QuestionQaItemDto 知识问答-明细
type QuestionQaItemDto struct {
ItemId string `json:"item_id"` // 主键id
QaId string `json:"qa_id"` // 知识问答id
QuestionId string `json:"question_id"` // 题目id
IsMustSelect int `json:"is_must_select"` // 是否必被选中(0:否 1:是)
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
FirstLabel *LabelDto `json:"first_label"` // 一级标签
SecondLabel *LabelDto `json:"second_label"` // 二级标签
Question *QuestionDto `json:"question"` // 题目
}
// GetQuestionQaItemDto 题库明细详情
func GetQuestionQaItemDto(m *model.QuestionQaItem) *QuestionQaItemDto {
return &QuestionQaItemDto{
ItemId: fmt.Sprintf("%d", m.ItemId),
QaId: fmt.Sprintf("%d", m.QaId),
QuestionId: fmt.Sprintf("%d", m.QuestionId),
IsMustSelect: m.IsMustSelect,
CreatedAt: m.CreatedAt,
UpdatedAt: m.UpdatedAt,
}
}
// GetQuestionQaItemListDto 题目列表
func GetQuestionQaItemListDto(m []*model.QuestionQaItem) []*QuestionQaItemDto {
// 处理返回值
responses := make([]*QuestionQaItemDto, len(m))
if len(m) > 0 {
for i, v := range m {
response := &QuestionQaItemDto{
ItemId: fmt.Sprintf("%d", v.ItemId),
QaId: fmt.Sprintf("%d", v.QaId),
QuestionId: fmt.Sprintf("%d", v.QuestionId),
IsMustSelect: v.IsMustSelect,
CreatedAt: v.CreatedAt,
UpdatedAt: v.UpdatedAt,
}
// 加载题目
if v.Question != nil {
response = response.LoadQuestion(v.Question)
}
// 加载一级标签
if v.Question.FirstLabel != nil {
response = response.LoadFirstLabel(v.Question.FirstLabel)
}
// 加载二级标签
if v.Question.SecondLabel != nil {
response = response.LoadSecondLabel(v.Question.SecondLabel)
}
// 将转换后的结构体添加到新切片中
responses[i] = response
}
}
return responses
}
// LoadFirstLabel 加载一级标签
func (r *QuestionQaItemDto) LoadFirstLabel(m *model.Label) *QuestionQaItemDto {
if m != nil {
r.FirstLabel = GetLabelDto(m)
}
return r
}
// LoadSecondLabel 加载二级标签
func (r *QuestionQaItemDto) LoadSecondLabel(m *model.Label) *QuestionQaItemDto {
if m != nil {
r.SecondLabel = GetLabelDto(m)
}
return r
}
// LoadQuestion 加载题目
func (r *QuestionQaItemDto) LoadQuestion(m *model.Question) *QuestionQaItemDto {
if m != nil {
r.Question = GetQuestionDto(m)
}
return r
}
+56
View File
@@ -0,0 +1,56 @@
package dto
import (
"knowledge/api/model"
"knowledge/utils"
"strings"
)
type ShareDto struct {
QuestionQa *QuestionQaDto `json:"question_qa"` // 题库数据
Question []*ShareQuestionDto `json:"question"` // 题目数据
}
// ShareQuestionDto 题目数据
type ShareQuestionDto struct {
QuestionName string `json:"question_name"` // 题目名称
QuestionType int `json:"question_type"` // 题目类型(1:单选 2:多选 3:问答 4:判断)
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:高)
IsMustSelect int `json:"is_must_select"`
}
// GetShareQuestionDto 分享题目详情
func GetShareQuestionDto(m *model.Question) *ShareQuestionDto {
var questionImage []string
if m.QuestionImage != "" {
result := strings.Split(m.QuestionImage, ",")
if len(result) > 0 {
for _, v := range result {
v = utils.AddOssDomain(v)
questionImage = append(questionImage, v)
}
}
}
return &ShareQuestionDto{
QuestionName: m.QuestionName,
QuestionType: m.QuestionType,
QuestionSource: m.QuestionSource,
QuestionImage: questionImage,
QuestionAnswer: m.QuestionAnswer,
QuestionAnalysis: m.QuestionAnalysis,
Difficulty: m.Difficulty,
}
}
// LoadQuestionQa 加载题库数据
func (r *ShareDto) LoadQuestionQa(m *model.QuestionQa) *ShareDto {
if m != nil {
r.QuestionQa = GetQuestionQaDto(m)
}
return r
}
+42
View File
@@ -0,0 +1,42 @@
package dto
import (
"fmt"
"knowledge/api/model"
"knowledge/utils"
)
type StaticDto struct {
Name string `json:"name"` // 名称
Total int `json:"total"` // 数量
}
// GetStaticListDto 问答题库列表
func GetStaticListDto(m []*model.QuestionQa) []*QuestionQaDto {
// 处理返回值
responses := make([]*QuestionQaDto, len(m))
if len(m) > 0 {
for i, v := range m {
response := &QuestionQaDto{
QaId: fmt.Sprintf("%d", v.QaId),
QaName: v.QaName,
QaQuantity: v.QaQuantity,
QaStatus: v.QaStatus,
QaRuleContent: v.QaRuleContent,
QaDisplayType: v.QaDisplayType,
QaExpireTime: v.QaExpireTime,
QaShareId: utils.AddDomain(v.QaShareId),
Image: utils.AddOssDomain(v.Image),
OpenNumber: v.OpenNumber,
CreatedAt: v.CreatedAt,
UpdatedAt: v.UpdatedAt,
}
// 将转换后的结构体添加到新切片中
responses[i] = response
}
}
return responses
}