chart.go 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100
  1. package models
  2. import (
  3. "errors"
  4. "eta/eta_chart_lib/global"
  5. "eta/eta_chart_lib/models/mgo"
  6. "eta/eta_chart_lib/utils"
  7. "fmt"
  8. "gorm.io/gorm"
  9. "strconv"
  10. "time"
  11. "go.mongodb.org/mongo-driver/bson"
  12. "github.com/nosixtools/solarlunar"
  13. )
  14. type ChartInfo struct {
  15. //ChartInfoId int `json:"-" orm:"column(chart_info_id);pk"`
  16. ChartInfoId int `json:"-" gorm:"column:chart_info_id;primaryKey"`
  17. ChartName string `description:"来源名称"`
  18. ChartNameEn string `description:"英文图表名称"`
  19. ChartClassifyId int `json:"-" description:"图表分类id"`
  20. SysUserId int `json:"-"`
  21. SysUserRealName string `json:"-"`
  22. UniqueCode string `description:"图表唯一编码"`
  23. CreateTime time.Time `json:"-"`
  24. ModifyTime time.Time `json:"-"`
  25. DateType int `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间"`
  26. StartDate string `description:"自定义开始日期"`
  27. EndDate string `description:"自定义结束日期"`
  28. IsSetName int `description:"设置名称"`
  29. EdbInfoIds string `description:"指标id"`
  30. ChartType int `description:"生成样式:1:曲线图,2:季节性图"`
  31. Calendar string `description:"公历/农历"`
  32. SeasonStartDate string `description:"季节性图开始日期"`
  33. SeasonEndDate string `description:"季节性图开始日期"`
  34. ChartImage string `description:"图表图片"`
  35. BarConfig string `description:"柱方图的配置,json数据" json:"-"`
  36. XMin string `description:"图表X轴最小值"`
  37. XMax string `description:"图表X轴最大值"`
  38. LeftMin string `description:"图表左侧最小值"`
  39. LeftMax string `description:"图表左侧最大值"`
  40. RightMin string `description:"图表右侧最小值"`
  41. RightMax string `description:"图表右侧最大值"`
  42. Right2Min string `description:"图表右侧2最小值"`
  43. Right2Max string `description:"图表右侧2最大值"`
  44. MinMaxSave int `description:"是否手动保存过上下限:0-否;1-是"`
  45. Source int `description:"1:ETA图库;2:商品价格曲线"`
  46. UnitEn string `description:"英文图表单位"`
  47. Unit string `description:"图表单位"`
  48. ExtraConfig string `description:"图表额外配置,json数据"`
  49. ChartSource string `description:"图表来源str"`
  50. ChartSourceEn string `description:"图表来源(英文)"`
  51. SeasonExtraConfig string `description:"季节性图表中的配置,json数据"`
  52. StartYear int `description:"当选择的日期类型为最近N年类型时,即date_type=20, 用start_year表示N"`
  53. ChartThemeId int `description:"图表应用主题ID"`
  54. ChartThemeStyle string `description:"图表应用主题样式"`
  55. SourcesFrom string `description:"图表来源"`
  56. Instructions string `description:"图表说明"`
  57. MarkersLines string `description:"标识线"`
  58. MarkersAreas string `description:"标识区"`
  59. }
  60. func (m *ChartInfo) ConvertDate() {
  61. m.StartDate = utils.GormDateStrToDateStr(m.StartDate)
  62. m.EndDate = utils.GormDateStrToDateStr(m.EndDate)
  63. m.SeasonStartDate = utils.GormDateStrToDateStr(m.SeasonStartDate)
  64. m.SeasonEndDate = utils.GormDateStrToDateStr(m.SeasonEndDate)
  65. return
  66. }
  67. func GetChartInfoByUniqueCode(uniqueCode string) (item *ChartInfo, err error) {
  68. //o := orm.NewOrmUsingDB("data")
  69. sql := ` SELECT * FROM chart_info WHERE unique_code=? `
  70. //err = o.Raw(sql, uniqueCode).QueryRow(&item)
  71. err = global.DbMap[utils.DbNameIndex].Raw(sql, uniqueCode).First(&item).Error
  72. if err != nil {
  73. item.ConvertDate()
  74. }
  75. return
  76. }
  77. type ChartEdbInfoMapping struct {
  78. EdbInfoId int `description:"指标id"`
  79. SourceName string `description:"来源名称"`
  80. Source int `description:"来源id"`
  81. EdbCode string `description:"指标编码"`
  82. EdbName string `description:"指标名称"`
  83. EdbAliasName string `description:"指标名称(别名)"`
  84. EdbAliasNameEn string `description:"英文指标名称(别名)"`
  85. EdbNameEn string `description:"英文指标名称"`
  86. Frequency string `description:"频率"`
  87. FrequencyEn string `description:"英文频率"`
  88. Unit string `description:"单位"`
  89. UnitEn string `description:"英文单位"`
  90. StartDate string `description:"起始日期"`
  91. EndDate string `description:"终止日期"`
  92. ModifyTime string `description:"指标最后更新时间"`
  93. ChartEdbMappingId int `description:"图表指标id" json:"-"`
  94. ChartInfoId int `description:"图表id"`
  95. MaxData float64 `description:"上限"`
  96. MinData float64 `description:"下限"`
  97. IsOrder bool `description:"true:正序,false:逆序"`
  98. IsAxis int `description:"1:左轴,0:右轴"`
  99. EdbInfoType int `description:"1:标准指标,0:领先指标"`
  100. EdbType int `description:"指标类型:1:基础指标,2:计算指标"`
  101. LeadValue int `description:"领先值"`
  102. LeadUnit string `description:"领先单位"`
  103. LeadUnitEn string `description:"领先英文单位"`
  104. ChartStyle string `description:"图表类型"`
  105. ChartColor string `description:"颜色"`
  106. ChartWidth float64 `description:"线条大小"`
  107. ChartScale float64 `description:"参考刻度线"`
  108. DataList interface{} `gorm:"-"`
  109. EdbInfoCategoryType int `description:"0:普通指标,1:预测指标"`
  110. PredictChartColor string `description:"预测数据的颜色"`
  111. ChartType int `description:"生成样式:1:曲线图,2:季节性图,3:面积图,4:柱状图,5:散点图,6:组合图"`
  112. LatestDate string `description:"数据最新日期"`
  113. LatestValue float64 `description:"数据最新值"`
  114. MoveLatestDate string `description:"移动后的数据最新日期"`
  115. UniqueCode string `description:"指标唯一编码"`
  116. MinValue float64 `json:"-" description:"最小值"`
  117. MaxValue float64 `json:"-" description:"最大值"`
  118. IsNullData bool `json:"-" description:"是否空数据"`
  119. MappingSource int `description:"1:ETA图库;2:商品价格曲线"`
  120. SubSource int `description:"子数据来源:0:经济数据库,1:日期序列"`
  121. SubSourceName string `description:"子数据来源名称"`
  122. IndicatorCode string `description:"指标代码"`
  123. StockCode string `description:"证券代码"`
  124. IsConvert int `description:"是否数据转换 0不转 1转"`
  125. ConvertType int `description:"数据转换类型 1乘 2除 3对数"`
  126. ConvertValue float64 `description:"数据转换值"`
  127. ConvertUnit string `description:"数据转换单位"`
  128. ConvertEnUnit string `description:"数据转换单位"`
  129. ClassifyId int `description:"分类id"`
  130. IsJoinPermission int `description:"是否加入权限管控,0:不加入;1:加入;默认:0"`
  131. }
  132. func (m *ChartEdbInfoMapping) AfterFind(db *gorm.DB) (err error) {
  133. m.StartDate = utils.GormDateStrToDateStr(m.StartDate)
  134. m.EndDate = utils.GormDateStrToDateStr(m.EndDate)
  135. m.LatestDate = utils.GormDateStrToDateStr(m.LatestDate)
  136. m.MoveLatestDate = utils.GormDateStrToDateStr(m.MoveLatestDate)
  137. m.ModifyTime = utils.GormDateStrToDateTimeStr(m.ModifyTime)
  138. return
  139. }
  140. func (m *ChartEdbInfoMapping) ConvertDate() {
  141. m.StartDate = utils.GormDateStrToDateStr(m.StartDate)
  142. m.EndDate = utils.GormDateStrToDateStr(m.EndDate)
  143. m.LatestDate = utils.GormDateStrToDateStr(m.LatestDate)
  144. m.MoveLatestDate = utils.GormDateStrToDateStr(m.MoveLatestDate)
  145. m.ModifyTime = utils.GormDateStrToDateTimeStr(m.ModifyTime)
  146. return
  147. }
  148. func GetChartEdbMappingList(chartInfoId int) (list []*ChartEdbInfoMapping, err error) {
  149. 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,a.chart_scale`
  150. 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,
  151. a.is_convert, a.convert_type, a.convert_value, a.convert_unit, a.convert_en_unit
  152. FROM chart_edb_mapping AS a
  153. INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
  154. WHERE chart_info_id=?
  155. ORDER BY chart_edb_mapping_id ASC `
  156. //_, err = o.Raw(sql, chartInfoId).QueryRows(&list)
  157. err = global.DbMap[utils.DbNameIndex].Raw(sql, chartInfoId).Find(&list).Error
  158. return
  159. }
  160. type EdbDataList struct {
  161. EdbDataId int `json:"-" description:" 指标数据ID"`
  162. EdbInfoId int `json:"-" description:"指标ID"`
  163. DataTime string `description:"数据日期"`
  164. DataTimestamp int64 `description:"数据日期"`
  165. Value float64 `description:"数据值" gorm:"column:value"`
  166. }
  167. func (m *EdbDataList) AfterFind(db *gorm.DB) (err error) {
  168. m.DataTime = utils.GormDateStrToDateStr(m.DataTime)
  169. return
  170. }
  171. // GetEdbDataList 获取指标的数据(日期正序返回)
  172. func GetEdbDataList(source, subSource, edbInfoId int, startDate, endDate string) (list []*EdbDataList, err error) {
  173. // 自有数据需要额外处理(从mongo获取)
  174. if source == utils.DATA_SOURCE_BUSINESS && utils.UseMongo {
  175. return getEdbDataListByMongo(source, subSource, edbInfoId, startDate, endDate)
  176. }
  177. if source == utils.DATA_SOURCE_THS && subSource == utils.DATA_SUB_SOURCE_HIGH_FREQUENCY && utils.UseMongo {
  178. return getThsHfEdbDataListByMongo(source, subSource, edbInfoId, startDate, endDate)
  179. }
  180. return getEdbDataListByMysql(source, subSource, edbInfoId, startDate, endDate)
  181. }
  182. // getEdbDataListByMysql
  183. // @Description: 从mysql中获取指标的数据(日期正序返回)
  184. // @author: Roc
  185. // @datetime 2024-05-08 16:49:48
  186. // @param source int
  187. // @param subSource int
  188. // @param edbInfoId int
  189. // @param startDate string
  190. // @param endDate string
  191. // @return list []*EdbDataList
  192. // @return err error
  193. func getEdbDataListByMysql(source, subSource, edbInfoId int, startDate, endDate string) (list []*EdbDataList, err error) {
  194. tableName := GetEdbDataTableName(source, subSource)
  195. if tableName == "" {
  196. err = errors.New("无效的渠道:" + strconv.Itoa(source))
  197. list = make([]*EdbDataList, 0)
  198. return list, err
  199. }
  200. var pars []interface{}
  201. var condition string
  202. if startDate != "" {
  203. condition += ` AND data_time>=? `
  204. pars = append(pars, startDate)
  205. }
  206. if endDate != "" {
  207. condition += ` AND data_time<=? `
  208. pars = append(pars, endDate)
  209. }
  210. sql := `SELECT edb_data_id,edb_info_id,data_time,value,data_timestamp FROM %s WHERE edb_info_id=? `
  211. if condition != "" {
  212. sql += condition
  213. }
  214. sql += ` ORDER BY data_time ASC `
  215. sql = fmt.Sprintf(sql, tableName)
  216. //o := orm.NewOrmUsingDB("data")
  217. //_, err = o.Raw(sql, edbInfoId, pars).QueryRows(&list)
  218. newPars := utils.ForwardPars(pars, edbInfoId)
  219. pars = append(pars, edbInfoId)
  220. sql = utils.ReplaceDriverKeywords("", sql)
  221. err = global.DbMap[utils.DbNameIndex].Raw(sql, newPars...).Find(&list).Error
  222. return
  223. }
  224. // getEdbDataListByMongo
  225. // @Description: 从mongo中获取指标的数据(日期正序返回)
  226. // @author: Roc
  227. // @datetime 2024-05-08 16:49:59
  228. // @param source int
  229. // @param subSource int
  230. // @param edbInfoId int
  231. // @param startDate string
  232. // @param endDate string
  233. // @return list []*EdbDataList
  234. // @return err error
  235. func getEdbDataListByMongo(source, subSource, edbInfoId int, startDate, endDate string) (list []*EdbDataList, err error) {
  236. list = make([]*EdbDataList, 0)
  237. mogDataObj := mgo.EdbDataBusiness{}
  238. // 构建查询条件
  239. queryConditions := bson.M{
  240. "edb_info_id": edbInfoId,
  241. }
  242. // 日期
  243. dateCondition, err := mgo.BuildDateCondition(startDate, endDate)
  244. if err != nil {
  245. return
  246. }
  247. if len(dateCondition) > 0 {
  248. queryConditions["data_time"] = dateCondition
  249. }
  250. // 获取列表数据
  251. tmpDataList, tmpErr := mogDataObj.GetAllDataList(queryConditions, []string{"data_time"})
  252. if tmpErr != nil {
  253. err = tmpErr
  254. return
  255. }
  256. for k, v := range tmpDataList {
  257. list = append(list, &EdbDataList{
  258. EdbDataId: k + 1,
  259. EdbInfoId: v.EdbInfoId,
  260. DataTime: v.DataTime.Format(utils.FormatDate),
  261. DataTimestamp: v.DataTimestamp,
  262. Value: v.Value,
  263. })
  264. }
  265. return
  266. }
  267. type EdbDataItemList struct {
  268. EdbDataId int `json:"-" description:" 指标数据ID"`
  269. EdbInfoId int `json:"-" description:"指标ID"`
  270. DataTime string `description:"数据日期"`
  271. DataTimestamp int64 `description:"数据日期"`
  272. Value float64 `description:"数据值"`
  273. }
  274. type EdbDataItems struct {
  275. Items []*EdbDataList
  276. Year int
  277. BetweenDay int `json:"-" description:"公历与农历之间相差的天数"`
  278. CuttingDataTimestamp int64 `description:"切割的时间戳"`
  279. }
  280. type EdbDataResult struct {
  281. List []*EdbDataItems
  282. }
  283. type QuarterData struct {
  284. Year string
  285. DataList []*EdbDataList
  286. CuttingDataTimestamp int64 `description:"切割的时间戳"`
  287. ChartLegend string
  288. Years string
  289. }
  290. type QuarterXDateItem struct {
  291. StartDate time.Time
  292. EndDate time.Time
  293. ShowName string
  294. ChartLegend string
  295. CuttingDataTimestamp int64 `description:"切割的时间戳"`
  296. }
  297. type ChartInfoDetailResp struct {
  298. ChartInfo *ChartInfo
  299. EdbInfoList []*ChartEdbInfoMapping
  300. XEdbIdValue []int `description:"柱方图的x轴数据,指标id"`
  301. YDataList []YData `description:"柱方图的y轴数据"`
  302. XDataList []XData `description:"商品价格曲线的X轴数据"`
  303. CorrelationChartInfo *CorrelationInfo `description:"相关性图表信息"`
  304. DataResp interface{} `description:"图表数据,根据图的类型而定的,没有确定的数据格式"`
  305. WaterMark string `description:"水印"`
  306. IsCollect bool `description:"是否收藏"`
  307. IsAuth bool `description:"是否授权"`
  308. }
  309. // XData 商品价格曲线的的x轴数据
  310. type XData struct {
  311. Name string `description:"别名"`
  312. NameEn string `description:"英文别名"`
  313. IsHide int `description:"是否隐藏,0不隐藏,1隐藏"`
  314. }
  315. // YData 柱方图的y轴数据
  316. type YData struct {
  317. Date string `description:"数据日期"`
  318. ConfigDate time.Time `description:"配置的日期" json:"-"`
  319. Color string `description:"数据颜色"`
  320. Name string `description:"别名"`
  321. NameEn string `description:"英文别名"`
  322. Value []float64 `description:"每个指标的值"`
  323. NoDataEdbList []int `description:"没有数据的指标列表"`
  324. XEdbInfoIdList []int `description:"对应X轴的指标id列表"`
  325. EdbValMap map[int]float64 `description:"指标与值的对应" json:"-"`
  326. M []int `description:"对应开始日期的间隔值" json:"-"`
  327. NameList []string `description:"每个值对应的名称"`
  328. EnNameList []string `description:"每个值对应的英文名称"`
  329. Unit string `description:"中文单位名称"`
  330. UnitEn string `description:"英文单位名称"`
  331. SeriesEdb struct {
  332. SeriesId int `description:"因子指标系列ID"`
  333. EdbInfoId int `description:"指标ID"`
  334. } `description:"对应的系列指标"`
  335. }
  336. // RollingCorrelationChartDataResp 滚动相关性图
  337. type RollingCorrelationChartDataResp struct {
  338. XDateTimeValue []string `description:"滚动相关性图的x轴数据,日期数据"`
  339. YDataList []YData `description:"滚动相关性图的y轴数据"`
  340. }
  341. // 指标季度数据计算(公历转农历)
  342. func AddCalculateQuarterV5(dataList []*EdbDataList) (result *EdbDataResult, err error) {
  343. var errMsg string
  344. defer func() {
  345. if errMsg != "" {
  346. fmt.Println("errMsg:", errMsg)
  347. }
  348. }()
  349. if len(dataList) <= 0 {
  350. result.List = make([]*EdbDataItems, 0)
  351. return
  352. }
  353. endDate := dataList[len(dataList)-1].DataTime
  354. endDateForm, err := time.Parse(utils.FormatDate, endDate)
  355. if err != nil {
  356. return result, err
  357. }
  358. thisMonth := int(endDateForm.Month())
  359. result = new(EdbDataResult)
  360. var yearArr []int
  361. yearMap := make(map[int]int)
  362. var cureentDate time.Time
  363. if thisMonth < 11 {
  364. for k, v := range dataList {
  365. dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
  366. if err != nil {
  367. errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
  368. return result, err
  369. }
  370. if k == len(dataList)-1 {
  371. cureentDate = dateTime
  372. }
  373. year := dateTime.Year()
  374. if _, ok := yearMap[year]; !ok {
  375. yearArr = append(yearArr, year)
  376. }
  377. yearMap[year] = year
  378. }
  379. } else {
  380. for k, v := range dataList {
  381. dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
  382. if err != nil {
  383. errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
  384. return result, err
  385. }
  386. if k == len(dataList)-1 {
  387. cureentDate = dateTime
  388. }
  389. year := dateTime.Year() + 1
  390. if _, ok := yearMap[year]; !ok {
  391. yearArr = append(yearArr, year)
  392. }
  393. yearMap[year] = year
  394. }
  395. }
  396. //排序
  397. fmt.Println("yearArr:", yearArr)
  398. thisYear := cureentDate.Year()
  399. //thisMonth := int(cureentDate.Month())
  400. fmt.Println("thisMonth:", thisMonth)
  401. for ky, vy := range yearArr {
  402. fmt.Println("line 432:", ky, vy, thisYear, thisMonth)
  403. if thisMonth < 11 {
  404. currentYearCjnl := strconv.Itoa(thisYear) + "-01-01" //当前年份春节农历
  405. currentYearCjgl := solarlunar.LunarToSolar(currentYearCjnl, false) //当前年份春节公历
  406. currentYearCjglDate, err := time.Parse(utils.FormatDate, currentYearCjgl)
  407. if err != nil {
  408. errMsg = "生成当前春节失败,Err:" + err.Error()
  409. return result, err
  410. }
  411. preYear := vy
  412. preYearCjnl := strconv.Itoa(preYear) + "-01-01" //之前年份春节农历
  413. preYearCjgl := solarlunar.LunarToSolar(preYearCjnl, false) //之前年份春节公历
  414. preYearCjglDate, err := time.Parse(utils.FormatDate, preYearCjgl)
  415. if err != nil {
  416. errMsg = "生成历史年份春节失败,Err:" + err.Error()
  417. return result, err
  418. }
  419. day := currentYearCjglDate.Sub(preYearCjglDate).Hours() / float64(24)
  420. items := new(EdbDataItems)
  421. items.BetweenDay = int(day) //公历日期换算成农历,需要减除的天数
  422. items.Year = preYear
  423. for _, v := range dataList {
  424. dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
  425. if err != nil {
  426. errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
  427. return result, err
  428. }
  429. newDate := dateTime.AddDate(0, 0, int(day))
  430. selectDateStr := strconv.Itoa(thisYear) + "-11" + "-30"
  431. selectDate, _ := time.Parse(utils.FormatDate, selectDateStr)
  432. if newDate.Before(selectDate) || newDate == selectDate {
  433. timestamp := newDate.UnixNano() / 1e6
  434. item := new(EdbDataList)
  435. item.DataTime = newDate.Format(utils.FormatDate)
  436. item.EdbInfoId = v.EdbInfoId
  437. item.Value = v.Value
  438. item.EdbDataId = v.EdbDataId
  439. item.DataTimestamp = timestamp
  440. items.Items = append(items.Items, item)
  441. }
  442. }
  443. result.List = append(result.List, items)
  444. } else {
  445. nextYear := thisYear + 1
  446. nextYearCjnl := strconv.Itoa(nextYear) + "-01-01" //当前年份春节农历
  447. nextYearCjgl := solarlunar.LunarToSolar(nextYearCjnl, false) //当前年份春节公历
  448. nextYearCjglDate, err := time.Parse(utils.FormatDate, nextYearCjgl)
  449. if err != nil {
  450. errMsg = "生成当前春节失败,Err:" + err.Error()
  451. return result, err
  452. }
  453. preYear := vy
  454. preYearCjnl := strconv.Itoa(preYear) + "-01-01" //之前年份春节农历
  455. preYearCjgl := solarlunar.LunarToSolar(preYearCjnl, false) //之前年份春节公历
  456. preYearCjglDate, err := time.Parse(utils.FormatDate, preYearCjgl)
  457. if err != nil {
  458. errMsg = "生成历史年份春节失败,Err:" + err.Error()
  459. return result, err
  460. }
  461. day := nextYearCjglDate.Sub(preYearCjglDate).Hours() / float64(24)
  462. fmt.Println("day:", day, nextYearCjglDate, preYearCjglDate)
  463. items := new(EdbDataItems)
  464. items.BetweenDay = int(day) //公历日期换算成农历,需要减除的天数
  465. items.Year = preYear - 1
  466. fmt.Println("preYear:", preYear, "ky:", ky, "yearArrLen:", len(yearArr))
  467. if ky+1 < len(yearArr) {
  468. for _, v := range dataList {
  469. dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
  470. if err != nil {
  471. errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
  472. return result, err
  473. }
  474. newDate := dateTime.AddDate(0, 0, int(day))
  475. selectDateStr := strconv.Itoa(nextYear) + "-05" + "-31"
  476. selectDate, _ := time.Parse(utils.FormatDate, selectDateStr)
  477. if newDate.Before(selectDate) || newDate == selectDate {
  478. timestamp := newDate.UnixNano() / 1e6
  479. item := new(EdbDataList)
  480. item.DataTime = newDate.Format(utils.FormatDate)
  481. item.EdbInfoId = v.EdbInfoId
  482. item.Value = v.Value
  483. item.EdbDataId = v.EdbDataId
  484. item.DataTimestamp = timestamp
  485. items.Items = append(items.Items, item)
  486. }
  487. }
  488. result.List = append(result.List, items)
  489. } else {
  490. for _, v := range dataList {
  491. dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
  492. if err != nil {
  493. errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
  494. return result, err
  495. }
  496. timestamp := dateTime.UnixNano() / 1e6
  497. item := new(EdbDataList)
  498. item.DataTime = dateTime.Format(utils.FormatDate)
  499. item.EdbInfoId = v.EdbInfoId
  500. item.Value = v.Value
  501. item.EdbDataId = v.EdbDataId
  502. item.DataTimestamp = timestamp
  503. items.Items = append(items.Items, item)
  504. }
  505. result.List = append(result.List, items)
  506. }
  507. }
  508. }
  509. return
  510. }
  511. // AddCalculateQuarterV6 指标季度数据计算(季节性图表)
  512. func AddCalculateQuarterV6(dataList []*EdbDataList) (result *EdbDataResult, err error) {
  513. var errMsg string
  514. defer func() {
  515. if errMsg != "" {
  516. fmt.Println("errMsg:", errMsg)
  517. }
  518. }()
  519. endDate := dataList[len(dataList)-1].DataTime
  520. endDateForm, err := time.Parse(utils.FormatDate, endDate)
  521. if err != nil {
  522. return result, err
  523. }
  524. thisMonth := int(endDateForm.Month())
  525. result = new(EdbDataResult)
  526. var yearArr []int
  527. yearMap := make(map[int]int)
  528. var cureentDate time.Time
  529. if thisMonth < 11 {
  530. for k, v := range dataList {
  531. dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
  532. if err != nil {
  533. errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
  534. return result, err
  535. }
  536. if k == len(dataList)-1 {
  537. cureentDate = dateTime
  538. }
  539. year := dateTime.Year()
  540. if _, ok := yearMap[year]; !ok {
  541. yearArr = append(yearArr, year)
  542. }
  543. yearMap[year] = year
  544. }
  545. } else {
  546. for k, v := range dataList {
  547. dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
  548. if err != nil {
  549. errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
  550. return result, err
  551. }
  552. if k == len(dataList)-1 {
  553. cureentDate = dateTime
  554. }
  555. year := dateTime.Year() + 1
  556. if _, ok := yearMap[year]; !ok {
  557. yearArr = append(yearArr, year)
  558. }
  559. yearMap[year] = year
  560. }
  561. }
  562. //排序
  563. fmt.Println("yearArr:", yearArr)
  564. thisYear := cureentDate.Year()
  565. //thisMonth := int(cureentDate.Month())
  566. fmt.Println("thisMonth:", thisMonth)
  567. for ky, vy := range yearArr {
  568. fmt.Printf("line 432:ky:%d, vy:%d, thisYear:%d, thisMonth:%d", ky, vy, thisYear, thisMonth)
  569. fmt.Println("")
  570. if thisMonth < 11 {
  571. currentYearCjnl := strconv.Itoa(thisYear) + "-01-01" //当前年份春节农历
  572. currentYearCjgl := solarlunar.LunarToSolar(currentYearCjnl, false) //当前年份春节公历
  573. currentYearCjglDate, err := time.Parse(utils.FormatDate, currentYearCjgl)
  574. if err != nil {
  575. errMsg = "生成当前春节失败,Err:" + err.Error()
  576. return result, err
  577. }
  578. preYear := vy
  579. preYearCjnl := strconv.Itoa(preYear) + "-01-01" //之前年份春节农历
  580. preYearCjgl := solarlunar.LunarToSolar(preYearCjnl, false) //之前年份春节公历
  581. preYearCjglDate, err := time.Parse(utils.FormatDate, preYearCjgl)
  582. if err != nil {
  583. errMsg = "生成历史年份春节失败,Err:" + err.Error()
  584. return result, err
  585. }
  586. day := currentYearCjglDate.Sub(preYearCjglDate).Hours() / float64(24)
  587. fmt.Println("day:", day, currentYearCjglDate, preYearCjglDate)
  588. items := new(EdbDataItems)
  589. items.BetweenDay = int(day) //公历日期换算成农历,需要减除的天数
  590. items.Year = preYear
  591. for _, v := range dataList {
  592. dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
  593. if err != nil {
  594. errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
  595. return result, err
  596. }
  597. newDate := dateTime.AddDate(0, 0, int(day))
  598. timestamp := newDate.UnixNano() / 1e6
  599. item := new(EdbDataList)
  600. item.DataTime = newDate.Format(utils.FormatDate)
  601. item.EdbInfoId = v.EdbInfoId
  602. item.Value = v.Value
  603. item.EdbDataId = v.EdbDataId
  604. item.DataTimestamp = timestamp
  605. items.Items = append(items.Items, item)
  606. }
  607. result.List = append(result.List, items)
  608. } else {
  609. nextYear := thisYear + 1
  610. nextYearCjnl := strconv.Itoa(nextYear) + "-01-01" //当前年份春节农历
  611. nextYearCjgl := solarlunar.LunarToSolar(nextYearCjnl, false) //当前年份春节公历
  612. nextYearCjglDate, err := time.Parse(utils.FormatDate, nextYearCjgl)
  613. if err != nil {
  614. errMsg = "生成当前春节失败,Err:" + err.Error()
  615. return result, err
  616. }
  617. preYear := vy
  618. preYearCjnl := strconv.Itoa(preYear) + "-01-01" //之前年份春节农历
  619. preYearCjgl := solarlunar.LunarToSolar(preYearCjnl, false) //之前年份春节公历
  620. preYearCjglDate, err := time.Parse(utils.FormatDate, preYearCjgl)
  621. if err != nil {
  622. errMsg = "生成历史年份春节失败,Err:" + err.Error()
  623. return result, err
  624. }
  625. day := nextYearCjglDate.Sub(preYearCjglDate).Hours() / float64(24)
  626. fmt.Println("day:", day, nextYearCjglDate, preYearCjglDate)
  627. items := new(EdbDataItems)
  628. items.BetweenDay = int(day) //公历日期换算成农历,需要减除的天数
  629. items.Year = preYear
  630. fmt.Println("preYear:", preYear, "ky:", ky, "yearArrLen:", len(yearArr))
  631. //if ky+1 < len(yearArr) {
  632. for _, v := range dataList {
  633. dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
  634. if err != nil {
  635. errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
  636. return result, err
  637. }
  638. newDate := dateTime.AddDate(0, 0, int(day))
  639. timestamp := newDate.UnixNano() / 1e6
  640. item := new(EdbDataList)
  641. item.DataTime = newDate.Format(utils.FormatDate)
  642. item.EdbInfoId = v.EdbInfoId
  643. item.Value = v.Value
  644. item.EdbDataId = v.EdbDataId
  645. item.DataTimestamp = timestamp
  646. items.Items = append(items.Items, item)
  647. }
  648. result.List = append(result.List, items)
  649. /*} else {
  650. for _, v := range dataList {
  651. dateTime, err := time.Parse(utils.FormatDate, v.DataTime)
  652. if err != nil {
  653. errMsg = "time.Parse Err:" + err.Error() + ";DataTime:" + v.DataTime
  654. return result, err
  655. }
  656. timestamp := dateTime.UnixNano() / 1e6
  657. item := new(EdbDataList)
  658. item.DataTime = dateTime.Format(utils.FormatDate)
  659. item.EdbInfoId = v.EdbInfoId
  660. item.Value = v.Value
  661. item.EdbDataId = v.EdbDataId
  662. item.DataTimestamp = timestamp
  663. items.Items = append(items.Items, item)
  664. }
  665. result.List = append(result.List, items)
  666. }*/
  667. }
  668. }
  669. return
  670. }
  671. type CorrelationInfo struct {
  672. LeadValue int `description:"领先值"`
  673. LeadUnit string `description:"领先单位"`
  674. StartDate string `description:"开始日期"`
  675. EndDate string `description:"结束日期"`
  676. EdbInfoIdFirst int `description:"A指标ID"`
  677. EdbInfoIdSecond int `description:"B指标ID"`
  678. PeriodData string `description:"X轴-期数数据"`
  679. CorrelationData string `description:"Y轴-相关性系数"`
  680. AnalysisMode int `description:"分析模式: 0-单因子; 1-多因子"`
  681. }
  682. type SeasonExtraItem struct {
  683. ChartLegend []SeasonChartLegend `description:"自定义的图例名称"`
  684. XStartDate string `description:"横坐标显示的起始日"`
  685. XEndDate string `description:"横坐标显示的截止日"`
  686. JumpYear int `description:"横坐标日期是否跨年,1跨年,0不跨年"`
  687. RightAxis SeasonRightAxis `description:"自定义右轴指标"`
  688. MaxMinLimits MaxMinLimits `description:"自定义同期上下限"`
  689. SamePeriodAverage SamePeriodAverage `description:"自定义同期均线"`
  690. SamePeriodStandardDeviation SamePeriodStandardDeviation `description:"自定义同期标准差"`
  691. }
  692. // 自定义右轴指标
  693. type SeasonRightAxis struct {
  694. IndicatorType int `description:"右轴指标类型 1:左轴指标同比,2:指标库,3:预测指标 "`
  695. Style string `description:"生成样式"`
  696. Shape string `description:"形状"`
  697. ChartColor string `description:"图表颜色"`
  698. Size int `description:"大小"`
  699. Legend string `description:"图例名称"`
  700. NumFormat int `description:"数值格式 1:百分比 2:小数"`
  701. IsConnected int `description:"是否连接 0不连接 1连接"`
  702. LineColor string `description:"线条颜色"`
  703. LineWidth float64 `description:"线条宽度"`
  704. LineStyle string `description:"线条样式"`
  705. IsShow bool `description:"是否显示"`
  706. IsAdd bool `description:"是否添加"`
  707. }
  708. // 自定义同期上下限
  709. type MaxMinLimits struct {
  710. Color string `description:"颜色"`
  711. Year int `description:"上下限取值范围"`
  712. Legend string `description:"图例名称"`
  713. IsShow bool `description:"是否显示"`
  714. IsAdd bool `description:"是否添加"`
  715. }
  716. // 自定义同期均线
  717. type SamePeriodAverage struct {
  718. Color string `description:"颜色"`
  719. Year int `description:"均线取值范围"`
  720. Legend string `description:"图例名称"`
  721. LineType string `description:"线型"`
  722. LineWidth float64 `description:"线宽"`
  723. IsShow bool `description:"是否显示"`
  724. IsAdd bool `description:"是否添加"`
  725. }
  726. // 自定义同期均线
  727. type SamePeriodAverageResp struct {
  728. Color string `description:"颜色"`
  729. Year int `description:"均线取值范围"`
  730. Legend string `description:"图例名称"`
  731. LineType string `description:"线型"`
  732. LineWidth float64 `description:"线宽"`
  733. IsShow bool `description:"是否显示"`
  734. List []*SamePeriodAverageData `description:"自定义均线列表"`
  735. IsAdd bool `description:"是否添加"`
  736. }
  737. type SamePeriodAverageData struct {
  738. DataTime string `description:"数据日期"`
  739. DataTimestamp int64 `description:"数据日期时间戳"`
  740. Value float64 `description:"均值"`
  741. }
  742. // 自定义同期标准差
  743. type SamePeriodStandardDeviation struct {
  744. Color string `description:"颜色"`
  745. Year int `description:"标准差取值范围"`
  746. Legend string `description:"图例名称"`
  747. Multiple float64 `description:"标准差倍数"`
  748. IsShow bool `description:"是否显示"`
  749. IsAdd bool `description:"是否添加"`
  750. }
  751. type SamePeriodStandardDeviationResp struct {
  752. Color string `description:"颜色"`
  753. Year int `description:"标准差取值范围"`
  754. Legend string `description:"图例名称"`
  755. Multiple float64 `description:"标准差倍数"`
  756. IsShow bool `description:"是否显示"`
  757. List []*MaxMinLimitsData `description:"自定义标准差列表"`
  758. IsAdd bool `description:"是否添加"`
  759. }
  760. type SeasonChartResp struct {
  761. MaxMinLimits MaxMinLimitsResp `description:"自定义上下限"`
  762. SamePeriodAverage SamePeriodAverageResp `description:"自定义同期均线"`
  763. SamePeriodStandardDeviation SamePeriodStandardDeviationResp `description:"自定义同期标准差线"`
  764. RightAxis SeasonRightAxisResp `description:"自定义右轴指标"`
  765. }
  766. // 自定义右轴指标
  767. type SeasonRightAxisResp struct {
  768. SeasonRightAxis
  769. EdbInfoList []*ChartEdbInfoMapping
  770. }
  771. type MaxMinLimitsResp struct {
  772. List []*MaxMinLimitsData `description:"自定义上下限列表"`
  773. Color string `description:"颜色"`
  774. Year int `description:"上下限取值范围"`
  775. Legend string `description:"图例名称"`
  776. IsShow bool `description:"是否显示"`
  777. IsAdd bool `description:"是否添加"`
  778. }
  779. type MaxMinLimitsData struct {
  780. DataTime string `description:"数据日期"`
  781. DataTimestamp int64 `description:"数据日期时间戳"`
  782. MaxValue float64 `description:"最大值"`
  783. MinValue float64 `description:"最小值"`
  784. }
  785. type SeasonChartLegend struct {
  786. Name string
  787. Value string
  788. }
  789. type QuarterDataList []*QuarterData
  790. func (m QuarterDataList) Len() int {
  791. return len(m)
  792. }
  793. func (m QuarterDataList) Less(i, j int) bool {
  794. return m[i].Years < m[j].Years
  795. }
  796. func (m QuarterDataList) Swap(i, j int) {
  797. m[i], m[j] = m[j], m[i]
  798. }
  799. type ChartDwCollectReq struct {
  800. UniqueCode string
  801. Token string
  802. }
  803. // 截面组合图额外配置
  804. type ChartSectionExtraConf struct {
  805. DateConfList []*ChartSectionDateConfItem
  806. IsHeap int `description:"是否堆积(1.堆积,0不堆积)"`
  807. XDataList []XData `description:"横轴名称设置"`
  808. UnitList *ChartSectionCombineUnit `description:"纵轴单位设置"`
  809. BaseChartSeriesName string `description:"基准系列名称"`
  810. SortType int `description:"排序类型,0默认,1升序,2降序"`
  811. }
  812. // 截面组合图额外配置
  813. type ChartSectionAllExtraConf struct {
  814. ChartSectionExtraConf
  815. SeriesList []*ChartSectionSeriesItem
  816. }
  817. type ChartSectionDateConfItem struct {
  818. MoveForward int `description:"前移的期数"`
  819. EdbInfoId int `description:"指标ID"`
  820. EdbName string `description:"指标名称"`
  821. EdbNameEn string `description:"指标名称英文"`
  822. EdbInfoType int `description:"指标类型"`
  823. Frequency string `description:"频度"`
  824. EndDate string `description:"最新日期"`
  825. StaticDate string `description:"固定日期"`
  826. DateType int `description:"日期类型:0 指标日期,1系统日期, 2固定日期"`
  827. DateConfName string `description:"引用日期名称"` // 引用日期名称不能重复
  828. DateConfNameEn string `description:"引用日期英文名称"`
  829. DateChange []*ChartSectionDateChange
  830. }
  831. // 截面组合图引用日期配置
  832. type ChartSectionDateChange struct {
  833. Year int
  834. Month int
  835. Day int
  836. Frequency string `description:"频度变换"`
  837. FrequencyDay string `description:"频度的固定日期"`
  838. ChangeType int `description:"日期变换类型1日期位移,2指定频率"`
  839. }
  840. // 截面组合图系列配置
  841. type ChartSectionSeriesItem struct {
  842. ChartSeriesId int `description:"系列ID"`
  843. SeriesName string `description:"系列名称"` //系列名称不可同名
  844. SeriesNameEn string `description:"系列英文名称"`
  845. ChartStyle string `description:"图表类型"`
  846. ChartColor string `description:"颜色"`
  847. ChartWidth int `description:"线条大小"`
  848. IsPoint int `description:"是否用数据点展示(0 否,1是)"`
  849. IsNumber int `description:"是否用数值展示(0 否,1是)"`
  850. IsAxis int `description:"1:左轴,0:右轴"`
  851. MaxData float64 `description:"上限"`
  852. MinData float64 `description:"下限"`
  853. //IsOrder bool `description:"true:正序,false:逆序"`
  854. EdbInfoList []*ChartSectionSeriesEdbConf
  855. DataList []float64
  856. NoDataEdbIndex []int
  857. }
  858. type ChartSectionSeriesEdbConf struct {
  859. ChartSeriesEdbMappingId int `description:"映射ID"`
  860. ChartSeriesId int `description:"系列ID"`
  861. //ChartInfoId int `description:"图表ID"`
  862. EdbInfoId int `description:"指标id"`
  863. DateConf *ChartSectionSeriesDateConfItem
  864. EdbName string `description:"中文别名"`
  865. EdbNameEn string `description:"英文别名"`
  866. EdbInfoType int `description:"指标类型"`
  867. Unit string `description:"单位"`
  868. UnitEn string `description:"英文单位"`
  869. DateConfName string `description:"引用日期名称"`
  870. DateConfType int `description:"日期类型,0指标最新日期, 1引用日期"`
  871. }
  872. type ChartSectionCombineDataResp struct {
  873. DateConfList []*ChartSectionDateConfItem
  874. IsHeap int `description:"是否堆积(1.堆积,0不堆积)"`
  875. XDataList []XData `description:"横轴名称设置"`
  876. UnitList *ChartSectionCombineUnit `description:"纵轴单位设置"`
  877. BaseChartSeriesName string `description:"基准系列名称"`
  878. SortType int `description:"排序类型,0默认,1升序,2降序"`
  879. SeriesList []*ChartSectionSeriesItem
  880. LeftMin string `description:"图表左侧最小值"`
  881. LeftMax string `description:"图表左侧最大值"`
  882. RightMin string `description:"图表右侧最小值"`
  883. RightMax string `description:"图表右侧最大值"`
  884. Right2Min string `description:"图表右侧最小值"`
  885. Right2Max string `description:"图表右侧最大值"`
  886. }
  887. // 系列里的指标日期配置
  888. type ChartSectionSeriesDateConfItem struct {
  889. MoveForward int `description:"前移的期数"`
  890. DateChange []*ChartSectionDateChange
  891. }
  892. // PreviewSectionCombineChartReq 预览截面组合图的请求
  893. type PreviewSectionCombineChartReq struct {
  894. ChartName string `description:"图表名称"`
  895. ChartClassifyId int `description:"分类id"`
  896. ExtraConfig string `description:"图表额外配置信息,json字符串"`
  897. }
  898. type ChartSectionCombineUnit struct {
  899. LeftName string `description:"左轴单位"`
  900. LeftNameEn string `description:"左轴英文单位"`
  901. RightName string `description:"右轴单位"`
  902. RightNameEn string `description:"右轴英文单位"`
  903. RightTwoName string `description:"右2轴单位"`
  904. RightTwoNameEn string `description:"右2轴英文单位"`
  905. }
  906. // 时序组合图额外配置
  907. type ChartTimeCombineExtraConf struct {
  908. IsHeap int `description:"是否堆积(1.堆积,0不堆积)"`
  909. }
  910. type ChartTimeCombineDataResp struct {
  911. IsHeap int `description:"是否堆积(1.堆积,0不堆积)"`
  912. }
  913. func GetChartInfoById(chartInfoId int) (item *ChartInfo, err error) {
  914. //o := orm.NewOrmUsingDB("data")
  915. sql := ` SELECT * FROM chart_info WHERE chart_info_id=? `
  916. //err = o.Raw(sql, chartInfoId).QueryRow(&item)
  917. err = global.DbMap[utils.DbNameIndex].Raw(sql, chartInfoId).First(&item).Error
  918. if err != nil {
  919. item.ConvertDate()
  920. }
  921. return
  922. }
  923. type MarkersLine struct {
  924. Axis int `json:"axis" description:"1左轴 2右轴 3横轴"`
  925. AxisName string `json:"axisName" description:"轴的名称,例如'左轴'"`
  926. MarkerType string `json:"markerType" description:"标识线或标识区"`
  927. MarkLineType int `json:"markLineType" description:"1:固定 2:指标计算"`
  928. Value string `json:"value" description:"连线指向的数值,例如'4000'"`
  929. FromValue string `json:"fromValue" description:"连线的起始点,可以为空"`
  930. ToValue string `json:"toValue" description:"连线的结束点,可以为空"`
  931. LineWidth float64 `json:"lineWidth" description:"连线的宽度"`
  932. DashStyle string `json:"dashStyle" description:"连线的虚线样式,例如'ShortDashDot'"`
  933. Color string `json:"color" description:"连线的颜色"`
  934. Text string `json:"text" description:"连线旁边显示的文本"`
  935. TextPosition string `json:"textPosition" description:"文本的显示位置,例如'bottom'"`
  936. TextColor string `json:"textColor" description:"文本颜色"`
  937. TextFontSize int `json:"textFontSize" description:"文本的字号大小"`
  938. IsShow bool `json:"isShow" description:"是否显示连线及文本"`
  939. EdbType int `json:"edbType" description:"指标类型 0图中第一个指标 1其他指标 前端回显用"`
  940. EdbInfoId int `json:"edbInfoId" description:"指标id"`
  941. Calculation int `json:"calculation" description:"计算方式 1区间均值 2区间均值加N倍标准差 3区间个数分位 4区间数值分位"`
  942. CalculationValue int `json:"calculationValue" description:"计算方式对应的值 2就是几倍标准差 3就是分位值 4就是数值值·"`
  943. TimeIntervalType int `json:"timeInterval" description:"时间区间 0跟随图表 1自定义"`
  944. StartDate MarkersLineTime `json:"startTime" description:"开始时间"`
  945. EndDate MarkersLineTime `json:"endTime" description:"结束时间"`
  946. }
  947. type MarkersLineTime struct {
  948. TimeType int `json:"timeType" description:"时间类型 1固定 2动态 3至今(仅结束时间)"`
  949. Date string `json:"date" description:"日期"`
  950. Conf EdbDateChangeConf `json:"conf" description:"动态时间配置"`
  951. }
  952. // EdbDateExtraConf
  953. // @Description: 导入指标日期前移和日期变换
  954. type EdbDateChangeConf struct {
  955. MoveForward int `json:"moveForward" description:"前移的期数"`
  956. BaseDate int `json:"baseDate" description:"基准日期 0系统日期 1指标最新日期"`
  957. DateChange []*EdbDateConfDateChange
  958. }
  959. type EdbDateConfDateChange struct {
  960. Year int `json:"year" description:"前移的期数"`
  961. Month int `json:"month" description:"前移的期数"`
  962. Day int `json:"day" description:"前移的期数"`
  963. Frequency string `json:"moveForward" description:"频度变换"`
  964. FrequencyDay string `json:"frequencyDay" description:"频度的固定日期"`
  965. ChangeType int `json:"changeType" description:"日期变换类型1日期位移,2指定频率"`
  966. }
  967. func getThsHfEdbDataListByMongo(source, subSource, edbInfoId int, startDate, endDate string) (list []*EdbDataList, err error) {
  968. list = make([]*EdbDataList, 0)
  969. mogDataObj := mgo.EdbDataThsHf{}
  970. // 构建查询条件
  971. queryConditions := bson.M{
  972. "edb_info_id": edbInfoId,
  973. }
  974. // 数据日期
  975. dateCondition, err := mgo.BuildDateCondition(startDate, endDate)
  976. if err != nil {
  977. return
  978. }
  979. if len(dateCondition) > 0 {
  980. queryConditions["data_time"] = dateCondition
  981. }
  982. // 获取列表数据
  983. tmpDataList, tmpErr := mogDataObj.GetAllDataList(queryConditions, []string{"data_time"})
  984. if tmpErr != nil {
  985. err = tmpErr
  986. return
  987. }
  988. for k, v := range tmpDataList {
  989. list = append(list, &EdbDataList{
  990. EdbDataId: k + 1,
  991. EdbInfoId: v.EdbInfoId,
  992. DataTime: v.DataTime.Format(utils.FormatDate),
  993. DataTimestamp: v.DataTimestamp,
  994. Value: v.Value,
  995. })
  996. }
  997. return
  998. }
  999. func GetChartEdbMappingsByChartInfoId(chartInfoId int) (list []*ChartEdbInfoMapping, err error) {
  1000. sql := ` SELECT * FROM chart_edb_mapping AS a WHERE chart_info_id = ? ORDER BY chart_edb_mapping_id ASC`
  1001. err = global.DbMap[utils.DbNameIndex].Raw(sql, chartInfoId).Find(&list).Error
  1002. return
  1003. }