chart_info.go 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990
  1. package data_manage
  2. import (
  3. "errors"
  4. "eta/eta_api/utils"
  5. "fmt"
  6. "github.com/beego/beego/v2/client/orm"
  7. "github.com/rdlucklib/rdluck_tools/paging"
  8. "strconv"
  9. "strings"
  10. "time"
  11. )
  12. type ChartInfo struct {
  13. ChartInfoId int `orm:"column(chart_info_id);pk"`
  14. ChartName string `description:"来源名称"`
  15. ChartNameEn string `description:"英文图表名称"`
  16. ChartClassifyId int `description:"图表分类id"`
  17. SysUserId int
  18. SysUserRealName string
  19. UniqueCode string `description:"图表唯一编码"`
  20. CreateTime time.Time
  21. ModifyTime time.Time
  22. DateType int `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间"`
  23. StartDate string `description:"自定义开始日期"`
  24. EndDate string `description:"自定义结束日期"`
  25. IsSetName int `description:"设置名称"`
  26. EdbInfoIds string `description:"指标id"`
  27. ChartType int `description:"生成样式:1:曲线图,2:季节性图,3:面积图,4:柱状图,5:散点图,6:组合图,7:柱方图,8:商品价格曲线图,9:相关性图,10:截面散点图, 11:雷达图"`
  28. Calendar string `description:"公历/农历"`
  29. SeasonStartDate string `description:"季节性图开始日期"`
  30. SeasonEndDate string `description:"季节性图开始日期"`
  31. ChartImage string `description:"图表图片"`
  32. Sort int `description:"排序字段,数字越小越排前面"`
  33. LeftMin string `description:"图表左侧最小值"`
  34. LeftMax string `description:"图表左侧最大值"`
  35. RightMin string `description:"图表右侧最小值"`
  36. RightMax string `description:"图表右侧最大值"`
  37. Right2Min string `description:"图表右侧2最小值"`
  38. Right2Max string `description:"图表右侧2最大值"`
  39. MinMaxSave int `description:"是否手动保存过上下限:0-否;1-是"`
  40. Disabled int `description:"是否禁用,0:启用,1:禁用,默认:0"`
  41. BarConfig string `description:"柱方图的配置,json数据"`
  42. Source int `description:"1:ETA图库;2:商品价格曲线"`
  43. ExtraConfig string `description:"图表额外配置,json数据"`
  44. SeasonExtraConfig string `description:"季节性图表中的配置,json数据"`
  45. StartYear int `description:"当选择的日期类型为最近N年类型时,即date_type=20, 用start_year表示N"`
  46. ChartThemeId int `description:"图表应用主题ID"`
  47. SourcesFrom string `description:"图表来源"`
  48. Instructions string `description:"图表说明"`
  49. MarkersLines string `description:"标识线"`
  50. MarkersAreas string `description:"标识区"`
  51. Unit string `description:"中文单位名称"`
  52. UnitEn string `description:"英文单位名称"`
  53. }
  54. type ChartInfoMore struct {
  55. ChartInfo
  56. IsEnChart bool `description:"是否展示英文标识"`
  57. }
  58. func AddChartInfo(item *ChartInfo) (lastId int64, err error) {
  59. o := orm.NewOrmUsingDB("data")
  60. lastId, err = o.Insert(item)
  61. return
  62. }
  63. type ChartInfoItem struct {
  64. ChartInfoId int `description:"图表id"`
  65. ChartName string `description:"图表名称"`
  66. ChartClassifyId int `description:"图表分类"`
  67. }
  68. // GetChartInfoAll 用于分类展示
  69. // @param source int 1:ETA图库;2:商品价格曲线
  70. func GetChartInfoAll(sourceList []int) (items []*ChartClassifyItems, err error) {
  71. num := len(sourceList)
  72. if num <= 0 {
  73. return
  74. }
  75. o := orm.NewOrmUsingDB("data")
  76. sql := ` SELECT chart_info_id,chart_classify_id,chart_name AS chart_classify_name,
  77. unique_code,sys_user_id,sys_user_real_name,date_type,start_date,end_date,chart_type,calendar,season_start_date,season_end_date,source
  78. FROM chart_info WHERE source in (` + utils.GetOrmInReplace(num) + `) ORDER BY sort asc,chart_info_id ASC `
  79. _, err = o.Raw(sql, sourceList).QueryRows(&items)
  80. return
  81. }
  82. // GetChartInfoByAdminId 获取所有我创建的图表,用于分类展示
  83. func GetChartInfoByAdminId(sourceList []int, adminId int) (items []*ChartClassifyItems, err error) {
  84. num := len(sourceList)
  85. if num <= 0 {
  86. return
  87. }
  88. o := orm.NewOrmUsingDB("data")
  89. sql := ` SELECT chart_info_id,chart_classify_id,chart_name AS chart_classify_name,
  90. unique_code,sys_user_id,sys_user_real_name,date_type,start_date,end_date,chart_type,calendar,season_start_date,season_end_date
  91. FROM chart_info where source in (` + utils.GetOrmInReplace(num) + `) AND sys_user_id = ? ORDER BY sort asc,create_time ASC `
  92. _, err = o.Raw(sql, sourceList, adminId).QueryRows(&items)
  93. return
  94. }
  95. // 用于分类展示
  96. func GetChartInfoAllList() (items []*ChartInfo, err error) {
  97. o := orm.NewOrmUsingDB("data")
  98. sql := ` SELECT *
  99. FROM chart_info ORDER BY create_time ASC `
  100. _, err = o.Raw(sql).QueryRows(&items)
  101. return
  102. }
  103. // 图表检索数据
  104. type ChartInfoSearch struct {
  105. EdbCode string `description:"图表编码"`
  106. StartDate string `description:"起始日期"`
  107. EndDate string `description:"终止日期"`
  108. DataList []*EdbInfoSearchData
  109. }
  110. type ChartInfoSearchData struct {
  111. DataTime string `description:"数据日期"`
  112. Value float64 `description:"数据"`
  113. }
  114. type ChartInfoSearchResp struct {
  115. SearchItem *EdbInfoSearch `description:"图表分类"`
  116. Status int `description:"1:数据已存在于弘则数据库,2:新数据"`
  117. }
  118. func GetChartInfoById(chartInfoId int) (item *ChartInfo, err error) {
  119. o := orm.NewOrmUsingDB("data")
  120. sql := ` SELECT * FROM chart_info WHERE chart_info_id=? `
  121. err = o.Raw(sql, chartInfoId).QueryRow(&item)
  122. return
  123. }
  124. func GetChartInfoViewById(chartInfoId int) (item *ChartInfoView, err error) {
  125. o := orm.NewOrmUsingDB("data")
  126. sql := ` SELECT * FROM chart_info WHERE chart_info_id=? `
  127. err = o.Raw(sql, chartInfoId).QueryRow(&item)
  128. return
  129. }
  130. func GetChartInfoViewByIds(chartInfoIds []string) (list []*ChartInfoView, err error) {
  131. o := orm.NewOrmUsingDB("data")
  132. sql := ` SELECT * FROM chart_info WHERE chart_info_id in ("` + strings.Join(chartInfoIds, `","`) + `") `
  133. _, err = o.Raw(sql).QueryRows(&list)
  134. return
  135. }
  136. type SaveChartInfoReq struct {
  137. ChartEdbInfoList []*ChartSaveItem `description:"指标及配置信息"`
  138. ChartInfoId int `description:"图表id,新增时传0"`
  139. DateType int `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:起始日期至今"`
  140. StartDate string `description:"自定义开始日期"`
  141. EndDate string `description:"自定义结束日期"`
  142. Calendar string `description:"公历/农历"`
  143. LeftMin string `description:"图表左侧最小值"`
  144. LeftMax string `description:"图表左侧最大值"`
  145. RightMin string `description:"图表右侧最小值"`
  146. RightMax string `description:"图表右侧最大值"`
  147. Right2Min string `description:"图表右侧最小值"`
  148. Right2Max string `description:"图表右侧最大值"`
  149. MinMaxSave int `description:"是否手动保存过上下限:0-否;1-是"`
  150. ExtraConfig string `description:"图表额外配置,json数据"`
  151. StartYear int `description:"当选择的日期类型为最近N年类型时,即date_type=20, 用start_year表示N"`
  152. }
  153. type ChartSaveItem struct {
  154. EdbInfoId int `description:"指标id"`
  155. MaxData float64 `description:"上限"`
  156. MinData float64 `description:"下限"`
  157. IsOrder bool `description:"true:正序,false:逆序"`
  158. IsAxis int `description:"1:左轴,0:右轴"`
  159. EdbInfoType int `description:"1:标准指标,0:领先指标"`
  160. LeadValue int `description:"领先值"`
  161. LeadUnit string `description:"领先单位"`
  162. ChartStyle string `description:"图表类型"`
  163. ChartColor string `description:"颜色"`
  164. PredictChartColor string `description:"预测数据的颜色"`
  165. ChartWidth float64 `description:"线条大小"`
  166. Source int `description:"1:ETA图库;2:商品价格曲线"`
  167. EdbAliasName string `description:"中文别名"`
  168. }
  169. func DeleteChartInfoAndData(chartInfoId int) (err error) {
  170. o := orm.NewOrmUsingDB("data")
  171. to, err := o.Begin()
  172. if err != nil {
  173. return
  174. }
  175. defer func() {
  176. if err != nil {
  177. _ = to.Rollback()
  178. } else {
  179. _ = to.Commit()
  180. }
  181. }()
  182. sql := ` DELETE FROM chart_info WHERE chart_info_id=? `
  183. _, err = to.Raw(sql, chartInfoId).Exec()
  184. if err != nil {
  185. return
  186. }
  187. sql = ` DELETE FROM chart_edb_mapping WHERE chart_info_id=? `
  188. _, err = to.Raw(sql, chartInfoId).Exec()
  189. return
  190. }
  191. func GetChartInfoCountByCondition(condition string, pars []interface{}) (count int, err error) {
  192. o := orm.NewOrmUsingDB("data")
  193. sql := ` SELECT COUNT(1) AS count FROM chart_info WHERE 1=1 `
  194. if condition != "" {
  195. sql += condition
  196. }
  197. err = o.Raw(sql, pars).QueryRow(&count)
  198. return
  199. }
  200. type EditChartInfoReq struct {
  201. ChartInfoId int `description:"图表ID"`
  202. ChartName string `description:"图表名称"`
  203. ChartClassifyId int `description:"分类id"`
  204. ChartEdbInfoList []*ChartSaveItem `description:"指标及配置信息"`
  205. ChartType int `description:"生成样式:1:曲线图,2:季节性图,3:面积图,4:柱状图,5:散点图,6:组合图,7:柱方图,8:商品价格曲线图,9:相关性图,10:截面散点图"`
  206. DateType int `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:起始日期至今,20:N年至今"`
  207. StartDate string `description:"自定义开始日期"`
  208. EndDate string `description:"自定义结束日期"`
  209. Calendar string `description:"公历/农历"`
  210. LeftMin string `description:"图表左侧最小值"`
  211. LeftMax string `description:"图表左侧最大值"`
  212. RightMin string `description:"图表右侧最小值"`
  213. RightMax string `description:"图表右侧最大值"`
  214. Right2Min string `description:"图表右侧最小值"`
  215. Right2Max string `description:"图表右侧最大值"`
  216. BarChartInfo BarChartInfoReq `description:"柱方图的配置"`
  217. CorrelationChartInfo CorrelationChartInfoReq `description:"相关性图表配置"`
  218. ExtraConfig string `description:"图表额外配置信息,json字符串"`
  219. SeasonExtraConfig SeasonExtraItem `description:"季节性图表中的配置,json数据"`
  220. StartYear int `description:"当选择的日期类型为最近N年类型时,即date_type=20, 用start_year表示N"`
  221. ChartThemeId int `description:"图表应用主题ID"`
  222. SourcesFrom string `description:"图表来源"`
  223. Instructions string `description:"图表说明"`
  224. MarkersLines string `description:"标识线"`
  225. MarkersAreas string `description:"标识区"`
  226. Unit string `description:"中文单位名称"`
  227. UnitEn string `description:"英文单位名称"`
  228. }
  229. type EditChartEnInfoReq struct {
  230. ChartInfoId int `description:"图表ID"`
  231. ChartNameEn string `description:"英文图表名称"`
  232. ChartEdbInfoList []*EditChartEnInfoEdbItem `description:"指标及配置信息"`
  233. ExtraConfig string `description:"图表额外配置信息,json字符串"`
  234. }
  235. type EditChartEnInfoEdbItem struct {
  236. EdbInfoId int `description:"指标ID"`
  237. EdbNameEn string `description:"英文指标名称"`
  238. UnitEn string `description:"英文单位"`
  239. }
  240. func ModifyChartInfo(item *EditChartInfoReq) (err error) {
  241. o := orm.NewOrmUsingDB("data")
  242. sql := ` UPDATE chart_info
  243. SET
  244. chart_name =?,
  245. chart_classify_id = ?,
  246. is_set_name=1,
  247. modify_time = NOW()
  248. WHERE chart_info_id = ?`
  249. _, err = o.Raw(sql, item.ChartName, item.ChartClassifyId, item.ChartInfoId).Exec()
  250. return
  251. }
  252. type ChartInfoList struct {
  253. ChartInfoId int `orm:"column(chart_info_id);pk"`
  254. ChartName string `description:"来源名称"`
  255. ChartChartClassifyId int `description:"图表分类id"`
  256. SysUserId int
  257. SysUserRealName string
  258. UniqueCode string `description:"图表唯一编码"`
  259. CreateTime time.Time
  260. ModifyTime time.Time
  261. EdbInfoList []*EdbInfoList
  262. }
  263. type ChartInfoListResp struct {
  264. Paging *paging.PagingItem
  265. Item *ChartInfoList
  266. }
  267. func GetChartInfoByCondition(condition string, pars []interface{}) (item *ChartInfo, err error) {
  268. o := orm.NewOrmUsingDB("data")
  269. sql := ` SELECT * FROM chart_info WHERE 1=1 `
  270. if condition != "" {
  271. sql += condition
  272. }
  273. err = o.Raw(sql, pars).QueryRow(&item)
  274. return
  275. }
  276. func GetChartInfoByNewest(source int) (item *ChartInfoList, err error) {
  277. o := orm.NewOrmUsingDB("data")
  278. sql := ` SELECT * FROM chart_info WHERE 1=1 AND source = ? ORDER BY modify_time DESC LIMIT 1 `
  279. err = o.Raw(sql, source).QueryRow(&item)
  280. return
  281. }
  282. func ModifyChartInfoModifyTime(chartInfoId int64) (err error) {
  283. o := orm.NewOrmUsingDB("data")
  284. sql := ` UPDATE chart_info SET modify_time = NOW() WHERE chart_info_id = ? `
  285. _, err = o.Raw(sql, chartInfoId).Exec()
  286. return
  287. }
  288. type MoveChartInfoReq struct {
  289. ChartInfoId int `description:"图表ID"`
  290. PrevChartInfoId int `description:"上一个图表ID"`
  291. NextChartInfoId int `description:"下一个图表ID"`
  292. ChartClassifyId int `description:"分类id"`
  293. }
  294. func MoveChartInfo(chartInfoId, classifyId int) (err error) {
  295. o := orm.NewOrmUsingDB("data")
  296. sql := ` UPDATE chart_info
  297. SET
  298. chart_classify_id = ?
  299. WHERE chart_info_id = ?`
  300. _, err = o.Raw(sql, classifyId, chartInfoId).Exec()
  301. return
  302. }
  303. type DeleteChartInfoReq struct {
  304. ChartInfoId int `description:"图表ID"`
  305. }
  306. type EdbDataList struct {
  307. EdbDataId int `description:" 指标数据ID"`
  308. EdbInfoId int `description:"指标ID"`
  309. DataTime string //`json:"-" description:"数据日期"`
  310. DataTimestamp int64 `description:"数据日期"`
  311. Value float64 `description:"数据值"`
  312. }
  313. // GetEdbDataList 获取指标的数据(日期正序返回)
  314. func GetEdbDataList(source, subSource, endInfoId int, startDate, endDate string) (list []*EdbDataList, err error) {
  315. tableName := GetEdbDataTableName(source, subSource)
  316. if tableName == "" {
  317. err = errors.New("无效的渠道:" + strconv.Itoa(source))
  318. list = make([]*EdbDataList, 0)
  319. return list, err
  320. }
  321. var pars []interface{}
  322. sql := `SELECT edb_data_id,edb_info_id,data_time,value,data_timestamp FROM %s WHERE edb_info_id=? `
  323. if startDate != "" {
  324. sql += ` AND data_time>=? `
  325. pars = append(pars, startDate)
  326. }
  327. if endDate != "" {
  328. sql += ` AND data_time<=? `
  329. pars = append(pars, endDate)
  330. }
  331. sql += ` ORDER BY data_time ASC `
  332. sql = fmt.Sprintf(sql, tableName)
  333. o := orm.NewOrmUsingDB("data")
  334. _, err = o.Raw(sql, endInfoId, pars).QueryRows(&list)
  335. return
  336. }
  337. type EdbDataListByUniqueCode struct {
  338. EdbDataId int `description:" 指标数据ID" json:"-"`
  339. EdbInfoId int `description:"指标ID" json:"-"`
  340. DataTime string //`json:"-" description:"数据日期"`
  341. DataTimestamp int64 `description:"数据日期"`
  342. Value float64 `description:"数据值"`
  343. }
  344. func GetEdbDataListByByUniqueCode(source, subSource, endInfoId int, startDate, endDate string) (list []*EdbDataListByUniqueCode, err error) {
  345. tableName := GetEdbDataTableName(source, subSource)
  346. if tableName == "" {
  347. err = errors.New("无效的渠道:" + strconv.Itoa(source))
  348. list = make([]*EdbDataListByUniqueCode, 0)
  349. return list, err
  350. }
  351. var pars []interface{}
  352. sql := `SELECT edb_data_id,edb_info_id,data_time,value,data_timestamp FROM %s WHERE edb_info_id=? `
  353. if startDate != "" {
  354. sql += ` AND data_time>=? `
  355. pars = append(pars, startDate)
  356. }
  357. if endDate != "" {
  358. sql += ` AND data_time<=? `
  359. pars = append(pars, endDate)
  360. }
  361. sql += ` ORDER BY data_time ASC `
  362. sql = fmt.Sprintf(sql, tableName)
  363. o := orm.NewOrmUsingDB("data")
  364. _, err = o.Raw(sql, endInfoId, pars).QueryRows(&list)
  365. return
  366. }
  367. func GetEdbDataLunarList(endInfoId int, startDate, endDate string) (list []*EdbDataList, err error) {
  368. tableName := "edb_data_quarter"
  369. sql := `SELECT edb_data_id,edb_info_id,data_time,TRUNCATE(value,2) AS value,data_timestamp FROM %s WHERE edb_info_id=? AND data_time>=? AND data_time<=? ORDER BY data_time ASC `
  370. sql = fmt.Sprintf(sql, tableName)
  371. o := orm.NewOrmUsingDB("data")
  372. _, err = o.Raw(sql, endInfoId, startDate, endDate).QueryRows(&list)
  373. return
  374. }
  375. func GetEdbDataListMinAndMax(source, subSource, endInfoId int, startDate, endDate string) (min_data, max_data float64, err error) {
  376. tableName := GetEdbDataTableName(source, subSource)
  377. sql := `SELECT min(value) AS min_data,max(value) AS max_data FROM %s WHERE edb_info_id=? `
  378. var pars []interface{}
  379. var condition string
  380. if startDate != "" {
  381. condition += ` AND data_time>=? `
  382. pars = append(pars, startDate)
  383. }
  384. if endDate != "" {
  385. condition += ` AND data_time<=? `
  386. pars = append(pars, endDate)
  387. }
  388. sql = fmt.Sprintf(sql, tableName)
  389. o := orm.NewOrmUsingDB("data")
  390. if condition != "" {
  391. sql += condition
  392. }
  393. err = o.Raw(sql, endInfoId, pars).QueryRow(&min_data, &max_data)
  394. return
  395. }
  396. type ChartEdbInfoMapping struct {
  397. EdbInfoId int `description:"指标id"`
  398. SourceName string `description:"来源名称"`
  399. Source int `description:"来源id"`
  400. SubSource int `description:"来源id"`
  401. EdbCode string `description:"指标编码"`
  402. EdbName string `description:"指标名称"`
  403. EdbAliasName string `description:"指标名称(别名)"`
  404. EdbNameEn string `description:"英文指标名称"`
  405. EdbAliasNameEn string `description:"英文指标名称(别名)"`
  406. EdbType int `description:"指标类型:1:基础指标,2:计算指标"`
  407. Frequency string `description:"频率"`
  408. FrequencyEn string `description:"英文频率"`
  409. Unit string `description:"单位"`
  410. UnitEn string `description:"英文单位"`
  411. StartDate string `description:"起始日期"`
  412. EndDate string `description:"终止日期"`
  413. ModifyTime string `description:"指标最后更新时间"`
  414. ChartEdbMappingId int `description:"图表指标id"`
  415. ChartInfoId int `description:"图表id"`
  416. MaxData float64 `description:"上限"`
  417. MinData float64 `description:"下限"`
  418. IsOrder bool `description:"true:正序,false:逆序"`
  419. IsAxis int `description:"1:左轴,0:右轴"`
  420. EdbInfoType int `description:"1:标准指标,0:领先指标"`
  421. EdbInfoCategoryType int `description:"0:普通指标,1:预测指标"`
  422. LeadValue int `description:"领先值"`
  423. LeadUnit string `description:"领先单位"`
  424. LeadUnitEn string `description:"领先英文单位"`
  425. ChartStyle string `description:"图表类型"`
  426. ChartColor string `description:"颜色"`
  427. PredictChartColor string `description:"预测数据的颜色"`
  428. ChartWidth float64 `description:"线条大小"`
  429. ChartType int `description:"生成样式:1:曲线图,2:季节性图,3:面积图,4:柱状图,5:散点图,6:组合图,7:柱方图,8:商品价格曲线图,9:相关性图"`
  430. LatestDate string `description:"数据最新日期"`
  431. LatestValue float64 `description:"数据最新值"`
  432. MoveLatestDate string `description:"移动后的数据最新日期"`
  433. UniqueCode string `description:"指标唯一编码"`
  434. MinValue float64 `json:"-" description:"最小值"`
  435. MaxValue float64 `json:"-" description:"最大值"`
  436. DataList interface{}
  437. IsNullData bool `json:"-" description:"是否空数据"`
  438. MappingSource int `description:"1:ETA图库;2:商品价格曲线"`
  439. RegionType string `description:"交易所来源,海外还是国内" json:"-"`
  440. ClassifyId int `description:"分类id"`
  441. IsConvert int `description:"是否数据转换 0不转 1转"`
  442. ConvertType int `description:"数据转换类型 1乘 2除 3对数"`
  443. ConvertValue float64 `description:"数据转换值"`
  444. ConvertUnit string `description:"数据转换单位"`
  445. ConvertEnUnit string `description:"数据转换单位"`
  446. }
  447. type QuarterData struct {
  448. Year int
  449. DataList []*EdbDataList
  450. CuttingDataTimestamp int64 `description:"切割的时间戳"`
  451. ChartLegend string
  452. Years string
  453. }
  454. type QuarterXDateItem struct {
  455. StartDate time.Time
  456. EndDate time.Time
  457. ShowName string
  458. ChartLegend string
  459. CuttingDataTimestamp int64 `description:"切割的时间戳"`
  460. }
  461. type QuarterDataByUniqueCode struct {
  462. Year int
  463. DataList []*EdbDataListByUniqueCode
  464. }
  465. type ChartEdbInfoDetailResp struct {
  466. EdbInfo *ChartEdbInfoMapping
  467. }
  468. type ChartInfoDetailResp struct {
  469. ChartInfo *ChartInfoView
  470. EdbInfoList []*ChartEdbInfoMapping
  471. XEdbIdValue []int `description:"柱方图的x轴数据,指标id"`
  472. YDataList []YData `description:"柱方图的y轴数据"`
  473. XDataList []XData `description:"商品价格曲线的X轴数据"`
  474. BarChartInfo BarChartInfoReq `description:"柱方图的配置"`
  475. CorrelationChartInfo *CorrelationInfo `description:"相关性图表信息"`
  476. DataResp interface{} `description:"图表数据,根据图的类型而定的,没有确定的数据格式"`
  477. }
  478. // XData 商品价格曲线的的x轴数据
  479. type XData struct {
  480. Name string `description:"别名"`
  481. NameEn string `description:"英文别名"`
  482. }
  483. // YData 柱方图的y轴数据
  484. type YData struct {
  485. Date string `description:"数据日期"`
  486. ConfigDate time.Time `description:"配置的日期" json:"-"`
  487. Color string `description:"数据颜色"`
  488. Name string `description:"别名"`
  489. NameEn string `description:"英文别名"`
  490. Value []float64 `description:"每个指标的值"`
  491. NoDataEdbList []int `description:"没有数据的指标列表"`
  492. XEdbInfoIdList []int `description:"对应X轴的指标id列表"`
  493. NameList []string `description:"每个值对应的名称"`
  494. EnNameList []string `description:"每个值对应的英文名称"`
  495. EdbValMap map[int]float64 `description:"指标与值的对应" json:"-"`
  496. M []int `description:"对应开始日期的间隔值" json:"-"`
  497. Unit string `description:"中文单位名称"`
  498. UnitEn string `description:"英文单位名称"`
  499. }
  500. func ModifyChartInfoAndMapping(edbInfoIdStr string, req *SaveChartInfoReq, chartType int) (err error) {
  501. o := orm.NewOrmUsingDB("data")
  502. to, err := o.Begin()
  503. if err != nil {
  504. return
  505. }
  506. defer func() {
  507. if err != nil {
  508. _ = to.Rollback()
  509. } else {
  510. _ = to.Commit()
  511. }
  512. }()
  513. //非季节图
  514. if chartType != 2 {
  515. updateStr := `edb_info_ids=?,
  516. modify_time = NOW(),
  517. date_type=?,
  518. start_date=?,
  519. end_date=?,
  520. left_min=?,
  521. left_max=?,
  522. right_min=?,
  523. right_max=?,
  524. right2_min=?,
  525. right2_max=?,
  526. min_max_save=?,
  527. start_year=?`
  528. pars := []interface{}{edbInfoIdStr, req.DateType, req.StartDate, req.EndDate, req.LeftMin, req.LeftMax, req.RightMin, req.RightMax, req.Right2Min, req.Right2Max, req.MinMaxSave, req.StartYear}
  529. if req.ExtraConfig != `` {
  530. updateStr += `,extra_config=? `
  531. pars = append(pars, req.ExtraConfig)
  532. }
  533. pars = append(pars, req.ChartInfoId)
  534. sql := ` UPDATE chart_info SET ` + updateStr + ` WHERE chart_info_id = ?`
  535. _, err = to.Raw(sql, pars).Exec()
  536. if err != nil {
  537. fmt.Println("UPDATE chart_info Err:", err.Error())
  538. return err
  539. }
  540. } else {
  541. sql := ` UPDATE chart_info
  542. SET
  543. edb_info_ids=?,
  544. modify_time = NOW(),
  545. calendar=?,
  546. date_type=?,
  547. start_date=?,
  548. end_date=?,
  549. season_start_date=?,
  550. season_end_date=?,
  551. left_min=?,
  552. left_max=?,
  553. right_min=?,
  554. right_max=?,
  555. right2_min=?,
  556. right2_max=?,
  557. min_max_save=?,
  558. start_year=?
  559. WHERE chart_info_id = ?`
  560. _, err = to.Raw(sql, edbInfoIdStr, req.Calendar, req.DateType, req.StartDate, req.EndDate, req.StartDate, req.EndDate, req.LeftMin, req.LeftMax, req.RightMin, req.RightMax, req.Right2Min, req.Right2Max, req.MinMaxSave, req.StartYear, req.ChartInfoId).Exec()
  561. if err != nil {
  562. fmt.Println("UPDATE chart_info Err:", err.Error())
  563. return err
  564. }
  565. }
  566. var edbInfoIdArr []string
  567. mapList := make([]*ChartEdbMapping, 0)
  568. for _, v := range req.ChartEdbInfoList {
  569. edbInfoIdArr = append(edbInfoIdArr, strconv.Itoa(v.EdbInfoId))
  570. var count int
  571. csql := `SELECT COUNT(1) AS count FROM chart_edb_mapping WHERE chart_info_id=? AND edb_info_id=? `
  572. err = to.Raw(csql, req.ChartInfoId, v.EdbInfoId).QueryRow(&count)
  573. if err != nil {
  574. fmt.Println("QueryRow Err:", err.Error())
  575. return err
  576. }
  577. if count > 0 {
  578. msql := `UPDATE chart_edb_mapping
  579. SET
  580. modify_time = NOW(),
  581. max_data = ?,
  582. min_data = ?,
  583. is_order = ?,
  584. is_axis = ?,
  585. edb_info_type = ?,
  586. lead_value = ?,
  587. lead_unit = ?,
  588. chart_style = ?,
  589. chart_color = ?,
  590. predict_chart_color = ?,
  591. chart_width = ?
  592. WHERE chart_info_id =? AND edb_info_id=? `
  593. _, err = to.Raw(msql, v.MaxData, v.MinData, v.IsOrder, v.IsAxis, v.EdbInfoType, v.LeadValue, v.LeadUnit, v.ChartStyle, v.ChartColor, v.PredictChartColor, v.ChartWidth, req.ChartInfoId, v.EdbInfoId).Exec()
  594. if err != nil {
  595. fmt.Println("chart_edb_mapping Err:" + err.Error())
  596. return err
  597. }
  598. } else {
  599. mapItem := new(ChartEdbMapping)
  600. mapItem.ChartInfoId = req.ChartInfoId
  601. mapItem.EdbInfoId = v.EdbInfoId
  602. mapItem.CreateTime = time.Now()
  603. mapItem.ModifyTime = time.Now()
  604. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  605. mapItem.UniqueCode = utils.MD5(utils.CHART_PREFIX + "_" + timestamp)
  606. mapItem.MaxData = v.MaxData
  607. mapItem.MinData = v.MinData
  608. mapItem.IsOrder = v.IsOrder
  609. mapItem.IsAxis = v.IsAxis
  610. mapItem.EdbInfoType = v.EdbInfoType
  611. mapItem.LeadValue = v.LeadValue
  612. mapItem.LeadUnit = v.LeadUnit
  613. mapItem.ChartStyle = v.ChartStyle
  614. mapItem.ChartColor = v.ChartColor
  615. mapItem.PredictChartColor = v.PredictChartColor
  616. mapItem.ChartWidth = v.ChartWidth
  617. mapList = append(mapList, mapItem)
  618. }
  619. }
  620. if len(mapList) > 0 {
  621. _, err = to.InsertMulti(1, mapList)
  622. if err != nil {
  623. fmt.Println("AddChartEdbMapping Err:" + err.Error())
  624. return err
  625. }
  626. }
  627. if len(edbInfoIdArr) > 0 {
  628. edbInfoIdStr := strings.Join(edbInfoIdArr, ",")
  629. if edbInfoIdStr != "" {
  630. dsql := `DELETE FROM chart_edb_mapping WHERE chart_info_id=? AND edb_info_id NOT IN(` + edbInfoIdStr + `)`
  631. _, err = to.Raw(dsql, req.ChartInfoId).Exec()
  632. if err != nil {
  633. fmt.Println("delete err:" + err.Error())
  634. return err
  635. }
  636. }
  637. }
  638. return
  639. }
  640. // EditChartInfoAndMapping 修改 ETA图库 的 图表与指标 的关系
  641. func EditChartInfoAndMapping(req *EditChartInfoReq, edbInfoIdStr string, calendar string, dateType, disabled int, barChartConf string, chartEdbInfoList []*ChartSaveItem, seasonExtra string) (err error) {
  642. o := orm.NewOrmUsingDB("data")
  643. to, err := o.Begin()
  644. if err != nil {
  645. return
  646. }
  647. defer func() {
  648. if err != nil {
  649. _ = to.Rollback()
  650. } else {
  651. _ = to.Commit()
  652. }
  653. }()
  654. var pars []interface{}
  655. pars = append(pars, req.ChartName)
  656. pars = append(pars, edbInfoIdStr)
  657. pars = append(pars, req.ChartType)
  658. pars = append(pars, req.ChartClassifyId)
  659. pars = append(pars, disabled)
  660. pars = append(pars, barChartConf)
  661. pars = append(pars, req.ExtraConfig)
  662. pars = append(pars, seasonExtra)
  663. pars = append(pars, req.StartYear)
  664. pars = append(pars, req.ChartThemeId)
  665. pars = append(pars, req.SourcesFrom)
  666. pars = append(pars, req.Instructions)
  667. pars = append(pars, req.MarkersLines)
  668. pars = append(pars, req.MarkersAreas)
  669. pars = append(pars, req.Unit)
  670. pars = append(pars, req.UnitEn)
  671. sql := ` UPDATE chart_info
  672. SET
  673. chart_name =?,
  674. edb_info_ids=?,
  675. chart_type=?,
  676. chart_classify_id = ?,
  677. modify_time = NOW(),
  678. disabled = ?,
  679. bar_config = ?,
  680. extra_config = ?,
  681. season_extra_config = ?,
  682. start_year = ?,
  683. chart_theme_id = ?,
  684. sources_from = ?,
  685. instructions = ?,
  686. markers_lines = ?,
  687. markers_areas = ?,
  688. unit = ?,
  689. unit_en = ?
  690. `
  691. if calendar != "" {
  692. sql += `,calendar = ? `
  693. pars = append(pars, calendar)
  694. }
  695. if dateType > 0 {
  696. sql += `,date_type = ? `
  697. pars = append(pars, dateType)
  698. }
  699. sql += `,start_date = ? `
  700. pars = append(pars, req.StartDate)
  701. sql += `,end_date = ? `
  702. pars = append(pars, req.EndDate)
  703. sql += `,season_start_date = ? `
  704. pars = append(pars, req.StartDate)
  705. sql += `,season_end_date = ? `
  706. pars = append(pars, req.EndDate)
  707. sql += `,left_min = ? `
  708. pars = append(pars, req.LeftMin)
  709. sql += `,left_max = ? `
  710. pars = append(pars, req.LeftMax)
  711. sql += `,right_min = ? `
  712. pars = append(pars, req.RightMin)
  713. sql += `,right_max = ? `
  714. pars = append(pars, req.RightMax)
  715. sql += `,right2_min = ? `
  716. pars = append(pars, req.Right2Min)
  717. sql += `,right2_max = ? `
  718. pars = append(pars, req.Right2Max)
  719. sql += `WHERE chart_info_id = ?`
  720. pars = append(pars, req.ChartInfoId)
  721. _, err = to.Raw(sql, pars).Exec()
  722. if err != nil {
  723. fmt.Println("UPDATE chart_info Err:", err.Error())
  724. return err
  725. }
  726. chartEdbMappingIdList := make([]string, 0)
  727. for _, v := range chartEdbInfoList {
  728. // 查询该指标是否存在,如果存在的话,那么就去修改,否则新增
  729. var tmpChartEdbMapping *ChartEdbMapping
  730. csql := `SELECT * FROM chart_edb_mapping WHERE chart_info_id=? AND edb_info_id=? AND source = ? `
  731. err = to.Raw(csql, req.ChartInfoId, v.EdbInfoId, utils.CHART_SOURCE_DEFAULT).QueryRow(&tmpChartEdbMapping)
  732. if err != nil && err.Error() != utils.ErrNoRow() {
  733. fmt.Println("QueryRow Err:", err.Error())
  734. return err
  735. }
  736. if tmpChartEdbMapping != nil {
  737. chartEdbMappingIdList = append(chartEdbMappingIdList, strconv.Itoa(tmpChartEdbMapping.ChartEdbMappingId))
  738. tmpChartEdbMapping.ModifyTime = time.Now()
  739. tmpChartEdbMapping.MaxData = v.MaxData
  740. tmpChartEdbMapping.MinData = v.MinData
  741. tmpChartEdbMapping.IsOrder = v.IsOrder
  742. tmpChartEdbMapping.IsAxis = v.IsAxis
  743. tmpChartEdbMapping.EdbInfoType = v.EdbInfoType
  744. tmpChartEdbMapping.LeadValue = v.LeadValue
  745. tmpChartEdbMapping.LeadUnit = v.LeadUnit
  746. tmpChartEdbMapping.ChartStyle = v.ChartStyle
  747. tmpChartEdbMapping.ChartColor = v.ChartColor
  748. tmpChartEdbMapping.PredictChartColor = v.PredictChartColor
  749. tmpChartEdbMapping.ChartWidth = v.ChartWidth
  750. tmpChartEdbMapping.EdbAliasName = v.EdbAliasName
  751. _, err = to.Update(tmpChartEdbMapping, "ModifyTime", "MaxData", "MinData", "IsOrder", "IsAxis", "EdbInfoType", "LeadValue", "LeadUnit", "ChartStyle", "ChartColor", "PredictChartColor", "ChartWidth", "EdbAliasName")
  752. if err != nil {
  753. fmt.Println("chart_edb_mapping Err:" + err.Error())
  754. return err
  755. }
  756. } else {
  757. mapItem := new(ChartEdbMapping)
  758. mapItem.ChartInfoId = req.ChartInfoId
  759. mapItem.EdbInfoId = v.EdbInfoId
  760. mapItem.CreateTime = time.Now()
  761. mapItem.ModifyTime = time.Now()
  762. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  763. mapItem.UniqueCode = utils.MD5(utils.CHART_PREFIX + "_" + timestamp + "_" + strconv.Itoa(v.EdbInfoId))
  764. mapItem.MaxData = v.MaxData
  765. mapItem.MinData = v.MinData
  766. mapItem.IsOrder = v.IsOrder
  767. mapItem.IsAxis = v.IsAxis
  768. mapItem.EdbInfoType = v.EdbInfoType
  769. mapItem.LeadValue = v.LeadValue
  770. mapItem.LeadUnit = v.LeadUnit
  771. mapItem.ChartStyle = v.ChartStyle
  772. mapItem.ChartColor = v.ChartColor
  773. mapItem.PredictChartColor = v.PredictChartColor
  774. mapItem.ChartWidth = v.ChartWidth
  775. mapItem.Source = utils.CHART_SOURCE_DEFAULT
  776. mapItem.EdbAliasName = v.EdbAliasName
  777. tmpId, err := to.Insert(mapItem)
  778. if err != nil {
  779. fmt.Println("AddChartEdbMapping Err:" + err.Error())
  780. return err
  781. }
  782. mapItem.ChartEdbMappingId = int(tmpId)
  783. chartEdbMappingIdList = append(chartEdbMappingIdList, strconv.Itoa(mapItem.ChartEdbMappingId))
  784. }
  785. }
  786. if len(chartEdbMappingIdList) > 0 {
  787. chartEdbMappingIdStr := strings.Join(chartEdbMappingIdList, ",")
  788. dsql := `DELETE FROM chart_edb_mapping WHERE chart_info_id=? AND chart_edb_mapping_id NOT IN(` + chartEdbMappingIdStr + `)`
  789. _, err = to.Raw(dsql, req.ChartInfoId).Exec()
  790. if err != nil {
  791. fmt.Println("delete err:" + err.Error())
  792. return err
  793. }
  794. }
  795. return
  796. }
  797. // EditFutureGoodChartInfoAndMapping 修改商品价格曲线的 图表与指标 的关系
  798. func EditFutureGoodChartInfoAndMapping(req *EditChartInfoReq, edbInfoIdStr string, calendar string, dateType, disabled int, barChartConf string) (err error) {
  799. o := orm.NewOrmUsingDB("data")
  800. to, err := o.Begin()
  801. if err != nil {
  802. return
  803. }
  804. defer func() {
  805. if err != nil {
  806. _ = to.Rollback()
  807. } else {
  808. _ = to.Commit()
  809. }
  810. }()
  811. var pars []interface{}
  812. pars = append(pars, req.ChartName)
  813. pars = append(pars, edbInfoIdStr)
  814. pars = append(pars, req.ChartType)
  815. pars = append(pars, req.ChartClassifyId)
  816. pars = append(pars, disabled)
  817. pars = append(pars, barChartConf)
  818. sql := ` UPDATE chart_info
  819. SET
  820. chart_name =?,
  821. edb_info_ids=?,
  822. chart_type=?,
  823. chart_classify_id = ?,
  824. modify_time = NOW(),
  825. disabled = ?,
  826. bar_config = ?
  827. `
  828. if calendar != "" {
  829. sql += `,calendar = ? `
  830. pars = append(pars, calendar)
  831. }
  832. if dateType > 0 {
  833. sql += `,date_type = ? `
  834. pars = append(pars, dateType)
  835. }
  836. sql += `,start_date = ? `
  837. pars = append(pars, req.StartDate)
  838. sql += `,end_date = ? `
  839. pars = append(pars, req.EndDate)
  840. sql += `,season_start_date = ? `
  841. pars = append(pars, req.StartDate)
  842. sql += `,season_end_date = ? `
  843. pars = append(pars, req.EndDate)
  844. sql += `,left_min = ? `
  845. pars = append(pars, req.LeftMin)
  846. sql += `,left_max = ? `
  847. pars = append(pars, req.LeftMax)
  848. sql += `,right_min = ? `
  849. pars = append(pars, req.RightMin)
  850. sql += `,right_max = ? `
  851. pars = append(pars, req.RightMax)
  852. sql += `,right2_min = ? `
  853. pars = append(pars, req.Right2Min)
  854. sql += `,right2_max = ? `
  855. pars = append(pars, req.Right2Max)
  856. sql += `WHERE chart_info_id = ?`
  857. pars = append(pars, req.ChartInfoId)
  858. _, err = to.Raw(sql, pars).Exec()
  859. if err != nil {
  860. fmt.Println("UPDATE chart_info Err:", err.Error())
  861. return err
  862. }
  863. chartEdbMappingIdList := make([]string, 0)
  864. for _, v := range req.BarChartInfo.EdbInfoIdList {
  865. // 查询该指标是否存在,如果存在的话,那么就去修改,否则新增
  866. var tmpChartEdbMapping *ChartEdbMapping
  867. csql := `SELECT * FROM chart_edb_mapping WHERE chart_info_id=? AND edb_info_id=? AND source = ? `
  868. err = to.Raw(csql, req.ChartInfoId, v.EdbInfoId, v.Source).QueryRow(&tmpChartEdbMapping)
  869. if err != nil && err.Error() != utils.ErrNoRow() {
  870. fmt.Println("QueryRow Err:", err.Error())
  871. return err
  872. }
  873. if tmpChartEdbMapping != nil {
  874. chartEdbMappingIdList = append(chartEdbMappingIdList, strconv.Itoa(tmpChartEdbMapping.ChartEdbMappingId))
  875. //tmpChartEdbMapping.ModifyTime = time.Now()
  876. //tmpChartEdbMapping.MaxData = v.MaxData
  877. //tmpChartEdbMapping.MinData = v.MinData
  878. //tmpChartEdbMapping.IsOrder = v.IsOrder
  879. //tmpChartEdbMapping.IsAxis = v.IsAxis
  880. //tmpChartEdbMapping.EdbInfoType = v.EdbInfoType
  881. //tmpChartEdbMapping.LeadValue = v.LeadValue
  882. //tmpChartEdbMapping.LeadUnit = v.LeadUnit
  883. //tmpChartEdbMapping.ChartStyle = v.ChartStyle
  884. //tmpChartEdbMapping.ChartColor = v.ChartColor
  885. //tmpChartEdbMapping.PredictChartColor = v.PredictChartColor
  886. //tmpChartEdbMapping.ChartWidth = v.ChartWidth
  887. //_, err = to.Update(tmpChartEdbMapping, "ModifyTime", "MaxData", "MinData", "IsOrder", "IsAxis", "EdbInfoType", "LeadValue", "LeadUnit", "ChartStyle", "ChartColor", "PredictChartColor", "ChartWidth")
  888. //if err != nil {
  889. // fmt.Println("chart_edb_mapping Err:" + err.Error())
  890. // return err
  891. //}
  892. } else {
  893. mapItem := new(ChartEdbMapping)
  894. mapItem.ChartInfoId = req.ChartInfoId
  895. mapItem.EdbInfoId = v.EdbInfoId
  896. mapItem.CreateTime = time.Now()
  897. mapItem.ModifyTime = time.Now()
  898. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  899. mapItem.UniqueCode = utils.MD5(utils.CHART_PREFIX + "_" + timestamp + "_" + strconv.Itoa(v.EdbInfoId))
  900. //mapItem.MaxData = v.MaxData
  901. //mapItem.MinData = v.MinData
  902. mapItem.IsOrder = true
  903. mapItem.IsAxis = 1
  904. mapItem.EdbInfoType = 1
  905. //mapItem.LeadValue = v.LeadValue
  906. //mapItem.LeadUnit = v.LeadUnit
  907. //mapItem.ChartStyle = v.ChartStyle
  908. //mapItem.ChartColor = v.ChartColor
  909. //mapItem.PredictChartColor = v.PredictChartColor
  910. //mapItem.ChartWidth = v.ChartWidth
  911. mapItem.Source = v.Source
  912. tmpId, err := to.Insert(mapItem)
  913. if err != nil {
  914. fmt.Println("AddChartEdbMapping Err:" + err.Error())
  915. return err
  916. }
  917. mapItem.ChartEdbMappingId = int(tmpId)
  918. chartEdbMappingIdList = append(chartEdbMappingIdList, strconv.Itoa(mapItem.ChartEdbMappingId))
  919. }
  920. }
  921. if len(chartEdbMappingIdList) > 0 {
  922. chartEdbMappingIdStr := strings.Join(chartEdbMappingIdList, ",")
  923. dsql := `DELETE FROM chart_edb_mapping WHERE chart_info_id=? AND chart_edb_mapping_id NOT IN(` + chartEdbMappingIdStr + `)`
  924. _, err = to.Raw(dsql, req.ChartInfoId).Exec()
  925. if err != nil {
  926. fmt.Println("delete err:" + err.Error())
  927. return err
  928. }
  929. }
  930. return
  931. }
  932. func EditChartEnInfoAndEdbEnInfo(req *EditChartEnInfoReq) (err error) {
  933. o := orm.NewOrmUsingDB("data")
  934. to, err := o.Begin()
  935. if err != nil {
  936. return
  937. }
  938. defer func() {
  939. if err != nil {
  940. _ = to.Rollback()
  941. } else {
  942. _ = to.Commit()
  943. }
  944. }()
  945. var pars []interface{}
  946. updateField := ` chart_name_en =?, `
  947. pars = append(pars, req.ChartNameEn)
  948. if req.ExtraConfig != `` {
  949. updateField += ` extra_config =?, `
  950. pars = append(pars, req.ExtraConfig)
  951. }
  952. sql := ` UPDATE chart_info
  953. SET ` + updateField + ` modify_time = NOW()
  954. WHERE chart_info_id = ?`
  955. pars = append(pars, req.ChartInfoId)
  956. _, err = to.Raw(sql, pars).Exec()
  957. if err != nil {
  958. fmt.Println("UPDATE chart_info Err:", err.Error())
  959. return err
  960. }
  961. var edbInfoIdArr []string
  962. for _, v := range req.ChartEdbInfoList {
  963. edbInfoIdArr = append(edbInfoIdArr, strconv.Itoa(v.EdbInfoId))
  964. var count int
  965. csql := `SELECT COUNT(1) AS count FROM chart_edb_mapping WHERE chart_info_id=? AND edb_info_id=? `
  966. err = to.Raw(csql, req.ChartInfoId, v.EdbInfoId).QueryRow(&count)
  967. if err != nil {
  968. fmt.Println("QueryRow Err:", err.Error())
  969. return err
  970. }
  971. if count > 0 {
  972. msql := ` UPDATE edb_info
  973. SET
  974. edb_name_en =?,
  975. unit_en = ?,
  976. modify_time = NOW()
  977. WHERE edb_info_id = ? `
  978. _, err = to.Raw(msql, v.EdbNameEn, v.UnitEn, v.EdbInfoId).Exec()
  979. if err != nil {
  980. fmt.Println("edb_info Err:" + err.Error())
  981. return err
  982. }
  983. }
  984. }
  985. return
  986. }
  987. func ModifyEdbDatadTimestamp(source, subSource, edbDataId int, dataTimestamp int64) (err error) {
  988. tableName := GetEdbDataTableName(source, subSource)
  989. sql := `UPDATE %s SET data_timestamp=? WHERE edb_data_id=? `
  990. sql = fmt.Sprintf(sql, tableName)
  991. o := orm.NewOrmUsingDB("data")
  992. _, err = o.Raw(sql, dataTimestamp, edbDataId).Exec()
  993. return
  994. }
  995. type AddChartInfoReq struct {
  996. ChartEdbInfoList []*ChartSaveItem `description:"指标及配置信息"`
  997. ChartClassifyId int `description:"分类id"`
  998. ChartName string `description:"图表名称"`
  999. ChartType int `description:"生成样式:1:曲线图,2:季节性图,3:面积图,4:柱状图,5:散点图,6:组合图,7:柱方图"`
  1000. DateType int `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:起始日期至今"`
  1001. StartDate string `description:"自定义开始日期"`
  1002. EndDate string `description:"自定义结束日期"`
  1003. Calendar string `description:"公历/农历"`
  1004. LeftMin string `description:"图表左侧最小值"`
  1005. LeftMax string `description:"图表左侧最大值"`
  1006. RightMin string `description:"图表右侧最小值"`
  1007. RightMax string `description:"图表右侧最大值"`
  1008. Right2Min string `description:"图表右侧2最小值"`
  1009. Right2Max string `description:"图表右侧2最大值"`
  1010. BarChartInfo BarChartInfoReq `description:"柱方图的配置"`
  1011. CorrelationChartInfo CorrelationChartInfoReq `description:"相关性图表配置"`
  1012. ExtraConfig string `description:"图表额外配置信息,json字符串"`
  1013. ChartImage string `description:"封面图" json:"-"`
  1014. SeasonExtraConfig SeasonExtraItem `description:"季节性图表中的配置,json数据"`
  1015. StartYear int `description:"当选择的日期类型为最近N年类型时,即date_type=20, 用start_year表示N"`
  1016. ChartThemeId int `description:"图表应用主题ID"`
  1017. SourcesFrom string `description:"图表来源"`
  1018. Instructions string `description:"图表说明"`
  1019. MarkersLines string `description:"标识线"`
  1020. MarkersAreas string `description:"标识区"`
  1021. Unit string `description:"中文单位名称"`
  1022. UnitEn string `description:"英文单位名称"`
  1023. }
  1024. type PreviewChartInfoReq struct {
  1025. ChartEdbInfoList []*ChartSaveItem `description:"指标及配置信息"`
  1026. DateType int `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:起始日期至今 20:最近N年"`
  1027. ChartType int `description:"生成样式:1:曲线图,2:季节性图,3:面积图,4:柱状图,5:散点图,6:组合图,7:柱方图"`
  1028. StartDate string `description:"自定义开始日期"`
  1029. EndDate string `description:"自定义结束日期"`
  1030. Calendar string `description:"公历/农历"`
  1031. SeasonExtraConfig SeasonExtraItem `description:"季节性图表中的配置,json数据"`
  1032. StartYear int `description:"当选择的日期类型为最近N年类型时,即date_type=20, 用start_year表示N"`
  1033. }
  1034. type SeasonExtraItem struct {
  1035. ChartLegend []SeasonChartLegend `description:"自定义的图例名称"`
  1036. XStartDate string `description:"横坐标显示的起始日"`
  1037. XEndDate string `description:"横坐标显示的截止日"`
  1038. JumpYear int `description:"横坐标日期是否跨年,1跨年,0不跨年"`
  1039. }
  1040. type SeasonChartLegend struct {
  1041. Name string
  1042. Value string
  1043. }
  1044. type AddChartInfoResp struct {
  1045. ChartInfoId int `description:"图表id"`
  1046. UniqueCode string `description:"图表唯一编码"`
  1047. ChartType int `description:"生成样式:1:曲线图,2:季节性图"`
  1048. }
  1049. type QuarterDataList []*QuarterData
  1050. func (m QuarterDataList) Len() int {
  1051. return len(m)
  1052. }
  1053. func (m QuarterDataList) Less(i, j int) bool {
  1054. return m[i].Years < m[j].Years
  1055. }
  1056. func (m QuarterDataList) Swap(i, j int) {
  1057. m[i], m[j] = m[j], m[i]
  1058. }
  1059. // 判断图表指标是否已经存在
  1060. func ChartInfoExist(condition, edbInfoIdStr string) (count int, err error) {
  1061. sql := `SELECT COUNT(1) AS count FROM (
  1062. SELECT GROUP_CONCAT(edb_info_id ORDER BY edb_info_id ASC SEPARATOR ',') AS edb_info_id_str
  1063. FROM chart_edb_mapping AS a
  1064. WHERE 1=1`
  1065. if condition != "" {
  1066. sql += condition
  1067. }
  1068. sql += ` GROUP BY chart_info_id
  1069. )AS t
  1070. WHERE t.edb_info_id_str=?
  1071. GROUP BY t.edb_info_id_str `
  1072. o := orm.NewOrmUsingDB("data")
  1073. err = o.Raw(sql, edbInfoIdStr).QueryRow(&count)
  1074. return
  1075. }
  1076. func ChartInfoSearchByKeyWord(keyword string, showSysId int) (searchList []*ChartInfo, err error) {
  1077. o := orm.NewOrmUsingDB("data")
  1078. sql := ` SELECT * FROM chart_info WHERE 1=1 `
  1079. var pars []interface{}
  1080. if keyword != "" {
  1081. sql += `AND chart_name LIKE ? `
  1082. pars = append(pars, utils.GetLikeKeyword(keyword))
  1083. }
  1084. if showSysId > 0 {
  1085. sql += ` AND sys_user_id = ? `
  1086. pars = append(pars, showSysId)
  1087. }
  1088. sql += ` ORDER BY create_time DESC `
  1089. if keyword == "" {
  1090. sql += ` LIMIT 100 `
  1091. }
  1092. _, err = o.Raw(sql, pars).QueryRows(&searchList)
  1093. return
  1094. }
  1095. // ChartInfoSearchByEmptyKeyWord 没有关键字的时候获取默认100条数据
  1096. func ChartInfoSearchByEmptyKeyWord(showSysId int, sourceList []int, noPermissionChartIdList []int, startSize, pageSize int) (total int64, searchList []*ChartInfo, err error) {
  1097. num := len(sourceList)
  1098. o := orm.NewOrmUsingDB("data")
  1099. baseSql := ` FROM chart_info WHERE 1=1 AND source in (` + utils.GetOrmInReplace(num) + `)`
  1100. var basePars []interface{}
  1101. basePars = append(basePars, sourceList)
  1102. if showSysId > 0 {
  1103. baseSql += ` AND sys_user_id = ? `
  1104. basePars = append(basePars, showSysId)
  1105. }
  1106. lenNoPermissionChartIdList := len(noPermissionChartIdList)
  1107. if lenNoPermissionChartIdList > 0 {
  1108. baseSql += ` AND chart_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionChartIdList) + `) `
  1109. basePars = append(basePars, noPermissionChartIdList)
  1110. }
  1111. // 查找数量
  1112. totalSql := " SELECT count(1) as total " + baseSql
  1113. err = o.Raw(totalSql, basePars).QueryRow(&total)
  1114. if err != nil {
  1115. return
  1116. }
  1117. // 查找列表数据
  1118. sql := " SELECT * " + baseSql + ` ORDER BY create_time DESC LIMIT ?,? `
  1119. basePars = append(basePars, startSize, pageSize)
  1120. _, err = o.Raw(sql, basePars).QueryRows(&searchList)
  1121. return
  1122. }
  1123. func GetNextChartInfo(classifyId int) (item *ChartInfo, err error) {
  1124. o := orm.NewOrmUsingDB("data")
  1125. sql := ` SELECT b.* FROM chart_classify AS a
  1126. INNER JOIN chart_info AS b ON a.chart_classify_id=b.chart_classify_id
  1127. WHERE a.chart_classify_id>?
  1128. ORDER BY a.chart_classify_id ASC
  1129. LIMIT 1 `
  1130. err = o.Raw(sql, classifyId).QueryRow(&item)
  1131. return
  1132. }
  1133. // GetChartInfoRefreshData 获取图表关联的指标信息
  1134. func GetChartInfoRefreshData(chartInfoId int) (baseEdbInfoArr, calculateInfoArr []*EdbInfo, err error) {
  1135. o := orm.NewOrmUsingDB("data")
  1136. sql := ` SELECT b.* FROM chart_edb_mapping AS a
  1137. INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
  1138. WHERE a.chart_info_id=? `
  1139. edbInfoList := make([]*EdbInfo, 0)
  1140. _, err = o.Raw(sql, chartInfoId).QueryRows(&edbInfoList)
  1141. if err != nil {
  1142. return
  1143. }
  1144. for _, v := range edbInfoList {
  1145. fmt.Println(v.EdbInfoId, v.EdbType)
  1146. if v.EdbType == 1 {
  1147. baseEdbInfoArr = append(baseEdbInfoArr, v)
  1148. } else {
  1149. calculateInfoArr = append(calculateInfoArr, v)
  1150. newBaseEdbInfoArr, newCalculateInfoArr, err := GetChartRefreshEdbInfo(v.EdbInfoId, v.Source, 0)
  1151. if err != nil {
  1152. return baseEdbInfoArr, calculateInfoArr, err
  1153. }
  1154. baseEdbInfoArr = append(baseEdbInfoArr, newBaseEdbInfoArr...)
  1155. calculateInfoArr = append(calculateInfoArr, newCalculateInfoArr...)
  1156. }
  1157. }
  1158. return
  1159. }
  1160. func GetChartRefreshEdbInfo(edbInfoId, source, n int) (baseEdbInfoArr, calculateInfoArr []*EdbInfo, err error) {
  1161. calculateList, err := GetEdbInfoCalculateMap(edbInfoId, source)
  1162. if err != nil && err.Error() != utils.ErrNoRow() {
  1163. return
  1164. }
  1165. n++
  1166. for _, item := range calculateList {
  1167. fmt.Println(item.EdbInfoId)
  1168. if item.EdbType == 1 {
  1169. baseEdbInfoArr = append(baseEdbInfoArr, item)
  1170. } else {
  1171. calculateInfoArr = append(calculateInfoArr, item)
  1172. if n > 10 {
  1173. return
  1174. }
  1175. newBaseEdbInfoArr, newCalculateInfoArr, _ := GetChartRefreshEdbInfo(item.EdbInfoId, item.Source, n)
  1176. baseEdbInfoArr = append(baseEdbInfoArr, newBaseEdbInfoArr...)
  1177. calculateInfoArr = append(calculateInfoArr, newCalculateInfoArr...)
  1178. }
  1179. }
  1180. return
  1181. }
  1182. type SetChartInfoImageReq struct {
  1183. ChartInfoId int `description:"图表ID"`
  1184. ImageUrl string `description:"图表图片地址"`
  1185. }
  1186. func EditChartInfoImage(req *SetChartInfoImageReq) (err error) {
  1187. o := orm.NewOrmUsingDB("data")
  1188. sql := ` UPDATE chart_info SET chart_image=?, modify_time = NOW() WHERE chart_info_id = ? `
  1189. _, err = o.Raw(sql, req.ImageUrl, req.ChartInfoId).Exec()
  1190. if err != nil {
  1191. fmt.Println("EditChartInfoImage Err:", err.Error())
  1192. return err
  1193. }
  1194. return
  1195. }
  1196. type ChartInfoDetailFromUniqueCodeResp struct {
  1197. ChartInfo *ChartInfoView
  1198. Status bool `description:"true:图表存在,false:图表不存在"`
  1199. EdbInfoList []*ChartEdbInfoMapping
  1200. XEdbIdValue []int `description:"柱方图的x轴数据,指标id"`
  1201. YDataList []YData `description:"柱方图的y轴数据"`
  1202. XDataList []XData `description:"商品价格曲线的X轴数据"`
  1203. BarChartInfo BarChartInfoReq `description:"柱方图的配置"`
  1204. CorrelationChartInfo *CorrelationInfo `description:"相关性图表信息"`
  1205. DataResp interface{} `description:"图表数据,根据图的类型而定的,没有确定的数据格式"`
  1206. }
  1207. func GetChartInfoByUniqueCode(uniqueCode string) (item *ChartInfo, err error) {
  1208. o := orm.NewOrmUsingDB("data")
  1209. sql := ` SELECT * FROM chart_info WHERE unique_code=? `
  1210. err = o.Raw(sql, uniqueCode).QueryRow(&item)
  1211. return
  1212. }
  1213. func GetChartInfoViewByUniqueCode(uniqueCode string) (item *ChartInfoView, err error) {
  1214. o := orm.NewOrmUsingDB("data")
  1215. sql := ` SELECT * FROM chart_info WHERE unique_code=? `
  1216. err = o.Raw(sql, uniqueCode).QueryRow(&item)
  1217. return
  1218. }
  1219. // GetFirstChartInfoByClassifyId 获取当前分类下,且排序数相同 的排序第一条的数据
  1220. func GetFirstChartInfoByClassifyId(classifyId int) (item *ChartInfo, err error) {
  1221. o := orm.NewOrmUsingDB("data")
  1222. sql := ` SELECT * FROM chart_info WHERE chart_classify_id=? order by sort asc,chart_info_id asc limit 1`
  1223. err = o.Raw(sql, classifyId).QueryRow(&item)
  1224. return
  1225. }
  1226. // UpdateChartInfoSortByClassifyId 根据图表id更新排序
  1227. func UpdateChartInfoSortByClassifyId(classifyId, nowSort, prevChartInfoId int, sourceList []int, updateSort string) (err error) {
  1228. o := orm.NewOrmUsingDB("data")
  1229. num := len(sourceList)
  1230. if num <= 0 {
  1231. return
  1232. }
  1233. sql := ` update chart_info set sort = ` + updateSort + ` WHERE chart_classify_id=? AND source in (` + utils.GetOrmInReplace(num) + `) AND `
  1234. if prevChartInfoId > 0 {
  1235. sql += ` (sort > ? or (chart_info_id > ` + fmt.Sprint(prevChartInfoId) + ` and sort = ` + fmt.Sprint(nowSort) + `))`
  1236. }
  1237. _, err = o.Raw(sql, classifyId, sourceList, nowSort).Exec()
  1238. return
  1239. }
  1240. // Update 更新图表基础信息
  1241. func (chartInfo *ChartInfo) Update(cols []string) (err error) {
  1242. o := orm.NewOrmUsingDB("data")
  1243. _, err = o.Update(chartInfo, cols...)
  1244. return
  1245. }
  1246. type ChartInfoView struct {
  1247. ChartInfoId int `orm:"column(chart_info_id);pk"`
  1248. ChartName string `description:"来源名称"`
  1249. ChartNameEn string `description:"英文图表名称"`
  1250. Unit string `description:"中文单位名称"`
  1251. UnitEn string `description:"英文单位名称"`
  1252. ChartClassifyId int `description:"图表分类id"`
  1253. ChartClassifyName string `description:"图表名称"`
  1254. SysUserId int
  1255. SysUserRealName string
  1256. UniqueCode string `description:"图表唯一编码"`
  1257. CreateTime time.Time
  1258. ModifyTime time.Time
  1259. DateType int `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间"`
  1260. StartDate string `description:"自定义开始日期"`
  1261. EndDate string `description:"自定义结束日期"`
  1262. IsSetName int `description:"设置名称"`
  1263. EdbInfoIds string `description:"指标id"`
  1264. ChartType int `description:"生成样式:1:曲线图,2:季节性图"`
  1265. Calendar string `description:"公历/农历"`
  1266. SeasonStartDate string `description:"季节性图开始日期"`
  1267. SeasonEndDate string `description:"季节性图开始日期"`
  1268. ChartImage string `description:"图表图片"`
  1269. Sort int `description:"排序字段,数字越小越排前面"`
  1270. IsAdd bool `description:"true:已加入我的图库,false:未加入我的图库"`
  1271. MyChartId int
  1272. MyChartClassifyId string `description:"我的图表分类,多个用逗号隔开"`
  1273. ChartClassify []*ChartClassifyView
  1274. EdbEndDate string `description:"指标最新更新日期"`
  1275. LeftMin string `description:"图表左侧最小值"`
  1276. LeftMax string `description:"图表左侧最大值"`
  1277. RightMin string `description:"图表右侧最小值"`
  1278. RightMax string `description:"图表右侧最大值"`
  1279. Right2Min string `description:"图表右侧最小值"`
  1280. Right2Max string `description:"图表右侧最大值"`
  1281. MinMaxSave int `description:"是否手动保存过上下限:0-否;1-是"`
  1282. IsEdit bool `description:"是否有编辑权限"`
  1283. IsEnChart bool `description:"是否展示英文标识"`
  1284. WarnMsg string `description:"错误信息"`
  1285. Disabled int `description:"是否禁用,0:启用,1:禁用,默认:0"`
  1286. BarConfig string `description:"柱方图的配置,json数据" json:"-"`
  1287. Source int `description:"1:ETA图库;2:商品价格曲线;3:相关性图表"`
  1288. //CorrelationLeadUnit string `description:"相关性图表-领先单位"`
  1289. ExtraConfig string `description:"图表额外配置,json数据"`
  1290. ChartSource string `description:"图表来源str"`
  1291. ChartSourceEn string `description:"图表来源(英文)"`
  1292. Button ChartViewButton `description:"操作按钮"`
  1293. SeasonExtraConfig string `description:"季节性图表中的配置,json数据"`
  1294. StartYear int `description:"当选择的日期类型为最近N年类型时,即date_type=20, 用start_year表示N"`
  1295. ChartThemeId int `description:"图表应用主题ID"`
  1296. ChartThemeStyle string `description:"图表应用主题样式"`
  1297. SourcesFrom string `description:"图表来源"`
  1298. Instructions string `description:"图表说明"`
  1299. MarkersLines string `description:"标识线"`
  1300. MarkersAreas string `description:"标识区"`
  1301. }
  1302. type ChartViewButton struct {
  1303. IsEdit bool `description:"是否有编辑权限"`
  1304. IsEnChart bool `description:"是否展示英文标识"`
  1305. IsAdd bool `description:"true:已加入我的图库,false:未加入我的图库"`
  1306. IsCopy bool `description:"是否有另存为按钮"`
  1307. IsSetName int `description:"设置名称"`
  1308. }
  1309. type ImageSvgToPngResp struct {
  1310. Data struct {
  1311. ResourceURL string `json:"ResourceUrl"`
  1312. } `json:"Data"`
  1313. ErrCode string `json:"ErrCode"`
  1314. ErrMsg string `json:"ErrMsg"`
  1315. IsSendEmail bool `json:"IsSendEmail"`
  1316. Msg string `json:"Msg"`
  1317. Ret int64 `json:"Ret"`
  1318. Success bool `json:"Success"`
  1319. }
  1320. // GetChartInfoByClassifyIdAndName 根据分类id和图表名获取图表信息
  1321. func GetChartInfoByClassifyIdAndName(classifyId int, chartName string) (item *ChartInfo, err error) {
  1322. o := orm.NewOrmUsingDB("data")
  1323. sql := ` SELECT * FROM chart_info WHERE chart_classify_id = ? and chart_name=? `
  1324. err = o.Raw(sql, classifyId, chartName).QueryRow(&item)
  1325. return
  1326. }
  1327. // BatchChartRefreshReq 批量刷新图表请求
  1328. type BatchChartRefreshReq struct {
  1329. ChartInfoCode []string `description:"图表编码数组"`
  1330. ReportId int `description:"报告id"`
  1331. ReportChapterId int `description:"报告章节id"`
  1332. Source string `description:"来源,枚举值:report、english_report、smart_report"`
  1333. }
  1334. // GetChartInfoListByUniqueCodeSlice 根据图表编码获取图表列表数据
  1335. func GetChartInfoListByUniqueCodeSlice(uniqueCodeSlice []string) (total int64, items []*ChartInfo, err error) {
  1336. if len(uniqueCodeSlice) <= 0 {
  1337. return
  1338. }
  1339. o := orm.NewOrmUsingDB("data")
  1340. sql := ` SELECT * FROM chart_info WHERE unique_code in ("` + strings.Join(uniqueCodeSlice, `","`) + `") `
  1341. total, err = o.Raw(sql).QueryRows(&items)
  1342. return
  1343. }
  1344. // GetChartInfoRefreshDataByChartInfoIdSlice 根据图表id切片获取对应的指标数据
  1345. func GetChartInfoRefreshDataByChartInfoIdSlice(chartInfoIdSlice []string) (baseEdbInfoArr, calculateInfoArr []*EdbInfo, err error) {
  1346. o := orm.NewOrmUsingDB("data")
  1347. if len(chartInfoIdSlice) <= 0 {
  1348. return
  1349. }
  1350. sql := ` SELECT b.* FROM chart_edb_mapping AS a
  1351. INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
  1352. WHERE a.chart_info_id in (` + strings.Join(chartInfoIdSlice, ",") + `) `
  1353. edbInfoList := make([]*EdbInfo, 0)
  1354. _, err = o.Raw(sql).QueryRows(&edbInfoList)
  1355. if err != nil {
  1356. return
  1357. }
  1358. for _, v := range edbInfoList {
  1359. if v.EdbType == 1 {
  1360. baseEdbInfoArr = append(baseEdbInfoArr, v)
  1361. } else {
  1362. calculateInfoArr = append(calculateInfoArr, v)
  1363. newBaseEdbInfoArr, newCalculateInfoArr, err := GetChartRefreshEdbInfo(v.EdbInfoId, v.Source, 0)
  1364. if err != nil {
  1365. return baseEdbInfoArr, calculateInfoArr, err
  1366. }
  1367. baseEdbInfoArr = append(baseEdbInfoArr, newBaseEdbInfoArr...)
  1368. calculateInfoArr = append(calculateInfoArr, newCalculateInfoArr...)
  1369. }
  1370. }
  1371. return
  1372. }
  1373. // CopyAddChartInfoReq 复制并新增图表
  1374. type CopyAddChartInfoReq struct {
  1375. ChartInfoId int `description:"待复制的图表id"`
  1376. ChartClassifyId int `description:"分类id"`
  1377. ChartName string `description:"图表名称"`
  1378. }
  1379. // ChartInfoListByEsResp 图表数据Es搜索返回
  1380. type ChartInfoListByEsResp struct {
  1381. Paging *paging.PagingItem
  1382. List []*ChartInfoMore
  1383. }
  1384. // GetChartInfoListByCondition 根据条件获取图表数据了列表
  1385. func GetChartInfoListByCondition(condition string, pars []interface{}, startSize, pageSize int) (items []*ChartInfo, err error) {
  1386. o := orm.NewOrmUsingDB("data")
  1387. sql := ` SELECT * FROM chart_info WHERE 1=1 `
  1388. if condition != "" {
  1389. sql += condition
  1390. }
  1391. sql += ` ORDER BY chart_info_id DESC LIMIT ?,? `
  1392. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  1393. return
  1394. }
  1395. // GetChartInfoListGroupByUserId 根据指标id列表、用户分组获取指标信息
  1396. func GetChartInfoListGroupByUserId(edbIdList []string) (items []*ChartInfo, err error) {
  1397. num := len(edbIdList)
  1398. if num <= 0 {
  1399. return
  1400. }
  1401. o := orm.NewOrmUsingDB("data")
  1402. sql := ` SELECT * FROM chart_info WHERE chart_info_id in (` + utils.GetOrmInReplace(num) + `) GROUP BY sys_user_id `
  1403. _, err = o.Raw(sql, edbIdList).QueryRows(&items)
  1404. return
  1405. }
  1406. // ModifyChartInfoUserIdByCodeList 根据指标code列表修改创建人
  1407. func ModifyChartInfoUserIdByCodeList(edbIdList []string, userId int, userName string) (err error) {
  1408. num := len(edbIdList)
  1409. if num <= 0 {
  1410. return
  1411. }
  1412. o := orm.NewOrmUsingDB("data")
  1413. sql := `UPDATE chart_info SET sys_user_id=?,sys_user_real_name=? WHERE chart_info_id in (` + utils.GetOrmInReplace(num) + `) `
  1414. _, err = o.Raw(sql, userId, userName, edbIdList).Exec()
  1415. return
  1416. }
  1417. // BarChartInfoReq 柱方图预览请求数据
  1418. type BarChartInfoReq struct {
  1419. EdbInfoIdList []BarChartInfoEdbItemReq `description:"指标信息"`
  1420. DateList []BarChartInfoDateReq `description:"日期配置"`
  1421. Sort BarChartInfoSortReq `description:"排序"`
  1422. XEdbList []BarChartInfoEdbItemReq `description:"X轴选择的指标列表"`
  1423. YEdbList []BarChartInfoEdbItemReq `description:"Y轴选择的指标列表"`
  1424. Unit string `description:"中文单位"`
  1425. UnitEn string `description:"英文单位"`
  1426. }
  1427. // BarChartInfoEdbItemReq 柱方图预览请求数据(指标相关)
  1428. type BarChartInfoEdbItemReq struct {
  1429. EdbInfoId int `description:"指标ID"`
  1430. Name string `description:"别名"`
  1431. NameEn string `description:"英文别名"`
  1432. Source int `description:"1:ETA图库;2:商品价格"`
  1433. }
  1434. // BarChartInfoDateReq 柱方图预览请求数据(日期相关)
  1435. type BarChartInfoDateReq struct {
  1436. Type int `description:"配置类型"`
  1437. Date string `description:"固定日期"`
  1438. Value int `description:"N天的值"`
  1439. Color string `description:"颜色"`
  1440. Name string `description:"别名"`
  1441. }
  1442. // BarChartInfoSortReq 柱方图预览请求数据(排序相关)
  1443. type BarChartInfoSortReq struct {
  1444. Sort int `description:"排序类型,0:默认,1:升序,2:降序"`
  1445. DateIndex int `description:"日期数据的下标,从0开始"`
  1446. }
  1447. // CorrelationChartInfoReq 相关性图表请求体
  1448. type CorrelationChartInfoReq struct {
  1449. LeadValue int `description:"领先期数"`
  1450. LeadUnit string `description:"频度"`
  1451. CalculateValue int `description:"计算窗口"`
  1452. CalculateUnit string `description:"计算频度"`
  1453. BaseCalculateValue int `description:"基础计算窗口(滚动相关性的时候用到)"`
  1454. BaseCalculateUnit string `description:"基础计算频度(滚动相关性的时候用到)"`
  1455. DateType int `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:起始日期至今"`
  1456. StartDate string `description:"开始日期"`
  1457. EndDate string `description:"结束日期"`
  1458. EdbInfoIdList []CorrelationChartInfoEdbItemReq `description:"指标信息"`
  1459. }
  1460. // CorrelationChartInfoEdbItemReq 相关性图表请求指标
  1461. type CorrelationChartInfoEdbItemReq struct {
  1462. EdbInfoId int `description:"指标ID"`
  1463. Name string `description:"别名"`
  1464. NameEn string `description:"英文别名"`
  1465. //Source int `description:"1:ETA图库;2:商品价格"`
  1466. }
  1467. // EditCorrelationChartInfoAndMapping 修改相关性图表的 图表与指标 的关系
  1468. func EditCorrelationChartInfoAndMapping(req *EditChartInfoReq, edbInfoIdStr string, calendar string, dateType, disabled int, barChartConf string, correlationChart *ChartInfoCorrelation, correlationUpdateCols []string) (err error) {
  1469. o := orm.NewOrmUsingDB("data")
  1470. to, err := o.Begin()
  1471. if err != nil {
  1472. return
  1473. }
  1474. defer func() {
  1475. if err != nil {
  1476. _ = to.Rollback()
  1477. } else {
  1478. _ = to.Commit()
  1479. }
  1480. }()
  1481. var pars []interface{}
  1482. pars = append(pars, req.ChartName)
  1483. pars = append(pars, edbInfoIdStr)
  1484. pars = append(pars, req.ChartType)
  1485. pars = append(pars, req.ChartClassifyId)
  1486. pars = append(pars, disabled)
  1487. pars = append(pars, barChartConf)
  1488. sql := ` UPDATE chart_info
  1489. SET
  1490. chart_name =?,
  1491. edb_info_ids=?,
  1492. chart_type=?,
  1493. chart_classify_id = ?,
  1494. modify_time = NOW(),
  1495. disabled = ?,
  1496. bar_config = ?
  1497. `
  1498. if calendar != "" {
  1499. sql += `,calendar = ? `
  1500. pars = append(pars, calendar)
  1501. }
  1502. if dateType > 0 {
  1503. sql += `,date_type = ? `
  1504. pars = append(pars, dateType)
  1505. }
  1506. sql += `,start_date = ? `
  1507. pars = append(pars, req.StartDate)
  1508. sql += `,end_date = ? `
  1509. pars = append(pars, req.EndDate)
  1510. sql += `,season_start_date = ? `
  1511. pars = append(pars, req.StartDate)
  1512. sql += `,season_end_date = ? `
  1513. pars = append(pars, req.EndDate)
  1514. sql += `,left_min = ? `
  1515. pars = append(pars, req.LeftMin)
  1516. sql += `,left_max = ? `
  1517. pars = append(pars, req.LeftMax)
  1518. sql += `,right_min = ? `
  1519. pars = append(pars, req.RightMin)
  1520. sql += `,right_max = ? `
  1521. pars = append(pars, req.RightMax)
  1522. sql += `WHERE chart_info_id = ?`
  1523. pars = append(pars, req.ChartInfoId)
  1524. _, err = to.Raw(sql, pars).Exec()
  1525. if err != nil {
  1526. fmt.Println("UPDATE chart_info Err:", err.Error())
  1527. return err
  1528. }
  1529. chartEdbMappingIdList := make([]string, 0)
  1530. for _, v := range req.CorrelationChartInfo.EdbInfoIdList {
  1531. // 查询该指标是否存在,如果存在的话,那么就去修改,否则新增
  1532. var tmpChartEdbMapping *ChartEdbMapping
  1533. csql := `SELECT * FROM chart_edb_mapping WHERE chart_info_id=? AND edb_info_id=? AND source = ? `
  1534. err = to.Raw(csql, req.ChartInfoId, v.EdbInfoId, utils.CHART_SOURCE_CORRELATION).QueryRow(&tmpChartEdbMapping)
  1535. if err != nil && err.Error() != utils.ErrNoRow() {
  1536. fmt.Println("QueryRow Err:", err.Error())
  1537. return err
  1538. }
  1539. if tmpChartEdbMapping != nil {
  1540. chartEdbMappingIdList = append(chartEdbMappingIdList, strconv.Itoa(tmpChartEdbMapping.ChartEdbMappingId))
  1541. //tmpChartEdbMapping.ModifyTime = time.Now()
  1542. //tmpChartEdbMapping.MaxData = v.MaxData
  1543. //tmpChartEdbMapping.MinData = v.MinData
  1544. //tmpChartEdbMapping.IsOrder = v.IsOrder
  1545. //tmpChartEdbMapping.IsAxis = v.IsAxis
  1546. //tmpChartEdbMapping.EdbInfoType = v.EdbInfoType
  1547. //tmpChartEdbMapping.LeadValue = v.LeadValue
  1548. //tmpChartEdbMapping.LeadUnit = v.LeadUnit
  1549. //tmpChartEdbMapping.ChartStyle = v.ChartStyle
  1550. //tmpChartEdbMapping.ChartColor = v.ChartColor
  1551. //tmpChartEdbMapping.PredictChartColor = v.PredictChartColor
  1552. //tmpChartEdbMapping.ChartWidth = v.ChartWidth
  1553. //_, err = to.Update(tmpChartEdbMapping, "ModifyTime", "MaxData", "MinData", "IsOrder", "IsAxis", "EdbInfoType", "LeadValue", "LeadUnit", "ChartStyle", "ChartColor", "PredictChartColor", "ChartWidth")
  1554. //if err != nil {
  1555. // fmt.Println("chart_edb_mapping Err:" + err.Error())
  1556. // return err
  1557. //}
  1558. } else {
  1559. mapItem := new(ChartEdbMapping)
  1560. mapItem.ChartInfoId = req.ChartInfoId
  1561. mapItem.EdbInfoId = v.EdbInfoId
  1562. mapItem.CreateTime = time.Now()
  1563. mapItem.ModifyTime = time.Now()
  1564. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  1565. mapItem.UniqueCode = utils.MD5(utils.CHART_PREFIX + "_" + timestamp + "_" + strconv.Itoa(v.EdbInfoId))
  1566. //mapItem.MaxData = v.MaxData
  1567. //mapItem.MinData = v.MinData
  1568. mapItem.IsOrder = true
  1569. mapItem.IsAxis = 1
  1570. mapItem.EdbInfoType = 1
  1571. //mapItem.LeadValue = v.LeadValue
  1572. //mapItem.LeadUnit = v.LeadUnit
  1573. //mapItem.ChartStyle = v.ChartStyle
  1574. //mapItem.ChartColor = v.ChartColor
  1575. //mapItem.PredictChartColor = v.PredictChartColor
  1576. //mapItem.ChartWidth = v.ChartWidth
  1577. mapItem.Source = utils.CHART_SOURCE_CORRELATION
  1578. tmpId, err := to.Insert(mapItem)
  1579. if err != nil {
  1580. fmt.Println("AddChartEdbMapping Err:" + err.Error())
  1581. return err
  1582. }
  1583. mapItem.ChartEdbMappingId = int(tmpId)
  1584. chartEdbMappingIdList = append(chartEdbMappingIdList, strconv.Itoa(mapItem.ChartEdbMappingId))
  1585. }
  1586. }
  1587. if len(chartEdbMappingIdList) > 0 {
  1588. chartEdbMappingIdStr := strings.Join(chartEdbMappingIdList, ",")
  1589. dsql := `DELETE FROM chart_edb_mapping WHERE chart_info_id=? AND chart_edb_mapping_id NOT IN(` + chartEdbMappingIdStr + `)`
  1590. _, err = to.Raw(dsql, req.ChartInfoId).Exec()
  1591. if err != nil {
  1592. fmt.Println("delete err:" + err.Error())
  1593. return err
  1594. }
  1595. }
  1596. // 相关性图表
  1597. _, err = to.Update(correlationChart, correlationUpdateCols...)
  1598. return
  1599. }
  1600. // PreviewSectionScatterChartReq 预览截面散点图的请求
  1601. type PreviewSectionScatterChartReq struct {
  1602. ChartName string `description:"图表名称"`
  1603. ChartClassifyId int `description:"分类id"`
  1604. ExtraConfig string `description:"图表额外配置信息,json字符串"`
  1605. }
  1606. // SectionScatterReq 截面散点请求
  1607. type SectionScatterReq struct {
  1608. XName string `description:"x轴名称"`
  1609. XNameEn string `description:"x轴名称(英文)"`
  1610. XUnitName string `description:"x轴单位名称"`
  1611. XUnitNameEn string `description:"x轴单位名称(英文)"`
  1612. YName string `description:"y轴名称"`
  1613. YNameEn string `description:"y轴名称(英文)"`
  1614. YUnitName string `description:"y轴单位名称"`
  1615. YUnitNameEn string `description:"y轴单位名称(英文)"`
  1616. XMinValue string `description:"X轴的最小值"`
  1617. XMaxValue string `description:"X轴的最大值"`
  1618. YMinValue string `description:"Y轴的最小值"`
  1619. YMaxValue string `description:"Y轴的最大值"`
  1620. //EdbList []SectionScatterEdbItemReq `description:"指标数据"`
  1621. SeriesList []SectionScatterSeriesItemReq `description:"系列数据"`
  1622. }
  1623. // SectionScatterSeriesItemReq 系列的请求
  1624. type SectionScatterSeriesItemReq struct {
  1625. Name string `description:"系列名"`
  1626. NameEn string `description:"系列名(英文名)"`
  1627. IsNameDefault bool `description:"是否使用默认的系列名 false修改过 true默认 影响自动更新"`
  1628. Color string `description:"颜色"`
  1629. EdbInfoList []SectionScatterEdbItemReq
  1630. ShowTrendLine bool `description:"是否展示趋势线"`
  1631. ShowFitEquation bool `description:"是否展示方程式"`
  1632. ShowRSquare bool `description:"是否展示R平方"`
  1633. }
  1634. // SectionScatterEdbItemReq 截面散点请求的指标
  1635. type SectionScatterEdbItemReq struct {
  1636. XEdbInfoId int `description:"X轴的指标ID"`
  1637. YEdbInfoId int `description:"Y轴的指标ID"`
  1638. Name string `description:"别名"`
  1639. NameEn string `description:"英文别名"`
  1640. XDateType int `description:"X轴的日期配置类型"`
  1641. XDate string `description:"X轴的日期固定日期"`
  1642. XDateValue int `description:"X轴的日期N天的值"`
  1643. YDateType int `description:"Y轴的日期配置类型"`
  1644. YDate string `description:"Y轴的日期固定日期"`
  1645. YDateValue int `description:"Y轴的日期N天的值"`
  1646. IsShow bool `description:"是否展示"`
  1647. }
  1648. // SectionScatterInfoResp 截面散点图数据
  1649. type SectionScatterInfoResp struct {
  1650. XName string `description:"x轴名称"`
  1651. XNameEn string `description:"x轴名称(英文)"`
  1652. XUnitName string `description:"x轴单位名称"`
  1653. XUnitNameEn string `description:"x轴单位名称(英文)"`
  1654. YName string `description:"y轴名称"`
  1655. YNameEn string `description:"y轴名称(英文)"`
  1656. YUnitName string `description:"y轴单位名称"`
  1657. YUnitNameEn string `description:"y轴单位名称(英文)"`
  1658. XMinValue string `description:"X轴的最小值"`
  1659. XMaxValue string `description:"X轴的最大值"`
  1660. YMinValue string `description:"Y轴的最小值"`
  1661. YMaxValue string `description:"Y轴的最大值"`
  1662. DataList []SectionScatterSeriesItemResp `description:"数据列"`
  1663. }
  1664. // SectionScatterSeriesItemResp 系列的返回
  1665. type SectionScatterSeriesItemResp struct {
  1666. Name string `description:"系列名"`
  1667. NameEn string `description:"系列名(英文)"`
  1668. IsNameDefault bool `description:"是否使用默认的系列名 false修改过 true默认 影响自动更新"`
  1669. Color string `description:"颜色"`
  1670. EdbInfoList []SectionScatterEdbItemResp
  1671. ShowTrendLine bool `description:"是否展示趋势线"`
  1672. ShowFitEquation bool `description:"是否展示方程式"`
  1673. ShowRSquare bool `description:"是否展示R平方"`
  1674. TrendLine string `description:"方程式"`
  1675. RSquare string `description:"R平方的值(决定系数R2)"`
  1676. TrendLimitData []CoordinatePoint `description:"趋势线的前后坐标点"`
  1677. }
  1678. // SectionScatterEdbItemResp 截面散点的返回参数
  1679. type SectionScatterEdbItemResp struct {
  1680. XEdbInfoId int `description:"X轴指标id"`
  1681. XDate string `description:"X轴指标实际日期"`
  1682. XName string `description:"X轴指标名称"`
  1683. XNameEn string `description:"X轴指标英文名称"`
  1684. XValue float64 `description:"X轴实际值"`
  1685. YEdbInfoId int `description:"Y轴指标id"`
  1686. YDate string `description:"Y轴指标实际日期"`
  1687. YName string `description:"Y轴指标名称"`
  1688. YNameEn string `description:"Y轴指标英文名称"`
  1689. YValue float64 `description:"Y轴实际值"`
  1690. IsShow bool `description:"是否展示"`
  1691. Name string `description:"标签名称"`
  1692. NameEn string `description:"英文标签名称"`
  1693. }
  1694. // CoordinatePoint 坐标点
  1695. type CoordinatePoint struct {
  1696. X float64
  1697. Y float64
  1698. }
  1699. // RollingCorrelationChartDataResp 滚动相关性图
  1700. type RollingCorrelationChartDataResp struct {
  1701. XDateTimeValue []string `description:"滚动相关性图的x轴数据,日期数据"`
  1702. YDataList []YData `description:"滚动相关性图的y轴数据"`
  1703. }
  1704. // GetChartInfoAll 用于分类展示
  1705. // @param source int 1:ETA图库;2:商品价格曲线
  1706. func GetChartInfoAllByClassifyId(source, classifyId int) (items []*ChartClassifyItems, err error) {
  1707. o := orm.NewOrmUsingDB("data")
  1708. sql := ` SELECT chart_info_id,chart_classify_id,chart_name AS chart_classify_name,chart_name_en AS chart_classify_name_en,
  1709. unique_code,sys_user_id,sys_user_real_name,date_type,start_date,end_date,chart_type,calendar,season_start_date,season_end_date
  1710. FROM chart_info WHERE chart_classify_id = ? AND source = ? ORDER BY sort asc,create_time DESC `
  1711. _, err = o.Raw(sql, classifyId, source).QueryRows(&items)
  1712. return
  1713. }
  1714. // ProfitFutureGoodChartResp 商品利润图
  1715. type ProfitFutureGoodChartResp struct {
  1716. XDataList []XData
  1717. YDataList []YData
  1718. ProfitName string `description:"利润的名称"`
  1719. ProfitNameEn string `description:"利润的英文名称"`
  1720. }
  1721. func FIXChartClassifyId(newId, oldId int) (err error) {
  1722. o := orm.NewOrmUsingDB("data")
  1723. sql := ` UPDATE chart_info SET chart_classify_id=? WHERE chart_classify_id=? `
  1724. _, err = o.Raw(sql, newId, oldId).Exec()
  1725. return
  1726. }
  1727. // GetChartInfoByAdminIdAndClassify 获取所有我创建的图表,用于分类展示
  1728. func GetChartInfoByAdminIdAndClassify(sourceList []int, adminId, classifyId int) (items []*ChartClassifyItems, err error) {
  1729. num := len(sourceList)
  1730. if num <= 0 {
  1731. return
  1732. }
  1733. o := orm.NewOrmUsingDB("data")
  1734. sql := ` SELECT chart_info_id,chart_classify_id,chart_name AS chart_classify_name,
  1735. unique_code,sys_user_id,sys_user_real_name,date_type,start_date,end_date,chart_type,calendar,season_start_date,season_end_date
  1736. FROM chart_info where source in (` + utils.GetOrmInReplace(num) + `) AND sys_user_id = ? AND chart_classify_id = ? ORDER BY sort asc,create_time ASC `
  1737. _, err = o.Raw(sql, sourceList, adminId, classifyId).QueryRows(&items)
  1738. return
  1739. }
  1740. // GetChartInfoAdminList 根据条件获取图表数据了列表
  1741. func GetChartInfoAdminList() (items []int, err error) {
  1742. o := orm.NewOrmUsingDB("data")
  1743. sql := ` SELECT sys_user_id FROM chart_info GROUP BY sys_user_id `
  1744. _, err = o.Raw(sql).QueryRows(&items)
  1745. return
  1746. }
  1747. // EditChartInfoExtraConfig 修改 ETA图库 的 图表额外配置
  1748. func EditChartInfoExtraConfig(chartId int, extraConfig string) (err error) {
  1749. o := orm.NewOrmUsingDB("data")
  1750. var pars []interface{}
  1751. pars = append(pars, extraConfig)
  1752. sql := ` UPDATE chart_info
  1753. SET
  1754. modify_time = NOW(),
  1755. extra_config = ?
  1756. `
  1757. sql += `WHERE chart_info_id = ?`
  1758. pars = append(pars, chartId)
  1759. _, err = o.Raw(sql, pars).Exec()
  1760. if err != nil {
  1761. fmt.Println("UPDATE chart_info Err:", err.Error())
  1762. return err
  1763. }
  1764. return
  1765. }
  1766. // PreviewRadarChartReq 预览雷达图的请求入参
  1767. type PreviewRadarChartReq struct {
  1768. ChartEdbInfoList []*ChartSaveItem `description:"指标及配置信息"`
  1769. ExtraConfig string `description:"图表额外配置信息,json字符串"`
  1770. }
  1771. // RadarChartInfoReq 雷达图预览请求数据
  1772. type RadarChartInfoReq struct {
  1773. DateList []RadarChartInfoDateReq `description:"日期配置"`
  1774. }
  1775. // RadarChartInfoEdbItemReq 雷达图预览请求数据(指标相关)
  1776. type RadarChartInfoEdbItemReq struct {
  1777. EdbInfoId int `description:"指标ID"`
  1778. Name string `description:"别名"`
  1779. //NameEn string `description:"英文别名"`
  1780. //Source int `description:"1:ETA图库;2:商品价格"`
  1781. }
  1782. // RadarChartInfoDateReq 雷达图预览请求数据(日期相关)
  1783. type RadarChartInfoDateReq struct {
  1784. Type int `description:"配置类型"`
  1785. Date string `description:"固定日期"`
  1786. Value int `description:"N天的值"`
  1787. Color string `description:"颜色"`
  1788. Name string `description:"别名"`
  1789. }
  1790. // RadarChartInfoResp 雷达图数据
  1791. type RadarChartInfoResp struct {
  1792. YDataList []RadarYData `description:"数据列"`
  1793. XEdbIdValue []int
  1794. }
  1795. // RadarYData 雷达图的y轴数据
  1796. type RadarYData struct {
  1797. Date string `description:"数据日期"`
  1798. Color string `description:"数据颜色"`
  1799. Name string `description:"别名"`
  1800. Value []float64 `description:"每个指标的值"`
  1801. }