modify line log api order
This commit is contained in:
parent
99c61b5af1
commit
2626234eeb
@ -57,7 +57,10 @@ func GetLineMessageLogCount(where ...interface{}) (c int, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetLineMessageLogList -
|
// GetLineMessageLogList -
|
||||||
func GetLineMessageLogList(g, u string, offset, limit int) (logs []*LineMessageLogWithUG, err error) {
|
func GetLineMessageLogList(g, u string, offset, limit int, orderArg string) (logs []*LineMessageLogWithUG, err error) {
|
||||||
|
if orderArg != "asc" && orderArg != "desc" {
|
||||||
|
orderArg = "desc"
|
||||||
|
}
|
||||||
params := struct {
|
params := struct {
|
||||||
Group string `db:"group"`
|
Group string `db:"group"`
|
||||||
User string `db:"user"`
|
User string `db:"user"`
|
||||||
@ -81,7 +84,7 @@ func GetLineMessageLogList(g, u string, offset, limit int) (logs []*LineMessageL
|
|||||||
}
|
}
|
||||||
params.User = u
|
params.User = u
|
||||||
}
|
}
|
||||||
order := `order by m.ctime desc`
|
order := fmt.Sprintf(`order by m.ctime %s`, orderArg)
|
||||||
pager := fmt.Sprintf("offset %d limit %d", offset, limit)
|
pager := fmt.Sprintf("offset %d limit %d", offset, limit)
|
||||||
|
|
||||||
stmt, err := x.PrepareNamed(fmt.Sprintf("%s %s %s %s", query, where, order, pager))
|
stmt, err := x.PrepareNamed(fmt.Sprintf("%s %s %s %s", query, where, order, pager))
|
||||||
|
@ -49,6 +49,10 @@ func GetLineMessageLog(c *context.Context) {
|
|||||||
|
|
||||||
g := c.DefaultQuery("group", "")
|
g := c.DefaultQuery("group", "")
|
||||||
u := c.DefaultQuery("user", "")
|
u := c.DefaultQuery("user", "")
|
||||||
|
order := c.DefaultQuery("order", "desc")
|
||||||
|
if order != "asc" && order != "desc" {
|
||||||
|
order = "desc"
|
||||||
|
}
|
||||||
|
|
||||||
where := make(map[string]string)
|
where := make(map[string]string)
|
||||||
if len(g) > 0 {
|
if len(g) > 0 {
|
||||||
@ -66,8 +70,12 @@ func GetLineMessageLog(c *context.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
page := utils.CalcPage(count, numP, numMax)
|
page := utils.CalcPage(count, numP, numMax)
|
||||||
|
if numP == -1 {
|
||||||
|
numP = page.Total
|
||||||
|
}
|
||||||
|
page = utils.CalcPage(count, numP, numMax)
|
||||||
|
|
||||||
logs, err := model.GetLineMessageLogList(g, u, page.Offset, page.Limit)
|
logs, err := model.GetLineMessageLogList(g, u, page.Offset, page.Limit, order)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.ServerError(nil)
|
c.ServerError(nil)
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user