chart_info.go 94 KB

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