123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- package edb_info
- import (
- "github.com/gin-gonic/gin"
- "hongze/hongze_yb/controller/response"
- "hongze/hongze_yb/models/request"
- "hongze/hongze_yb/models/tables/edb_data"
- edbInfoModel "hongze/hongze_yb/models/tables/edb_info"
- "hongze/hongze_yb/utils"
- "strconv"
- )
- // EdbData 指标数据
- func EdbData(c *gin.Context) {
- var req request.EdbInfoDataReq
- if err := c.Bind(&req); err != nil {
- response.Fail("参数有误", c)
- return
- }
- if req.EdbInfoId <= 0 {
- response.Fail("参数错误", c)
- return
- }
- if req.DateType <= 0 {
- req.DateType = 3
- }
- if req.EdbInfoType <= 0 {
- req.EdbInfoType = 1
- }
- edbInfo, e := edbInfoModel.GetEdbInfoById(req.EdbInfoId)
- if e != nil {
- if e == utils.ErrNoRow {
- response.FailMsg("获取失败", "指标不存在,EdbInfoId:"+strconv.Itoa(req.EdbInfoId), c)
- return
- }
- response.FailMsg("获取失败", "获取指标信息失败,Err:"+e.Error(), c)
- return
- }
- maxYear := 0
- if !edbInfo.LatestDate.IsZero() {
- maxYear = edbInfo.LatestDate.Year()
- }
- dataList := make([]*edb_data.EdbDataList, 0)
- startDate, endDate := utils.GetDateByDateTypeV2(req.DateType, req.StartDate, req.EndDate, req.StartYear, maxYear)
- dataList, e = edb_data.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, req.EdbInfoId, startDate, endDate)
- if e != nil {
- response.FailMsg("获取失败", "获取指标数据失败, Err: "+e.Error(), c)
- return
- }
- type EdbInfoDataFullClassifyResp struct {
- EdbInfo *edbInfoModel.EdbInfo
- DataList []*edb_data.EdbDataList
- }
- resp := new(EdbInfoDataFullClassifyResp)
- resp.EdbInfo = edbInfo
- resp.DataList = dataList
- response.OkData("获取成功", resp, c)
- }
|