chart.go 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647
  1. package models
  2. import (
  3. "errors"
  4. "eta_gn/eta_chart_lib/global"
  5. "eta_gn/eta_chart_lib/models/mgo"
  6. "eta_gn/eta_chart_lib/utils"
  7. "fmt"
  8. "strconv"
  9. "time"
  10. "go.mongodb.org/mongo-driver/bson"
  11. "gorm.io/gorm"
  12. "github.com/nosixtools/solarlunar"
  13. )
  14. // type ChartInfo struct {
  15. // ChartInfoId int `json:"-" orm:"column(chart_info_id);pk"`
  16. // ChartName string `description:"来源名称"`
  17. // ChartNameEn string `description:"英文图表名称"`
  18. // ChartClassifyId int `json:"-" description:"图表分类id"`
  19. // SysUserId int `json:"-"`
  20. // SysUserRealName string `json:"-"`
  21. // UniqueCode string `description:"图表唯一编码"`
  22. // CreateTime time.Time `json:"-"`
  23. // ModifyTime time.Time `json:"-"`
  24. // DateType int `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间"`
  25. // StartDate string `description:"自定义开始日期"`
  26. // EndDate string `description:"自定义结束日期"`
  27. // IsSetName int `description:"设置名称"`
  28. // EdbInfoIds string `description:"指标id"`
  29. // ChartType int `description:"生成样式:1:曲线图,2:季节性图"`
  30. // Calendar string `description:"公历/农历"`
  31. // SeasonStartDate string `description:"季节性图开始日期"`
  32. // SeasonEndDate string `description:"季节性图开始日期"`
  33. // ChartImage string `description:"图表图片"`
  34. // BarConfig string `description:"柱方图的配置,json数据" json:"-"`
  35. // XMin string `description:"图表X轴最小值"`
  36. // XMax string `description:"图表X轴最大值"`
  37. // LeftMin string `description:"图表左侧最小值"`
  38. // LeftMax string `description:"图表左侧最大值"`
  39. // RightMin string `description:"图表右侧最小值"`
  40. // RightMax string `description:"图表右侧最大值"`
  41. // Right2Min string `description:"图表右侧2最小值"`
  42. // Right2Max string `description:"图表右侧2最大值"`
  43. // MinMaxSave int `description:"是否手动保存过上下限:0-否;1-是"`
  44. // Source int `description:"1:ETA图库;2:商品价格曲线"`
  45. // Unit string `description:"中文单位名称"`
  46. // UnitEn string `description:"英文单位名称"`
  47. // ExtraConfig string `description:"图表额外配置,json数据" json:"-"`
  48. // ChartSource string `description:"图表来源str"`
  49. // ChartSourceEn string `description:"图表来源(英文)"`
  50. // SeasonExtraConfig string `description:"季节性图表中的配置,json数据"`
  51. // StartYear int `description:"当选择的日期类型为最近N年类型时,即date_type=20, 用start_year表示N"`
  52. // ChartThemeId int `description:"图表应用主题ID"`
  53. // ChartThemeStyle string `description:"图表应用主题样式"`
  54. // SourcesFrom string `description:"图表来源"`
  55. // Instructions string `description:"图表说明"`
  56. // MarkersLines string `description:"标识线"`
  57. // MarkersAreas string `description:"标识区"`
  58. // }
  59. type ChartInfo struct {
  60. ChartInfoId int `gorm:"column:chart_info_id;primaryKey" json:"-" orm:"column(chart_info_id);pk"`
  61. ChartName string `gorm:"column:chart_name" description:"来源名称"`
  62. ChartNameEn string `gorm:"column:chart_name_en" description:"英文图表名称"`
  63. ChartClassifyId int `gorm:"column:chart_classify_id" json:"-" description:"图表分类id"`
  64. SysUserId int `gorm:"column:sys_user_id" json:"-"`
  65. SysUserRealName string `gorm:"column:sys_user_real_name" json:"-"`
  66. UniqueCode string `gorm:"column:unique_code" description:"图表唯一编码"`
  67. CreateTime time.Time `gorm:"column:create_time" json:"-"`
  68. ModifyTime time.Time `gorm:"column:modify_time" json:"-"`
  69. DateType int `gorm:"column:date_type" description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间"`
  70. StartDate string `gorm:"column:start_date" description:"自定义开始日期"`
  71. EndDate string `gorm:"column:end_date" description:"自定义结束日期"`
  72. IsSetName int `gorm:"column:is_set_name" description:"设置名称"`
  73. EdbInfoIds string `gorm:"column:edb_info_ids" description:"指标id"`
  74. ChartType int `gorm:"column:chart_type" description:"生成样式:1:曲线图,2:季节性图"`
  75. Calendar string `gorm:"column:calendar" description:"公历/农历"`
  76. SeasonStartDate string `gorm:"column:season_start_date" description:"季节性图开始日期"`
  77. SeasonEndDate string `gorm:"column:season_end_date" description:"季节性图结束日期"`
  78. ChartImage string `gorm:"column:chart_image" description:"图表图片"`
  79. BarConfig string `gorm:"column:bar_config" description:"柱方图的配置,json数据" json:"-"`
  80. XMin string `gorm:"column:x_min" description:"图表X轴最小值"`
  81. XMax string `gorm:"column:x_max" description:"图表X轴最大值"`
  82. LeftMin string `gorm:"column:left_min" description:"图表左侧最小值"`
  83. LeftMax string `gorm:"column:left_max" description:"图表左侧最大值"`
  84. RightMin string `gorm:"column:right_min" description:"图表右侧最小值"`
  85. RightMax string `gorm:"column:right_max" description:"图表右侧最大值"`
  86. Right2Min string `gorm:"column:right2_min" description:"图表右侧2最小值"`
  87. Right2Max string `gorm:"column:right2_max" description:"图表右侧2最大值"`
  88. MinMaxSave int `gorm:"column:min_max_save" description:"是否手动保存过上下限:0-否;1-是"`
  89. Source int `gorm:"column:source" description:"1:ETA图库;2:商品价格曲线"`
  90. Unit string `gorm:"column:unit" description:"中文单位名称"`
  91. UnitEn string `gorm:"column:unit_en" description:"英文单位名称"`
  92. ExtraConfig string `gorm:"column:extra_config" description:"图表额外配置,json数据" json:"-"`
  93. ChartSource string `gorm:"column:chart_source" description:"图表来源"`
  94. ChartSourceEn string `gorm:"column:chart_source_en" description:"图表来源(英文)"`
  95. SeasonExtraConfig string `gorm:"column:season_extra_config" description:"季节性图表中的配置,json数据"`
  96. StartYear int `gorm:"column:start_year" description:"当选择的日期类型为最近N年类型时,即date_type=20,用start_year表示N"`
  97. ChartThemeId int `gorm:"column:chart_theme_id" description:"图表应用主题ID"`
  98. ChartThemeStyle string `gorm:"column:chart_theme_style" description:"图表应用主题样式"`
  99. SourcesFrom string `gorm:"column:sources_from" description:"图表来源"`
  100. Instructions string `gorm:"column:instructions" description:"图表说明"`
  101. MarkersLines string `gorm:"column:markers_lines" description:"标识线"`
  102. MarkersAreas string `gorm:"column:markers_areas" description:"标识区"`
  103. }
  104. func (c *ChartInfo) TableName() string {
  105. return "chart_info"
  106. }
  107. func GetChartInfoByUniqueCode(uniqueCode string) (item *ChartInfo, err error) {
  108. o := global.DmSQL["data"]
  109. sql := ` SELECT * FROM chart_info WHERE unique_code=? `
  110. err = o.Raw(sql, uniqueCode).First(&item).Error
  111. return
  112. }
  113. // func GetChartInfoByUniqueCode(uniqueCode string) (item *ChartInfo, err error) {
  114. // o := orm.NewOrmUsingDB("data")
  115. // sql := ` SELECT * FROM chart_info WHERE unique_code=? `
  116. // err = o.Raw(sql, uniqueCode).QueryRow(&item)
  117. // return
  118. // }
  119. // type ChartEdbInfoMapping struct {
  120. // EdbInfoId int `description:"指标id"`
  121. // SourceName string `description:"来源名称"`
  122. // Source int `description:"来源id"`
  123. // EdbCode string `description:"指标编码"`
  124. // EdbName string `description:"指标名称"`
  125. // EdbAliasName string `description:"指标名称(别名)"`
  126. // EdbAliasNameEn string `description:"英文指标名称(别名)"`
  127. // EdbNameEn string `description:"英文指标名称"`
  128. // Frequency string `description:"频率"`
  129. // FrequencyEn string `description:"英文频率"`
  130. // Unit string `description:"单位"`
  131. // UnitEn string `description:"英文单位"`
  132. // StartDate string `description:"起始日期"`
  133. // EndDate string `description:"终止日期"`
  134. // ModifyTime string `description:"指标最后更新时间"`
  135. // ChartEdbMappingId int `description:"图表指标id" json:"-"`
  136. // ChartInfoId int `description:"图表id"`
  137. // MaxData float64 `description:"上限"`
  138. // MinData float64 `description:"下限"`
  139. // IsOrder bool `description:"true:正序,false:逆序"`
  140. // IsAxis int `description:"1:左轴,0:右轴"`
  141. // EdbInfoType int `description:"1:标准指标,0:领先指标"`
  142. // EdbType int `description:"指标类型:1:基础指标,2:计算指标"`
  143. // LeadValue int `description:"领先值"`
  144. // LeadUnit string `description:"领先单位"`
  145. // LeadUnitEn string `description:"领先英文单位"`
  146. // ChartStyle string `description:"图表类型"`
  147. // ChartColor string `description:"颜色"`
  148. // ChartWidth float64 `description:"线条大小"`
  149. // DataList interface{}
  150. // EdbInfoCategoryType int `description:"0:普通指标,1:预测指标"`
  151. // PredictChartColor string `description:"预测数据的颜色"`
  152. // ChartType int `description:"生成样式:1:曲线图,2:季节性图,3:面积图,4:柱状图,5:散点图,6:组合图"`
  153. // LatestDate string `description:"数据最新日期"`
  154. // LatestValue float64 `description:"数据最新值"`
  155. // MoveLatestDate string `description:"移动后的数据最新日期"`
  156. // UniqueCode string `description:"指标唯一编码"`
  157. // MinValue float64 `json:"-" description:"最小值"`
  158. // MaxValue float64 `json:"-" description:"最大值"`
  159. // IsNullData bool `json:"-" description:"是否空数据"`
  160. // MappingSource int `description:"1:ETA图库;2:商品价格曲线"`
  161. // SubSource int `description:"子数据来源:0:经济数据库,1:日期序列"`
  162. // SubSourceName string `description:"子数据来源名称"`
  163. // IndicatorCode string `description:"指标代码"`
  164. // StockCode string `description:"证券代码"`
  165. // IsConvert int `description:"是否数据转换 0不转 1转"`
  166. // ConvertType int `description:"数据转换类型 1乘 2除 3对数"`
  167. // ConvertValue float64 `description:"数据转换值"`
  168. // ConvertUnit string `description:"数据转换单位"`
  169. // ConvertEnUnit string `description:"数据转换单位"`
  170. // ClassifyId int `description:"分类id"`
  171. // IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
  172. // }
  173. type ChartEdbInfoMapping struct {
  174. EdbInfoId int `gorm:"column:edb_info_id;primaryKey" description:"指标id"`
  175. SourceName string `gorm:"column:source_name" description:"来源名称"`
  176. Source int `gorm:"column:source" description:"来源id"`
  177. EdbCode string `gorm:"column:edb_code" description:"指标编码"`
  178. EdbName string `gorm:"column:edb_name" description:"指标名称"`
  179. EdbAliasName string `gorm:"column:edb_alias_name" description:"指标名称(别名)"`
  180. EdbAliasNameEn string `gorm:"column:edb_alias_name_en" description:"英文指标名称(别名)"`
  181. EdbNameEn string `gorm:"column:edb_name_en" description:"英文指标名称"`
  182. Frequency string `gorm:"column:frequency" description:"频率"`
  183. FrequencyEn string `gorm:"column:frequency_en" description:"英文频率"`
  184. Unit string `gorm:"column:unit" description:"单位"`
  185. UnitEn string `gorm:"column:unit_en" description:"英文单位"`
  186. StartDate string `gorm:"column:start_date" description:"起始日期"`
  187. EndDate string `gorm:"column:end_date" description:"终止日期"`
  188. ModifyTime string `gorm:"column:modify_time" description:"指标最后更新时间"`
  189. ChartEdbMappingId int `gorm:"column:chart_edb_mapping_id" description:"图表指标id" json:"-"`
  190. ChartInfoId int `gorm:"column:chart_info_id" description:"图表id"`
  191. MaxData float64 `gorm:"column:max_data" description:"上限"`
  192. MinData float64 `gorm:"column:min_data" description:"下限"`
  193. IsOrder bool `gorm:"column:is_order" description:"true:正序,false:逆序"`
  194. IsAxis int `gorm:"column:is_axis" description:"1:左轴,0:右轴"`
  195. EdbInfoType int `gorm:"column:edb_info_type" description:"1:标准指标,0:领先指标"`
  196. EdbType int `gorm:"column:edb_type" description:"指标类型:1:基础指标,2:计算指标"`
  197. LeadValue int `gorm:"column:lead_value" description:"领先值"`
  198. LeadUnit string `gorm:"column:lead_unit" description:"领先单位"`
  199. LeadUnitEn string `gorm:"column:lead_unit_en" description:"领先英文单位"`
  200. ChartStyle string `gorm:"column:chart_style" description:"图表类型"`
  201. ChartColor string `gorm:"column:chart_color" description:"颜色"`
  202. ChartWidth float64 `gorm:"column:chart_width" description:"线条大小"`
  203. DataList interface{} `gorm:"column:data_list" description:"数据列表"`
  204. EdbInfoCategoryType int `gorm:"column:edb_info_category_type" description:"0:普通指标,1:预测指标"`
  205. PredictChartColor string `gorm:"column:predict_chart_color" description:"预测数据的颜色"`
  206. ChartType int `gorm:"column:chart_type" description:"生成样式:1:曲线图,2:季节性图,3:面积图,4:柱状图,5:散点图,6:组合图"`
  207. LatestDate string `gorm:"column:latest_date" description:"数据最新日期"`
  208. LatestValue float64 `gorm:"column:latest_value" description:"数据最新值"`
  209. MoveLatestDate string `gorm:"column:move_latest_date" description:"移动后的数据最新日期"`
  210. UniqueCode string `gorm:"column:unique_code" description:"指标唯一编码"`
  211. MinValue float64 `gorm:"column:min_value" json:"-" description:"最小值"`
  212. MaxValue float64 `gorm:"column:max_value" json:"-" description:"最大值"`
  213. IsNullData bool `gorm:"column:is_null_data" json:"-" description:"是否空数据"`
  214. MappingSource int `gorm:"column:mapping_source" description:"1:ETA图库;2:商品价格曲线"`
  215. SubSource int `gorm:"column:sub_source" description:"子数据来源:0:经济数据库,1:日期序列"`
  216. SubSourceName string `gorm:"column:sub_source_name" description:"子数据来源名称"`
  217. IndicatorCode string `gorm:"column:indicator_code" description:"指标代码"`
  218. StockCode string `gorm:"column:stock_code" description:"证券代码"`
  219. IsConvert int `gorm:"column:is_convert" description:"是否数据转换 0不转 1转"`
  220. ConvertType int `gorm:"column:convert_type" description:"数据转换类型 1乘 2除 3对数"`
  221. ConvertValue float64 `gorm:"column:convert_value" description:"数据转换值"`
  222. ConvertUnit string `gorm:"column:convert_unit" description:"数据转换单位"`
  223. ConvertEnUnit string `gorm:"column:convert_en_unit" description:"数据转换单位英文"`
  224. ClassifyId int `gorm:"column:classify_id" description:"分类id"`
  225. IsJoinPermission int `gorm:"column:is_join_permission" description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
  226. }
  227. func GetChartEdbMappingList(chartInfoId int) (list []*ChartEdbInfoMapping, err error) {
  228. o := global.DmSQL["data"]
  229. 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`
  230. 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,
  231. a.is_convert, a.convert_type, a.convert_value, a.convert_unit, a.convert_en_unit
  232. FROM chart_edb_mapping AS a
  233. INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
  234. WHERE chart_info_id=?
  235. ORDER BY chart_edb_mapping_id ASC `
  236. err = o.Raw(sql, chartInfoId).Scan(&list).Error
  237. return
  238. }
  239. // func GetChartEdbMappingList(chartInfoId int) (list []*ChartEdbInfoMapping, err error) {
  240. // o := orm.NewOrmUsingDB("data")
  241. // 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`
  242. // 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,
  243. // a.is_convert, a.convert_type, a.convert_value, a.convert_unit, a.convert_en_unit
  244. // FROM chart_edb_mapping AS a
  245. // INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
  246. // WHERE chart_info_id=?
  247. // ORDER BY chart_edb_mapping_id ASC `
  248. // _, err = o.Raw(sql, chartInfoId).QueryRows(&list)
  249. // return
  250. // }
  251. // type EdbDataList struct {
  252. // EdbDataId int `json:"-" description:" 指标数据ID"`
  253. // EdbInfoId int `json:"-" description:"指标ID"`
  254. // DataTime string `description:"数据日期"`
  255. // DataTimestamp int64 `description:"数据日期"`
  256. // Value float64 `description:"数据值"`
  257. // }
  258. type EdbDataList struct {
  259. EdbDataId int `gorm:"column:edb_data_id;primaryKey" description:"指标数据ID"`
  260. EdbInfoId int `gorm:"column:edb_info_id" description:"指标ID"`
  261. DataTime string `gorm:"column:data_time" description:"数据日期"`
  262. DataTimestamp int64 `gorm:"column:data_timestamp" description:"数据日期时间戳"`
  263. Value float64 `gorm:"column:value" description:"数据值"`
  264. }
  265. func (e *EdbDataList) AfterFind(db *gorm.DB) (err error) {
  266. tmp, err := time.Parse(utils.FormatDateWallWithLoc, e.DataTime)
  267. if err != nil {
  268. return
  269. }
  270. e.DataTime = tmp.Format(utils.FormatDate)
  271. return
  272. }
  273. // GetEdbDataList 获取指标的数据(日期正序返回)
  274. func GetEdbDataList(source, subSource, edbInfoId int, startDate, endDate string) (list []*EdbDataList, err error) {
  275. // 自有数据需要额外处理(从mongo获取)
  276. if source == utils.DATA_SOURCE_BUSINESS && utils.UseMongo {
  277. return getEdbDataListByMongo(source, subSource, edbInfoId, startDate, endDate)
  278. }
  279. if source == utils.DATA_SOURCE_THS && subSource == utils.DATA_SUB_SOURCE_HIGH_FREQUENCY && utils.UseMongo {
  280. return getThsHfEdbDataListByMongo(source, subSource, edbInfoId, startDate, endDate)
  281. }
  282. return getEdbDataListByMysql(source, subSource, edbInfoId, startDate, endDate)
  283. }
  284. // getEdbDataListByMysql
  285. // @Description: 从mysql中获取指标的数据(日期正序返回)
  286. // @author: Roc
  287. // @datetime 2024-05-08 16:49:48
  288. // @param source int
  289. // @param subSource int
  290. // @param edbInfoId int
  291. // @param startDate string
  292. // @param endDate string
  293. // @return list []*EdbDataList
  294. // @return err error
  295. func getEdbDataListByMysql(source, subSource, edbInfoId int, startDate, endDate string) (list []*EdbDataList, err error) {
  296. tableName := GetEdbDataTableName(source, subSource)
  297. if tableName == "" {
  298. err = errors.New("无效的渠道:" + strconv.Itoa(source))
  299. list = make([]*EdbDataList, 0)
  300. return list, err
  301. }
  302. var pars []interface{}
  303. var condition string
  304. if startDate != "" {
  305. condition += ` AND data_time>=? `
  306. pars = append(pars, startDate)
  307. }
  308. if endDate != "" {
  309. condition += ` AND data_time<=? `
  310. pars = append(pars, endDate)
  311. }
  312. sql := `SELECT edb_data_id,edb_info_id,data_time,value,data_timestamp FROM %s WHERE edb_info_id=? `
  313. if condition != "" {
  314. sql += condition
  315. }
  316. sql += ` ORDER BY data_time ASC `
  317. sql = fmt.Sprintf(sql, tableName)
  318. o := global.DmSQL["data"]
  319. pars = append([]interface{}{edbInfoId}, pars...)
  320. err = o.Raw(sql, pars...).Find(&list).Error
  321. return
  322. }
  323. // getEdbDataListByMongo
  324. // @Description: 从mongo中获取指标的数据(日期正序返回)
  325. // @author: Roc
  326. // @datetime 2024-05-08 16:49:59
  327. // @param source int
  328. // @param subSource int
  329. // @param edbInfoId int
  330. // @param startDate string
  331. // @param endDate string
  332. // @return list []*EdbDataList
  333. // @return err error
  334. func getEdbDataListByMongo(source, subSource, edbInfoId int, startDate, endDate string) (list []*EdbDataList, err error) {
  335. list = make([]*EdbDataList, 0)
  336. mogDataObj := mgo.EdbDataBusiness{}
  337. // 构建查询条件
  338. queryConditions := bson.M{
  339. "edb_info_id": edbInfoId,
  340. }
  341. // 日期
  342. dateCondition, err := mgo.BuildDateCondition(startDate, endDate)
  343. if err != nil {
  344. return
  345. }
  346. if len(dateCondition) > 0 {
  347. queryConditions["data_time"] = dateCondition
  348. }
  349. // 获取列表数据
  350. tmpDataList, tmpErr := mogDataObj.GetAllDataList(queryConditions, []string{"data_time"})
  351. if tmpErr != nil {
  352. err = tmpErr
  353. return
  354. }
  355. for k, v := range tmpDataList {
  356. list = append(list, &EdbDataList{
  357. EdbDataId: k + 1,
  358. EdbInfoId: v.EdbInfoId,
  359. DataTime: v.DataTime.Format(utils.FormatDate),
  360. DataTimestamp: v.DataTimestamp,
  361. Value: v.Value,
  362. })
  363. }
  364. return
  365. }
  366. // getEdbDataListByMysql
  367. // @Description: 从mysql中获取指标的数据(日期正序返回)
  368. // @author: Roc
  369. // @datetime 2024-05-08 16:49:48
  370. // @param source int
  371. // @param subSource int
  372. // @param edbInfoId int
  373. // @param startDate string
  374. // @param endDate string
  375. // @return list []*EdbDataList
  376. // @return err error
  377. // func getEdbDataListByMysql(source, subSource, edbInfoId int, startDate, endDate string) (list []*EdbDataList, err error) {
  378. // tableName := GetEdbDataTableName(source, subSource)
  379. // if tableName == "" {
  380. // err = errors.New("无效的渠道:" + strconv.Itoa(source))
  381. // list = make([]*EdbDataList, 0)
  382. // return list, err
  383. // }
  384. // var pars []interface{}
  385. // var condition string
  386. // if startDate != "" {
  387. // condition += ` AND data_time>=? `
  388. // pars = append(pars, startDate)
  389. // }
  390. // if endDate != "" {
  391. // condition += ` AND data_time<=? `
  392. // pars = append(pars, endDate)
  393. // }
  394. // sql := `SELECT edb_data_id,edb_info_id,data_time,value,data_timestamp FROM %s WHERE edb_info_id=? `
  395. // if condition != "" {
  396. // sql += condition
  397. // }
  398. // sql += ` ORDER BY data_time ASC `
  399. // sql = fmt.Sprintf(sql, tableName)
  400. // o := orm.NewOrmUsingDB("data")
  401. // _, err = o.Raw(sql, edbInfoId, pars).QueryRows(&list)
  402. // return
  403. // }
  404. // // getEdbDataListByMongo
  405. // // @Description: 从mongo中获取指标的数据(日期正序返回)
  406. // // @author: Roc
  407. // // @datetime 2024-05-08 16:49:59
  408. // // @param source int
  409. // // @param subSource int
  410. // // @param edbInfoId int
  411. // // @param startDate string
  412. // // @param endDate string
  413. // // @return list []*EdbDataList
  414. // // @return err error
  415. // func getEdbDataListByMongo(source, subSource, edbInfoId int, startDate, endDate string) (list []*EdbDataList, err error) {
  416. // list = make([]*EdbDataList, 0)
  417. // mogDataObj := mgo.EdbDataBusiness{}
  418. // // 构建查询条件
  419. // queryConditions := bson.M{
  420. // "edb_info_id": edbInfoId,
  421. // }
  422. // // 日期
  423. // dateCondition, err := mgo.BuildDateCondition(startDate, endDate)
  424. // if err != nil {
  425. // return
  426. // }
  427. // if len(dateCondition) > 0 {
  428. // queryConditions["data_time"] = dateCondition
  429. // }
  430. // // 获取列表数据
  431. // tmpDataList, tmpErr := mogDataObj.GetAllDataList(queryConditions, []string{"data_time"})
  432. // if tmpErr != nil {
  433. // err = tmpErr
  434. // return
  435. // }
  436. // for k, v := range tmpDataList {
  437. // list = append(list, &EdbDataList{
  438. // EdbDataId: k + 1,
  439. // EdbInfoId: v.EdbInfoId,
  440. // DataTime: v.DataTime.Format(utils.FormatDate),
  441. // DataTimestamp: v.DataTimestamp,
  442. // Value: v.Value,
  443. // })
  444. // }
  445. // return
  446. // }
  447. type EdbDataItemList struct {
  448. EdbDataId int `json:"-" description:" 指标数据ID"`
  449. EdbInfoId int `json:"-" description:"指标ID"`
  450. DataTime string `description:"数据日期"`
  451. DataTimestamp int64 `description:"数据日期"`
  452. Value float64 `description:"数据值"`
  453. }
  454. // type EdbDataItems struct {
  455. // Items []*EdbDataList
  456. // Year int
  457. // BetweenDay int `json:"-" description:"公历与农历之间相差的天数"`
  458. // CuttingDataTimestamp int64 `description:"切割的时间戳"`
  459. // }
  460. type EdbDataItems struct {
  461. Items []*EdbDataList `gorm:"column:items" description:"指标数据项列表"`
  462. Year int `gorm:"column:year" description:"年份"`
  463. BetweenDay int `gorm:"column:between_day" json:"-" description:"公历与农历之间相差的天数"`
  464. CuttingDataTimestamp int64 `gorm:"column:cutting_data_timestamp" description:"切割的时间戳"`
  465. }
  466. type EdbDataResult struct {
  467. List []*EdbDataItems
  468. }
  469. type QuarterData struct {
  470. Year string
  471. DataList []*EdbDataList
  472. CuttingDataTimestamp int64 `description:"切割的时间戳"`
  473. ChartLegend string
  474. Years string
  475. }
  476. type QuarterXDateItem struct {
  477. StartDate time.Time
  478. EndDate time.Time
  479. ShowName string
  480. ChartLegend string
  481. CuttingDataTimestamp int64 `description:"切割的时间戳"`
  482. }
  483. type ChartInfoDetailResp struct {
  484. ChartInfo *ChartInfo
  485. EdbInfoList []*ChartEdbInfoMapping
  486. XEdbIdValue []int `description:"柱方图的x轴数据,指标id"`
  487. YDataList []YData `description:"柱方图的y轴数据"`
  488. XDataList []XData `description:"商品价格曲线的X轴数据"`
  489. CorrelationChartInfo *CorrelationInfo `description:"相关性图表信息"`
  490. DataResp interface{} `description:"图表数据,根据图的类型而定的,没有确定的数据格式"`
  491. WaterMark string `description:"水印"`
  492. IsCollect bool `description:"是否收藏"`
  493. }
  494. // XData 商品价格曲线的的x轴数据
  495. type XData struct {
  496. Name string `description:"别名"`
  497. NameEn string `description:"英文别名"`
  498. IsHide int `description:"是否隐藏,0不隐藏,1隐藏"`
  499. }
  500. // YData 柱方图的y轴数据
  501. type YData struct {
  502. Date string `description:"数据日期"`
  503. ConfigDate time.Time `description:"配置的日期" json:"-"`
  504. Color string `description:"数据颜色"`
  505. Name string `description:"别名"`
  506. NameEn string `description:"英文别名"`
  507. Value []float64 `description:"每个指标的值"`
  508. NoDataEdbList []int `description:"没有数据的指标列表"`
  509. XEdbInfoIdList []int `description:"对应X轴的指标id列表"`
  510. EdbValMap map[int]float64 `description:"指标与值的对应" json:"-"`
  511. M []int `description:"对应开始日期的间隔值" json:"-"`
  512. NameList []string `description:"每个值对应的名称"`
  513. EnNameList []string `description:"每个值对应的英文名称"`
  514. SeriesEdb struct {
  515. SeriesId int `description:"因子指标系列ID"`
  516. EdbInfoId int `description:"指标ID"`
  517. } `description:"对应的系列指标"`
  518. }
  519. // RollingCorrelationChartDataResp 滚动相关性图
  520. type RollingCorrelationChartDataResp struct {
  521. XDateTimeValue []string `description:"滚动相关性图的x轴数据,日期数据"`
  522. YDataList []YData `description:"滚动相关性图的y轴数据"`
  523. }
  524. // 指标季度数据计算(公历转农历)
  525. func AddCalculateQuarterV5(dataList []*EdbDataList) (result *EdbDataResult, err error) {
  526. var errMsg string
  527. defer func() {
  528. if errMsg != "" {
  529. fmt.Println("errMsg:", errMsg)
  530. }
  531. }()
  532. if len(dataList) <= 0 {
  533. result.List = make([]*EdbDataItems, 0)
  534. return
  535. }
  536. endDate := dataList[len(dataList)-1].DataTime
  537. endDateForm, err := time.Parse(utils.FormatDate, endDate)
  538. if err != nil {
  539. return result, err
  540. }
  541. thisMonth := int(endDateForm.Month())
  542. result = new(EdbDataResult)
  543. var yearArr []int
  544. yearMap := make(map[int]int)
  545. var cureentDate time.Time
  546. if thisMonth < 11 {
  547. for k, v := range dataList {
  548. dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
  549. if err != nil {
  550. errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
  551. return result, err
  552. }
  553. if k == len(dataList)-1 {
  554. cureentDate = dateTime
  555. }
  556. year := dateTime.Year()
  557. if _, ok := yearMap[year]; !ok {
  558. yearArr = append(yearArr, year)
  559. }
  560. yearMap[year] = year
  561. }
  562. } else {
  563. for k, v := range dataList {
  564. dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
  565. if err != nil {
  566. errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
  567. return result, err
  568. }
  569. if k == len(dataList)-1 {
  570. cureentDate = dateTime
  571. }
  572. year := dateTime.Year() + 1
  573. if _, ok := yearMap[year]; !ok {
  574. yearArr = append(yearArr, year)
  575. }
  576. yearMap[year] = year
  577. }
  578. }
  579. //排序
  580. fmt.Println("yearArr:", yearArr)
  581. thisYear := cureentDate.Year()
  582. //thisMonth := int(cureentDate.Month())
  583. fmt.Println("thisMonth:", thisMonth)
  584. for ky, vy := range yearArr {
  585. fmt.Println("line 432:", ky, vy, thisYear, thisMonth)
  586. if thisMonth < 11 {
  587. currentYearCjnl := strconv.Itoa(thisYear) + "-01-01" //当前年份春节农历
  588. currentYearCjgl := solarlunar.LunarToSolar(currentYearCjnl, false) //当前年份春节公历
  589. currentYearCjglDate, err := time.Parse(utils.FormatDate, currentYearCjgl)
  590. if err != nil {
  591. errMsg = "生成当前春节失败,Err:" + err.Error()
  592. return result, err
  593. }
  594. preYear := vy
  595. preYearCjnl := strconv.Itoa(preYear) + "-01-01" //之前年份春节农历
  596. preYearCjgl := solarlunar.LunarToSolar(preYearCjnl, false) //之前年份春节公历
  597. preYearCjglDate, err := time.Parse(utils.FormatDate, preYearCjgl)
  598. if err != nil {
  599. errMsg = "生成历史年份春节失败,Err:" + err.Error()
  600. return result, err
  601. }
  602. day := currentYearCjglDate.Sub(preYearCjglDate).Hours() / float64(24)
  603. items := new(EdbDataItems)
  604. items.BetweenDay = int(day) //公历日期换算成农历,需要减除的天数
  605. items.Year = preYear
  606. for _, v := range dataList {
  607. dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
  608. if err != nil {
  609. errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
  610. return result, err
  611. }
  612. newDate := dateTime.AddDate(0, 0, int(day))
  613. selectDateStr := strconv.Itoa(thisYear) + "-11" + "-30"
  614. selectDate, _ := time.Parse(utils.FormatDate, selectDateStr)
  615. if newDate.Before(selectDate) || newDate == selectDate {
  616. timestamp := newDate.UnixNano() / 1e6
  617. item := new(EdbDataList)
  618. item.DataTime = newDate.Format(utils.FormatDate)
  619. item.EdbInfoId = v.EdbInfoId
  620. item.Value = v.Value
  621. item.EdbDataId = v.EdbDataId
  622. item.DataTimestamp = timestamp
  623. items.Items = append(items.Items, item)
  624. }
  625. }
  626. result.List = append(result.List, items)
  627. } else {
  628. nextYear := thisYear + 1
  629. nextYearCjnl := strconv.Itoa(nextYear) + "-01-01" //当前年份春节农历
  630. nextYearCjgl := solarlunar.LunarToSolar(nextYearCjnl, false) //当前年份春节公历
  631. nextYearCjglDate, err := time.Parse(utils.FormatDate, nextYearCjgl)
  632. if err != nil {
  633. errMsg = "生成当前春节失败,Err:" + err.Error()
  634. return result, err
  635. }
  636. preYear := vy
  637. preYearCjnl := strconv.Itoa(preYear) + "-01-01" //之前年份春节农历
  638. preYearCjgl := solarlunar.LunarToSolar(preYearCjnl, false) //之前年份春节公历
  639. preYearCjglDate, err := time.Parse(utils.FormatDate, preYearCjgl)
  640. if err != nil {
  641. errMsg = "生成历史年份春节失败,Err:" + err.Error()
  642. return result, err
  643. }
  644. day := nextYearCjglDate.Sub(preYearCjglDate).Hours() / float64(24)
  645. fmt.Println("day:", day, nextYearCjglDate, preYearCjglDate)
  646. items := new(EdbDataItems)
  647. items.BetweenDay = int(day) //公历日期换算成农历,需要减除的天数
  648. items.Year = preYear - 1
  649. fmt.Println("preYear:", preYear, "ky:", ky, "yearArrLen:", len(yearArr))
  650. if ky+1 < len(yearArr) {
  651. for _, v := range dataList {
  652. dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
  653. if err != nil {
  654. errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
  655. return result, err
  656. }
  657. newDate := dateTime.AddDate(0, 0, int(day))
  658. selectDateStr := strconv.Itoa(nextYear) + "-05" + "-31"
  659. selectDate, _ := time.Parse(utils.FormatDate, selectDateStr)
  660. if newDate.Before(selectDate) || newDate == selectDate {
  661. timestamp := newDate.UnixNano() / 1e6
  662. item := new(EdbDataList)
  663. item.DataTime = newDate.Format(utils.FormatDate)
  664. item.EdbInfoId = v.EdbInfoId
  665. item.Value = v.Value
  666. item.EdbDataId = v.EdbDataId
  667. item.DataTimestamp = timestamp
  668. items.Items = append(items.Items, item)
  669. }
  670. }
  671. result.List = append(result.List, items)
  672. } else {
  673. for _, v := range dataList {
  674. dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
  675. if err != nil {
  676. errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
  677. return result, err
  678. }
  679. timestamp := dateTime.UnixNano() / 1e6
  680. item := new(EdbDataList)
  681. item.DataTime = dateTime.Format(utils.FormatDate)
  682. item.EdbInfoId = v.EdbInfoId
  683. item.Value = v.Value
  684. item.EdbDataId = v.EdbDataId
  685. item.DataTimestamp = timestamp
  686. items.Items = append(items.Items, item)
  687. }
  688. result.List = append(result.List, items)
  689. }
  690. }
  691. }
  692. return
  693. }
  694. // AddCalculateQuarterV6 指标季度数据计算(季节性图表)
  695. func AddCalculateQuarterV6(dataList []*EdbDataList) (result *EdbDataResult, err error) {
  696. var errMsg string
  697. defer func() {
  698. if errMsg != "" {
  699. fmt.Println("errMsg:", errMsg)
  700. }
  701. }()
  702. endDate := dataList[len(dataList)-1].DataTime
  703. endDateForm, err := time.Parse(utils.FormatDate, endDate)
  704. if err != nil {
  705. return result, err
  706. }
  707. thisMonth := int(endDateForm.Month())
  708. result = new(EdbDataResult)
  709. var yearArr []int
  710. yearMap := make(map[int]int)
  711. var cureentDate time.Time
  712. if thisMonth < 11 {
  713. for k, v := range dataList {
  714. dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
  715. if err != nil {
  716. errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
  717. return result, err
  718. }
  719. if k == len(dataList)-1 {
  720. cureentDate = dateTime
  721. }
  722. year := dateTime.Year()
  723. if _, ok := yearMap[year]; !ok {
  724. yearArr = append(yearArr, year)
  725. }
  726. yearMap[year] = year
  727. }
  728. } else {
  729. for k, v := range dataList {
  730. dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
  731. if err != nil {
  732. errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
  733. return result, err
  734. }
  735. if k == len(dataList)-1 {
  736. cureentDate = dateTime
  737. }
  738. year := dateTime.Year() + 1
  739. if _, ok := yearMap[year]; !ok {
  740. yearArr = append(yearArr, year)
  741. }
  742. yearMap[year] = year
  743. }
  744. }
  745. //排序
  746. fmt.Println("yearArr:", yearArr)
  747. thisYear := cureentDate.Year()
  748. //thisMonth := int(cureentDate.Month())
  749. fmt.Println("thisMonth:", thisMonth)
  750. for ky, vy := range yearArr {
  751. fmt.Printf("line 432:ky:%d, vy:%d, thisYear:%d, thisMonth:%d", ky, vy, thisYear, thisMonth)
  752. fmt.Println("")
  753. if thisMonth < 11 {
  754. currentYearCjnl := strconv.Itoa(thisYear) + "-01-01" //当前年份春节农历
  755. currentYearCjgl := solarlunar.LunarToSolar(currentYearCjnl, false) //当前年份春节公历
  756. currentYearCjglDate, err := time.Parse(utils.FormatDate, currentYearCjgl)
  757. if err != nil {
  758. errMsg = "生成当前春节失败,Err:" + err.Error()
  759. return result, err
  760. }
  761. preYear := vy
  762. preYearCjnl := strconv.Itoa(preYear) + "-01-01" //之前年份春节农历
  763. preYearCjgl := solarlunar.LunarToSolar(preYearCjnl, false) //之前年份春节公历
  764. preYearCjglDate, err := time.Parse(utils.FormatDate, preYearCjgl)
  765. if err != nil {
  766. errMsg = "生成历史年份春节失败,Err:" + err.Error()
  767. return result, err
  768. }
  769. day := currentYearCjglDate.Sub(preYearCjglDate).Hours() / float64(24)
  770. fmt.Println("day:", day, currentYearCjglDate, preYearCjglDate)
  771. items := new(EdbDataItems)
  772. items.BetweenDay = int(day) //公历日期换算成农历,需要减除的天数
  773. items.Year = preYear
  774. for _, v := range dataList {
  775. dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
  776. if err != nil {
  777. errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
  778. return result, err
  779. }
  780. newDate := dateTime.AddDate(0, 0, int(day))
  781. timestamp := newDate.UnixNano() / 1e6
  782. item := new(EdbDataList)
  783. item.DataTime = newDate.Format(utils.FormatDate)
  784. item.EdbInfoId = v.EdbInfoId
  785. item.Value = v.Value
  786. item.EdbDataId = v.EdbDataId
  787. item.DataTimestamp = timestamp
  788. items.Items = append(items.Items, item)
  789. }
  790. result.List = append(result.List, items)
  791. } else {
  792. nextYear := thisYear + 1
  793. nextYearCjnl := strconv.Itoa(nextYear) + "-01-01" //当前年份春节农历
  794. nextYearCjgl := solarlunar.LunarToSolar(nextYearCjnl, false) //当前年份春节公历
  795. nextYearCjglDate, err := time.Parse(utils.FormatDate, nextYearCjgl)
  796. if err != nil {
  797. errMsg = "生成当前春节失败,Err:" + err.Error()
  798. return result, err
  799. }
  800. preYear := vy
  801. preYearCjnl := strconv.Itoa(preYear) + "-01-01" //之前年份春节农历
  802. preYearCjgl := solarlunar.LunarToSolar(preYearCjnl, false) //之前年份春节公历
  803. preYearCjglDate, err := time.Parse(utils.FormatDate, preYearCjgl)
  804. if err != nil {
  805. errMsg = "生成历史年份春节失败,Err:" + err.Error()
  806. return result, err
  807. }
  808. day := nextYearCjglDate.Sub(preYearCjglDate).Hours() / float64(24)
  809. fmt.Println("day:", day, nextYearCjglDate, preYearCjglDate)
  810. items := new(EdbDataItems)
  811. items.BetweenDay = int(day) //公历日期换算成农历,需要减除的天数
  812. items.Year = preYear
  813. fmt.Println("preYear:", preYear, "ky:", ky, "yearArrLen:", len(yearArr))
  814. //if ky+1 < len(yearArr) {
  815. for _, v := range dataList {
  816. dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
  817. if err != nil {
  818. errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
  819. return result, err
  820. }
  821. newDate := dateTime.AddDate(0, 0, int(day))
  822. timestamp := newDate.UnixNano() / 1e6
  823. item := new(EdbDataList)
  824. item.DataTime = newDate.Format(utils.FormatDate)
  825. item.EdbInfoId = v.EdbInfoId
  826. item.Value = v.Value
  827. item.EdbDataId = v.EdbDataId
  828. item.DataTimestamp = timestamp
  829. items.Items = append(items.Items, item)
  830. }
  831. result.List = append(result.List, items)
  832. /*} else {
  833. for _, v := range dataList {
  834. dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
  835. if err != nil {
  836. errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
  837. return result, err
  838. }
  839. timestamp := dateTime.UnixNano() / 1e6
  840. item := new(EdbDataList)
  841. item.DataTime = dateTime.Format(utils.FormatDate)
  842. item.EdbInfoId = v.EdbInfoId
  843. item.Value = v.Value
  844. item.EdbDataId = v.EdbDataId
  845. item.DataTimestamp = timestamp
  846. items.Items = append(items.Items, item)
  847. }
  848. result.List = append(result.List, items)
  849. }*/
  850. }
  851. }
  852. return
  853. }
  854. // func AddCalculateQuarterV5(dataList []*EdbDataList) (result *EdbDataResult, err error) {
  855. // var errMsg string
  856. // defer func() {
  857. // if errMsg != "" {
  858. // fmt.Println("errMsg:", errMsg)
  859. // }
  860. // }()
  861. // if len(dataList) <= 0 {
  862. // result.List = make([]*EdbDataItems, 0)
  863. // return
  864. // }
  865. // endDate := dataList[len(dataList)-1].DataTime
  866. // endDateForm, err := time.Parse(utils.FormatDate, endDate)
  867. // if err != nil {
  868. // return result, err
  869. // }
  870. // thisMonth := int(endDateForm.Month())
  871. // result = new(EdbDataResult)
  872. // var yearArr []int
  873. // yearMap := make(map[int]int)
  874. // var cureentDate time.Time
  875. // if thisMonth < 11 {
  876. // for k, v := range dataList {
  877. // dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
  878. // if err != nil {
  879. // errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
  880. // return result, err
  881. // }
  882. // if k == len(dataList)-1 {
  883. // cureentDate = dateTime
  884. // }
  885. // year := dateTime.Year()
  886. // if _, ok := yearMap[year]; !ok {
  887. // yearArr = append(yearArr, year)
  888. // }
  889. // yearMap[year] = year
  890. // }
  891. // } else {
  892. // for k, v := range dataList {
  893. // dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
  894. // if err != nil {
  895. // errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
  896. // return result, err
  897. // }
  898. // if k == len(dataList)-1 {
  899. // cureentDate = dateTime
  900. // }
  901. // year := dateTime.Year() + 1
  902. // if _, ok := yearMap[year]; !ok {
  903. // yearArr = append(yearArr, year)
  904. // }
  905. // yearMap[year] = year
  906. // }
  907. // }
  908. // //排序
  909. // fmt.Println("yearArr:", yearArr)
  910. // thisYear := cureentDate.Year()
  911. // //thisMonth := int(cureentDate.Month())
  912. // fmt.Println("thisMonth:", thisMonth)
  913. // for ky, vy := range yearArr {
  914. // fmt.Println("line 432:", ky, vy, thisYear, thisMonth)
  915. // if thisMonth < 11 {
  916. // currentYearCjnl := strconv.Itoa(thisYear) + "-01-01" //当前年份春节农历
  917. // currentYearCjgl := solarlunar.LunarToSolar(currentYearCjnl, false) //当前年份春节公历
  918. // currentYearCjglDate, err := time.Parse(utils.FormatDate, currentYearCjgl)
  919. // if err != nil {
  920. // errMsg = "生成当前春节失败,Err:" + err.Error()
  921. // return result, err
  922. // }
  923. // preYear := vy
  924. // preYearCjnl := strconv.Itoa(preYear) + "-01-01" //之前年份春节农历
  925. // preYearCjgl := solarlunar.LunarToSolar(preYearCjnl, false) //之前年份春节公历
  926. // preYearCjglDate, err := time.Parse(utils.FormatDate, preYearCjgl)
  927. // if err != nil {
  928. // errMsg = "生成历史年份春节失败,Err:" + err.Error()
  929. // return result, err
  930. // }
  931. // day := currentYearCjglDate.Sub(preYearCjglDate).Hours() / float64(24)
  932. // items := new(EdbDataItems)
  933. // items.BetweenDay = int(day) //公历日期换算成农历,需要减除的天数
  934. // items.Year = preYear
  935. // for _, v := range dataList {
  936. // dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
  937. // if err != nil {
  938. // errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
  939. // return result, err
  940. // }
  941. // newDate := dateTime.AddDate(0, 0, int(day))
  942. // selectDateStr := strconv.Itoa(thisYear) + "-11" + "-30"
  943. // selectDate, _ := time.Parse(utils.FormatDate, selectDateStr)
  944. // if newDate.Before(selectDate) || newDate == selectDate {
  945. // timestamp := newDate.UnixNano() / 1e6
  946. // item := new(EdbDataList)
  947. // item.DataTime = newDate.Format(utils.FormatDate)
  948. // item.EdbInfoId = v.EdbInfoId
  949. // item.Value = v.Value
  950. // item.EdbDataId = v.EdbDataId
  951. // item.DataTimestamp = timestamp
  952. // items.Items = append(items.Items, item)
  953. // }
  954. // }
  955. // result.List = append(result.List, items)
  956. // } else {
  957. // nextYear := thisYear + 1
  958. // nextYearCjnl := strconv.Itoa(nextYear) + "-01-01" //当前年份春节农历
  959. // nextYearCjgl := solarlunar.LunarToSolar(nextYearCjnl, false) //当前年份春节公历
  960. // nextYearCjglDate, err := time.Parse(utils.FormatDate, nextYearCjgl)
  961. // if err != nil {
  962. // errMsg = "生成当前春节失败,Err:" + err.Error()
  963. // return result, err
  964. // }
  965. // preYear := vy
  966. // preYearCjnl := strconv.Itoa(preYear) + "-01-01" //之前年份春节农历
  967. // preYearCjgl := solarlunar.LunarToSolar(preYearCjnl, false) //之前年份春节公历
  968. // preYearCjglDate, err := time.Parse(utils.FormatDate, preYearCjgl)
  969. // if err != nil {
  970. // errMsg = "生成历史年份春节失败,Err:" + err.Error()
  971. // return result, err
  972. // }
  973. // day := nextYearCjglDate.Sub(preYearCjglDate).Hours() / float64(24)
  974. // fmt.Println("day:", day, nextYearCjglDate, preYearCjglDate)
  975. // items := new(EdbDataItems)
  976. // items.BetweenDay = int(day) //公历日期换算成农历,需要减除的天数
  977. // items.Year = preYear - 1
  978. // fmt.Println("preYear:", preYear, "ky:", ky, "yearArrLen:", len(yearArr))
  979. // if ky+1 < len(yearArr) {
  980. // for _, v := range dataList {
  981. // dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
  982. // if err != nil {
  983. // errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
  984. // return result, err
  985. // }
  986. // newDate := dateTime.AddDate(0, 0, int(day))
  987. // selectDateStr := strconv.Itoa(nextYear) + "-05" + "-31"
  988. // selectDate, _ := time.Parse(utils.FormatDate, selectDateStr)
  989. // if newDate.Before(selectDate) || newDate == selectDate {
  990. // timestamp := newDate.UnixNano() / 1e6
  991. // item := new(EdbDataList)
  992. // item.DataTime = newDate.Format(utils.FormatDate)
  993. // item.EdbInfoId = v.EdbInfoId
  994. // item.Value = v.Value
  995. // item.EdbDataId = v.EdbDataId
  996. // item.DataTimestamp = timestamp
  997. // items.Items = append(items.Items, item)
  998. // }
  999. // }
  1000. // result.List = append(result.List, items)
  1001. // } else {
  1002. // for _, v := range dataList {
  1003. // dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
  1004. // if err != nil {
  1005. // errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
  1006. // return result, err
  1007. // }
  1008. // timestamp := dateTime.UnixNano() / 1e6
  1009. // item := new(EdbDataList)
  1010. // item.DataTime = dateTime.Format(utils.FormatDate)
  1011. // item.EdbInfoId = v.EdbInfoId
  1012. // item.Value = v.Value
  1013. // item.EdbDataId = v.EdbDataId
  1014. // item.DataTimestamp = timestamp
  1015. // items.Items = append(items.Items, item)
  1016. // }
  1017. // result.List = append(result.List, items)
  1018. // }
  1019. // }
  1020. // }
  1021. // return
  1022. // }
  1023. // // AddCalculateQuarterV6 指标季度数据计算(季节性图表)
  1024. // func AddCalculateQuarterV6(dataList []*EdbDataList) (result *EdbDataResult, err error) {
  1025. // var errMsg string
  1026. // defer func() {
  1027. // if errMsg != "" {
  1028. // fmt.Println("errMsg:", errMsg)
  1029. // }
  1030. // }()
  1031. // endDate := dataList[len(dataList)-1].DataTime
  1032. // endDateForm, err := time.Parse(utils.FormatDate, endDate)
  1033. // if err != nil {
  1034. // return result, err
  1035. // }
  1036. // thisMonth := int(endDateForm.Month())
  1037. // result = new(EdbDataResult)
  1038. // var yearArr []int
  1039. // yearMap := make(map[int]int)
  1040. // var cureentDate time.Time
  1041. // if thisMonth < 11 {
  1042. // for k, v := range dataList {
  1043. // dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
  1044. // if err != nil {
  1045. // errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
  1046. // return result, err
  1047. // }
  1048. // if k == len(dataList)-1 {
  1049. // cureentDate = dateTime
  1050. // }
  1051. // year := dateTime.Year()
  1052. // if _, ok := yearMap[year]; !ok {
  1053. // yearArr = append(yearArr, year)
  1054. // }
  1055. // yearMap[year] = year
  1056. // }
  1057. // } else {
  1058. // for k, v := range dataList {
  1059. // dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
  1060. // if err != nil {
  1061. // errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
  1062. // return result, err
  1063. // }
  1064. // if k == len(dataList)-1 {
  1065. // cureentDate = dateTime
  1066. // }
  1067. // year := dateTime.Year() + 1
  1068. // if _, ok := yearMap[year]; !ok {
  1069. // yearArr = append(yearArr, year)
  1070. // }
  1071. // yearMap[year] = year
  1072. // }
  1073. // }
  1074. // //排序
  1075. // fmt.Println("yearArr:", yearArr)
  1076. // thisYear := cureentDate.Year()
  1077. // //thisMonth := int(cureentDate.Month())
  1078. // fmt.Println("thisMonth:", thisMonth)
  1079. // for ky, vy := range yearArr {
  1080. // fmt.Printf("line 432:ky:%d, vy:%d, thisYear:%d, thisMonth:%d", ky, vy, thisYear, thisMonth)
  1081. // fmt.Println("")
  1082. // if thisMonth < 11 {
  1083. // currentYearCjnl := strconv.Itoa(thisYear) + "-01-01" //当前年份春节农历
  1084. // currentYearCjgl := solarlunar.LunarToSolar(currentYearCjnl, false) //当前年份春节公历
  1085. // currentYearCjglDate, err := time.Parse(utils.FormatDate, currentYearCjgl)
  1086. // if err != nil {
  1087. // errMsg = "生成当前春节失败,Err:" + err.Error()
  1088. // return result, err
  1089. // }
  1090. // preYear := vy
  1091. // preYearCjnl := strconv.Itoa(preYear) + "-01-01" //之前年份春节农历
  1092. // preYearCjgl := solarlunar.LunarToSolar(preYearCjnl, false) //之前年份春节公历
  1093. // preYearCjglDate, err := time.Parse(utils.FormatDate, preYearCjgl)
  1094. // if err != nil {
  1095. // errMsg = "生成历史年份春节失败,Err:" + err.Error()
  1096. // return result, err
  1097. // }
  1098. // day := currentYearCjglDate.Sub(preYearCjglDate).Hours() / float64(24)
  1099. // fmt.Println("day:", day, currentYearCjglDate, preYearCjglDate)
  1100. // items := new(EdbDataItems)
  1101. // items.BetweenDay = int(day) //公历日期换算成农历,需要减除的天数
  1102. // items.Year = preYear
  1103. // for _, v := range dataList {
  1104. // dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
  1105. // if err != nil {
  1106. // errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
  1107. // return result, err
  1108. // }
  1109. // newDate := dateTime.AddDate(0, 0, int(day))
  1110. // timestamp := newDate.UnixNano() / 1e6
  1111. // item := new(EdbDataList)
  1112. // item.DataTime = newDate.Format(utils.FormatDate)
  1113. // item.EdbInfoId = v.EdbInfoId
  1114. // item.Value = v.Value
  1115. // item.EdbDataId = v.EdbDataId
  1116. // item.DataTimestamp = timestamp
  1117. // items.Items = append(items.Items, item)
  1118. // }
  1119. // result.List = append(result.List, items)
  1120. // } else {
  1121. // nextYear := thisYear + 1
  1122. // nextYearCjnl := strconv.Itoa(nextYear) + "-01-01" //当前年份春节农历
  1123. // nextYearCjgl := solarlunar.LunarToSolar(nextYearCjnl, false) //当前年份春节公历
  1124. // nextYearCjglDate, err := time.Parse(utils.FormatDate, nextYearCjgl)
  1125. // if err != nil {
  1126. // errMsg = "生成当前春节失败,Err:" + err.Error()
  1127. // return result, err
  1128. // }
  1129. // preYear := vy
  1130. // preYearCjnl := strconv.Itoa(preYear) + "-01-01" //之前年份春节农历
  1131. // preYearCjgl := solarlunar.LunarToSolar(preYearCjnl, false) //之前年份春节公历
  1132. // preYearCjglDate, err := time.Parse(utils.FormatDate, preYearCjgl)
  1133. // if err != nil {
  1134. // errMsg = "生成历史年份春节失败,Err:" + err.Error()
  1135. // return result, err
  1136. // }
  1137. // day := nextYearCjglDate.Sub(preYearCjglDate).Hours() / float64(24)
  1138. // fmt.Println("day:", day, nextYearCjglDate, preYearCjglDate)
  1139. // items := new(EdbDataItems)
  1140. // items.BetweenDay = int(day) //公历日期换算成农历,需要减除的天数
  1141. // items.Year = preYear
  1142. // fmt.Println("preYear:", preYear, "ky:", ky, "yearArrLen:", len(yearArr))
  1143. // //if ky+1 < len(yearArr) {
  1144. // for _, v := range dataList {
  1145. // dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
  1146. // if err != nil {
  1147. // errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
  1148. // return result, err
  1149. // }
  1150. // newDate := dateTime.AddDate(0, 0, int(day))
  1151. // timestamp := newDate.UnixNano() / 1e6
  1152. // item := new(EdbDataList)
  1153. // item.DataTime = newDate.Format(utils.FormatDate)
  1154. // item.EdbInfoId = v.EdbInfoId
  1155. // item.Value = v.Value
  1156. // item.EdbDataId = v.EdbDataId
  1157. // item.DataTimestamp = timestamp
  1158. // items.Items = append(items.Items, item)
  1159. // }
  1160. // result.List = append(result.List, items)
  1161. // /*} else {
  1162. // for _, v := range dataList {
  1163. // dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
  1164. // if err != nil {
  1165. // errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
  1166. // return result, err
  1167. // }
  1168. // timestamp := dateTime.UnixNano() / 1e6
  1169. // item := new(EdbDataList)
  1170. // item.DataTime = dateTime.Format(utils.FormatDate)
  1171. // item.EdbInfoId = v.EdbInfoId
  1172. // item.Value = v.Value
  1173. // item.EdbDataId = v.EdbDataId
  1174. // item.DataTimestamp = timestamp
  1175. // items.Items = append(items.Items, item)
  1176. // }
  1177. // result.List = append(result.List, items)
  1178. // }*/
  1179. // }
  1180. // }
  1181. // return
  1182. // }
  1183. type CorrelationInfo struct {
  1184. LeadValue int `description:"领先值"`
  1185. LeadUnit string `description:"领先单位"`
  1186. StartDate string `description:"开始日期"`
  1187. EndDate string `description:"结束日期"`
  1188. EdbInfoIdFirst int `description:"A指标ID"`
  1189. EdbInfoIdSecond int `description:"B指标ID"`
  1190. PeriodData string `description:"X轴-期数数据"`
  1191. CorrelationData string `description:"Y轴-相关性系数"`
  1192. AnalysisMode int `description:"分析模式: 0-单因子; 1-多因子"`
  1193. }
  1194. type SeasonExtraItem struct {
  1195. ChartLegend []SeasonChartLegend `description:"自定义的图例名称"`
  1196. XStartDate string `description:"横坐标显示的起始日"`
  1197. XEndDate string `description:"横坐标显示的截止日"`
  1198. JumpYear int `description:"横坐标日期是否跨年,1跨年,0不跨年"`
  1199. RightAxis SeasonRightAxis `description:"自定义右轴指标"`
  1200. MaxMinLimits MaxMinLimits `description:"自定义同期上下限"`
  1201. SamePeriodAverage SamePeriodAverage `description:"自定义同期均线"`
  1202. SamePeriodStandardDeviation SamePeriodStandardDeviation `description:"自定义同期标准差"`
  1203. }
  1204. // 自定义右轴指标
  1205. type SeasonRightAxis struct {
  1206. IndicatorType int `description:"右轴指标类型 1:左轴指标同比,2:指标库,3:预测指标 "`
  1207. Style string `description:"生成样式"`
  1208. Shape string `description:"形状"`
  1209. ChartColor string `description:"图表颜色"`
  1210. Size int `description:"大小"`
  1211. Legend string `description:"图例名称"`
  1212. NumFormat int `description:"数值格式 1:百分比 2:小数"`
  1213. IsConnected int `description:"是否连接 0不连接 1连接"`
  1214. LineColor string `description:"线条颜色"`
  1215. LineWidth float64 `description:"线条宽度"`
  1216. LineStyle string `description:"线条样式"`
  1217. IsShow bool `description:"是否显示"`
  1218. IsAdd bool `description:"是否添加"`
  1219. }
  1220. // 自定义同期上下限
  1221. type MaxMinLimits struct {
  1222. Color string `description:"颜色"`
  1223. Year int `description:"上下限取值范围"`
  1224. Legend string `description:"图例名称"`
  1225. IsShow bool `description:"是否显示"`
  1226. IsAdd bool `description:"是否添加"`
  1227. }
  1228. // 自定义同期均线
  1229. type SamePeriodAverage struct {
  1230. Color string `description:"颜色"`
  1231. Year int `description:"均线取值范围"`
  1232. Legend string `description:"图例名称"`
  1233. LineType string `description:"线型"`
  1234. LineWidth float64 `description:"线宽"`
  1235. IsShow bool `description:"是否显示"`
  1236. IsAdd bool `description:"是否添加"`
  1237. }
  1238. // 自定义同期均线
  1239. type SamePeriodAverageResp struct {
  1240. Color string `description:"颜色"`
  1241. Year int `description:"均线取值范围"`
  1242. Legend string `description:"图例名称"`
  1243. LineType string `description:"线型"`
  1244. LineWidth float64 `description:"线宽"`
  1245. IsShow bool `description:"是否显示"`
  1246. List []*SamePeriodAverageData `description:"自定义均线列表"`
  1247. IsAdd bool `description:"是否添加"`
  1248. }
  1249. type SamePeriodAverageData struct {
  1250. DataTime string `description:"数据日期"`
  1251. DataTimestamp int64 `description:"数据日期时间戳"`
  1252. Value float64 `description:"均值"`
  1253. }
  1254. // 自定义同期标准差
  1255. type SamePeriodStandardDeviation struct {
  1256. Color string `description:"颜色"`
  1257. Year int `description:"标准差取值范围"`
  1258. Legend string `description:"图例名称"`
  1259. Multiple float64 `description:"标准差倍数"`
  1260. IsShow bool `description:"是否显示"`
  1261. IsAdd bool `description:"是否添加"`
  1262. }
  1263. type SamePeriodStandardDeviationResp struct {
  1264. Color string `description:"颜色"`
  1265. Year int `description:"标准差取值范围"`
  1266. Legend string `description:"图例名称"`
  1267. Multiple float64 `description:"标准差倍数"`
  1268. IsShow bool `description:"是否显示"`
  1269. List []*MaxMinLimitsData `description:"自定义标准差列表"`
  1270. IsAdd bool `description:"是否添加"`
  1271. }
  1272. type SeasonChartResp struct {
  1273. MaxMinLimits MaxMinLimitsResp `description:"自定义上下限"`
  1274. SamePeriodAverage SamePeriodAverageResp `description:"自定义同期均线"`
  1275. SamePeriodStandardDeviation SamePeriodStandardDeviationResp `description:"自定义同期标准差线"`
  1276. RightAxis SeasonRightAxisResp `description:"自定义右轴指标"`
  1277. }
  1278. // 自定义右轴指标
  1279. type SeasonRightAxisResp struct {
  1280. SeasonRightAxis
  1281. EdbInfoList []*ChartEdbInfoMapping
  1282. }
  1283. type MaxMinLimitsResp struct {
  1284. List []*MaxMinLimitsData `description:"自定义上下限列表"`
  1285. Color string `description:"颜色"`
  1286. Year int `description:"上下限取值范围"`
  1287. Legend string `description:"图例名称"`
  1288. IsShow bool `description:"是否显示"`
  1289. IsAdd bool `description:"是否添加"`
  1290. }
  1291. type MaxMinLimitsData struct {
  1292. DataTime string `description:"数据日期"`
  1293. DataTimestamp int64 `description:"数据日期时间戳"`
  1294. MaxValue float64 `description:"最大值"`
  1295. MinValue float64 `description:"最小值"`
  1296. }
  1297. type SeasonChartLegend struct {
  1298. Name string
  1299. Value string
  1300. }
  1301. type QuarterDataList []*QuarterData
  1302. func (m QuarterDataList) Len() int {
  1303. return len(m)
  1304. }
  1305. func (m QuarterDataList) Less(i, j int) bool {
  1306. return m[i].Years < m[j].Years
  1307. }
  1308. func (m QuarterDataList) Swap(i, j int) {
  1309. m[i], m[j] = m[j], m[i]
  1310. }
  1311. type ChartDwCollectReq struct {
  1312. UniqueCode string
  1313. Token string
  1314. }
  1315. // 截面组合图额外配置
  1316. type ChartSectionExtraConf struct {
  1317. DateConfList []*ChartSectionDateConfItem
  1318. IsHeap int `description:"是否堆积(1.堆积,0不堆积)"`
  1319. XDataList []XData `description:"横轴名称设置"`
  1320. UnitList *ChartSectionCombineUnit `description:"纵轴单位设置"`
  1321. BaseChartSeriesName string `description:"基准系列名称"`
  1322. SortType int `description:"排序类型,0默认,1升序,2降序"`
  1323. }
  1324. // 截面组合图额外配置
  1325. type ChartSectionAllExtraConf struct {
  1326. ChartSectionExtraConf
  1327. SeriesList []*ChartSectionSeriesItem
  1328. }
  1329. type ChartSectionDateConfItem struct {
  1330. MoveForward int `description:"前移的期数"`
  1331. EdbInfoId int `description:"指标ID"`
  1332. EdbName string `description:"指标名称"`
  1333. EdbNameEn string `description:"指标名称英文"`
  1334. EdbInfoType int `description:"指标类型"`
  1335. Frequency string `description:"频度"`
  1336. EndDate string `description:"最新日期"`
  1337. StaticDate string `description:"固定日期"`
  1338. DateType int `description:"日期类型:0 指标日期,1系统日期, 2固定日期"`
  1339. DateConfName string `description:"引用日期名称"` // 引用日期名称不能重复
  1340. DateConfNameEn string `description:"引用日期英文名称"`
  1341. DateChange []*ChartSectionDateChange
  1342. }
  1343. // 截面组合图引用日期配置
  1344. type ChartSectionDateChange struct {
  1345. Year int
  1346. Month int
  1347. Day int
  1348. Frequency string `description:"频度变换"`
  1349. FrequencyDay string `description:"频度的固定日期"`
  1350. ChangeType int `description:"日期变换类型1日期位移,2指定频率"`
  1351. }
  1352. // 截面组合图系列配置
  1353. // type ChartSectionSeriesItem struct {
  1354. // ChartSeriesId int `description:"系列ID"`
  1355. // SeriesName string `description:"系列名称"` //系列名称不可同名
  1356. // SeriesNameEn string `description:"系列英文名称"`
  1357. // ChartStyle string `description:"图表类型"`
  1358. // ChartColor string `description:"颜色"`
  1359. // ChartWidth int `description:"线条大小"`
  1360. // IsPoint int `description:"是否用数据点展示(0 否,1是)"`
  1361. // IsNumber int `description:"是否用数值展示(0 否,1是)"`
  1362. // IsAxis int `description:"1:左轴,0:右轴"`
  1363. // MaxData float64 `description:"上限"`
  1364. // MinData float64 `description:"下限"`
  1365. // //IsOrder bool `description:"true:正序,false:逆序"`
  1366. // EdbInfoList []*ChartSectionSeriesEdbConf
  1367. // DataList []float64
  1368. // NoDataEdbIndex []int
  1369. // }
  1370. // 截面组合图系列配置
  1371. type ChartSectionSeriesItem struct {
  1372. ChartSeriesId int `gorm:"column:chart_series_id;primaryKey" description:"系列ID"`
  1373. SeriesName string `gorm:"column:series_name" description:"系列名称"` //系列名称不可同名
  1374. SeriesNameEn string `gorm:"column:series_name_en" description:"系列英文名称"`
  1375. ChartStyle string `gorm:"column:chart_style" description:"图表类型"`
  1376. ChartColor string `gorm:"column:chart_color" description:"颜色"`
  1377. ChartWidth int `gorm:"column:chart_width" description:"线条大小"`
  1378. IsPoint int `gorm:"column:is_point" description:"是否用数据点展示(0 否,1是)"`
  1379. IsNumber int `gorm:"column:is_number" description:"是否用数值展示(0 否,1是)"`
  1380. IsAxis int `gorm:"column:is_axis" description:"1:左轴,0:右轴"`
  1381. MaxData float64 `gorm:"column:max_data" description:"上限"`
  1382. MinData float64 `gorm:"column:min_data" description:"下限"`
  1383. EdbInfoList []*ChartSectionSeriesEdbConf `gorm:"foreignkey:ChartSeriesId" description:"指标列表"`
  1384. DataList []float64 `gorm:"column:data_list" description:"数据列表"`
  1385. NoDataEdbIndex []int `gorm:"column:no_data_edb_index" description:"没有数据的指标索引"`
  1386. }
  1387. type ChartSectionSeriesEdbConf struct {
  1388. ChartSeriesEdbMappingId int `description:"映射ID"`
  1389. ChartSeriesId int `description:"系列ID"`
  1390. //ChartInfoId int `description:"图表ID"`
  1391. EdbInfoId int `description:"指标id"`
  1392. DateConf *ChartSectionSeriesDateConfItem
  1393. EdbName string `description:"中文别名"`
  1394. EdbNameEn string `description:"英文别名"`
  1395. EdbInfoType int `description:"指标类型"`
  1396. Unit string `description:"单位"`
  1397. UnitEn string `description:"英文单位"`
  1398. DateConfName string `description:"引用日期名称"`
  1399. DateConfType int `description:"日期类型,0指标最新日期, 1引用日期"`
  1400. }
  1401. type ChartSectionCombineDataResp struct {
  1402. DateConfList []*ChartSectionDateConfItem
  1403. IsHeap int `description:"是否堆积(1.堆积,0不堆积)"`
  1404. XDataList []XData `description:"横轴名称设置"`
  1405. UnitList *ChartSectionCombineUnit `description:"纵轴单位设置"`
  1406. BaseChartSeriesName string `description:"基准系列名称"`
  1407. SortType int `description:"排序类型,0默认,1升序,2降序"`
  1408. SeriesList []*ChartSectionSeriesItem
  1409. LeftMin string `description:"图表左侧最小值"`
  1410. LeftMax string `description:"图表左侧最大值"`
  1411. RightMin string `description:"图表右侧最小值"`
  1412. RightMax string `description:"图表右侧最大值"`
  1413. Right2Min string `description:"图表右侧最小值"`
  1414. Right2Max string `description:"图表右侧最大值"`
  1415. }
  1416. // 系列里的指标日期配置
  1417. type ChartSectionSeriesDateConfItem struct {
  1418. MoveForward int `description:"前移的期数"`
  1419. DateChange []*ChartSectionDateChange
  1420. }
  1421. // PreviewSectionCombineChartReq 预览截面组合图的请求
  1422. type PreviewSectionCombineChartReq struct {
  1423. ChartName string `description:"图表名称"`
  1424. ChartClassifyId int `description:"分类id"`
  1425. ExtraConfig string `description:"图表额外配置信息,json字符串"`
  1426. }
  1427. type ChartSectionCombineUnit struct {
  1428. LeftName string `description:"左轴单位"`
  1429. LeftNameEn string `description:"左轴英文单位"`
  1430. RightName string `description:"右轴单位"`
  1431. RightNameEn string `description:"右轴英文单位"`
  1432. RightTwoName string `description:"右2轴单位"`
  1433. RightTwoNameEn string `description:"右2轴英文单位"`
  1434. }
  1435. // 时序组合图额外配置
  1436. type ChartTimeCombineExtraConf struct {
  1437. IsHeap int `description:"是否堆积(1.堆积,0不堆积)"`
  1438. }
  1439. type ChartTimeCombineDataResp struct {
  1440. IsHeap int `description:"是否堆积(1.堆积,0不堆积)"`
  1441. }
  1442. func GetChartInfoById(chartInfoId int) (item *ChartInfo, err error) {
  1443. o := global.DmSQL["data"]
  1444. sql := ` SELECT * FROM chart_info WHERE chart_info_id=? `
  1445. err = o.Raw(sql, chartInfoId).First(&item).Error
  1446. return
  1447. }
  1448. // func GetChartInfoById(chartInfoId int) (item *ChartInfo, err error) {
  1449. // o := orm.NewOrmUsingDB("data")
  1450. // sql := ` SELECT * FROM chart_info WHERE chart_info_id=? `
  1451. // err = o.Raw(sql, chartInfoId).QueryRow(&item)
  1452. // return
  1453. // }
  1454. type MarkersLine struct {
  1455. Axis int `json:"axis" description:"1左轴 2右轴 3横轴"`
  1456. AxisName string `json:"axisName" description:"轴的名称,例如'左轴'"`
  1457. MarkerType string `json:"markerType" description:"标识线或标识区"`
  1458. MarkLineType int `json:"markLineType" description:"1:固定 2:指标计算"`
  1459. Value string `json:"value" description:"连线指向的数值,例如'4000'"`
  1460. FromValue string `json:"fromValue" description:"连线的起始点,可以为空"`
  1461. ToValue string `json:"toValue" description:"连线的结束点,可以为空"`
  1462. LineWidth float64 `json:"lineWidth" description:"连线的宽度"`
  1463. DashStyle string `json:"dashStyle" description:"连线的虚线样式,例如'ShortDashDot'"`
  1464. Color string `json:"color" description:"连线的颜色"`
  1465. Text string `json:"text" description:"连线旁边显示的文本"`
  1466. TextPosition string `json:"textPosition" description:"文本的显示位置,例如'bottom'"`
  1467. TextColor string `json:"textColor" description:"文本颜色"`
  1468. TextFontSize int `json:"textFontSize" description:"文本的字号大小"`
  1469. IsShow bool `json:"isShow" description:"是否显示连线及文本"`
  1470. EdbType int `json:"edbType" description:"指标类型 0图中第一个指标 1其他指标 前端回显用"`
  1471. EdbInfoId int `json:"edbInfoId" description:"指标id"`
  1472. Calculation int `json:"calculation" description:"计算方式 1区间均值 2区间均值加N倍标准差 3区间个数分位 4区间数值分位"`
  1473. CalculationValue int `json:"calculationValue" description:"计算方式对应的值 2就是几倍标准差 3就是分位值 4就是数值值·"`
  1474. TimeIntervalType int `json:"timeInterval" description:"时间区间 0跟随图表 1自定义"`
  1475. StartDate MarkersLineTime `json:"startTime" description:"开始时间"`
  1476. EndDate MarkersLineTime `json:"endTime" description:"结束时间"`
  1477. }
  1478. type MarkersLineTime struct {
  1479. TimeType int `json:"timeType" description:"时间类型 1固定 2动态 3至今(仅结束时间)"`
  1480. Date string `json:"date" description:"日期"`
  1481. Conf EdbDateChangeConf `json:"conf" description:"动态时间配置"`
  1482. }
  1483. // EdbDateExtraConf
  1484. // @Description: 导入指标日期前移和日期变换
  1485. type EdbDateChangeConf struct {
  1486. MoveForward int `json:"moveForward" description:"前移的期数"`
  1487. BaseDate int `json:"baseDate" description:"基准日期 0系统日期 1指标最新日期"`
  1488. DateChange []*EdbDateConfDateChange
  1489. }
  1490. type EdbDateConfDateChange struct {
  1491. Year int `json:"year" description:"前移的期数"`
  1492. Month int `json:"month" description:"前移的期数"`
  1493. Day int `json:"day" description:"前移的期数"`
  1494. Frequency string `json:"moveForward" description:"频度变换"`
  1495. FrequencyDay string `json:"frequencyDay" description:"频度的固定日期"`
  1496. ChangeType int `json:"changeType" description:"日期变换类型1日期位移,2指定频率"`
  1497. }
  1498. func getThsHfEdbDataListByMongo(source, subSource, edbInfoId int, startDate, endDate string) (list []*EdbDataList, err error) {
  1499. list = make([]*EdbDataList, 0)
  1500. mogDataObj := mgo.EdbDataThsHf{}
  1501. // 构建查询条件
  1502. queryConditions := bson.M{
  1503. "edb_info_id": edbInfoId,
  1504. }
  1505. // 数据日期
  1506. dateCondition, err := mgo.BuildDateCondition(startDate, endDate)
  1507. if err != nil {
  1508. return
  1509. }
  1510. if len(dateCondition) > 0 {
  1511. queryConditions["data_time"] = dateCondition
  1512. }
  1513. // 获取列表数据
  1514. tmpDataList, tmpErr := mogDataObj.GetAllDataList(queryConditions, []string{"data_time"})
  1515. if tmpErr != nil {
  1516. err = tmpErr
  1517. return
  1518. }
  1519. for k, v := range tmpDataList {
  1520. list = append(list, &EdbDataList{
  1521. EdbDataId: k + 1,
  1522. EdbInfoId: v.EdbInfoId,
  1523. DataTime: v.DataTime.Format(utils.FormatDate),
  1524. DataTimestamp: v.DataTimestamp,
  1525. Value: v.Value,
  1526. })
  1527. }
  1528. return
  1529. }