knowledge-api/api/dto/QuestionQa.go
2024-07-02 17:37:50 +08:00

97 lines
3.2 KiB
Go
Raw 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 (
"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"` // 过期时间
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 问答题库列表
func GetQuestionQaListDto(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
}
// 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
}