1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- package controller
- import (
- "eta/eta_docs/controller/resp"
- "eta/eta_docs/global"
- "eta/eta_docs/models/crm"
- "eta/eta_docs/models/request"
- "eta/eta_docs/models/response"
- "eta/eta_docs/utils"
- "github.com/gin-gonic/gin"
- "github.com/go-playground/validator/v10"
- )
- // VersionUpdateLogController 版本更新日志
- type VersionUpdateLogController struct{}
- // Menu
- // @Description 菜单
- // @Success 200 {string} string "获取成功"
- // @Router /version_log/menu [get]
- func (a *VersionUpdateLogController) Menu(c *gin.Context) {
- // 获取列表数据
- logOb := new(crm.EtaVersionUpdateLog)
- list, e := logOb.GetItemsByCondition("", make([]interface{}, 0), "update_date DESC")
- if e != nil {
- resp.FailMsg("获取失败", "获取ETA更新日志列表失败, Err: "+e.Error(), c)
- return
- }
- result := make([]string, 0)
- for _, v := range list {
- strDate := v.UpdateDate.Format("2006年01月")
- if !utils.InArrayByStr(result, strDate) {
- result = append(result, strDate)
- }
- }
- resp.OkData("获取成功", result, c)
- }
- // List
- // @Description 列表
- // @Success 200 {string} string "获取成功"
- // @Router /version_log/list [get]
- func (a *VersionUpdateLogController) List(c *gin.Context) {
- var req request.VersionUpdateLogListReq
- err := c.Bind(&req)
- if err != nil {
- errs, ok := err.(validator.ValidationErrors)
- if !ok {
- resp.FailData("参数解析失败", "Err:"+err.Error(), c)
- return
- }
- resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
- return
- }
- // 获取列表数据
- logOb := new(crm.EtaVersionUpdateLog)
- list, e := logOb.GetItemsByCondition("", make([]interface{}, 0), "update_date DESC")
- if e != nil {
- resp.FailMsg("获取失败", "获取ETA更新日志列表失败, Err: "+e.Error(), c)
- return
- }
- items := make([]*response.VersionUpdateLogItem, 0)
- logsMap := make(map[string][]*response.VersionUpdateLogDetailItem)
- for _, v := range list {
- strDate := v.UpdateDate.Format("2006年01月")
- if logsMap[strDate] == nil {
- logsMap[strDate] = make([]*response.VersionUpdateLogDetailItem, 0)
- item := new(response.VersionUpdateLogItem)
- item.DateFlag = strDate
- items = append(items, item)
- }
- t := new(response.VersionUpdateLogDetailItem)
- t.Version = v.Version
- t.UpdateDate = v.UpdateDate.Format(utils.FormatDate)
- t.Content = v.Content
- logsMap[strDate] = append(logsMap[strDate], t)
- }
- result := make([]*response.VersionUpdateLogItem, 0)
- for _, v := range items {
- if req.DateFlag != "" && req.DateFlag != v.DateFlag {
- continue
- }
- v.List = logsMap[v.DateFlag]
- result = append(result, v)
- }
- resp.OkData("获取成功", result, c)
- }
|