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