chart_info.go 105 KB

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