chart_info.go 112 KB

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