chart.go 71 KB

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