knowledge-api/api/dto/QuestionQaItem.go
2024-10-12 17:09:44 +08:00

101 lines
2.8 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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)
// 加载图片
r.Question = r.Question.LoadQuestionImage(m.QuestionImage)
// 加载答案
r.Question = r.Question.LoadQuestionAnswer(m)
}
return r
}