package controllers import ( "eta/eta_mini_api/models" "eta/eta_mini_api/models/response" "eta/eta_mini_api/services" ) type ChartController struct { BaseAuthController } // @Title List // @Description create users // @Param PageSize query int true "每页数据条数" // @Param CurrentIndex query int true "当前页页码,从1开始" // @Success 200 {object} models.BaseResponse // @router /list [get] func (this *ChartController) List() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() pageSize, _ := this.GetInt("PageSize") currentIndex, _ := this.GetInt("CurrentIndex") result, err := services.GetChartList(currentIndex, pageSize) if err != nil { br.Msg = "查询图表失败" br.ErrMsg = "查询图表失败,系统异常,Err:" + err.Error() return } if result.Ret != 200 { br.Msg = "查询图表失败" br.ErrMsg = result.ErrMsg return } br.Msg = "查询图表成功" br.Data = result.Data br.Success = true br.Ret = 200 } // @Title Locate // @Description create users // @Param PageSize query int true "每页数据条数" // @Param CurrentIndex query int true "当前页页码,从1开始" // @Success 200 {object} models.BaseResponse // @router /locate [get] func (this *ChartController) Locate() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() pageSize, _ := this.GetInt("PageSize") currentIndex, _ := this.GetInt("CurrentIndex") if currentIndex <= 0 { currentIndex = 1 } if pageSize <= 0 { pageSize = 2 } result, err := services.GetChartList(currentIndex, pageSize) if err != nil { br.Msg = "查询图表失败" br.ErrMsg = "查询图表失败,系统异常,Err:" + err.Error() return } if result.Ret != 200 { br.Msg = result.Msg br.ErrMsg = result.ErrMsg return } total := len(result.Data.List) charts := make([]*response.ChartLocateItem, 0) items := result.Data.List for k, v := range items { var prevChartInfoId, nextChartInfoId int switch k { case 0: prevChartInfoId = -1 if k < total-1 { nextChartInfoId = items[k+1].ChartInfoId } else { nextChartInfoId = -1 } case total - 1: nextChartInfoId = -1 if k > 0 { prevChartInfoId = items[k-1].ChartInfoId } default: prevChartInfoId = items[k-1].ChartInfoId nextChartInfoId = items[k+1].ChartInfoId } tmpLocate := &response.ChartLocateItem{ ChartInfoId: v.ChartInfoId, ChartName: v.ChartName, UniqueCode: v.UniqueCode, PrevChartInfoId: prevChartInfoId, NextChartInfoId: nextChartInfoId, } charts = append(charts, tmpLocate) } br.Data = charts br.Msg = "查询成功" br.Success = true br.Ret = 200 }