chart.go 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660
  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. }
  1530. // ConvertToResp
  1531. // @Description: 转成需要输出的格式
  1532. // @receiver m
  1533. func (m *ChartEdbInfoMapping) ConvertToResp() {
  1534. m.ModifyTime = utils.GormDateStrToDateTimeStr(m.ModifyTime)
  1535. m.StartDate = utils.GormDateStrToDateStr(m.StartDate)
  1536. m.EndDate = utils.GormDateStrToDateStr(m.EndDate)
  1537. m.LatestDate = utils.GormDateStrToDateStr(m.LatestDate)
  1538. m.MoveLatestDate = utils.GormDateStrToDateStr(m.MoveLatestDate)
  1539. return
  1540. }