chart_info.go 71 KB

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