初始化
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"vote-admin-api/api/model"
|
||||
)
|
||||
|
||||
// ArticleDto 文章表
|
||||
type ArticleDto struct {
|
||||
ArticleId string `json:"article_id"` // 主键id
|
||||
ArticleTitle string `json:"article_title"` // 文章标题
|
||||
ArticleStatus int `json:"article_status"` // 文章状态(1:正常 2:禁用)
|
||||
VoteNum uint `json:"vote_num"` // 总票数
|
||||
ArticleContent string `json:"article_content"` // 文章内容
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
|
||||
ArticleAuthor []*ArticleAuthorDto `json:"article_author"` // 作者
|
||||
Rank *int `json:"rank"` // 排名
|
||||
IsVote bool `json:"is_vote"` // 是否已投票(false:否 true:是)
|
||||
}
|
||||
|
||||
// GetArticleListDto 列表-分页
|
||||
func GetArticleListDto(m []*model.Article) []*ArticleDto {
|
||||
// 处理返回值
|
||||
responses := make([]*ArticleDto, len(m))
|
||||
|
||||
if len(m) > 0 {
|
||||
for i, v := range m {
|
||||
response := &ArticleDto{
|
||||
ArticleId: fmt.Sprintf("%d", v.ArticleId),
|
||||
ArticleTitle: v.ArticleTitle,
|
||||
ArticleStatus: v.ArticleStatus,
|
||||
VoteNum: v.VoteNum,
|
||||
CreatedAt: v.CreatedAt,
|
||||
UpdatedAt: v.UpdatedAt,
|
||||
}
|
||||
|
||||
// 加载数据-作者
|
||||
if v.ArticleAuthor != nil {
|
||||
response = response.LoadArticleAuthor(v.ArticleAuthor)
|
||||
}
|
||||
|
||||
// 将转换后的结构体添加到新切片中
|
||||
responses[i] = response
|
||||
}
|
||||
}
|
||||
|
||||
return responses
|
||||
}
|
||||
|
||||
// GetArticleDto 详情
|
||||
func GetArticleDto(m *model.Article) *ArticleDto {
|
||||
return &ArticleDto{
|
||||
ArticleId: fmt.Sprintf("%d", m.ArticleId),
|
||||
ArticleTitle: m.ArticleTitle,
|
||||
ArticleStatus: m.ArticleStatus,
|
||||
VoteNum: m.VoteNum,
|
||||
ArticleContent: m.ArticleContent,
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
// LoadArticleAuthor 加载数据-作者
|
||||
func (r *ArticleDto) LoadArticleAuthor(m []*model.ArticleAuthor) *ArticleDto {
|
||||
if len(m) > 0 {
|
||||
r.ArticleAuthor = GetArticleAuthorListDto(m)
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// LoadRank 加载数据-排名
|
||||
func (r *ArticleDto) LoadRank(m int) *ArticleDto {
|
||||
if m > 0 {
|
||||
r.Rank = &m
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// LoadVoteStatus 加载数据-投票状态
|
||||
func (r *ArticleDto) LoadVoteStatus(m bool) *ArticleDto {
|
||||
r.IsVote = m
|
||||
return r
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"vote-admin-api/api/model"
|
||||
)
|
||||
|
||||
type ArticleAuthorDto struct {
|
||||
AuthorName string `json:"author_name"` // 作者姓名
|
||||
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{
|
||||
AuthorName: v.AuthorName,
|
||||
}
|
||||
|
||||
// 加载数据-医院属性
|
||||
if v.BaseHospital != nil {
|
||||
response = response.LoadBaseHospitalAttr(v.BaseHospital)
|
||||
}
|
||||
|
||||
// 将转换后的结构体添加到新切片中
|
||||
responses[i] = response
|
||||
}
|
||||
}
|
||||
|
||||
return responses
|
||||
}
|
||||
|
||||
// LoadBaseHospitalAttr 加载数据-医院属性
|
||||
func (r *ArticleAuthorDto) LoadBaseHospitalAttr(m *model.BaseHospital) *ArticleAuthorDto {
|
||||
if m != nil {
|
||||
r.HospitalName = m.HospitalName
|
||||
}
|
||||
return r
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"vote-admin-api/api/model"
|
||||
)
|
||||
|
||||
// BaseAgreementDto 基础-协议
|
||||
type BaseAgreementDto struct {
|
||||
AgreementId string `json:"agreement_id"` // 主键id
|
||||
AgreementType int `json:"agreement_type"` // 协议类型(1:大赛介绍 2:投票规则)
|
||||
AgreementContent string `json:"agreement_content"` // 协议内容
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
|
||||
}
|
||||
|
||||
// GetBaseAgreementDto 详情
|
||||
func GetBaseAgreementDto(m *model.BaseAgreement) *BaseAgreementDto {
|
||||
return &BaseAgreementDto{
|
||||
AgreementId: fmt.Sprintf("%d", m.AgreementId),
|
||||
AgreementType: m.AgreementType,
|
||||
AgreementContent: m.AgreementContent,
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"vote-admin-api/api/model"
|
||||
)
|
||||
|
||||
type DataDto struct {
|
||||
ViewNum uint `json:"view_num"` // 浏览数量
|
||||
VoteNum uint `json:"vote_num"` // 投票数量
|
||||
}
|
||||
|
||||
// GetDataDto 详情
|
||||
func GetDataDto(m *model.Data) *DataDto {
|
||||
return &DataDto{
|
||||
ViewNum: m.ViewNum,
|
||||
VoteNum: m.VoteNum,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"vote-admin-api/api/model"
|
||||
"vote-admin-api/utils"
|
||||
)
|
||||
|
||||
// LoginDto 登陆
|
||||
type LoginDto struct {
|
||||
UserId string `json:"user_id"` // 用户id
|
||||
NickName string `json:"nick_name"` // 用户名称
|
||||
Avatar string `json:"avatar"` // 头像
|
||||
Token string `json:"token"` // token
|
||||
}
|
||||
|
||||
// IndexDto 首页
|
||||
type IndexDto struct {
|
||||
QuestionCount int64 `json:"question_count"` // 问题数量
|
||||
UserCount int64 `json:"user_count"` // 用户数量
|
||||
ValidMemberCount int64 `json:"valid_member_count"` // 有效会员数
|
||||
QuestionSubmitCount int64 `json:"question_submit_count"` // 问题总提交次数
|
||||
QuestionPayCount int64 `json:"question_pay_count"` // 问题总支付次数
|
||||
MemberBuyCount int64 `json:"member_buy_count"` // 会员购买次数
|
||||
MemberAmountTotal float64 `json:"member_amount_total"` // 会员购买总金额
|
||||
SingleAmountTotal float64 `json:"single_amount_total"` // 单项购买总金额
|
||||
AmountTotal float64 `json:"amount_total"` // 会员+单项购买总金额
|
||||
}
|
||||
|
||||
// IndexDataDto 首页动态统计数据
|
||||
type IndexDataDto struct {
|
||||
Date string `json:"date"` // 日期
|
||||
Count int64 `json:"count"` // 数量
|
||||
}
|
||||
|
||||
// AdminLoginDto 微信登陆
|
||||
func AdminLoginDto(m *model.AdminUser) *LoginDto {
|
||||
return &LoginDto{
|
||||
UserId: fmt.Sprintf("%d", m.UserId),
|
||||
NickName: m.NickName,
|
||||
Avatar: utils.AddOssDomain(m.Avatar),
|
||||
}
|
||||
}
|
||||
|
||||
// LoadToken 加载token
|
||||
func (r *LoginDto) LoadToken(token string) *LoginDto {
|
||||
r.Token = token
|
||||
return r
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"vote-admin-api/api/model"
|
||||
)
|
||||
|
||||
// UserDto 用户表
|
||||
type UserDto struct {
|
||||
UserId string `json:"user_id"` // 用户id
|
||||
UserStatus int `json:"user_status"` // 状态(1:正常 2:禁用)
|
||||
OpenId string `json:"open_id"` // 用户微信标识
|
||||
LoginAt *model.LocalTime `json:"login_at"` // 登陆时间
|
||||
LoginIp string `json:"login_ip"` // 登陆ip
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"vote-admin-api/api/model"
|
||||
)
|
||||
|
||||
// VideoDto 视频表
|
||||
type VideoDto struct {
|
||||
VideoId string `json:"video_id"` // 主键id
|
||||
VideoTitle string `json:"video_title"` // 视频标题
|
||||
VideoStatus int `json:"article_status"` // 视频状态(1:正常 2:禁用)
|
||||
VoteNum uint `json:"vote_num"` // 总票数
|
||||
VideoUrl string `json:"video_url"` // 视频地址
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
|
||||
VideoAuthor []*VideoAuthorDto `json:"video_author"` // 作者
|
||||
Rank *int `json:"rank"` // 排名
|
||||
IsVote bool `json:"is_vote"` // 是否已投票(false:否 true:是)
|
||||
}
|
||||
|
||||
// GetVideoListDto 列表-分页
|
||||
func GetVideoListDto(m []*model.Video) []*VideoDto {
|
||||
// 处理返回值
|
||||
responses := make([]*VideoDto, len(m))
|
||||
|
||||
if len(m) > 0 {
|
||||
for i, v := range m {
|
||||
response := &VideoDto{
|
||||
VideoId: fmt.Sprintf("%d", v.VideoId),
|
||||
VideoTitle: v.VideoTitle,
|
||||
VideoStatus: v.VideoStatus,
|
||||
VoteNum: v.VoteNum,
|
||||
VideoUrl: v.VideoUrl,
|
||||
CreatedAt: v.CreatedAt,
|
||||
UpdatedAt: v.UpdatedAt,
|
||||
}
|
||||
|
||||
// 加载数据-作者
|
||||
if v.VideoAuthor != nil {
|
||||
response = response.LoadVideoAuthor(v.VideoAuthor)
|
||||
}
|
||||
|
||||
// 将转换后的结构体添加到新切片中
|
||||
responses[i] = response
|
||||
}
|
||||
}
|
||||
|
||||
return responses
|
||||
}
|
||||
|
||||
// GetVideoDto 详情
|
||||
func GetVideoDto(m *model.Video) *VideoDto {
|
||||
return &VideoDto{
|
||||
VideoId: fmt.Sprintf("%d", m.VideoId),
|
||||
VideoTitle: m.VideoTitle,
|
||||
VideoStatus: m.VideoStatus,
|
||||
VoteNum: m.VoteNum,
|
||||
VideoUrl: m.VideoUrl,
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
// LoadVideoAuthor 加载数据-作者
|
||||
func (r *VideoDto) LoadVideoAuthor(m []*model.VideoAuthor) *VideoDto {
|
||||
if len(m) > 0 {
|
||||
r.VideoAuthor = GetVideoAuthorListDto(m)
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// LoadRank 加载数据-排名
|
||||
func (r *VideoDto) LoadRank(m int) *VideoDto {
|
||||
if m > 0 {
|
||||
r.Rank = &m
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// LoadVoteStatus 加载数据-投票状态
|
||||
func (r *VideoDto) LoadVoteStatus(m bool) *VideoDto {
|
||||
r.IsVote = m
|
||||
return r
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"vote-admin-api/api/model"
|
||||
)
|
||||
|
||||
type VideoAuthorDto struct {
|
||||
AuthorName string `json:"author_name"` // 作者姓名
|
||||
HospitalName string `json:"hospital_name"` // 作者所属医院
|
||||
}
|
||||
|
||||
// GetVideoAuthorListDto 列表-分页
|
||||
func GetVideoAuthorListDto(m []*model.VideoAuthor) []*VideoAuthorDto {
|
||||
// 处理返回值
|
||||
responses := make([]*VideoAuthorDto, len(m))
|
||||
|
||||
if len(m) > 0 {
|
||||
for i, v := range m {
|
||||
response := &VideoAuthorDto{
|
||||
AuthorName: v.AuthorName,
|
||||
}
|
||||
|
||||
// 加载数据-医院属性
|
||||
if v.BaseHospital != nil {
|
||||
response = response.LoadBaseHospitalAttr(v.BaseHospital)
|
||||
}
|
||||
|
||||
// 将转换后的结构体添加到新切片中
|
||||
responses[i] = response
|
||||
}
|
||||
}
|
||||
|
||||
return responses
|
||||
}
|
||||
|
||||
// LoadBaseHospitalAttr 加载数据-医院属性
|
||||
func (r *VideoAuthorDto) LoadBaseHospitalAttr(m *model.BaseHospital) *VideoAuthorDto {
|
||||
if m != nil {
|
||||
r.HospitalName = m.HospitalName
|
||||
}
|
||||
return r
|
||||
}
|
||||
Reference in New Issue
Block a user