chart_info.go 94 KB

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