12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037 |
- 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 `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
- }
- 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
- }
- 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
- }
- func GetEdbDataList(source, subSource, edbInfoId int, startDate, endDate string) (list []*EdbDataList, err error) {
- 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)
- }
- 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
- }
- 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 `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:"是否收藏"`
- }
- type XData struct {
- Name string `description:"别名"`
- NameEn string `description:"英文别名"`
- IsHide int `description:"是否隐藏,0不隐藏,1隐藏"`
- }
- 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:"对应的系列指标"`
- }
- 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()
- 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
- }
- 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()
- 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))
- 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 `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"`
- 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
- }
- 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
- }
- 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:"动态时间配置"`
- }
- 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
- }
- 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
- }
|