Skip to content

Commit

Permalink
Merge pull request #438 from go-admin-team/1.3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
wenjianzhang authored May 31, 2021
2 parents fda4a94 + fb42953 commit 974d5b2
Show file tree
Hide file tree
Showing 18 changed files with 59 additions and 58 deletions.
2 changes: 1 addition & 1 deletion app/admin/apis/sys_job/sys_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (e SysJob) RemoveJobForService(c *gin.Context) {
return
}
var v dto.GeneralDelDto
err = c.Bind(&v)
err = c.BindUri(&v)
if err != nil {
log.Warnf("参数验证错误, error: %s", err)
e.Error(http.StatusUnprocessableEntity, err, "参数验证失败")
Expand Down
10 changes: 7 additions & 3 deletions app/admin/service/sys_china_area_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package service

import (
"errors"
common "go-admin/common/models"

"gorm.io/gorm"

Expand Down Expand Up @@ -71,10 +72,13 @@ func (e *SysChinaAreaData) InsertSysChinaAreaData(model *models.SysChinaAreaData

// UpdateSysChinaAreaData 修改SysChinaAreaData对象
func (e *SysChinaAreaData) UpdateSysChinaAreaData(c *models.SysChinaAreaData, p *actions.DataPermission) error {
db := e.Orm.Model(c).
db := e.Orm.Model(&models.SysChinaAreaData{
Model: common.Model{
Id: c.GetId().(int),
}}).
Scopes(
actions.Permission(c.TableName(), p),
).Where(c.GetId()).Updates(c)
).Updates(c)
if err := db.Error; err != nil {
e.Log.Errorf("Service UpdateSysChinaAreaData error: %s", err)
return err
Expand Down Expand Up @@ -103,4 +107,4 @@ func (e *SysChinaAreaData) RemoveSysChinaAreaData(d *dto.SysChinaAreaDataById, p
return errors.New("无权删除该数据")
}
return nil
}
}
11 changes: 6 additions & 5 deletions app/admin/service/sys_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"go-admin/app/admin/models/system"
"go-admin/app/admin/service/dto"
cDto "go-admin/common/dto"
common "go-admin/common/models"
"go-admin/common/service"
"gorm.io/gorm"
)
Expand Down Expand Up @@ -84,8 +85,9 @@ func (e *SysConfig) InsertSysConfig(model *system.SysConfig) error {
func (e *SysConfig) UpdateSysConfig(c *system.SysConfig) error {
var err error

db := e.Orm.Model(c).
Where(c.GetId()).Updates(c)
db := e.Orm.Model(&system.SysConfig{Model: common.Model{
Id: c.GetId().(int),
}}).Updates(c)
err = db.Error
if err != nil {
e.Log.Errorf("Service UpdateSysConfig error:%s", err)
Expand All @@ -103,8 +105,7 @@ func (e *SysConfig) RemoveSysConfig(d *dto.SysConfigById, c *system.SysConfig) e
var err error
var data system.SysConfig

db := e.Orm.Model(&data).
Where(d.Ids).Delete(c)
db := e.Orm.Model(&data).Delete(c, d.Ids)
if db.Error != nil {
err = db.Error
e.Log.Errorf("Service RemoveSysConfig error:%s", err)
Expand All @@ -129,4 +130,4 @@ func (e *SysConfig) GetSysConfigByKEY(c *dto.SysConfigControl) error {
}

return nil
}
}
13 changes: 4 additions & 9 deletions app/admin/service/sys_dept.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
log "github.com/go-admin-team/go-admin-core/logger"
"github.com/go-admin-team/go-admin-core/sdk/pkg"

"gorm.io/gorm"

"go-admin/app/admin/models/system"
Expand Down Expand Up @@ -85,9 +84,9 @@ func (e *SysDept) InsertSysDept(model *system.SysDept) error {
// UpdateSysDept 修改SysDept对象
func (e *SysDept) UpdateSysDept(c *system.SysDept) error {
var err error
var data system.SysDept

db := e.Orm.Model(&data).
db := e.Orm.Model(&system.SysDept{
DeptId: c.GetId().(int),
}).
Where(c.GetId()).Updates(c)
if db.Error != nil {
e.Log.Errorf("db error:%s", err)
Expand All @@ -97,9 +96,6 @@ func (e *SysDept) UpdateSysDept(c *system.SysDept) error {
return errors.New("无权更新该数据")
}

//参数1:是要修改的数据
//参数2:是修改的数据

return nil
}

Expand All @@ -108,8 +104,7 @@ func (e *SysDept) RemoveSysDept(d *dto.SysDeptById) error {
var err error
var data system.SysDept

db := e.Orm.Model(&data).
Where(d.GetId()).Delete(&data)
db := e.Orm.Model(&data).Delete(&data, d.GetId())
if db.Error != nil {
err = db.Error
e.Log.Errorf("Delete error: %s", err)
Expand Down
10 changes: 4 additions & 6 deletions app/admin/service/sys_dict_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,9 @@ func (e *SysDictData) Insert(model *system.SysDictData) error {
// Update 修改对象
func (e *SysDictData) Update(c *system.SysDictData) error {
var err error
var data system.SysDictData

db := e.Orm.Model(&data).
Where(c.GetId()).Updates(c)
db := e.Orm.Model(&system.SysDictData{
DictCode: c.GetId().(int),
}).Updates(c)
if db.Error != nil {
e.Log.Errorf("db error: %s", err)
return err
Expand All @@ -91,8 +90,7 @@ func (e *SysDictData) Remove(d *dto.SysDictDataById, c *system.SysDictData) erro
var err error
var data system.SysDictData

db := e.Orm.Model(&data).
Where(d.GetId()).Delete(c)
db := e.Orm.Model(&data).Delete(c, d.GetId())
if db.Error != nil {
err = db.Error
e.Log.Errorf("Delete error: %s", err)
Expand Down
10 changes: 4 additions & 6 deletions app/admin/service/sys_dict_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,9 @@ func (e *SysDictType) Insert(model *system.SysDictType) error {
// Update 修改对象
func (e *SysDictType) Update(c *system.SysDictType) error {
var err error
var data system.SysDictType

db := e.Orm.Model(&data).
Where(c.GetId()).Updates(c)
db := e.Orm.Model(&system.SysDictType{
ID: c.GetId().(int),
}).Updates(c)
if db.Error != nil {
e.Log.Errorf("db error: %s", err)
return err
Expand All @@ -91,8 +90,7 @@ func (e *SysDictType) Remove(d *dto.SysDictTypeById, c *system.SysDictType) erro
var err error
var data system.SysDictType

db := e.Orm.Model(&data).
Where(d.GetId()).Delete(c)
db := e.Orm.Model(&data).Delete(c, d.GetId())
if db.Error != nil {
err = db.Error
e.Log.Errorf("Delete error: %s", err)
Expand Down
7 changes: 4 additions & 3 deletions app/admin/service/sys_file_dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package service
import (
"errors"
"fmt"
"go-admin/app/admin/models/system"

"gorm.io/gorm"

Expand Down Expand Up @@ -91,10 +92,10 @@ func (e *SysFileDir) UpdateSysFileDir(c *dto.SysFileDirControl, p *actions.DataP
var err error
data, _ := c.GenerateM()

db := e.Orm.
db := e.Orm.Model(&system.SysRole{RoleId: c.GetId().(int)}).
Scopes(
actions.Permission(data.TableName(), p),
).Where(c.ID).Updates(data)
).Updates(data)
if db.Error != nil {
e.Log.Errorf("db error: %s", err)
return err
Expand All @@ -113,7 +114,7 @@ func (e *SysFileDir) RemoveSysFileDir(d *dto.SysFileDirById, p *actions.DataPerm
db := e.Orm.Model(&data).
Scopes(
actions.Permission(data.TableName(), p),
).Where(d.Id).Delete(&data)
).Delete(&data, d.Id)
if db.Error != nil {
err = db.Error
e.Log.Errorf("Delete error: %s", err)
Expand Down
9 changes: 6 additions & 3 deletions app/admin/service/sys_file_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package service

import (
"errors"
common "go-admin/common/models"

"gorm.io/gorm"

Expand Down Expand Up @@ -89,10 +90,12 @@ func (e *SysFileInfo) UpdateSysFileInfo(c *dto.SysFileInfoControl, p *actions.Da
e.Log.Errorf("db error: %s", err)
return err
}
err = e.Orm.Debug().Model(&data).
err = e.Orm.Debug().Model(&models.SysFileInfo{Model: common.Model{
Id: c.ID,
}}).
Scopes(
actions.Permission(data.TableName(), p),
).Where("id = ?", c.ID).Updates(&data).Error
).Updates(&data).Error
if err != nil {
e.Log.Errorf("db error: %s", err)
return err
Expand All @@ -112,7 +115,7 @@ func (e *SysFileInfo) RemoveSysFileInfo(d *dto.SysFileInfoById, p *actions.DataP
db := e.Orm.Model(&data).
Scopes(
actions.Permission(data.TableName(), p),
).Where(d.GetId()).Delete(&data)
).Delete(&data, d.GetId())
if db.Error != nil {
err = db.Error
e.Log.Errorf("Delete error: %s", err)
Expand Down
3 changes: 1 addition & 2 deletions app/admin/service/sys_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ type SysJob struct {
func (e *SysJob) RemoveJob(c *dto.GeneralDelDto) error {
var err error
var data models.SysJob
data.JobId = c.Id
err = e.Orm.Table(data.TableName()).First(&data).Error
err = e.Orm.Table(data.TableName()).First(&data, c.Id).Error
if err != nil {
e.Log.Errorf("db error: %s", err)
return err
Expand Down
5 changes: 2 additions & 3 deletions app/admin/service/sys_login_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (e *SysLoginLog) UpdateSysLoginLog(c common.ActiveRecord) error {
var data system.SysLoginLog

db := e.Orm.Model(&data).
Where(c.GetId()).Updates(c)
Where("id = ?", c.GetId()).Updates(c)
if db.Error != nil {
e.Log.Errorf("db error:%s", err)
return err
Expand All @@ -92,8 +92,7 @@ func (e *SysLoginLog) RemoveSysLoginLog(d *dto.SysLoginLogById, c common.ActiveR
var err error
var data system.SysLoginLog

db := e.Orm.Model(&data).
Where(d.Ids).Delete(c)
db := e.Orm.Model(&data).Delete(c, d.Ids)
if db.Error != nil {
err = db.Error
e.Log.Errorf("Delete error: %s", err)
Expand Down
5 changes: 2 additions & 3 deletions app/admin/service/sys_menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (e *SysMenu) UpdateSysMenu(c *system.SysMenu) error {
var data system.SysMenu

db := e.Orm.Model(&data).
Where(c.GetId()).Updates(c)
Where("menu_id = ?", c.GetId()).Updates(c)
if db.Error != nil {
e.Log.Errorf("db error:%s", err)
return err
Expand All @@ -124,8 +124,7 @@ func (e *SysMenu) RemoveSysMenu(d *dto.SysMenuById) error {
var err error
var data system.SysMenu

db := e.Orm.Model(&data).
Where(d.GetId()).Delete(&data)
db := e.Orm.Model(&data).Delete(&data, d.GetId())
if db.Error != nil {
err = db.Error
e.Log.Errorf("Delete error: %s", err)
Expand Down
10 changes: 6 additions & 4 deletions app/admin/service/sys_opera_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"go-admin/app/admin/models/system"
"go-admin/app/admin/service/dto"
cDto "go-admin/common/dto"
common "go-admin/common/models"
"go-admin/common/service"
"gorm.io/gorm"
)
Expand Down Expand Up @@ -68,8 +69,9 @@ func (e *SysOperaLog) InsertSysOperaLog(model *system.SysOperaLog) error {
func (e *SysOperaLog) UpdateSysOperaLog(c *system.SysOperaLog) error {
var err error

db := e.Orm.Model(c).
Where(c.GetId()).Updates(c)
db := e.Orm.Model(&system.SysOperaLog{Model: common.Model{
Id: c.GetId().(int),
}}).Updates(c)
if err = db.Error; err != nil {
e.Log.Errorf("Service UpdateSysOperaLog error:%s", err.Error())
return err
Expand All @@ -86,7 +88,7 @@ func (e *SysOperaLog) RemoveSysOperaLog(d *dto.SysOperaLogById) error {
var err error
var data system.SysOperaLog

db := e.Orm.Model(&data).Where(d.Ids).Delete(&data)
db := e.Orm.Model(&data).Delete(&data, d.Ids)
if err = db.Error; err != nil {
e.Log.Errorf("Service RemoveSysOperaLog error:%s", err.Error())
return err
Expand All @@ -95,4 +97,4 @@ func (e *SysOperaLog) RemoveSysOperaLog(d *dto.SysOperaLogById) error {
return errors.New("无权删除该数据")
}
return nil
}
}
2 changes: 1 addition & 1 deletion app/admin/service/sys_post.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (e *SysPost) UpdateSysPost(c *system.SysPost) error {
var data system.SysPost

db := e.Orm.Model(&data).
Where(c.GetId()).Updates(c)
Where("post_id = ?", c.GetId()).Updates(c)
if db.Error != nil {
e.Log.Errorf("db error:%s", err)
return err
Expand Down
4 changes: 2 additions & 2 deletions app/admin/service/sys_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (e *SysRole) UpdateSysRole(c *system.SysRole) error {
}
}()
db := tx.Model(&c).
Where(c.GetId()).Updates(c)
Where(" role_id = ?", c.GetId()).Updates(c)
if db.Error != nil {
e.Log.Errorf("db error:%s", err)
return err
Expand Down Expand Up @@ -221,4 +221,4 @@ func (e *SysRole) UpdateDataScope(c *system.SysRole) (err error) {
}
}
return err
}
}
8 changes: 4 additions & 4 deletions app/admin/service/sys_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (e *SysUser) UpdateSysUser(c common.ActiveRecord, p *actions.DataPermission
db := e.Orm.Model(c).
Scopes(
actions.Permission(c.TableName(), p),
).Where(c.GetId()).Updates(c)
).Where("user_id = ?", c.GetId()).Updates(c)
if db.Error != nil {
e.Log.Errorf("db error: %s", err)
return err
Expand All @@ -103,7 +103,7 @@ func (e *SysUser) RemoveSysUser(d cDto.Control, c common.ActiveRecord, p *action
db := e.Orm.Model(&data).
Scopes(
actions.Permission(data.TableName(), p),
).Where(d.GetId()).Delete(c)
).Delete(c, d.GetId())
if db.Error != nil {
err = db.Error
e.Log.Errorf("Delete error: %s", err)
Expand All @@ -128,7 +128,7 @@ func (e *SysUser) UpdateSysUserPwd(id int, oldPassword, newPassword string, p *a
err = e.Orm.Model(c).
Scopes(
actions.Permission(c.TableName(), p),
).Where(id).Select("UserId", "Password", "Salt").First(c).Error
).Where("user_id = ?", id).Select("UserId", "Password", "Salt").First(c).Error
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return errors.New("无权更新该数据")
Expand All @@ -148,7 +148,7 @@ func (e *SysUser) UpdateSysUserPwd(id int, oldPassword, newPassword string, p *a
return err
}
c.Password = newPassword
db := e.Orm.Model(c).Where(id).Select("Password", "Salt").Updates(c)
db := e.Orm.Model(c).Where("user_id = ?", id).Select("Password", "Salt").Updates(c)
if err = db.Error; err != nil {
e.Log.Errorf("db error: %s", err)
return err
Expand Down
3 changes: 3 additions & 0 deletions cmd/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ func setup() {
log.Fatalf("queue setup error, %s\n", err.Error())
}
sdk.Runtime.SetQueueAdapter(queueAdapter)
defer func() {
go queueAdapter.Run()
}()
}

//7. 设置分布式锁
Expand Down
2 changes: 1 addition & 1 deletion common/global/adm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package global

const (
// Version go-admin Version Info
Version = "1.3.8"
Version = "1.3.9"
)

var (
Expand Down
Loading

0 comments on commit 974d5b2

Please sign in to comment.