fix line log count

This commit is contained in:
Jay 2018-10-15 16:36:06 +08:00
parent 53669a298f
commit 871ba9300c
2 changed files with 30 additions and 3 deletions

View File

@ -32,8 +32,27 @@ func AddLineMessageLog(g, u, msg, t string) (msglog *LineMessageLog, err error)
} }
// GetLineMessageLogCount - // GetLineMessageLogCount -
func GetLineMessageLogCount() (c int, err error) { func GetLineMessageLogCount(where ...interface{}) (c int, err error) {
err = x.Get(&c, `select count(*) as c from "public"."line_message_log"`) query := `select count(*) as c from "public"."line_message_log"`
values := make([]string, 0)
if len(where) > 0 {
if whereMap, ok := where[0].(map[string]string); ok {
str := ""
idx := 1
for k, v := range whereMap {
if len(str) > 0 {
str += " and "
}
str += fmt.Sprintf(` "%s" = $%d`, k, idx)
idx++
values = append(values, v)
}
if len(str) > 0 {
query += " where " + str
}
}
}
err = x.Get(&c, query, values)
return return
} }

View File

@ -49,7 +49,15 @@ func GetLineMessageLog(c *context.Context) {
g := c.DefaultQuery("group", "") g := c.DefaultQuery("group", "")
u := c.DefaultQuery("user", "") u := c.DefaultQuery("user", "")
count, err := model.GetLineMessageLogCount() where := make(map[string]string)
if len(g) > 0 {
where["group"] = g
}
if len(u) > 0 {
where["user"] = u
}
count, err := model.GetLineMessageLogCount(where)
if err != nil { if err != nil {
c.ServerError(nil) c.ServerError(nil)
return return