58 lines
2.1 KiB
Go
58 lines
2.1 KiB
Go
package dto
|
|
|
|
import (
|
|
"case-open-api/api/model"
|
|
"fmt"
|
|
)
|
|
|
|
// CaseItemQuestionDto 病历表-明细-题目
|
|
type CaseItemQuestionDto struct {
|
|
QuestionId string `json:"question_id"` // 主键id
|
|
CaseItemId string `json:"case_item_id"` // 病例明细id
|
|
QuestionName string `json:"question_name"` // 题目名称
|
|
QuestionType int `json:"question_type"` // 题目类型(1:单选 2:多选 3:问答 4:判断)
|
|
QuestionAnswer string `json:"question_answer"` // 答案
|
|
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
|
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
|
|
CaseItemQuestionOption []*CaseItemQuestionOptionDto `json:"case_item_question_option"` // 题目选项列表
|
|
}
|
|
|
|
// GetCaseItemQuestionListDto 列表
|
|
func GetCaseItemQuestionListDto(m []*model.CaseItemQuestion) []*CaseItemQuestionDto {
|
|
// 处理返回值
|
|
responses := make([]*CaseItemQuestionDto, len(m))
|
|
|
|
if len(m) > 0 {
|
|
for i, v := range m {
|
|
response := &CaseItemQuestionDto{
|
|
QuestionId: fmt.Sprintf("%d", v.QuestionId),
|
|
CaseItemId: fmt.Sprintf("%d", v.CaseItemId),
|
|
QuestionName: v.QuestionName,
|
|
QuestionType: v.QuestionType,
|
|
QuestionAnswer: v.QuestionAnswer,
|
|
CreatedAt: v.CreatedAt,
|
|
UpdatedAt: v.UpdatedAt,
|
|
}
|
|
|
|
// 加载数据-病例明细-题目-选项
|
|
if v.CaseItemQuestionOption != nil {
|
|
response = response.LoadCaseItemQuestionOption(v.CaseItemQuestionOption)
|
|
}
|
|
|
|
// 将转换后的结构体添加到新切片中
|
|
responses[i] = response
|
|
}
|
|
}
|
|
|
|
return responses
|
|
}
|
|
|
|
// LoadCaseItemQuestionOption 加载数据-病例明细-题目-选项
|
|
func (r *CaseItemQuestionDto) LoadCaseItemQuestionOption(m []*model.CaseItemQuestionOption) *CaseItemQuestionDto {
|
|
if len(m) > 0 {
|
|
r.CaseItemQuestionOption = GetCaseItemQuestionOptionListDto(m)
|
|
}
|
|
|
|
return r
|
|
}
|