fix: add role limit

This commit is contained in:
fallen-angle
2022-04-27 22:08:02 +08:00
parent fc347a4140
commit 22cb5ec61f
19 changed files with 274 additions and 77 deletions

View File

@@ -8,9 +8,9 @@ import (
type BackArticle struct {
ID int `gorm:"primaryKey;column:id" json:"-"` // 文章id
CreateTime time.Time `gorm:"column:create_time" json:"createTime"` // 文章新建时间
CreateUser string `gorm:"column:create_user" json:"createUser"` // 文章创建者id
CreateUser int `gorm:"column:create_user" json:"createUser"` // 文章创建者id
ModifyTime time.Time `gorm:"column:modify_time" json:"modifyTime"` // 文章最后更新时间
ModifyUser string `gorm:"column:modify_user" json:"modifyUser"` // 文章最后更新者id
ModifyUser int `gorm:"column:modify_user" json:"modifyUser"` // 文章最后更新者id
Title string `gorm:"column:title" json:"title"` // 文章标题
Tags string `gorm:"column:tags" json:"tags"` // 文章Tag
Resume string `gorm:"column:resume" json:"resume"` // 文章简述
@@ -20,6 +20,17 @@ type BackArticle struct {
IsDelete int8 `gorm:"column:is_delete" json:"isDelete"` // 删除标志
}
type ListArtile struct {
ID int `json:"-"`
Username string `json:"username"`
CreateTime time.Time `json:"createTime"`
ModifyTime time.Time `json:"modifyTime"`
Title string `json:"title"`
Tags string `json:"tags"`
Resume string `json:"resume"`
Cover string `json:"cover"`
}
func init() {
initJcMap[BackArticle]()
}

View File

@@ -41,3 +41,23 @@ type HotelContactRequest struct {
InData FakerDate `json:"in_data"`
OutData FakerDate `json:"out_data"`
}
type RailwayContactRequest struct {
Name string `json:"name"`
Age int `json:"age,string"`
Sex int `json:"sex,string"`
Phone int `json:"phone"`
Address string `json:"address"`
Train string `json:"train"`
Launch FakerDate `json:"launch"`
Identification string `json:"identification"`
}
type PatientRequest struct {
Name string `json:"name"`
Age int `json:"age,string"`
Sex int `json:"sex,string"`
Phone string `json:"phone"`
Address string `json:"address"`
Identification string `json:"identification"`
}

View File

@@ -3,7 +3,7 @@ package models
import "time"
type BackUser struct {
ID int `gorm:"primaryKey;column:id" json:"-"` // 用户ID
ID int `gorm:"primaryKey;column:id" json:"id"` // 用户ID
Username string `gorm:"column:username" json:"username"` // 用户真实姓名
Password string `gorm:"column:password" json:"password"` // 用户密码
Role int `gorm:"column:role" json:"role"` // 用户角色
@@ -14,6 +14,7 @@ type BackUser struct {
Approver int `gorm:"column:approver" json:"approver"` // 注册审核人ID
ModifyTime time.Time `gorm:"column:modify_time" json:"modifyTime"`
IsDelete int8 `gorm:"column:is_delete" json:"isDelete"` // 删除标志
Region string `gorm:"column:region" json:"region"` // 用户所属地域
}
type UserLogin struct {
@@ -27,6 +28,8 @@ type UserRegister struct {
Email string `json:"email"`
Phone string `json:"phone"`
Aptitude string `json:"aptitude"`
Region string `json:"region"`
Role int `json:"role"`
}
type UserChangePwd struct {
@@ -40,6 +43,14 @@ type UserApprove struct {
Pass bool `json:"pass"`
}
type TokenClaims struct {
ID int `json:"id"`
Username string `json:"username"`
Email string `json:"email"`
Role int `json:"role"`
Region string `json:"region"`
}
func init() {
initJcMap[BackUser]()
}

View File

@@ -93,6 +93,24 @@ func Upsert[T any](colMap map[string]interface{}) (ok bool, rowsAffected int64)
return true, tx.RowsAffected
}
func Update[T any](queryMap []map[string]interface{}, updateMap map[string]interface{}) (ok bool, rowsAffected int64) {
tx := global.Db.Model(new(T))
for _, e := range queryMap {
e[IS_DELETE] = 0
tx = tx.Or(e)
}
return UpdateByOrm(tx, updateMap)
}
func UpdateByOrm(tx *gorm.DB, updateMap map[string]interface{}) (ok bool, rowsAffected int64) {
tx.Updates(updateMap)
if tx.Error != nil {
fmt.Println(tx.Error)
return false, 0
}
return true, tx.RowsAffected
}
// DeleteById will delete by id, not delete the record from database, only set the field "is_delete" as 1
func DeleteById[T any](id int) (ok bool, rowsAffected int64) {
tx := global.Db.Model(new(T)).Where("id = ?", id).Update("is_delete", 1)