🎨 优化model
This commit is contained in:
parent
2d467c710f
commit
8c5fa60081
@ -3,13 +3,13 @@ package entity
|
|||||||
import "online_code/common/types"
|
import "online_code/common/types"
|
||||||
|
|
||||||
// Category 分类表
|
// Category 分类表
|
||||||
type Category struct {
|
type CategoryBasic struct {
|
||||||
types.BaseDbModel
|
types.BaseDbModel
|
||||||
Identity string `json:"identity" gorm:"column:identity;type:varchar(36);comment:'分类的唯一标识'"`
|
Identity string `json:"identity" gorm:"column:identity;type:varchar(36);comment:'分类的唯一标识'"`
|
||||||
Name string `json:"name" gorm:"column:name;type:varchar(100);comment:'分类名称'" `
|
Name string `json:"name" gorm:"column:name;type:varchar(100);comment:'分类名称'" `
|
||||||
ParentId int `json:"parent_id" gorm:"column:parent_id;type:int(11);comment:'父级ID'" `
|
ParentId int `json:"parent_id" gorm:"column:parent_id;type:int(11);comment:'父级ID'" `
|
||||||
}
|
}
|
||||||
|
|
||||||
func (table *Category) TableName() string {
|
func (table *CategoryBasic) TableName() string {
|
||||||
return "category"
|
return "category_basic"
|
||||||
}
|
}
|
@ -3,7 +3,7 @@ package entity
|
|||||||
import "online_code/common/types"
|
import "online_code/common/types"
|
||||||
|
|
||||||
// Problem 问题表
|
// Problem 问题表
|
||||||
type Problem struct {
|
type ProblemBasic struct {
|
||||||
types.BaseDbModel
|
types.BaseDbModel
|
||||||
Identity string `json:"identity" gorm:"column:identity;type:varchar(36);comment:'问题表的唯一标识'" ` // 问题表的唯一标识
|
Identity string `json:"identity" gorm:"column:identity;type:varchar(36);comment:'问题表的唯一标识'" ` // 问题表的唯一标识
|
||||||
ProblemCategories []*ProblemCategory `json:"problem_categories" gorm:"foreignKey:problem_id;references:id;comment:'关联问题分类表'" ` // 关联问题分类表
|
ProblemCategories []*ProblemCategory `json:"problem_categories" gorm:"foreignKey:problem_id;references:id;comment:'关联问题分类表'" ` // 关联问题分类表
|
||||||
@ -16,6 +16,6 @@ type Problem struct {
|
|||||||
SubmitNum int64 `json:"submit_num" gorm:"column:submit_num;type:int(11);comment:'提交次数'" ` // 提交次数
|
SubmitNum int64 `json:"submit_num" gorm:"column:submit_num;type:int(11);comment:'提交次数'" ` // 提交次数
|
||||||
}
|
}
|
||||||
|
|
||||||
func (table *Problem) TableName() string {
|
func (table *ProblemBasic) TableName() string {
|
||||||
return "problem_basic"
|
return "problem_basic"
|
||||||
}
|
}
|
@ -7,9 +7,9 @@ import (
|
|||||||
// ProblemCategory 问题分类关联表
|
// ProblemCategory 问题分类关联表
|
||||||
type ProblemCategory struct {
|
type ProblemCategory struct {
|
||||||
types.BaseDbModel
|
types.BaseDbModel
|
||||||
ProblemId uint `json:"problem_id" gorm:"column:problem_id;type:int(11);comment:'问题的ID'" ` // 问题的ID
|
ProblemId uint `json:"problem_id" gorm:"column:problem_id;type:int(11);comment:'问题的ID'" ` // 问题的ID
|
||||||
CategoryId uint `json:"category_id" gorm:"column:category_id;type:int(11);comment:'分类的ID'" ` // 分类的ID
|
CategoryId uint `json:"category_id" gorm:"column:category_id;type:int(11);comment:'分类的ID'" ` // 分类的ID
|
||||||
CategoryBasic *Category `json:"category_basic" gorm:"foreignKey:id;references:category_id;comment:'关联分类的基础信息表'" ` // 关联分类的基础信息表
|
CategoryBasic *CategoryBasic `json:"category_basic" gorm:"foreignKey:id;references:category_id;comment:'关联分类的基础信息表'" ` // 关联分类的基础信息表
|
||||||
}
|
}
|
||||||
|
|
||||||
func (table *ProblemCategory) TableName() string {
|
func (table *ProblemCategory) TableName() string {
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
package entity
|
|
||||||
|
|
||||||
// Submit 提交表
|
|
||||||
type Submit struct {
|
|
||||||
Identity string `json:"identity" gorm:"column:identity;type:varchar(36);comment:'用户唯一标识'" ` // 唯一标识
|
|
||||||
ProblemIdentity string `json:"problem_identity" gorm:"column:problem_identity;type:varchar(36);comment:'问题表的唯一标识'" ` // 问题表的唯一标识
|
|
||||||
ProblemBasic *Problem `json:"problem_basic" gorm:"foreignKey:identity;references:problem_identity;comment:'关联问题基础表'" ` // 关联问题基础表
|
|
||||||
UserIdentity string `json:"user_identity" gorm:"column:user_identity;type:varchar(36);comment:'用户表的唯一标识'" ` // 用户表的唯一标识
|
|
||||||
UserBasic *User `json:"user_basic" gorm:"foreignKey:identity;references:user_identity;comment:'联用户基础表'" ` // 关联用户基础表
|
|
||||||
Path string `json:"path" gorm:"column:path;type:varchar(255);comment:'代码存放路径'" ` // 代码存放路径
|
|
||||||
Status int `json:"status" gorm:"column:status;type:tinyint(1);comment:'状态'" ` // 【-1-待判断,1-答案正确,2-答案错误,3-运行超时,4-运行超内存, 5-编译错误】
|
|
||||||
}
|
|
||||||
|
|
||||||
func (table *Submit) TableName() string {
|
|
||||||
return "submit"
|
|
||||||
}
|
|
16
models/entity/submit_basic.go
Normal file
16
models/entity/submit_basic.go
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package entity
|
||||||
|
|
||||||
|
// Submit 提交表
|
||||||
|
type SubmitBasic struct {
|
||||||
|
Identity string `json:"identity" gorm:"column:identity;type:varchar(36);comment:'用户唯一标识'" ` // 唯一标识
|
||||||
|
ProblemIdentity string `json:"problem_identity" gorm:"column:problem_identity;type:varchar(36);comment:'问题表的唯一标识'" ` // 问题表的唯一标识
|
||||||
|
ProblemBasic *ProblemBasic `json:"problem_basic" gorm:"foreignKey:identity;references:problem_identity;comment:'关联问题基础表'" ` // 关联问题基础表
|
||||||
|
UserIdentity string `json:"user_identity" gorm:"column:user_identity;type:varchar(36);comment:'用户表的唯一标识'" ` // 用户表的唯一标识
|
||||||
|
UserBasic *UserBasic `json:"user_basic" gorm:"foreignKey:identity;references:user_identity;comment:'联用户基础表'" ` // 关联用户基础表
|
||||||
|
Path string `json:"path" gorm:"column:path;type:varchar(255);comment:'代码存放路径'" ` // 代码存放路径
|
||||||
|
Status int `json:"status" gorm:"column:status;type:tinyint(1);comment:'状态'" ` // 【-1-待判断,1-答案正确,2-答案错误,3-运行超时,4-运行超内存, 5-编译错误】
|
||||||
|
}
|
||||||
|
|
||||||
|
func (table *SubmitBasic) TableName() string {
|
||||||
|
return "submit_basic"
|
||||||
|
}
|
@ -2,7 +2,7 @@ package entity
|
|||||||
|
|
||||||
import "online_code/common/types"
|
import "online_code/common/types"
|
||||||
|
|
||||||
type User struct {
|
type UserBasic struct {
|
||||||
types.BaseDbModel
|
types.BaseDbModel
|
||||||
Identity string `json:"identity" gorm:"column:identity;type:varchar(36);comment:'用户唯一标识'"`
|
Identity string `json:"identity" gorm:"column:identity;type:varchar(36);comment:'用户唯一标识'"`
|
||||||
Name string `json:"name" gorm:"column:name;type:varchar(100);not null;comment:'用户名'"`
|
Name string `json:"name" gorm:"column:name;type:varchar(100);not null;comment:'用户名'"`
|
||||||
@ -14,6 +14,6 @@ type User struct {
|
|||||||
IsAdmin int `json:"is_admin" gorm:"column:is_admin;type:tinyint(1);comment:'是否是管理员【0-否,1-是】'"`
|
IsAdmin int `json:"is_admin" gorm:"column:is_admin;type:tinyint(1);comment:'是否是管理员【0-否,1-是】'"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (table *User) TableName() string {
|
func (table *UserBasic) TableName() string {
|
||||||
return "user"
|
return "user_basic"
|
||||||
}
|
}
|
@ -2,5 +2,6 @@ package param
|
|||||||
|
|
||||||
type GetProblemList struct {
|
type GetProblemList struct {
|
||||||
page
|
page
|
||||||
Keyword string `json:"keyword" form:"keyword"` // 问题关键字
|
Keyword string `json:"keyword" form:"keyword"` // 问题关键字
|
||||||
|
CategoryIdentity string `json:"category_identity" form:"category_identity"` // 问题分类标识
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,10 @@ func (problemService) GetList(p param.GetProblemList) (records entity.Problem, c
|
|||||||
if p.Keyword != "" {
|
if p.Keyword != "" {
|
||||||
sel.Where("title LIKE ? OR content like ?", "%"+p.Keyword+"%", "%"+p.Keyword+"%")
|
sel.Where("title LIKE ? OR content like ?", "%"+p.Keyword+"%", "%"+p.Keyword+"%")
|
||||||
}
|
}
|
||||||
|
if p.CategoryIdentity != "" {
|
||||||
|
sel.Joins("RIGHT JOINN problem_category pc on pc.problem_id = problem.id").
|
||||||
|
Where("pc.category_id= (SELECT cb.id FROM category cb WHERE cb.identity = ?)", p.CategoryIdentity)
|
||||||
|
}
|
||||||
|
|
||||||
err = sel.Order("updated_at DESC").Find(&records).Offset(-1).Limit(-1).Count(&count).Error
|
err = sel.Order("updated_at DESC").Find(&records).Offset(-1).Limit(-1).Count(&count).Error
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user