chart_info.go 77 KB

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