case-admin-api/api/dto/CaseComment.go
2025-03-07 17:23:50 +08:00

137 lines
4.4 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 (
"case-admin-api/api/model"
"case-admin-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:正常)
IsSensitive int `json:"is_sensitive"` // 是否存在敏感词0:否 1:是)
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"` // 修改时间
Area string `json:"area"` // 省份
HospitalName string `json:"hospital_name"` // 医院
DepartmentName string `json:"department_name"` // 科室
Title string `json:"title"` // 职称
UserName string `json:"user_name"` // 用户名称
}
// 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,
IsSensitive: v.IsSensitive,
IsHighQuality: v.IsHighQuality,
IsGrantHighQuality: v.IsGrantHighQuality,
LikeNum: v.LikeNum,
Content: v.Content,
ContentWord: v.ContentWord,
CreatedAt: v.CreatedAt,
UpdatedAt: v.UpdatedAt,
}
if v.ParentId != 0 {
response.ParentId = fmt.Sprintf("%d", v.ParentId)
}
if v.RootId != 0 {
response.RootId = fmt.Sprintf("%d", v.RootId)
}
// 加载数据-用户名称
if v.User != nil {
// 加载数据-科室
response = response.LoadDepartmentName(v.User)
// 加载数据-职称
response = response.LoadTitle(v.User)
// 加载数据-用户名称
response = response.LoadUserName(v.User)
// 加载数据-省份
if v.User.Hospital != nil {
response = response.LoadArea(v.User.Hospital)
response = response.LoadHospitalName(v.User.Hospital)
}
}
// 将转换后的结构体添加到新切片中
responses[i] = response
}
}
return responses
}
// LoadArea 加载数据-省份
func (r *CaseCommentDto) LoadArea(m *model.BasicHospital) *CaseCommentDto {
if m != nil {
r.Area = m.Province
}
return r
}
// LoadDepartmentName 加载数据-科室
func (r *CaseCommentDto) LoadDepartmentName(m *model.User) *CaseCommentDto {
if m != nil {
r.DepartmentName = m.DepartmentName
}
return r
}
// LoadTitle 加载数据-职称
func (r *CaseCommentDto) LoadTitle(m *model.User) *CaseCommentDto {
if m != nil {
r.Title = utils.DoctorTitleToString(m.Title)
}
return r
}
// LoadUserName 加载数据-用户名称
func (r *CaseCommentDto) LoadUserName(m *model.User) *CaseCommentDto {
if m != nil {
r.UserName = m.UserName
}
return r
}
// LoadHospitalName 加载数据-医院名称
func (r *CaseCommentDto) LoadHospitalName(m *model.BasicHospital) *CaseCommentDto {
if m != nil {
r.HospitalName = m.HospitalName
}
return r
}