chart.go 44 KB

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