123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- package data
- import (
- "eta/eta_api/models/data_manage"
- "eta/eta_api/utils"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- )
- type HisugarIndexSource2EdbReq struct {
- EdbCode string
- EdbName string
- Frequency string
- Unit string
- ClassifyId int
- AdminId int
- AdminRealName string
- }
- // HisugarIndexSource2Edb 新增泛糖科技数据从数据源到指标库
- func HisugarIndexSource2Edb(req HisugarIndexSource2EdbReq, lang string) (edb *data_manage.EdbInfo, errMsg string, skip bool, err error) {
- if req.EdbCode == "" {
- err = fmt.Errorf("指标ID为空")
- return
- }
- defer func() {
- if err != nil {
- tips := fmt.Sprintf("HisugarIndexSource2Edb新增失败, Err: %s", err.Error())
- fmt.Println(tips)
- utils.FileLog.Info(tips)
- }
- }()
- source := utils.DATA_SOURCE_HISUGAR
- // 是否新增过指标
- exist, e := data_manage.GetEdbInfoByEdbCode(source, req.EdbCode)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = fmt.Errorf("获取指标是否存在失败, err: %s", e.Error())
- return
- }
- if exist != nil {
- skip = true
- return
- }
- // 开始结束时间
- var startDate, endDate string
- // 新增指标库
- edbInfo, e, msg, _ := EdbInfoAdd(source, utils.DATA_SUB_SOURCE_EDB, req.ClassifyId, req.EdbCode, req.EdbName, req.Frequency, req.Unit, startDate, endDate, req.AdminId, req.AdminRealName, lang)
- if e != nil {
- errMsg = msg
- err = fmt.Errorf("EdbInfo: 新增指标失败, err: %s", e.Error())
- return
- }
- edb = edbInfo
- return
- }
- // GethisugarIndexInfo 获取指标信息-分页
- func GethisugarIndexInfo(keyWord string, classifyIdList []string, frequencyList []string, currentIndex int, pageSize int) (baseFromHisugarIndexPage *data_manage.BaseFromHisugarIndexPage, err error) {
- // 获取指标
- var condition string
- var pars []interface{}
- if keyWord != "" {
- condition += ` AND CONCAT(index_name,index_code) LIKE '%` + keyWord + `%'`
- }
- if len(classifyIdList) > 0 {
- condition += ` AND classify_id IN (`
- for _, v := range classifyIdList {
- condition += `?,`
- pars = append(pars, v)
- }
- condition = condition[:len(condition)-1] + `)`
- }
- if len(frequencyList) > 0 {
- condition += ` AND frequency IN (`
- for _, v := range frequencyList {
- condition += `?,`
- pars = append(pars, v)
- }
- condition = condition[:len(condition)-1] + `)`
- }
- count, err := data_manage.GetHisugarIndexInfoCount(condition, pars)
- if err != nil {
- return
- }
- page := paging.GetPaging(currentIndex, pageSize, count)
- if count <= 0 {
- baseFromHisugarIndexPage = &data_manage.BaseFromHisugarIndexPage{
- List: []*data_manage.BaseFromHisugarIndex{},
- Paging: page,
- }
- return
- }
- startSize := utils.StartIndex(currentIndex, pageSize)
- fenWeiIndexInfoList, err := data_manage.GetHisugarIndexInfoPage(condition, pars, startSize, pageSize)
- if err != nil {
- return
- }
- baseFromHisugarIndexPage = &data_manage.BaseFromHisugarIndexPage{
- List: fenWeiIndexInfoList,
- Paging: page,
- }
- return
- }
|