`, strings.Join(note[1:], "\n"), note[0], len(note)-1)
} else {
note[0] = kit.Format(`%s%s`, note[0], "")
}
m.Push(head[int(day.Weekday())], note[0])
}
// 下月开头
tail := end.AddDate(0, 0, 6-int(end.Weekday())+1)
for day := end; end.Weekday() != 0 && day.Before(tail); day = day.AddDate(0, 0, 1) {
m.Push(head[int(day.Weekday())], ShowDay(m, day))
}
case "year":
// 年计划
for i := 1; i < 13; i++ {
m.Push("month", kit.Format("%02d", i))
m.Push("task", "")
}
// 查询任务
match := first.Format("2006")
template := m.Conf("plan", kit.Keys("meta.template", kit.Select("year", m.Option("template"))))
m.Richs("task", nil, "*", func(key string, value map[string]interface{}) {
m.Grows("task", kit.Keys("hash", key), "", "", func(index int, value map[string]interface{}) {
if now := kit.Format(value["begin_time"]); now[0:4] == match && kit.Format(value["type"]) == "年度目标" {
b, _ := kit.Render(kit.Format(template, key), value)
m.Push("month", now[5:7])
m.Push("task", string(b))
}
})
})
m.Sort("month", "int")
case "long":
// 长计划
one := time.Unix(int64(kit.Time(kit.Select(kit.Format("%d-01-01", first.Year()-5), arg, 1))), 0)
end := time.Unix(int64(kit.Time(kit.Select(kit.Format("%d-12-31", first.Year()+5), arg, 2))), 0)
for day := one; day.Before(end); day = day.AddDate(1, 0, 0) {
m.Push("year", day.Year())
m.Push("task", "")
}
// 查询任务
template := m.Conf("plan", kit.Keys("meta.template", kit.Select("year", m.Option("template"))))
m.Richs("task", nil, "*", func(key string, value map[string]interface{}) {
m.Grows("task", kit.Keys("hash", key), "", "", func(index int, value map[string]interface{}) {
if t, e := time.ParseInLocation(ice.ICE_TIME, kit.Format(value["begin_time"]), time.Local); e == nil {
if t.After(one) && t.Before(end) && kit.Format(value["type"]) == "年度目标" {
b, _ := kit.Render(kit.Format(template, key), value)
m.Push("year", t.Year())
m.Push("task", string(b))
}
}
})
})
m.Sort("year", "int")
}
}},
"stat": {Name: "stat", Help: "统计", Meta: kit.Dict("remote", "you"), 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) {
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())
m.Option("cache.limit", -1)
m.Richs("task", nil, "*", func(key string, value map[string]interface{}) {
stat := map[string]int{}
m.Grows("task", kit.Keys("hash", key), "", "", func(index int, value map[string]interface{}) {
if len(arg) > 1 && kit.Time(kit.Format(value["begin_time"])) > end_time {
return
}
if len(arg) > 0 && kit.Time(kit.Format(value["begin_time"])) < begin_time {
return
}
if stat[kit.Format(value["status"])] += 1; value["status"] != "prepare" {
use := kit.Time(kit.Format(value["close_time"])) - kit.Time(kit.Format(value["begin_time"]))
if value["status"] == "process" {
use = now_time - kit.Time(kit.Format(value["begin_time"]))
}
stat["sum"] += use
if use > stat["max"] {
stat["max"] = use
}
if use < stat["min"] {
stat["min"] = use
}
}
stat["total"] += 1
})
m.Push("zone", kit.Value(value, "meta.zone"))
for _, k := range []string{"prepare", "process", "cancel", "finish", "total"} {
m.Push(k, stat[k])
}
m.Push("sum", kit.FmtTime(int64(stat["sum"])*int64(time.Second)))
if stat["finish"] == 0 {
stat["finish"] = 1
}
m.Push("avg", kit.FmtTime(int64(stat["sum"]/stat["finish"])*int64(time.Second)))
m.Push("min", kit.FmtTime(int64(stat["min"])*int64(time.Second)))
m.Push("max", kit.FmtTime(int64(stat["max"])*int64(time.Second)))
})
}},
"miss": {Name: "miss zone type name text", Help: "任务", Meta: kit.Dict("remote", "you"), 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", "location", "figure", "key", "cb", "location", "className", "opts",
), Hand: func(m *ice.Message, c *ice.Context, key string, arg ...string) {
if len(arg) > 0 && arg[0] == "action" {
switch arg[1] {
case "input":
// 输入补全
switch arg[2] {
case "zone":
m.Richs("task", nil, "*", func(key string, value map[string]interface{}) {
m.Push("zone", kit.Value(value, "meta.zone"))
m.Push("count", kit.Value(value, "meta.count"))
})
case "type", "name":
m.Confm("task", kit.Keys("meta.word", arg[2]), func(key string, value string) {
m.Push(arg[2], key)
m.Push("count", value)
})
}
m.Sort("count", "int_r")
return
}
}
if len(arg) < 2 {
// 查询任务
m.Cmdy("task", arg)
return
}
// 创建任务
m.Cmdy("task", arg[0], "", arg[1:])
}},
},
}
func init() { web.Index.Register(Index, &web.Frame{}) }