chart.go 69 KB

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