version_update_log.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package controller
  2. import (
  3. "eta/eta_docs/controller/resp"
  4. "eta/eta_docs/global"
  5. "eta/eta_docs/models/crm"
  6. "eta/eta_docs/models/request"
  7. "eta/eta_docs/models/response"
  8. "eta/eta_docs/utils"
  9. "github.com/gin-gonic/gin"
  10. "github.com/go-playground/validator/v10"
  11. )
  12. // VersionUpdateLogController 版本更新日志
  13. type VersionUpdateLogController struct{}
  14. // Menu
  15. // @Description 菜单
  16. // @Success 200 {string} string "获取成功"
  17. // @Router /version_log/menu [get]
  18. func (a *VersionUpdateLogController) Menu(c *gin.Context) {
  19. // 获取列表数据
  20. logOb := new(crm.EtaVersionUpdateLog)
  21. list, e := logOb.GetItemsByCondition("", make([]interface{}, 0), "update_date DESC")
  22. if e != nil {
  23. resp.FailMsg("获取失败", "获取ETA更新日志列表失败, Err: "+e.Error(), c)
  24. return
  25. }
  26. result := make([]string, 0)
  27. for _, v := range list {
  28. strDate := v.UpdateDate.Format("2006年01月")
  29. if !utils.InArrayByStr(result, strDate) {
  30. result = append(result, strDate)
  31. }
  32. }
  33. resp.OkData("获取成功", result, c)
  34. }
  35. // List
  36. // @Description 列表
  37. // @Success 200 {string} string "获取成功"
  38. // @Router /version_log/list [get]
  39. func (a *VersionUpdateLogController) List(c *gin.Context) {
  40. var req request.VersionUpdateLogListReq
  41. err := c.Bind(&req)
  42. if err != nil {
  43. errs, ok := err.(validator.ValidationErrors)
  44. if !ok {
  45. resp.FailData("参数解析失败", "Err:"+err.Error(), c)
  46. return
  47. }
  48. resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
  49. return
  50. }
  51. // 获取列表数据
  52. logOb := new(crm.EtaVersionUpdateLog)
  53. list, e := logOb.GetItemsByCondition("", make([]interface{}, 0), "update_date DESC")
  54. if e != nil {
  55. resp.FailMsg("获取失败", "获取ETA更新日志列表失败, Err: "+e.Error(), c)
  56. return
  57. }
  58. items := make([]*response.VersionUpdateLogItem, 0)
  59. logsMap := make(map[string][]*response.VersionUpdateLogDetailItem)
  60. for _, v := range list {
  61. strDate := v.UpdateDate.Format("2006年01月")
  62. if logsMap[strDate] == nil {
  63. logsMap[strDate] = make([]*response.VersionUpdateLogDetailItem, 0)
  64. item := new(response.VersionUpdateLogItem)
  65. item.DateFlag = strDate
  66. items = append(items, item)
  67. }
  68. t := new(response.VersionUpdateLogDetailItem)
  69. t.Version = v.Version
  70. t.UpdateDate = v.UpdateDate.Format(utils.FormatDate)
  71. t.Content = v.Content
  72. logsMap[strDate] = append(logsMap[strDate], t)
  73. }
  74. result := make([]*response.VersionUpdateLogItem, 0)
  75. for _, v := range items {
  76. if req.DateFlag != "" && req.DateFlag != v.DateFlag {
  77. continue
  78. }
  79. v.List = logsMap[v.DateFlag]
  80. result = append(result, v)
  81. }
  82. resp.OkData("获取成功", result, c)
  83. }