package data_manage

import (
	"eta_gn/eta_api/global"
	"github.com/rdlucklib/rdluck_tools/paging"
)

type UpdatesStatisticalItem struct {
	Total   int
	Source  int
	EdbType int `description:"指标类型:1:基础指标,2:计算指标"`
}

func GetUpdatesStatistical(condition string, pars []interface{}) (list []*UpdatesStatisticalItem, err error) {
	sql := ` SELECT COUNT(1) AS total,source,edb_type FROM edb_info
			WHERE 1=1 `
	sql += condition
	sql += ` GROUP BY source  `
	err = global.DmSQL["data"].Raw(sql, pars...).Scan(&list).Error

	return
}

type UpdatesStatisticalResp struct {
	ThsUpdate                   int `description:"同花顺已更新"`
	ThsNotUpdate                int `description:"同花顺未更新"`
	WindUpdate                  int `description:"wind已更新"`
	WindNotUpdate               int `description:"wind未更新"`
	PbUpdate                    int `description:"彭博已更新"`
	PbNotUpdate                 int `description:"彭博未更新"`
	PbFinanceUpdate             int `description:"彭博财务已更新"`
	PbFinanceNotUpdate          int `description:"彭博财务未更新"`
	LzUpdate                    int `description:"隆众已更新"`
	LzNotUpdate                 int `description:"隆众未更新"`
	SmmUpdate                   int `description:"Smm已更新"`
	SmmNotUpdate                int `description:"Smm未更新"`
	MysteelUpdate               int `description:"钢联已更新"`
	MysteelNotUpdate            int `description:"钢联未更新"`
	ZzUpdate                    int `description:"郑商所已更新"`
	ZzNotUpdate                 int `description:"郑商所未更新"`
	DlUpdate                    int `description:"大商所已更新"`
	DlNotUpdate                 int `description:"大商所未更新"`
	ShUpdate                    int `description:"上期所已更新"`
	ShNotUpdate                 int `description:"上期所未更新"`
	CffexUpdate                 int `description:"中金所已更新"`
	CffexNotUpdate              int `description:"中金所未更新"`
	ShfeUpdate                  int `description:"上期能源已更新"`
	ShfeNotUpdate               int `description:"上期能源未更新"`
	GieUpdate                   int `description:"欧洲天然气已更新"`
	GieNotUpdate                int `description:"欧洲天然气未更新"`
	CalculateUpdate             int `description:"计算指标已更新"`
	CalculateNotUpdate          int `description:"计算指标未更新"`
	ManualUpdate                int `description:"手工指标已更新"`
	ManualNotUpdate             int `description:"手工指标未更新"`
	LtUpdate                    int `description:"路透已更新"`
	LtNotUpdate                 int `description:"路透未更新"`
	CoalUpdate                  int `description:"煤炭网已更新"`
	CoalNotUpdate               int `description:"煤炭网未更新"`
	GoogleTravelUpdate          int `description:"谷歌出行已更新"`
	GoogleTravelNotUpdate       int `description:"谷歌出行未更新"`
	EiaSteoUpdate               int `description:"eia steo报告已更新"`
	EiaSteoNotUpdate            int `description:"eia steo报告未更新"`
	UNUpdate                    int `description:"UN报告已更新"`
	UNNotUpdate                 int `description:"UN报告未更新"`
	SciUpdate                   int `description:"卓创数据已更新"`
	SciNotUpdate                int `description:"卓创数据未更新"`
	BaiinfoUpdate               int `description:"百川盈孚数据已更新"`
	BaiinfoNotUpdate            int `description:"百川盈孚数据未更新"`
	NationalStatisticsUpdate    int `description:"国家统计局数据已更新"`
	NationalStatisticsNotUpdate int `description:"国家统计局数据未更新"`
	FubaoUpdate                 int `description:"富宝已更新"`
	FubaoNotUpdate              int `description:"富宝未更新"`
}

func GetUpdatesList(condition string, pars []interface{}, startSize, pageSize int) (list []*EdbInfoView, err error) {
	sql := ` SELECT * FROM edb_info
			WHERE 1=1 `
	sql += condition
	sql += ` LIMIT ?,? `
	pars = append(pars, startSize)
	pars = append(pars, pageSize)
	err = global.DmSQL["data"].Raw(sql, pars...).Scan(&list).Error

	return
}

// GetAllUpdatesList 获取所有待更新的指标
func GetAllUpdatesList() (list []*EdbInfoView, err error) {
	o := global.DmSQL["data"]
	sql := ` SELECT * FROM edb_info
			WHERE 1=1 AND  is_update=? AND no_update=? AND edb_info_type = ? ORDER BY edb_type ASC `
	err = o.Raw(sql, 1, 0, 0).Scan(&list).Error

	return
}

func GetUpdatesListTotal(condition string, pars []interface{}) (count int, err error) {
	o := global.DmSQL["data"]
	sql := ` SELECT COUNT(1) AS count FROM edb_info
			WHERE 1=1 `
	sql += condition
	err = o.Raw(sql, pars...).Scan(&count).Error

	return
}

type UpdatesListResp struct {
	List   []*EdbInfoView
	Total  int
	Paging *paging.PagingItem
}