新增了接口

This commit is contained in:
2024-12-30 16:34:26 +08:00
parent e6e78ad658
commit 60850d98da
153 changed files with 10293 additions and 5 deletions
+43
View File
@@ -0,0 +1,43 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// 后台-用户表
type AdminUser struct {
UserId int64 `gorm:"column:user_id;type:bigint(19);primary_key;comment:主键id" json:"user_id"`
Access string `gorm:"column:access;type:varchar(64);comment:账号;NOT NULL" json:"access"`
Password string `gorm:"column:password;type:varchar(128);comment:密码;NOT NULL" json:"password"`
Salt string `gorm:"column:salt;type:varchar(255);comment:密码掩码;NOT NULL" json:"salt"`
NickName string `gorm:"column:nick_name;type:varchar(255);comment:昵称" json:"nick_name"`
IsAdmin int `gorm:"column:is_admin;type:tinyint(1);default:0;comment:是否管理员(0:否 1:是)" json:"is_admin"`
Status int `gorm:"column:status;type:tinyint(1);default:2;comment:状态(1:正常 2:审核中 3:审核失败)" json:"status"`
IsDeleted int `gorm:"column:is_deleted;type:tinyint(1);default:0;comment:是否被删除(0:否 1:是)" json:"is_deleted"`
IsDisabled int `gorm:"column:is_disabled;type:tinyint(1);default:0;comment:是否被禁用(0:否 1:是)" json:"is_disabled"`
Phone string `gorm:"column:phone;type:varchar(11);comment:手机号" json:"phone"`
Avatar string `gorm:"column:avatar;type:varchar(255);comment:头像" json:"avatar"`
Sex int `gorm:"column:sex;type:tinyint(1);comment:性别(1:男 2:女)" json:"sex"`
Email string `gorm:"column:email;type:varchar(100);comment:邮箱" json:"email"`
Model
}
func (m *AdminUser) TableName() string {
return "admin_user"
}
func (m *AdminUser) BeforeCreate(tx *gorm.DB) error {
if m.UserId == 0 {
m.UserId = 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
}
+39
View File
@@ -0,0 +1,39 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// BasicHospital 基础数据-医院
type BasicHospital 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(100);comment:医院名称" json:"hospital_name"`
Source int `gorm:"column:source;type:tinyint(1);comment:来源(2:肝胆相照 3:佳动例);NOT NULL" json:"source"`
HospitalLevel string `gorm:"column:hospital_level;type:varchar(20);comment:医院等级" json:"hospital_level"`
DoctorNumber int `gorm:"column:doctor_number;type:int(5);default:0;comment:医生数量" json:"doctor_number"`
Province string `gorm:"column:province;type:varchar(50);comment:省份" json:"province"`
City string `gorm:"column:city;type:varchar(50);comment:城市" json:"city"`
County string `gorm:"column:county;type:varchar(50);comment:区县" json:"county"`
Address string `gorm:"column:address;type:varchar(255);comment:地址" json:"address"`
Model
}
func (m *BasicHospital) TableName() string {
return "basic_hospital"
}
func (m *BasicHospital) 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
}
+39
View File
@@ -0,0 +1,39 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// Case 病历表
type Case struct {
CaseId int64 `gorm:"column:case_id;type:bigint(19);primary_key;comment:主键id" json:"case_id"`
ProjectId int64 `gorm:"column:project_id;type:bigint(19);comment:所属项目id;NOT NULL" json:"project_id"`
CaseStatus int `gorm:"column:case_status;type:tinyint(1);default:1;comment:病例状态(1:正常 2:禁用)" json:"case_status"`
CaseName string `gorm:"column:case_name;type:varchar(100);comment:病例名称" json:"case_name"`
CaseAuthor string `gorm:"column:case_author;type:varchar(100);comment:病例作者" json:"case_author"`
IssuedScore int `gorm:"column:issued_score;type:int(5);default:0;comment:多平台已发放积分" json:"issued_score"`
JoinNum int `gorm:"column:join_num;type:int(5);default:0;comment:多平台参加总人数" json:"join_num"`
JoinWhiteNum int `gorm:"column:join_white_num;type:int(5);default:0;comment:多平台白名单参加总人数" json:"join_white_num"`
MessageNum int `gorm:"column:message_num;type:int(5);default:0;comment:多平台留言人数" json:"message_num"`
Model
}
func (m *Case) TableName() string {
return "case"
}
func (m *Case) BeforeCreate(tx *gorm.DB) error {
if m.CaseId == 0 {
m.CaseId = 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
}
+43
View File
@@ -0,0 +1,43 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// CaseComment 病历表-评论
type CaseComment struct {
CommentId int64 `gorm:"column:comment_id;type:bigint(19);primary_key;comment:主键id" json:"comment_id"`
CaseId int64 `gorm:"column:case_id;type:bigint(19);comment:所属病例id;NOT NULL" json:"case_id"`
PlatformId int64 `gorm:"column:platform_id;type:bigint(19);comment:来源平台id;NOT NULL" json:"platform_id"`
ParentId int64 `gorm:"column:parent_id;type:bigint(19);comment:父级id,一级评论为null" json:"parent_id"`
RootId int64 `gorm:"column:root_id;type:bigint(19);comment:根评论id,一级评论时为null。其余为一级评论id" json:"root_id"`
Level int `gorm:"column:level;type:tinyint(1);default:1;comment:级别(1:留言 2:回复 3:评论)" json:"level"`
UserId int64 `gorm:"column:user_id;type:bigint(19);comment:用户id;NOT NULL" json:"user_id"`
Status int `gorm:"column:status;type:tinyint(1);default:1;comment:评论状态(0:禁用 1:正常)" json:"status"`
IsHighQuality int `gorm:"column:is_high_quality;type:tinyint(1);default:0;comment:是否优质留言(0:否 1:是)" json:"is_high_quality"`
IsGrantHighQuality int `gorm:"column:is_grant_high_quality;type:tinyint(1);default:0;comment:优质留言积分是否已发放(0:否 1:是)" json:"is_grant_high_quality"`
LikeNum int `gorm:"column:like_num;type:int(5);default:0;comment:点赞数量" json:"like_num"`
Content string `gorm:"column:content;type:varchar(500);comment:评论内容" json:"content"`
Model
User *User `gorm:"foreignKey:UserId;references:user_id" json:"user"`
}
func (m *CaseComment) TableName() string {
return "case_comment"
}
func (m *CaseComment) BeforeCreate(tx *gorm.DB) error {
if m.CommentId == 0 {
m.CommentId = 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
}
+33
View File
@@ -0,0 +1,33 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// CaseCommentLike 病历-评论-点赞
type CaseCommentLike struct {
LikeId int64 `gorm:"column:like_id;type:bigint(19);primary_key;comment:主键id" json:"like_id"`
CommentId int64 `gorm:"column:comment_id;type:bigint(19);comment:评论id" json:"comment_id"`
UserId int64 `gorm:"column:user_id;type:bigint(19);comment:用户id" json:"user_id"`
Model
}
func (m *CaseCommentLike) TableName() string {
return "case_comment_like"
}
func (m *CaseCommentLike) BeforeCreate(tx *gorm.DB) error {
if m.LikeId == 0 {
m.LikeId = 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
}
+36
View File
@@ -0,0 +1,36 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// CaseItem 病历表-明细
type CaseItem struct {
CaseItemId int64 `gorm:"column:case_item_id;type:bigint(19);primary_key;comment:主键id" json:"case_item_id"`
CaseId int64 `gorm:"column:case_id;type:bigint(19);comment:所属病例id;NOT NULL" json:"case_id"`
Page int `gorm:"column:page;type:int(1);default:1;comment:页码" json:"page"`
Content string `gorm:"column:content;type:text;comment:详情内容" json:"content"`
IsRightNext int `gorm:"column:is_right_next;type:tinyint(1);default:1;comment:是否答对后允许下一步(0:否 1:是)" json:"is_right_next"`
ErrorTips string `gorm:"column:error_tips;type:varchar(200);comment:答错提示" json:"error_tips"`
Model
}
func (m *CaseItem) TableName() string {
return "case_item"
}
func (m *CaseItem) BeforeCreate(tx *gorm.DB) error {
if m.CaseItemId == 0 {
m.CaseItemId = 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
}
+37
View File
@@ -0,0 +1,37 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// CaseItemQuestion 病历表-明细-题目
type CaseItemQuestion struct {
QuestionId int64 `gorm:"column:question_id;type:bigint(19);primary_key;comment:主键id" json:"question_id"`
CaseId int64 `gorm:"column:case_id;type:bigint(19);comment:病例id" json:"case_id"`
CaseItemId int64 `gorm:"column:case_item_id;type:bigint(19);comment:病例明细id;NOT NULL" json:"case_item_id"`
QuestionName string `gorm:"column:question_name;type:varchar(1000);comment:题目名称" json:"question_name"`
QuestionType int `gorm:"column:question_type;type:tinyint(1);comment:题目类型(1:单选 2:多选 3:问答 4:判断)" json:"question_type"`
QuestionAnswer string `gorm:"column:question_answer;type:varchar(255);comment:答案" json:"question_answer"`
Model
CaseItemQuestionOption []*CaseItemQuestionOption `gorm:"foreignKey:QuestionId;references:question_id" json:"case_item_question_option"`
}
func (m *CaseItemQuestion) TableName() string {
return "case_item_question"
}
func (m *CaseItemQuestion) BeforeCreate(tx *gorm.DB) error {
if m.QuestionId == 0 {
m.QuestionId = 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
}
+33
View File
@@ -0,0 +1,33 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// CaseItemQuestionOption 病历表-明细-题目-选项
type CaseItemQuestionOption struct {
OptionId int64 `gorm:"column:option_id;type:bigint(19);primary_key;comment:主键id" json:"option_id"`
QuestionId int64 `gorm:"column:question_id;type:bigint(19);comment:题目id;NOT NULL" json:"question_id"`
OptionValue string `gorm:"column:option_value;type:varchar(255);comment:选项内容" json:"option_value"`
Model
}
func (m *CaseItemQuestionOption) TableName() string {
return "case_item_question_option"
}
func (m *CaseItemQuestionOption) BeforeCreate(tx *gorm.DB) error {
if m.OptionId == 0 {
m.OptionId = 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
}
+38
View File
@@ -0,0 +1,38 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// CasePlatform 统计数据-病例-平台
type CasePlatform struct {
CasePlatformId int64 `gorm:"column:case_platform_id;type:bigint(19);primary_key;comment:主键id" json:"case_platform_id"`
CaseId int64 `gorm:"column:case_id;type:bigint(19);comment:所属病例id;NOT NULL" json:"case_id"`
PlatformId int64 `gorm:"column:platform_id;type:bigint(19);comment:用户所属平台id;NOT NULL" json:"platform_id"`
IssuedScore int `gorm:"column:issued_score;type:int(5);default:0;comment:已发放积分" json:"issued_score"`
JoinNum int `gorm:"column:join_num;type:int(5);default:0;comment:参加人数" json:"join_num"`
JoinWhiteNum int `gorm:"column:join_white_num;type:int(5);default:0;comment:白名单参加人数" json:"join_white_num"`
MessageNum int `gorm:"column:message_num;type:int(5);default:0;comment:留言人数" json:"message_num"`
Model
ProjectPlatform *ProjectPlatform `gorm:"foreignKey:PlatformId;references:platform_id" json:"project_platform"`
}
func (m *CasePlatform) TableName() string {
return "case_platform"
}
func (m *CasePlatform) BeforeCreate(tx *gorm.DB) error {
if m.CasePlatformId == 0 {
m.CasePlatformId = 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
}
+40
View File
@@ -0,0 +1,40 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// CaseUser 统计数据-病例-用户
type CaseUser struct {
CaseUserId int64 `gorm:"column:case_user_id;type:bigint(19);primary_key;comment:主键id" json:"case_user_id"`
CaseId int64 `gorm:"column:case_id;type:bigint(19);comment:所属病例id;NOT NULL" json:"case_id"`
PlatformId int64 `gorm:"column:platform_id;type:bigint(19);comment:用户所属平台id;NOT NULL" json:"platform_id"`
UserId int64 `gorm:"column:user_id;type:bigint(19);comment:用户id;NOT NULL" json:"user_id"`
ShareUserIden string `gorm:"column:share_user_iden;type:varchar(100);comment:分享人标识" json:"share_user_iden"`
ReadDuration int `gorm:"column:read_duration;type:int(5);default:0;comment:阅读时长(秒)" json:"read_duration"`
TotalScore int `gorm:"column:total_score;type:int(5);default:0;comment:单个病例领取总积分" json:"total_score"`
Model
Platform *Platform `gorm:"foreignKey:PlatformId;references:platform_id" json:"platform"`
User *User `gorm:"foreignKey:UserId;references:user_id" json:"user"`
Case *Case `gorm:"foreignKey:CaseId;references:case_id" json:"case"`
}
func (m *CaseUser) TableName() string {
return "case_user"
}
func (m *CaseUser) BeforeCreate(tx *gorm.DB) error {
if m.CaseUserId == 0 {
m.CaseUserId = 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
}
+35
View File
@@ -0,0 +1,35 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// Platform 项目表-关联平台
type Platform struct {
PlatformId int64 `gorm:"column:platform_id;type:bigint(19);primary_key;comment:主键id" json:"platform_id"`
PlatformName string `gorm:"column:platform_name;type:varchar(100);comment:平台名称;NOT NULL" json:"platform_name"`
PlatformStatus int `gorm:"column:platform_status;type:tinyint(1);default:1;comment:平台状态(1:正常 2:禁用);NOT NULL" json:"platform_status"`
PlatformKey string `gorm:"column:platform_key;type:varchar(100);comment:平台标识(用于鉴权);NOT NULL" json:"platform_key"`
PlatformSecret string `gorm:"column:platform_secret;type:varchar(100);comment:平台密钥(用于鉴权)" json:"platform_secret"`
Model
}
func (m *Platform) TableName() string {
return "platform"
}
func (m *Platform) BeforeCreate(tx *gorm.DB) error {
if m.PlatformId == 0 {
m.PlatformId = 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
}
+38
View File
@@ -0,0 +1,38 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// Project 项目表
type Project struct {
ProjectId int64 `gorm:"column:project_id;type:bigint(19);primary_key;comment:主键id" json:"project_id"`
ProjectName string `gorm:"column:project_name;type:varchar(255);comment:项目名称" json:"project_name"`
ProjectStatus int `gorm:"column:project_status;type:tinyint(1);comment:项目状态(0:无效 1:正常)" json:"project_status"`
ProjectImage string `gorm:"column:project_image;type:varchar(255);comment:项目背景图" json:"project_image"`
IsLimitNum int `gorm:"column:is_limit_num;type:tinyint(1);default:0;comment:是否限制参加数量(0:否 1:是)" json:"is_limit_num"`
MaxJoinNum int `gorm:"column:max_join_num;type:int(5);default:0;comment:医生最多可参加数量" json:"max_join_num"`
Model
Case []*Case `gorm:"foreignKey:ProjectId;references:project_id" json:"case"`
ProjectPlatform []*ProjectPlatform `gorm:"foreignKey:ProjectId;references:project_id" json:"project_platform"`
}
func (m *Project) TableName() string {
return "project"
}
func (m *Project) BeforeCreate(tx *gorm.DB) error {
if m.ProjectId == 0 {
m.ProjectId = 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
}
+44
View File
@@ -0,0 +1,44 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// ProjectPlatform 项目表-关联平台
type ProjectPlatform struct {
ProjectPlatformId int64 `gorm:"column:project_platform_id;type:bigint(19);primary_key;comment:主键id" json:"project_platform_id"`
PlatformId int64 `gorm:"column:platform_id;type:bigint(19);comment:主键id;NOT NULL" json:"platform_id"`
ProjectId int64 `gorm:"column:project_id;type:bigint(19);comment:项目id;NOT NULL" json:"project_id"`
Status int `gorm:"column:status;type:tinyint(1);default:1;comment:状态(1:正常 2:禁用)" json:"status"`
IsWelfare int `gorm:"column:is_welfare;type:tinyint(1);default:1;comment:是否开启福利(0:否 1:是)" json:"is_welfare"`
ReadDuration int `gorm:"column:read_duration;type:int(10);comment:阅读时长(秒)" json:"read_duration"`
SingleCaseScore int `gorm:"column:single_case_score;type:int(10);comment:单个病例总积分" json:"single_case_score"`
CompleteRead int `gorm:"column:complete_read;type:int(10);comment:完成阅读积分" json:"complete_read"`
CompleteReadTime int `gorm:"column:complete_read_time;type:int(10);comment:完成阅读时间积分" json:"complete_read_time"`
FirstHighQuality int `gorm:"column:first_high_quality;type:int(10);comment:首次优质留言积分" json:"first_high_quality"`
OnceMoreHighQuality int `gorm:"column:once_more_high_quality;type:int(10);comment:再次优质留言积分" json:"once_more_high_quality"`
IsWhite int `gorm:"column:is_white;type:tinyint(1);default:0;comment:是否开启白名单(0:否 1:是)" json:"is_white"`
WhiteType int `gorm:"column:white_type;type:tinyint(1);comment:白名单类型(1:医院 2:医生 3:动态)" json:"white_type"`
Model
Platform *Platform `gorm:"foreignKey:PlatformId;references:platform_id" json:"platform"`
}
func (m *ProjectPlatform) TableName() string {
return "project_platform"
}
func (m *ProjectPlatform) BeforeCreate(tx *gorm.DB) error {
if m.ProjectPlatformId == 0 {
m.ProjectPlatformId = 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
}
+34
View File
@@ -0,0 +1,34 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// ProjectPlatformArea 关联平台-白名单-省份
type ProjectPlatformArea struct {
WhiteAreaId int64 `gorm:"column:white_area_id;type:bigint(19);primary_key;comment:主键id" json:"white_area_id"`
PlatformId int64 `gorm:"column:platform_id;type:bigint(19);comment:关联平台id;NOT NULL" json:"platform_id"`
AreaName string `gorm:"column:area_name;type:varchar(100);comment:地址名称;NOT NULL" json:"area_name"`
Status int `gorm:"column:status;type:tinyint(1);default:1;comment:状态(1:正常 2:禁用)" json:"status"`
Model
}
func (m *ProjectPlatformArea) TableName() string {
return "project_platform_area"
}
func (m *ProjectPlatformArea) BeforeCreate(tx *gorm.DB) error {
if m.WhiteAreaId == 0 {
m.WhiteAreaId = 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
}
+35
View File
@@ -0,0 +1,35 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// ProjectPlatformDoctor 关联平台-白名单-医生
type ProjectPlatformDoctor struct {
WhiteDoctorId int64 `gorm:"column:white_doctor_id;type:bigint(19);primary_key;comment:主键id" json:"white_doctor_id"`
PlatformId int64 `gorm:"column:platform_id;type:bigint(19);comment:关联平台id;NOT NULL" json:"platform_id"`
UserId int64 `gorm:"column:user_id;type:bigint(19);comment:关联用户id" json:"user_id"`
Status int `gorm:"column:status;type:tinyint(1);default:1;comment:状态(1:正常 2:禁用)" json:"status"`
Model
User []*User `gorm:"foreignKey:UserId;references:user_id" json:"user"`
}
func (m *ProjectPlatformDoctor) TableName() string {
return "project_platform_doctor"
}
func (m *ProjectPlatformDoctor) BeforeCreate(tx *gorm.DB) error {
if m.WhiteDoctorId == 0 {
m.WhiteDoctorId = 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
}
+35
View File
@@ -0,0 +1,35 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// ProjectPlatformDynamic 关联平台-白名单-动态
type ProjectPlatformDynamic struct {
WhiteDynamicId int64 `gorm:"column:white_dynamic_id;type:bigint(19);primary_key;comment:主键id" json:"white_dynamic_id"`
PlatformId int64 `gorm:"column:platform_id;type:bigint(19);comment:关联平台id;NOT NULL" json:"platform_id"`
DynamicType string `gorm:"column:dynamic_type;type:varchar(50);comment:动态类型(area:省份 level:医院等级 title:职称 department:科室 url:地址栏 类型间以-链接)" json:"dynamic_type"`
Status int `gorm:"column:status;type:tinyint(1);comment:状态(1:正常 2:禁用)" json:"status"`
Model
ProjectPlatformDynamicItem []*ProjectPlatformDynamicItem `gorm:"foreignKey:WhiteDynamicId;references:white_dynamic_id" json:"project_platform_dynamic_item"`
}
func (m *ProjectPlatformDynamic) TableName() string {
return "project_platform_dynamic"
}
func (m *ProjectPlatformDynamic) BeforeCreate(tx *gorm.DB) error {
if m.WhiteDynamicId == 0 {
m.WhiteDynamicId = 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
}
+33
View File
@@ -0,0 +1,33 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// ProjectPlatformDynamicItem 关联平台-白名单-动态-明细
type ProjectPlatformDynamicItem struct {
ItemId int64 `gorm:"column:item_id;type:bigint(19);primary_key;comment:主键id" json:"item_id"`
WhiteDynamicId int64 `gorm:"column:white_dynamic_id;type:bigint(19);comment:关联动态白名单id;NOT NULL" json:"white_dynamic_id"`
ItemValue string `gorm:"column:item_value;type:varchar(255);comment:明细值(area:省份 level:医院等级 title:职称 department:科室 url:地址栏 类型间以-链接)" json:"item_value"`
Model
}
func (m *ProjectPlatformDynamicItem) TableName() string {
return "project_platform_dynamic_item"
}
func (m *ProjectPlatformDynamicItem) BeforeCreate(tx *gorm.DB) error {
if m.ItemId == 0 {
m.ItemId = 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
}
+34
View File
@@ -0,0 +1,34 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// ProjectPlatformGrade 关联平台-白名单-医院等级
type ProjectPlatformGrade struct {
WhiteGradeId int64 `gorm:"column:white_grade_id;type:bigint(19);primary_key;comment:主键id" json:"white_grade_id"`
PlatformId int64 `gorm:"column:platform_id;type:bigint(19);comment:关联平台id;NOT NULL" json:"platform_id"`
Grade string `gorm:"column:grade;type:varchar(100);comment:等级(次字段存疑,等确定医院等级后修改);NOT NULL" json:"grade"`
Status int `gorm:"column:status;type:tinyint(1);default:1;comment:状态(1:正常 2:禁用)" json:"status"`
Model
}
func (m *ProjectPlatformGrade) TableName() string {
return "project_platform_grade"
}
func (m *ProjectPlatformGrade) BeforeCreate(tx *gorm.DB) error {
if m.WhiteGradeId == 0 {
m.WhiteGradeId = 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
}
+35
View File
@@ -0,0 +1,35 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// ProjectPlatformHospital 关联平台-白名单-医院
type ProjectPlatformHospital struct {
WhiteHospitalId int64 `gorm:"column:white_hospital_id;type:bigint(19);primary_key;comment:主键id" json:"white_hospital_id"`
PlatformId int64 `gorm:"column:platform_id;type:bigint(19);comment:关联平台id;NOT NULL" json:"platform_id"`
HospitalId int64 `gorm:"column:hospital_id;type:bigint(19);comment:医院id;NOT NULL" json:"hospital_id"`
Status int `gorm:"column:status;type:tinyint(1);default:1;comment:状态(1:正常 2:禁用)" json:"status"`
Model
BasicHospital []*BasicHospital `gorm:"foreignKey:HospitalId;references:hospital_id" json:"basic_hospital"`
}
func (m *ProjectPlatformHospital) TableName() string {
return "project_platform_hospital"
}
func (m *ProjectPlatformHospital) BeforeCreate(tx *gorm.DB) error {
if m.WhiteHospitalId == 0 {
m.WhiteHospitalId = 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
}
+39
View File
@@ -0,0 +1,39 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// RecordScore 积分发放记录
type RecordScore struct {
ScoreId int64 `gorm:"column:score_id;type:bigint(19);primary_key;comment:主键id" json:"score_id"`
ProjectId int64 `gorm:"column:project_id;type:bigint(19);comment:所属项目id;NOT NULL" json:"project_id"`
CaseId int64 `gorm:"column:case_id;type:bigint(19);comment:所属病例id" json:"case_id"`
PlatformId int64 `gorm:"column:platform_id;type:bigint(19);comment:用户所属平台id" json:"platform_id"`
UserIden string `gorm:"column:user_iden;type:varchar(100);comment:用户标识(用于区分不同平台用户)" json:"user_iden"`
UserName string `gorm:"column:user_name;type:varchar(100);comment:用户名称" json:"user_name"`
Type int `gorm:"column:type;type:tinyint(1);default:1;comment:积分类型(1:完成阅读 2:阅读时间满足 3:优质留言 4:再次优质留言 " json:"type"`
NodeName string `gorm:"column:node_name;type:varchar(50);comment:获取积分节点名称(如:阅读时间足够)" json:"node_name"`
Score int `gorm:"column:score;type:int(5);comment:积分" json:"score"`
Model
}
func (m *RecordScore) TableName() string {
return "record_score"
}
func (m *RecordScore) BeforeCreate(tx *gorm.DB) error {
if m.ScoreId == 0 {
m.ScoreId = 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
}
+46
View File
@@ -0,0 +1,46 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// User 用户表
type User struct {
UserId int64 `gorm:"column:user_id;type:bigint(19);primary_key;comment:主键id" json:"user_id"`
UserIden string `gorm:"column:user_iden;type:varchar(50);comment:第三方平台唯一标识" json:"user_iden"`
UserName string `gorm:"column:user_name;type:varchar(200);comment:用户名称" json:"user_name"`
UserMobile string `gorm:"column:user_mobile;type:varchar(20);comment:手机号" json:"user_mobile"`
MobileEncryption string `gorm:"column:mobile_encryption;type:varchar(100);comment:手机号加密" json:"mobile_encryption"`
Status int `gorm:"column:status;type:tinyint(1);default:1;comment:状态(0:禁用 1:正常 2:删除)" json:"status"`
RegisterSource int `gorm:"column:register_source;type:tinyint(1);default:1;comment:注册来源(1:未知 2:app用户 3:佳动例)" json:"register_source"`
OpenId string `gorm:"column:open_id;type:varchar(100);comment:用户微信标识" json:"open_id"`
UnionId string `gorm:"column:union_id;type:varchar(100);comment:微信开放平台标识" json:"union_id"`
Sex int `gorm:"column:sex;type:tinyint(1);default:0;comment:性别(0:未知 1:男 2:女)" json:"sex"`
Avatar string `gorm:"column:avatar;type:varchar(255);comment:头像" json:"avatar"`
Title int `gorm:"column:title;type:tinyint(1);comment:医生职称(1:主任医师 2:主任中医师 3:副主任医师 4:副主任中医师 5:主治医师 6:住院医师)" json:"title"`
DepartmentName string `gorm:"column:department_name;type:varchar(100);comment:科室名称" json:"department_name"`
HospitalId int64 `gorm:"column:hospital_id;type:bigint(19);comment:所属医院id" json:"hospital_id"`
Address string `gorm:"column:address;type:varchar(255);comment:医生地址" json:"address"`
Model
Hospital *BasicHospital `gorm:"foreignKey:HospitalId;references:hospital_id" json:"hospital"`
}
func (m *User) TableName() string {
return "user"
}
func (m *User) BeforeCreate(tx *gorm.DB) error {
if m.UserId == 0 {
m.UserId = 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
}
+38
View File
@@ -0,0 +1,38 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// UserAnswerRecords 用户答题记录表
type UserAnswerRecords struct {
CaseUserQuestionId int64 `gorm:"column:case_user_question_id;type:bigint(19);primary_key;comment:主键id" json:"case_user_question_id"`
CaseId int64 `gorm:"column:case_id;type:bigint(19);comment:病例id;NOT NULL" json:"case_id"`
PlatformId int64 `gorm:"column:platform_id;type:bigint(19);comment:用户所属平台id;NOT NULL" json:"platform_id"`
QuestionId int64 `gorm:"column:question_id;type:bigint(19);comment:题目id;NOT NULL" json:"question_id"`
UserId int64 `gorm:"column:user_id;type:bigint(19);comment:用户id;NOT NULL" json:"user_id"`
Answer string `gorm:"column:answer;type:varchar(255);comment:答案" json:"answer"`
IsTrue int `gorm:"column:is_true;type:tinyint(1);comment:是否正确(0:否 1:是)" json:"is_true"`
Model
CaseItemQuestion *CaseItemQuestion `gorm:"foreignKey:QuestionId;references:question_id" json:"case_item_question"`
}
func (m *UserAnswerRecords) TableName() string {
return "user_answer_records"
}
func (m *UserAnswerRecords) BeforeCreate(tx *gorm.DB) error {
if m.CaseUserQuestionId == 0 {
m.CaseUserQuestionId = 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
}
+87
View File
@@ -0,0 +1,87 @@
package model
import (
"database/sql/driver"
"errors"
"fmt"
"gorm.io/gorm"
"strings"
"time"
)
type Model struct {
CreatedAt LocalTime `gorm:"column:created_at;type:datetime;comment:创建时间" json:"created_at"`
UpdatedAt LocalTime `gorm:"column:updated_at;type:datetime;comment:修改时间" json:"updated_at"`
}
// LocalTime 自定义数据类型
type LocalTime time.Time
func (t *LocalTime) UnmarshalJSON(data []byte) error {
if string(data) == "null" {
return nil
}
var err error
// 前端接收的时间字符串
str := string(data)
// 去除接收的str收尾多余的"
timeStr := strings.Trim(str, "\"")
t1, err := time.Parse("2006-01-02 15:04:05", timeStr)
*t = LocalTime(t1)
return err
}
func (t LocalTime) MarshalJSON() ([]byte, error) {
formatted := fmt.Sprintf("\"%v\"", time.Time(t).Format("2006-01-02 15:04:05"))
return []byte(formatted), nil
}
func (t LocalTime) Value() (driver.Value, error) {
// MyTime 转换成 time.Time 类型
tTime := time.Time(t)
return tTime.Format("2006-01-02 15:04:05"), nil
}
func (t *LocalTime) Scan(v interface{}) error {
switch vt := v.(type) {
case time.Time:
// 字符串转成 time.Time 类型
*t = LocalTime(vt)
default:
return errors.New("类型处理错误")
}
return nil
}
func (t *LocalTime) String() string {
return fmt.Sprintf("hhh:%s", time.Time(*t).String())
}
func (t *LocalTime) IsEmpty() bool {
return time.Time(*t).IsZero()
}
func (m *Model) BeforeUpdate(tx *gorm.DB) (err error) {
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}
func Paginate(page, pageSize int) func(db *gorm.DB) *gorm.DB {
return func(db *gorm.DB) *gorm.DB {
if page <= 0 {
page = 1
}
switch {
case pageSize > 100:
pageSize = 100
case pageSize <= 0:
pageSize = 10
}
offset := (page - 1) * pageSize
return db.Offset(offset).Limit(pageSize)
}
}