Merge pull request #80 from wenjianzhang/v1.0.0-fixbug
V1.0.0 fixbug Control role_name and tole_key cannot be duplicate Add key only control Add count where condition 'deleted' at 'is null
This commit is contained in:
13 files changed
+86
-36
No files matched your search
@@ -101,6 +101,7 @@ func UpdateRole(c *gin.Context) {
|
||||
err := c.Bind(&data)
|
||||
tools.HasError(err, "数据解析失败", -1)
|
||||
result, err := data.Update(data.RoleId)
|
||||
tools.HasError(err, "", -1)
|
||||
var t models.RoleMenu
|
||||
_, err = t.DeleteRoleMenu(data.RoleId)
|
||||
tools.HasError(err, "添加失败1", -1)
|
||||
|
||||
@@ -348,19 +348,6 @@ INSERT INTO `sys_menu` VALUES (120, NULL, '通过id获取岗位信息', 'bug', '
|
||||
INSERT INTO `sys_menu` VALUES (121, NULL, '创建岗位', 'bug', '/api/v1/post', '/0/63/204/121', 'A', 'POST', NULL, 204, NULL, NULL, NULL, 0, '1', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL);
|
||||
INSERT INTO `sys_menu` VALUES (122, NULL, '修改岗位', 'bug', '/api/v1/post', '/0/63/204/122', 'A', 'PUT', NULL, 204, NULL, NULL, NULL, 0, '1', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL);
|
||||
INSERT INTO `sys_menu` VALUES (123, NULL, '删除岗位', 'bug', '/api/v1/post/:id', '/0/63/204/123', 'A', 'DELETE', NULL, 204, NULL, NULL, NULL, 0, '1', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL);
|
||||
INSERT INTO `sys_menu` VALUES (124, NULL, '获取排班信息', 'bug', '/api/v1/calendar', '/0/63/210/124', 'A', 'GET', NULL, 210, NULL, NULL, NULL, 0, '1', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL);
|
||||
INSERT INTO `sys_menu` VALUES (125, NULL, '创建排班', 'bug', '/api/v1/calendar', '/0/63/210/125', 'A', 'POST', NULL, 210, NULL, NULL, NULL, 0, '1', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL);
|
||||
INSERT INTO `sys_menu` VALUES (126, NULL, '修改排班', 'bug', '/api/v1/calendar/:id', '/0/63/210/126', 'A', 'PUT', NULL, 210, NULL, NULL, NULL, 0, '1', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL);
|
||||
INSERT INTO `sys_menu` VALUES (127, NULL, '删除排班', 'bug', '/api/v1/calendar/:id', '/0/63/210/127', 'A', 'DELETE', NULL, 210, NULL, NULL, NULL, 0, '1', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL);
|
||||
INSERT INTO `sys_menu` VALUES (128, NULL, '获取会员', 'bug', '/api/v1/member', '/0/63/207/128', 'A', 'GET', NULL, 207, NULL, NULL, NULL, 0, '1', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL);
|
||||
INSERT INTO `sys_menu` VALUES (129, NULL, '创建会员', 'bug', '/api/v1/member', '/0/63/207/129', 'A', 'POST', NULL, 207, NULL, NULL, NULL, 0, '1', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL);
|
||||
INSERT INTO `sys_menu` VALUES (130, NULL, '修改会员', 'bug', '/api/v1/member/:id', '/0/63/207/130', 'A', 'PUT', NULL, 207, NULL, NULL, NULL, 0, '1', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL);
|
||||
INSERT INTO `sys_menu` VALUES (131, NULL, '删除会员', 'bug', '/api/v1/member/:id', '/0/63/207/131', 'A', 'DELETE', NULL, 207, NULL, NULL, NULL, 0, '1', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL);
|
||||
INSERT INTO `sys_menu` VALUES (132, NULL, '获取订单', 'bug', '/api/v1/orders', '/0/63/209/132', 'A', 'GET', NULL, 209, NULL, NULL, NULL, 0, '1', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL);
|
||||
INSERT INTO `sys_menu` VALUES (133, NULL, '通过id获取订单', 'bug', '/api/v1/orders/:id', '/0/63/209/133', 'A', 'GET', NULL, 209, NULL, NULL, NULL, 0, '1', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL);
|
||||
INSERT INTO `sys_menu` VALUES (134, NULL, '新建订单', 'bug', '/api/v1/orders', '/0/63/209/134', 'A', 'POST', NULL, 209, NULL, NULL, NULL, 0, '1', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL);
|
||||
INSERT INTO `sys_menu` VALUES (135, NULL, '修改订单', 'bug', '/api/v1/orders/:id', '/0/63/209/135', 'A', 'PUT', NULL, 209, NULL, NULL, NULL, 0, '1', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL);
|
||||
INSERT INTO `sys_menu` VALUES (136, NULL, '删除订单', 'bug', '/api/v1/orders/:id', '/0/63/209/136', 'A', 'DELETE', NULL, 209, NULL, NULL, NULL, 0, '1', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL);
|
||||
INSERT INTO `sys_menu` VALUES (137, NULL, '菜单列表', 'bug', '/api/v1/menulist', '/0/63/66/137', 'A', 'GET', NULL, 66, NULL, NULL, NULL, 0, '1', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL);
|
||||
INSERT INTO `sys_menu` VALUES (138, NULL, '获取根据id菜单信息', 'bug', '/api/v1/menu/:id', '/0/63/66/138', 'A', 'GET', NULL, 66, NULL, NULL, NULL, 0, '1', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL);
|
||||
INSERT INTO `sys_menu` VALUES (139, NULL, '创建菜单', 'bug', '/api/v1/menu', '/0/63/66/139', 'A', 'POST', NULL, 66, NULL, NULL, NULL, 0, '1', '1', '1', 0, '2020-04-11 15:52:48', NULL, NULL);
|
||||
|
||||
@@ -23,6 +23,7 @@ require (
|
||||
github.com/mitchellh/go-homedir v1.1.0
|
||||
github.com/mojocn/base64Captcha v1.3.1
|
||||
github.com/mssola/user_agent v0.5.1
|
||||
github.com/pkg/errors v0.8.1
|
||||
github.com/robfig/cron/v3 v3.0.0
|
||||
github.com/satori/go.uuid v1.2.0
|
||||
github.com/shirou/gopsutil v2.20.3+incompatible
|
||||
|
||||
+16
-1
@@ -1,6 +1,7 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
orm "go-admin/database"
|
||||
"go-admin/tools"
|
||||
_ "time"
|
||||
@@ -27,6 +28,12 @@ func (SysConfig) TableName() string {
|
||||
// Config 创建
|
||||
func (e *SysConfig) Create() (SysConfig, error) {
|
||||
var doc SysConfig
|
||||
i := 0
|
||||
orm.Eloquent.Table(e.TableName()).Where("config_name=? or config_key = ?", e.ConfigName, e.ConfigKey).Count(&i)
|
||||
if i > 0 {
|
||||
return doc, errors.New("参数名称或者参数键名已经存在!")
|
||||
}
|
||||
|
||||
result := orm.Eloquent.Table(e.TableName()).Create(&e)
|
||||
if result.Error != nil {
|
||||
err := result.Error
|
||||
@@ -80,7 +87,7 @@ func (e *SysConfig) GetPage(pageSize int, pageIndex int) ([]SysConfig, int, erro
|
||||
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
table.Count(&count)
|
||||
table.Where("`deleted_at` IS NULL").Count(&count)
|
||||
return doc, count, nil
|
||||
}
|
||||
|
||||
@@ -89,6 +96,14 @@ func (e *SysConfig) Update(id int) (update SysConfig, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
if e.ConfigName != "" && e.ConfigName != update.ConfigName {
|
||||
return update, errors.New("参数名称不允许修改!")
|
||||
}
|
||||
|
||||
if e.ConfigKey != "" && e.ConfigKey != update.ConfigKey {
|
||||
return update, errors.New("参数键名不允许修改!")
|
||||
}
|
||||
|
||||
//参数1:是要修改的数据
|
||||
//参数2:是修改的数据
|
||||
if err = orm.Eloquent.Table(e.TableName()).Model(&update).Updates(&e).Error; err != nil {
|
||||
|
||||
+17
-1
@@ -1,6 +1,7 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
orm "go-admin/database"
|
||||
"go-admin/tools"
|
||||
)
|
||||
@@ -30,6 +31,13 @@ func (DictData) TableName() string {
|
||||
|
||||
func (e *DictData) Create() (DictData, error) {
|
||||
var doc DictData
|
||||
|
||||
i := 0
|
||||
orm.Eloquent.Table(e.TableName()).Where("dict_label=? or dict_value = ?", e.DictLabel, e.DictValue).Count(&i)
|
||||
if i > 0 {
|
||||
return doc, errors.New("字典标签或者字典键值已经存在!")
|
||||
}
|
||||
|
||||
result := orm.Eloquent.Table(e.TableName()).Create(&e)
|
||||
if result.Error != nil {
|
||||
err := result.Error
|
||||
@@ -106,7 +114,7 @@ func (e *DictData) GetPage(pageSize int, pageIndex int) ([]DictData, int, error)
|
||||
if err := table.Order("dict_sort").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
table.Count(&count)
|
||||
table.Where("`deleted_at` IS NULL").Count(&count)
|
||||
return doc, count, nil
|
||||
}
|
||||
|
||||
@@ -115,6 +123,14 @@ func (e *DictData) Update(id int) (update DictData, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
if e.DictLabel != "" && e.DictLabel != update.DictLabel {
|
||||
return update, errors.New("标签不允许修改!")
|
||||
}
|
||||
|
||||
if e.DictValue != "" && e.DictValue != update.DictValue {
|
||||
return update, errors.New("键值不允许修改!")
|
||||
}
|
||||
|
||||
//参数1:是要修改的数据
|
||||
//参数2:是修改的数据
|
||||
if err = orm.Eloquent.Table(e.TableName()).Model(&update).Updates(&e).Error; err != nil {
|
||||
|
||||
+17
-1
@@ -1,6 +1,7 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
orm "go-admin/database"
|
||||
"go-admin/tools"
|
||||
)
|
||||
@@ -24,6 +25,13 @@ func (DictType) TableName() string {
|
||||
|
||||
func (e *DictType) Create() (DictType, error) {
|
||||
var doc DictType
|
||||
|
||||
i := 0
|
||||
orm.Eloquent.Table(e.TableName()).Where("dict_name=? or dict_type = ?", e.DictName, e.DictType).Count(&i)
|
||||
if i > 0 {
|
||||
return doc, errors.New("字典名称或者字典类型已经存在!")
|
||||
}
|
||||
|
||||
result := orm.Eloquent.Table(e.TableName()).Create(&e)
|
||||
if result.Error != nil {
|
||||
err := result.Error
|
||||
@@ -94,7 +102,7 @@ func (e *DictType) GetPage(pageSize int, pageIndex int) ([]DictType, int, error)
|
||||
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
table.Count(&count)
|
||||
table.Where("`deleted_at` IS NULL").Count(&count)
|
||||
return doc, count, nil
|
||||
}
|
||||
|
||||
@@ -103,6 +111,14 @@ func (e *DictType) Update(id int) (update DictType, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
if e.DictName != "" && e.DictName != update.DictName {
|
||||
return update, errors.New("名称不允许修改!")
|
||||
}
|
||||
|
||||
if e.DictType != "" && e.DictType != update.DictType {
|
||||
return update, errors.New("类型不允许修改!")
|
||||
}
|
||||
|
||||
//参数1:是要修改的数据
|
||||
//参数2:是修改的数据
|
||||
if err = orm.Eloquent.Table(e.TableName()).Model(&update).Updates(&e).Error; err != nil {
|
||||
|
||||
+1
-1
@@ -64,7 +64,7 @@ func (e *LoginLog) GetPage(pageSize int, pageIndex int) ([]LoginLog, int, error)
|
||||
if err := table.Order("info_id desc").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
table.Count(&count)
|
||||
table.Where("`deleted_at` IS NULL").Count(&count)
|
||||
return doc, count, nil
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -76,7 +76,7 @@ func (e *SysOperLog) GetPage(pageSize int, pageIndex int) ([]SysOperLog, int, er
|
||||
if err := table.Order("oper_id desc").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
table.Count(&count)
|
||||
table.Where("`deleted_at` IS NULL").Count(&count)
|
||||
return doc, count, nil
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -104,7 +104,7 @@ func (e *Post) GetPage(pageSize int, pageIndex int) ([]Post, int, error) {
|
||||
if err := table.Order("sort").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
table.Count(&count)
|
||||
table.Where("`deleted_at` IS NULL").Count(&count)
|
||||
return doc, count, nil
|
||||
}
|
||||
|
||||
|
||||
+28
-14
@@ -1,25 +1,26 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
orm "go-admin/database"
|
||||
"go-admin/tools"
|
||||
)
|
||||
|
||||
type SysRole struct {
|
||||
RoleId int `json:"roleId" gorm:"primary_key;AUTO_INCREMENT"` // 角色编码
|
||||
RoleName string `json:"roleName" gorm:"type:varchar(128);"` // 角色名称
|
||||
Status string `json:"status" gorm:"type:int(1);"` //
|
||||
RoleKey string `json:"roleKey" gorm:"type:varchar(128);"` //角色代码
|
||||
RoleSort int `json:"roleSort" gorm:"type:int(4);"` //角色排序
|
||||
Flag string `json:"flag" gorm:"type:varchar(128);"` //
|
||||
CreateBy string `json:"createBy" gorm:"type:varchar(128);"` //
|
||||
UpdateBy string `json:"updateBy" gorm:"type:varchar(128);"` //
|
||||
Remark string `json:"remark" gorm:"type:varchar(255);"` //备注
|
||||
Admin bool `json:"admin" gorm:"type:char(1);"`
|
||||
RoleId int `json:"roleId" gorm:"primary_key;AUTO_INCREMENT"` // 角色编码
|
||||
RoleName string `json:"roleName" gorm:"type:varchar(128);"` // 角色名称
|
||||
Status string `json:"status" gorm:"type:int(1);"` //
|
||||
RoleKey string `json:"roleKey" gorm:"type:varchar(128);"` //角色代码
|
||||
RoleSort int `json:"roleSort" gorm:"type:int(4);"` //角色排序
|
||||
Flag string `json:"flag" gorm:"type:varchar(128);"` //
|
||||
CreateBy string `json:"createBy" gorm:"type:varchar(128);"` //
|
||||
UpdateBy string `json:"updateBy" gorm:"type:varchar(128);"` //
|
||||
Remark string `json:"remark" gorm:"type:varchar(255);"` //备注
|
||||
Admin bool `json:"admin" gorm:"type:char(1);"`
|
||||
DataScope string `json:"dataScope" gorm:"type:varchar(128);"`
|
||||
Params string `json:"params" gorm:"-"`
|
||||
MenuIds []int `json:"menuIds" gorm:"-"`
|
||||
DeptIds []int `json:"deptIds" gorm:"-"`
|
||||
Params string `json:"params" gorm:"-"`
|
||||
MenuIds []int `json:"menuIds" gorm:"-"`
|
||||
DeptIds []int `json:"deptIds" gorm:"-"`
|
||||
BaseModel
|
||||
}
|
||||
|
||||
@@ -58,7 +59,7 @@ func (e *SysRole) GetPage(pageSize int, pageIndex int) ([]SysRole, int, error) {
|
||||
if err := table.Order("role_sort").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
table.Count(&count)
|
||||
table.Where("`deleted_at` IS NULL").Count(&count)
|
||||
return doc, count, nil
|
||||
}
|
||||
|
||||
@@ -107,6 +108,11 @@ func (role *SysRole) GetRoleMeunId() ([]int, error) {
|
||||
}
|
||||
|
||||
func (role *SysRole) Insert() (id int, err error) {
|
||||
i := 0
|
||||
orm.Eloquent.Table("sys_role").Where("role_name=? or role_key = ?", role.RoleName, role.RoleKey).Count(&i)
|
||||
if i > 0 {
|
||||
return 0, errors.New("角色名称或者角色标识已经存在!")
|
||||
}
|
||||
role.UpdateBy = ""
|
||||
result := orm.Eloquent.Table("sys_role").Create(&role)
|
||||
if result.Error != nil {
|
||||
@@ -141,6 +147,14 @@ func (role *SysRole) Update(id int) (update SysRole, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
if role.RoleName != "" && role.RoleName != update.RoleName {
|
||||
return update, errors.New("角色名称不允许修改!")
|
||||
}
|
||||
|
||||
if role.RoleKey != "" && role.RoleKey != update.RoleKey {
|
||||
return update, errors.New("角色标识不允许修改!")
|
||||
}
|
||||
|
||||
//参数1:是要修改的数据
|
||||
//参数2:是修改的数据
|
||||
if err = orm.Eloquent.Table("sys_role").Model(&update).Updates(&role).Error; err != nil {
|
||||
|
||||
+1
-1
@@ -153,7 +153,7 @@ func (e *SysUser) GetPage(pageSize int, pageIndex int) ([]SysUserPage, int, erro
|
||||
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
table.Count(&count)
|
||||
table.Where("`deleted_at` IS NULL").Count(&count)
|
||||
return doc, count, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ func (e *SysTables) GetPage(pageSize int, pageIndex int) ([]SysTables, int, erro
|
||||
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
table.Count(&count)
|
||||
table.Where("`deleted_at` IS NULL").Count(&count)
|
||||
return doc, count, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ func (e *{{.ClassName}}) GetPage(pageSize int, pageIndex int) ([]{{.ClassName}},
|
||||
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
table.Count(&count)
|
||||
table.Where("`deleted_at` IS NULL").Count(&count)
|
||||
return doc, count, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user