feat:update userinfo
This commit is contained in:
1 parent
cb06f596e9
commit
b98997a69f
11 files changed
+42
-110
No files matched your search
@@ -14,6 +14,7 @@ import (
|
||||
// CreateAction 通用新增动作
|
||||
func CreateAction(m model.ActiveRecord) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
m.SetCreateBy(tools.GetUserIdStr(c))
|
||||
object := m.Generate()
|
||||
var err error
|
||||
idb, exist := c.Get("db")
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
// DeleteAction 通用删除动作
|
||||
func DeleteAction(m model.ActiveRecord) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
m.SetUpdateBy(tools.GetUserIdStr(c))
|
||||
object := m.Generate()
|
||||
var err error
|
||||
idb, exist := c.Get("db")
|
||||
|
||||
@@ -33,8 +33,11 @@ func IndexAction(m model.ActiveRecord, d dto.Dtor) gin.HandlerFunc {
|
||||
tools.HasError(err, "参数验证失败", 422)
|
||||
err = req.Validate()
|
||||
tools.HasError(err, "参数验证失败", 422)
|
||||
p, err := newDataPermission(db, tools.GetUserId(c))
|
||||
tools.HasError(err, "权限范围鉴定错误", 500)
|
||||
var p = new(dataPermission)
|
||||
if userId := tools.GetUserIdStr(c); userId != "" {
|
||||
p, err = newDataPermission(db, userId)
|
||||
tools.HasError(err, "权限范围鉴定错误", 500)
|
||||
}
|
||||
err = db.WithContext(c).Model(object).
|
||||
Scopes(
|
||||
tools.MakeCondition(req.GetNeedSearch()),
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
// UpdateAction 通用更新动作
|
||||
func UpdateAction(m model.ActiveRecord) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
m.SetUpdateBy(tools.GetUserIdStr(c))
|
||||
object := m.Generate()
|
||||
var err error
|
||||
idb, exist := c.Get("db")
|
||||
|
||||
+1
-73
@@ -5,7 +5,6 @@ import (
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"go-admin/dto"
|
||||
"go-admin/jobs"
|
||||
"go-admin/models"
|
||||
"go-admin/tools"
|
||||
@@ -13,83 +12,12 @@ import (
|
||||
"go-admin/tools/app/msg"
|
||||
)
|
||||
|
||||
func GetSysJobList(c *gin.Context) {
|
||||
var data models.SysJob
|
||||
var err error
|
||||
var pageSize = 10
|
||||
var pageIndex = 1
|
||||
|
||||
if size := c.Request.FormValue("pageSize"); size != "" {
|
||||
pageSize, err = tools.StringToInt(size)
|
||||
}
|
||||
if index := c.Request.FormValue("pageIndex"); index != "" {
|
||||
pageIndex, err = tools.StringToInt(index)
|
||||
}
|
||||
|
||||
var v dto.SysJobSearch
|
||||
err = c.Bind(&v)
|
||||
tools.HasError(err, "数据解析失败", 422)
|
||||
|
||||
data.DataScope = tools.GetUserIdStr(c)
|
||||
list := make([]models.SysJob, 0)
|
||||
count, err := data.GetPage(pageSize, pageIndex, v, &list)
|
||||
tools.HasError(err, "", -1)
|
||||
|
||||
app.PageOK(c, list, count, pageIndex, pageSize, "")
|
||||
}
|
||||
|
||||
func GetSysJob(c *gin.Context) {
|
||||
var data models.SysJob
|
||||
var v tools.GeneralGetDto
|
||||
err := c.BindUri(&v)
|
||||
tools.HasError(err, "", 500)
|
||||
data.JobId = v.Id
|
||||
err = data.Get(data.JobId)
|
||||
tools.HasError(err, "抱歉未找到相关信息", -1)
|
||||
|
||||
app.OK(c, data, "")
|
||||
}
|
||||
|
||||
func InsertSysJob(c *gin.Context) {
|
||||
var data models.SysJob
|
||||
err := c.ShouldBindJSON(&data)
|
||||
data.CreateBy = tools.GetUserIdStr(c)
|
||||
tools.HasError(err, "", 500)
|
||||
err = data.Create()
|
||||
tools.HasError(err, "", -1)
|
||||
app.OK(c, data, "")
|
||||
}
|
||||
|
||||
func UpdateSysJob(c *gin.Context) {
|
||||
var data models.SysJob
|
||||
err := c.ShouldBindJSON(&data)
|
||||
tools.HasError(err, "数据解析失败", -1)
|
||||
data.UpdateBy = tools.GetUserIdStr(c)
|
||||
err = data.Update(data.JobId)
|
||||
tools.HasError(err, "", -1)
|
||||
|
||||
app.OK(c, data, "")
|
||||
}
|
||||
|
||||
func DeleteSysJob(c *gin.Context) {
|
||||
var data models.SysJob
|
||||
|
||||
var v tools.GeneralDelDto
|
||||
err := c.BindUri(&v)
|
||||
tools.HasError(err, "", 500)
|
||||
data.UpdateBy = tools.GetUserIdStr(c)
|
||||
IDS := tools.IdsStrToIdsIntGroupStr(v.Id)
|
||||
err = data.BatchDelete(IDS)
|
||||
tools.HasError(err, msg.DeletedFail, 500)
|
||||
app.OK(c, nil, msg.DeletedSuccess)
|
||||
}
|
||||
|
||||
func RemoveJob(c *gin.Context) {
|
||||
var data models.SysJob
|
||||
var v tools.GeneralDelDto
|
||||
err := c.BindUri(&v)
|
||||
tools.HasError(err, "", 500)
|
||||
data.JobId, _ = tools.StringToInt(v.Id)
|
||||
data.JobId = v.Id
|
||||
err = data.Get(data.JobId)
|
||||
tools.HasError(err, "", 500)
|
||||
cn := jobs.Remove(data.EntryId)
|
||||
|
||||
+9
-6
@@ -42,6 +42,14 @@ func (e *SysJob) GetId() interface{} {
|
||||
return e.JobId
|
||||
}
|
||||
|
||||
func (e *SysJob) SetCreateBy(createBy string){
|
||||
e.CreateBy = createBy
|
||||
}
|
||||
|
||||
func (e *SysJob) SetUpdateBy(updateBy string){
|
||||
e.UpdateBy = updateBy
|
||||
}
|
||||
|
||||
// 创建SysJob
|
||||
func (e *SysJob) Create() (err error) {
|
||||
return orm.Eloquent.Table(e.TableName()).Create(e).Error
|
||||
@@ -59,15 +67,10 @@ func (e *SysJob) GetPage(pageSize int, pageIndex int, v interface{}, list interf
|
||||
// 数据权限控制(如果不需要数据权限请将此处去掉)
|
||||
//dataPermission := new(DataPermission)
|
||||
userid, _ := tools.StringToInt(e.DataScope)
|
||||
//dataPermission.UserId = userid
|
||||
//table, err := dataPermission.GetDataScope(e.TableName(), table)
|
||||
//if err != nil {
|
||||
// return 0, err
|
||||
//}
|
||||
|
||||
var count int64
|
||||
|
||||
if err := table.Scopes(DataScopes(e.TableName(),userid),tools.Paginate(pageSize, pageIndex)).Find(list).Offset(-1).Limit(-1).Count(&count).Error; err != nil {
|
||||
if err := table.Scopes(DataScopes(e.TableName(), userid), tools.Paginate(pageSize, pageIndex)).Find(list).Offset(-1).Limit(-1).Count(&count).Error; err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return int(count), nil
|
||||
|
||||
+8
-9
@@ -216,19 +216,18 @@ func (e *SysUser) GetPage(pageSize int, pageIndex int) ([]SysUserPage, int, erro
|
||||
table = table.Where("sys_user.dept_id in (select dept_id from sys_dept where dept_path like ? )", "%"+tools.IntToString(e.DeptId)+"%")
|
||||
}
|
||||
|
||||
userid, _ := tools.StringToInt(e.DataScope)
|
||||
//dataPermission.UserId = userid
|
||||
//table, err := dataPermission.GetDataScope(e.TableName(), table)
|
||||
//if err != nil {
|
||||
// return 0, err
|
||||
//}
|
||||
|
||||
// 数据权限控制(如果不需要数据权限请将此处去掉)
|
||||
dataPermission := new(DataPermission)
|
||||
dataPermission.UserId, _ = tools.StringToInt(e.DataScope)
|
||||
table,err := dataPermission.GetDataScope(e.TableName(), table)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
var count int64
|
||||
|
||||
if err := table.Scopes(DataScopes(e.TableName(), userid)).Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Offset(-1).Limit(-1).Count(&count).Error; err != nil {
|
||||
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Offset(-1).Limit(-1).Count(&count).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
//table.Where("sys_user.deleted_at IS NULL").Count(&count)
|
||||
return doc, int(count), nil
|
||||
}
|
||||
|
||||
|
||||
+3
-11
@@ -82,8 +82,6 @@ func sysNoCheckRoleRouter(r *gin.RouterGroup) {
|
||||
|
||||
registerSysSettingRouter(v1)
|
||||
|
||||
registerSysJobRouter(v1)
|
||||
|
||||
}
|
||||
|
||||
func registerDBRouter(api *gin.RouterGroup) {
|
||||
@@ -109,16 +107,10 @@ func registerSysTableRouter(v1 *gin.RouterGroup) {
|
||||
}
|
||||
}
|
||||
|
||||
func registerSysJobRouter(v1 *gin.RouterGroup) {
|
||||
func registerSysJobRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
|
||||
|
||||
r := v1.Group("/sysjob")
|
||||
r := v1.Group("/sysjob").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
|
||||
{
|
||||
//r.GET("", sysjob.GetSysJobList)
|
||||
//r.GET("/:id", sysjob.GetSysJob)
|
||||
//r.POST("", sysjob.InsertSysJob)
|
||||
//r.PUT("", sysjob.UpdateSysJob)
|
||||
//r.DELETE("/:id", sysjob.DeleteSysJob)
|
||||
|
||||
sysJob := &models.SysJob{}
|
||||
r.GET("", actions.IndexAction(sysJob, new(dto.SysJobSearch)))
|
||||
r.GET("/:id", actions.ViewAction(sysJob))
|
||||
@@ -154,7 +146,7 @@ func sysCheckRoleRouterInit(r *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddle
|
||||
registerMenuRouter(v1, authMiddleware)
|
||||
registerLoginLogRouter(v1, authMiddleware)
|
||||
registerOperLogRouter(v1, authMiddleware)
|
||||
|
||||
registerSysJobRouter(v1, authMiddleware)
|
||||
}
|
||||
|
||||
func registerBaseRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
|
||||
|
||||
@@ -3,7 +3,7 @@ import request from '@/utils/request'
|
||||
// 查询{{.ClassName}}列表
|
||||
export function list{{.ClassName}}(query) {
|
||||
return request({
|
||||
url: '/api/v1/{{.ModuleName}}List',
|
||||
url: '/api/v1/{{.ModuleName}}',
|
||||
method: 'get',
|
||||
params: query
|
||||
})
|
||||
|
||||
+10
-8
@@ -1,7 +1,6 @@
|
||||
package tools
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
"go-admin/tools/config"
|
||||
|
||||
"github.com/matchstalk/go-admin-core/search"
|
||||
@@ -9,26 +8,29 @@ import (
|
||||
)
|
||||
|
||||
type GeneralDelDto struct {
|
||||
Id string `uri:"id" json:"id" validate:"required"`
|
||||
Ids []string `json:"ids"`
|
||||
Id int `uri:"id" json:"id" validate:"required"`
|
||||
Ids []int `json:"ids"`
|
||||
}
|
||||
|
||||
func (g GeneralDelDto) GetIds() []string {
|
||||
ids := make([]string, 0)
|
||||
func (g GeneralDelDto) GetIds() []int {
|
||||
ids := make([]int, 0)
|
||||
if g.Id != 0 {
|
||||
ids = append(ids, g.Id)
|
||||
}
|
||||
if len(g.Ids) > 0 {
|
||||
for _, id := range g.Ids {
|
||||
if len(id) > 0 {
|
||||
if id > 0 {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if len(g.Id) > 0 {
|
||||
if g.Id > 0 {
|
||||
ids = append(ids, g.Id)
|
||||
}
|
||||
}
|
||||
if len(ids) <= 0 {
|
||||
//方式全部删除
|
||||
ids = append(ids, uuid.New().String())
|
||||
ids = append(ids, 0)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import "gorm.io/gorm/schema"
|
||||
|
||||
type ActiveRecord interface {
|
||||
schema.Tabler
|
||||
SetCreateBy(createBy string)
|
||||
SetUpdateBy(updateBy string)
|
||||
Generate() ActiveRecord
|
||||
GetId() interface{}
|
||||
GenerateList() interface{}
|
||||
|
||||
Reference in new issue
Block a user