初始化提交

This commit is contained in:
2024-08-28 18:31:18 +08:00
parent 9c1e56d5af
commit 70bac9077e
27 changed files with 1608 additions and 42 deletions
+7 -7
View File
@@ -8,14 +8,14 @@ import (
// Article 文章表
type Article struct {
ArticleId int64 `gorm:"column:article_id;type:bigint(19);primary_key;comment:主键id" json:"article_id"`
ArticleTitle string `gorm:"column:article_title;type:varchar(200);comment:文章标题" json:"article_title"`
ArticleStatus int `gorm:"column:article_status;type:tinyint(1);default:1;comment:文章状态(1:正常 2:禁用)" json:"article_status"`
StartTime *LocalTime `gorm:"column:start_time;type:datetime;comment:开始投票时间" json:"start_time"`
EndTime *LocalTime `gorm:"column:end_time;type:datetime;comment:结束投票时间" json:"end_time"`
VoteNum uint `gorm:"column:vote_num;type:int(10) unsigned;default:0;comment:总票数" json:"vote_num"`
ArticleContent string `gorm:"column:article_content;type:text;comment:文章内容" json:"article_content"`
ArticleId int64 `gorm:"column:article_id;type:bigint(19);primary_key;comment:主键id" json:"article_id"`
ArticleTitle string `gorm:"column:article_title;type:varchar(200);comment:文章标题" json:"article_title"`
ArticleStatus int `gorm:"column:article_status;type:tinyint(1);default:1;comment:文章状态(1:正常 2:禁用)" json:"article_status"`
VoteNum uint `gorm:"column:vote_num;type:int(10) unsigned;default:0;comment:总票数" json:"vote_num"`
ArticleContent string `gorm:"column:article_content;type:text;comment:文章内容" json:"article_content"`
Model
ArticleAuthor []*ArticleAuthor `gorm:"foreignKey:ArticleId;references:article_id" json:"article_author"`
Rank *int `gorm:"column:rank;type:tinyint(1) unsigned;comment:排名" json:"rank"`
}
func (m *Article) TableName() string {
+1
View File
@@ -13,6 +13,7 @@ type ArticleAuthor struct {
AuthorName string `gorm:"column:author_name;type:varchar(100);comment:作者姓名" json:"author_name"`
HospitalId int64 `gorm:"column:hospital_id;type:bigint(19);comment:作者所属医院id" json:"hospital_id"`
Model
BaseHospital *BaseHospital `gorm:"foreignKey:HospitalId;references:hospital_id" json:"base_hospital"`
}
func (m *ArticleAuthor) TableName() string {
+26
View File
@@ -0,0 +1,26 @@
package model
import (
"gorm.io/gorm"
"vote-api/global"
)
// BaseArea 地区表
type BaseArea struct {
AreaId int64 `gorm:"column:area_id;type:bigint(19);primary_key;comment:地区编号" json:"area_id"`
AreaName string `gorm:"column:area_name;type:varchar(255);comment:名称" json:"area_name"`
ParentId int64 `gorm:"column:parent_id;type:bigint(19);comment:上级编号" json:"parent_id"`
Zip string `gorm:"column:zip;type:varchar(10);comment:邮编" json:"zip"`
AreaType int `gorm:"column:area_type;type:tinyint(4);comment:类型(1:国家,2:省,3:市,4:区县)" json:"area_type"`
}
func (m *BaseArea) TableName() string {
return "base_area"
}
func (m *BaseArea) BeforeCreate(tx *gorm.DB) error {
if m.AreaId == 0 {
m.AreaId = global.Snowflake.Generate().Int64()
}
return nil
}
+46
View File
@@ -0,0 +1,46 @@
package model
import (
"gorm.io/gorm"
"time"
"vote-api/global"
)
// BaseHospital 医院表
type BaseHospital struct {
HospitalId int64 `gorm:"column:hospital_id;type:bigint(19);primary_key;comment:主键id" json:"hospital_id"`
HospitalName string `gorm:"column:hospital_name;type:varchar(255);comment:医院名称" json:"hospital_name"`
HospitalStatus int `gorm:"column:hospital_status;type:tinyint(1);default:1;comment:状态(0:禁用 1:正常 2:删除)" json:"hospital_status"`
HospitalLevelName string `gorm:"column:hospital_level_name;type:varchar(20);comment:医院等级名称" json:"hospital_level_name"`
PostCode string `gorm:"column:post_code;type:varchar(50);comment:邮政编码" json:"post_code"`
TelePhone string `gorm:"column:tele_phone;type:varchar(20);comment:电话" json:"tele_phone"`
ProvinceId int `gorm:"column:province_id;type:int(11);comment:省份id" json:"province_id"`
Province string `gorm:"column:province;type:varchar(50);comment:省份" json:"province"`
CityId int `gorm:"column:city_id;type:int(11);comment:城市id" json:"city_id"`
City string `gorm:"column:city;type:varchar(50);comment:城市" json:"city"`
CountyId int `gorm:"column:county_id;type:int(11);comment:区县id" json:"county_id"`
County string `gorm:"column:county;type:varchar(50);comment:区县" json:"county"`
Address string `gorm:"column:address;type:varchar(255);comment:地址" json:"address"`
Lat string `gorm:"column:lat;type:varchar(255);comment:纬度" json:"lat"`
Lng string `gorm:"column:lng;type:varchar(255);comment:经度" json:"lng"`
Desc string `gorm:"column:desc;type:varchar(255);comment:简介" json:"desc"`
Model
}
func (m *BaseHospital) TableName() string {
return "base_hospital"
}
func (m *BaseHospital) BeforeCreate(tx *gorm.DB) error {
if m.HospitalId == 0 {
m.HospitalId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}
+1 -1
View File
@@ -10,7 +10,7 @@ import (
type Data struct {
DataId int64 `gorm:"column:data_id;type:bigint(19);primary_key;comment:主键id" json:"data_id"`
ViewNum uint `gorm:"column:view_num;type:int(10) unsigned;default:0;comment:浏览数量" json:"view_num"`
VoteNum uint `gorm:"column:vote_num;type:int(10) unsigned;comment:投票数量" json:"vote_num"`
VoteNum uint `gorm:"column:vote_num;type:int(10) unsigned;default:0;comment:投票数量" json:"vote_num"`
Model
}
+33
View File
@@ -0,0 +1,33 @@
package model
import (
"gorm.io/gorm"
"time"
"vote-api/global"
)
// SystemTime 配置-时间
type SystemTime struct {
SystemTimeId int64 `gorm:"column:system_time_id;type:bigint(19);primary_key;comment:主键id" json:"system_time_id"`
StartTime *LocalTime `gorm:"column:start_time;type:datetime;comment:开始投票时间;NOT NULL" json:"start_time"`
EndTime *LocalTime `gorm:"column:end_time;type:datetime;comment:结束投票时间;NOT NULL" json:"end_time"`
Model
}
func (m *SystemTime) TableName() string {
return "system_time"
}
func (m *SystemTime) BeforeCreate(tx *gorm.DB) error {
if m.SystemTimeId == 0 {
m.SystemTimeId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}
+6 -7
View File
@@ -8,14 +8,13 @@ import (
// Video 视频表
type Video struct {
VideoId int64 `gorm:"column:video_id;type:bigint(19);primary_key;comment:主键id" json:"video_id"`
VideoTitle string `gorm:"column:video_title;type:varchar(200);comment:视频标题" json:"video_title"`
VideoStatus int `gorm:"column:video_status;type:tinyint(1);default:1;comment:视频状态(1:正常 2:禁用)" json:"video_status"`
StartTime *LocalTime `gorm:"column:start_time;type:datetime;comment:开始投票时间" json:"start_time"`
EndTime *LocalTime `gorm:"column:end_time;type:datetime;comment:结束投票时间" json:"end_time"`
VoteNum uint `gorm:"column:vote_num;type:int(10) unsigned;default:0;comment:总票数" json:"vote_num"`
VideoUrl string `gorm:"column:video_url;type:varchar(255);comment:视频地址" json:"video_url"`
VideoId int64 `gorm:"column:video_id;type:bigint(19);primary_key;comment:主键id" json:"video_id"`
VideoTitle string `gorm:"column:video_title;type:varchar(200);comment:视频标题" json:"video_title"`
VideoStatus int `gorm:"column:video_status;type:tinyint(1);default:1;comment:视频状态(1:正常 2:禁用)" json:"video_status"`
VoteNum uint `gorm:"column:vote_num;type:int(10) unsigned;default:0;comment:总票数" json:"vote_num"`
VideoUrl string `gorm:"column:video_url;type:varchar(255);comment:视频地址" json:"video_url"`
Model
VideoAuthor []*VideoAuthor `gorm:"foreignKey:VideoId;references:video_id" json:"video_author"`
}
func (m *Video) TableName() string {
+1
View File
@@ -13,6 +13,7 @@ type VideoAuthor struct {
AuthorName string `gorm:"column:author_name;type:varchar(100);comment:作者姓名" json:"author_name"`
HospitalId int64 `gorm:"column:hospital_id;type:bigint(19);comment:作者所属医院id" json:"hospital_id"`
Model
BaseHospital *BaseHospital `gorm:"foreignKey:HospitalId;references:hospital_id" json:"base_hospital"`
}
func (m *VideoAuthor) TableName() string {