This commit is contained in:
IT 老营长 @云轩领航-创始人 2024-09-18 13:33:20 +08:00
parent 91ac804ddb
commit 617decf4d0
10 changed files with 369 additions and 0 deletions

107
src/dashboard/dashboard.go Normal file
View File

@ -0,0 +1,107 @@
package dashboard
import (
"gorm.io/driver/mysql"
"gorm.io/gorm"
"gorm.io/gorm/logger"
"shylinux.com/x/ice"
"shylinux.com/x/icebergs/base/aaa"
"shylinux.com/x/icebergs/base/ctx"
"shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/web"
kit "shylinux.com/x/toolkits"
"shylinux.com/x/mysql-story/src/db"
"shylinux.com/x/operation/src/dashboard/model"
)
type dashboard struct {
Table
order string `data:"1"`
fields string `data:"dashboard_type,host,port,username,database"`
config string `name:"config host* port* username* password* database*" role:"leader"`
}
func (s dashboard) List(m *ice.Message, arg ...string) {
if len(arg) == 0 {
return
}
s.SelectDetail(m, model.UID, arg[0])
if DashboardType(kit.Int(m.Append(model.DASHBOARD_TYPE))) == DashboardPlace {
if s.IsLeader(m) {
m.Action(s.Schema)
}
s.UserPlaceInit(m)
} else if m.Append(model.USERNAME) == "" {
m.SetAppend().EchoInfoButton("", s.Config)
} else {
if s.IsLeader(m) {
m.PushAction(s.Config).Action(s.Config, s.Schema)
s.UserPlaceInit(m)
} else {
m.Action()
}
}
}
func (s dashboard) Config(m *ice.Message, arg ...string) {
s.Update(m, kit.Dict(arg), model.UID, m.Option(model.DASHBOARD_UID))
s.UserPlaceInit(m)
}
func (s dashboard) Schema(m *ice.Message, arg ...string) {
db := m.Configv(db.DB).(*gorm.DB)
s.Show(m, db.Raw(`
select TABLE_SCHEMA,TABLE_NAME,TABLE_ROWS,DATA_LENGTH,INDEX_LENGTH from information_schema.TABLES
where TABLE_SCHEMA != 'mysql' AND TABLE_SCHEMA != 'information_schema' AND TABLE_SCHEMA != 'performance_schema'
order by DATA_LENGTH desc
`))
m.Display("/plugin/table.js")
}
func init() { ice.TeamCtxCmd(dashboard{}) }
func (s dashboard) Open(msg *ice.Message, cb func(*gorm.DB)) {
dsn := kit.Format("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=True",
msg.Append(model.USERNAME), msg.Append(model.PASSWORD), msg.Append(model.HOST), msg.Append(model.PORT), msg.Append(model.DATABASE))
if db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{Logger: logger.Default.LogMode(logger.Info)}); !msg.Warn(err) {
cb(db)
}
}
func (s dashboard) Scan(m *ice.Message, dashboard_uid string, cb func(*ice.Message, ice.Maps)) {
msg := m.Cmd(s, s.Select, model.UID, dashboard_uid)
switch DashboardType(kit.Int(msg.Append(model.TYPE))) {
case DashboardPlace:
m.Table(func(value ice.Maps) {
msg := s.SpaceCmd(m, value[web.SPACE], value[ctx.INDEX], mdb.SELECT, kit.Simple(kit.UnMarshal(value[model.QUERY])), kit.Dict(
mdb.SELECT, kit.Select("count(*)", value[mdb.FIELD]), ice.MSG_USERROLE, aaa.TECH,
))
cb(msg, value)
})
case DashboardMySQL:
s.Open(m, func(db *gorm.DB) {
m.Table(func(value ice.Maps) {
db = db.Table(s.TableName(kit.Join(kit.Slice(kit.Split(value[ctx.INDEX], "."), -2), ".")))
kit.If(value[model.QUERY], func(p string) { s.Where(m, db, kit.Simple(kit.UnMarshal(p))...) })
msg := s.Rows(m.Spawn(), db.Select(kit.Select("count(*)", value[mdb.FIELD])))
cb(msg, value)
})
})
case DashboardRedis:
}
}
type DashboardType int
const (
DashboardPlace DashboardType = iota
DashboardMySQL
DashboardRedis
)
var DashboardTypeList = map[DashboardType]string{
DashboardPlace: "place",
DashboardMySQL: "mysql",
DashboardRedis: "redis",
}
func (s DashboardType) String() string { return DashboardTypeList[s] }

View File

@ -0,0 +1,15 @@
package dashboard
import (
"shylinux.com/x/ice"
"shylinux.com/x/operation/src/operation"
)
type userDashboard struct{ Table }
func init() { ice.TeamCtxCmd(userDashboard{}) }
type UserDashboardRole = operation.UserCloudRole
var UserDashboardRoleList = operation.UserCloudRoleList

43
src/storage/common.go Normal file
View File

@ -0,0 +1,43 @@
package storage
import (
"shylinux.com/x/ice"
kit "shylinux.com/x/toolkits"
"shylinux.com/x/enterprise/src/guanlixitong"
"shylinux.com/x/operation/src/storage/model"
)
type Table struct {
guanlixitong.Table
list string `name:"list storage_uid uid auto" role:"void"`
}
func (s Table) Inputs(m *ice.Message, arg ...string) {
switch arg[0] {
case model.USER_STORAGE_ROLE:
s.InputsListRole(m, UserStorageRoleList, arg...)
case model.STORAGE_TYPE:
s.InputsList(m, StorageTypeList, arg...)
default:
s.Table.Inputs(m, arg...)
}
}
func (s Table) RewriteAppend(m *ice.Message, arg ...string) *ice.Message {
m.RewriteAppend(func(value, key string, index int) string {
switch key {
case model.USER_STORAGE_ROLE:
value = UserStorageRole(kit.Int(value)).String()
case model.STORAGE_TYPE:
value = StorageType(kit.Int(value)).String()
case model.FILE_TYPE:
value = FileType(kit.Int(value)).String()
}
return value
})
return s.Table.RewriteAppend(m)
}
type Tables struct{ Table }
func (s Tables) BeforeMigrate(m *ice.Message, arg ...string) {}

64
src/storage/file.go Normal file
View File

@ -0,0 +1,64 @@
package storage
import (
"path"
"shylinux.com/x/ice"
"shylinux.com/x/icebergs/base/cli"
"shylinux.com/x/icebergs/base/web"
kit "shylinux.com/x/toolkits"
"shylinux.com/x/operation/src/storage/model"
)
type file struct {
Table
order string `data:"1"`
fields string `data:"title,content,size,user_uid"`
upload string `name:"upload" role:"leader,worker"`
create string `name:"create title* content*" role:"leader,worker"`
remove string `name:"remove" role:"leader,worker"`
right string `name:"right" role:"void"`
}
func (s file) Upload(m *ice.Message, arg ...string) {
up := kit.Simple(m.Optionv(ice.MSG_UPLOAD))
p := s.path(m, m.Option(model.STORAGE_UID), up[1])
m.Cmdy(web.CACHE, web.WATCH, up[0], p)
s.ValueCreate(m, model.TYPE, kit.Format(FilePath), model.TITLE, up[1], model.CONTENT, "", model.SIZE, up[2])
s.DashboardUpdate(m)
}
func (s file) Right(m *ice.Message, arg ...string) {
msg := m.Cmd(s.Prefix(m, Portal{}), Portal{}.PlaceList, m.Option(model.USER_UID), arg[0])
m.WarnNotRight(kit.Int(msg.Append(model.USER_STORAGE_ROLE)) == 0)
}
func (s file) List(m *ice.Message, arg ...string) {
if s.ValueList(m, arg).Display(""); len(arg) == 1 {
m.Action(s.Upload)
} else if len(arg) == 2 {
m.PushQRCode(cli.QRCODE, kit.MergeURL2(m.Option(ice.MSG_USERWEB), m.Resource(s.path(m, arg[0], m.Append(model.TITLE)))))
m.EchoImages(m.Resource(s.path(m, arg[0], m.Append(model.TITLE))))
}
}
func init() { ice.TeamCtxCmd(file{}) }
func (s file) path(m *ice.Message, arg ...string) string {
return path.Join("usr/local/storage/", path.Join(arg...))
}
type FileType int
const (
FileBlob FileType = iota
FilePath
FileLink
)
var FileTypeList = map[FileType]string{
FileBlob: "blob",
FilePath: "path",
FileLink: "link",
}
func (s FileType) String() string { return FileTypeList[s] }

9
src/storage/file.js Normal file
View File

@ -0,0 +1,9 @@
Volcanos(chat.ONIMPORT, {
_init: function(can, msg) {
can.onimport.myView(can, msg, function(value) { return [
{view: html.TITLE, list: [value.title||value.name, can.base.Size(value.size)]},
{view: html.STATUS, list: [can.onimport.timeView(can, value), value.user_name]},
{view: html.OUTPUT, list: [value.content||value.info]},
] })
},
})

View File

@ -0,0 +1,37 @@
package model
import "shylinux.com/x/mysql-story/src/db"
const (
UID = "uid"
NAME = "name"
TYPE = "type"
ROLE = "role"
TITLE = "title"
CONTENT = "content"
USER_UID = "user_uid"
USER_STORAGE_ROLE = "user_storage_role"
STORAGE_UID = "storage_uid"
STORAGE_NAME = "storage_name"
STORAGE_TYPE = "storage_type"
FILE_UID = "file_uid"
FILE_TYPE = "file_type"
COMPANY_UID = "company_uid"
CITY_UID = "city_uid"
SIZE = "size"
)
type UserStorage struct {
db.ModelUserPlace
StorageUID string `gorm:"type:char(32);index"`
}
type Storage struct {
db.ModelPlace
CompanyUID string `gorm:"type:char(32);index"`
}
type File struct {
db.ModelContent
StorageUID string `gorm:"type:char(32);index"`
}
func init() { db.CmdModels("", &UserStorage{}, &Storage{}, &File{}) }

21
src/storage/portal.go Normal file
View File

@ -0,0 +1,21 @@
package storage
import (
"shylinux.com/x/ice"
"shylinux.com/x/community/src/gonganxitong"
"shylinux.com/x/enterprise/src/guanlixitong"
)
type Portal struct {
guanlixitong.Portal
placeCreate string `name:"placeCreate city_name* company_name* storage_name* storage_type*:select" role:"void"`
}
func (s Portal) AfterPlaceAuth(m *ice.Message, arg ...string) {
defer s.DashboardCreate(m, "")()
s.DashboardInsert(m, "1", "文件数量", file{}, "")
s.DashboardInsert(m, "2", "文件大小", file{}, "SUM(size)")
}
func init() { gonganxitong.PortalCmd(Portal{Portal: guanlixitong.NewPortal(userStorage{}, storage{})}) }

33
src/storage/portal.json Normal file
View File

@ -0,0 +1,33 @@
{
"portal": "文件存储", "member": "网盘成员",
"file": "文件目录",
"icons": {
"file": "https://img.icons8.com/officel/80/user-folder.png"
},
"input": {
"My Storage": "我的网盘",
"user_storage_role": "用户角色",
"storage_uid": "网盘",
"storage_name": "网盘名称",
"storage_type": "网盘类型"
},
"value": {
"user_storage_role": {
"visitor": "访客",
"creator": "创建人",
"leader": "管理人员",
"worker": "工作人员",
"server": "服务人员",
"style": {
"creator": "danger",
"leader": "danger"
}
},
"storage_type": {
"system": "系统文件",
"local": "本地文件",
"baidu": "百度网盘",
"aliyun": "阿里云盘"
}
}
}

25
src/storage/storage.go Normal file
View File

@ -0,0 +1,25 @@
package storage
import "shylinux.com/x/ice"
type storage struct{ Table }
func init() { ice.TeamCtxCmd(storage{}) }
type StorageType int
const (
StorageSystem StorageType = iota
StorageLocal
StorageBaidu
StorageAliyun
)
var StorageTypeList = map[StorageType]string{
StorageSystem: "system",
StorageLocal: "local",
StorageBaidu: "baidu",
StorageAliyun: "aliyun",
}
func (s StorageType) String() string { return StorageTypeList[s] }

View File

@ -0,0 +1,15 @@
package storage
import (
"shylinux.com/x/ice"
"shylinux.com/x/enterprise/src/guanlixitong"
)
type userStorage struct{ Table }
func init() { ice.TeamCtxCmd(userStorage{}) }
type UserStorageRole = guanlixitong.UserGroupRole
var UserStorageRoleList = guanlixitong.UserGroupRoleList