feat: file manage
This commit is contained in:
1 parent
b9d3483ba3
commit
128e34ab04
11 files changed
+544
-44
No files matched your search
@@ -20,9 +20,6 @@ import (
|
||||
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
|
||||
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
|
||||
// @Router /api/v1/public/uploadFile [post]
|
||||
|
||||
|
||||
|
||||
func UploadFile(c *gin.Context) {
|
||||
tag,_ := c.GetPostForm("type")
|
||||
urlPerfix := fmt.Sprintf("http://%s/",c.Request.Host)
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package sysfiledir
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
"go-admin/models"
|
||||
"go-admin/tools"
|
||||
"go-admin/tools/app"
|
||||
"go-admin/tools/app/msg"
|
||||
)
|
||||
|
||||
func GetSysFileDirList(c *gin.Context) {
|
||||
var SysFileDir models.SysFileDir
|
||||
SysFileDir.Lable = c.Request.FormValue("lable")
|
||||
SysFileDir.PId, _ = tools.StringToInt(c.Request.FormValue("pid"))
|
||||
SysFileDir.Id, _ = tools.StringToInt(c.Request.FormValue("id"))
|
||||
SysFileDir.DataScope = tools.GetUserIdStr(c)
|
||||
result, err := SysFileDir.SetSysFileDir()
|
||||
tools.HasError(err, "抱歉未找到相关信息", -1)
|
||||
app.OK(c, result, "")
|
||||
}
|
||||
|
||||
func GetSysFileDir(c *gin.Context) {
|
||||
var data models.SysFileDir
|
||||
data.Id, _ = tools.StringToInt(c.Param("id"))
|
||||
result, err := data.Get()
|
||||
tools.HasError(err, "抱歉未找到相关信息", -1)
|
||||
|
||||
app.OK(c, result, "")
|
||||
}
|
||||
|
||||
func InsertSysFileDir(c *gin.Context) {
|
||||
var data models.SysFileDir
|
||||
err := c.ShouldBindJSON(&data)
|
||||
data.CreateBy = tools.GetUserIdStr(c)
|
||||
tools.HasError(err, "", 500)
|
||||
result, err := data.Create()
|
||||
tools.HasError(err, "", -1)
|
||||
app.OK(c, result, "")
|
||||
}
|
||||
|
||||
func UpdateSysFileDir(c *gin.Context) {
|
||||
var data models.SysFileDir
|
||||
err := c.BindWith(&data, binding.JSON)
|
||||
tools.HasError(err, "数据解析失败", -1)
|
||||
data.UpdateBy = tools.GetUserIdStr(c)
|
||||
result, err := data.Update(data.Id)
|
||||
tools.HasError(err, "", -1)
|
||||
|
||||
app.OK(c, result, "")
|
||||
}
|
||||
|
||||
func DeleteSysFileDir(c *gin.Context) {
|
||||
var data models.SysFileDir
|
||||
data.UpdateBy = tools.GetUserIdStr(c)
|
||||
|
||||
IDS := tools.IdsStrToIdsIntGroup("id", c)
|
||||
_, err := data.BatchDelete(IDS)
|
||||
tools.HasError(err, msg.DeletedFail, 500)
|
||||
app.OK(c, nil, msg.DeletedSuccess)
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package sysfileinfo
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
"go-admin/models"
|
||||
"go-admin/tools"
|
||||
"go-admin/tools/app"
|
||||
"go-admin/tools/app/msg"
|
||||
)
|
||||
|
||||
func GetSysFileInfoList(c *gin.Context) {
|
||||
var data models.SysFileInfo
|
||||
var err error
|
||||
var pageSize = 10
|
||||
var pageIndex = 1
|
||||
|
||||
if size := c.Request.FormValue("pageSize"); size != "" {
|
||||
pageSize = tools.StrToInt(err, size)
|
||||
}
|
||||
if index := c.Request.FormValue("pageIndex"); index != "" {
|
||||
pageIndex = tools.StrToInt(err, index)
|
||||
}
|
||||
|
||||
|
||||
|
||||
data.DataScope = tools.GetUserIdStr(c)
|
||||
result, count, err := data.GetPage(pageSize, pageIndex)
|
||||
tools.HasError(err, "", -1)
|
||||
|
||||
app.PageOK(c, result, count, pageIndex, pageSize, "")
|
||||
}
|
||||
|
||||
func GetSysFileInfo(c *gin.Context) {
|
||||
var data models.SysFileInfo
|
||||
data.Id, _ = tools.StringToInt(c.Param("id"))
|
||||
result, err := data.Get()
|
||||
tools.HasError(err, "抱歉未找到相关信息", -1)
|
||||
|
||||
app.OK(c, result, "")
|
||||
}
|
||||
|
||||
func InsertSysFileInfo(c *gin.Context) {
|
||||
var data models.SysFileInfo
|
||||
err := c.ShouldBindJSON(&data)
|
||||
data.CreateBy = tools.GetUserIdStr(c)
|
||||
tools.HasError(err, "", 500)
|
||||
result, err := data.Create()
|
||||
tools.HasError(err, "", -1)
|
||||
app.OK(c, result, "")
|
||||
}
|
||||
|
||||
func UpdateSysFileInfo(c *gin.Context) {
|
||||
var data models.SysFileInfo
|
||||
err := c.BindWith(&data, binding.JSON)
|
||||
tools.HasError(err, "数据解析失败", -1)
|
||||
data.UpdateBy = tools.GetUserIdStr(c)
|
||||
result, err := data.Update(data.Id)
|
||||
tools.HasError(err, "", -1)
|
||||
|
||||
app.OK(c, result, "")
|
||||
}
|
||||
|
||||
func DeleteSysFileInfo(c *gin.Context) {
|
||||
var data models.SysFileInfo
|
||||
data.UpdateBy = tools.GetUserIdStr(c)
|
||||
|
||||
IDS := tools.IdsStrToIdsIntGroup("id", c)
|
||||
_, err := data.BatchDelete(IDS)
|
||||
tools.HasError(err, msg.DeletedFail, 500)
|
||||
app.OK(c, nil, msg.DeletedSuccess)
|
||||
}
|
||||
+12
-2
@@ -64,12 +64,22 @@ func GetSysTables(c *gin.Context) {
|
||||
var res app.Response
|
||||
res.Data = result
|
||||
mp := make(map[string]interface{})
|
||||
mp["rows"] = result.Columns
|
||||
mp["list"] = result.Columns
|
||||
mp["info"] = result
|
||||
res.Data = mp
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
func GetSysTablesTree(c *gin.Context) {
|
||||
var data tools.SysTables
|
||||
result, err := data.GetTree()
|
||||
tools2.HasError(err, "抱歉未找到相关信息", -1)
|
||||
|
||||
var res app.Response
|
||||
res.Data = result
|
||||
c.JSON(http.StatusOK, res.ReturnOK())
|
||||
}
|
||||
|
||||
// @Summary 添加表结构
|
||||
// @Description 添加表结构
|
||||
// @Tags 工具 - 生成表
|
||||
@@ -200,7 +210,7 @@ func genTableInit(tablesList []string, i int, c *gin.Context) (tools.SysTables,
|
||||
func UpdateSysTable(c *gin.Context) {
|
||||
var data tools.SysTables
|
||||
err := c.Bind(&data)
|
||||
tools2.HasError(err, "数据解析失败", -1)
|
||||
tools2.HasError(err, "数据解析失败", 500)
|
||||
data.UpdateBy = tools2.GetUserIdStr(c)
|
||||
result, err := data.Update()
|
||||
tools2.HasError(err, "", -1)
|
||||
|
||||
@@ -0,0 +1,178 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
orm "go-admin/global"
|
||||
"go-admin/tools"
|
||||
)
|
||||
|
||||
type SysFileDir struct {
|
||||
Id int `json:"id" gorm:"type:int(11);primary_key"` //
|
||||
Lable string `json:"lable" gorm:"type:varchar(255);"` // 名称
|
||||
PId int `json:"pId" gorm:"type:int(11);"` // 父id
|
||||
Sort int `json:"sort" gorm:""` //排序
|
||||
Path string `json:"path" gorm:"size:255;"` //
|
||||
CreateBy string `json:"createBy" gorm:"type:varchar(128);"` // 创建人
|
||||
UpdateBy string `json:"updateBy" gorm:"type:varchar(128);"` // 编辑人
|
||||
Children []SysFileDir `json:"children" gorm:"-"`
|
||||
DataScope string `json:"dataScope" gorm:"-"`
|
||||
Params string `json:"params" gorm:"-"`
|
||||
BaseModel
|
||||
}
|
||||
|
||||
func (SysFileDir) TableName() string {
|
||||
return "sys_file_dir"
|
||||
}
|
||||
|
||||
// 创建SysFileDir
|
||||
func (e *SysFileDir) Create() (SysFileDir, error) {
|
||||
var doc SysFileDir
|
||||
result := orm.Eloquent.Table(e.TableName()).Create(&e)
|
||||
if result.Error != nil {
|
||||
err := result.Error
|
||||
return doc, err
|
||||
}
|
||||
|
||||
path := "/" + tools.IntToString(e.Id)
|
||||
if int(e.PId) != 0 {
|
||||
var deptP SysFileDir
|
||||
orm.Eloquent.Table(e.TableName()).Where("id = ?", e.PId).First(&deptP)
|
||||
path = deptP.Path + path
|
||||
} else {
|
||||
path = "/0" + path
|
||||
}
|
||||
var mp = map[string]string{}
|
||||
mp["deptPath"] = path
|
||||
if err := orm.Eloquent.Table(e.TableName()).Where("id = ?", e.Id).Update(mp).Error; err != nil {
|
||||
err := result.Error
|
||||
return doc, err
|
||||
}
|
||||
doc = *e
|
||||
doc.Path = path
|
||||
|
||||
return doc, nil
|
||||
}
|
||||
|
||||
// 获取SysFileDir
|
||||
func (e *SysFileDir) Get() (SysFileDir, error) {
|
||||
var doc SysFileDir
|
||||
table := orm.Eloquent.Table(e.TableName())
|
||||
|
||||
if e.Id != 0 {
|
||||
table = table.Where("id = ?", e.Id)
|
||||
}
|
||||
|
||||
if err := table.First(&doc).Error; err != nil {
|
||||
return doc, err
|
||||
}
|
||||
return doc, nil
|
||||
}
|
||||
|
||||
// 获取SysFileDir带分页
|
||||
func (e *SysFileDir) GetPage() ([]SysFileDir, int, error) {
|
||||
var doc []SysFileDir
|
||||
|
||||
table := orm.Eloquent.Select("*").Table(e.TableName())
|
||||
|
||||
// 数据权限控制(如果不需要数据权限请将此处去掉)
|
||||
//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 int
|
||||
|
||||
if err := table.Find(&doc).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
table.Where("`deleted_at` IS NULL").Count(&count)
|
||||
return doc, count, nil
|
||||
}
|
||||
|
||||
// 更新SysFileDir
|
||||
func (e *SysFileDir) Update(id int) (update SysFileDir, err error) {
|
||||
if err = orm.Eloquent.Table(e.TableName()).Where("id = ?", id).First(&update).Error; err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
path := "/" + tools.IntToString(e.Id)
|
||||
if int(e.Id) != 0 {
|
||||
var deptP SysFileDir
|
||||
orm.Eloquent.Table(e.TableName()).Where("id = ?", e.Id).First(&deptP)
|
||||
path = deptP.Path + path
|
||||
} else {
|
||||
path = "/0" + path
|
||||
}
|
||||
e.Path = path
|
||||
|
||||
if e.Path != "" && e.Path != update.Path {
|
||||
return update, errors.New("上级不允许修改!")
|
||||
}
|
||||
|
||||
//参数1:是要修改的数据
|
||||
//参数2:是修改的数据
|
||||
if err = orm.Eloquent.Table(e.TableName()).Model(&update).Updates(&e).Error; err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 删除SysFileDir
|
||||
func (e *SysFileDir) Delete(id int) (success bool, err error) {
|
||||
if err = orm.Eloquent.Table(e.TableName()).Where("id = ?", id).Delete(&SysFileDir{}).Error; err != nil {
|
||||
success = false
|
||||
return
|
||||
}
|
||||
success = true
|
||||
return
|
||||
}
|
||||
|
||||
//批量删除
|
||||
func (e *SysFileDir) BatchDelete(id []int) (Result bool, err error) {
|
||||
if err = orm.Eloquent.Table(e.TableName()).Where("id in (?)", id).Delete(&SysFileDir{}).Error; err != nil {
|
||||
return
|
||||
}
|
||||
Result = true
|
||||
return
|
||||
}
|
||||
|
||||
func (e *SysFileDir) SetSysFileDir() ([]SysFileDir, error) {
|
||||
list, _, err := e.GetPage()
|
||||
|
||||
m := make([]SysFileDir, 0)
|
||||
for i := 0; i < len(list); i++ {
|
||||
if list[i].PId != 0 {
|
||||
continue
|
||||
}
|
||||
info := SysFileDirDigui(&list, list[i])
|
||||
|
||||
m = append(m, info)
|
||||
}
|
||||
return m, err
|
||||
}
|
||||
|
||||
func SysFileDirDigui(deptlist *[]SysFileDir, menu SysFileDir) SysFileDir {
|
||||
list := *deptlist
|
||||
|
||||
min := make([]SysFileDir, 0)
|
||||
for j := 0; j < len(list); j++ {
|
||||
|
||||
if menu.Id != list[j].PId {
|
||||
continue
|
||||
}
|
||||
mi := SysFileDir{}
|
||||
mi.Id = list[j].Id
|
||||
mi.PId = list[j].PId
|
||||
mi.Lable = list[j].Lable
|
||||
mi.Sort = list[j].Sort
|
||||
mi.CreatedAt = list[j].CreatedAt
|
||||
mi.UpdatedAt = list[j].UpdatedAt
|
||||
mi.Children = []SysFileDir{}
|
||||
ms := SysFileDirDigui(deptlist, mi)
|
||||
min = append(min, ms)
|
||||
|
||||
}
|
||||
menu.Children = min
|
||||
return menu
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
orm "go-admin/global"
|
||||
"go-admin/tools"
|
||||
)
|
||||
|
||||
type SysFileInfo struct {
|
||||
Id int `json:"id" gorm:"type:int(11);primary_key"` // id
|
||||
Type string `json:"type" gorm:"type:varchar(255);"` // 文件类型
|
||||
Name string `json:"name" gorm:"type:varchar(255);"` // 文件名称
|
||||
Size string `json:"size" gorm:"type:int(11);"` // 文件大小
|
||||
PId string `json:"pId" gorm:"type:int(11);"` // 目录id
|
||||
Source string `json:"source" gorm:"type:varchar(255);"` // 文件源
|
||||
Url string `json:"url" gorm:"type:varchar(255);"` // 文件路径
|
||||
FullUrl string `json:"fullUrl" gorm:"type:varchar(255);"` // 文件全路径
|
||||
CreateBy string `json:"createBy" gorm:"type:varchar(128);"` // 创建人
|
||||
UpdateBy string `json:"updateBy" gorm:"type:varchar(128);"` // 编辑人
|
||||
DataScope string `json:"dataScope" gorm:"-"`
|
||||
Params string `json:"params" gorm:"-"`
|
||||
BaseModel
|
||||
}
|
||||
|
||||
func (SysFileInfo) TableName() string {
|
||||
return "sys_file_info"
|
||||
}
|
||||
|
||||
// 创建SysFileInfo
|
||||
func (e *SysFileInfo) Create() (SysFileInfo, error) {
|
||||
var doc SysFileInfo
|
||||
result := orm.Eloquent.Table(e.TableName()).Create(&e)
|
||||
if result.Error != nil {
|
||||
err := result.Error
|
||||
return doc, err
|
||||
}
|
||||
doc = *e
|
||||
return doc, nil
|
||||
}
|
||||
|
||||
// 获取SysFileInfo
|
||||
func (e *SysFileInfo) Get() (SysFileInfo, error) {
|
||||
var doc SysFileInfo
|
||||
table := orm.Eloquent.Table(e.TableName())
|
||||
|
||||
if e.Id != 0 {
|
||||
table = table.Where("id = ?", e.Id)
|
||||
}
|
||||
|
||||
if err := table.First(&doc).Error; err != nil {
|
||||
return doc, err
|
||||
}
|
||||
return doc, nil
|
||||
}
|
||||
|
||||
// 获取SysFileInfo带分页
|
||||
func (e *SysFileInfo) GetPage(pageSize int, pageIndex int) ([]SysFileInfo, int, error) {
|
||||
var doc []SysFileInfo
|
||||
|
||||
table := orm.Eloquent.Select("*").Table(e.TableName())
|
||||
|
||||
// 数据权限控制(如果不需要数据权限请将此处去掉)
|
||||
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 int
|
||||
|
||||
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
table.Where("`deleted_at` IS NULL").Count(&count)
|
||||
return doc, count, nil
|
||||
}
|
||||
|
||||
// 更新SysFileInfo
|
||||
func (e *SysFileInfo) Update(id int) (update SysFileInfo, err error) {
|
||||
if err = orm.Eloquent.Table(e.TableName()).Where("id = ?", id).First(&update).Error; err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
//参数1:是要修改的数据
|
||||
//参数2:是修改的数据
|
||||
if err = orm.Eloquent.Table(e.TableName()).Model(&update).Updates(&e).Error; err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 删除SysFileInfo
|
||||
func (e *SysFileInfo) Delete(id int) (success bool, err error) {
|
||||
if err = orm.Eloquent.Table(e.TableName()).Where("id = ?", id).Delete(&SysFileInfo{}).Error; err != nil {
|
||||
success = false
|
||||
return
|
||||
}
|
||||
success = true
|
||||
return
|
||||
}
|
||||
|
||||
//批量删除
|
||||
func (e *SysFileInfo) BatchDelete(id []int) (Result bool, err error) {
|
||||
if err = orm.Eloquent.Table(e.TableName()).Where("id in (?)", id).Delete(&SysFileInfo{}).Error; err != nil {
|
||||
return
|
||||
}
|
||||
Result = true
|
||||
return
|
||||
}
|
||||
+35
-31
@@ -6,37 +6,41 @@ import (
|
||||
)
|
||||
|
||||
type SysColumns struct {
|
||||
ColumnId int `gorm:"primary_key;auto_increment" json:"columnId"`
|
||||
TableId int `gorm:"" json:"tableId"`
|
||||
ColumnName string `gorm:"size:128;" json:"columnName"`
|
||||
ColumnComment string `gorm:"column:column_comment;size:128;" json:"columnComment"`
|
||||
ColumnType string `gorm:"column:column_type;size:128;" json:"columnType"`
|
||||
GoType string `gorm:"column:go_type;size:128;" json:"goType"`
|
||||
GoField string `gorm:"column:go_field;size:128;" json:"goField"`
|
||||
JsonField string `gorm:"column:json_field;size:128;" json:"jsonField"`
|
||||
IsPk string `gorm:"column:is_pk;size:4;" json:"isPk"`
|
||||
IsIncrement string `gorm:"column:is_increment;size:4;" json:"isIncrement"`
|
||||
IsRequired string `gorm:"column:is_required;size:4;" json:"isRequired"`
|
||||
IsInsert string `gorm:"column:is_insert;size:4;" json:"isInsert"`
|
||||
IsEdit string `gorm:"column:is_edit;size:4;" json:"isEdit"`
|
||||
IsList string `gorm:"column:is_list;size:4;" json:"isList"`
|
||||
IsQuery string `gorm:"column:is_query;size:4;" json:"isQuery"`
|
||||
QueryType string `gorm:"column:query_type;size:128;" json:"queryType"`
|
||||
HtmlType string `gorm:"column:html_type;size:128;" json:"htmlType"`
|
||||
DictType string `gorm:"column:dict_type;size:128;" json:"dictType"`
|
||||
Sort int `gorm:"column:sort;" json:"sort"`
|
||||
List string `gorm:"column:list;size:1;" json:"list"`
|
||||
Pk bool `gorm:"column:pk;size:1;" json:"pk"`
|
||||
Required bool `gorm:"column:required;size:1;" json:"required"`
|
||||
SuperColumn bool `gorm:"column:super_column;size:1;" json:"superColumn"`
|
||||
UsableColumn bool `gorm:"column:usable_column;size:1;" json:"usableColumn"`
|
||||
Increment bool `gorm:"column:increment;size:1;" json:"increment"`
|
||||
Insert bool `gorm:"column:insert;size:1;" json:"insert"`
|
||||
Edit bool `gorm:"column:edit;size:1;" json:"edit"`
|
||||
Query bool `gorm:"column:query;size:1;" json:"query"`
|
||||
Remark string `gorm:"column:remark;size:255;" json:"remark"`
|
||||
CreateBy string `gorm:"column:create_by;size:128;" json:"createBy"`
|
||||
UpdateBy string `gorm:"column:update_By;size:128;" json:"updateBy"`
|
||||
ColumnId int `gorm:"primary_key;auto_increment" json:"columnId"`
|
||||
TableId int `gorm:"" json:"tableId"`
|
||||
ColumnName string `gorm:"size:128;" json:"columnName"`
|
||||
ColumnComment string `gorm:"column:column_comment;size:128;" json:"columnComment"`
|
||||
ColumnType string `gorm:"column:column_type;size:128;" json:"columnType"`
|
||||
GoType string `gorm:"column:go_type;size:128;" json:"goType"`
|
||||
GoField string `gorm:"column:go_field;size:128;" json:"goField"`
|
||||
JsonField string `gorm:"column:json_field;size:128;" json:"jsonField"`
|
||||
IsPk string `gorm:"column:is_pk;size:4;" json:"isPk"`
|
||||
IsIncrement string `gorm:"column:is_increment;size:4;" json:"isIncrement"`
|
||||
IsRequired string `gorm:"column:is_required;size:4;" json:"isRequired"`
|
||||
IsInsert string `gorm:"column:is_insert;size:4;" json:"isInsert"`
|
||||
IsEdit string `gorm:"column:is_edit;size:4;" json:"isEdit"`
|
||||
IsList string `gorm:"column:is_list;size:4;" json:"isList"`
|
||||
IsQuery string `gorm:"column:is_query;size:4;" json:"isQuery"`
|
||||
QueryType string `gorm:"column:query_type;size:128;" json:"queryType"`
|
||||
HtmlType string `gorm:"column:html_type;size:128;" json:"htmlType"`
|
||||
DictType string `gorm:"column:dict_type;size:128;" json:"dictType"`
|
||||
Sort int `gorm:"column:sort;" json:"sort"`
|
||||
List string `gorm:"column:list;size:1;" json:"list"`
|
||||
Pk bool `gorm:"column:pk;size:1;" json:"pk"`
|
||||
Required bool `gorm:"column:required;size:1;" json:"required"`
|
||||
SuperColumn bool `gorm:"column:super_column;size:1;" json:"superColumn"`
|
||||
UsableColumn bool `gorm:"column:usable_column;size:1;" json:"usableColumn"`
|
||||
Increment bool `gorm:"column:increment;size:1;" json:"increment"`
|
||||
Insert bool `gorm:"column:insert;size:1;" json:"insert"`
|
||||
Edit bool `gorm:"column:edit;size:1;" json:"edit"`
|
||||
Query bool `gorm:"column:query;size:1;" json:"query"`
|
||||
Remark string `gorm:"column:remark;size:255;" json:"remark"`
|
||||
FkTableName int `gorm:"" json:"fkTableName"`
|
||||
FkCol []SysColumns `gorm:"-" json:"fkCol"`
|
||||
FkLableId int `gorm:"" json:"fkLableId"`
|
||||
FkLableName string `gorm:"size:255;" json:"fkLableName"`
|
||||
CreateBy string `gorm:"column:create_by;size:128;" json:"createBy"`
|
||||
UpdateBy string `gorm:"column:update_By;size:128;" json:"updateBy"`
|
||||
|
||||
models.BaseModel
|
||||
}
|
||||
|
||||
@@ -96,6 +96,37 @@ func (e *SysTables) Get() (SysTables, error) {
|
||||
return doc, nil
|
||||
}
|
||||
|
||||
func (e *SysTables) GetTree() ([]SysTables, error) {
|
||||
var doc []SysTables
|
||||
var err error
|
||||
table := orm.Eloquent.Select("*").Table("sys_tables")
|
||||
|
||||
if e.TBName != "" {
|
||||
table = table.Where("table_name = ?", e.TBName)
|
||||
}
|
||||
if e.TableId != 0 {
|
||||
table = table.Where("table_id = ?", e.TableId)
|
||||
}
|
||||
if e.TableComment != "" {
|
||||
table = table.Where("table_comment = ?", e.TableComment)
|
||||
}
|
||||
|
||||
if err := table.Find(&doc).Error; err != nil {
|
||||
return doc, err
|
||||
}
|
||||
for i := 0; i < len(doc); i++ {
|
||||
var col SysColumns
|
||||
//col.FkCol = append(col.FkCol, SysColumns{ColumnId: 0, ColumnName: "请选择"})
|
||||
col.TableId = doc[i].TableId
|
||||
if doc[i].Columns, err = col.GetList(); err != nil {
|
||||
return doc, err
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return doc, nil
|
||||
}
|
||||
|
||||
func (e *SysTables) Create() (SysTables, error) {
|
||||
var doc SysTables
|
||||
result := orm.Eloquent.Table("sys_tables").Create(&e)
|
||||
|
||||
+4
-1
@@ -26,6 +26,8 @@ func examplesNoCheckRoleRouter(r *gin.Engine) {
|
||||
v1.GET("/nilcheckrole", nil)
|
||||
|
||||
// {{无需认证路由自动补充在此处请勿删除}}
|
||||
registerSysFileInfoRouter(v1)
|
||||
registerSysFileDirRouter(v1)
|
||||
}
|
||||
|
||||
// 需要认证的路由示例
|
||||
@@ -35,5 +37,6 @@ func examplesCheckRoleRouter(r *gin.Engine, authMiddleware *jwtauth.GinJWTMiddle
|
||||
// 空接口防止v1定义无使用报错
|
||||
v1.GET("/checkrole", nil)
|
||||
|
||||
// {{认证路由自动补充在此处请勿删除}}
|
||||
// {{认证路由自动补充在此处请勿删除}}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"go-admin/apis/sysfiledir"
|
||||
"go-admin/apis/sysfileinfo"
|
||||
)
|
||||
|
||||
// 无需认证的路由代码
|
||||
func registerSysFileInfoRouter(v1 *gin.RouterGroup) {
|
||||
|
||||
v1.GET("/sysfileinfoList",sysfileinfo.GetSysFileInfoList)
|
||||
|
||||
r := v1.Group("/sysfileinfo")
|
||||
{
|
||||
r.GET("/:id", sysfileinfo.GetSysFileInfo)
|
||||
r.POST("", sysfileinfo.InsertSysFileInfo)
|
||||
r.PUT("", sysfileinfo.UpdateSysFileInfo)
|
||||
r.DELETE("/:id", sysfileinfo.DeleteSysFileInfo)
|
||||
}
|
||||
}
|
||||
|
||||
// 无需认证的路由代码
|
||||
func registerSysFileDirRouter(v1 *gin.RouterGroup) {
|
||||
|
||||
v1.GET("/sysfiledirList",sysfiledir.GetSysFileDirList)
|
||||
|
||||
r := v1.Group("/sysfiledir")
|
||||
{
|
||||
r.GET("/:id", sysfiledir.GetSysFileDir)
|
||||
r.POST("", sysfiledir.InsertSysFileDir)
|
||||
r.PUT("", sysfiledir.UpdateSysFileDir)
|
||||
r.DELETE("/:id", sysfiledir.DeleteSysFileDir)
|
||||
}
|
||||
}
|
||||
+8
-7
@@ -50,7 +50,7 @@ func sysBaseRouter(r *gin.RouterGroup) {
|
||||
|
||||
func sysStaticFileRouter(r *gin.RouterGroup) {
|
||||
mime.AddExtensionType(".js", "application/javascript")
|
||||
|
||||
|
||||
r.Static("/static", "./static")
|
||||
r.Static("/form-generator", "./static/form-generator")
|
||||
}
|
||||
@@ -67,6 +67,7 @@ func sysNoCheckRoleRouter(r *gin.RouterGroup) {
|
||||
v1.GET("/gen/preview/:tableId", Preview)
|
||||
v1.GET("/gen/toproject/:tableId", GenCode)
|
||||
v1.GET("/gen/todb/:tableId", GenMenuAndApi)
|
||||
v1.GET("/gen/tabletree", GetSysTablesTree)
|
||||
v1.GET("/menuTreeselect", system.GetMenuTreeelect)
|
||||
v1.GET("/dict/databytype/:dictType", dict.GetDictDataByDictType)
|
||||
|
||||
@@ -79,6 +80,7 @@ func sysNoCheckRoleRouter(r *gin.RouterGroup) {
|
||||
registerSysSettingRouter(v1)
|
||||
|
||||
registerSysJobRouter(v1)
|
||||
|
||||
}
|
||||
|
||||
func registerDBRouter(api *gin.RouterGroup) {
|
||||
@@ -89,6 +91,7 @@ func registerDBRouter(api *gin.RouterGroup) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func registerSysTableRouter(v1 *gin.RouterGroup) {
|
||||
systables := v1.Group("/sys/tables")
|
||||
{
|
||||
@@ -114,11 +117,10 @@ func registerSysJobRouter(v1 *gin.RouterGroup) {
|
||||
r.DELETE("/:jobId", sysjob.DeleteSysJob)
|
||||
}
|
||||
|
||||
v1.GET("/job/remove/:jobId",sysjob.RemoveJob)
|
||||
v1.GET("/job/start/:jobId",sysjob.StartJob)
|
||||
v1.GET("/job/remove/:jobId", sysjob.RemoveJob)
|
||||
v1.GET("/job/start/:jobId", sysjob.StartJob)
|
||||
}
|
||||
|
||||
|
||||
func sysCheckRoleRouterInit(r *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
|
||||
r.POST("/login", authMiddleware.LoginHandler)
|
||||
// Refresh time can be longer than token timeout
|
||||
@@ -128,8 +130,6 @@ func sysCheckRoleRouterInit(r *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddle
|
||||
|
||||
r.Group("").Use(authMiddleware.MiddlewareFunc()).GET("/wslogout/:id/:channel", ws.WebsocketManager.UnWsClient)
|
||||
|
||||
|
||||
|
||||
v1 := r.Group("/api/v1")
|
||||
|
||||
registerPageRouter(v1, authMiddleware)
|
||||
@@ -144,6 +144,7 @@ func sysCheckRoleRouterInit(r *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddle
|
||||
registerMenuRouter(v1, authMiddleware)
|
||||
registerLoginLogRouter(v1, authMiddleware)
|
||||
registerOperLogRouter(v1, authMiddleware)
|
||||
|
||||
}
|
||||
|
||||
func registerBaseRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
|
||||
@@ -288,7 +289,7 @@ func registerSysSettingRouter(v1 *gin.RouterGroup) {
|
||||
{
|
||||
setting.GET("", system.GetSetting)
|
||||
setting.POST("", system.CreateSetting)
|
||||
setting.GET("/serverInfo",monitor.ServerInfo)
|
||||
setting.GET("/serverInfo", monitor.ServerInfo)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user