57 lines
1.7 KiB
Go
57 lines
1.7 KiB
Go
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
|
||
}
|