From dd3b68d32c022b6b40f2d22d498b56a86deb51b2 Mon Sep 17 00:00:00 2001 From: shylinux Date: Mon, 13 Apr 2020 21:27:54 +0800 Subject: [PATCH] opt command name --- base/cli/cli.go | 1 + base/ctx/ctx.go | 20 +- base/ssh/ssh.go | 5 + base/web/web.go | 66 +-- core/chat/chat.go | 4 +- core/code/code.go | 4 +- core/mall/mall.go | 844 +++++++++++++++++---------------------- core/team/team.go | 108 ++--- core/wiki/wiki.go | 105 +---- misc/git/git.go | 34 +- misc/input/input.go | 3 - misc/md/md.go | 54 +++ misc/md/md.js | 9 + misc/md/md.shy | 1 + misc/railway/railway.go | 96 +++++ misc/railway/railway.js | 9 + misc/railway/railway.shy | 1 + misc/tmux/tmux.go | 31 +- type.go | 10 +- 19 files changed, 671 insertions(+), 734 deletions(-) create mode 100644 misc/md/md.go create mode 100644 misc/md/md.js create mode 100644 misc/md/md.shy create mode 100644 misc/railway/railway.go create mode 100644 misc/railway/railway.js create mode 100644 misc/railway/railway.shy diff --git a/base/cli/cli.go b/base/cli/cli.go index 9ad51160..f697c814 100644 --- a/base/cli/cli.go +++ b/base/cli/cli.go @@ -69,6 +69,7 @@ var Index = &ice.Context{Name: "cli", Help: "命令模块", }}, ice.CLI_RUNTIME: {Name: "runtime", Help: "运行环境", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + m.Cmdy(ice.CTX_CONFIG, ice.CLI_RUNTIME, arg) }}, ice.CLI_SYSTEM: {Name: "system", Help: "系统命令", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) { cmd := exec.Command(arg[0], arg[1:]...) diff --git a/base/ctx/ctx.go b/base/ctx/ctx.go index 129cd365..cfc96b5f 100644 --- a/base/ctx/ctx.go +++ b/base/ctx/ctx.go @@ -110,19 +110,27 @@ var Index = &ice.Context{Name: "ctx", Help: "配置模块", button := false for i, v := range list { if i > 0 { - ls := kit.Split(v, ":=") - switch ls[0] { + switch ls := kit.Split(v, ":="); ls[0] { + case "[", "]": case "auto": cmd.List = append(cmd.List, kit.List(kit.MDB_INPUT, "button", "name", "查看", "value", "auto")...) cmd.List = append(cmd.List, kit.List(kit.MDB_INPUT, "button", "name", "返回", "value", "Last")...) button = true default: - if len(ls) > 1 && ls[1] == "button" { + kind, value := "text", "" + if len(ls) == 3 { + kind, value = ls[1], ls[2] + } else if len(ls) == 2 { + if strings.Contains(v, "=") { + value = ls[1] + } else { + kind = ls[1] + } + } + if kind == "button" { button = true } - cmd.List = append(cmd.List, kit.List( - kit.MDB_INPUT, kit.Select("text", ls, 1), "name", ls[0], "value", kit.Select("", ls, 2), - )...) + cmd.List = append(cmd.List, kit.List(kit.MDB_INPUT, kind, "name", ls[0], "value", value)...) } } } diff --git a/base/ssh/ssh.go b/base/ssh/ssh.go index 6c22f947..8aee695c 100644 --- a/base/ssh/ssh.go +++ b/base/ssh/ssh.go @@ -357,6 +357,11 @@ var Index = &ice.Context{Name: "ssh", Help: "终端模块", } }) }}, + + "what": {Name: "what", Help: "上位机", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + ls := kit.Split("window:=auto", " ", ":=") + m.Echo("%v %v", len(ls), ls) + }}, }, } diff --git a/base/web/web.go b/base/web/web.go index 86a9c549..fab5ac92 100644 --- a/base/web/web.go +++ b/base/web/web.go @@ -483,7 +483,7 @@ var Index = &ice.Context{Name: "web", Help: "网络模块", ice.WEB_SHARE: {Name: "share", Help: "共享链", Value: kit.Data("index", "usr/volcanos/share.html", "template", share_template)}, ice.WEB_ROUTE: {Name: "route", Help: "路由", Value: kit.Data(kit.MDB_SHORT, kit.MDB_NAME)}, - ice.WEB_PROXY: {Name: "proxy", Help: "代理", Value: kit.Data()}, + ice.WEB_PROXY: {Name: "proxy", Help: "代理", Value: kit.Data(kit.MDB_SHORT, "proxy")}, ice.WEB_GROUP: {Name: "group", Help: "分组", Value: kit.Data(kit.MDB_SHORT, "group")}, ice.WEB_LABEL: {Name: "label", Help: "标签", Value: kit.Data(kit.MDB_SHORT, "label")}, }, @@ -508,8 +508,7 @@ var Index = &ice.Context{Name: "web", Help: "网络模块", m.Conf(ice.WEB_SHARE, "meta.template", share_template) }}, ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - m.Save(ice.WEB_SPIDE, ice.WEB_SERVE, - ice.WEB_GROUP, ice.WEB_LABEL, + m.Save(ice.WEB_SPIDE, ice.WEB_SERVE, ice.WEB_GROUP, ice.WEB_LABEL, ice.WEB_FAVOR, ice.WEB_CACHE, ice.WEB_STORY, ice.WEB_SHARE, ) @@ -521,12 +520,8 @@ var Index = &ice.Context{Name: "web", Help: "网络模块", }) }}, - ice.WEB_SPIDE: {Name: "spide name [msg|raw|cache] POST|GET url [json|form|part|file|data] arg...", Help: "蜘蛛侠", List: kit.List( - kit.MDB_INPUT, "text", "name", "name", - kit.MDB_INPUT, "button", "value", "查看", "action", "auto", - kit.MDB_INPUT, "button", "value", "返回", "cb", "Last", - ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - if len(arg) == 0 { + ice.WEB_SPIDE: {Name: "spide name=auto [action:select=msg|raw|cache] [method:select=POST|GET] url [format:select=json|form|part|data|file] arg... auto", Help: "蜘蛛侠", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + if len(arg) == 0 || arg[0] == "" { // 爬虫列表 m.Richs(ice.WEB_SPIDE, nil, "*", func(key string, value map[string]interface{}) { m.Push(key, value["client"], []string{"name", "share", "login", "method", "url"}) @@ -534,7 +529,7 @@ var Index = &ice.Context{Name: "web", Help: "网络模块", m.Sort("name") return } - if len(arg) == 1 { + if len(arg) == 1 || len(arg) > 3 && arg[3] == "" { // 爬虫详情 m.Richs(ice.WEB_SPIDE, nil, arg[0], func(key string, value map[string]interface{}) { m.Push("detail", value) @@ -625,8 +620,6 @@ var Index = &ice.Context{Name: "web", Help: "网络模块", body, ok := m.Optionv("body").(io.Reader) if !ok && len(arg) > 0 && method != "GET" { switch arg[0] { - case "data": - body, arg = bytes.NewBufferString(arg[1]), arg[2:] case "file": if f, e := os.Open(arg[1]); m.Warn(e != nil, "%s", e) { return @@ -634,6 +627,8 @@ var Index = &ice.Context{Name: "web", Help: "网络模块", defer f.Close() body, arg = f, arg[2:] } + case "data": + body, arg = bytes.NewBufferString(arg[1]), arg[2:] case "part": buf := &bytes.Buffer{} mp := multipart.NewWriter(buf) @@ -782,10 +777,8 @@ var Index = &ice.Context{Name: "web", Help: "网络模块", m.Cmd(ice.WEB_SPACE, "connect", k) } }}, - ice.WEB_SPACE: {Name: "space", Help: "空间站", Meta: kit.Dict("exports", []string{"pod", "name"}), List: kit.List( - kit.MDB_INPUT, "text", "name", "name", - kit.MDB_INPUT, "button", "value", "查看", "action", "auto", - kit.MDB_INPUT, "button", "value", "返回", "cb", "Last", + ice.WEB_SPACE: {Name: "space name auto", Help: "空间站", Meta: kit.Dict( + "exports", []string{"pod", "name"}, ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) == 0 { // 空间列表 @@ -901,13 +894,8 @@ var Index = &ice.Context{Name: "web", Help: "网络模块", }) == nil, "not found %s", arg[0]) } }}, - ice.WEB_DREAM: {Name: "dream", Help: "梦想家", Meta: kit.Dict( - "exports", []string{"you", "name"}, - "detail", []interface{}{"启动", "停止"}, - ), List: kit.List( - kit.MDB_INPUT, "text", "value", "", "name", "name", - kit.MDB_INPUT, "button", "value", "创建", "action", "auto", - kit.MDB_INPUT, "button", "value", "返回", "cb", "Last", + ice.WEB_DREAM: {Name: "dream name auto", Help: "梦想家", Meta: kit.Dict( + "exports", []string{"you", "name"}, "detail", []interface{}{"启动", "停止"}, ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) > 1 && arg[0] == "action" { switch arg[1] { @@ -962,16 +950,8 @@ var Index = &ice.Context{Name: "web", Help: "网络模块", m.Cmdy("nfs.dir", p) }}, - ice.WEB_FAVOR: {Name: "favor [path [type name [text [key value]....]]", Help: "收藏夹", Meta: kit.Dict( - "exports", []string{"hot", "favor"}, - "detail", []string{"编辑", "收藏", "收录", "导出", "删除"}, - ), List: kit.List( - kit.MDB_INPUT, "text", "name", "favor", "action", "auto", - kit.MDB_INPUT, "text", "name", "id", "action", "auto", - kit.MDB_INPUT, "button", "name", "查看", "action", "auto", - kit.MDB_INPUT, "button", "name", "返回", "cb", "Last", - kit.MDB_INPUT, "button", "name", "渲染", - kit.MDB_INPUT, "button", "name", "回放", + ice.WEB_FAVOR: {Name: "favor favor=auto id=auto auto", Help: "收藏夹", Meta: kit.Dict( + "exports", []string{"hot", "favor"}, "detail", []string{"编辑", "收藏", "收录", "导出", "删除"}, ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { switch m.Option("_action") { case "渲染": @@ -1322,12 +1302,8 @@ var Index = &ice.Context{Name: "web", Help: "网络模块", m.Echo(arg[2]) } }}, - ice.WEB_STORY: {Name: "story", Help: "故事会", Meta: kit.Dict("exports", []string{"top", "story"}, - "detail", []string{"共享", "更新", "推送"}), List: kit.List( - kit.MDB_INPUT, "text", "name", "story", "action", "auto", - kit.MDB_INPUT, "text", "name", "list", "action", "auto", - kit.MDB_INPUT, "button", "value", "查看", "action", "auto", - kit.MDB_INPUT, "button", "value", "返回", "cb", "Last", + ice.WEB_STORY: {Name: "story story=auto key=auto auto", Help: "故事会", Meta: kit.Dict( + "exports", []string{"top", "story"}, "detail", []string{"共享", "更新", "推送"}, ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) > 1 && arg[0] == "action" { story, list := m.Option("story"), m.Option("list") @@ -1651,8 +1627,7 @@ var Index = &ice.Context{Name: "web", Help: "网络模块", m.Richs(ice.WEB_STORY, nil, list, func(key string, value map[string]interface{}) { // 直连节点 - m.Push("list", key) - m.Push(list, value, []string{"time", "count", "scene", "story"}) + m.Push(key, value, []string{"time", "key", "count", "scene", "story"}) m.Richs(ice.WEB_CACHE, nil, value["data"], func(key string, value map[string]interface{}) { m.Push("drama", value["text"]) m.Push("data", key) @@ -1661,8 +1636,7 @@ var Index = &ice.Context{Name: "web", Help: "网络模块", kit.Fetch(value["list"], func(key string, val string) { m.Richs(ice.WEB_STORY, nil, val, func(key string, value map[string]interface{}) { // 复合节点 - m.Push("list", key) - m.Push(list, value, []string{"time", "count", "scene", "story"}) + m.Push(key, value, []string{"time", "key", "count", "scene", "story"}) m.Richs(ice.WEB_CACHE, nil, value["data"], func(key string, value map[string]interface{}) { m.Push("drama", value["text"]) m.Push("data", key) @@ -1691,11 +1665,7 @@ var Index = &ice.Context{Name: "web", Help: "网络模块", }) } }}, - ice.WEB_SHARE: {Name: "share", Help: "共享链", List: kit.List( - kit.MDB_INPUT, "text", "name", "share", "action", "auto", - kit.MDB_INPUT, "button", "value", "查看", "action", "auto", - kit.MDB_INPUT, "button", "value", "返回", "cb", "Last", - ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + ice.WEB_SHARE: {Name: "share share auto", Help: "共享链", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) == 0 { // 共享列表 m.Grows(ice.WEB_SHARE, nil, "", "", func(index int, value map[string]interface{}) { diff --git a/core/chat/chat.go b/core/chat/chat.go index 3ce47236..9086eabd 100644 --- a/core/chat/chat.go +++ b/core/chat/chat.go @@ -189,14 +189,14 @@ var Index = &ice.Context{Name: "chat", Help: "聊天中心", } }}, - "search": {Name: "search label:text=some word:text=启动流程 auto", Help: "搜索引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + "search": {Name: "search label=some word=启动流程 auto", Help: "搜索引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) < 2 { m.Cmdy(ice.WEB_LABEL, arg) return } m.Cmdy(ice.WEB_LABEL, arg[0], "*", "favor", "search", arg[1:]) }}, - "commend": {Name: "commend label:text=some word:text=请求响应 auto", Help: "推荐引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + "commend": {Name: "commend label=some word=请求响应 auto", Help: "推荐引擎", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) < 2 { m.Cmdy(ice.WEB_LABEL, arg) return diff --git a/core/code/code.go b/core/code/code.go index bdb22e88..83f4fdad 100644 --- a/core/code/code.go +++ b/core/code/code.go @@ -138,9 +138,9 @@ var Index = &ice.Context{Name: "code", Help: "编程中心", } }}, - "login": {Name: "login", Help: "登录", Meta: kit.Dict( + "login": {Name: "login key", Help: "登录", Meta: kit.Dict( "detail", []string{"编辑", "删除", "清理", "清空"}, - ), List: ice.ListLook("key"), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) > 0 && arg[0] == "action" { switch arg[1] { case "modify", "编辑": diff --git a/core/mall/mall.go b/core/mall/mall.go index 36ca439f..2d825ec5 100644 --- a/core/mall/mall.go +++ b/core/mall/mall.go @@ -6,7 +6,6 @@ import ( "github.com/shylinux/toolkits" "encoding/csv" - "fmt" "strconv" "strings" ) @@ -39,8 +38,6 @@ func input(m *ice.Message, arg ...string) bool { var Index = &ice.Context{Name: "mall", Help: "贸易中心", Caches: map[string]*ice.Cache{}, Configs: map[string]*ice.Config{ - "railway": {Name: "railway", Help: "12306", Value: kit.Data("site", "https://kyfw.12306.cn")}, - "asset": {Name: "asset", Help: "资产", Value: kit.Data(kit.MDB_SHORT, "account", "site", kit.Dict( "公积金", "https://grwsyw.gjj.beijing.gov.cn/ish/flow/menu/PPLGRZH0102?_r=0.6644871172745264", "社保", "http://fuwu.rsj.beijing.gov.cn/csibiz/indinfo/index.jsp", @@ -52,495 +49,390 @@ var Index = &ice.Context{Name: "mall", Help: "贸易中心", Commands: map[string]*ice.Command{ ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Load() - m.Cmd(ice.WEB_SPIDE, "add", "12306", m.Conf("railway", "meta.site")) }}, ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - m.Save("asset", "railway") + m.Save("asset") }}, - "spend": {Name: "spend", Help: "支出", List: kit.List( - kit.MDB_INPUT, "text", "name", "account", "figure", "key", - kit.MDB_INPUT, "text", "name", "to", "figure", "key", - kit.MDB_INPUT, "text", "name", "name", "figure", "key", - kit.MDB_INPUT, "button", "name", "记录", - kit.MDB_INPUT, "textarea", "name", "text", "figure", "key", - kit.MDB_INPUT, "text", "name", "value", "figure", "key", - kit.MDB_INPUT, "text", "name", "time", "figure", "date", - ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - if input(m, arg...) { - // 输入补全 - return - } - if len(arg) < 2 { - // 查看流水 - m.Cmdy("asset", arg) - return - } - // 添加流水 - amount := kit.Int(arg[4]) - m.Cmdy("asset", arg[0], "", "转出", arg[1], arg[2], -amount, "time", arg[5:]) - m.Cmdy("asset", arg[1], "", "转入", arg[0], arg[2], amount, "time", arg[5:]) - m.Cmdy("asset", arg[1], "", "支出", arg[2], arg[3], -amount, "time", arg[5:]) - m.Cmdy("asset", "流水", "", "支出", arg[2], arg[3], -amount, "time", arg[5:]) - }}, - "trans": {Name: "trans", Help: "转账", List: kit.List( - kit.MDB_INPUT, "text", "name", "account", "figure", "key", - kit.MDB_INPUT, "text", "name", "to", "figure", "key", - kit.MDB_INPUT, "text", "name", "name", "figure", "key", - kit.MDB_INPUT, "button", "name", "记录", - kit.MDB_INPUT, "textarea", "name", "text", "figure", "key", - kit.MDB_INPUT, "text", "name", "value", "figure", "key", - kit.MDB_INPUT, "text", "name", "time", "figure", "date", - ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - if input(m, arg...) { - // 输入补全 - return - } - if len(arg) < 2 { - // 查看流水 - m.Cmdy("asset", arg) - return - } - // 添加流水 - amount := kit.Int(arg[4]) - m.Cmdy("asset", arg[0], "", "转出", arg[1], arg[2], -amount, "time", arg[5:]) - m.Cmdy("asset", arg[1], "", "转入", arg[0], arg[2], amount, "time", arg[5:]) - m.Cmd("asset", "流水", "", "转出", arg[2], arg[3], -amount, "time", arg[5:]) - m.Cmd("asset", "流水", "", "转入", arg[2], arg[3], amount, "time", arg[5:]) - }}, - "bonus": {Name: "bonus", Help: "收入", List: kit.List( - kit.MDB_INPUT, "text", "name", "account", "figure", "key", - kit.MDB_INPUT, "text", "name", "name", "figure", "key", - kit.MDB_INPUT, "text", "name", "value", "figure", "key", - kit.MDB_INPUT, "button", "name", "记录", - kit.MDB_INPUT, "textarea", "name", "text", "figure", "key", - kit.MDB_INPUT, "text", "name", "time", "figure", "date", - ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - if input(m, arg...) { - // 输入补全 - return - } - if len(arg) < 2 { - // 查看流水 - m.Cmdy("asset", arg) - return - } - // 添加流水 - amount := kit.Int(arg[2]) - m.Cmdy("asset", arg[0], "", "收入", arg[1], arg[3], amount, "time", arg[4:]) - m.Cmdy("asset", "流水", "", "收入", arg[1], arg[3], amount, "time", arg[4:]) - }}, - "month": {Name: "month", Help: "工资", List: kit.List( - kit.MDB_INPUT, "text", "name", "month", - kit.MDB_INPUT, "text", "name", "value", "figure", "key", - kit.MDB_INPUT, "text", "name", "value", "figure", "key", - kit.MDB_INPUT, "button", "name", "计算", - kit.MDB_INPUT, "button", "name", "记录", - ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - // 输入补全 - if input(m, arg...) { - return - } - - data := map[string]int64{"个税方案": 6, "基本工资": 0, "个税": 0, - "公积金比例": 1200, "养老保险比例": 800, "医疗保险比例": 200, "失业保险比例": 20, "工伤保险比例": 2, "生育保险比例": 0, - "公积金金额": 0, "养老保险金额": 0, "医疗保险金额": 0, "失业保险金额": 0, "工伤保险金额": 0, "生育保险金额": 0, - - "企业公积金比例": 1200, "企业养老保险比例": 2000, "企业医疗保险比例": 1000, "企业失业保险比例": 100, "企业工伤保险比例": 30, "企业生育保险比例": 80, - "企业公积金金额": 0, "企业养老保险金额": 0, "企业医疗保险金额": 0, "企业失业保险金额": 0, "企业工伤保险金额": 0, "企业生育保险金额": 0, - } - - for i := 3; i < len(arg)-1; i += 2 { - if _, ok := data[arg[i]]; ok { - data[arg[i]] = kit.Int64(arg[i+1]) - arg[i] = "" - } - } - - data["养老保险比例"] = 725 - data["失业保险比例"] = 18 - - salary := kit.Int64(arg[1]) - data["个税"] = kit.Int64(arg[2]) - base := data["基本工资"] - if base == 0 { - base = salary - } - - // 五险一金 - amount := int64(0) - for _, k := range []string{"公积金", "养老保险", "医疗保险", "失业保险", "工伤保险"} { - m.Push("名目", k) - value := -base * kit.Int64(data[k+"比例"]) / 10000 - m.Info("%v %v: %v %v", base, k, base*kit.Int64(data[k+"比例"]), value) - if m.Push("比例", data[k+"比例"]); data[k+"金额"] == 0 { - if k == "医疗保险" { - value -= 300 - } - data[k+"金额"] = value - } else { - value = data[k+"金额"] - } - amount += value - m.Push("金额", data[k+"金额"]) - } - - // 企业五险一金 - company := int64(0) - for _, k := range []string{"企业公积金", "企业养老保险", "企业医疗保险", "企业失业保险", "企业工伤保险", "企业生育保险"} { - m.Push("名目", k) - value := -base * kit.Int64(data[k+"比例"]) / 10000 - if m.Push("比例", data[k+"比例"]); data[k+"金额"] == 0 { - data[k+"金额"] = value - } - company += -value - m.Push("金额", data[k+"金额"]) - } - m.Push("名目", "企业承担") - m.Push("比例", "") - m.Push("金额", company) - - // 其它津贴 - for i := 3; i < len(arg)-1; i += 2 { - if arg[i] != "" && data[arg[i]] == 0 { - m.Push("名目", arg[i]) - m.Push("比例", "") - m.Push("金额", arg[i+1]) - amount += kit.Int64(arg[i+1]) - } - } - salary += amount - - m.Push("名目", "税前收入") - m.Push("比例", "") - m.Push("金额", salary) - - tax, amount := int64(0), salary - if data["个税方案"] == 6 { - // 2011年个税法案 - month := []int64{ - 8350000, 4500, - 5850000, 3500, - 3850000, 3000, - 1250000, 2500, - 800000, 2000, - 500000, 1000, - 350000, 300, - } - - for i := 0; i < len(month); i += 2 { - if amount > month[i] { - tax, amount = tax+(amount-month[i])*month[i+1]/10000, month[i] - } - } - if data["个税"] != 0 { - tax = data["个税"] - } - m.Push("名目", "个税") - m.Push("比例", "") - m.Push("金额", tax) - - m.Push("名目", "税后收入") - m.Push("比例", "") - m.Push("金额", salary-tax) - } else { - // 2019年个税法案 - // year := []int{ - // 96000000, 4500, - // 66000000, 3500, - // 42000000, 3000, - // 30000000, 2500, - // 14400000, 2000, - // 3600000, 1000, - // 0, 300, - // } - } - - switch m.Option(ice.MSG_ACTION) { - case "计算": - case "记录": - // 收入 - m.Cmd("bonus", "工资", "企业承担", company, arg[0]) - m.Cmd("bonus", "工资", "基本工资", arg[1], arg[0]) - for i := 3; i < len(arg)-1; i += 2 { - if arg[i] != "" && data[arg[i]] == 0 { - m.Cmd("bonus", "工资", arg[i], arg[i+1], arg[0]) - } - } - - // 转账 - m.Cmd("trans", "工资", "公积金", -data["企业公积金金额"], arg[0]) - for _, k := range []string{"企业养老保险", "企业医疗保险", "企业失业保险", "企业工伤保险", "企业生育保险"} { - m.Cmd("trans", "工资", k, -data[k+"金额"], arg[0]) - } - m.Cmd("trans", "工资", "公积金", -data["公积金金额"], arg[0]) - for _, k := range []string{"养老保险", "医疗保险", "失业保险"} { - m.Cmd("trans", "工资", k, -data[k+"金额"], arg[0]) - } - - // 个税 - m.Cmd("trans", "工资", "个税", tax, arg[0]) - } - }}, - "asset": {Name: "asset account type name value", Help: []string{"资产", - "action save file [account [key value]]", - "action load file [account]", - }, List: kit.List( - kit.MDB_INPUT, "text", "name", "account", "action", "auto", - kit.MDB_INPUT, "text", "name", "id", "action", "auto", - kit.MDB_INPUT, "button", "name", "查看", "action", "auto", - kit.MDB_INPUT, "button", "name", "返回", "cb", "Last", - kit.MDB_INPUT, "button", "name", "保存", - ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - if m.Option("_action") == "保存" { - arg = []string{"action", "save"} - } - if len(arg) > 0 && arg[0] == "action" { - switch arg[1] { - case "modify": - // 修改数据 - m.Richs(cmd, nil, m.Option("account"), func(key string, account map[string]interface{}) { - m.Grows(cmd, kit.Keys("hash", key), "id", arg[5], func(index int, current map[string]interface{}) { - m.Log(ice.LOG_MODIFY, "%s: %d %s: %s->%s", key, index, kit.Value(current, arg[2]), arg[2], arg[3]) - kit.Value(current, arg[2], arg[3]) - }) - }) - - case "save": - // 保存数据 - m.Option("cache.limit", -2) - if f, p, e := kit.Create(kit.Select("usr/local/asset.csv", arg, 2)); m.Assert(e) { - defer f.Close() - - w := csv.NewWriter(f) - defer w.Flush() - - w.Write([]string{"时间", "收支类型", "账目分类", "备注", "金额", "账户"}) - m.Richs(cmd, nil, kit.Select("*", arg, 3), func(key string, account map[string]interface{}) { - if kit.Format(kit.Value(account, "meta.account")) == "流水" { - return - } - m.Grows(cmd, kit.Keys("hash", key), kit.Select("", arg, 4), kit.Select("", arg, 5), func(index int, current map[string]interface{}) { - w.Write([]string{ - kit.Format(current["time"]), - kit.Format(current["type"]), - kit.Format(current["name"]), - kit.Format(current["text"]), - kit.Format(current["value"]), - kit.Format(kit.Value(account, "meta.account")), - }) - }) - }) - m.Log(ice.LOG_EXPORT, "%s", p) - m.Cmdy(ice.WEB_STORY, "catch", "csv", p) - } - - case "load": - // 加载数据 - m.CSV(m.Cmdx("nfs.cat", arg[2])).Table(func(index int, data map[string]string, head []string) { - v, _ := strconv.ParseFloat(data["金额"], 64) - for _, account := range []string{kit.Select(data["账户"], arg, 3), "流水"} { - // amount := kit.Int(v * 100) - item := kit.Dict( - "type", data["收支类型"], "name", data["账目分类"], "text", data["备注"], "value", kit.Int(v), - "time", data["时间"], "extra", kit.UnMarshal(data["extra"]), - ) - - if m.Richs(cmd, nil, account, nil) == nil { - // 添加账户 - m.Log(ice.LOG_CREATE, "account: %s", account) - m.Rich(cmd, nil, kit.Data("account", account, "amount", "0", "bonus", "0", "spend", "0")) - } - - m.Richs(cmd, nil, account, func(key string, value map[string]interface{}) { - // 账户流水 - m.Grow(cmd, kit.Keys("hash", key), item) - - // 账户结余 - amount := kit.Int(kit.Value(value, "meta.amount")) + kit.Int(v) - m.Log(ice.LOG_INSERT, "%s: %v", key, amount) - kit.Value(value, "meta.amount", amount) - - switch data["收支类型"] { - case "收入": - bonus := kit.Int(kit.Value(value, "meta.bonus")) + kit.Int(v) - kit.Value(value, "meta.bonus", bonus) - case "支出": - spend := kit.Int(kit.Value(value, "meta.spend")) + kit.Int(v) - kit.Value(value, "meta.spend", spend) - } - }) - } - }) - } - return - } - - if len(arg) == 0 { - // 账户列表 - m.Richs(cmd, nil, "*", func(key string, value map[string]interface{}) { - m.Push(key, value["meta"], []string{"account", "count", "amount", "bonus", "spend"}) - }) - m.Sort("amount", "int_r") - return - } - - if len(arg) > 5 && m.Richs(cmd, nil, arg[0], nil) == nil { - // 添加账户 - m.Rich(cmd, nil, kit.Data("account", arg[0], "amount", "0", "bonus", "0", "spend", "0")) - m.Log(ice.LOG_CREATE, "account: %s", arg[0]) - } - - field := []string{"time", "id", "value", "type", "name", "text"} - m.Richs(cmd, nil, arg[0], func(key string, value map[string]interface{}) { - if len(arg) == 1 { - // 消费流水 - m.Grows(cmd, kit.Keys("hash", key), "", "", func(index int, value map[string]interface{}) { - m.Push("", value, field) - }) - m.Sort("id", "int_r") + "spend": {Name: "spend account=@key to=@key name=@key 记录:button text:textarea value=@key time=@date", + Help: "支出", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + if input(m, arg...) { + // 输入补全 return } - if len(arg) == 2 { - // 消费详情 - m.Grows(cmd, kit.Keys("hash", key), "id", arg[1], func(index int, value map[string]interface{}) { - m.Push("detail", value) - }) + if len(arg) < 2 { + // 查看流水 + m.Cmdy("asset", arg) return } - if len(arg) < 6 { - // 消费查询 - name, value := "type", arg[2] - switch len(arg) { - case 3: - // 消费分类 - name, value = "type", arg[2] - case 4: - // 消费对象 - name, value = "name", arg[3] - case 5: - // 消费备注 - name, value = "text", arg[4] - } - m.Grows(cmd, kit.Keys("hash", key), name, value, func(index int, value map[string]interface{}) { - m.Push("", value, field) - }) - m.Sort("id", "int_r") - return - } - - // 词汇统计 - web.Count(m, cmd, "meta.word.type", arg[2]) - web.Count(m, cmd, "meta.word.name", arg[3]) - web.Count(m, cmd, "meta.word.text", arg[4]) - web.Count(m, cmd, "meta.word.value", strings.TrimPrefix(arg[5], "-")) - - // 数据结构 - amount := kit.Int(arg[5]) - extra := kit.Dict() - data := kit.Dict( - kit.MDB_TYPE, arg[2], kit.MDB_NAME, arg[3], kit.MDB_TEXT, arg[4], - "value", amount, "extra", extra, - ) - for i := 6; i < len(arg)-1; i += 2 { - switch arg[i] { - case kit.MDB_TIME: - kit.Value(data, arg[i], arg[i+1]) - default: - kit.Value(extra, arg[i], arg[i+1]) - } - } // 添加流水 - n := m.Grow(cmd, kit.Keys(kit.MDB_HASH, key), data) - - // 账户结余 - total := kit.Int(kit.Value(value, "meta.amount")) + amount - m.Log(ice.LOG_INSERT, "account: %s total: %v", arg[0], total) - kit.Value(value, "meta.amount", total) - m.Echo("%s: %d %d\n", arg[0], n, total) - - // 收支统计 - switch data["type"] { - case "收入": - bonus := kit.Int(kit.Value(value, "meta.bonus")) + amount - kit.Value(value, "meta.bonus", bonus) - case "支出": - spend := kit.Int(kit.Value(value, "meta.spend")) + amount - kit.Value(value, "meta.spend", spend) + amount := kit.Int(arg[4]) + m.Cmdy("asset", arg[0], "", "转出", arg[1], arg[2], -amount, "time", arg[5:]) + m.Cmdy("asset", arg[1], "", "转入", arg[0], arg[2], amount, "time", arg[5:]) + m.Cmdy("asset", arg[1], "", "支出", arg[2], arg[3], -amount, "time", arg[5:]) + m.Cmdy("asset", "流水", "", "支出", arg[2], arg[3], -amount, "time", arg[5:]) + }}, + "trans": {Name: "trans account=@key to=@key name=@key 记录:button text:textarea value=@key time=@date", + Help: "转账", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + if input(m, arg...) { + // 输入补全 + return } - }) - }}, - - "railway": &ice.Command{Name: "railway", Help: "12306", List: kit.List( - kit.MDB_INPUT, "text", "name", "date", "figure", "date", - kit.MDB_INPUT, "text", "name", "from", "value", "北京", "figure", "city", - kit.MDB_INPUT, "text", "name", "to", "value", "曲阜", "figure", "city", - kit.MDB_INPUT, "button", "name", "查询", - ), Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) { - if !m.Confs("railway", "meta.place") { - list := strings.Split(strings.TrimPrefix(m.Cmdx(ice.WEB_SPIDE, "12306", "raw", "GET", "/otn/resources/js/framework/station_name.js?station_version=1.9090"), "var statuion_names ='"), "|") - for i := 0; i < len(list)-5; i += 5 { - m.Conf("railway", kit.Keys("meta.place", list[i+1]), list[i+2]) + if len(arg) < 2 { + // 查看流水 + m.Cmdy("asset", arg) + return + } + // 添加流水 + amount := kit.Int(arg[4]) + m.Cmdy("asset", arg[0], "", "转出", arg[1], arg[2], -amount, "time", arg[5:]) + m.Cmdy("asset", arg[1], "", "转入", arg[0], arg[2], amount, "time", arg[5:]) + m.Cmd("asset", "流水", "", "转出", arg[2], arg[3], -amount, "time", arg[5:]) + m.Cmd("asset", "流水", "", "转入", arg[2], arg[3], amount, "time", arg[5:]) + }}, + "bonus": {Name: "bonus account=@key name=@key value=@key 记录:button text:textarea time=@date", + Help: "收入", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + if input(m, arg...) { + // 输入补全 + return + } + if len(arg) < 2 { + // 查看流水 + m.Cmdy("asset", arg) + return + } + // 添加流水 + amount := kit.Int(arg[2]) + m.Cmdy("asset", arg[0], "", "收入", arg[1], arg[3], amount, "time", arg[4:]) + m.Cmdy("asset", "流水", "", "收入", arg[1], arg[3], amount, "time", arg[4:]) + }}, + "month": {Name: "month month value value 计算:button 记录:button", + Help: "工资", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + // 输入补全 + if input(m, arg...) { + return } - } - date := strings.Split(m.Time("24h"), " ")[0] - if len(arg) > 0 { - date, arg = arg[0], arg[1:] - } - date = strings.Split(date, " ")[0] - from := "北京" - if len(arg) > 0 { - from, arg = arg[0], arg[1:] - } - from_code := m.Conf("railway", kit.Keys("meta.place", from)) - to := "曲阜" - if len(arg) > 0 { - to, arg = arg[0], arg[1:] - } - to_code := m.Conf("railway", kit.Keys("meta.place", to)) + data := map[string]int64{"个税方案": 6, "基本工资": 0, "个税": 0, + "公积金比例": 1200, "养老保险比例": 800, "医疗保险比例": 200, "失业保险比例": 20, "工伤保险比例": 2, "生育保险比例": 0, + "公积金金额": 0, "养老保险金额": 0, "医疗保险金额": 0, "失业保险金额": 0, "工伤保险金额": 0, "生育保险金额": 0, - m.Echo("%s->%s %s\n", from, to, date) + "企业公积金比例": 1200, "企业养老保险比例": 2000, "企业医疗保险比例": 1000, "企业失业保险比例": 100, "企业工伤保险比例": 30, "企业生育保险比例": 80, + "企业公积金金额": 0, "企业养老保险金额": 0, "企业医疗保险金额": 0, "企业失业保险金额": 0, "企业工伤保险金额": 0, "企业生育保险金额": 0, + } - if len(arg) > 0 { - m.Cmdy(ice.WEB_SPIDE, "12306", "raw", "GET", fmt.Sprintf("/otn/czxx/queryByTrainNo?train_no=%s&from_station_telecode=%s&to_station_telecode=%s&depart_date=%s", - arg[0], from_code, to_code, date)) - return - } + for i := 3; i < len(arg)-1; i += 2 { + if _, ok := data[arg[i]]; ok { + data[arg[i]] = kit.Int64(arg[i+1]) + arg[i] = "" + } + } - m.Cmd(ice.WEB_SPIDE, "12306", "GET", fmt.Sprintf("/otn/leftTicket/init?linktypeid=dc&fs=%s,%s&ts=%s,%s&date=%s&flag=N,N,Y", - from, from_code, to, to_code, date)) - m.Cmd(ice.WEB_SPIDE, "12306", "GET", fmt.Sprintf("/otn/leftTicket/queryZ?leftTicketDTO.train_date=%s&leftTicketDTO.from_station=%s&leftTicketDTO.to_station=%s&purpose_codes=ADULT", - date, from_code, to_code)).Table(func(index int, value map[string]string, head []string) { - kit.Fetch(kit.Value(kit.UnMarshal(value["data"]), "result"), func(index int, value string) { - fields := strings.Split(value, "|") - m.Push("车次", fields[3]) - m.Push("出发", fields[8]) - m.Push("到站", fields[9]) - m.Push("时长", fields[10]) - m.Push("二等座", fields[30]) - m.Push("一等座", fields[31]) + data["养老保险比例"] = 725 + data["失业保险比例"] = 18 + + salary := kit.Int64(arg[1]) + data["个税"] = kit.Int64(arg[2]) + base := data["基本工资"] + if base == 0 { + base = salary + } + + // 五险一金 + amount := int64(0) + for _, k := range []string{"公积金", "养老保险", "医疗保险", "失业保险", "工伤保险"} { + m.Push("名目", k) + value := -base * kit.Int64(data[k+"比例"]) / 10000 + m.Info("%v %v: %v %v", base, k, base*kit.Int64(data[k+"比例"]), value) + if m.Push("比例", data[k+"比例"]); data[k+"金额"] == 0 { + if k == "医疗保险" { + value -= 300 + } + data[k+"金额"] = value + } else { + value = data[k+"金额"] + } + amount += value + m.Push("金额", data[k+"金额"]) + } + + // 企业五险一金 + company := int64(0) + for _, k := range []string{"企业公积金", "企业养老保险", "企业医疗保险", "企业失业保险", "企业工伤保险", "企业生育保险"} { + m.Push("名目", k) + value := -base * kit.Int64(data[k+"比例"]) / 10000 + if m.Push("比例", data[k+"比例"]); data[k+"金额"] == 0 { + data[k+"金额"] = value + } + company += -value + m.Push("金额", data[k+"金额"]) + } + m.Push("名目", "企业承担") + m.Push("比例", "") + m.Push("金额", company) + + // 其它津贴 + for i := 3; i < len(arg)-1; i += 2 { + if arg[i] != "" && data[arg[i]] == 0 { + m.Push("名目", arg[i]) + m.Push("比例", "") + m.Push("金额", arg[i+1]) + amount += kit.Int64(arg[i+1]) + } + } + salary += amount + + m.Push("名目", "税前收入") + m.Push("比例", "") + m.Push("金额", salary) + + tax, amount := int64(0), salary + if data["个税方案"] == 6 { + // 2011年个税法案 + month := []int64{ + 8350000, 4500, + 5850000, 3500, + 3850000, 3000, + 1250000, 2500, + 800000, 2000, + 500000, 1000, + 350000, 300, + } + + for i := 0; i < len(month); i += 2 { + if amount > month[i] { + tax, amount = tax+(amount-month[i])*month[i+1]/10000, month[i] + } + } + if data["个税"] != 0 { + tax = data["个税"] + } + m.Push("名目", "个税") + m.Push("比例", "") + m.Push("金额", tax) + + m.Push("名目", "税后收入") + m.Push("比例", "") + m.Push("金额", salary-tax) + } else { + // 2019年个税法案 + // year := []int{ + // 96000000, 4500, + // 66000000, 3500, + // 42000000, 3000, + // 30000000, 2500, + // 14400000, 2000, + // 3600000, 1000, + // 0, 300, + // } + } + + switch m.Option(ice.MSG_ACTION) { + case "计算": + case "记录": + // 收入 + m.Cmd("bonus", "工资", "企业承担", company, arg[0]) + m.Cmd("bonus", "工资", "基本工资", arg[1], arg[0]) + for i := 3; i < len(arg)-1; i += 2 { + if arg[i] != "" && data[arg[i]] == 0 { + m.Cmd("bonus", "工资", arg[i], arg[i+1], arg[0]) + } + } + + // 转账 + m.Cmd("trans", "工资", "公积金", -data["企业公积金金额"], arg[0]) + for _, k := range []string{"企业养老保险", "企业医疗保险", "企业失业保险", "企业工伤保险", "企业生育保险"} { + m.Cmd("trans", "工资", k, -data[k+"金额"], arg[0]) + } + m.Cmd("trans", "工资", "公积金", -data["公积金金额"], arg[0]) + for _, k := range []string{"养老保险", "医疗保险", "失业保险"} { + m.Cmd("trans", "工资", k, -data[k+"金额"], arg[0]) + } + + // 个税 + m.Cmd("trans", "工资", "个税", tax, arg[0]) + } + }}, + "asset": {Name: "asset account=auto id=auto auto", + Help: "资产", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + if m.Option("_action") == "保存" { + arg = []string{"action", "save"} + } + if len(arg) > 0 && arg[0] == "action" { + switch arg[1] { + case "modify": + // 修改数据 + m.Richs(cmd, nil, m.Option("account"), func(key string, account map[string]interface{}) { + m.Grows(cmd, kit.Keys("hash", key), "id", arg[5], func(index int, current map[string]interface{}) { + m.Log(ice.LOG_MODIFY, "%s: %d %s: %s->%s", key, index, kit.Value(current, arg[2]), arg[2], arg[3]) + kit.Value(current, arg[2], arg[3]) + }) + }) + + case "save": + // 保存数据 + m.Option("cache.limit", -2) + if f, p, e := kit.Create(kit.Select("usr/local/asset.csv", arg, 2)); m.Assert(e) { + defer f.Close() + + w := csv.NewWriter(f) + defer w.Flush() + + w.Write([]string{"时间", "收支类型", "账目分类", "备注", "金额", "账户"}) + m.Richs(cmd, nil, kit.Select("*", arg, 3), func(key string, account map[string]interface{}) { + if kit.Format(kit.Value(account, "meta.account")) == "流水" { + return + } + m.Grows(cmd, kit.Keys("hash", key), kit.Select("", arg, 4), kit.Select("", arg, 5), func(index int, current map[string]interface{}) { + w.Write([]string{ + kit.Format(current["time"]), + kit.Format(current["type"]), + kit.Format(current["name"]), + kit.Format(current["text"]), + kit.Format(current["value"]), + kit.Format(kit.Value(account, "meta.account")), + }) + }) + }) + m.Log(ice.LOG_EXPORT, "%s", p) + m.Cmdy(ice.WEB_STORY, "catch", "csv", p) + } + + case "load": + // 加载数据 + m.CSV(m.Cmdx("nfs.cat", arg[2])).Table(func(index int, data map[string]string, head []string) { + v, _ := strconv.ParseFloat(data["金额"], 64) + for _, account := range []string{kit.Select(data["账户"], arg, 3), "流水"} { + // amount := kit.Int(v * 100) + item := kit.Dict( + "type", data["收支类型"], "name", data["账目分类"], "text", data["备注"], "value", kit.Int(v), + "time", data["时间"], "extra", kit.UnMarshal(data["extra"]), + ) + + if m.Richs(cmd, nil, account, nil) == nil { + // 添加账户 + m.Log(ice.LOG_CREATE, "account: %s", account) + m.Rich(cmd, nil, kit.Data("account", account, "amount", "0", "bonus", "0", "spend", "0")) + } + + m.Richs(cmd, nil, account, func(key string, value map[string]interface{}) { + // 账户流水 + m.Grow(cmd, kit.Keys("hash", key), item) + + // 账户结余 + amount := kit.Int(kit.Value(value, "meta.amount")) + kit.Int(v) + m.Log(ice.LOG_INSERT, "%s: %v", key, amount) + kit.Value(value, "meta.amount", amount) + + switch data["收支类型"] { + case "收入": + bonus := kit.Int(kit.Value(value, "meta.bonus")) + kit.Int(v) + kit.Value(value, "meta.bonus", bonus) + case "支出": + spend := kit.Int(kit.Value(value, "meta.spend")) + kit.Int(v) + kit.Value(value, "meta.spend", spend) + } + }) + } + }) + } + return + } + + if len(arg) == 0 { + // 账户列表 + m.Richs(cmd, nil, "*", func(key string, value map[string]interface{}) { + m.Push(key, value["meta"], []string{"account", "count", "amount", "bonus", "spend"}) + }) + m.Sort("amount", "int_r") + return + } + + if len(arg) > 5 && m.Richs(cmd, nil, arg[0], nil) == nil { + // 添加账户 + m.Rich(cmd, nil, kit.Data("account", arg[0], "amount", "0", "bonus", "0", "spend", "0")) + m.Log(ice.LOG_CREATE, "account: %s", arg[0]) + } + + field := []string{"time", "id", "value", "type", "name", "text"} + m.Richs(cmd, nil, arg[0], func(key string, value map[string]interface{}) { + if len(arg) == 1 { + // 消费流水 + m.Grows(cmd, kit.Keys("hash", key), "", "", func(index int, value map[string]interface{}) { + m.Push("", value, field) + }) + m.Sort("id", "int_r") + return + } + if len(arg) == 2 { + // 消费详情 + m.Grows(cmd, kit.Keys("hash", key), "id", arg[1], func(index int, value map[string]interface{}) { + m.Push("detail", value) + }) + return + } + if len(arg) < 6 { + // 消费查询 + name, value := "type", arg[2] + switch len(arg) { + case 3: + // 消费分类 + name, value = "type", arg[2] + case 4: + // 消费对象 + name, value = "name", arg[3] + case 5: + // 消费备注 + name, value = "text", arg[4] + } + m.Grows(cmd, kit.Keys("hash", key), name, value, func(index int, value map[string]interface{}) { + m.Push("", value, field) + }) + m.Sort("id", "int_r") + return + } + + // 词汇统计 + web.Count(m, cmd, "meta.word.type", arg[2]) + web.Count(m, cmd, "meta.word.name", arg[3]) + web.Count(m, cmd, "meta.word.text", arg[4]) + web.Count(m, cmd, "meta.word.value", strings.TrimPrefix(arg[5], "-")) + + // 数据结构 + amount := kit.Int(arg[5]) + extra := kit.Dict() + data := kit.Dict( + kit.MDB_TYPE, arg[2], kit.MDB_NAME, arg[3], kit.MDB_TEXT, arg[4], + "value", amount, "extra", extra, + ) + for i := 6; i < len(arg)-1; i += 2 { + switch arg[i] { + case kit.MDB_TIME: + kit.Value(data, arg[i], arg[i+1]) + default: + kit.Value(extra, arg[i], arg[i+1]) + } + } + // 添加流水 + n := m.Grow(cmd, kit.Keys(kit.MDB_HASH, key), data) + + // 账户结余 + total := kit.Int(kit.Value(value, "meta.amount")) + amount + m.Log(ice.LOG_INSERT, "account: %s total: %v", arg[0], total) + kit.Value(value, "meta.amount", total) + m.Echo("%s: %d %d\n", arg[0], n, total) + + // 收支统计 + switch data["type"] { + case "收入": + bonus := kit.Int(kit.Value(value, "meta.bonus")) + amount + kit.Value(value, "meta.bonus", bonus) + case "支出": + spend := kit.Int(kit.Value(value, "meta.spend")) + amount + kit.Value(value, "meta.spend", spend) + } }) - }) - }}, - "passcode": &ice.Command{Name: "passcode", Help: "passcode", Meta: kit.Dict("active", "mall/input"), Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) { - prefix := []string{ice.WEB_SPIDE, "12306"} - if len(arg) == 0 { - m.Cmd(prefix, "raw", "/passport/web/auth/uamtk-static", "form", "appid", "otn") - m.Cmd(prefix, "raw", "GET", "/otn/HttpZF/GetJS") - m.Cmd(prefix, "raw", "/otn/login/conf") - - m.Cmdy(prefix, "GET", fmt.Sprintf("/passport/captcha/captcha-image64?login_site=E&module=login&rand=sjrand")) - return - } - - switch arg[0] { - case "check": - m.Cmdy(prefix, "GET", fmt.Sprintf("/passport/captcha/captcha-check?login_site=E&rand=sjrand&answer=%s", arg[1])) - case "login": - m.Cmdy(prefix, "raw", "/passport/web/login", "form", "username", arg[1], "password", arg[2], "answer", arg[3], "appid", "otn") - } - }}, + }}, }, } diff --git a/core/team/team.go b/core/team/team.go index ddda224c..55ee137a 100644 --- a/core/team/team.go +++ b/core/team/team.go @@ -35,8 +35,7 @@ var Index = &ice.Context{Name: "team", Help: "团队中心", Configs: map[string]*ice.Config{ "task": {Name: "task", Help: "任务", Value: kit.Data(kit.MDB_SHORT, "zone")}, "plan": {Name: "plan", Help: "计划", Value: kit.Data(kit.MDB_SHORT, "zone", - "head", []interface{}{"周日", "周一", "周二", "周三", "周四", "周五", "周六"}, - "template", kit.Dict( + "head", []interface{}{"周日", "周一", "周二", "周三", "周四", "周五", "周六"}, "template", kit.Dict( "day", `
{{.status}} {{.name}}: {{.text}}
`, "week", `
{{.name}}
`, "month", `
{{.name}}
`, @@ -52,13 +51,7 @@ var Index = &ice.Context{Name: "team", Help: "团队中心", m.Save("task") }}, - "task": {Name: "task [zone [id [type [name [text args...]]]]]", Help: "任务", List: kit.List( - kit.MDB_INPUT, "text", "name", "zone", "action", "auto", - kit.MDB_INPUT, "text", "name", "id", "action", "auto", - kit.MDB_INPUT, "button", "name", "查看", "action", "auto", - kit.MDB_INPUT, "button", "name", "返回", "cb", "Last", - kit.MDB_INPUT, "button", "name", "保存", - ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + "task": {Name: "task [zone=auto [id=auto]] auto", Help: "任务", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if m.Option("_action") == "保存" { arg = []string{"action", "export"} } @@ -145,10 +138,40 @@ var Index = &ice.Context{Name: "team", Help: "团队中心", return } - if len(arg) == 0 { - // 分类列表 - m.Richs(cmd, nil, "*", func(key string, value map[string]interface{}) { - m.Push(key, value["meta"], []string{"time", "count", "zone"}) + if len(arg) < 5 { + m.Richs(cmd, nil, kit.Select("*", arg, 0), func(key string, value map[string]interface{}) { + if len(arg) == 0 { + // 分类列表 + m.Push(key, value["meta"], []string{"time", "count", "zone"}) + return + } + + field := []string{"begin_time", "id", "status", "type", "name", "text"} + if len(arg) == 1 { + // 任务列表 + m.Grows(cmd, kit.Keys("hash", key), "", "", func(index int, value map[string]interface{}) { + m.Push("", value, field) + }) + } else if len(arg) == 2 { + // 任务详情 + m.Grows(cmd, kit.Keys("hash", key), "id", arg[1], func(index int, value map[string]interface{}) { + m.Push("detail", value) + }) + } else { + name, value := "type", arg[2] + switch len(arg) { + case 3: + // 分类查询 + name, value = "type", arg[2] + case 4: + // 名称查询 + name, value = "name", arg[3] + } + m.Grows(cmd, kit.Keys("hash", key), name, value, func(index int, value map[string]interface{}) { + m.Push("", value, field) + }) + } + m.Sort("time", "time_r") }) return } @@ -159,44 +182,7 @@ var Index = &ice.Context{Name: "team", Help: "团队中心", m.Log(ice.LOG_CREATE, "zone: %s", arg[0]) } - field := []string{"begin_time", "id", "status", "type", "name", "text"} m.Richs(cmd, nil, arg[0], func(key string, value map[string]interface{}) { - if len(arg) == 1 { - // 任务列表 - m.Grows(cmd, kit.Keys("hash", key), "", "", func(index int, value map[string]interface{}) { - m.Push("", value, field) - }) - m.Sort("time", "time_r") - return - } - - if len(arg) == 2 { - // 任务详情 - m.Grows(cmd, kit.Keys("hash", key), "id", arg[1], func(index int, value map[string]interface{}) { - m.Push("detail", value) - }) - m.Sort("time", "time_r") - return - } - - if len(arg) < 5 { - // 任务查询 - name, value := "type", arg[2] - switch len(arg) { - case 3: - // 分类查询 - name, value = "type", arg[2] - case 4: - // 名称查询 - name, value = "name", arg[3] - } - m.Grows(cmd, kit.Keys("hash", key), name, value, func(index int, value map[string]interface{}) { - m.Push("", value, field) - }) - m.Sort("time", "time_r") - return - } - // 词汇统计 web.Count(m, cmd, "meta.word.type", arg[2]) web.Count(m, cmd, "meta.word.name", arg[3]) @@ -225,13 +211,8 @@ var Index = &ice.Context{Name: "team", Help: "团队中心", m.Echo("%s: %d", kit.Value(value, "meta.zone"), n) }) }}, - "plan": {Name: "plan day|week|month|year", Help: "计划", Meta: kit.Dict( + "plan": {Name: "plan scale:select=day|week|month|year begin_time=@date end_time=@date auto", Help: "计划", Meta: kit.Dict( "display", "team/plan", "detail", []string{"process", "finish", "cancel"}, - ), List: kit.List( - kit.MDB_INPUT, "select", "name", "scale", "value", "day", "values", []string{"day", "week", "month", "months", "year", "long"}, "action", "auto", - kit.MDB_INPUT, "text", "name", "begin_time", "figure", "date", "action", "auto", - kit.MDB_INPUT, "text", "name", "end_time", "figure", "date", "action", "auto", - kit.MDB_INPUT, "button", "name", "查看", "action", "auto", ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { // 起始日期 first := time.Now() @@ -423,11 +404,7 @@ var Index = &ice.Context{Name: "team", Help: "团队中心", m.Sort("year", "int") } }}, - "stat": {Name: "stat", Help: "统计", List: kit.List( - kit.MDB_INPUT, "text", "name", "begin_time", "figure", "date", "action", "auto", - kit.MDB_INPUT, "text", "name", "end_time", "figure", "date", "action", "auto", - kit.MDB_INPUT, "button", "name", "查看", "action", "auto", - ), Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) { + "stat": {Name: "stat begin_time=@date end_time=@date auto", Help: "统计", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) { begin_time := kit.Time(kit.Select("1990-07-30", arg, 0)) end_time := kit.Time(kit.Select("1990-07-30", arg, 1)) now_time := kit.Time(m.Time()) @@ -473,14 +450,7 @@ var Index = &ice.Context{Name: "team", Help: "团队中心", m.Push("max", kit.FmtTime(int64(stat["max"])*int64(time.Second))) }) }}, - "miss": {Name: "miss zone type name text", Help: "任务", List: kit.List( - kit.MDB_INPUT, "text", "name", "zone", "figure", "key", "action", "auto", - kit.MDB_INPUT, "text", "name", "type", "figure", "key", - kit.MDB_INPUT, "text", "name", "name", "figure", "key", - kit.MDB_INPUT, "button", "name", "添加", - kit.MDB_INPUT, "textarea", "name", "text", - kit.MDB_INPUT, "text", "name", "begin_time", "figure", "date", "position", "opts", - ), Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) { + "miss": {Name: "miss zone=@key type=@key name=@key 添加:button text:textarea @begin_time=@date", Help: "任务", Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) { if len(arg) > 0 && arg[0] == "action" { switch arg[1] { case "input": diff --git a/core/wiki/wiki.go b/core/wiki/wiki.go index ea9a0c05..9924c8fc 100644 --- a/core/wiki/wiki.go +++ b/core/wiki/wiki.go @@ -1,15 +1,12 @@ package wiki import ( - "github.com/gomarkdown/markdown" "github.com/shylinux/icebergs" _ "github.com/shylinux/icebergs/base" "github.com/shylinux/icebergs/base/web" "github.com/shylinux/toolkits" "fmt" - "io/ioutil" - "math/rand" "os" "path" "strings" @@ -36,10 +33,6 @@ func reply(m *ice.Message, cmd string, arg ...string) bool { var Index = &ice.Context{Name: "wiki", Help: "文档中心", Caches: map[string]*ice.Cache{}, Configs: map[string]*ice.Config{ - "note": {Name: "note", Help: "笔记", Value: kit.Data( - "path", "", "head", "time size line path", - )}, - "title": {Name: "title", Help: "标题", Value: kit.Data("template", title)}, "brief": {Name: "brief", Help: "摘要", Value: kit.Data("template", brief)}, "refer": {Name: "refer", Help: "参考", Value: kit.Data("template", refer)}, @@ -47,7 +40,7 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心", "local": {Name: "local", Help: "文件", Value: kit.Data("template", local)}, "shell": {Name: "shell", Help: "命令", Value: kit.Data("template", shell)}, - "field": {Name: "shell", Help: "命令", Value: kit.Data("template", field, + "field": {Name: "field", Help: "插件", Value: kit.Data("template", field, "some", kit.Dict("simple", kit.Dict( "inputs", kit.List( kit.MDB_INPUT, "text", "name", "name", @@ -62,7 +55,9 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心", "stack": {Name: "stack", Help: "结构", Value: kit.Data("template", stack)}, "chart": {Name: "chart", Help: "绘图", Value: kit.Data("template", prefix, "suffix", ``)}, - "draw": {Name: "draw", Help: "思维导图", Value: kit.Data(kit.MDB_SHORT, "name", "path", "", "regs", ".*\\.svg", "prefix", ``, "suffix", ``)}, + "draw": {Name: "draw", Help: "思维导图", Value: kit.Data(kit.MDB_SHORT, "name", "path", "", "regs", ".*\\.svg", + "prefix", ``, "suffix", ``, + )}, "data": {Name: "data", Help: "数据表格", Value: kit.Data(kit.MDB_SHORT, "name", "path", "", "regs", ".*\\.csv")}, "word": {Name: "word", Help: "语言文字", Value: kit.Data(kit.MDB_SHORT, "name", "path", "", "regs", ".*\\.shy", "alias", map[string]interface{}{ @@ -86,28 +81,6 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心", m.Save("feel") }}, - "note": {Name: "note file", Help: "文档", Meta: kit.Dict("display", "inner"), List: kit.List( - kit.MDB_INPUT, "text", "name", "path", "value", "README.md", "action", "auto", - kit.MDB_INPUT, "button", "name", "执行", "action", "auto", - kit.MDB_INPUT, "button", "name", "返回", "cb", "Last", - ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - if len(arg) > 0 && strings.HasSuffix(arg[0], ".md") { - arg[0] = path.Join(m.Conf("note", "meta.path"), arg[0]) - } - m.Cmdy(kit.Select("_tree", "_text", len(arg) > 0 && strings.HasSuffix(arg[0], ".md")), arg) - }}, - "_tree": {Name: "_tree [path [true]]", Help: "文库", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - m.Option("dir_reg", ".*\\.md") - m.Option("dir_deep", kit.Select("", arg, 1)) - m.Cmdy("nfs.dir", kit.Select(m.Conf("note", "meta.path"), arg, 0), m.Conf("note", "meta.head")) - }}, - "_text": {Name: "_text file", Help: "文章", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - if b, e := ioutil.ReadFile(arg[0]); m.Assert(e) { - data := markdown.ToHTML(b, nil, nil) - m.Echo(string(data)) - } - }}, - "title": {Name: "title [chapter|section|endmenu|premenu] text", Help: "标题", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { title, _ := m.Optionv("title").(map[string]int) switch arg[0] { @@ -161,6 +134,7 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心", m.Option(kit.MDB_TYPE, cmd) m.Option(kit.MDB_NAME, arg[0]) m.Option(kit.MDB_TEXT, arg[1]) + m.Render(ice.RENDER_TEMPLATE, m.Conf(cmd, "meta.template")) }}, "refer": {Name: "refer name text", Help: "参考", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { @@ -187,6 +161,7 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心", m.Option(kit.MDB_TYPE, cmd) m.Option(kit.MDB_NAME, arg[0]) m.Option(kit.MDB_TEXT, arg[1]) + m.Optionv("list", kit.Split(arg[1], "\n")) m.Render(ice.RENDER_TEMPLATE, m.Conf(cmd, "meta.template")) }}, @@ -195,8 +170,8 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心", m.Option(kit.MDB_TYPE, cmd) m.Option(kit.MDB_NAME, arg[0]) m.Option(kit.MDB_TEXT, arg[1]) - m.Option("input", m.Cmdx("nfs.cat", arg[1])) + m.Option("input", m.Cmdx("nfs.cat", arg[1])) switch ls := strings.Split(arg[1], "."); ls[len(ls)-1] { case "csv": list := []string{""} @@ -220,22 +195,13 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心", } m.Render(ice.RENDER_TEMPLATE, m.Conf(cmd, "meta.template")) }}, - "shell": {Name: "shell name dir cmd", Help: "命令", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + "shell": {Name: "shell name text", Help: "命令", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Option(kit.MDB_TYPE, cmd) m.Option(kit.MDB_NAME, arg[0]) - m.Option("cmd_dir", arg[1]) + m.Option(kit.MDB_TEXT, arg[1]) - input, output := "", "" - switch arg = arg[2:]; arg[0] { - case "install", "compile": - input = strings.Join(arg[1:], " ") - default: - input = strings.Join(arg, " ") - output = m.Cmdx(ice.CLI_SYSTEM, "sh", "-c", input) - } - - m.Option("input", input) - m.Option("output", output) + m.Option("input", strings.Join(arg[1:], " ")) + m.Option("output", m.Cmdx(ice.CLI_SYSTEM, "sh", "-c", m.Option("input"))) m.Render(ice.RENDER_TEMPLATE, m.Conf(cmd, "meta.template")) }}, "field": {Name: "field name text", Help: "插件", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { @@ -268,6 +234,7 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心", m.Option(kit.MDB_TYPE, cmd) m.Option(kit.MDB_NAME, arg[0]) m.Option(kit.MDB_TEXT, arg[1]) + m.Optionv("list", kit.Split(strings.TrimSpace(arg[1]), "\n")) m.Render(ice.RENDER_TEMPLATE, m.Conf(cmd, "meta.template")) }}, @@ -314,11 +281,7 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心", Stack(m, cmd, 0, kit.Parse(nil, "", chain.show(m, arg[1])...)) m.Echo("") }}, - "chart": {Name: "chart label|chain|table name text [fg bg fs ls p m]", Help: "绘图", Meta: map[string]interface{}{}, List: kit.List( - kit.MDB_INPUT, "select", "value", "chain", "values", "block chain table", - kit.MDB_INPUT, "text", "value", "", - kit.MDB_INPUT, "button", "value", "生成", - ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + "chart": {Name: "chart label|chain|table name text [fg bg fs ls p m]", Help: "绘图", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { // 创建类型 var chart Chart switch arg[0] { @@ -360,37 +323,18 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心", m.Render(ice.RENDER_TEMPLATE, m.Conf("chart", "meta.suffix")) }}, - "draw": {Name: "draw", Help: "思维导图", Meta: kit.Dict("display", "wiki/draw"), List: kit.List( - kit.MDB_INPUT, "text", "name", "path", "action", "auto", - kit.MDB_INPUT, "button", "name", "查看", "action", "auto", - kit.MDB_INPUT, "button", "name", "返回", "cb", "Last", - ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + "draw": {Name: "draw path auto", Help: "思维导图", Meta: kit.Dict("display", "wiki/draw"), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) > 0 && arg[0] == "action" { switch arg[1] { case "保存": m.Cmd("nfs.save", path.Join(m.Conf(cmd, "meta.path"), kit.Select("hi.svg", arg[2])), arg[3:]) - - case "执行": - list := []string{"red", "green", "yellow", "cyan", "blue", "white", "black"} - switch kit.Select("", arg, 2) { - case "color": - m.Push("fill", list[rand.Intn(len(list))]) - m.Push("fill", list[rand.Intn(len(list))]) - default: - x := kit.Int(m.Option("x"))%300 + 10 - m.Push("x", x) - } } return } reply(m, cmd, arg...) }}, - "data": {Name: "data", Help: "数据表格", Meta: kit.Dict("display", "wiki/data"), List: kit.List( - kit.MDB_INPUT, "text", "name", "path", "action", "auto", - kit.MDB_INPUT, "button", "name", "执行", "action", "auto", - kit.MDB_INPUT, "button", "name", "返回", "cb", "Last", - ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + "data": {Name: "data path auto", Help: "数据表格", Meta: kit.Dict("display", "wiki/data"), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) > 0 && arg[0] == "action" { switch arg[1] { case "保存": @@ -406,11 +350,7 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心", // 解析数据 m.CSV(m.Result()) }}, - "word": {Name: "word", Help: "语言文字", Meta: kit.Dict("display", "wiki/word"), List: kit.List( - kit.MDB_INPUT, "text", "name", "path", "value", "自然/编程/hi.shy", - kit.MDB_INPUT, "button", "name", "执行", "action", "auto", - kit.MDB_INPUT, "button", "name", "返回", "cb", "Last", - ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + "word": {Name: "word path auto", Help: "语言文字", Meta: kit.Dict("display", "wiki/word"), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) > 0 && arg[0] == "action" { switch arg[1] { case "story": @@ -473,11 +413,8 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心", m.Optionv(ice.MSG_ALIAS, m.Confv("word", "meta.alias")) m.Set("result").Cmdy(ice.SSH_SOURCE, path.Join(m.Conf(cmd, "meta.path"), arg[0])) }}, - "feel": {Name: "feel", Help: "影音媒体", Meta: kit.Dict("display", "wiki/feel", "detail", []string{"标签", "删除"}), List: kit.List( - kit.MDB_INPUT, "text", "name", "name", - kit.MDB_INPUT, "button", "name", "执行", - kit.MDB_INPUT, "button", "name", "返回", "cb", "Last", - kit.MDB_INPUT, "button", "name", "上传", "figure", "upload", + "feel": {Name: "feel path auto 上传:button=@upload", Help: "影音媒体", Meta: kit.Dict( + "display", "wiki/feel", "detail", []string{"标签", "删除"}, ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if m.Option("_action") == "上传" { m.Cmd(ice.WEB_CACHE, "watch", m.Option("_data"), path.Join(m.Option("name"), m.Option("_name"))) @@ -523,11 +460,7 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心", // 下载文件 m.Echo(path.Join(m.Conf(cmd, "meta.path"), arg[0])) }}, - "walk": {Name: "walk", Help: "走遍世界", Meta: kit.Dict("display", "wiki/walk"), List: kit.List( - kit.MDB_INPUT, "text", "name", "file", "figure", "province", - kit.MDB_INPUT, "button", "name", "执行", - kit.MDB_INPUT, "button", "name", "返回", "cb", "Last", - ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + "walk": {Name: "walk path=@province auto", Help: "走遍世界", Meta: kit.Dict("display", "wiki/walk"), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) > 0 && arg[0] == "action" { switch arg[1] { case "保存": diff --git a/misc/git/git.go b/misc/git/git.go index 4be5b41b..974d0718 100644 --- a/misc/git/git.go +++ b/misc/git/git.go @@ -28,8 +28,7 @@ var Index = &ice.Context{Name: "git", Help: "代码库", Caches: map[string]*ice.Cache{}, Configs: map[string]*ice.Config{ "git": {Name: "git", Help: "代码库", Value: kit.Data( - "source", "https://github.com/git/git.git", - "config", kit.Dict( + "source", "https://github.com/git/git.git", "config", kit.Dict( "alias", kit.Dict("s", "status", "b", "branch"), "color", kit.Dict("ui", "true"), "push", kit.Dict("default", "simple"), @@ -59,6 +58,8 @@ var Index = &ice.Context{Name: "git", Help: "代码库", }) }) }}, + ice.CODE_PROJECT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + }}, "init": {Name: "init", Help: "初始化", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { // 系统项目 @@ -75,12 +76,12 @@ var Index = &ice.Context{Name: "git", Help: "代码库", add(m, value["name"], value["path"]) }) }}, + "auto": {Name: "auto", Help: "自动化", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + }}, + "load": {Name: "load", Help: "序列化", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + }}, - "repos": {Name: "repos [name [path [remote [branch]]]]", Help: "仓库", List: kit.List( - kit.MDB_INPUT, "text", "name", "name", "action", "auto", - kit.MDB_INPUT, "button", "name", "查看", "action", "auto", - kit.MDB_INPUT, "button", "name", "返回", "cb", "Last", - ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + "repos": {Name: "repos [name=auto [path [remote [branch]]]] auto", Help: "代码仓库", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) > 1 { if _, e := os.Stat(path.Join(arg[1], ".git")); e != nil && os.IsNotExist(e) { // 下载仓库 @@ -104,11 +105,7 @@ var Index = &ice.Context{Name: "git", Help: "代码库", }) m.Sort("name") }}, - "total": {Name: "total", Help: "统计", List: kit.List( - kit.MDB_INPUT, "text", "name", "name", "action", "auto", - kit.MDB_INPUT, "button", "name", "查看", "action", "auto", - kit.MDB_INPUT, "button", "name", "返回", "cb", "Last", - ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + "total": {Name: "total name auto", Help: "提交统计", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) > 0 { // 提交详情 m.Richs("repos", nil, arg[0], func(key string, value map[string]interface{}) { @@ -150,15 +147,11 @@ var Index = &ice.Context{Name: "git", Help: "代码库", m.Push("rest", rest) m.Sort("adds", "int_r") }}, - "status": {Name: "status repos", Help: "状态", Meta: kit.Dict( + "status": {Name: "status name auto", Help: "文件状态", Meta: kit.Dict( "detail", []interface{}{"add", "reset", "remove", kit.Dict("name", "commit", "args", kit.List( kit.MDB_INPUT, "select", "name", "type", "values", []string{"add", "opt"}, kit.MDB_INPUT, "text", "name", "name", "value", "some", ))}, - ), List: kit.List( - kit.MDB_INPUT, "text", "name", "name", "action", "auto", - kit.MDB_INPUT, "button", "name", "查看", "action", "auto", - kit.MDB_INPUT, "button", "name", "返回", "cb", "Last", ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { prefix := []string{ice.CLI_SYSTEM, "git"} @@ -272,11 +265,8 @@ var Index = &ice.Context{Name: "git", Help: "代码库", } }}, - "trend": {Name: "check name [path [repos]]", Help: "检查", Meta: kit.Dict("display", "/plugin/story/trend"), List: kit.List( - kit.MDB_INPUT, "text", "name", "repos", "action", "auto", - kit.MDB_INPUT, "text", "name", "begin_time", "figure", "date", - kit.MDB_INPUT, "button", "name", "执行", "action", "auto", - kit.MDB_INPUT, "button", "name", "返回", "cb", "Last", + "trend": {Name: "trend name=auto begin_time=@date auto", Help: "趋势图", Meta: kit.Dict( + "display", "/plugin/story/trend", ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) == 0 { m.Option("_display", "table") diff --git a/misc/input/input.go b/misc/input/input.go index 9b5aff85..7d2df4ae 100644 --- a/misc/input/input.go +++ b/misc/input/input.go @@ -157,7 +157,4 @@ var Index = &ice.Context{Name: "input", Help: "输入法", }, } -// ice add person 码神 dcpy -// 码神 - func init() { code.Index.Register(Index, nil) } diff --git a/misc/md/md.go b/misc/md/md.go new file mode 100644 index 00000000..64a1c5c7 --- /dev/null +++ b/misc/md/md.go @@ -0,0 +1,54 @@ +package md + +import ( + "github.com/shylinux/icebergs" + "github.com/shylinux/icebergs/core/wiki" + "github.com/shylinux/toolkits" + + "github.com/gomarkdown/markdown" + "io/ioutil" + "math/rand" +) + +var Index = &ice.Context{Name: "md", Help: "md", + Caches: map[string]*ice.Cache{}, + Configs: map[string]*ice.Config{ + "note": {Name: "note", Help: "笔记", Value: kit.Data( + "path", "", "head", "time size line path", + )}, + + "md": {Name: "md", Help: "md", Value: kit.Data(kit.MDB_SHORT, "name")}, + }, + Commands: map[string]*ice.Command{ + ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}}, + ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}}, + + "md": {Name: "md", Help: "md", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + m.Echo("hello world") + }}, + + "note": {Name: "note file", Help: "文档", Meta: kit.Dict("display", "inner"), List: kit.List( + kit.MDB_INPUT, "text", "name", "path", "value", "README.md", "action", "auto", + kit.MDB_INPUT, "button", "name", "执行", "action", "auto", + kit.MDB_INPUT, "button", "name", "返回", "cb", "Last", + ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + if len(arg) > 0 && strings.HasSuffix(arg[0], ".md") { + arg[0] = path.Join(m.Conf("note", "meta.path"), arg[0]) + } + m.Cmdy(kit.Select("_tree", "_text", len(arg) > 0 && strings.HasSuffix(arg[0], ".md")), arg) + }}, + "_tree": {Name: "_tree [path [true]]", Help: "文库", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + m.Option("dir_reg", ".*\\.md") + m.Option("dir_deep", kit.Select("", arg, 1)) + m.Cmdy("nfs.dir", kit.Select(m.Conf("note", "meta.path"), arg, 0), m.Conf("note", "meta.head")) + }}, + "_text": {Name: "_text file", Help: "文章", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + if b, e := ioutil.ReadFile(arg[0]); m.Assert(e) { + data := markdown.ToHTML(b, nil, nil) + m.Echo(string(data)) + } + }}, + }, +} + +func init() { wiki.Index.Register(Index, nil) } diff --git a/misc/md/md.js b/misc/md/md.js new file mode 100644 index 00000000..957bfb22 --- /dev/null +++ b/misc/md/md.js @@ -0,0 +1,9 @@ +Volcanos("onimport", {help: "导入数据", list: [], + "init": function(can, msg, cb, output, action, option) {}, +}) +Volcanos("onaction", {help: "控件菜单", list: []}) +Volcanos("onchoice", {help: "控件交互", list: ["刷新"] + "刷新": function(event, can, value, cmd, target) {}, +}) +Volcanos("ondetail", {help: "控件详情", list: []}) +Volcanos("onexport", {help: "导出数据", list: []}) diff --git a/misc/md/md.shy b/misc/md/md.shy new file mode 100644 index 00000000..fd854e9d --- /dev/null +++ b/misc/md/md.shy @@ -0,0 +1 @@ +title "md" diff --git a/misc/railway/railway.go b/misc/railway/railway.go new file mode 100644 index 00000000..c9ca6e5d --- /dev/null +++ b/misc/railway/railway.go @@ -0,0 +1,96 @@ +package railway + +import ( + "github.com/shylinux/icebergs" + "github.com/shylinux/icebergs/core/wiki" + "github.com/shylinux/toolkits" +) + +var Index = &ice.Context{Name: "railway", Help: "railway", + Caches: map[string]*ice.Cache{}, + Configs: map[string]*ice.Config{ + "railway": {Name: "railway", Help: "12306", Value: kit.Data("site", "https://kyfw.12306.cn")}, + }, + Commands: map[string]*ice.Command{ + ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + m.Load() + m.Cmd(ice.WEB_SPIDE, "add", "12306", m.Conf("railway", "meta.site")) + }}, + ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + m.Save("railway") + }}, + + "railway": &ice.Command{Name: "railway", Help: "12306", List: kit.List( + kit.MDB_INPUT, "text", "name", "date", "figure", "date", + kit.MDB_INPUT, "text", "name", "from", "value", "北京", "figure", "city", + kit.MDB_INPUT, "text", "name", "to", "value", "曲阜", "figure", "city", + kit.MDB_INPUT, "button", "name", "查询", + ), Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) { + if !m.Confs("railway", "meta.place") { + list := strings.Split(strings.TrimPrefix(m.Cmdx(ice.WEB_SPIDE, "12306", "raw", "GET", "/otn/resources/js/framework/station_name.js?station_version=1.9090"), "var statuion_names ='"), "|") + for i := 0; i < len(list)-5; i += 5 { + m.Conf("railway", kit.Keys("meta.place", list[i+1]), list[i+2]) + } + } + + date := strings.Split(m.Time("24h"), " ")[0] + if len(arg) > 0 { + date, arg = arg[0], arg[1:] + } + date = strings.Split(date, " ")[0] + from := "北京" + if len(arg) > 0 { + from, arg = arg[0], arg[1:] + } + from_code := m.Conf("railway", kit.Keys("meta.place", from)) + to := "曲阜" + if len(arg) > 0 { + to, arg = arg[0], arg[1:] + } + to_code := m.Conf("railway", kit.Keys("meta.place", to)) + + m.Echo("%s->%s %s\n", from, to, date) + + if len(arg) > 0 { + m.Cmdy(ice.WEB_SPIDE, "12306", "raw", "GET", fmt.Sprintf("/otn/czxx/queryByTrainNo?train_no=%s&from_station_telecode=%s&to_station_telecode=%s&depart_date=%s", + arg[0], from_code, to_code, date)) + return + } + + m.Cmd(ice.WEB_SPIDE, "12306", "GET", fmt.Sprintf("/otn/leftTicket/init?linktypeid=dc&fs=%s,%s&ts=%s,%s&date=%s&flag=N,N,Y", + from, from_code, to, to_code, date)) + m.Cmd(ice.WEB_SPIDE, "12306", "GET", fmt.Sprintf("/otn/leftTicket/queryZ?leftTicketDTO.train_date=%s&leftTicketDTO.from_station=%s&leftTicketDTO.to_station=%s&purpose_codes=ADULT", + date, from_code, to_code)).Table(func(index int, value map[string]string, head []string) { + kit.Fetch(kit.Value(kit.UnMarshal(value["data"]), "result"), func(index int, value string) { + fields := strings.Split(value, "|") + m.Push("车次", fields[3]) + m.Push("出发", fields[8]) + m.Push("到站", fields[9]) + m.Push("时长", fields[10]) + m.Push("二等座", fields[30]) + m.Push("一等座", fields[31]) + }) + }) + }}, + "passcode": &ice.Command{Name: "passcode", Help: "passcode", Meta: kit.Dict("active", "mall/input"), Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) { + prefix := []string{ice.WEB_SPIDE, "12306"} + if len(arg) == 0 { + m.Cmd(prefix, "raw", "/passport/web/auth/uamtk-static", "form", "appid", "otn") + m.Cmd(prefix, "raw", "GET", "/otn/HttpZF/GetJS") + m.Cmd(prefix, "raw", "/otn/login/conf") + + m.Cmdy(prefix, "GET", fmt.Sprintf("/passport/captcha/captcha-image64?login_site=E&module=login&rand=sjrand")) + return + } + + switch arg[0] { + case "check": + m.Cmdy(prefix, "GET", fmt.Sprintf("/passport/captcha/captcha-check?login_site=E&rand=sjrand&answer=%s", arg[1])) + case "login": + m.Cmdy(prefix, "raw", "/passport/web/login", "form", "username", arg[1], "password", arg[2], "answer", arg[3], "appid", "otn") + } + }}, + }, +} + +func init() { wiki.Index.Register(Index, nil) } diff --git a/misc/railway/railway.js b/misc/railway/railway.js new file mode 100644 index 00000000..957bfb22 --- /dev/null +++ b/misc/railway/railway.js @@ -0,0 +1,9 @@ +Volcanos("onimport", {help: "导入数据", list: [], + "init": function(can, msg, cb, output, action, option) {}, +}) +Volcanos("onaction", {help: "控件菜单", list: []}) +Volcanos("onchoice", {help: "控件交互", list: ["刷新"] + "刷新": function(event, can, value, cmd, target) {}, +}) +Volcanos("ondetail", {help: "控件详情", list: []}) +Volcanos("onexport", {help: "导出数据", list: []}) diff --git a/misc/railway/railway.shy b/misc/railway/railway.shy new file mode 100644 index 00000000..5658fe5e --- /dev/null +++ b/misc/railway/railway.shy @@ -0,0 +1 @@ +title "railway" diff --git a/misc/tmux/tmux.go b/misc/tmux/tmux.go index ef4ceba6..1ff86995 100644 --- a/misc/tmux/tmux.go +++ b/misc/tmux/tmux.go @@ -42,6 +42,14 @@ var Index = &ice.Context{Name: "tmux", Help: "工作台", )}, }, Commands: map[string]*ice.Command{ + ice.CODE_INSTALL: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + }}, + ice.CODE_PREPARE: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + m.Cmd("nfs.link", path.Join(os.Getenv("HOME"), ".tmux.conf"), "etc/conf/tmux.conf") + }}, + ice.CODE_PROJECT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + }}, + "init": {Name: "init", Help: "初始化", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Watch(ice.DREAM_START, m.Prefix("auto")) @@ -111,24 +119,17 @@ var Index = &ice.Context{Name: "tmux", Help: "工作台", m.Cmdy(prefix, "send-keys", "-t", arg[0], v, "Enter") } }}, + "load": {Name: "load", Help: "序列化", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + }}, - "text": {Name: "text", Help: "文本", List: kit.List( - kit.MDB_INPUT, "text", "name", "name", - kit.MDB_INPUT, "button", "value", "保存", - kit.MDB_INPUT, "textarea", "name", "text", - ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + "text": {Name: "text name 保存:button text:textarea", Help: "文本", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { prefix := kit.Simple(m.Confv("prefix", "meta.cmd")) if len(arg) > 1 && arg[1] != "" { m.Cmd(prefix, "set-buffer", arg[1]) } m.Cmdy(prefix, "show-buffer").Set(ice.MSG_APPEND) }}, - "buffer": {Name: "buffer", Help: "缓存", List: kit.List( - kit.MDB_INPUT, "text", "name", "buffer", "action", "auto", - kit.MDB_INPUT, "text", "name", "value", - kit.MDB_INPUT, "button", "value", "查看", "action", "auto", - kit.MDB_INPUT, "button", "value", "返回", "cb", "Last", - ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + "buffer": {Name: "buffer [buffer=auto [value]] auto", Help: "缓存", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { prefix := kit.Simple(m.Confv("prefix", "meta.cmd")) if len(arg) > 1 { // 设置缓存 @@ -153,12 +154,8 @@ var Index = &ice.Context{Name: "tmux", Help: "工作台", } } }}, - "session": {Name: "session [session [window [pane [cmd]]]]", Help: "会话", Meta: kit.Dict("detail", []string{"选择", "编辑", "删除", "下载"}), List: kit.List( - kit.MDB_INPUT, "text", "name", "session", "action", "auto", - kit.MDB_INPUT, "text", "name", "window", "action", "auto", - kit.MDB_INPUT, "text", "name", "pane", "action", "auto", - kit.MDB_INPUT, "button", "value", "查看", "action", "auto", - kit.MDB_INPUT, "button", "value", "返回", "cb", "Last", + "session": {Name: "session [session=auto [window=auto [pane=auto [cmd]]]] auto", Help: "会话", Meta: kit.Dict( + "detail", []string{"选择", "编辑", "删除", "下载"}, ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { prefix := kit.Simple(m.Confv("prefix", "meta.cmd")) diff --git a/type.go b/type.go index d18310fc..3b86ae08 100644 --- a/type.go +++ b/type.go @@ -869,11 +869,15 @@ func (m *Message) TryCatch(msg *Message, safe bool, hand ...func(msg *Message)) case io.EOF: case nil: default: - m.Log(LOG_WARN, "catch: %s", e) + _, file, line, _ := runtime.Caller(3) + if list := strings.Split(file, "/"); len(list) > 2 { + file = strings.Join(list[len(list)-2:], "/") + } + m.Log(LOG_WARN, "catch: %s %s:%d", e, file, line) m.Log(LOG_INFO, "chain: %s", msg.Format("chain")) - m.Log(LOG_WARN, "catch: %s", e) + m.Log(LOG_WARN, "catch: %s %s:%d", e, file, line) m.Log(LOG_INFO, "stack: %s", msg.Format("stack")) - if m.Log(LOG_WARN, "catch: %s", e); len(hand) > 1 { + if m.Log(LOG_WARN, "catch: %s %s:%d", e, file, line); len(hand) > 1 { // 捕获异常 m.TryCatch(msg, safe, hand[1:]...) } else if !safe {