修改createBy和updateBy为uint类型
This commit is contained in:
1 parent
0ae41f247c
commit
41b06c806a
7 files changed
+25
-9
No files matched your search
@@ -31,7 +31,7 @@ func CreateAction(control dto.Control) gin.HandlerFunc {
|
|||||||
var object model.ActiveRecord
|
var object model.ActiveRecord
|
||||||
object, err = req.GenerateM()
|
object, err = req.GenerateM()
|
||||||
tools.HasError(err, "模型生成失败", 422)
|
tools.HasError(err, "模型生成失败", 422)
|
||||||
object.SetCreateBy(tools.GetUserIdStr(c))
|
object.SetCreateBy(tools.GetUserIdUint(c))
|
||||||
err = db.WithContext(c).Create(object).Error
|
err = db.WithContext(c).Create(object).Error
|
||||||
tools.HasError(err, "创建失败", 500)
|
tools.HasError(err, "创建失败", 500)
|
||||||
app.OK(c, object.GetId(), "创建成功")
|
app.OK(c, object.GetId(), "创建成功")
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ func DeleteAction(control dto.Control) gin.HandlerFunc {
|
|||||||
object, err = req.GenerateM()
|
object, err = req.GenerateM()
|
||||||
tools.HasError(err, "模型生成失败", 500)
|
tools.HasError(err, "模型生成失败", 500)
|
||||||
|
|
||||||
object.SetUpdateBy(tools.GetUserIdStr(c))
|
object.SetUpdateBy(tools.GetUserIdUint(c))
|
||||||
|
|
||||||
//数据权限检查
|
//数据权限检查
|
||||||
p := getPermissionFromContext(c)
|
p := getPermissionFromContext(c)
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ func UpdateAction(control dto.Control) gin.HandlerFunc {
|
|||||||
var object model.ActiveRecord
|
var object model.ActiveRecord
|
||||||
object, err = req.GenerateM()
|
object, err = req.GenerateM()
|
||||||
tools.HasError(err, "参数验证失败", 422)
|
tools.HasError(err, "参数验证失败", 422)
|
||||||
object.SetUpdateBy(tools.GetUserIdStr(c))
|
object.SetUpdateBy(tools.GetUserIdUint(c))
|
||||||
|
|
||||||
//数据权限检查
|
//数据权限检查
|
||||||
p := getPermissionFromContext(c)
|
p := getPermissionFromContext(c)
|
||||||
|
|||||||
+5
-4
@@ -4,6 +4,7 @@ import (
|
|||||||
orm "go-admin/global"
|
orm "go-admin/global"
|
||||||
"go-admin/tools"
|
"go-admin/tools"
|
||||||
"go-admin/tools/model"
|
"go-admin/tools/model"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SysJob struct {
|
type SysJob struct {
|
||||||
@@ -37,12 +38,12 @@ func (e *SysJob) GetId() interface{} {
|
|||||||
return e.JobId
|
return e.JobId
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *SysJob) SetCreateBy(createBy string) {
|
func (e *SysJob) SetCreateBy(createBy uint) {
|
||||||
e.CreateBy = createBy
|
e.CreateBy = strconv.Itoa(int(createBy))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *SysJob) SetUpdateBy(updateBy string) {
|
func (e *SysJob) SetUpdateBy(updateBy uint) {
|
||||||
e.UpdateBy = updateBy
|
e.UpdateBy = strconv.Itoa(int(updateBy))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建SysJob
|
// 创建SysJob
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
type ByModel struct {
|
||||||
|
CreateBy uint `gorm:"index;"` // 创建者
|
||||||
|
UpdateBy uint `gorm:"index;"` // 更新者
|
||||||
|
}
|
||||||
+2
-2
@@ -4,8 +4,8 @@ import "gorm.io/gorm/schema"
|
|||||||
|
|
||||||
type ActiveRecord interface {
|
type ActiveRecord interface {
|
||||||
schema.Tabler
|
schema.Tabler
|
||||||
SetCreateBy(createBy string)
|
SetCreateBy(createBy uint)
|
||||||
SetUpdateBy(updateBy string)
|
SetUpdateBy(updateBy uint)
|
||||||
Generate() ActiveRecord
|
Generate() ActiveRecord
|
||||||
GetId() interface{}
|
GetId() interface{}
|
||||||
}
|
}
|
||||||
@@ -17,6 +17,15 @@ func ExtractClaims(c *gin.Context) jwt.MapClaims {
|
|||||||
return claims.(jwt.MapClaims)
|
return claims.(jwt.MapClaims)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetUserIdUint(c *gin.Context) uint {
|
||||||
|
data := ExtractClaims(c)
|
||||||
|
if data["identity"] != nil {
|
||||||
|
return uint((data["identity"]).(float64))
|
||||||
|
}
|
||||||
|
fmt.Println(GetCurrentTimeStr() + " [WARING] " + c.Request.Method + " " + c.Request.URL.Path + " GetUserId 缺少identity")
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
func GetUserId(c *gin.Context) int {
|
func GetUserId(c *gin.Context) int {
|
||||||
data := ExtractClaims(c)
|
data := ExtractClaims(c)
|
||||||
if data["identity"] != nil {
|
if data["identity"] != nil {
|
||||||
|
|||||||
Reference in new issue
Block a user