chart_info.go 79 KB

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