log.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // 留存分布
  2. package controllers
  3. import (
  4. "github.com/astaxie/beego"
  5. "time"
  6. // "log"
  7. "box-gm/models"
  8. )
  9. type LogController struct {
  10. beego.Controller
  11. }
  12. // 主界面
  13. // 通过c.Data[key]返回数据
  14. // ace模板文件通过{{.key}}获取数据
  15. func (c *LogController) Get() {
  16. userinfo := c.GetSession("user")
  17. if userinfo == nil {
  18. c.Ctx.Redirect(302, "/accountlogin")
  19. return
  20. }
  21. c.Data["username"] = userinfo.(*LoginInfo).Username
  22. c.Data["token"] = models.GetToken()
  23. userPermission := models.GetPermission(userinfo.(*LoginInfo).Username)
  24. if (userPermission & (1 << uint(models.ModelStatment))) == 0 {
  25. c.Ctx.Redirect(302, "/accountlogin")
  26. return
  27. }
  28. filename := ""
  29. if c.GetString("action") == "query" {
  30. username := c.GetString("username")
  31. ts1 := c.GetString("start_time")
  32. ts2 := c.GetString("end_time")
  33. operate := c.GetString("operate")
  34. start_time := StrToTime(ts1)
  35. end_time := StrToTime(ts2)
  36. c.Data["logs"] = models.QueryLog(username, start_time, end_time, operate, 0)
  37. c.Data["Username"] = username
  38. c.Data["Start_time"] = ts1
  39. c.Data["End_time"] = ts2
  40. c.Data["Operate"] = operate
  41. }else {
  42. currTime := time.Now()
  43. c.Data["Start_time"] = currTime.Format("2006-01-02")
  44. c.Data["End_time"] = currTime.Format("2006-01-02")
  45. }
  46. if c.GetString("querydata") == "log" {
  47. c.Ctx.Output.Download(filename)
  48. }else {
  49. //界面模板文件
  50. c.TplName = "log.tpl"
  51. }
  52. }