chart_info.go 68 KB

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