chart.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. package models
  2. import (
  3. "errors"
  4. "eta/eta_chart_lib/utils"
  5. "fmt"
  6. "github.com/beego/beego/v2/client/orm"
  7. "strconv"
  8. "time"
  9. "github.com/nosixtools/solarlunar"
  10. )
  11. type ChartInfo struct {
  12. ChartInfoId int `json:"-" orm:"column(chart_info_id);pk"`
  13. ChartName string `description:"来源名称"`
  14. ChartNameEn string `description:"英文图表名称"`
  15. ChartClassifyId int `json:"-" description:"图表分类id"`
  16. SysUserId int `json:"-"`
  17. SysUserRealName string `json:"-"`
  18. UniqueCode string `description:"图表唯一编码"`
  19. CreateTime time.Time `json:"-"`
  20. ModifyTime time.Time `json:"-"`
  21. DateType int `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间"`
  22. StartDate string `description:"自定义开始日期"`
  23. EndDate string `description:"自定义结束日期"`
  24. IsSetName int `description:"设置名称"`
  25. EdbInfoIds string `description:"指标id"`
  26. ChartType int `description:"生成样式:1:曲线图,2:季节性图"`
  27. Calendar string `description:"公历/农历"`
  28. SeasonStartDate string `description:"季节性图开始日期"`
  29. SeasonEndDate string `description:"季节性图开始日期"`
  30. ChartImage string `description:"图表图片"`
  31. BarConfig string `description:"柱方图的配置,json数据" json:"-"`
  32. LeftMin string `description:"图表左侧最小值"`
  33. LeftMax string `description:"图表左侧最大值"`
  34. Source int `description:"1:ETA图库;2:商品价格曲线"`
  35. Unit string `description:"中文单位名称"`
  36. UnitEn string `description:"英文单位名称"`
  37. ExtraConfig string `description:"图表额外配置,json数据" json:"-"`
  38. ChartSource string `description:"图表来源str"`
  39. ChartSourceEn string `description:"图表来源(英文)"`
  40. SeasonExtraConfig string `description:"季节性图表中的配置,json数据"`
  41. StartYear int `description:"当选择的日期类型为最近N年类型时,即date_type=20, 用start_year表示N"`
  42. ChartThemeId int `description:"图表应用主题ID"`
  43. ChartThemeStyle string `description:"图表应用主题样式"`
  44. SourcesFrom string `description:"图表来源"`
  45. Instructions string `description:"图表说明"`
  46. MarkersLines string `description:"标识线"`
  47. MarkersAreas string `description:"标识区"`
  48. }
  49. func GetChartInfoByUniqueCode(uniqueCode string) (item *ChartInfo, err error) {
  50. o := orm.NewOrmUsingDB("data")
  51. sql := ` SELECT * FROM chart_info WHERE unique_code=? `
  52. err = o.Raw(sql, uniqueCode).QueryRow(&item)
  53. return
  54. }
  55. type ChartEdbInfoMapping struct {
  56. EdbInfoId int `description:"指标id"`
  57. SourceName string `description:"来源名称"`
  58. Source int `description:"来源id"`
  59. EdbCode string `description:"指标编码"`
  60. EdbName string `description:"指标名称"`
  61. EdbAliasName string `description:"指标名称(别名)"`
  62. EdbAliasNameEn string `description:"英文指标名称(别名)"`
  63. EdbNameEn string `description:"英文指标名称"`
  64. Frequency string `description:"频率"`
  65. FrequencyEn string `description:"英文频率"`
  66. Unit string `description:"单位"`
  67. UnitEn string `description:"英文单位"`
  68. StartDate string `description:"起始日期"`
  69. EndDate string `description:"终止日期"`
  70. ModifyTime string `description:"指标最后更新时间"`
  71. ChartEdbMappingId int `description:"图表指标id" json:"-"`
  72. ChartInfoId int `description:"图表id"`
  73. MaxData float64 `description:"上限"`
  74. MinData float64 `description:"下限"`
  75. IsOrder bool `description:"true:正序,false:逆序"`
  76. IsAxis int `description:"1:左轴,0:右轴"`
  77. EdbInfoType int `description:"1:标准指标,0:领先指标"`
  78. EdbType int `description:"指标类型:1:基础指标,2:计算指标"`
  79. LeadValue int `description:"领先值"`
  80. LeadUnit string `description:"领先单位"`
  81. LeadUnitEn string `description:"领先英文单位"`
  82. ChartStyle string `description:"图表类型"`
  83. ChartColor string `description:"颜色"`
  84. ChartWidth float64 `description:"线条大小"`
  85. DataList interface{}
  86. EdbInfoCategoryType int `description:"0:普通指标,1:预测指标"`
  87. PredictChartColor string `description:"预测数据的颜色"`
  88. ChartType int `description:"生成样式:1:曲线图,2:季节性图,3:面积图,4:柱状图,5:散点图,6:组合图"`
  89. LatestDate string `description:"数据最新日期"`
  90. LatestValue float64 `description:"数据最新值"`
  91. MoveLatestDate string `description:"移动后的数据最新日期"`
  92. UniqueCode string `description:"指标唯一编码"`
  93. MinValue float64 `json:"-" description:"最小值"`
  94. MaxValue float64 `json:"-" description:"最大值"`
  95. IsNullData bool `json:"-" description:"是否空数据"`
  96. MappingSource int `description:"1:ETA图库;2:商品价格曲线"`
  97. SubSource int `description:"子数据来源:0:经济数据库,1:日期序列"`
  98. SubSourceName string `description:"子数据来源名称"`
  99. IndicatorCode string `description:"指标代码"`
  100. StockCode string `description:"证券代码"`
  101. }
  102. func GetChartEdbMappingList(chartInfoId int) (list []*ChartEdbInfoMapping, err error) {
  103. o := orm.NewOrmUsingDB("data")
  104. 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`
  105. 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
  106. FROM chart_edb_mapping AS a
  107. INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
  108. WHERE chart_info_id=?
  109. ORDER BY chart_edb_mapping_id ASC `
  110. _, err = o.Raw(sql, chartInfoId).QueryRows(&list)
  111. return
  112. }
  113. type EdbDataList struct {
  114. EdbDataId int `json:"-" description:" 指标数据ID"`
  115. EdbInfoId int `json:"-" description:"指标ID"`
  116. DataTime string `json:"-" description:"数据日期"`
  117. DataTimestamp int64 `description:"数据日期"`
  118. Value float64 `description:"数据值"`
  119. }
  120. // GetEdbDataList 获取指标的数据(日期正序返回)
  121. func GetEdbDataList(source, subSource, endInfoId int, startDate, endDate string) (list []*EdbDataList, err error) {
  122. tableName := GetEdbDataTableName(source, subSource)
  123. if tableName == "" {
  124. err = errors.New("无效的渠道:" + strconv.Itoa(source))
  125. list = make([]*EdbDataList, 0)
  126. return list, err
  127. }
  128. var pars []interface{}
  129. var condition string
  130. if startDate != "" {
  131. condition += ` AND data_time>=? `
  132. pars = append(pars, startDate)
  133. }
  134. if endDate != "" {
  135. condition += ` AND data_time<=? `
  136. pars = append(pars, endDate)
  137. }
  138. sql := `SELECT edb_data_id,edb_info_id,data_time,TRUNCATE(value,4) AS value,data_timestamp FROM %s WHERE edb_info_id=? `
  139. if condition != "" {
  140. sql += condition
  141. }
  142. sql += ` ORDER BY data_time ASC `
  143. sql = fmt.Sprintf(sql, tableName)
  144. o := orm.NewOrmUsingDB("data")
  145. _, err = o.Raw(sql, endInfoId, pars).QueryRows(&list)
  146. return
  147. }
  148. type EdbDataItemList struct {
  149. EdbDataId int `json:"-" description:" 指标数据ID"`
  150. EdbInfoId int `json:"-" description:"指标ID"`
  151. DataTime string `description:"数据日期"`
  152. DataTimestamp int64 `description:"数据日期"`
  153. Value float64 `description:"数据值"`
  154. }
  155. type EdbDataItems struct {
  156. Items []*EdbDataList
  157. Year int
  158. BetweenDay int `json:"-" description:"公历与农历之间相差的天数"`
  159. CuttingDataTimestamp int64 `description:"切割的时间戳"`
  160. }
  161. type EdbDataResult struct {
  162. List []*EdbDataItems
  163. }
  164. type QuarterData struct {
  165. Year string
  166. DataList []*EdbDataList
  167. CuttingDataTimestamp int64 `description:"切割的时间戳"`
  168. ChartLegend string
  169. Years string
  170. }
  171. type QuarterXDateItem struct {
  172. StartDate time.Time
  173. EndDate time.Time
  174. ShowName string
  175. ChartLegend string
  176. CuttingDataTimestamp int64 `description:"切割的时间戳"`
  177. }
  178. type ChartInfoDetailResp struct {
  179. ChartInfo *ChartInfo
  180. EdbInfoList []*ChartEdbInfoMapping
  181. XEdbIdValue []int `description:"柱方图的x轴数据,指标id"`
  182. YDataList []YData `description:"柱方图的y轴数据"`
  183. XDataList []XData `description:"商品价格曲线的X轴数据"`
  184. CorrelationChartInfo *CorrelationInfo `description:"相关性图表信息"`
  185. DataResp interface{} `description:"图表数据,根据图的类型而定的,没有确定的数据格式"`
  186. WaterMark string `description:"水印"`
  187. }
  188. // XData 商品价格曲线的的x轴数据
  189. type XData struct {
  190. Name string `description:"别名"`
  191. NameEn string `description:"英文别名"`
  192. }
  193. // YData 柱方图的y轴数据
  194. type YData struct {
  195. Date string `description:"数据日期"`
  196. ConfigDate time.Time `description:"配置的日期" json:"-"`
  197. Color string `description:"数据颜色"`
  198. Name string `description:"别名"`
  199. NameEn string `description:"英文别名"`
  200. Value []float64 `description:"每个指标的值"`
  201. NoDataEdbList []int `description:"没有数据的指标列表"`
  202. XEdbInfoIdList []int `description:"对应X轴的指标id列表"`
  203. EdbValMap map[int]float64 `description:"指标与值的对应" json:"-"`
  204. M []int `description:"对应开始日期的间隔值" json:"-"`
  205. NameList []string `description:"每个值对应的名称"`
  206. EnNameList []string `description:"每个值对应的英文名称"`
  207. }
  208. // RollingCorrelationChartDataResp 滚动相关性图
  209. type RollingCorrelationChartDataResp struct {
  210. XDateTimeValue []string `description:"滚动相关性图的x轴数据,日期数据"`
  211. YDataList []YData `description:"滚动相关性图的y轴数据"`
  212. }
  213. // 指标季度数据计算(公历转农历)
  214. func AddCalculateQuarterV5(dataList []*EdbDataList) (result *EdbDataResult, err error) {
  215. var errMsg string
  216. defer func() {
  217. if errMsg != "" {
  218. fmt.Println("errMsg:", errMsg)
  219. }
  220. }()
  221. if len(dataList) <= 0 {
  222. result.List = make([]*EdbDataItems, 0)
  223. return
  224. }
  225. endDate := dataList[len(dataList)-1].DataTime
  226. endDateForm, err := time.Parse(utils.FormatDate, endDate)
  227. if err != nil {
  228. return result, err
  229. }
  230. thisMonth := int(endDateForm.Month())
  231. result = new(EdbDataResult)
  232. var yearArr []int
  233. yearMap := make(map[int]int)
  234. var cureentDate time.Time
  235. if thisMonth < 11 {
  236. for k, v := range dataList {
  237. dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
  238. if err != nil {
  239. errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
  240. return result, err
  241. }
  242. if k == len(dataList)-1 {
  243. cureentDate = dateTime
  244. }
  245. year := dateTime.Year()
  246. if _, ok := yearMap[year]; !ok {
  247. yearArr = append(yearArr, year)
  248. }
  249. yearMap[year] = year
  250. }
  251. } else {
  252. for k, v := range dataList {
  253. dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
  254. if err != nil {
  255. errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
  256. return result, err
  257. }
  258. if k == len(dataList)-1 {
  259. cureentDate = dateTime
  260. }
  261. year := dateTime.Year() + 1
  262. if _, ok := yearMap[year]; !ok {
  263. yearArr = append(yearArr, year)
  264. }
  265. yearMap[year] = year
  266. }
  267. }
  268. //排序
  269. fmt.Println("yearArr:", yearArr)
  270. thisYear := cureentDate.Year()
  271. //thisMonth := int(cureentDate.Month())
  272. fmt.Println("thisMonth:", thisMonth)
  273. for ky, vy := range yearArr {
  274. fmt.Println("line 432:", ky, vy, thisYear, thisMonth)
  275. if thisMonth < 11 {
  276. currentYearCjnl := strconv.Itoa(thisYear) + "-01-01" //当前年份春节农历
  277. currentYearCjgl := solarlunar.LunarToSolar(currentYearCjnl, false) //当前年份春节公历
  278. currentYearCjglDate, err := time.Parse(utils.FormatDate, currentYearCjgl)
  279. if err != nil {
  280. errMsg = "生成当前春节失败,Err:" + err.Error()
  281. return result, err
  282. }
  283. preYear := vy
  284. preYearCjnl := strconv.Itoa(preYear) + "-01-01" //之前年份春节农历
  285. preYearCjgl := solarlunar.LunarToSolar(preYearCjnl, false) //之前年份春节公历
  286. preYearCjglDate, err := time.Parse(utils.FormatDate, preYearCjgl)
  287. if err != nil {
  288. errMsg = "生成历史年份春节失败,Err:" + err.Error()
  289. return result, err
  290. }
  291. day := currentYearCjglDate.Sub(preYearCjglDate).Hours() / float64(24)
  292. items := new(EdbDataItems)
  293. items.BetweenDay = int(day) //公历日期换算成农历,需要减除的天数
  294. items.Year = preYear
  295. for _, v := range dataList {
  296. dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
  297. if err != nil {
  298. errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
  299. return result, err
  300. }
  301. newDate := dateTime.AddDate(0, 0, int(day))
  302. selectDateStr := strconv.Itoa(thisYear) + "-11" + "-30"
  303. selectDate, _ := time.Parse(utils.FormatDate, selectDateStr)
  304. if newDate.Before(selectDate) || newDate == selectDate {
  305. timestamp := newDate.UnixNano() / 1e6
  306. item := new(EdbDataList)
  307. item.DataTime = newDate.Format(utils.FormatDate)
  308. item.EdbInfoId = v.EdbInfoId
  309. item.Value = v.Value
  310. item.EdbDataId = v.EdbDataId
  311. item.DataTimestamp = timestamp
  312. items.Items = append(items.Items, item)
  313. }
  314. }
  315. result.List = append(result.List, items)
  316. } else {
  317. nextYear := thisYear + 1
  318. nextYearCjnl := strconv.Itoa(nextYear) + "-01-01" //当前年份春节农历
  319. nextYearCjgl := solarlunar.LunarToSolar(nextYearCjnl, false) //当前年份春节公历
  320. nextYearCjglDate, err := time.Parse(utils.FormatDate, nextYearCjgl)
  321. if err != nil {
  322. errMsg = "生成当前春节失败,Err:" + err.Error()
  323. return result, err
  324. }
  325. preYear := vy
  326. preYearCjnl := strconv.Itoa(preYear) + "-01-01" //之前年份春节农历
  327. preYearCjgl := solarlunar.LunarToSolar(preYearCjnl, false) //之前年份春节公历
  328. preYearCjglDate, err := time.Parse(utils.FormatDate, preYearCjgl)
  329. if err != nil {
  330. errMsg = "生成历史年份春节失败,Err:" + err.Error()
  331. return result, err
  332. }
  333. day := nextYearCjglDate.Sub(preYearCjglDate).Hours() / float64(24)
  334. fmt.Println("day:", day, nextYearCjglDate, preYearCjglDate)
  335. items := new(EdbDataItems)
  336. items.BetweenDay = int(day) //公历日期换算成农历,需要减除的天数
  337. items.Year = preYear - 1
  338. fmt.Println("preYear:", preYear, "ky:", ky, "yearArrLen:", len(yearArr))
  339. if ky+1 < len(yearArr) {
  340. for _, v := range dataList {
  341. dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
  342. if err != nil {
  343. errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
  344. return result, err
  345. }
  346. newDate := dateTime.AddDate(0, 0, int(day))
  347. selectDateStr := strconv.Itoa(nextYear) + "-05" + "-31"
  348. selectDate, _ := time.Parse(utils.FormatDate, selectDateStr)
  349. if newDate.Before(selectDate) || newDate == selectDate {
  350. timestamp := newDate.UnixNano() / 1e6
  351. item := new(EdbDataList)
  352. item.DataTime = newDate.Format(utils.FormatDate)
  353. item.EdbInfoId = v.EdbInfoId
  354. item.Value = v.Value
  355. item.EdbDataId = v.EdbDataId
  356. item.DataTimestamp = timestamp
  357. items.Items = append(items.Items, item)
  358. }
  359. }
  360. result.List = append(result.List, items)
  361. } else {
  362. for _, v := range dataList {
  363. dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
  364. if err != nil {
  365. errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
  366. return result, err
  367. }
  368. timestamp := dateTime.UnixNano() / 1e6
  369. item := new(EdbDataList)
  370. item.DataTime = dateTime.Format(utils.FormatDate)
  371. item.EdbInfoId = v.EdbInfoId
  372. item.Value = v.Value
  373. item.EdbDataId = v.EdbDataId
  374. item.DataTimestamp = timestamp
  375. items.Items = append(items.Items, item)
  376. }
  377. result.List = append(result.List, items)
  378. }
  379. }
  380. }
  381. return
  382. }
  383. // AddCalculateQuarterV6 指标季度数据计算(季节性图表)
  384. func AddCalculateQuarterV6(dataList []*EdbDataList) (result *EdbDataResult, err error) {
  385. var errMsg string
  386. defer func() {
  387. if errMsg != "" {
  388. fmt.Println("errMsg:", errMsg)
  389. }
  390. }()
  391. endDate := dataList[len(dataList)-1].DataTime
  392. endDateForm, err := time.Parse(utils.FormatDate, endDate)
  393. if err != nil {
  394. return result, err
  395. }
  396. thisMonth := int(endDateForm.Month())
  397. result = new(EdbDataResult)
  398. var yearArr []int
  399. yearMap := make(map[int]int)
  400. var cureentDate time.Time
  401. if thisMonth < 11 {
  402. for k, v := range dataList {
  403. dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
  404. if err != nil {
  405. errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
  406. return result, err
  407. }
  408. if k == len(dataList)-1 {
  409. cureentDate = dateTime
  410. }
  411. year := dateTime.Year()
  412. if _, ok := yearMap[year]; !ok {
  413. yearArr = append(yearArr, year)
  414. }
  415. yearMap[year] = year
  416. }
  417. } else {
  418. for k, v := range dataList {
  419. dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
  420. if err != nil {
  421. errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
  422. return result, err
  423. }
  424. if k == len(dataList)-1 {
  425. cureentDate = dateTime
  426. }
  427. year := dateTime.Year() + 1
  428. if _, ok := yearMap[year]; !ok {
  429. yearArr = append(yearArr, year)
  430. }
  431. yearMap[year] = year
  432. }
  433. }
  434. //排序
  435. fmt.Println("yearArr:", yearArr)
  436. thisYear := cureentDate.Year()
  437. //thisMonth := int(cureentDate.Month())
  438. fmt.Println("thisMonth:", thisMonth)
  439. for ky, vy := range yearArr {
  440. fmt.Printf("line 432:ky:%d, vy:%d, thisYear:%d, thisMonth:%d", ky, vy, thisYear, thisMonth)
  441. fmt.Println("")
  442. if thisMonth < 11 {
  443. currentYearCjnl := strconv.Itoa(thisYear) + "-01-01" //当前年份春节农历
  444. currentYearCjgl := solarlunar.LunarToSolar(currentYearCjnl, false) //当前年份春节公历
  445. currentYearCjglDate, err := time.Parse(utils.FormatDate, currentYearCjgl)
  446. if err != nil {
  447. errMsg = "生成当前春节失败,Err:" + err.Error()
  448. return result, err
  449. }
  450. preYear := vy
  451. preYearCjnl := strconv.Itoa(preYear) + "-01-01" //之前年份春节农历
  452. preYearCjgl := solarlunar.LunarToSolar(preYearCjnl, false) //之前年份春节公历
  453. preYearCjglDate, err := time.Parse(utils.FormatDate, preYearCjgl)
  454. if err != nil {
  455. errMsg = "生成历史年份春节失败,Err:" + err.Error()
  456. return result, err
  457. }
  458. day := currentYearCjglDate.Sub(preYearCjglDate).Hours() / float64(24)
  459. fmt.Println("day:", day, currentYearCjglDate, preYearCjglDate)
  460. items := new(EdbDataItems)
  461. items.BetweenDay = int(day) //公历日期换算成农历,需要减除的天数
  462. items.Year = preYear
  463. for _, v := range dataList {
  464. dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
  465. if err != nil {
  466. errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
  467. return result, err
  468. }
  469. newDate := dateTime.AddDate(0, 0, int(day))
  470. timestamp := newDate.UnixNano() / 1e6
  471. item := new(EdbDataList)
  472. item.DataTime = newDate.Format(utils.FormatDate)
  473. item.EdbInfoId = v.EdbInfoId
  474. item.Value = v.Value
  475. item.EdbDataId = v.EdbDataId
  476. item.DataTimestamp = timestamp
  477. items.Items = append(items.Items, item)
  478. }
  479. result.List = append(result.List, items)
  480. } else {
  481. nextYear := thisYear + 1
  482. nextYearCjnl := strconv.Itoa(nextYear) + "-01-01" //当前年份春节农历
  483. nextYearCjgl := solarlunar.LunarToSolar(nextYearCjnl, false) //当前年份春节公历
  484. nextYearCjglDate, err := time.Parse(utils.FormatDate, nextYearCjgl)
  485. if err != nil {
  486. errMsg = "生成当前春节失败,Err:" + err.Error()
  487. return result, err
  488. }
  489. preYear := vy
  490. preYearCjnl := strconv.Itoa(preYear) + "-01-01" //之前年份春节农历
  491. preYearCjgl := solarlunar.LunarToSolar(preYearCjnl, false) //之前年份春节公历
  492. preYearCjglDate, err := time.Parse(utils.FormatDate, preYearCjgl)
  493. if err != nil {
  494. errMsg = "生成历史年份春节失败,Err:" + err.Error()
  495. return result, err
  496. }
  497. day := nextYearCjglDate.Sub(preYearCjglDate).Hours() / float64(24)
  498. fmt.Println("day:", day, nextYearCjglDate, preYearCjglDate)
  499. items := new(EdbDataItems)
  500. items.BetweenDay = int(day) //公历日期换算成农历,需要减除的天数
  501. items.Year = preYear
  502. fmt.Println("preYear:", preYear, "ky:", ky, "yearArrLen:", len(yearArr))
  503. //if ky+1 < len(yearArr) {
  504. for _, v := range dataList {
  505. dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
  506. if err != nil {
  507. errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
  508. return result, err
  509. }
  510. newDate := dateTime.AddDate(0, 0, int(day))
  511. timestamp := newDate.UnixNano() / 1e6
  512. item := new(EdbDataList)
  513. item.DataTime = newDate.Format(utils.FormatDate)
  514. item.EdbInfoId = v.EdbInfoId
  515. item.Value = v.Value
  516. item.EdbDataId = v.EdbDataId
  517. item.DataTimestamp = timestamp
  518. items.Items = append(items.Items, item)
  519. }
  520. result.List = append(result.List, items)
  521. /*} else {
  522. for _, v := range dataList {
  523. dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
  524. if err != nil {
  525. errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
  526. return result, err
  527. }
  528. timestamp := dateTime.UnixNano() / 1e6
  529. item := new(EdbDataList)
  530. item.DataTime = dateTime.Format(utils.FormatDate)
  531. item.EdbInfoId = v.EdbInfoId
  532. item.Value = v.Value
  533. item.EdbDataId = v.EdbDataId
  534. item.DataTimestamp = timestamp
  535. items.Items = append(items.Items, item)
  536. }
  537. result.List = append(result.List, items)
  538. }*/
  539. }
  540. }
  541. return
  542. }
  543. type CorrelationInfo struct {
  544. LeadValue int `description:"领先值"`
  545. LeadUnit string `description:"领先单位"`
  546. StartDate string `description:"开始日期"`
  547. EndDate string `description:"结束日期"`
  548. EdbInfoIdFirst int `description:"A指标ID"`
  549. EdbInfoIdSecond int `description:"B指标ID"`
  550. PeriodData string `description:"X轴-期数数据"`
  551. CorrelationData string `description:"Y轴-相关性系数"`
  552. }
  553. type SeasonExtraItem struct {
  554. ChartLegend []SeasonChartLegend `description:"自定义的图例名称"`
  555. XStartDate string `description:"横坐标显示的起始日"`
  556. XEndDate string `description:"横坐标显示的截止日"`
  557. JumpYear int `description:"横坐标日期是否跨年,1跨年,0不跨年"`
  558. }
  559. type SeasonChartLegend struct {
  560. Name string
  561. Value string
  562. }
  563. type QuarterDataList []*QuarterData
  564. func (m QuarterDataList) Len() int {
  565. return len(m)
  566. }
  567. func (m QuarterDataList) Less(i, j int) bool {
  568. return m[i].Years < m[j].Years
  569. }
  570. func (m QuarterDataList) Swap(i, j int) {
  571. m[i], m[j] = m[j], m[i]
  572. }