mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-21 18:20:50 +00:00
feat: update system
This commit is contained in:
+7
-7
@@ -19,7 +19,7 @@ import (
|
|||||||
// @Router /api/v1/deptList [get]
|
// @Router /api/v1/deptList [get]
|
||||||
// @Security
|
// @Security
|
||||||
func GetDeptList(c *gin.Context) {
|
func GetDeptList(c *gin.Context) {
|
||||||
var Dept models.Dept
|
var Dept models.SysDept
|
||||||
Dept.DeptName = c.Request.FormValue("deptName")
|
Dept.DeptName = c.Request.FormValue("deptName")
|
||||||
Dept.Status = c.Request.FormValue("status")
|
Dept.Status = c.Request.FormValue("status")
|
||||||
Dept.DeptId, _ = tools.StringToInt(c.Request.FormValue("deptId"))
|
Dept.DeptId, _ = tools.StringToInt(c.Request.FormValue("deptId"))
|
||||||
@@ -30,7 +30,7 @@ func GetDeptList(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetDeptTree(c *gin.Context) {
|
func GetDeptTree(c *gin.Context) {
|
||||||
var Dept models.Dept
|
var Dept models.SysDept
|
||||||
Dept.DeptName = c.Request.FormValue("deptName")
|
Dept.DeptName = c.Request.FormValue("deptName")
|
||||||
Dept.Status= c.Request.FormValue("status")
|
Dept.Status= c.Request.FormValue("status")
|
||||||
Dept.DeptId, _ = tools.StringToInt(c.Request.FormValue("deptId"))
|
Dept.DeptId, _ = tools.StringToInt(c.Request.FormValue("deptId"))
|
||||||
@@ -48,7 +48,7 @@ func GetDeptTree(c *gin.Context) {
|
|||||||
// @Router /api/v1/dept/{deptId} [get]
|
// @Router /api/v1/dept/{deptId} [get]
|
||||||
// @Security
|
// @Security
|
||||||
func GetDept(c *gin.Context) {
|
func GetDept(c *gin.Context) {
|
||||||
var Dept models.Dept
|
var Dept models.SysDept
|
||||||
Dept.DeptId, _ = tools.StringToInt(c.Param("deptId"))
|
Dept.DeptId, _ = tools.StringToInt(c.Param("deptId"))
|
||||||
Dept.DataScope = tools.GetUserIdStr(c)
|
Dept.DataScope = tools.GetUserIdStr(c)
|
||||||
result, err := Dept.Get()
|
result, err := Dept.Get()
|
||||||
@@ -67,7 +67,7 @@ func GetDept(c *gin.Context) {
|
|||||||
// @Router /api/v1/dept [post]
|
// @Router /api/v1/dept [post]
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
func InsertDept(c *gin.Context) {
|
func InsertDept(c *gin.Context) {
|
||||||
var data models.Dept
|
var data models.SysDept
|
||||||
err := c.BindWith(&data, binding.JSON)
|
err := c.BindWith(&data, binding.JSON)
|
||||||
tools.HasError(err, "", 500)
|
tools.HasError(err, "", 500)
|
||||||
data.CreateBy = tools.GetUserIdStr(c)
|
data.CreateBy = tools.GetUserIdStr(c)
|
||||||
@@ -88,7 +88,7 @@ func InsertDept(c *gin.Context) {
|
|||||||
// @Router /api/v1/dept [put]
|
// @Router /api/v1/dept [put]
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
func UpdateDept(c *gin.Context) {
|
func UpdateDept(c *gin.Context) {
|
||||||
var data models.Dept
|
var data models.SysDept
|
||||||
err := c.BindJSON(&data)
|
err := c.BindJSON(&data)
|
||||||
tools.HasError(err, "", -1)
|
tools.HasError(err, "", -1)
|
||||||
data.UpdateBy = tools.GetUserIdStr(c)
|
data.UpdateBy = tools.GetUserIdStr(c)
|
||||||
@@ -105,7 +105,7 @@ func UpdateDept(c *gin.Context) {
|
|||||||
// @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
|
// @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
|
||||||
// @Router /api/v1/dept/{id} [delete]
|
// @Router /api/v1/dept/{id} [delete]
|
||||||
func DeleteDept(c *gin.Context) {
|
func DeleteDept(c *gin.Context) {
|
||||||
var data models.Dept
|
var data models.SysDept
|
||||||
id, err := tools.StringToInt(c.Param("id"))
|
id, err := tools.StringToInt(c.Param("id"))
|
||||||
_, err = data.Delete(id)
|
_, err = data.Delete(id)
|
||||||
tools.HasError(err, "删除失败", 500)
|
tools.HasError(err, "删除失败", 500)
|
||||||
@@ -113,7 +113,7 @@ func DeleteDept(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetDeptTreeRoleselect(c *gin.Context) {
|
func GetDeptTreeRoleselect(c *gin.Context) {
|
||||||
var Dept models.Dept
|
var Dept models.SysDept
|
||||||
var SysRole models.SysRole
|
var SysRole models.SysRole
|
||||||
id, err := tools.StringToInt(c.Param("roleId"))
|
id, err := tools.StringToInt(c.Param("roleId"))
|
||||||
SysRole.RoleId = id
|
SysRole.RoleId = id
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ func GetSysUserProfile(c *gin.Context) {
|
|||||||
tools.HasError(err, "抱歉未找到相关信息", -1)
|
tools.HasError(err, "抱歉未找到相关信息", -1)
|
||||||
var SysRole models.SysRole
|
var SysRole models.SysRole
|
||||||
var Post models.Post
|
var Post models.Post
|
||||||
var Dept models.Dept
|
var Dept models.SysDept
|
||||||
//获取角色列表
|
//获取角色列表
|
||||||
roles, err := SysRole.GetList()
|
roles, err := SysRole.GetList()
|
||||||
//获取职位列表
|
//获取职位列表
|
||||||
|
|||||||
+629
-650
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -18,7 +18,7 @@ settings:
|
|||||||
secret: go-admin
|
secret: go-admin
|
||||||
timeout: 3600
|
timeout: 3600
|
||||||
database:
|
database:
|
||||||
driver: mysql # mysql,sqlite3, pgsql
|
driver: mysql # mysql,sqlite3, postgres
|
||||||
dbname: dbname
|
dbname: dbname
|
||||||
source: user:password@tcp(127.0.0.1:3306)/dbname?charset=utf8&parseTime=True&loc=Local
|
source: user:password@tcp(127.0.0.1:3306)/dbname?charset=utf8&parseTime=True&loc=Local
|
||||||
# source: sqlite3.db
|
# source: sqlite3.db
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ func Setup(driver string) {
|
|||||||
// db.Setup()
|
// db.Setup()
|
||||||
//}
|
//}
|
||||||
|
|
||||||
if dbType == "pgsql" {
|
if dbType == "postgres" {
|
||||||
var db = new(PgSql)
|
var db = new(PgSql)
|
||||||
db.Setup()
|
db.Setup()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package database
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/jinzhu/gorm"
|
"github.com/jinzhu/gorm"
|
||||||
|
_ "github.com/jinzhu/gorm/dialects/postgres"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"go-admin/global"
|
"go-admin/global"
|
||||||
"go-admin/tools/config"
|
"go-admin/tools/config"
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
orm "go-admin/global"
|
orm "go-admin/global"
|
||||||
"go-admin/tools"
|
"go-admin/tools"
|
||||||
|
"time"
|
||||||
_ "time"
|
_ "time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -21,6 +22,12 @@ type SysConfig struct {
|
|||||||
BaseModel
|
BaseModel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DataInit() {
|
||||||
|
config1:=SysConfig{1, "主框架页-默认皮肤样式名称", "sys_index_skinName", "skin-blue", "Y", "蓝色 skin-blue、绿色 skin-green、紫色 skin-purple、红色 skin-red、黄色 skin-yellow", "1", "1", "","",BaseModel{time.Now(), time.Now(), nil}}
|
||||||
|
|
||||||
|
orm.Eloquent.Create(&config1)
|
||||||
|
}
|
||||||
|
|
||||||
func (SysConfig) TableName() string {
|
func (SysConfig) TableName() string {
|
||||||
return "sys_config"
|
return "sys_config"
|
||||||
}
|
}
|
||||||
|
|||||||
+24
-24
@@ -7,7 +7,7 @@ import (
|
|||||||
_ "time"
|
_ "time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Dept struct {
|
type SysDept struct {
|
||||||
DeptId int `json:"deptId" gorm:"primary_key;AUTO_INCREMENT"` //部门编码
|
DeptId int `json:"deptId" gorm:"primary_key;AUTO_INCREMENT"` //部门编码
|
||||||
ParentId int `json:"parentId" gorm:"type:int(11);"` //上级部门
|
ParentId int `json:"parentId" gorm:"type:int(11);"` //上级部门
|
||||||
DeptPath string `json:"deptPath" gorm:"type:varchar(255);"` //
|
DeptPath string `json:"deptPath" gorm:"type:varchar(255);"` //
|
||||||
@@ -21,11 +21,11 @@ type Dept struct {
|
|||||||
UpdateBy string `json:"updateBy" gorm:"type:varchar(64);"`
|
UpdateBy string `json:"updateBy" gorm:"type:varchar(64);"`
|
||||||
DataScope string `json:"dataScope" gorm:"-"`
|
DataScope string `json:"dataScope" gorm:"-"`
|
||||||
Params string `json:"params" gorm:"-"`
|
Params string `json:"params" gorm:"-"`
|
||||||
Children []Dept `json:"children" gorm:"-"`
|
Children []SysDept `json:"children" gorm:"-"`
|
||||||
BaseModel
|
BaseModel
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Dept) TableName() string {
|
func (SysDept) TableName() string {
|
||||||
return "sys_dept"
|
return "sys_dept"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,8 +35,8 @@ type DeptLable struct {
|
|||||||
Children []DeptLable `gorm:"-" json:"children"`
|
Children []DeptLable `gorm:"-" json:"children"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Dept) Create() (Dept, error) {
|
func (e *SysDept) Create() (SysDept, error) {
|
||||||
var doc Dept
|
var doc SysDept
|
||||||
result := orm.Eloquent.Table(e.TableName()).Create(&e)
|
result := orm.Eloquent.Table(e.TableName()).Create(&e)
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
err := result.Error
|
err := result.Error
|
||||||
@@ -44,7 +44,7 @@ func (e *Dept) Create() (Dept, error) {
|
|||||||
}
|
}
|
||||||
deptPath := "/" + tools.IntToString(e.DeptId)
|
deptPath := "/" + tools.IntToString(e.DeptId)
|
||||||
if int(e.ParentId) != 0 {
|
if int(e.ParentId) != 0 {
|
||||||
var deptP Dept
|
var deptP SysDept
|
||||||
orm.Eloquent.Table(e.TableName()).Where("dept_id = ?", e.ParentId).First(&deptP)
|
orm.Eloquent.Table(e.TableName()).Where("dept_id = ?", e.ParentId).First(&deptP)
|
||||||
deptPath = deptP.DeptPath + deptPath
|
deptPath = deptP.DeptPath + deptPath
|
||||||
} else {
|
} else {
|
||||||
@@ -61,8 +61,8 @@ func (e *Dept) Create() (Dept, error) {
|
|||||||
return doc, nil
|
return doc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Dept) Get() (Dept, error) {
|
func (e *SysDept) Get() (SysDept, error) {
|
||||||
var doc Dept
|
var doc SysDept
|
||||||
|
|
||||||
table := orm.Eloquent.Table(e.TableName())
|
table := orm.Eloquent.Table(e.TableName())
|
||||||
if e.DeptId != 0 {
|
if e.DeptId != 0 {
|
||||||
@@ -78,8 +78,8 @@ func (e *Dept) Get() (Dept, error) {
|
|||||||
return doc, nil
|
return doc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Dept) GetList() ([]Dept, error) {
|
func (e *SysDept) GetList() ([]SysDept, error) {
|
||||||
var doc []Dept
|
var doc []SysDept
|
||||||
|
|
||||||
table := orm.Eloquent.Table(e.TableName())
|
table := orm.Eloquent.Table(e.TableName())
|
||||||
if e.DeptId != 0 {
|
if e.DeptId != 0 {
|
||||||
@@ -98,8 +98,8 @@ func (e *Dept) GetList() ([]Dept, error) {
|
|||||||
return doc, nil
|
return doc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Dept) GetPage(bl bool) ([]Dept, error) {
|
func (e *SysDept) GetPage(bl bool) ([]SysDept, error) {
|
||||||
var doc []Dept
|
var doc []SysDept
|
||||||
|
|
||||||
table := orm.Eloquent.Select("*").Table(e.TableName())
|
table := orm.Eloquent.Select("*").Table(e.TableName())
|
||||||
if e.DeptId != 0 {
|
if e.DeptId != 0 {
|
||||||
@@ -131,10 +131,10 @@ func (e *Dept) GetPage(bl bool) ([]Dept, error) {
|
|||||||
return doc, nil
|
return doc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Dept) SetDept(bl bool) ([]Dept, error) {
|
func (e *SysDept) SetDept(bl bool) ([]SysDept, error) {
|
||||||
list, err := e.GetPage(bl)
|
list, err := e.GetPage(bl)
|
||||||
|
|
||||||
m := make([]Dept, 0)
|
m := make([]SysDept, 0)
|
||||||
for i := 0; i < len(list); i++ {
|
for i := 0; i < len(list); i++ {
|
||||||
if list[i].ParentId != 0 {
|
if list[i].ParentId != 0 {
|
||||||
continue
|
continue
|
||||||
@@ -146,16 +146,16 @@ func (e *Dept) SetDept(bl bool) ([]Dept, error) {
|
|||||||
return m, err
|
return m, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func Digui(deptlist *[]Dept, menu Dept) Dept {
|
func Digui(deptlist *[]SysDept, menu SysDept) SysDept {
|
||||||
list := *deptlist
|
list := *deptlist
|
||||||
|
|
||||||
min := make([]Dept, 0)
|
min := make([]SysDept, 0)
|
||||||
for j := 0; j < len(list); j++ {
|
for j := 0; j < len(list); j++ {
|
||||||
|
|
||||||
if menu.DeptId != list[j].ParentId {
|
if menu.DeptId != list[j].ParentId {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
mi := Dept{}
|
mi := SysDept{}
|
||||||
mi.DeptId = list[j].DeptId
|
mi.DeptId = list[j].DeptId
|
||||||
mi.ParentId = list[j].ParentId
|
mi.ParentId = list[j].ParentId
|
||||||
mi.DeptPath = list[j].DeptPath
|
mi.DeptPath = list[j].DeptPath
|
||||||
@@ -165,7 +165,7 @@ func Digui(deptlist *[]Dept, menu Dept) Dept {
|
|||||||
mi.Phone = list[j].Phone
|
mi.Phone = list[j].Phone
|
||||||
mi.Email = list[j].Email
|
mi.Email = list[j].Email
|
||||||
mi.Status = list[j].Status
|
mi.Status = list[j].Status
|
||||||
mi.Children = []Dept{}
|
mi.Children = []SysDept{}
|
||||||
ms := Digui(deptlist, mi)
|
ms := Digui(deptlist, mi)
|
||||||
min = append(min, ms)
|
min = append(min, ms)
|
||||||
|
|
||||||
@@ -174,14 +174,14 @@ func Digui(deptlist *[]Dept, menu Dept) Dept {
|
|||||||
return menu
|
return menu
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Dept) Update(id int) (update Dept, err error) {
|
func (e *SysDept) Update(id int) (update SysDept, err error) {
|
||||||
if err = orm.Eloquent.Table(e.TableName()).Where("dept_id = ?", id).First(&update).Error; err != nil {
|
if err = orm.Eloquent.Table(e.TableName()).Where("dept_id = ?", id).First(&update).Error; err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
deptPath := "/" + tools.IntToString(e.DeptId)
|
deptPath := "/" + tools.IntToString(e.DeptId)
|
||||||
if int(e.ParentId) != 0 {
|
if int(e.ParentId) != 0 {
|
||||||
var deptP Dept
|
var deptP SysDept
|
||||||
orm.Eloquent.Table(e.TableName()).Where("dept_id = ?", e.ParentId).First(&deptP)
|
orm.Eloquent.Table(e.TableName()).Where("dept_id = ?", e.ParentId).First(&deptP)
|
||||||
deptPath = deptP.DeptPath + deptPath
|
deptPath = deptP.DeptPath + deptPath
|
||||||
} else {
|
} else {
|
||||||
@@ -203,7 +203,7 @@ func (e *Dept) Update(id int) (update Dept, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Dept) Delete(id int) (success bool, err error) {
|
func (e *SysDept) Delete(id int) (success bool, err error) {
|
||||||
|
|
||||||
user := SysUser{}
|
user := SysUser{}
|
||||||
user.DeptId = id
|
user.DeptId = id
|
||||||
@@ -223,7 +223,7 @@ func (e *Dept) Delete(id int) (success bool, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = tx.Table(e.TableName()).Where("dept_id = ?", id).Delete(&Dept{}).Error; err != nil {
|
if err = tx.Table(e.TableName()).Where("dept_id = ?", id).Delete(&SysDept{}).Error; err != nil {
|
||||||
success = false
|
success = false
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return
|
return
|
||||||
@@ -237,7 +237,7 @@ func (e *Dept) Delete(id int) (success bool, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dept *Dept) SetDeptLable() (m []DeptLable, err error) {
|
func (dept *SysDept) SetDeptLable() (m []DeptLable, err error) {
|
||||||
deptlist, err := dept.GetList()
|
deptlist, err := dept.GetList()
|
||||||
|
|
||||||
m = make([]DeptLable, 0)
|
m = make([]DeptLable, 0)
|
||||||
@@ -255,7 +255,7 @@ func (dept *Dept) SetDeptLable() (m []DeptLable, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func DiguiDeptLable(deptlist *[]Dept, dept DeptLable) DeptLable {
|
func DiguiDeptLable(deptlist *[]SysDept, dept DeptLable) DeptLable {
|
||||||
list := *deptlist
|
list := *deptlist
|
||||||
|
|
||||||
min := make([]DeptLable, 0)
|
min := make([]DeptLable, 0)
|
||||||
|
|||||||
+6
-4
@@ -8,12 +8,12 @@ import (
|
|||||||
|
|
||||||
func AutoMigrate(db *gorm.DB) error {
|
func AutoMigrate(db *gorm.DB) error {
|
||||||
db.SingularTable(true)
|
db.SingularTable(true)
|
||||||
|
err:=db.AutoMigrate(
|
||||||
return db.AutoMigrate(
|
|
||||||
new(models.CasbinRule),
|
new(models.CasbinRule),
|
||||||
|
new(models.SysDept),
|
||||||
|
new(models.SysConfig),
|
||||||
new(tools.SysTables),
|
new(tools.SysTables),
|
||||||
new(tools.SysColumns),
|
new(tools.SysColumns),
|
||||||
new(models.Dept),
|
|
||||||
new(models.Menu),
|
new(models.Menu),
|
||||||
new(models.LoginLog),
|
new(models.LoginLog),
|
||||||
new(models.SysOperLog),
|
new(models.SysOperLog),
|
||||||
@@ -23,9 +23,11 @@ func AutoMigrate(db *gorm.DB) error {
|
|||||||
new(models.SysRole),
|
new(models.SysRole),
|
||||||
new(models.Post),
|
new(models.Post),
|
||||||
new(models.DictData),
|
new(models.DictData),
|
||||||
new(models.SysConfig),
|
|
||||||
new(models.DictType),
|
new(models.DictType),
|
||||||
).Error
|
).Error
|
||||||
|
|
||||||
|
models.DataInit()
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ func InitDb() error {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
sql := strings.Replace(sqlList[i]+";", "\n", "", 0)
|
sql := strings.Replace(sqlList[i]+";", "\n", "", 0)
|
||||||
|
sql = strings.TrimSpace(sql)
|
||||||
if err = orm.Eloquent.Exec(sql).Error; err != nil {
|
if err = orm.Eloquent.Exec(sql).Error; err != nil {
|
||||||
if !strings.Contains(err.Error(), "Query was empty") {
|
if !strings.Contains(err.Error(), "Query was empty") {
|
||||||
return err
|
return err
|
||||||
|
|||||||
Reference in New Issue
Block a user