This commit is contained in:
jingganjiaoyu 2024-09-07 17:11:41 +08:00
parent 88c86438cd
commit c40871690c
5 changed files with 40 additions and 44 deletions

View File

@ -17,14 +17,16 @@ func (s client) List(m *ice.Message, arg ...string) {
s.Fields(m, model.HOST, model.PORT, model.USERNAME, model.DATABASE)
s.SelectDetail(m, model.UID, arg[0])
if m.Append(model.USERNAME) == "" {
m.EchoInfoButton("", s.Config)
m.SetAppend().EchoInfoButton("", s.Config)
} else {
m.PushAction(s.Config).Action(s.Config)
s.UserPlaceInit(m)
}
}
}
func (s client) Config(m *ice.Message, arg ...string) {
s.Update(m, kit.Dict(arg), model.UID, m.Option(model.CLIENT_UID))
s.UserPlaceInit(m)
}
func init() { ice.TeamCtxCmd(client{}) }
@ -32,11 +34,13 @@ func init() { ice.TeamCtxCmd(client{}) }
type ClientType int
const (
ClientMySQL ClientType = iota
ClientPlace ClientType = iota
ClientMySQL
ClientRedis
)
var ClientTypeList = map[ClientType]string{
ClientPlace: "place",
ClientMySQL: "mysql",
ClientRedis: "redis",
}

View File

@ -25,6 +25,7 @@ const (
DATABASE = "database"
TABLES = "tables"
FIELDS = "fields"
QUERY = "query"
VALUE = "value"
SCORE = "score"
)
@ -45,12 +46,12 @@ type Client struct {
type Summary struct {
db.ModelContent
ClientUID string `gorm:"type:char(32);index"`
Space string `gorm:"type:varchar(32)"`
Index string `gorm:"type:varchar(32)"`
Space string `gorm:"type:varchar(64)"`
Index string `gorm:"type:varchar(128)"`
Query string `gorm:"type:varchar(255)"`
Field string `gorm:"type:varchar(255)"`
Value float32 `gorm:"default:0"`
Score float32 `gorm:"default:0"`
Tables string `gorm:"type:varchar(32)"`
Fields string `gorm:"type:varchar(32)"`
}
func init() { db.CmdModels("", &UserClient{}, &Client{}, &Summary{}) }

View File

@ -7,7 +7,7 @@ import (
type Portal struct {
operation.Portal
placeCreate string `name:"placeCreate city_name* company_name* client_type*:select client_name*" role:"void"`
placeCreate string `name:"placeCreate city_name* company_name* client_name* client_type*:select" role:"void"`
}
func init() { gonganxitong.PortalCmd(Portal{Portal: operation.NewPortal(userClient{}, client{})}) }

View File

@ -16,55 +16,47 @@ import (
type summary struct {
Table
client client
userClient userClient
create string `name:"create title* space index* score" role:"leader"`
modify string `name:"modify title* space index* score" role:"leader"`
remove string `name:"remove" role:"leader"`
scan string `name:"scan" role:"leader"`
client client
create string `name:"create title* space index* query field score" role:"leader"`
modify string `name:"modify title* space index* query field score" role:"leader"`
remove string `name:"remove" role:"leader"`
scan string `name:"scan" role:"leader"`
}
func (s summary) Create(m *ice.Message, arg ...string) {
s.Table.Create(m, kit.Simple(arg, m.OptionSimple(model.USER_UID, model.CLIENT_UID))...)
s.RecordEventWithName(m, "")
}
func (s summary) Remove(m *ice.Message, arg ...string) {
s.Table.Delete(m, m.OptionSimple(model.CLIENT_UID, model.UID)...)
}
func (s summary) Modify(m *ice.Message, arg ...string) {
s.Table.Update(m, kit.Dict(arg), m.OptionSimple(model.CLIENT_UID, model.UID)...)
}
func (s summary) Create(m *ice.Message, arg ...string) { s.Table.ValueCreate(m, arg...) }
func (s summary) Modify(m *ice.Message, arg ...string) { s.Table.ValueModify(m, arg...) }
func (s summary) Remove(m *ice.Message, arg ...string) { s.Table.ValueRemove(m, arg...) }
func (s summary) Scan(m *ice.Message, arg ...string) {
if false {
s.List(m, arg...).Table(func(value ice.Maps) {
msg := m.Cmd(web.SPACE, value[web.SPACE], value[ctx.INDEX], s.Select, kit.Dict(mdb.FIELDS, kit.Select("count(*)", value[model.FIELDS])))
client_uid := kit.Select(m.Option(model.CLIENT_UID), arg, 0)
msg := m.Cmd(s.client, s.Select, model.UID, client_uid)
switch ClientType(kit.Int(msg.Append(model.TYPE))) {
case ClientPlace:
s.List(m, client_uid).Table(func(value ice.Maps) {
msg := m.Cmd(web.SPACE, 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])))
s.Update(m, kit.Dict(model.VALUE, msg.Append(msg.Append(ice.MSG_APPEND))), model.UID, value[model.UID])
})
return
case ClientMySQL:
s.Open(m, func(db *gorm.DB) {
s.List(m, client_uid).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])))
s.Update(m, kit.Dict(model.VALUE, msg.Append(msg.Append(ice.MSG_APPEND))), model.UID, value[model.UID])
})
})
}
s.Open(m, func(db *gorm.DB) {
s.List(m, arg...).Table(func(value ice.Maps) {
db = db.Table(s.TableName(kit.Join(kit.Slice(kit.Split(value[ctx.INDEX], "."), -2), ".")))
msg := s.Rows(m.Spawn(), db.Select(kit.Select("count(*)", value[model.FIELDS])))
s.Update(m, kit.Dict(model.VALUE, msg.Append(msg.Append(ice.MSG_APPEND))), model.UID, value[model.UID])
})
})
}
func (s summary) List(m *ice.Message, arg ...string) *ice.Message {
s.Orders(m, model.SCORE, s.Desc(model.CREATED_AT))
s.Select(m, model.CLIENT_UID, arg[0]).Action(s.Create, s.Scan).PushAction(s.Modify, s.Remove).Display("").DisplayCSS("")
if m.Length() == 0 {
m.EchoInfoButton("")
}
return m
s.Select(m, model.CLIENT_UID, arg[0]).PushAction(s.Modify, s.Remove).Action(s.Create, s.Scan)
return s.Button(m, "").Display("").DisplayCSS("")
}
func init() { ice.TeamCtxCmd(summary{}) }
func (s summary) Open(m *ice.Message, cb func(*gorm.DB)) {
msg := m.Cmd(s.client, s.Select, model.UID, m.Option(model.CLIENT_UID))
func (s summary) 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)}); !m.Warn(err) {
if db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{Logger: logger.Default.LogMode(logger.Info)}); !msg.Warn(err) {
cb(db)
}
}

View File

@ -1,6 +1,5 @@
Volcanos(chat.ONIMPORT, {
_init: function(can, msg) {
var count = (parseInt(can.ConfWidth()/80)); if (msg.Length() < count) { count = msg.Length() }
_init: function(can, msg) { var count = (parseInt(can.ConfWidth()/80)); if (msg.Length() < count) { count = msg.Length() }
var width = can.ConfWidth()/(count||1)
can.page.Append(can, can._output, msg.Table(function(value) {
return {view: html.ITEM, style: {width: width}, list: [{view: ["value", "", value.value]}, {view: ["title", "", value.title]}], oncontextmenu: function(event) {