130 lines
4.3 KiB
Go
130 lines
4.3 KiB
Go
package dto
|
||
|
||
import (
|
||
"case-api/api/model"
|
||
"case-api/utils"
|
||
"fmt"
|
||
)
|
||
|
||
// CaseCommentDto 病历表-评论
|
||
type CaseCommentDto struct {
|
||
CommentId string `json:"comment_id"` // 主键id
|
||
CaseId string `json:"case_id"` // 所属病例id
|
||
PlatformId string `json:"platform_id"` // 来源平台id
|
||
ParentId *string `json:"parent_id,omitempty"` // 父级id,一级评论为null
|
||
RootId *string `json:"root_id,omitempty"` // 根评论id,一级评论时为null。其余为一级评论id
|
||
Level int `json:"level"` // 级别(1:留言 2:回复 3:评论)
|
||
UserId string `json:"user_id"` // 用户id
|
||
Status int `json:"status"` // 评论状态(0:禁用 1:正常)
|
||
UserName string `json:"user_name"` // 用户名称
|
||
AreaName string `json:"area_name"` // 地址名称
|
||
HospitalName string `json:"hospital_name"` // 医院名称
|
||
DepartmentName string `json:"department_name"` // 科室名称
|
||
Title string `json:"title"` // 职称
|
||
IsHighQuality int `json:"is_high_quality"` // 是否优质留言(0:否 1:是)
|
||
IsGrantHighQuality int `json:"is_grant_high_quality"` // 优质留言积分是否已发放(0:否 1:是)
|
||
LikeNum int `json:"like_num"` // 点赞数量
|
||
Content string `json:"content"` // 评论内容
|
||
ContentWord string `json:"content_word"` // 评论内容(原版)
|
||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
|
||
CaseComment []*CaseCommentDto `json:"case_comment"` // 次级评论
|
||
IsLike bool `json:"is_like"` // 点赞状态(0:否 1:是)
|
||
TotalAmount int64 `json:"total_amount"` // 剩余评论数量
|
||
}
|
||
|
||
// GetCaseCommentListDto 列表
|
||
func GetCaseCommentListDto(m []*model.CaseComment) []*CaseCommentDto {
|
||
// 处理返回值
|
||
responses := make([]*CaseCommentDto, len(m))
|
||
|
||
if len(m) > 0 {
|
||
for i, v := range m {
|
||
response := &CaseCommentDto{
|
||
CommentId: fmt.Sprintf("%d", v.CommentId),
|
||
CaseId: fmt.Sprintf("%d", v.CaseId),
|
||
PlatformId: fmt.Sprintf("%d", v.PlatformId),
|
||
Level: v.Level,
|
||
UserId: fmt.Sprintf("%d", v.UserId),
|
||
Status: v.Status,
|
||
IsHighQuality: v.IsHighQuality,
|
||
LikeNum: v.LikeNum,
|
||
Content: v.Content,
|
||
ContentWord: v.ContentWord,
|
||
CreatedAt: v.CreatedAt,
|
||
UpdatedAt: v.UpdatedAt,
|
||
}
|
||
|
||
// 加载数据-用户字段
|
||
if v.User != nil {
|
||
response = response.LoadUser(v.User)
|
||
|
||
// 加载数据-医院字段
|
||
if v.User.Hospital != nil {
|
||
response = response.LoadHospital(v.User.Hospital)
|
||
}
|
||
}
|
||
|
||
// 将转换后的结构体添加到新切片中
|
||
responses[i] = response
|
||
}
|
||
}
|
||
|
||
return responses
|
||
}
|
||
|
||
// LoadCaseComment 加载数据-次级评论
|
||
func (r *CaseCommentDto) LoadCaseComment(m []*model.CaseComment) *CaseCommentDto {
|
||
if len(m) > 0 {
|
||
r.CaseComment = GetCaseCommentListDto(m)
|
||
}
|
||
|
||
return r
|
||
}
|
||
|
||
// LoadIsLike 加载数据-点赞
|
||
func (r *CaseCommentDto) LoadIsLike(m int64) *CaseCommentDto {
|
||
if m > 0 {
|
||
r.IsLike = true
|
||
}
|
||
|
||
return r
|
||
}
|
||
|
||
// LoadTotalAmount 加载数据-剩余数量
|
||
func (r *CaseCommentDto) LoadTotalAmount(m int64) *CaseCommentDto {
|
||
if m > 0 {
|
||
r.TotalAmount = m
|
||
}
|
||
|
||
return r
|
||
}
|
||
|
||
// LoadUser 加载数据-用户字段
|
||
func (r *CaseCommentDto) LoadUser(m *model.User) *CaseCommentDto {
|
||
if m != nil {
|
||
r.UserName = m.UserName
|
||
r.DepartmentName = m.DepartmentName
|
||
r.Title = utils.DoctorTitleToString(m.Title)
|
||
|
||
if m.Address != "" {
|
||
r.AreaName = m.Address
|
||
}
|
||
}
|
||
|
||
return r
|
||
}
|
||
|
||
// LoadHospital 加载数据-医院字段
|
||
func (r *CaseCommentDto) LoadHospital(m *model.BasicHospital) *CaseCommentDto {
|
||
if m != nil {
|
||
r.HospitalName = m.HospitalName
|
||
|
||
if m.Address == "" {
|
||
r.AreaName = m.Province
|
||
}
|
||
}
|
||
|
||
return r
|
||
}
|