50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package dto
|
|
|
|
import (
|
|
"fmt"
|
|
"vote-admin-api/api/model"
|
|
)
|
|
|
|
type ArticleAuthorDto struct {
|
|
AuthorId string `json:"author_id"` // 主键id
|
|
ArticleId string `json:"article_id"` // 文章id
|
|
AuthorName string `json:"author_name"` // 作者姓名
|
|
HospitalId string `json:"hospital_id"` // 作者所属id
|
|
HospitalName string `json:"hospital_name"` // 作者所属医院
|
|
}
|
|
|
|
// GetArticleAuthorListDto 列表-分页
|
|
func GetArticleAuthorListDto(m []*model.ArticleAuthor) []*ArticleAuthorDto {
|
|
// 处理返回值
|
|
responses := make([]*ArticleAuthorDto, len(m))
|
|
|
|
if len(m) > 0 {
|
|
for i, v := range m {
|
|
response := &ArticleAuthorDto{
|
|
AuthorId: fmt.Sprintf("%d", v.AuthorId),
|
|
ArticleId: fmt.Sprintf("%d", v.ArticleId),
|
|
AuthorName: v.AuthorName,
|
|
HospitalId: fmt.Sprintf("%d", v.HospitalId),
|
|
}
|
|
|
|
// 加载数据-医院属性
|
|
if v.BaseHospital != nil {
|
|
response = response.LoadBaseHospital(v.BaseHospital)
|
|
}
|
|
|
|
// 将转换后的结构体添加到新切片中
|
|
responses[i] = response
|
|
}
|
|
}
|
|
|
|
return responses
|
|
}
|
|
|
|
// LoadBaseHospital 加载数据-医院
|
|
func (r *ArticleAuthorDto) LoadBaseHospital(m *model.BaseHospital) *ArticleAuthorDto {
|
|
if m != nil {
|
|
r.HospitalName = m.HospitalName
|
|
}
|
|
return r
|
|
}
|