chart_info.go 76 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001
  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. tmpId, err := to.Insert(mapItem)
  789. if err != nil {
  790. fmt.Println("AddChartEdbMapping Err:" + err.Error())
  791. return err
  792. }
  793. mapItem.ChartEdbMappingId = int(tmpId)
  794. chartEdbMappingIdList = append(chartEdbMappingIdList, strconv.Itoa(mapItem.ChartEdbMappingId))
  795. }
  796. }
  797. if len(chartEdbMappingIdList) > 0 {
  798. chartEdbMappingIdStr := strings.Join(chartEdbMappingIdList, ",")
  799. dsql := `DELETE FROM chart_edb_mapping WHERE chart_info_id=? AND chart_edb_mapping_id NOT IN(` + chartEdbMappingIdStr + `)`
  800. _, err = to.Raw(dsql, req.ChartInfoId).Exec()
  801. if err != nil {
  802. fmt.Println("delete err:" + err.Error())
  803. return err
  804. }
  805. }
  806. return
  807. }
  808. // EditFutureGoodChartInfoAndMapping 修改商品价格曲线的 图表与指标 的关系
  809. func EditFutureGoodChartInfoAndMapping(req *EditChartInfoReq, edbInfoIdStr string, calendar string, dateType, disabled int, barChartConf string) (err error) {
  810. o := orm.NewOrmUsingDB("data")
  811. to, err := o.Begin()
  812. if err != nil {
  813. return
  814. }
  815. defer func() {
  816. if err != nil {
  817. _ = to.Rollback()
  818. } else {
  819. _ = to.Commit()
  820. }
  821. }()
  822. var pars []interface{}
  823. pars = append(pars, req.ChartName)
  824. pars = append(pars, edbInfoIdStr)
  825. pars = append(pars, req.ChartType)
  826. pars = append(pars, req.ChartClassifyId)
  827. pars = append(pars, disabled)
  828. pars = append(pars, barChartConf)
  829. sql := ` UPDATE chart_info
  830. SET
  831. chart_name =?,
  832. edb_info_ids=?,
  833. chart_type=?,
  834. chart_classify_id = ?,
  835. modify_time = NOW(),
  836. disabled = ?,
  837. bar_config = ?
  838. `
  839. if calendar != "" {
  840. sql += `,calendar = ? `
  841. pars = append(pars, calendar)
  842. }
  843. if dateType > 0 {
  844. sql += `,date_type = ? `
  845. pars = append(pars, dateType)
  846. }
  847. sql += `,start_date = ? `
  848. pars = append(pars, req.StartDate)
  849. sql += `,end_date = ? `
  850. pars = append(pars, req.EndDate)
  851. sql += `,season_start_date = ? `
  852. pars = append(pars, req.StartDate)
  853. sql += `,season_end_date = ? `
  854. pars = append(pars, req.EndDate)
  855. sql += `,left_min = ? `
  856. pars = append(pars, req.LeftMin)
  857. sql += `,left_max = ? `
  858. pars = append(pars, req.LeftMax)
  859. sql += `,right_min = ? `
  860. pars = append(pars, req.RightMin)
  861. sql += `,right_max = ? `
  862. pars = append(pars, req.RightMax)
  863. sql += `,right2_min = ? `
  864. pars = append(pars, req.Right2Min)
  865. sql += `,right2_max = ? `
  866. pars = append(pars, req.Right2Max)
  867. sql += `WHERE chart_info_id = ?`
  868. pars = append(pars, req.ChartInfoId)
  869. _, err = to.Raw(sql, pars).Exec()
  870. if err != nil {
  871. fmt.Println("UPDATE chart_info Err:", err.Error())
  872. return err
  873. }
  874. chartEdbMappingIdList := make([]string, 0)
  875. for _, v := range req.BarChartInfo.EdbInfoIdList {
  876. // 查询该指标是否存在,如果存在的话,那么就去修改,否则新增
  877. var tmpChartEdbMapping *ChartEdbMapping
  878. csql := `SELECT * FROM chart_edb_mapping WHERE chart_info_id=? AND edb_info_id=? AND source = ? `
  879. err = to.Raw(csql, req.ChartInfoId, v.EdbInfoId, v.Source).QueryRow(&tmpChartEdbMapping)
  880. if err != nil && err.Error() != utils.ErrNoRow() {
  881. fmt.Println("QueryRow Err:", err.Error())
  882. return err
  883. }
  884. if tmpChartEdbMapping != nil {
  885. chartEdbMappingIdList = append(chartEdbMappingIdList, strconv.Itoa(tmpChartEdbMapping.ChartEdbMappingId))
  886. //tmpChartEdbMapping.ModifyTime = time.Now()
  887. //tmpChartEdbMapping.MaxData = v.MaxData
  888. //tmpChartEdbMapping.MinData = v.MinData
  889. //tmpChartEdbMapping.IsOrder = v.IsOrder
  890. //tmpChartEdbMapping.IsAxis = v.IsAxis
  891. //tmpChartEdbMapping.EdbInfoType = v.EdbInfoType
  892. //tmpChartEdbMapping.LeadValue = v.LeadValue
  893. //tmpChartEdbMapping.LeadUnit = v.LeadUnit
  894. //tmpChartEdbMapping.ChartStyle = v.ChartStyle
  895. //tmpChartEdbMapping.ChartColor = v.ChartColor
  896. //tmpChartEdbMapping.PredictChartColor = v.PredictChartColor
  897. //tmpChartEdbMapping.ChartWidth = v.ChartWidth
  898. //_, err = to.Update(tmpChartEdbMapping, "ModifyTime", "MaxData", "MinData", "IsOrder", "IsAxis", "EdbInfoType", "LeadValue", "LeadUnit", "ChartStyle", "ChartColor", "PredictChartColor", "ChartWidth")
  899. //if err != nil {
  900. // fmt.Println("chart_edb_mapping Err:" + err.Error())
  901. // return err
  902. //}
  903. } else {
  904. mapItem := new(ChartEdbMapping)
  905. mapItem.ChartInfoId = req.ChartInfoId
  906. mapItem.EdbInfoId = v.EdbInfoId
  907. mapItem.CreateTime = time.Now()
  908. mapItem.ModifyTime = time.Now()
  909. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  910. mapItem.UniqueCode = utils.MD5(utils.CHART_PREFIX + "_" + timestamp + "_" + strconv.Itoa(v.EdbInfoId))
  911. //mapItem.MaxData = v.MaxData
  912. //mapItem.MinData = v.MinData
  913. mapItem.IsOrder = true
  914. mapItem.IsAxis = 1
  915. mapItem.EdbInfoType = 1
  916. //mapItem.LeadValue = v.LeadValue
  917. //mapItem.LeadUnit = v.LeadUnit
  918. //mapItem.ChartStyle = v.ChartStyle
  919. //mapItem.ChartColor = v.ChartColor
  920. //mapItem.PredictChartColor = v.PredictChartColor
  921. //mapItem.ChartWidth = v.ChartWidth
  922. mapItem.Source = v.Source
  923. tmpId, err := to.Insert(mapItem)
  924. if err != nil {
  925. fmt.Println("AddChartEdbMapping Err:" + err.Error())
  926. return err
  927. }
  928. mapItem.ChartEdbMappingId = int(tmpId)
  929. chartEdbMappingIdList = append(chartEdbMappingIdList, strconv.Itoa(mapItem.ChartEdbMappingId))
  930. }
  931. }
  932. if len(chartEdbMappingIdList) > 0 {
  933. chartEdbMappingIdStr := strings.Join(chartEdbMappingIdList, ",")
  934. dsql := `DELETE FROM chart_edb_mapping WHERE chart_info_id=? AND chart_edb_mapping_id NOT IN(` + chartEdbMappingIdStr + `)`
  935. _, err = to.Raw(dsql, req.ChartInfoId).Exec()
  936. if err != nil {
  937. fmt.Println("delete err:" + err.Error())
  938. return err
  939. }
  940. }
  941. return
  942. }
  943. func EditChartEnInfoAndEdbEnInfo(req *EditChartEnInfoReq) (err error) {
  944. o := orm.NewOrmUsingDB("data")
  945. to, err := o.Begin()
  946. if err != nil {
  947. return
  948. }
  949. defer func() {
  950. if err != nil {
  951. _ = to.Rollback()
  952. } else {
  953. _ = to.Commit()
  954. }
  955. }()
  956. var pars []interface{}
  957. updateField := ` chart_name_en =?, `
  958. pars = append(pars, req.ChartNameEn)
  959. if req.ExtraConfig != `` {
  960. updateField += ` extra_config =?, `
  961. pars = append(pars, req.ExtraConfig)
  962. }
  963. sql := ` UPDATE chart_info
  964. SET ` + updateField + ` modify_time = NOW()
  965. WHERE chart_info_id = ?`
  966. pars = append(pars, req.ChartInfoId)
  967. _, err = to.Raw(sql, pars).Exec()
  968. if err != nil {
  969. fmt.Println("UPDATE chart_info Err:", err.Error())
  970. return err
  971. }
  972. var edbInfoIdArr []string
  973. for _, v := range req.ChartEdbInfoList {
  974. edbInfoIdArr = append(edbInfoIdArr, strconv.Itoa(v.EdbInfoId))
  975. var count int
  976. csql := `SELECT COUNT(1) AS count FROM chart_edb_mapping WHERE chart_info_id=? AND edb_info_id=? `
  977. err = to.Raw(csql, req.ChartInfoId, v.EdbInfoId).QueryRow(&count)
  978. if err != nil {
  979. fmt.Println("QueryRow Err:", err.Error())
  980. return err
  981. }
  982. if count > 0 {
  983. msql := ` UPDATE edb_info
  984. SET
  985. edb_name_en =?,
  986. unit_en = ?,
  987. modify_time = NOW()
  988. WHERE edb_info_id = ? `
  989. _, err = to.Raw(msql, v.EdbNameEn, v.UnitEn, v.EdbInfoId).Exec()
  990. if err != nil {
  991. fmt.Println("edb_info Err:" + err.Error())
  992. return err
  993. }
  994. }
  995. }
  996. return
  997. }
  998. func ModifyEdbDatadTimestamp(source, subSource, edbDataId int, dataTimestamp int64) (err error) {
  999. tableName := GetEdbDataTableName(source, subSource)
  1000. sql := `UPDATE %s SET data_timestamp=? WHERE edb_data_id=? `
  1001. sql = fmt.Sprintf(sql, tableName)
  1002. o := orm.NewOrmUsingDB("data")
  1003. _, err = o.Raw(sql, dataTimestamp, edbDataId).Exec()
  1004. return
  1005. }
  1006. type AddChartInfoReq struct {
  1007. ChartEdbInfoList []*ChartSaveItem `description:"指标及配置信息"`
  1008. ChartClassifyId int `description:"分类id"`
  1009. ChartName string `description:"图表名称"`
  1010. ChartType int `description:"生成样式:1:曲线图,2:季节性图,3:面积图,4:柱状图,5:散点图,6:组合图,7:柱方图"`
  1011. DateType int `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:起始日期至今"`
  1012. StartDate string `description:"自定义开始日期"`
  1013. EndDate string `description:"自定义结束日期"`
  1014. Calendar string `description:"公历/农历"`
  1015. LeftMin string `description:"图表左侧最小值"`
  1016. LeftMax string `description:"图表左侧最大值"`
  1017. RightMin string `description:"图表右侧最小值"`
  1018. RightMax string `description:"图表右侧最大值"`
  1019. Right2Min string `description:"图表右侧2最小值"`
  1020. Right2Max string `description:"图表右侧2最大值"`
  1021. BarChartInfo BarChartInfoReq `description:"柱方图的配置"`
  1022. CorrelationChartInfo CorrelationChartInfoReq `description:"相关性图表配置"`
  1023. ExtraConfig string `description:"图表额外配置信息,json字符串"`
  1024. ChartImage string `description:"封面图" json:"-"`
  1025. SeasonExtraConfig SeasonExtraItem `description:"季节性图表中的配置,json数据"`
  1026. StartYear int `description:"当选择的日期类型为最近N年类型时,即date_type=20, 用start_year表示N"`
  1027. ChartThemeId int `description:"图表应用主题ID"`
  1028. SourcesFrom string `description:"图表来源"`
  1029. Instructions string `description:"图表说明"`
  1030. MarkersLines string `description:"标识线"`
  1031. MarkersAreas string `description:"标识区"`
  1032. Unit string `description:"中文单位名称"`
  1033. UnitEn string `description:"英文单位名称"`
  1034. }
  1035. type PreviewChartInfoReq struct {
  1036. ChartEdbInfoList []*ChartSaveItem `description:"指标及配置信息"`
  1037. DateType int `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:起始日期至今 20:最近N年"`
  1038. ChartType int `description:"生成样式:1:曲线图,2:季节性图,3:面积图,4:柱状图,5:散点图,6:组合图,7:柱方图"`
  1039. StartDate string `description:"自定义开始日期"`
  1040. EndDate string `description:"自定义结束日期"`
  1041. Calendar string `description:"公历/农历"`
  1042. SeasonExtraConfig SeasonExtraItem `description:"季节性图表中的配置,json数据"`
  1043. StartYear int `description:"当选择的日期类型为最近N年类型时,即date_type=20, 用start_year表示N"`
  1044. }
  1045. type SeasonExtraItem struct {
  1046. ChartLegend []SeasonChartLegend `description:"自定义的图例名称"`
  1047. XStartDate string `description:"横坐标显示的起始日"`
  1048. XEndDate string `description:"横坐标显示的截止日"`
  1049. JumpYear int `description:"横坐标日期是否跨年,1跨年,0不跨年"`
  1050. }
  1051. type SeasonChartLegend struct {
  1052. Name string
  1053. Value string
  1054. }
  1055. type AddChartInfoResp struct {
  1056. ChartInfoId int `description:"图表id"`
  1057. UniqueCode string `description:"图表唯一编码"`
  1058. ChartType int `description:"生成样式:1:曲线图,2:季节性图"`
  1059. }
  1060. type QuarterDataList []*QuarterData
  1061. func (m QuarterDataList) Len() int {
  1062. return len(m)
  1063. }
  1064. func (m QuarterDataList) Less(i, j int) bool {
  1065. return m[i].Years < m[j].Years
  1066. }
  1067. func (m QuarterDataList) Swap(i, j int) {
  1068. m[i], m[j] = m[j], m[i]
  1069. }
  1070. // 判断图表指标是否已经存在
  1071. func ChartInfoExist(condition, edbInfoIdStr string) (count int, err error) {
  1072. sql := `SELECT COUNT(1) AS count FROM (
  1073. SELECT GROUP_CONCAT(edb_info_id ORDER BY edb_info_id ASC SEPARATOR ',') AS edb_info_id_str
  1074. FROM chart_edb_mapping AS a
  1075. WHERE 1=1`
  1076. if condition != "" {
  1077. sql += condition
  1078. }
  1079. sql += ` GROUP BY chart_info_id
  1080. )AS t
  1081. WHERE t.edb_info_id_str=?
  1082. GROUP BY t.edb_info_id_str `
  1083. o := orm.NewOrmUsingDB("data")
  1084. err = o.Raw(sql, edbInfoIdStr).QueryRow(&count)
  1085. return
  1086. }
  1087. func ChartInfoSearchByKeyWord(keyword string, showSysId int) (searchList []*ChartInfo, err error) {
  1088. o := orm.NewOrmUsingDB("data")
  1089. sql := ` SELECT * FROM chart_info WHERE 1=1 `
  1090. var pars []interface{}
  1091. if keyword != "" {
  1092. sql += `AND chart_name LIKE ? `
  1093. pars = append(pars, utils.GetLikeKeyword(keyword))
  1094. }
  1095. if showSysId > 0 {
  1096. sql += ` AND sys_user_id = ? `
  1097. pars = append(pars, showSysId)
  1098. }
  1099. sql += ` ORDER BY create_time DESC `
  1100. if keyword == "" {
  1101. sql += ` LIMIT 100 `
  1102. }
  1103. _, err = o.Raw(sql, pars).QueryRows(&searchList)
  1104. return
  1105. }
  1106. // ChartInfoSearchByEmptyKeyWord 没有关键字的时候获取默认100条数据
  1107. func ChartInfoSearchByEmptyKeyWord(showSysId int, sourceList []int, noPermissionChartIdList []int, startSize, pageSize int) (total int64, searchList []*ChartInfo, err error) {
  1108. num := len(sourceList)
  1109. o := orm.NewOrmUsingDB("data")
  1110. baseSql := ` FROM chart_info WHERE 1=1 AND source in (` + utils.GetOrmInReplace(num) + `)`
  1111. var basePars []interface{}
  1112. basePars = append(basePars, sourceList)
  1113. if showSysId > 0 {
  1114. baseSql += ` AND sys_user_id = ? `
  1115. basePars = append(basePars, showSysId)
  1116. }
  1117. lenNoPermissionChartIdList := len(noPermissionChartIdList)
  1118. if lenNoPermissionChartIdList > 0 {
  1119. baseSql += ` AND chart_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionChartIdList) + `) `
  1120. basePars = append(basePars, noPermissionChartIdList)
  1121. }
  1122. // 查找数量
  1123. totalSql := " SELECT count(1) as total " + baseSql
  1124. err = o.Raw(totalSql, basePars).QueryRow(&total)
  1125. if err != nil {
  1126. return
  1127. }
  1128. // 查找列表数据
  1129. sql := " SELECT * " + baseSql + ` ORDER BY create_time DESC LIMIT ?,? `
  1130. basePars = append(basePars, startSize, pageSize)
  1131. _, err = o.Raw(sql, basePars).QueryRows(&searchList)
  1132. return
  1133. }
  1134. func GetNextChartInfo(classifyId int) (item *ChartInfo, err error) {
  1135. o := orm.NewOrmUsingDB("data")
  1136. sql := ` SELECT b.* FROM chart_classify AS a
  1137. INNER JOIN chart_info AS b ON a.chart_classify_id=b.chart_classify_id
  1138. WHERE a.chart_classify_id>?
  1139. ORDER BY a.chart_classify_id ASC
  1140. LIMIT 1 `
  1141. err = o.Raw(sql, classifyId).QueryRow(&item)
  1142. return
  1143. }
  1144. // GetChartInfoRefreshData 获取图表关联的指标信息
  1145. func GetChartInfoRefreshData(chartInfoId int) (baseEdbInfoArr, calculateInfoArr []*EdbInfo, err error) {
  1146. o := orm.NewOrmUsingDB("data")
  1147. sql := ` SELECT b.* FROM chart_edb_mapping AS a
  1148. INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
  1149. WHERE a.chart_info_id=? `
  1150. edbInfoList := make([]*EdbInfo, 0)
  1151. _, err = o.Raw(sql, chartInfoId).QueryRows(&edbInfoList)
  1152. if err != nil {
  1153. return
  1154. }
  1155. for _, v := range edbInfoList {
  1156. fmt.Println(v.EdbInfoId, v.EdbType)
  1157. if v.EdbType == 1 {
  1158. baseEdbInfoArr = append(baseEdbInfoArr, v)
  1159. } else {
  1160. calculateInfoArr = append(calculateInfoArr, v)
  1161. newBaseEdbInfoArr, newCalculateInfoArr, err := GetChartRefreshEdbInfo(v.EdbInfoId, v.Source, 0)
  1162. if err != nil {
  1163. return baseEdbInfoArr, calculateInfoArr, err
  1164. }
  1165. baseEdbInfoArr = append(baseEdbInfoArr, newBaseEdbInfoArr...)
  1166. calculateInfoArr = append(calculateInfoArr, newCalculateInfoArr...)
  1167. }
  1168. }
  1169. return
  1170. }
  1171. func GetChartRefreshEdbInfo(edbInfoId, source, n int) (baseEdbInfoArr, calculateInfoArr []*EdbInfo, err error) {
  1172. calculateList, err := GetEdbInfoCalculateMap(edbInfoId, source)
  1173. if err != nil && err.Error() != utils.ErrNoRow() {
  1174. return
  1175. }
  1176. n++
  1177. for _, item := range calculateList {
  1178. fmt.Println(item.EdbInfoId)
  1179. if item.EdbType == 1 {
  1180. baseEdbInfoArr = append(baseEdbInfoArr, item)
  1181. } else {
  1182. calculateInfoArr = append(calculateInfoArr, item)
  1183. if n > 10 {
  1184. return
  1185. }
  1186. newBaseEdbInfoArr, newCalculateInfoArr, _ := GetChartRefreshEdbInfo(item.EdbInfoId, item.Source, n)
  1187. baseEdbInfoArr = append(baseEdbInfoArr, newBaseEdbInfoArr...)
  1188. calculateInfoArr = append(calculateInfoArr, newCalculateInfoArr...)
  1189. }
  1190. }
  1191. return
  1192. }
  1193. type SetChartInfoImageReq struct {
  1194. ChartInfoId int `description:"图表ID"`
  1195. ImageUrl string `description:"图表图片地址"`
  1196. }
  1197. func EditChartInfoImage(req *SetChartInfoImageReq) (err error) {
  1198. o := orm.NewOrmUsingDB("data")
  1199. sql := ` UPDATE chart_info SET chart_image=?, modify_time = NOW() WHERE chart_info_id = ? `
  1200. _, err = o.Raw(sql, req.ImageUrl, req.ChartInfoId).Exec()
  1201. if err != nil {
  1202. fmt.Println("EditChartInfoImage Err:", err.Error())
  1203. return err
  1204. }
  1205. return
  1206. }
  1207. type ChartInfoDetailFromUniqueCodeResp struct {
  1208. ChartInfo *ChartInfoView
  1209. Status bool `description:"true:图表存在,false:图表不存在"`
  1210. EdbInfoList []*ChartEdbInfoMapping
  1211. XEdbIdValue []int `description:"柱方图的x轴数据,指标id"`
  1212. YDataList []YData `description:"柱方图的y轴数据"`
  1213. XDataList []XData `description:"商品价格曲线的X轴数据"`
  1214. BarChartInfo BarChartInfoReq `description:"柱方图的配置"`
  1215. CorrelationChartInfo *CorrelationInfo `description:"相关性图表信息"`
  1216. DataResp interface{} `description:"图表数据,根据图的类型而定的,没有确定的数据格式"`
  1217. }
  1218. func GetChartInfoByUniqueCode(uniqueCode string) (item *ChartInfo, err error) {
  1219. o := orm.NewOrmUsingDB("data")
  1220. sql := ` SELECT * FROM chart_info WHERE unique_code=? `
  1221. err = o.Raw(sql, uniqueCode).QueryRow(&item)
  1222. return
  1223. }
  1224. func GetChartInfoViewByUniqueCode(uniqueCode string) (item *ChartInfoView, err error) {
  1225. o := orm.NewOrmUsingDB("data")
  1226. sql := ` SELECT * FROM chart_info WHERE unique_code=? `
  1227. err = o.Raw(sql, uniqueCode).QueryRow(&item)
  1228. return
  1229. }
  1230. // GetFirstChartInfoByClassifyId 获取当前分类下,且排序数相同 的排序第一条的数据
  1231. func GetFirstChartInfoByClassifyId(classifyId int) (item *ChartInfo, err error) {
  1232. o := orm.NewOrmUsingDB("data")
  1233. sql := ` SELECT * FROM chart_info WHERE chart_classify_id=? order by sort asc,chart_info_id asc limit 1`
  1234. err = o.Raw(sql, classifyId).QueryRow(&item)
  1235. return
  1236. }
  1237. // UpdateChartInfoSortByClassifyId 根据图表id更新排序
  1238. func UpdateChartInfoSortByClassifyId(classifyId, nowSort, prevChartInfoId int, sourceList []int, updateSort string) (err error) {
  1239. o := orm.NewOrmUsingDB("data")
  1240. num := len(sourceList)
  1241. if num <= 0 {
  1242. return
  1243. }
  1244. sql := ` update chart_info set sort = ` + updateSort + ` WHERE chart_classify_id=? AND source in (` + utils.GetOrmInReplace(num) + `) AND `
  1245. if prevChartInfoId > 0 {
  1246. sql += ` (sort > ? or (chart_info_id > ` + fmt.Sprint(prevChartInfoId) + ` and sort = ` + fmt.Sprint(nowSort) + `))`
  1247. }
  1248. _, err = o.Raw(sql, classifyId, sourceList, nowSort).Exec()
  1249. return
  1250. }
  1251. // Update 更新图表基础信息
  1252. func (chartInfo *ChartInfo) Update(cols []string) (err error) {
  1253. o := orm.NewOrmUsingDB("data")
  1254. _, err = o.Update(chartInfo, cols...)
  1255. return
  1256. }
  1257. type ChartInfoView struct {
  1258. ChartInfoId int `orm:"column(chart_info_id);pk"`
  1259. ChartName string `description:"来源名称"`
  1260. ChartNameEn string `description:"英文图表名称"`
  1261. Unit string `description:"中文单位名称"`
  1262. UnitEn string `description:"英文单位名称"`
  1263. ChartClassifyId int `description:"图表分类id"`
  1264. ChartClassifyName string `description:"图表名称"`
  1265. SysUserId int
  1266. SysUserRealName string
  1267. UniqueCode string `description:"图表唯一编码"`
  1268. CreateTime time.Time
  1269. ModifyTime time.Time
  1270. DateType int `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间"`
  1271. StartDate string `description:"自定义开始日期"`
  1272. EndDate string `description:"自定义结束日期"`
  1273. IsSetName int `description:"设置名称"`
  1274. EdbInfoIds string `description:"指标id"`
  1275. ChartType int `description:"生成样式:1:曲线图,2:季节性图"`
  1276. Calendar string `description:"公历/农历"`
  1277. SeasonStartDate string `description:"季节性图开始日期"`
  1278. SeasonEndDate string `description:"季节性图开始日期"`
  1279. ChartImage string `description:"图表图片"`
  1280. Sort int `description:"排序字段,数字越小越排前面"`
  1281. IsAdd bool `description:"true:已加入我的图库,false:未加入我的图库"`
  1282. MyChartId int
  1283. MyChartClassifyId string `description:"我的图表分类,多个用逗号隔开"`
  1284. ChartClassify []*ChartClassifyView
  1285. EdbEndDate string `description:"指标最新更新日期"`
  1286. LeftMin string `description:"图表左侧最小值"`
  1287. LeftMax string `description:"图表左侧最大值"`
  1288. RightMin string `description:"图表右侧最小值"`
  1289. RightMax string `description:"图表右侧最大值"`
  1290. Right2Min string `description:"图表右侧最小值"`
  1291. Right2Max string `description:"图表右侧最大值"`
  1292. MinMaxSave int `description:"是否手动保存过上下限:0-否;1-是"`
  1293. IsEdit bool `description:"是否有编辑权限"`
  1294. IsEnChart bool `description:"是否展示英文标识"`
  1295. WarnMsg string `description:"错误信息"`
  1296. Disabled int `description:"是否禁用,0:启用,1:禁用,默认:0"`
  1297. BarConfig string `description:"柱方图的配置,json数据" json:"-"`
  1298. Source int `description:"1:ETA图库;2:商品价格曲线;3:相关性图表"`
  1299. //CorrelationLeadUnit string `description:"相关性图表-领先单位"`
  1300. ExtraConfig string `description:"图表额外配置,json数据"`
  1301. ChartSource string `description:"图表来源str"`
  1302. ChartSourceEn string `description:"图表来源(英文)"`
  1303. Button ChartViewButton `description:"操作按钮"`
  1304. SeasonExtraConfig string `description:"季节性图表中的配置,json数据"`
  1305. StartYear int `description:"当选择的日期类型为最近N年类型时,即date_type=20, 用start_year表示N"`
  1306. ChartThemeId int `description:"图表应用主题ID"`
  1307. ChartThemeStyle string `description:"图表应用主题样式"`
  1308. SourcesFrom string `description:"图表来源"`
  1309. Instructions string `description:"图表说明"`
  1310. MarkersLines string `description:"标识线"`
  1311. MarkersAreas string `description:"标识区"`
  1312. }
  1313. type ChartViewButton struct {
  1314. IsEdit bool `description:"是否有编辑权限"`
  1315. IsEnChart bool `description:"是否展示英文标识"`
  1316. IsAdd bool `description:"true:已加入我的图库,false:未加入我的图库"`
  1317. IsCopy bool `description:"是否有另存为按钮"`
  1318. IsSetName int `description:"设置名称"`
  1319. }
  1320. type ImageSvgToPngResp struct {
  1321. Data struct {
  1322. ResourceURL string `json:"ResourceUrl"`
  1323. } `json:"Data"`
  1324. ErrCode string `json:"ErrCode"`
  1325. ErrMsg string `json:"ErrMsg"`
  1326. IsSendEmail bool `json:"IsSendEmail"`
  1327. Msg string `json:"Msg"`
  1328. Ret int64 `json:"Ret"`
  1329. Success bool `json:"Success"`
  1330. }
  1331. // GetChartInfoByClassifyIdAndName 根据分类id和图表名获取图表信息
  1332. func GetChartInfoByClassifyIdAndName(classifyId int, chartName string) (item *ChartInfo, err error) {
  1333. o := orm.NewOrmUsingDB("data")
  1334. sql := ` SELECT * FROM chart_info WHERE chart_classify_id = ? and chart_name=? `
  1335. err = o.Raw(sql, classifyId, chartName).QueryRow(&item)
  1336. return
  1337. }
  1338. // BatchChartRefreshReq 批量刷新图表请求
  1339. type BatchChartRefreshReq struct {
  1340. ChartInfoCode []string `description:"图表编码数组"`
  1341. ReportId int `description:"报告id"`
  1342. ReportChapterId int `description:"报告章节id"`
  1343. Source string `description:"来源,枚举值:report、english_report、smart_report"`
  1344. }
  1345. // GetChartInfoListByUniqueCodeSlice 根据图表编码获取图表列表数据
  1346. func GetChartInfoListByUniqueCodeSlice(uniqueCodeSlice []string) (total int64, items []*ChartInfo, err error) {
  1347. if len(uniqueCodeSlice) <= 0 {
  1348. return
  1349. }
  1350. o := orm.NewOrmUsingDB("data")
  1351. sql := ` SELECT * FROM chart_info WHERE unique_code in ("` + strings.Join(uniqueCodeSlice, `","`) + `") `
  1352. total, err = o.Raw(sql).QueryRows(&items)
  1353. return
  1354. }
  1355. // GetChartInfoRefreshDataByChartInfoIdSlice 根据图表id切片获取对应的指标数据
  1356. func GetChartInfoRefreshDataByChartInfoIdSlice(chartInfoIdSlice []string) (baseEdbInfoArr, calculateInfoArr []*EdbInfo, err error) {
  1357. o := orm.NewOrmUsingDB("data")
  1358. if len(chartInfoIdSlice) <= 0 {
  1359. return
  1360. }
  1361. sql := ` SELECT b.* FROM chart_edb_mapping AS a
  1362. INNER JOIN edb_info AS b ON a.edb_info_id=b.edb_info_id
  1363. WHERE a.chart_info_id in (` + strings.Join(chartInfoIdSlice, ",") + `) `
  1364. edbInfoList := make([]*EdbInfo, 0)
  1365. _, err = o.Raw(sql).QueryRows(&edbInfoList)
  1366. if err != nil {
  1367. return
  1368. }
  1369. for _, v := range edbInfoList {
  1370. if v.EdbType == 1 {
  1371. baseEdbInfoArr = append(baseEdbInfoArr, v)
  1372. } else {
  1373. calculateInfoArr = append(calculateInfoArr, v)
  1374. newBaseEdbInfoArr, newCalculateInfoArr, err := GetChartRefreshEdbInfo(v.EdbInfoId, v.Source, 0)
  1375. if err != nil {
  1376. return baseEdbInfoArr, calculateInfoArr, err
  1377. }
  1378. baseEdbInfoArr = append(baseEdbInfoArr, newBaseEdbInfoArr...)
  1379. calculateInfoArr = append(calculateInfoArr, newCalculateInfoArr...)
  1380. }
  1381. }
  1382. return
  1383. }
  1384. // CopyAddChartInfoReq 复制并新增图表
  1385. type CopyAddChartInfoReq struct {
  1386. ChartInfoId int `description:"待复制的图表id"`
  1387. ChartClassifyId int `description:"分类id"`
  1388. ChartName string `description:"图表名称"`
  1389. }
  1390. // ChartInfoListByEsResp 图表数据Es搜索返回
  1391. type ChartInfoListByEsResp struct {
  1392. Paging *paging.PagingItem
  1393. List []*ChartInfoMore
  1394. }
  1395. // GetChartInfoListByCondition 根据条件获取图表数据了列表
  1396. func GetChartInfoListByCondition(condition string, pars []interface{}, startSize, pageSize int) (items []*ChartInfo, err error) {
  1397. o := orm.NewOrmUsingDB("data")
  1398. sql := ` SELECT * FROM chart_info WHERE 1=1 `
  1399. if condition != "" {
  1400. sql += condition
  1401. }
  1402. sql += ` ORDER BY chart_info_id DESC LIMIT ?,? `
  1403. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  1404. return
  1405. }
  1406. // GetChartInfoListGroupByUserId 根据指标id列表、用户分组获取指标信息
  1407. func GetChartInfoListGroupByUserId(edbIdList []string) (items []*ChartInfo, err error) {
  1408. num := len(edbIdList)
  1409. if num <= 0 {
  1410. return
  1411. }
  1412. o := orm.NewOrmUsingDB("data")
  1413. sql := ` SELECT * FROM chart_info WHERE chart_info_id in (` + utils.GetOrmInReplace(num) + `) GROUP BY sys_user_id `
  1414. _, err = o.Raw(sql, edbIdList).QueryRows(&items)
  1415. return
  1416. }
  1417. // ModifyChartInfoUserIdByCodeList 根据指标code列表修改创建人
  1418. func ModifyChartInfoUserIdByCodeList(edbIdList []string, userId int, userName string) (err error) {
  1419. num := len(edbIdList)
  1420. if num <= 0 {
  1421. return
  1422. }
  1423. o := orm.NewOrmUsingDB("data")
  1424. sql := `UPDATE chart_info SET sys_user_id=?,sys_user_real_name=? WHERE chart_info_id in (` + utils.GetOrmInReplace(num) + `) `
  1425. _, err = o.Raw(sql, userId, userName, edbIdList).Exec()
  1426. return
  1427. }
  1428. // BarChartInfoReq 柱方图预览请求数据
  1429. type BarChartInfoReq struct {
  1430. EdbInfoIdList []BarChartInfoEdbItemReq `description:"指标信息"`
  1431. DateList []BarChartInfoDateReq `description:"日期配置"`
  1432. Sort BarChartInfoSortReq `description:"排序"`
  1433. XEdbList []BarChartInfoEdbItemReq `description:"X轴选择的指标列表"`
  1434. YEdbList []BarChartInfoEdbItemReq `description:"Y轴选择的指标列表"`
  1435. Unit string `description:"中文单位"`
  1436. UnitEn string `description:"英文单位"`
  1437. }
  1438. // BarChartInfoEdbItemReq 柱方图预览请求数据(指标相关)
  1439. type BarChartInfoEdbItemReq struct {
  1440. EdbInfoId int `description:"指标ID"`
  1441. Name string `description:"别名"`
  1442. NameEn string `description:"英文别名"`
  1443. Source int `description:"1:ETA图库;2:商品价格"`
  1444. }
  1445. // BarChartInfoDateReq 柱方图预览请求数据(日期相关)
  1446. type BarChartInfoDateReq struct {
  1447. Type int `description:"配置类型"`
  1448. Date string `description:"固定日期"`
  1449. Value int `description:"N天的值"`
  1450. Color string `description:"颜色"`
  1451. Name string `description:"别名"`
  1452. }
  1453. // BarChartInfoSortReq 柱方图预览请求数据(排序相关)
  1454. type BarChartInfoSortReq struct {
  1455. Sort int `description:"排序类型,0:默认,1:升序,2:降序"`
  1456. DateIndex int `description:"日期数据的下标,从0开始"`
  1457. }
  1458. // CorrelationChartInfoReq 相关性图表请求体
  1459. type CorrelationChartInfoReq struct {
  1460. LeadValue int `description:"领先期数"`
  1461. LeadUnit string `description:"频度"`
  1462. CalculateValue int `description:"计算窗口"`
  1463. CalculateUnit string `description:"计算频度"`
  1464. BaseCalculateValue int `description:"基础计算窗口(滚动相关性的时候用到)"`
  1465. BaseCalculateUnit string `description:"基础计算频度(滚动相关性的时候用到)"`
  1466. DateType int `description:"日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:起始日期至今"`
  1467. StartDate string `description:"开始日期"`
  1468. EndDate string `description:"结束日期"`
  1469. EdbInfoIdList []CorrelationChartInfoEdbItemReq `description:"指标信息"`
  1470. }
  1471. // CorrelationChartInfoEdbItemReq 相关性图表请求指标
  1472. type CorrelationChartInfoEdbItemReq struct {
  1473. EdbInfoId int `description:"指标ID"`
  1474. Name string `description:"别名"`
  1475. NameEn string `description:"英文别名"`
  1476. //Source int `description:"1:ETA图库;2:商品价格"`
  1477. }
  1478. // EditCorrelationChartInfoAndMapping 修改相关性图表的 图表与指标 的关系
  1479. func EditCorrelationChartInfoAndMapping(req *EditChartInfoReq, edbInfoIdStr string, calendar string, dateType, disabled int, barChartConf string, correlationChart *ChartInfoCorrelation, correlationUpdateCols []string) (err error) {
  1480. o := orm.NewOrmUsingDB("data")
  1481. to, err := o.Begin()
  1482. if err != nil {
  1483. return
  1484. }
  1485. defer func() {
  1486. if err != nil {
  1487. _ = to.Rollback()
  1488. } else {
  1489. _ = to.Commit()
  1490. }
  1491. }()
  1492. var pars []interface{}
  1493. pars = append(pars, req.ChartName)
  1494. pars = append(pars, edbInfoIdStr)
  1495. pars = append(pars, req.ChartType)
  1496. pars = append(pars, req.ChartClassifyId)
  1497. pars = append(pars, disabled)
  1498. pars = append(pars, barChartConf)
  1499. sql := ` UPDATE chart_info
  1500. SET
  1501. chart_name =?,
  1502. edb_info_ids=?,
  1503. chart_type=?,
  1504. chart_classify_id = ?,
  1505. modify_time = NOW(),
  1506. disabled = ?,
  1507. bar_config = ?
  1508. `
  1509. if calendar != "" {
  1510. sql += `,calendar = ? `
  1511. pars = append(pars, calendar)
  1512. }
  1513. if dateType > 0 {
  1514. sql += `,date_type = ? `
  1515. pars = append(pars, dateType)
  1516. }
  1517. sql += `,start_date = ? `
  1518. pars = append(pars, req.StartDate)
  1519. sql += `,end_date = ? `
  1520. pars = append(pars, req.EndDate)
  1521. sql += `,season_start_date = ? `
  1522. pars = append(pars, req.StartDate)
  1523. sql += `,season_end_date = ? `
  1524. pars = append(pars, req.EndDate)
  1525. sql += `,left_min = ? `
  1526. pars = append(pars, req.LeftMin)
  1527. sql += `,left_max = ? `
  1528. pars = append(pars, req.LeftMax)
  1529. sql += `,right_min = ? `
  1530. pars = append(pars, req.RightMin)
  1531. sql += `,right_max = ? `
  1532. pars = append(pars, req.RightMax)
  1533. sql += `WHERE chart_info_id = ?`
  1534. pars = append(pars, req.ChartInfoId)
  1535. _, err = to.Raw(sql, pars).Exec()
  1536. if err != nil {
  1537. fmt.Println("UPDATE chart_info Err:", err.Error())
  1538. return err
  1539. }
  1540. chartEdbMappingIdList := make([]string, 0)
  1541. for _, v := range req.CorrelationChartInfo.EdbInfoIdList {
  1542. // 查询该指标是否存在,如果存在的话,那么就去修改,否则新增
  1543. var tmpChartEdbMapping *ChartEdbMapping
  1544. csql := `SELECT * FROM chart_edb_mapping WHERE chart_info_id=? AND edb_info_id=? AND source = ? `
  1545. err = to.Raw(csql, req.ChartInfoId, v.EdbInfoId, utils.CHART_SOURCE_CORRELATION).QueryRow(&tmpChartEdbMapping)
  1546. if err != nil && err.Error() != utils.ErrNoRow() {
  1547. fmt.Println("QueryRow Err:", err.Error())
  1548. return err
  1549. }
  1550. if tmpChartEdbMapping != nil {
  1551. chartEdbMappingIdList = append(chartEdbMappingIdList, strconv.Itoa(tmpChartEdbMapping.ChartEdbMappingId))
  1552. //tmpChartEdbMapping.ModifyTime = time.Now()
  1553. //tmpChartEdbMapping.MaxData = v.MaxData
  1554. //tmpChartEdbMapping.MinData = v.MinData
  1555. //tmpChartEdbMapping.IsOrder = v.IsOrder
  1556. //tmpChartEdbMapping.IsAxis = v.IsAxis
  1557. //tmpChartEdbMapping.EdbInfoType = v.EdbInfoType
  1558. //tmpChartEdbMapping.LeadValue = v.LeadValue
  1559. //tmpChartEdbMapping.LeadUnit = v.LeadUnit
  1560. //tmpChartEdbMapping.ChartStyle = v.ChartStyle
  1561. //tmpChartEdbMapping.ChartColor = v.ChartColor
  1562. //tmpChartEdbMapping.PredictChartColor = v.PredictChartColor
  1563. //tmpChartEdbMapping.ChartWidth = v.ChartWidth
  1564. //_, err = to.Update(tmpChartEdbMapping, "ModifyTime", "MaxData", "MinData", "IsOrder", "IsAxis", "EdbInfoType", "LeadValue", "LeadUnit", "ChartStyle", "ChartColor", "PredictChartColor", "ChartWidth")
  1565. //if err != nil {
  1566. // fmt.Println("chart_edb_mapping Err:" + err.Error())
  1567. // return err
  1568. //}
  1569. } else {
  1570. mapItem := new(ChartEdbMapping)
  1571. mapItem.ChartInfoId = req.ChartInfoId
  1572. mapItem.EdbInfoId = v.EdbInfoId
  1573. mapItem.CreateTime = time.Now()
  1574. mapItem.ModifyTime = time.Now()
  1575. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  1576. mapItem.UniqueCode = utils.MD5(utils.CHART_PREFIX + "_" + timestamp + "_" + strconv.Itoa(v.EdbInfoId))
  1577. //mapItem.MaxData = v.MaxData
  1578. //mapItem.MinData = v.MinData
  1579. mapItem.IsOrder = true
  1580. mapItem.IsAxis = 1
  1581. mapItem.EdbInfoType = 1
  1582. //mapItem.LeadValue = v.LeadValue
  1583. //mapItem.LeadUnit = v.LeadUnit
  1584. //mapItem.ChartStyle = v.ChartStyle
  1585. //mapItem.ChartColor = v.ChartColor
  1586. //mapItem.PredictChartColor = v.PredictChartColor
  1587. //mapItem.ChartWidth = v.ChartWidth
  1588. mapItem.Source = utils.CHART_SOURCE_CORRELATION
  1589. tmpId, err := to.Insert(mapItem)
  1590. if err != nil {
  1591. fmt.Println("AddChartEdbMapping Err:" + err.Error())
  1592. return err
  1593. }
  1594. mapItem.ChartEdbMappingId = int(tmpId)
  1595. chartEdbMappingIdList = append(chartEdbMappingIdList, strconv.Itoa(mapItem.ChartEdbMappingId))
  1596. }
  1597. }
  1598. if len(chartEdbMappingIdList) > 0 {
  1599. chartEdbMappingIdStr := strings.Join(chartEdbMappingIdList, ",")
  1600. dsql := `DELETE FROM chart_edb_mapping WHERE chart_info_id=? AND chart_edb_mapping_id NOT IN(` + chartEdbMappingIdStr + `)`
  1601. _, err = to.Raw(dsql, req.ChartInfoId).Exec()
  1602. if err != nil {
  1603. fmt.Println("delete err:" + err.Error())
  1604. return err
  1605. }
  1606. }
  1607. // 相关性图表
  1608. _, err = to.Update(correlationChart, correlationUpdateCols...)
  1609. return
  1610. }
  1611. // PreviewSectionScatterChartReq 预览截面散点图的请求
  1612. type PreviewSectionScatterChartReq struct {
  1613. ChartName string `description:"图表名称"`
  1614. ChartClassifyId int `description:"分类id"`
  1615. ExtraConfig string `description:"图表额外配置信息,json字符串"`
  1616. }
  1617. // SectionScatterReq 截面散点请求
  1618. type SectionScatterReq struct {
  1619. XName string `description:"x轴名称"`
  1620. XNameEn string `description:"x轴名称(英文)"`
  1621. XUnitName string `description:"x轴单位名称"`
  1622. XUnitNameEn string `description:"x轴单位名称(英文)"`
  1623. YName string `description:"y轴名称"`
  1624. YNameEn string `description:"y轴名称(英文)"`
  1625. YUnitName string `description:"y轴单位名称"`
  1626. YUnitNameEn string `description:"y轴单位名称(英文)"`
  1627. XMinValue string `description:"X轴的最小值"`
  1628. XMaxValue string `description:"X轴的最大值"`
  1629. YMinValue string `description:"Y轴的最小值"`
  1630. YMaxValue string `description:"Y轴的最大值"`
  1631. //EdbList []SectionScatterEdbItemReq `description:"指标数据"`
  1632. SeriesList []SectionScatterSeriesItemReq `description:"系列数据"`
  1633. }
  1634. // SectionScatterSeriesItemReq 系列的请求
  1635. type SectionScatterSeriesItemReq struct {
  1636. Name string `description:"系列名"`
  1637. NameEn string `description:"系列名(英文名)"`
  1638. IsNameDefault bool `description:"是否使用默认的系列名 false修改过 true默认 影响自动更新"`
  1639. Color string `description:"颜色"`
  1640. EdbInfoList []SectionScatterEdbItemReq
  1641. ShowTrendLine bool `description:"是否展示趋势线"`
  1642. ShowFitEquation bool `description:"是否展示方程式"`
  1643. ShowRSquare bool `description:"是否展示R平方"`
  1644. }
  1645. // SectionScatterEdbItemReq 截面散点请求的指标
  1646. type SectionScatterEdbItemReq struct {
  1647. XEdbInfoId int `description:"X轴的指标ID"`
  1648. YEdbInfoId int `description:"Y轴的指标ID"`
  1649. Name string `description:"别名"`
  1650. NameEn string `description:"英文别名"`
  1651. XDateType int `description:"X轴的日期配置类型"`
  1652. XDate string `description:"X轴的日期固定日期"`
  1653. XDateValue int `description:"X轴的日期N天的值"`
  1654. YDateType int `description:"Y轴的日期配置类型"`
  1655. YDate string `description:"Y轴的日期固定日期"`
  1656. YDateValue int `description:"Y轴的日期N天的值"`
  1657. IsShow bool `description:"是否展示"`
  1658. }
  1659. // SectionScatterInfoResp 截面散点图数据
  1660. type SectionScatterInfoResp struct {
  1661. XName string `description:"x轴名称"`
  1662. XNameEn string `description:"x轴名称(英文)"`
  1663. XUnitName string `description:"x轴单位名称"`
  1664. XUnitNameEn string `description:"x轴单位名称(英文)"`
  1665. YName string `description:"y轴名称"`
  1666. YNameEn string `description:"y轴名称(英文)"`
  1667. YUnitName string `description:"y轴单位名称"`
  1668. YUnitNameEn string `description:"y轴单位名称(英文)"`
  1669. XMinValue string `description:"X轴的最小值"`
  1670. XMaxValue string `description:"X轴的最大值"`
  1671. YMinValue string `description:"Y轴的最小值"`
  1672. YMaxValue string `description:"Y轴的最大值"`
  1673. DataList []SectionScatterSeriesItemResp `description:"数据列"`
  1674. }
  1675. // SectionScatterSeriesItemResp 系列的返回
  1676. type SectionScatterSeriesItemResp struct {
  1677. Name string `description:"系列名"`
  1678. NameEn string `description:"系列名(英文)"`
  1679. IsNameDefault bool `description:"是否使用默认的系列名 false修改过 true默认 影响自动更新"`
  1680. Color string `description:"颜色"`
  1681. EdbInfoList []SectionScatterEdbItemResp
  1682. ShowTrendLine bool `description:"是否展示趋势线"`
  1683. ShowFitEquation bool `description:"是否展示方程式"`
  1684. ShowRSquare bool `description:"是否展示R平方"`
  1685. TrendLine string `description:"方程式"`
  1686. RSquare string `description:"R平方的值(决定系数R2)"`
  1687. TrendLimitData []CoordinatePoint `description:"趋势线的前后坐标点"`
  1688. }
  1689. // SectionScatterEdbItemResp 截面散点的返回参数
  1690. type SectionScatterEdbItemResp struct {
  1691. XEdbInfoId int `description:"X轴指标id"`
  1692. XDate string `description:"X轴指标实际日期"`
  1693. XName string `description:"X轴指标名称"`
  1694. XNameEn string `description:"X轴指标英文名称"`
  1695. XValue float64 `description:"X轴实际值"`
  1696. YEdbInfoId int `description:"Y轴指标id"`
  1697. YDate string `description:"Y轴指标实际日期"`
  1698. YName string `description:"Y轴指标名称"`
  1699. YNameEn string `description:"Y轴指标英文名称"`
  1700. YValue float64 `description:"Y轴实际值"`
  1701. IsShow bool `description:"是否展示"`
  1702. Name string `description:"标签名称"`
  1703. NameEn string `description:"英文标签名称"`
  1704. }
  1705. // CoordinatePoint 坐标点
  1706. type CoordinatePoint struct {
  1707. X float64
  1708. Y float64
  1709. }
  1710. // RollingCorrelationChartDataResp 滚动相关性图
  1711. type RollingCorrelationChartDataResp struct {
  1712. XDateTimeValue []string `description:"滚动相关性图的x轴数据,日期数据"`
  1713. YDataList []YData `description:"滚动相关性图的y轴数据"`
  1714. }
  1715. // GetChartInfoAll 用于分类展示
  1716. // @param source int 1:ETA图库;2:商品价格曲线
  1717. func GetChartInfoAllByClassifyId(source, classifyId int) (items []*ChartClassifyItems, err error) {
  1718. o := orm.NewOrmUsingDB("data")
  1719. sql := ` SELECT chart_info_id,chart_classify_id,chart_name AS chart_classify_name,chart_name_en AS chart_classify_name_en,
  1720. unique_code,sys_user_id,sys_user_real_name,date_type,start_date,end_date,chart_type,calendar,season_start_date,season_end_date
  1721. FROM chart_info WHERE chart_classify_id = ? AND source = ? ORDER BY sort asc,create_time DESC `
  1722. _, err = o.Raw(sql, classifyId, source).QueryRows(&items)
  1723. return
  1724. }
  1725. // ProfitFutureGoodChartResp 商品利润图
  1726. type ProfitFutureGoodChartResp struct {
  1727. XDataList []XData
  1728. YDataList []YData
  1729. ProfitName string `description:"利润的名称"`
  1730. ProfitNameEn string `description:"利润的英文名称"`
  1731. }
  1732. func FIXChartClassifyId(newId, oldId int) (err error) {
  1733. o := orm.NewOrmUsingDB("data")
  1734. sql := ` UPDATE chart_info SET chart_classify_id=? WHERE chart_classify_id=? `
  1735. _, err = o.Raw(sql, newId, oldId).Exec()
  1736. return
  1737. }
  1738. // GetChartInfoByAdminIdAndClassify 获取所有我创建的图表,用于分类展示
  1739. func GetChartInfoByAdminIdAndClassify(sourceList []int, adminId, classifyId int) (items []*ChartClassifyItems, err error) {
  1740. num := len(sourceList)
  1741. if num <= 0 {
  1742. return
  1743. }
  1744. o := orm.NewOrmUsingDB("data")
  1745. sql := ` SELECT chart_info_id,chart_classify_id,chart_name AS chart_classify_name,
  1746. unique_code,sys_user_id,sys_user_real_name,date_type,start_date,end_date,chart_type,calendar,season_start_date,season_end_date
  1747. FROM chart_info where source in (` + utils.GetOrmInReplace(num) + `) AND sys_user_id = ? AND chart_classify_id = ? ORDER BY sort asc,create_time ASC `
  1748. _, err = o.Raw(sql, sourceList, adminId, classifyId).QueryRows(&items)
  1749. return
  1750. }
  1751. // GetChartInfoAdminList 根据条件获取图表数据了列表
  1752. func GetChartInfoAdminList() (items []int, err error) {
  1753. o := orm.NewOrmUsingDB("data")
  1754. sql := ` SELECT sys_user_id FROM chart_info GROUP BY sys_user_id `
  1755. _, err = o.Raw(sql).QueryRows(&items)
  1756. return
  1757. }
  1758. // EditChartInfoExtraConfig 修改 ETA图库 的 图表额外配置
  1759. func EditChartInfoExtraConfig(chartId int, extraConfig string) (err error) {
  1760. o := orm.NewOrmUsingDB("data")
  1761. var pars []interface{}
  1762. pars = append(pars, extraConfig)
  1763. sql := ` UPDATE chart_info
  1764. SET
  1765. modify_time = NOW(),
  1766. extra_config = ?
  1767. `
  1768. sql += `WHERE chart_info_id = ?`
  1769. pars = append(pars, chartId)
  1770. _, err = o.Raw(sql, pars).Exec()
  1771. if err != nil {
  1772. fmt.Println("UPDATE chart_info Err:", err.Error())
  1773. return err
  1774. }
  1775. return
  1776. }
  1777. // PreviewRadarChartReq 预览雷达图的请求入参
  1778. type PreviewRadarChartReq struct {
  1779. ChartEdbInfoList []*ChartSaveItem `description:"指标及配置信息"`
  1780. ExtraConfig string `description:"图表额外配置信息,json字符串"`
  1781. }
  1782. // RadarChartInfoReq 雷达图预览请求数据
  1783. type RadarChartInfoReq struct {
  1784. DateList []RadarChartInfoDateReq `description:"日期配置"`
  1785. }
  1786. // RadarChartInfoEdbItemReq 雷达图预览请求数据(指标相关)
  1787. type RadarChartInfoEdbItemReq struct {
  1788. EdbInfoId int `description:"指标ID"`
  1789. Name string `description:"别名"`
  1790. //NameEn string `description:"英文别名"`
  1791. //Source int `description:"1:ETA图库;2:商品价格"`
  1792. }
  1793. // RadarChartInfoDateReq 雷达图预览请求数据(日期相关)
  1794. type RadarChartInfoDateReq struct {
  1795. Type int `description:"配置类型"`
  1796. Date string `description:"固定日期"`
  1797. Value int `description:"N天的值"`
  1798. Color string `description:"颜色"`
  1799. Name string `description:"别名"`
  1800. }
  1801. // RadarChartInfoResp 雷达图数据
  1802. type RadarChartInfoResp struct {
  1803. YDataList []RadarYData `description:"数据列"`
  1804. XEdbIdValue []int
  1805. }
  1806. // RadarYData 雷达图的y轴数据
  1807. type RadarYData struct {
  1808. Date string `description:"数据日期"`
  1809. Color string `description:"数据颜色"`
  1810. Name string `description:"别名"`
  1811. Value []float64 `description:"每个指标的值"`
  1812. }