chart_info.go 77 KB

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