1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660 |
- package models
- import (
- "errors"
- "eta_gn/eta_chart_lib/global"
- "eta_gn/eta_chart_lib/models/mgo"
- "eta_gn/eta_chart_lib/utils"
- "fmt"
- "strconv"
- "time"
- "go.mongodb.org/mongo-driver/bson"
- "gorm.io/gorm"
- "github.com/nosixtools/solarlunar"
- )
- // type ChartInfo struct {
- // ChartInfoId int `json:"-" orm:"column(chart_info_id);pk"`
- // ChartName string `description:"来源名称"`
- // ChartNameEn string `description:"英文图表名称"`
- // ChartClassifyId int `json:"-" description:"图表分类id"`
- // SysUserId int `json:"-"`
- // SysUserRealName string `json:"-"`
- // UniqueCode string `description:"图表唯一编码"`
- // CreateTime time.Time `json:"-"`
- // ModifyTime time.Time `json:"-"`
- // DateType int `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间"`
- // StartDate string `description:"自定义开始日期"`
- // EndDate string `description:"自定义结束日期"`
- // IsSetName int `description:"设置名称"`
- // EdbInfoIds string `description:"指标id"`
- // ChartType int `description:"生成样式:1:曲线图,2:季节性图"`
- // Calendar string `description:"公历/农历"`
- // SeasonStartDate string `description:"季节性图开始日期"`
- // SeasonEndDate string `description:"季节性图开始日期"`
- // ChartImage string `description:"图表图片"`
- // BarConfig string `description:"柱方图的配置,json数据" json:"-"`
- // XMin string `description:"图表X轴最小值"`
- // XMax string `description:"图表X轴最大值"`
- // LeftMin string `description:"图表左侧最小值"`
- // LeftMax string `description:"图表左侧最大值"`
- // RightMin string `description:"图表右侧最小值"`
- // RightMax string `description:"图表右侧最大值"`
- // Right2Min string `description:"图表右侧2最小值"`
- // Right2Max string `description:"图表右侧2最大值"`
- // MinMaxSave int `description:"是否手动保存过上下限:0-否;1-是"`
- // Source int `description:"1:ETA图库;2:商品价格曲线"`
- // Unit string `description:"中文单位名称"`
- // UnitEn string `description:"英文单位名称"`
- // ExtraConfig string `description:"图表额外配置,json数据" json:"-"`
- // ChartSource string `description:"图表来源str"`
- // ChartSourceEn string `description:"图表来源(英文)"`
- // SeasonExtraConfig string `description:"季节性图表中的配置,json数据"`
- // StartYear int `description:"当选择的日期类型为最近N年类型时,即date_type=20, 用start_year表示N"`
- // ChartThemeId int `description:"图表应用主题ID"`
- // ChartThemeStyle string `description:"图表应用主题样式"`
- // SourcesFrom string `description:"图表来源"`
- // Instructions string `description:"图表说明"`
- // MarkersLines string `description:"标识线"`
- // MarkersAreas string `description:"标识区"`
- // }
- type ChartInfo struct {
- ChartInfoId int `gorm:"column:chart_info_id;primaryKey" json:"-" orm:"column(chart_info_id);pk"`
- ChartName string `gorm:"column:chart_name" description:"来源名称"`
- ChartNameEn string `gorm:"column:chart_name_en" description:"英文图表名称"`
- ChartClassifyId int `gorm:"column:chart_classify_id" json:"-" description:"图表分类id"`
- SysUserId int `gorm:"column:sys_user_id" json:"-"`
- SysUserRealName string `gorm:"column:sys_user_real_name" json:"-"`
- UniqueCode string `gorm:"column:unique_code" description:"图表唯一编码"`
- CreateTime time.Time `gorm:"column:create_time" json:"-"`
- ModifyTime time.Time `gorm:"column:modify_time" json:"-"`
- DateType int `gorm:"column:date_type" description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间"`
- StartDate string `gorm:"column:start_date" description:"自定义开始日期"`
- EndDate string `gorm:"column:end_date" description:"自定义结束日期"`
- IsSetName int `gorm:"column:is_set_name" description:"设置名称"`
- EdbInfoIds string `gorm:"column:edb_info_ids" description:"指标id"`
- ChartType int `gorm:"column:chart_type" description:"生成样式:1:曲线图,2:季节性图"`
- Calendar string `gorm:"column:calendar" description:"公历/农历"`
- SeasonStartDate string `gorm:"column:season_start_date" description:"季节性图开始日期"`
- SeasonEndDate string `gorm:"column:season_end_date" description:"季节性图结束日期"`
- ChartImage string `gorm:"column:chart_image" description:"图表图片"`
- BarConfig string `gorm:"column:bar_config" description:"柱方图的配置,json数据" json:"-"`
- XMin string `gorm:"column:x_min" description:"图表X轴最小值"`
- XMax string `gorm:"column:x_max" description:"图表X轴最大值"`
- LeftMin string `gorm:"column:left_min" description:"图表左侧最小值"`
- LeftMax string `gorm:"column:left_max" description:"图表左侧最大值"`
- RightMin string `gorm:"column:right_min" description:"图表右侧最小值"`
- RightMax string `gorm:"column:right_max" description:"图表右侧最大值"`
- Right2Min string `gorm:"column:right2_min" description:"图表右侧2最小值"`
- Right2Max string `gorm:"column:right2_max" description:"图表右侧2最大值"`
- MinMaxSave int `gorm:"column:min_max_save" description:"是否手动保存过上下限:0-否;1-是"`
- Source int `gorm:"column:source" description:"1:ETA图库;2:商品价格曲线"`
- Unit string `gorm:"column:unit" description:"中文单位名称"`
- UnitEn string `gorm:"column:unit_en" description:"英文单位名称"`
- ExtraConfig string `gorm:"column:extra_config" description:"图表额外配置,json数据" json:"-"`
- ChartSource string `gorm:"column:chart_source" description:"图表来源"`
- ChartSourceEn string `gorm:"column:chart_source_en" description:"图表来源(英文)"`
- SeasonExtraConfig string `gorm:"column:season_extra_config" description:"季节性图表中的配置,json数据"`
- StartYear int `gorm:"column:start_year" description:"当选择的日期类型为最近N年类型时,即date_type=20,用start_year表示N"`
- ChartThemeId int `gorm:"column:chart_theme_id" description:"图表应用主题ID"`
- ChartThemeStyle string `gorm:"column:chart_theme_style" description:"图表应用主题样式"`
- SourcesFrom string `gorm:"column:sources_from" description:"图表来源"`
- Instructions string `gorm:"column:instructions" description:"图表说明"`
- MarkersLines string `gorm:"column:markers_lines" description:"标识线"`
- MarkersAreas string `gorm:"column:markers_areas" description:"标识区"`
- }
- func (c *ChartInfo) TableName() string {
- return "chart_info"
- }
- func GetChartInfoByUniqueCode(uniqueCode string) (item *ChartInfo, err error) {
- o := global.DmSQL["data"]
- sql := ` SELECT * FROM chart_info WHERE unique_code=? `
- err = o.Raw(sql, uniqueCode).First(&item).Error
- return
- }
- // func GetChartInfoByUniqueCode(uniqueCode string) (item *ChartInfo, err error) {
- // o := orm.NewOrmUsingDB("data")
- // sql := ` SELECT * FROM chart_info WHERE unique_code=? `
- // err = o.Raw(sql, uniqueCode).QueryRow(&item)
- // return
- // }
- // type ChartEdbInfoMapping struct {
- // EdbInfoId int `description:"指标id"`
- // SourceName string `description:"来源名称"`
- // Source int `description:"来源id"`
- // EdbCode string `description:"指标编码"`
- // EdbName string `description:"指标名称"`
- // EdbAliasName string `description:"指标名称(别名)"`
- // EdbAliasNameEn string `description:"英文指标名称(别名)"`
- // EdbNameEn string `description:"英文指标名称"`
- // Frequency string `description:"频率"`
- // FrequencyEn string `description:"英文频率"`
- // Unit string `description:"单位"`
- // UnitEn string `description:"英文单位"`
- // StartDate string `description:"起始日期"`
- // EndDate string `description:"终止日期"`
- // ModifyTime string `description:"指标最后更新时间"`
- // ChartEdbMappingId int `description:"图表指标id" json:"-"`
- // ChartInfoId int `description:"图表id"`
- // MaxData float64 `description:"上限"`
- // MinData float64 `description:"下限"`
- // IsOrder bool `description:"true:正序,false:逆序"`
- // IsAxis int `description:"1:左轴,0:右轴"`
- // EdbInfoType int `description:"1:标准指标,0:领先指标"`
- // EdbType int `description:"指标类型:1:基础指标,2:计算指标"`
- // LeadValue int `description:"领先值"`
- // LeadUnit string `description:"领先单位"`
- // LeadUnitEn string `description:"领先英文单位"`
- // ChartStyle string `description:"图表类型"`
- // ChartColor string `description:"颜色"`
- // ChartWidth float64 `description:"线条大小"`
- // DataList interface{}
- // EdbInfoCategoryType int `description:"0:普通指标,1:预测指标"`
- // PredictChartColor string `description:"预测数据的颜色"`
- // ChartType int `description:"生成样式:1:曲线图,2:季节性图,3:面积图,4:柱状图,5:散点图,6:组合图"`
- // LatestDate string `description:"数据最新日期"`
- // LatestValue float64 `description:"数据最新值"`
- // MoveLatestDate string `description:"移动后的数据最新日期"`
- // UniqueCode string `description:"指标唯一编码"`
- // MinValue float64 `json:"-" description:"最小值"`
- // MaxValue float64 `json:"-" description:"最大值"`
- // IsNullData bool `json:"-" description:"是否空数据"`
- // MappingSource int `description:"1:ETA图库;2:商品价格曲线"`
- // SubSource int `description:"子数据来源:0:经济数据库,1:日期序列"`
- // SubSourceName string `description:"子数据来源名称"`
- // IndicatorCode string `description:"指标代码"`
- // StockCode string `description:"证券代码"`
- // IsConvert int `description:"是否数据转换 0不转 1转"`
- // ConvertType int `description:"数据转换类型 1乘 2除 3对数"`
- // ConvertValue float64 `description:"数据转换值"`
- // ConvertUnit string `description:"数据转换单位"`
- // ConvertEnUnit string `description:"数据转换单位"`
- // ClassifyId int `description:"分类id"`
- // IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
- // }
- type ChartEdbInfoMapping struct {
- EdbInfoId int `gorm:"column:edb_info_id;primaryKey" description:"指标id"`
- SourceName string `gorm:"column:source_name" description:"来源名称"`
- Source int `gorm:"column:source" description:"来源id"`
- EdbCode string `gorm:"column:edb_code" description:"指标编码"`
- EdbName string `gorm:"column:edb_name" description:"指标名称"`
- EdbAliasName string `gorm:"column:edb_alias_name" description:"指标名称(别名)"`
- EdbAliasNameEn string `gorm:"column:edb_alias_name_en" description:"英文指标名称(别名)"`
- EdbNameEn string `gorm:"column:edb_name_en" description:"英文指标名称"`
- Frequency string `gorm:"column:frequency" description:"频率"`
- FrequencyEn string `gorm:"column:frequency_en" description:"英文频率"`
- Unit string `gorm:"column:unit" description:"单位"`
- UnitEn string `gorm:"column:unit_en" description:"英文单位"`
- StartDate string `gorm:"column:start_date" description:"起始日期"`
- EndDate string `gorm:"column:end_date" description:"终止日期"`
- ModifyTime string `gorm:"column:modify_time" description:"指标最后更新时间"`
- ChartEdbMappingId int `gorm:"column:chart_edb_mapping_id" description:"图表指标id" json:"-"`
- ChartInfoId int `gorm:"column:chart_info_id" description:"图表id"`
- MaxData float64 `gorm:"column:max_data" description:"上限"`
- MinData float64 `gorm:"column:min_data" description:"下限"`
- IsOrder bool `gorm:"column:is_order" description:"true:正序,false:逆序"`
- IsAxis int `gorm:"column:is_axis" description:"1:左轴,0:右轴"`
- EdbInfoType int `gorm:"column:edb_info_type" description:"1:标准指标,0:领先指标"`
- EdbType int `gorm:"column:edb_type" description:"指标类型:1:基础指标,2:计算指标"`
- LeadValue int `gorm:"column:lead_value" description:"领先值"`
- LeadUnit string `gorm:"column:lead_unit" description:"领先单位"`
- LeadUnitEn string `gorm:"column:lead_unit_en" description:"领先英文单位"`
- ChartStyle string `gorm:"column:chart_style" description:"图表类型"`
- ChartColor string `gorm:"column:chart_color" description:"颜色"`
- ChartWidth float64 `gorm:"column:chart_width" description:"线条大小"`
- DataList interface{} `gorm:"column:data_list" description:"数据列表"`
- EdbInfoCategoryType int `gorm:"column:edb_info_category_type" description:"0:普通指标,1:预测指标"`
- PredictChartColor string `gorm:"column:predict_chart_color" description:"预测数据的颜色"`
- ChartType int `gorm:"column:chart_type" description:"生成样式:1:曲线图,2:季节性图,3:面积图,4:柱状图,5:散点图,6:组合图"`
- LatestDate string `gorm:"column:latest_date" description:"数据最新日期"`
- LatestValue float64 `gorm:"column:latest_value" description:"数据最新值"`
- MoveLatestDate string `gorm:"column:move_latest_date" description:"移动后的数据最新日期"`
- UniqueCode string `gorm:"column:unique_code" description:"指标唯一编码"`
- MinValue float64 `gorm:"column:min_value" json:"-" description:"最小值"`
- MaxValue float64 `gorm:"column:max_value" json:"-" description:"最大值"`
- IsNullData bool `gorm:"column:is_null_data" json:"-" description:"是否空数据"`
- MappingSource int `gorm:"column:mapping_source" description:"1:ETA图库;2:商品价格曲线"`
- SubSource int `gorm:"column:sub_source" description:"子数据来源:0:经济数据库,1:日期序列"`
- SubSourceName string `gorm:"column:sub_source_name" description:"子数据来源名称"`
- IndicatorCode string `gorm:"column:indicator_code" description:"指标代码"`
- StockCode string `gorm:"column:stock_code" description:"证券代码"`
- IsConvert int `gorm:"column:is_convert" description:"是否数据转换 0不转 1转"`
- ConvertType int `gorm:"column:convert_type" description:"数据转换类型 1乘 2除 3对数"`
- ConvertValue float64 `gorm:"column:convert_value" description:"数据转换值"`
- ConvertUnit string `gorm:"column:convert_unit" description:"数据转换单位"`
- ConvertEnUnit string `gorm:"column:convert_en_unit" description:"数据转换单位英文"`
- ClassifyId int `gorm:"column:classify_id" description:"分类id"`
- IsJoinPermission int `gorm:"column:is_join_permission" description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
- }
- func GetChartEdbMappingList(chartInfoId int) (list []*ChartEdbInfoMapping, err error) {
- o := global.DmSQL["data"]
- aField := `a.chart_edb_mapping_id,a.chart_info_id,a.edb_info_id,a.create_time,a.modify_time,a.unique_code,a.max_data,a.min_data,a.is_order,a.is_axis,a.edb_info_type,a.lead_value,a.lead_unit,a.chart_style,a.chart_color,a.predict_chart_color,a.chart_width,a.source as mapping_source,a.edb_alias_name`
- sql := ` SELECT ` + aField + `,b.source_name,b.source,b.edb_code,b.edb_name,b.edb_name_en,b.frequency,b.unit,b.unit_en,b.start_date,b.end_date,b.modify_time,b.edb_type,b.latest_date,b.latest_value,b.unique_code,b.edb_info_type AS edb_info_category_type,b.sub_source,
- a.is_convert, a.convert_type, a.convert_value, a.convert_unit, a.convert_en_unit
- FROM chart_edb_mapping AS a
- INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
- WHERE chart_info_id=?
- ORDER BY chart_edb_mapping_id ASC `
- err = o.Raw(sql, chartInfoId).Scan(&list).Error
- return
- }
- // func GetChartEdbMappingList(chartInfoId int) (list []*ChartEdbInfoMapping, err error) {
- // o := orm.NewOrmUsingDB("data")
- // aField := `a.chart_edb_mapping_id,a.chart_info_id,a.edb_info_id,a.create_time,a.modify_time,a.unique_code,a.max_data,a.min_data,a.is_order,a.is_axis,a.edb_info_type,a.lead_value,a.lead_unit,a.chart_style,a.chart_color,a.predict_chart_color,a.chart_width,a.source as mapping_source,a.edb_alias_name`
- // sql := ` SELECT ` + aField + `,b.source_name,b.source,b.edb_code,b.edb_name,b.edb_name_en,b.frequency,b.unit,b.unit_en,b.start_date,b.end_date,b.modify_time,b.edb_type,b.latest_date,b.latest_value,b.unique_code,b.edb_info_type AS edb_info_category_type,b.sub_source,
- // a.is_convert, a.convert_type, a.convert_value, a.convert_unit, a.convert_en_unit
- // FROM chart_edb_mapping AS a
- // INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
- // WHERE chart_info_id=?
- // ORDER BY chart_edb_mapping_id ASC `
- // _, err = o.Raw(sql, chartInfoId).QueryRows(&list)
- // return
- // }
- // type EdbDataList struct {
- // EdbDataId int `json:"-" description:" 指标数据ID"`
- // EdbInfoId int `json:"-" description:"指标ID"`
- // DataTime string `description:"数据日期"`
- // DataTimestamp int64 `description:"数据日期"`
- // Value float64 `description:"数据值"`
- // }
- type EdbDataList struct {
- EdbDataId int `gorm:"column:edb_data_id;primaryKey" description:"指标数据ID"`
- EdbInfoId int `gorm:"column:edb_info_id" description:"指标ID"`
- DataTime string `gorm:"column:data_time" description:"数据日期"`
- DataTimestamp int64 `gorm:"column:data_timestamp" description:"数据日期时间戳"`
- Value float64 `gorm:"column:value" description:"数据值"`
- }
- func (e *EdbDataList) AfterFind(db *gorm.DB) (err error) {
- tmp, err := time.Parse(utils.FormatDateWallWithLoc, e.DataTime)
- if err != nil {
- return
- }
- e.DataTime = tmp.Format(utils.FormatDate)
- return
- }
- // GetEdbDataList 获取指标的数据(日期正序返回)
- func GetEdbDataList(source, subSource, edbInfoId int, startDate, endDate string) (list []*EdbDataList, err error) {
- // 自有数据需要额外处理(从mongo获取)
- if source == utils.DATA_SOURCE_BUSINESS && utils.UseMongo {
- return getEdbDataListByMongo(source, subSource, edbInfoId, startDate, endDate)
- }
- if source == utils.DATA_SOURCE_THS && subSource == utils.DATA_SUB_SOURCE_HIGH_FREQUENCY && utils.UseMongo {
- return getThsHfEdbDataListByMongo(source, subSource, edbInfoId, startDate, endDate)
- }
- return getEdbDataListByMysql(source, subSource, edbInfoId, startDate, endDate)
- }
- // getEdbDataListByMysql
- // @Description: 从mysql中获取指标的数据(日期正序返回)
- // @author: Roc
- // @datetime 2024-05-08 16:49:48
- // @param source int
- // @param subSource int
- // @param edbInfoId int
- // @param startDate string
- // @param endDate string
- // @return list []*EdbDataList
- // @return err error
- func getEdbDataListByMysql(source, subSource, edbInfoId int, startDate, endDate string) (list []*EdbDataList, err error) {
- tableName := GetEdbDataTableName(source, subSource)
- if tableName == "" {
- err = errors.New("无效的渠道:" + strconv.Itoa(source))
- list = make([]*EdbDataList, 0)
- return list, err
- }
- var pars []interface{}
- var condition string
- if startDate != "" {
- condition += ` AND data_time>=? `
- pars = append(pars, startDate)
- }
- if endDate != "" {
- condition += ` AND data_time<=? `
- pars = append(pars, endDate)
- }
- sql := `SELECT edb_data_id,edb_info_id,data_time,"value",data_timestamp FROM %s WHERE edb_info_id=? `
- if condition != "" {
- sql += condition
- }
- sql += ` ORDER BY data_time ASC `
- sql = fmt.Sprintf(sql, tableName)
- o := global.DmSQL["data"]
- pars = append([]interface{}{edbInfoId}, pars...)
- err = o.Raw(sql, pars...).Find(&list).Error
- return
- }
- // getEdbDataListByMongo
- // @Description: 从mongo中获取指标的数据(日期正序返回)
- // @author: Roc
- // @datetime 2024-05-08 16:49:59
- // @param source int
- // @param subSource int
- // @param edbInfoId int
- // @param startDate string
- // @param endDate string
- // @return list []*EdbDataList
- // @return err error
- func getEdbDataListByMongo(source, subSource, edbInfoId int, startDate, endDate string) (list []*EdbDataList, err error) {
- list = make([]*EdbDataList, 0)
- mogDataObj := mgo.EdbDataBusiness{}
- // 构建查询条件
- queryConditions := bson.M{
- "edb_info_id": edbInfoId,
- }
- // 日期
- dateCondition, err := mgo.BuildDateCondition(startDate, endDate)
- if err != nil {
- return
- }
- if len(dateCondition) > 0 {
- queryConditions["data_time"] = dateCondition
- }
- // 获取列表数据
- tmpDataList, tmpErr := mogDataObj.GetAllDataList(queryConditions, []string{"data_time"})
- if tmpErr != nil {
- err = tmpErr
- return
- }
- for k, v := range tmpDataList {
- list = append(list, &EdbDataList{
- EdbDataId: k + 1,
- EdbInfoId: v.EdbInfoId,
- DataTime: v.DataTime.Format(utils.FormatDate),
- DataTimestamp: v.DataTimestamp,
- Value: v.Value,
- })
- }
- return
- }
- // getEdbDataListByMysql
- // @Description: 从mysql中获取指标的数据(日期正序返回)
- // @author: Roc
- // @datetime 2024-05-08 16:49:48
- // @param source int
- // @param subSource int
- // @param edbInfoId int
- // @param startDate string
- // @param endDate string
- // @return list []*EdbDataList
- // @return err error
- // func getEdbDataListByMysql(source, subSource, edbInfoId int, startDate, endDate string) (list []*EdbDataList, err error) {
- // tableName := GetEdbDataTableName(source, subSource)
- // if tableName == "" {
- // err = errors.New("无效的渠道:" + strconv.Itoa(source))
- // list = make([]*EdbDataList, 0)
- // return list, err
- // }
- // var pars []interface{}
- // var condition string
- // if startDate != "" {
- // condition += ` AND data_time>=? `
- // pars = append(pars, startDate)
- // }
- // if endDate != "" {
- // condition += ` AND data_time<=? `
- // pars = append(pars, endDate)
- // }
- // sql := `SELECT edb_data_id,edb_info_id,data_time,value,data_timestamp FROM %s WHERE edb_info_id=? `
- // if condition != "" {
- // sql += condition
- // }
- // sql += ` ORDER BY data_time ASC `
- // sql = fmt.Sprintf(sql, tableName)
- // o := orm.NewOrmUsingDB("data")
- // _, err = o.Raw(sql, edbInfoId, pars).QueryRows(&list)
- // return
- // }
- // // getEdbDataListByMongo
- // // @Description: 从mongo中获取指标的数据(日期正序返回)
- // // @author: Roc
- // // @datetime 2024-05-08 16:49:59
- // // @param source int
- // // @param subSource int
- // // @param edbInfoId int
- // // @param startDate string
- // // @param endDate string
- // // @return list []*EdbDataList
- // // @return err error
- // func getEdbDataListByMongo(source, subSource, edbInfoId int, startDate, endDate string) (list []*EdbDataList, err error) {
- // list = make([]*EdbDataList, 0)
- // mogDataObj := mgo.EdbDataBusiness{}
- // // 构建查询条件
- // queryConditions := bson.M{
- // "edb_info_id": edbInfoId,
- // }
- // // 日期
- // dateCondition, err := mgo.BuildDateCondition(startDate, endDate)
- // if err != nil {
- // return
- // }
- // if len(dateCondition) > 0 {
- // queryConditions["data_time"] = dateCondition
- // }
- // // 获取列表数据
- // tmpDataList, tmpErr := mogDataObj.GetAllDataList(queryConditions, []string{"data_time"})
- // if tmpErr != nil {
- // err = tmpErr
- // return
- // }
- // for k, v := range tmpDataList {
- // list = append(list, &EdbDataList{
- // EdbDataId: k + 1,
- // EdbInfoId: v.EdbInfoId,
- // DataTime: v.DataTime.Format(utils.FormatDate),
- // DataTimestamp: v.DataTimestamp,
- // Value: v.Value,
- // })
- // }
- // return
- // }
- type EdbDataItemList struct {
- EdbDataId int `json:"-" description:" 指标数据ID"`
- EdbInfoId int `json:"-" description:"指标ID"`
- DataTime string `description:"数据日期"`
- DataTimestamp int64 `description:"数据日期"`
- Value float64 `description:"数据值"`
- }
- // type EdbDataItems struct {
- // Items []*EdbDataList
- // Year int
- // BetweenDay int `json:"-" description:"公历与农历之间相差的天数"`
- // CuttingDataTimestamp int64 `description:"切割的时间戳"`
- // }
- type EdbDataItems struct {
- Items []*EdbDataList `gorm:"column:items" description:"指标数据项列表"`
- Year int `gorm:"column:year" description:"年份"`
- BetweenDay int `gorm:"column:between_day" json:"-" description:"公历与农历之间相差的天数"`
- CuttingDataTimestamp int64 `gorm:"column:cutting_data_timestamp" description:"切割的时间戳"`
- }
- type EdbDataResult struct {
- List []*EdbDataItems
- }
- type QuarterData struct {
- Year string
- DataList []*EdbDataList
- CuttingDataTimestamp int64 `description:"切割的时间戳"`
- ChartLegend string
- Years string
- }
- type QuarterXDateItem struct {
- StartDate time.Time
- EndDate time.Time
- ShowName string
- ChartLegend string
- CuttingDataTimestamp int64 `description:"切割的时间戳"`
- }
- type ChartInfoDetailResp struct {
- ChartInfo *ChartInfo
- EdbInfoList []*ChartEdbInfoMapping
- XEdbIdValue []int `description:"柱方图的x轴数据,指标id"`
- YDataList []YData `description:"柱方图的y轴数据"`
- XDataList []XData `description:"商品价格曲线的X轴数据"`
- CorrelationChartInfo *CorrelationInfo `description:"相关性图表信息"`
- DataResp interface{} `description:"图表数据,根据图的类型而定的,没有确定的数据格式"`
- WaterMark string `description:"水印"`
- IsCollect bool `description:"是否收藏"`
- }
- // XData 商品价格曲线的的x轴数据
- type XData struct {
- Name string `description:"别名"`
- NameEn string `description:"英文别名"`
- IsHide int `description:"是否隐藏,0不隐藏,1隐藏"`
- }
- // YData 柱方图的y轴数据
- type YData struct {
- Date string `description:"数据日期"`
- ConfigDate time.Time `description:"配置的日期" json:"-"`
- Color string `description:"数据颜色"`
- Name string `description:"别名"`
- NameEn string `description:"英文别名"`
- Value []float64 `description:"每个指标的值"`
- NoDataEdbList []int `description:"没有数据的指标列表"`
- XEdbInfoIdList []int `description:"对应X轴的指标id列表"`
- EdbValMap map[int]float64 `description:"指标与值的对应" json:"-"`
- M []int `description:"对应开始日期的间隔值" json:"-"`
- NameList []string `description:"每个值对应的名称"`
- EnNameList []string `description:"每个值对应的英文名称"`
- SeriesEdb struct {
- SeriesId int `description:"因子指标系列ID"`
- EdbInfoId int `description:"指标ID"`
- } `description:"对应的系列指标"`
- }
- // RollingCorrelationChartDataResp 滚动相关性图
- type RollingCorrelationChartDataResp struct {
- XDateTimeValue []string `description:"滚动相关性图的x轴数据,日期数据"`
- YDataList []YData `description:"滚动相关性图的y轴数据"`
- }
- // 指标季度数据计算(公历转农历)
- func AddCalculateQuarterV5(dataList []*EdbDataList) (result *EdbDataResult, err error) {
- var errMsg string
- defer func() {
- if errMsg != "" {
- fmt.Println("errMsg:", errMsg)
- }
- }()
- if len(dataList) <= 0 {
- result.List = make([]*EdbDataItems, 0)
- return
- }
- endDate := dataList[len(dataList)-1].DataTime
- endDateForm, err := time.Parse(utils.FormatDate, endDate)
- if err != nil {
- return result, err
- }
- thisMonth := int(endDateForm.Month())
- result = new(EdbDataResult)
- var yearArr []int
- yearMap := make(map[int]int)
- var cureentDate time.Time
- if thisMonth < 11 {
- for k, v := range dataList {
- dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
- if err != nil {
- errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
- return result, err
- }
- if k == len(dataList)-1 {
- cureentDate = dateTime
- }
- year := dateTime.Year()
- if _, ok := yearMap[year]; !ok {
- yearArr = append(yearArr, year)
- }
- yearMap[year] = year
- }
- } else {
- for k, v := range dataList {
- dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
- if err != nil {
- errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
- return result, err
- }
- if k == len(dataList)-1 {
- cureentDate = dateTime
- }
- year := dateTime.Year() + 1
- if _, ok := yearMap[year]; !ok {
- yearArr = append(yearArr, year)
- }
- yearMap[year] = year
- }
- }
- //排序
- fmt.Println("yearArr:", yearArr)
- thisYear := cureentDate.Year()
- //thisMonth := int(cureentDate.Month())
- fmt.Println("thisMonth:", thisMonth)
- for ky, vy := range yearArr {
- fmt.Println("line 432:", ky, vy, thisYear, thisMonth)
- if thisMonth < 11 {
- currentYearCjnl := strconv.Itoa(thisYear) + "-01-01" //当前年份春节农历
- currentYearCjgl := solarlunar.LunarToSolar(currentYearCjnl, false) //当前年份春节公历
- currentYearCjglDate, err := time.Parse(utils.FormatDate, currentYearCjgl)
- if err != nil {
- errMsg = "生成当前春节失败,Err:" + err.Error()
- return result, err
- }
- preYear := vy
- preYearCjnl := strconv.Itoa(preYear) + "-01-01" //之前年份春节农历
- preYearCjgl := solarlunar.LunarToSolar(preYearCjnl, false) //之前年份春节公历
- preYearCjglDate, err := time.Parse(utils.FormatDate, preYearCjgl)
- if err != nil {
- errMsg = "生成历史年份春节失败,Err:" + err.Error()
- return result, err
- }
- day := currentYearCjglDate.Sub(preYearCjglDate).Hours() / float64(24)
- items := new(EdbDataItems)
- items.BetweenDay = int(day) //公历日期换算成农历,需要减除的天数
- items.Year = preYear
- for _, v := range dataList {
- dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
- if err != nil {
- errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
- return result, err
- }
- newDate := dateTime.AddDate(0, 0, int(day))
- selectDateStr := strconv.Itoa(thisYear) + "-11" + "-30"
- selectDate, _ := time.Parse(utils.FormatDate, selectDateStr)
- if newDate.Before(selectDate) || newDate == selectDate {
- timestamp := newDate.UnixNano() / 1e6
- item := new(EdbDataList)
- item.DataTime = newDate.Format(utils.FormatDate)
- item.EdbInfoId = v.EdbInfoId
- item.Value = v.Value
- item.EdbDataId = v.EdbDataId
- item.DataTimestamp = timestamp
- items.Items = append(items.Items, item)
- }
- }
- result.List = append(result.List, items)
- } else {
- nextYear := thisYear + 1
- nextYearCjnl := strconv.Itoa(nextYear) + "-01-01" //当前年份春节农历
- nextYearCjgl := solarlunar.LunarToSolar(nextYearCjnl, false) //当前年份春节公历
- nextYearCjglDate, err := time.Parse(utils.FormatDate, nextYearCjgl)
- if err != nil {
- errMsg = "生成当前春节失败,Err:" + err.Error()
- return result, err
- }
- preYear := vy
- preYearCjnl := strconv.Itoa(preYear) + "-01-01" //之前年份春节农历
- preYearCjgl := solarlunar.LunarToSolar(preYearCjnl, false) //之前年份春节公历
- preYearCjglDate, err := time.Parse(utils.FormatDate, preYearCjgl)
- if err != nil {
- errMsg = "生成历史年份春节失败,Err:" + err.Error()
- return result, err
- }
- day := nextYearCjglDate.Sub(preYearCjglDate).Hours() / float64(24)
- fmt.Println("day:", day, nextYearCjglDate, preYearCjglDate)
- items := new(EdbDataItems)
- items.BetweenDay = int(day) //公历日期换算成农历,需要减除的天数
- items.Year = preYear - 1
- fmt.Println("preYear:", preYear, "ky:", ky, "yearArrLen:", len(yearArr))
- if ky+1 < len(yearArr) {
- for _, v := range dataList {
- dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
- if err != nil {
- errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
- return result, err
- }
- newDate := dateTime.AddDate(0, 0, int(day))
- selectDateStr := strconv.Itoa(nextYear) + "-05" + "-31"
- selectDate, _ := time.Parse(utils.FormatDate, selectDateStr)
- if newDate.Before(selectDate) || newDate == selectDate {
- timestamp := newDate.UnixNano() / 1e6
- item := new(EdbDataList)
- item.DataTime = newDate.Format(utils.FormatDate)
- item.EdbInfoId = v.EdbInfoId
- item.Value = v.Value
- item.EdbDataId = v.EdbDataId
- item.DataTimestamp = timestamp
- items.Items = append(items.Items, item)
- }
- }
- result.List = append(result.List, items)
- } else {
- for _, v := range dataList {
- dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
- if err != nil {
- errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
- return result, err
- }
- timestamp := dateTime.UnixNano() / 1e6
- item := new(EdbDataList)
- item.DataTime = dateTime.Format(utils.FormatDate)
- item.EdbInfoId = v.EdbInfoId
- item.Value = v.Value
- item.EdbDataId = v.EdbDataId
- item.DataTimestamp = timestamp
- items.Items = append(items.Items, item)
- }
- result.List = append(result.List, items)
- }
- }
- }
- return
- }
- // AddCalculateQuarterV6 指标季度数据计算(季节性图表)
- func AddCalculateQuarterV6(dataList []*EdbDataList) (result *EdbDataResult, err error) {
- var errMsg string
- defer func() {
- if errMsg != "" {
- fmt.Println("errMsg:", errMsg)
- }
- }()
- endDate := dataList[len(dataList)-1].DataTime
- endDateForm, err := time.Parse(utils.FormatDate, endDate)
- if err != nil {
- return result, err
- }
- thisMonth := int(endDateForm.Month())
- result = new(EdbDataResult)
- var yearArr []int
- yearMap := make(map[int]int)
- var cureentDate time.Time
- if thisMonth < 11 {
- for k, v := range dataList {
- dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
- if err != nil {
- errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
- return result, err
- }
- if k == len(dataList)-1 {
- cureentDate = dateTime
- }
- year := dateTime.Year()
- if _, ok := yearMap[year]; !ok {
- yearArr = append(yearArr, year)
- }
- yearMap[year] = year
- }
- } else {
- for k, v := range dataList {
- dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
- if err != nil {
- errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
- return result, err
- }
- if k == len(dataList)-1 {
- cureentDate = dateTime
- }
- year := dateTime.Year() + 1
- if _, ok := yearMap[year]; !ok {
- yearArr = append(yearArr, year)
- }
- yearMap[year] = year
- }
- }
- //排序
- fmt.Println("yearArr:", yearArr)
- thisYear := cureentDate.Year()
- //thisMonth := int(cureentDate.Month())
- fmt.Println("thisMonth:", thisMonth)
- for ky, vy := range yearArr {
- fmt.Printf("line 432:ky:%d, vy:%d, thisYear:%d, thisMonth:%d", ky, vy, thisYear, thisMonth)
- fmt.Println("")
- if thisMonth < 11 {
- currentYearCjnl := strconv.Itoa(thisYear) + "-01-01" //当前年份春节农历
- currentYearCjgl := solarlunar.LunarToSolar(currentYearCjnl, false) //当前年份春节公历
- currentYearCjglDate, err := time.Parse(utils.FormatDate, currentYearCjgl)
- if err != nil {
- errMsg = "生成当前春节失败,Err:" + err.Error()
- return result, err
- }
- preYear := vy
- preYearCjnl := strconv.Itoa(preYear) + "-01-01" //之前年份春节农历
- preYearCjgl := solarlunar.LunarToSolar(preYearCjnl, false) //之前年份春节公历
- preYearCjglDate, err := time.Parse(utils.FormatDate, preYearCjgl)
- if err != nil {
- errMsg = "生成历史年份春节失败,Err:" + err.Error()
- return result, err
- }
- day := currentYearCjglDate.Sub(preYearCjglDate).Hours() / float64(24)
- fmt.Println("day:", day, currentYearCjglDate, preYearCjglDate)
- items := new(EdbDataItems)
- items.BetweenDay = int(day) //公历日期换算成农历,需要减除的天数
- items.Year = preYear
- for _, v := range dataList {
- dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
- if err != nil {
- errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
- return result, err
- }
- newDate := dateTime.AddDate(0, 0, int(day))
- timestamp := newDate.UnixNano() / 1e6
- item := new(EdbDataList)
- item.DataTime = newDate.Format(utils.FormatDate)
- item.EdbInfoId = v.EdbInfoId
- item.Value = v.Value
- item.EdbDataId = v.EdbDataId
- item.DataTimestamp = timestamp
- items.Items = append(items.Items, item)
- }
- result.List = append(result.List, items)
- } else {
- nextYear := thisYear + 1
- nextYearCjnl := strconv.Itoa(nextYear) + "-01-01" //当前年份春节农历
- nextYearCjgl := solarlunar.LunarToSolar(nextYearCjnl, false) //当前年份春节公历
- nextYearCjglDate, err := time.Parse(utils.FormatDate, nextYearCjgl)
- if err != nil {
- errMsg = "生成当前春节失败,Err:" + err.Error()
- return result, err
- }
- preYear := vy
- preYearCjnl := strconv.Itoa(preYear) + "-01-01" //之前年份春节农历
- preYearCjgl := solarlunar.LunarToSolar(preYearCjnl, false) //之前年份春节公历
- preYearCjglDate, err := time.Parse(utils.FormatDate, preYearCjgl)
- if err != nil {
- errMsg = "生成历史年份春节失败,Err:" + err.Error()
- return result, err
- }
- day := nextYearCjglDate.Sub(preYearCjglDate).Hours() / float64(24)
- fmt.Println("day:", day, nextYearCjglDate, preYearCjglDate)
- items := new(EdbDataItems)
- items.BetweenDay = int(day) //公历日期换算成农历,需要减除的天数
- items.Year = preYear
- fmt.Println("preYear:", preYear, "ky:", ky, "yearArrLen:", len(yearArr))
- //if ky+1 < len(yearArr) {
- for _, v := range dataList {
- dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
- if err != nil {
- errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
- return result, err
- }
- newDate := dateTime.AddDate(0, 0, int(day))
- timestamp := newDate.UnixNano() / 1e6
- item := new(EdbDataList)
- item.DataTime = newDate.Format(utils.FormatDate)
- item.EdbInfoId = v.EdbInfoId
- item.Value = v.Value
- item.EdbDataId = v.EdbDataId
- item.DataTimestamp = timestamp
- items.Items = append(items.Items, item)
- }
- result.List = append(result.List, items)
- /*} else {
- for _, v := range dataList {
- dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
- if err != nil {
- errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
- return result, err
- }
- timestamp := dateTime.UnixNano() / 1e6
- item := new(EdbDataList)
- item.DataTime = dateTime.Format(utils.FormatDate)
- item.EdbInfoId = v.EdbInfoId
- item.Value = v.Value
- item.EdbDataId = v.EdbDataId
- item.DataTimestamp = timestamp
- items.Items = append(items.Items, item)
- }
- result.List = append(result.List, items)
- }*/
- }
- }
- return
- }
- // func AddCalculateQuarterV5(dataList []*EdbDataList) (result *EdbDataResult, err error) {
- // var errMsg string
- // defer func() {
- // if errMsg != "" {
- // fmt.Println("errMsg:", errMsg)
- // }
- // }()
- // if len(dataList) <= 0 {
- // result.List = make([]*EdbDataItems, 0)
- // return
- // }
- // endDate := dataList[len(dataList)-1].DataTime
- // endDateForm, err := time.Parse(utils.FormatDate, endDate)
- // if err != nil {
- // return result, err
- // }
- // thisMonth := int(endDateForm.Month())
- // result = new(EdbDataResult)
- // var yearArr []int
- // yearMap := make(map[int]int)
- // var cureentDate time.Time
- // if thisMonth < 11 {
- // for k, v := range dataList {
- // dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
- // if err != nil {
- // errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
- // return result, err
- // }
- // if k == len(dataList)-1 {
- // cureentDate = dateTime
- // }
- // year := dateTime.Year()
- // if _, ok := yearMap[year]; !ok {
- // yearArr = append(yearArr, year)
- // }
- // yearMap[year] = year
- // }
- // } else {
- // for k, v := range dataList {
- // dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
- // if err != nil {
- // errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
- // return result, err
- // }
- // if k == len(dataList)-1 {
- // cureentDate = dateTime
- // }
- // year := dateTime.Year() + 1
- // if _, ok := yearMap[year]; !ok {
- // yearArr = append(yearArr, year)
- // }
- // yearMap[year] = year
- // }
- // }
- // //排序
- // fmt.Println("yearArr:", yearArr)
- // thisYear := cureentDate.Year()
- // //thisMonth := int(cureentDate.Month())
- // fmt.Println("thisMonth:", thisMonth)
- // for ky, vy := range yearArr {
- // fmt.Println("line 432:", ky, vy, thisYear, thisMonth)
- // if thisMonth < 11 {
- // currentYearCjnl := strconv.Itoa(thisYear) + "-01-01" //当前年份春节农历
- // currentYearCjgl := solarlunar.LunarToSolar(currentYearCjnl, false) //当前年份春节公历
- // currentYearCjglDate, err := time.Parse(utils.FormatDate, currentYearCjgl)
- // if err != nil {
- // errMsg = "生成当前春节失败,Err:" + err.Error()
- // return result, err
- // }
- // preYear := vy
- // preYearCjnl := strconv.Itoa(preYear) + "-01-01" //之前年份春节农历
- // preYearCjgl := solarlunar.LunarToSolar(preYearCjnl, false) //之前年份春节公历
- // preYearCjglDate, err := time.Parse(utils.FormatDate, preYearCjgl)
- // if err != nil {
- // errMsg = "生成历史年份春节失败,Err:" + err.Error()
- // return result, err
- // }
- // day := currentYearCjglDate.Sub(preYearCjglDate).Hours() / float64(24)
- // items := new(EdbDataItems)
- // items.BetweenDay = int(day) //公历日期换算成农历,需要减除的天数
- // items.Year = preYear
- // for _, v := range dataList {
- // dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
- // if err != nil {
- // errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
- // return result, err
- // }
- // newDate := dateTime.AddDate(0, 0, int(day))
- // selectDateStr := strconv.Itoa(thisYear) + "-11" + "-30"
- // selectDate, _ := time.Parse(utils.FormatDate, selectDateStr)
- // if newDate.Before(selectDate) || newDate == selectDate {
- // timestamp := newDate.UnixNano() / 1e6
- // item := new(EdbDataList)
- // item.DataTime = newDate.Format(utils.FormatDate)
- // item.EdbInfoId = v.EdbInfoId
- // item.Value = v.Value
- // item.EdbDataId = v.EdbDataId
- // item.DataTimestamp = timestamp
- // items.Items = append(items.Items, item)
- // }
- // }
- // result.List = append(result.List, items)
- // } else {
- // nextYear := thisYear + 1
- // nextYearCjnl := strconv.Itoa(nextYear) + "-01-01" //当前年份春节农历
- // nextYearCjgl := solarlunar.LunarToSolar(nextYearCjnl, false) //当前年份春节公历
- // nextYearCjglDate, err := time.Parse(utils.FormatDate, nextYearCjgl)
- // if err != nil {
- // errMsg = "生成当前春节失败,Err:" + err.Error()
- // return result, err
- // }
- // preYear := vy
- // preYearCjnl := strconv.Itoa(preYear) + "-01-01" //之前年份春节农历
- // preYearCjgl := solarlunar.LunarToSolar(preYearCjnl, false) //之前年份春节公历
- // preYearCjglDate, err := time.Parse(utils.FormatDate, preYearCjgl)
- // if err != nil {
- // errMsg = "生成历史年份春节失败,Err:" + err.Error()
- // return result, err
- // }
- // day := nextYearCjglDate.Sub(preYearCjglDate).Hours() / float64(24)
- // fmt.Println("day:", day, nextYearCjglDate, preYearCjglDate)
- // items := new(EdbDataItems)
- // items.BetweenDay = int(day) //公历日期换算成农历,需要减除的天数
- // items.Year = preYear - 1
- // fmt.Println("preYear:", preYear, "ky:", ky, "yearArrLen:", len(yearArr))
- // if ky+1 < len(yearArr) {
- // for _, v := range dataList {
- // dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
- // if err != nil {
- // errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
- // return result, err
- // }
- // newDate := dateTime.AddDate(0, 0, int(day))
- // selectDateStr := strconv.Itoa(nextYear) + "-05" + "-31"
- // selectDate, _ := time.Parse(utils.FormatDate, selectDateStr)
- // if newDate.Before(selectDate) || newDate == selectDate {
- // timestamp := newDate.UnixNano() / 1e6
- // item := new(EdbDataList)
- // item.DataTime = newDate.Format(utils.FormatDate)
- // item.EdbInfoId = v.EdbInfoId
- // item.Value = v.Value
- // item.EdbDataId = v.EdbDataId
- // item.DataTimestamp = timestamp
- // items.Items = append(items.Items, item)
- // }
- // }
- // result.List = append(result.List, items)
- // } else {
- // for _, v := range dataList {
- // dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
- // if err != nil {
- // errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
- // return result, err
- // }
- // timestamp := dateTime.UnixNano() / 1e6
- // item := new(EdbDataList)
- // item.DataTime = dateTime.Format(utils.FormatDate)
- // item.EdbInfoId = v.EdbInfoId
- // item.Value = v.Value
- // item.EdbDataId = v.EdbDataId
- // item.DataTimestamp = timestamp
- // items.Items = append(items.Items, item)
- // }
- // result.List = append(result.List, items)
- // }
- // }
- // }
- // return
- // }
- // // AddCalculateQuarterV6 指标季度数据计算(季节性图表)
- // func AddCalculateQuarterV6(dataList []*EdbDataList) (result *EdbDataResult, err error) {
- // var errMsg string
- // defer func() {
- // if errMsg != "" {
- // fmt.Println("errMsg:", errMsg)
- // }
- // }()
- // endDate := dataList[len(dataList)-1].DataTime
- // endDateForm, err := time.Parse(utils.FormatDate, endDate)
- // if err != nil {
- // return result, err
- // }
- // thisMonth := int(endDateForm.Month())
- // result = new(EdbDataResult)
- // var yearArr []int
- // yearMap := make(map[int]int)
- // var cureentDate time.Time
- // if thisMonth < 11 {
- // for k, v := range dataList {
- // dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
- // if err != nil {
- // errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
- // return result, err
- // }
- // if k == len(dataList)-1 {
- // cureentDate = dateTime
- // }
- // year := dateTime.Year()
- // if _, ok := yearMap[year]; !ok {
- // yearArr = append(yearArr, year)
- // }
- // yearMap[year] = year
- // }
- // } else {
- // for k, v := range dataList {
- // dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
- // if err != nil {
- // errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
- // return result, err
- // }
- // if k == len(dataList)-1 {
- // cureentDate = dateTime
- // }
- // year := dateTime.Year() + 1
- // if _, ok := yearMap[year]; !ok {
- // yearArr = append(yearArr, year)
- // }
- // yearMap[year] = year
- // }
- // }
- // //排序
- // fmt.Println("yearArr:", yearArr)
- // thisYear := cureentDate.Year()
- // //thisMonth := int(cureentDate.Month())
- // fmt.Println("thisMonth:", thisMonth)
- // for ky, vy := range yearArr {
- // fmt.Printf("line 432:ky:%d, vy:%d, thisYear:%d, thisMonth:%d", ky, vy, thisYear, thisMonth)
- // fmt.Println("")
- // if thisMonth < 11 {
- // currentYearCjnl := strconv.Itoa(thisYear) + "-01-01" //当前年份春节农历
- // currentYearCjgl := solarlunar.LunarToSolar(currentYearCjnl, false) //当前年份春节公历
- // currentYearCjglDate, err := time.Parse(utils.FormatDate, currentYearCjgl)
- // if err != nil {
- // errMsg = "生成当前春节失败,Err:" + err.Error()
- // return result, err
- // }
- // preYear := vy
- // preYearCjnl := strconv.Itoa(preYear) + "-01-01" //之前年份春节农历
- // preYearCjgl := solarlunar.LunarToSolar(preYearCjnl, false) //之前年份春节公历
- // preYearCjglDate, err := time.Parse(utils.FormatDate, preYearCjgl)
- // if err != nil {
- // errMsg = "生成历史年份春节失败,Err:" + err.Error()
- // return result, err
- // }
- // day := currentYearCjglDate.Sub(preYearCjglDate).Hours() / float64(24)
- // fmt.Println("day:", day, currentYearCjglDate, preYearCjglDate)
- // items := new(EdbDataItems)
- // items.BetweenDay = int(day) //公历日期换算成农历,需要减除的天数
- // items.Year = preYear
- // for _, v := range dataList {
- // dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
- // if err != nil {
- // errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
- // return result, err
- // }
- // newDate := dateTime.AddDate(0, 0, int(day))
- // timestamp := newDate.UnixNano() / 1e6
- // item := new(EdbDataList)
- // item.DataTime = newDate.Format(utils.FormatDate)
- // item.EdbInfoId = v.EdbInfoId
- // item.Value = v.Value
- // item.EdbDataId = v.EdbDataId
- // item.DataTimestamp = timestamp
- // items.Items = append(items.Items, item)
- // }
- // result.List = append(result.List, items)
- // } else {
- // nextYear := thisYear + 1
- // nextYearCjnl := strconv.Itoa(nextYear) + "-01-01" //当前年份春节农历
- // nextYearCjgl := solarlunar.LunarToSolar(nextYearCjnl, false) //当前年份春节公历
- // nextYearCjglDate, err := time.Parse(utils.FormatDate, nextYearCjgl)
- // if err != nil {
- // errMsg = "生成当前春节失败,Err:" + err.Error()
- // return result, err
- // }
- // preYear := vy
- // preYearCjnl := strconv.Itoa(preYear) + "-01-01" //之前年份春节农历
- // preYearCjgl := solarlunar.LunarToSolar(preYearCjnl, false) //之前年份春节公历
- // preYearCjglDate, err := time.Parse(utils.FormatDate, preYearCjgl)
- // if err != nil {
- // errMsg = "生成历史年份春节失败,Err:" + err.Error()
- // return result, err
- // }
- // day := nextYearCjglDate.Sub(preYearCjglDate).Hours() / float64(24)
- // fmt.Println("day:", day, nextYearCjglDate, preYearCjglDate)
- // items := new(EdbDataItems)
- // items.BetweenDay = int(day) //公历日期换算成农历,需要减除的天数
- // items.Year = preYear
- // fmt.Println("preYear:", preYear, "ky:", ky, "yearArrLen:", len(yearArr))
- // //if ky+1 < len(yearArr) {
- // for _, v := range dataList {
- // dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
- // if err != nil {
- // errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
- // return result, err
- // }
- // newDate := dateTime.AddDate(0, 0, int(day))
- // timestamp := newDate.UnixNano() / 1e6
- // item := new(EdbDataList)
- // item.DataTime = newDate.Format(utils.FormatDate)
- // item.EdbInfoId = v.EdbInfoId
- // item.Value = v.Value
- // item.EdbDataId = v.EdbDataId
- // item.DataTimestamp = timestamp
- // items.Items = append(items.Items, item)
- // }
- // result.List = append(result.List, items)
- // /*} else {
- // for _, v := range dataList {
- // dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
- // if err != nil {
- // errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
- // return result, err
- // }
- // timestamp := dateTime.UnixNano() / 1e6
- // item := new(EdbDataList)
- // item.DataTime = dateTime.Format(utils.FormatDate)
- // item.EdbInfoId = v.EdbInfoId
- // item.Value = v.Value
- // item.EdbDataId = v.EdbDataId
- // item.DataTimestamp = timestamp
- // items.Items = append(items.Items, item)
- // }
- // result.List = append(result.List, items)
- // }*/
- // }
- // }
- // return
- // }
- type CorrelationInfo struct {
- LeadValue int `description:"领先值"`
- LeadUnit string `description:"领先单位"`
- StartDate string `description:"开始日期"`
- EndDate string `description:"结束日期"`
- EdbInfoIdFirst int `description:"A指标ID"`
- EdbInfoIdSecond int `description:"B指标ID"`
- PeriodData string `description:"X轴-期数数据"`
- CorrelationData string `description:"Y轴-相关性系数"`
- AnalysisMode int `description:"分析模式: 0-单因子; 1-多因子"`
- }
- type SeasonExtraItem struct {
- ChartLegend []SeasonChartLegend `description:"自定义的图例名称"`
- XStartDate string `description:"横坐标显示的起始日"`
- XEndDate string `description:"横坐标显示的截止日"`
- JumpYear int `description:"横坐标日期是否跨年,1跨年,0不跨年"`
- RightAxis SeasonRightAxis `description:"自定义右轴指标"`
- MaxMinLimits MaxMinLimits `description:"自定义同期上下限"`
- SamePeriodAverage SamePeriodAverage `description:"自定义同期均线"`
- SamePeriodStandardDeviation SamePeriodStandardDeviation `description:"自定义同期标准差"`
- }
- // 自定义右轴指标
- type SeasonRightAxis struct {
- IndicatorType int `description:"右轴指标类型 1:左轴指标同比,2:指标库,3:预测指标 "`
- Style string `description:"生成样式"`
- Shape string `description:"形状"`
- ChartColor string `description:"图表颜色"`
- Size int `description:"大小"`
- Legend string `description:"图例名称"`
- NumFormat int `description:"数值格式 1:百分比 2:小数"`
- IsConnected int `description:"是否连接 0不连接 1连接"`
- LineColor string `description:"线条颜色"`
- LineWidth float64 `description:"线条宽度"`
- LineStyle string `description:"线条样式"`
- IsShow bool `description:"是否显示"`
- IsAdd bool `description:"是否添加"`
- }
- // 自定义同期上下限
- type MaxMinLimits struct {
- Color string `description:"颜色"`
- Year int `description:"上下限取值范围"`
- Legend string `description:"图例名称"`
- IsShow bool `description:"是否显示"`
- IsAdd bool `description:"是否添加"`
- }
- // 自定义同期均线
- type SamePeriodAverage struct {
- Color string `description:"颜色"`
- Year int `description:"均线取值范围"`
- Legend string `description:"图例名称"`
- LineType string `description:"线型"`
- LineWidth float64 `description:"线宽"`
- IsShow bool `description:"是否显示"`
- IsAdd bool `description:"是否添加"`
- }
- // 自定义同期均线
- type SamePeriodAverageResp struct {
- Color string `description:"颜色"`
- Year int `description:"均线取值范围"`
- Legend string `description:"图例名称"`
- LineType string `description:"线型"`
- LineWidth float64 `description:"线宽"`
- IsShow bool `description:"是否显示"`
- List []*SamePeriodAverageData `description:"自定义均线列表"`
- IsAdd bool `description:"是否添加"`
- }
- type SamePeriodAverageData struct {
- DataTime string `description:"数据日期"`
- DataTimestamp int64 `description:"数据日期时间戳"`
- Value float64 `description:"均值"`
- }
- // 自定义同期标准差
- type SamePeriodStandardDeviation struct {
- Color string `description:"颜色"`
- Year int `description:"标准差取值范围"`
- Legend string `description:"图例名称"`
- Multiple float64 `description:"标准差倍数"`
- IsShow bool `description:"是否显示"`
- IsAdd bool `description:"是否添加"`
- }
- type SamePeriodStandardDeviationResp struct {
- Color string `description:"颜色"`
- Year int `description:"标准差取值范围"`
- Legend string `description:"图例名称"`
- Multiple float64 `description:"标准差倍数"`
- IsShow bool `description:"是否显示"`
- List []*MaxMinLimitsData `description:"自定义标准差列表"`
- IsAdd bool `description:"是否添加"`
- }
- type SeasonChartResp struct {
- MaxMinLimits MaxMinLimitsResp `description:"自定义上下限"`
- SamePeriodAverage SamePeriodAverageResp `description:"自定义同期均线"`
- SamePeriodStandardDeviation SamePeriodStandardDeviationResp `description:"自定义同期标准差线"`
- RightAxis SeasonRightAxisResp `description:"自定义右轴指标"`
- }
- // 自定义右轴指标
- type SeasonRightAxisResp struct {
- SeasonRightAxis
- EdbInfoList []*ChartEdbInfoMapping
- }
- type MaxMinLimitsResp struct {
- List []*MaxMinLimitsData `description:"自定义上下限列表"`
- Color string `description:"颜色"`
- Year int `description:"上下限取值范围"`
- Legend string `description:"图例名称"`
- IsShow bool `description:"是否显示"`
- IsAdd bool `description:"是否添加"`
- }
- type MaxMinLimitsData struct {
- DataTime string `description:"数据日期"`
- DataTimestamp int64 `description:"数据日期时间戳"`
- MaxValue float64 `description:"最大值"`
- MinValue float64 `description:"最小值"`
- }
- type SeasonChartLegend struct {
- Name string
- Value string
- }
- type QuarterDataList []*QuarterData
- func (m QuarterDataList) Len() int {
- return len(m)
- }
- func (m QuarterDataList) Less(i, j int) bool {
- return m[i].Years < m[j].Years
- }
- func (m QuarterDataList) Swap(i, j int) {
- m[i], m[j] = m[j], m[i]
- }
- type ChartDwCollectReq struct {
- UniqueCode string
- Token string
- }
- // 截面组合图额外配置
- type ChartSectionExtraConf struct {
- DateConfList []*ChartSectionDateConfItem
- IsHeap int `description:"是否堆积(1.堆积,0不堆积)"`
- XDataList []XData `description:"横轴名称设置"`
- UnitList *ChartSectionCombineUnit `description:"纵轴单位设置"`
- BaseChartSeriesName string `description:"基准系列名称"`
- SortType int `description:"排序类型,0默认,1升序,2降序"`
- }
- // 截面组合图额外配置
- type ChartSectionAllExtraConf struct {
- ChartSectionExtraConf
- SeriesList []*ChartSectionSeriesItem
- }
- type ChartSectionDateConfItem struct {
- MoveForward int `description:"前移的期数"`
- EdbInfoId int `description:"指标ID"`
- EdbName string `description:"指标名称"`
- EdbNameEn string `description:"指标名称英文"`
- EdbInfoType int `description:"指标类型"`
- Frequency string `description:"频度"`
- EndDate string `description:"最新日期"`
- StaticDate string `description:"固定日期"`
- DateType int `description:"日期类型:0 指标日期,1系统日期, 2固定日期"`
- DateConfName string `description:"引用日期名称"` // 引用日期名称不能重复
- DateConfNameEn string `description:"引用日期英文名称"`
- DateChange []*ChartSectionDateChange
- }
- // 截面组合图引用日期配置
- type ChartSectionDateChange struct {
- Year int
- Month int
- Day int
- Frequency string `description:"频度变换"`
- FrequencyDay string `description:"频度的固定日期"`
- ChangeType int `description:"日期变换类型1日期位移,2指定频率"`
- }
- // 截面组合图系列配置
- // type ChartSectionSeriesItem struct {
- // ChartSeriesId int `description:"系列ID"`
- // SeriesName string `description:"系列名称"` //系列名称不可同名
- // SeriesNameEn string `description:"系列英文名称"`
- // ChartStyle string `description:"图表类型"`
- // ChartColor string `description:"颜色"`
- // ChartWidth int `description:"线条大小"`
- // IsPoint int `description:"是否用数据点展示(0 否,1是)"`
- // IsNumber int `description:"是否用数值展示(0 否,1是)"`
- // IsAxis int `description:"1:左轴,0:右轴"`
- // MaxData float64 `description:"上限"`
- // MinData float64 `description:"下限"`
- // //IsOrder bool `description:"true:正序,false:逆序"`
- // EdbInfoList []*ChartSectionSeriesEdbConf
- // DataList []float64
- // NoDataEdbIndex []int
- // }
- // 截面组合图系列配置
- type ChartSectionSeriesItem struct {
- ChartSeriesId int `gorm:"column:chart_series_id;primaryKey" description:"系列ID"`
- SeriesName string `gorm:"column:series_name" description:"系列名称"` //系列名称不可同名
- SeriesNameEn string `gorm:"column:series_name_en" description:"系列英文名称"`
- ChartStyle string `gorm:"column:chart_style" description:"图表类型"`
- ChartColor string `gorm:"column:chart_color" description:"颜色"`
- ChartWidth int `gorm:"column:chart_width" description:"线条大小"`
- IsPoint int `gorm:"column:is_point" description:"是否用数据点展示(0 否,1是)"`
- IsNumber int `gorm:"column:is_number" description:"是否用数值展示(0 否,1是)"`
- IsAxis int `gorm:"column:is_axis" description:"1:左轴,0:右轴"`
- MaxData float64 `gorm:"column:max_data" description:"上限"`
- MinData float64 `gorm:"column:min_data" description:"下限"`
- EdbInfoList []*ChartSectionSeriesEdbConf `gorm:"foreignkey:ChartSeriesId" description:"指标列表"`
- DataList []float64 `gorm:"column:data_list" description:"数据列表"`
- NoDataEdbIndex []int `gorm:"column:no_data_edb_index" description:"没有数据的指标索引"`
- }
- type ChartSectionSeriesEdbConf struct {
- ChartSeriesEdbMappingId int `description:"映射ID"`
- ChartSeriesId int `description:"系列ID"`
- //ChartInfoId int `description:"图表ID"`
- EdbInfoId int `description:"指标id"`
- DateConf *ChartSectionSeriesDateConfItem
- EdbName string `description:"中文别名"`
- EdbNameEn string `description:"英文别名"`
- EdbInfoType int `description:"指标类型"`
- Unit string `description:"单位"`
- UnitEn string `description:"英文单位"`
- DateConfName string `description:"引用日期名称"`
- DateConfType int `description:"日期类型,0指标最新日期, 1引用日期"`
- }
- type ChartSectionCombineDataResp struct {
- DateConfList []*ChartSectionDateConfItem
- IsHeap int `description:"是否堆积(1.堆积,0不堆积)"`
- XDataList []XData `description:"横轴名称设置"`
- UnitList *ChartSectionCombineUnit `description:"纵轴单位设置"`
- BaseChartSeriesName string `description:"基准系列名称"`
- SortType int `description:"排序类型,0默认,1升序,2降序"`
- SeriesList []*ChartSectionSeriesItem
- LeftMin string `description:"图表左侧最小值"`
- LeftMax string `description:"图表左侧最大值"`
- RightMin string `description:"图表右侧最小值"`
- RightMax string `description:"图表右侧最大值"`
- Right2Min string `description:"图表右侧最小值"`
- Right2Max string `description:"图表右侧最大值"`
- }
- // 系列里的指标日期配置
- type ChartSectionSeriesDateConfItem struct {
- MoveForward int `description:"前移的期数"`
- DateChange []*ChartSectionDateChange
- }
- // PreviewSectionCombineChartReq 预览截面组合图的请求
- type PreviewSectionCombineChartReq struct {
- ChartName string `description:"图表名称"`
- ChartClassifyId int `description:"分类id"`
- ExtraConfig string `description:"图表额外配置信息,json字符串"`
- }
- type ChartSectionCombineUnit struct {
- LeftName string `description:"左轴单位"`
- LeftNameEn string `description:"左轴英文单位"`
- RightName string `description:"右轴单位"`
- RightNameEn string `description:"右轴英文单位"`
- RightTwoName string `description:"右2轴单位"`
- RightTwoNameEn string `description:"右2轴英文单位"`
- }
- // 时序组合图额外配置
- type ChartTimeCombineExtraConf struct {
- IsHeap int `description:"是否堆积(1.堆积,0不堆积)"`
- }
- type ChartTimeCombineDataResp struct {
- IsHeap int `description:"是否堆积(1.堆积,0不堆积)"`
- }
- func GetChartInfoById(chartInfoId int) (item *ChartInfo, err error) {
- o := global.DmSQL["data"]
- sql := ` SELECT * FROM chart_info WHERE chart_info_id=? `
- err = o.Raw(sql, chartInfoId).First(&item).Error
- return
- }
- // func GetChartInfoById(chartInfoId int) (item *ChartInfo, err error) {
- // o := orm.NewOrmUsingDB("data")
- // sql := ` SELECT * FROM chart_info WHERE chart_info_id=? `
- // err = o.Raw(sql, chartInfoId).QueryRow(&item)
- // return
- // }
- type MarkersLine struct {
- Axis int `json:"axis" description:"1左轴 2右轴 3横轴"`
- AxisName string `json:"axisName" description:"轴的名称,例如'左轴'"`
- MarkerType string `json:"markerType" description:"标识线或标识区"`
- MarkLineType int `json:"markLineType" description:"1:固定 2:指标计算"`
- Value string `json:"value" description:"连线指向的数值,例如'4000'"`
- FromValue string `json:"fromValue" description:"连线的起始点,可以为空"`
- ToValue string `json:"toValue" description:"连线的结束点,可以为空"`
- LineWidth float64 `json:"lineWidth" description:"连线的宽度"`
- DashStyle string `json:"dashStyle" description:"连线的虚线样式,例如'ShortDashDot'"`
- Color string `json:"color" description:"连线的颜色"`
- Text string `json:"text" description:"连线旁边显示的文本"`
- TextPosition string `json:"textPosition" description:"文本的显示位置,例如'bottom'"`
- TextColor string `json:"textColor" description:"文本颜色"`
- TextFontSize int `json:"textFontSize" description:"文本的字号大小"`
- IsShow bool `json:"isShow" description:"是否显示连线及文本"`
- EdbType int `json:"edbType" description:"指标类型 0图中第一个指标 1其他指标 前端回显用"`
- EdbInfoId int `json:"edbInfoId" description:"指标id"`
- Calculation int `json:"calculation" description:"计算方式 1区间均值 2区间均值加N倍标准差 3区间个数分位 4区间数值分位"`
- CalculationValue int `json:"calculationValue" description:"计算方式对应的值 2就是几倍标准差 3就是分位值 4就是数值值·"`
- TimeIntervalType int `json:"timeInterval" description:"时间区间 0跟随图表 1自定义"`
- StartDate MarkersLineTime `json:"startTime" description:"开始时间"`
- EndDate MarkersLineTime `json:"endTime" description:"结束时间"`
- }
- type MarkersLineTime struct {
- TimeType int `json:"timeType" description:"时间类型 1固定 2动态 3至今(仅结束时间)"`
- Date string `json:"date" description:"日期"`
- Conf EdbDateChangeConf `json:"conf" description:"动态时间配置"`
- }
- // EdbDateExtraConf
- // @Description: 导入指标日期前移和日期变换
- type EdbDateChangeConf struct {
- MoveForward int `json:"moveForward" description:"前移的期数"`
- BaseDate int `json:"baseDate" description:"基准日期 0系统日期 1指标最新日期"`
- DateChange []*EdbDateConfDateChange
- }
- type EdbDateConfDateChange struct {
- Year int `json:"year" description:"前移的期数"`
- Month int `json:"month" description:"前移的期数"`
- Day int `json:"day" description:"前移的期数"`
- Frequency string `json:"moveForward" description:"频度变换"`
- FrequencyDay string `json:"frequencyDay" description:"频度的固定日期"`
- ChangeType int `json:"changeType" description:"日期变换类型1日期位移,2指定频率"`
- }
- func getThsHfEdbDataListByMongo(source, subSource, edbInfoId int, startDate, endDate string) (list []*EdbDataList, err error) {
- list = make([]*EdbDataList, 0)
- mogDataObj := mgo.EdbDataThsHf{}
- // 构建查询条件
- queryConditions := bson.M{
- "edb_info_id": edbInfoId,
- }
- // 数据日期
- dateCondition, err := mgo.BuildDateCondition(startDate, endDate)
- if err != nil {
- return
- }
- if len(dateCondition) > 0 {
- queryConditions["data_time"] = dateCondition
- }
- // 获取列表数据
- tmpDataList, tmpErr := mogDataObj.GetAllDataList(queryConditions, []string{"data_time"})
- if tmpErr != nil {
- err = tmpErr
- return
- }
- for k, v := range tmpDataList {
- list = append(list, &EdbDataList{
- EdbDataId: k + 1,
- EdbInfoId: v.EdbInfoId,
- DataTime: v.DataTime.Format(utils.FormatDate),
- DataTimestamp: v.DataTimestamp,
- Value: v.Value,
- })
- }
- return
- }
- // ConvertToResp
- // @Description: 转成需要输出的格式
- // @receiver m
- func (m *ChartEdbInfoMapping) ConvertToResp() {
- m.ModifyTime = utils.GormDateStrToDateTimeStr(m.ModifyTime)
- m.StartDate = utils.GormDateStrToDateStr(m.StartDate)
- m.EndDate = utils.GormDateStrToDateStr(m.EndDate)
- m.LatestDate = utils.GormDateStrToDateStr(m.LatestDate)
- m.MoveLatestDate = utils.GormDateStrToDateStr(m.MoveLatestDate)
- return
- }
|