56 lines
1.6 KiB
Go
56 lines
1.6 KiB
Go
package dto
|
|
|
|
import (
|
|
"case-api/api/model"
|
|
"fmt"
|
|
)
|
|
|
|
type StatCaseQuestionDto struct {
|
|
StatId string `json:"stat_id"` // 主键id
|
|
CaseId string `json:"case_id"` // 病例id
|
|
QuestionId string `json:"question_id"` // 题目id
|
|
OptionId string `json:"option_id"` // 选项id
|
|
OptionValue string `json:"option_value"` // 选项内容
|
|
SelectNum int `json:"select_num"` // 被选择数量
|
|
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
|
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
|
|
Proportion float64 `json:"proportion"` // 占比
|
|
}
|
|
|
|
// GetStatCaseQuestionListDto 列表
|
|
func GetStatCaseQuestionListDto(m []*model.StatCaseQuestion) []*StatCaseQuestionDto {
|
|
// 处理返回值
|
|
responses := make([]*StatCaseQuestionDto, len(m))
|
|
|
|
if len(m) > 0 {
|
|
for i, v := range m {
|
|
response := &StatCaseQuestionDto{
|
|
StatId: fmt.Sprintf("%d", v.StatId),
|
|
CaseId: fmt.Sprintf("%d", v.CaseId),
|
|
QuestionId: fmt.Sprintf("%d", v.QuestionId),
|
|
OptionId: fmt.Sprintf("%d", v.QuestionId),
|
|
SelectNum: v.SelectNum,
|
|
}
|
|
|
|
// 加载数据-选项内容
|
|
if v.CaseItemQuestionOption != nil {
|
|
response.LoadOptionValue(v.CaseItemQuestionOption)
|
|
}
|
|
|
|
// 将转换后的结构体添加到新切片中
|
|
responses[i] = response
|
|
}
|
|
}
|
|
|
|
return responses
|
|
}
|
|
|
|
// LoadOptionValue 加载数据-选项内容
|
|
func (r *StatCaseQuestionDto) LoadOptionValue(m *model.CaseItemQuestionOption) *StatCaseQuestionDto {
|
|
if m != nil {
|
|
r.OptionValue = m.OptionValue
|
|
}
|
|
|
|
return r
|
|
}
|