chart_info.go 125 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257
  1. package data_manage
  2. import (
  3. "encoding/json"
  4. "eta_gn/eta_api/controllers"
  5. "eta_gn/eta_api/models"
  6. "eta_gn/eta_api/models/data_manage"
  7. "eta_gn/eta_api/models/data_manage/response"
  8. "eta_gn/eta_api/models/system"
  9. "eta_gn/eta_api/services"
  10. "eta_gn/eta_api/services/data"
  11. "eta_gn/eta_api/services/data/data_manage_permission"
  12. "eta_gn/eta_api/services/data/excel"
  13. "eta_gn/eta_api/services/eta_forum"
  14. "eta_gn/eta_api/utils"
  15. "fmt"
  16. "github.com/rdlucklib/rdluck_tools/paging"
  17. "os"
  18. "os/exec"
  19. "strconv"
  20. "strings"
  21. "time"
  22. )
  23. // 图表管理
  24. type ChartInfoController struct {
  25. controllers.BaseAuthController
  26. }
  27. // @Title 保存图表接口
  28. // @Description 保存图表接口
  29. // @Param request body data_manage.SaveChartInfoReq true "type json string"
  30. // @Success Ret=200 返回图表id
  31. // @router /chart_info/save [post]
  32. func (this *ChartInfoController) ChartInfoSave() {
  33. br := new(models.BaseResponse).Init()
  34. defer func() {
  35. this.Data["json"] = br
  36. this.ServeJSON()
  37. }()
  38. sysUser := this.SysUser
  39. if sysUser == nil {
  40. br.Msg = "请登录"
  41. br.ErrMsg = "请登录,SysUser Is Empty"
  42. br.Ret = 408
  43. return
  44. }
  45. var req data_manage.SaveChartInfoReq
  46. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  47. if err != nil {
  48. br.Msg = "参数解析异常!"
  49. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  50. return
  51. }
  52. if req.ChartInfoId > 0 && len(req.ChartEdbInfoList) <= 0 {
  53. br.Msg = "参数错误!"
  54. return
  55. }
  56. chartItem, err := data_manage.GetChartInfoById(req.ChartInfoId)
  57. if err != nil {
  58. if utils.IsErrNoRow(err) {
  59. br.Msg = "图表已被删除,请刷新页面!"
  60. br.ErrMsg = "图表已被删除,请刷新页面,ChartInfoId:" + strconv.Itoa(req.ChartInfoId)
  61. return
  62. }
  63. br.Msg = "获取图表信息失败!"
  64. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  65. return
  66. }
  67. //图表操作权限
  68. if req.Calendar == "" {
  69. req.Calendar = "公历"
  70. }
  71. err = data_manage.ModifyChartInfoAndMapping(chartItem.EdbInfoIds, &req, chartItem.ChartType)
  72. if err != nil {
  73. br.Msg = "保存失败"
  74. br.ErrMsg = "保存失败,Err:" + err.Error()
  75. return
  76. }
  77. key := utils.HZ_CHART_LIB_DETAIL + chartItem.UniqueCode
  78. if utils.Re == nil && utils.Rc != nil {
  79. utils.Rc.Delete(key)
  80. }
  81. //修改es数据
  82. go data.EsAddOrEditChartInfo(chartItem.ChartInfoId)
  83. //修改my eta es数据
  84. go data.EsAddOrEditMyChartInfoByChartInfoId(chartItem.ChartInfoId)
  85. //新增操作日志
  86. {
  87. chartLog := new(data_manage.ChartInfoLog)
  88. chartLog.ChartName = chartItem.ChartName
  89. chartLog.ChartInfoId = req.ChartInfoId
  90. chartLog.ChartClassifyId = chartItem.ChartClassifyId
  91. chartLog.SysUserId = sysUser.AdminId
  92. chartLog.SysUserRealName = sysUser.RealName
  93. chartLog.UniqueCode = chartItem.UniqueCode
  94. chartLog.CreateTime = time.Now()
  95. chartLog.Content = string(this.Ctx.Input.RequestBody)
  96. chartLog.Status = "修改配置项"
  97. chartLog.Method = this.Ctx.Input.URI()
  98. go data_manage.AddChartInfoLog(chartLog)
  99. }
  100. br.Ret = 200
  101. br.Success = true
  102. br.Msg = "保存成功"
  103. br.IsAddLog = true
  104. }
  105. // ChartInfoAdd
  106. // @Title 新增图表接口
  107. // @Description 新增图表接口
  108. // @Param request body data_manage.AddChartInfoReq true "type json string"
  109. // @Success 200 {object} data_manage.AddChartInfoResp
  110. // @router /chart_info/add [post]
  111. func (this *ChartInfoController) ChartInfoAdd() {
  112. br := new(models.BaseResponse).Init()
  113. defer func() {
  114. this.Data["json"] = br
  115. this.ServeJSON()
  116. }()
  117. sysUser := this.SysUser
  118. if sysUser == nil {
  119. br.Msg = "请登录"
  120. br.ErrMsg = "请登录,SysUser Is Empty"
  121. br.Ret = 408
  122. return
  123. }
  124. deleteCache := true
  125. cacheKey := "CACHE_CHART_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  126. defer func() {
  127. if deleteCache {
  128. utils.Rc.Delete(cacheKey)
  129. }
  130. }()
  131. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  132. deleteCache = false
  133. br.Msg = "系统处理中,请稍后重试!"
  134. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  135. return
  136. }
  137. var req data_manage.AddChartInfoReq
  138. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  139. if err != nil {
  140. br.Msg = "参数解析异常!"
  141. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  142. return
  143. }
  144. req.ChartName = strings.Trim(req.ChartName, " ")
  145. if req.ChartName == "" {
  146. br.Msg = "请填写图表名称!"
  147. return
  148. }
  149. if req.ChartClassifyId <= 0 {
  150. br.Msg = "分类参数错误!"
  151. return
  152. }
  153. // 来源字数校验
  154. type SourcesFrom struct {
  155. Text string `json:"text"`
  156. }
  157. if req.SourcesFrom != "" && len(req.SourcesFrom) > 0 {
  158. var sourcesFrom SourcesFrom
  159. err = json.Unmarshal([]byte(req.SourcesFrom), &sourcesFrom)
  160. if err != nil {
  161. return
  162. }
  163. if len(sourcesFrom.Text) > 50 {
  164. br.Msg = "字数已达上限!"
  165. br.ErrMsg = "来源文本字数已达上限,请修改!"
  166. return
  167. }
  168. }
  169. // 说明字数校验
  170. if req.Instructions != "" && len(req.Instructions) > 0 {
  171. var instructions SourcesFrom
  172. err = json.Unmarshal([]byte(req.Instructions), &instructions)
  173. if err != nil {
  174. return
  175. }
  176. if len(instructions.Text) > 100 {
  177. br.Msg = "字数已达上限!"
  178. br.ErrMsg = "说明文本字数已达上限,请修改!"
  179. return
  180. }
  181. }
  182. chartInfo, err, errMsg, isSendEmail := data.AddChartInfo(req, sysUser.AdminId, sysUser.RealName, this.Lang)
  183. if err != nil {
  184. br.Msg = "保存失败"
  185. if errMsg != `` {
  186. br.Msg = errMsg
  187. }
  188. br.ErrMsg = err.Error()
  189. br.IsSendEmail = isSendEmail
  190. return
  191. }
  192. resp := new(data_manage.AddChartInfoResp)
  193. resp.ChartInfoId = chartInfo.ChartInfoId
  194. resp.UniqueCode = chartInfo.UniqueCode
  195. resp.ChartType = req.ChartType
  196. //新增操作日志
  197. {
  198. chartLog := new(data_manage.ChartInfoLog)
  199. chartLog.ChartInfoId = chartInfo.ChartInfoId
  200. chartLog.ChartName = req.ChartName
  201. chartLog.ChartClassifyId = req.ChartClassifyId
  202. chartLog.SysUserId = sysUser.AdminId
  203. chartLog.SysUserRealName = sysUser.RealName
  204. chartLog.UniqueCode = chartInfo.UniqueCode
  205. chartLog.CreateTime = time.Now()
  206. chartLog.Content = string(this.Ctx.Input.RequestBody)
  207. chartLog.Status = "新增图表"
  208. chartLog.Method = this.Ctx.Input.URI()
  209. go data_manage.AddChartInfoLog(chartLog)
  210. }
  211. br.Ret = 200
  212. br.Success = true
  213. br.Msg = "保存成功"
  214. br.Data = resp
  215. br.IsAddLog = true
  216. }
  217. // @Title 编辑图表接口
  218. // @Description 编辑图表接口
  219. // @Param request body data_manage.EditChartInfoReq true "type json string"
  220. // @Success Ret=200 保存成功
  221. // @router /chart_info/edit [post]
  222. func (this *ChartInfoController) ChartInfoEdit() {
  223. br := new(models.BaseResponse).Init()
  224. defer func() {
  225. this.Data["json"] = br
  226. this.ServeJSON()
  227. }()
  228. sysUser := this.SysUser
  229. if sysUser == nil {
  230. br.Msg = "请登录"
  231. br.ErrMsg = "请登录,SysUser Is Empty"
  232. br.Ret = 408
  233. return
  234. }
  235. var req data_manage.EditChartInfoReq
  236. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  237. if err != nil {
  238. br.Msg = "参数解析异常!"
  239. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  240. return
  241. }
  242. chartItem, err, errMsg, isSendEmail := data.EditChartInfo(req, sysUser, this.Lang)
  243. if err != nil {
  244. br.Msg = "保存失败"
  245. if errMsg != `` {
  246. br.Msg = errMsg
  247. }
  248. br.ErrMsg = err.Error()
  249. br.IsSendEmail = isSendEmail
  250. return
  251. }
  252. resp := new(data_manage.AddChartInfoResp)
  253. resp.ChartInfoId = chartItem.ChartInfoId
  254. resp.UniqueCode = chartItem.UniqueCode
  255. resp.ChartType = req.ChartType
  256. //新增操作日志
  257. {
  258. chartLog := new(data_manage.ChartInfoLog)
  259. chartLog.ChartName = chartItem.ChartName
  260. chartLog.ChartInfoId = req.ChartInfoId
  261. chartLog.ChartClassifyId = chartItem.ChartClassifyId
  262. chartLog.SysUserId = sysUser.AdminId
  263. chartLog.SysUserRealName = sysUser.RealName
  264. chartLog.UniqueCode = chartItem.UniqueCode
  265. chartLog.CreateTime = time.Now()
  266. chartLog.Content = string(this.Ctx.Input.RequestBody)
  267. chartLog.Status = "编辑图表"
  268. chartLog.Method = this.Ctx.Input.URL()
  269. go data_manage.AddChartInfoLog(chartLog)
  270. }
  271. br.Ret = 200
  272. br.Success = true
  273. br.Msg = "保存成功"
  274. br.Data = resp
  275. br.IsAddLog = true
  276. }
  277. // ChartEnInfoEdit
  278. // @Title 编辑图表英文信息接口
  279. // @Description 编辑图表英文信息接口
  280. // @Param request body data_manage.EditChartEnInfoReq true "type json string"
  281. // @Success Ret=200 编辑成功
  282. // @router /chart_info/en/edit [post]
  283. func (this *ChartInfoController) ChartEnInfoEdit() {
  284. br := new(models.BaseResponse).Init()
  285. defer func() {
  286. this.Data["json"] = br
  287. this.ServeJSON()
  288. }()
  289. sysUser := this.SysUser
  290. if sysUser == nil {
  291. br.Msg = "请登录"
  292. br.ErrMsg = "请登录,SysUser Is Empty"
  293. br.Ret = 408
  294. return
  295. }
  296. var req data_manage.EditChartEnInfoReq
  297. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  298. if err != nil {
  299. br.Msg = "参数解析异常!"
  300. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  301. return
  302. }
  303. req.ChartNameEn = strings.Trim(req.ChartNameEn, " ")
  304. if req.ChartInfoId <= 0 {
  305. br.Msg = "请选择图表"
  306. return
  307. }
  308. //判断指标名称是否存在
  309. chartItem, err := data_manage.GetChartInfoById(req.ChartInfoId)
  310. if err != nil {
  311. if utils.IsErrNoRow(err) {
  312. br.Msg = "图表已被删除,请刷新页面"
  313. br.ErrMsg = "图表已被删除,请刷新页面"
  314. return
  315. }
  316. br.Msg = "获取图表信息失败"
  317. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  318. return
  319. }
  320. // 判断是否有传入对应的指标配置
  321. noEdbInfoType := []int{10}
  322. if len(req.ChartEdbInfoList) <= 0 && !utils.InArrayByInt(noEdbInfoType, chartItem.ChartType) {
  323. br.Msg = "请选择指标!"
  324. return
  325. }
  326. var edbCondition string
  327. var edbPars []interface{}
  328. for _, v := range req.ChartEdbInfoList {
  329. edbInfoId := v.EdbInfoId
  330. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  331. if err != nil {
  332. if utils.IsErrNoRow(err) {
  333. br.Msg = "图表不存在!"
  334. br.ErrMsg = "图表指标不存在,ChartInfoId:" + strconv.Itoa(edbInfoId)
  335. return
  336. } else {
  337. br.Msg = "获取图表信息失败!"
  338. br.ErrMsg = "获取图表的指标信息失败,Err:" + err.Error()
  339. return
  340. }
  341. }
  342. if edbInfo == nil {
  343. br.Msg = "指标不存在!"
  344. br.ErrMsg = "指标不存在,ChartInfoId:" + strconv.Itoa(edbInfoId)
  345. return
  346. }
  347. //判断指标名称是否重复
  348. if v.EdbNameEn != "" {
  349. edbCondition = ""
  350. edbPars = make([]interface{}, 0)
  351. edbCondition += " AND edb_info_id<>? "
  352. edbPars = append(edbPars, edbInfo.EdbInfoId)
  353. /*edbCondition += " AND source=? "
  354. edbPars = append(edbPars, edbInfo.Source)*/
  355. edbCondition += " AND edb_name_en=? "
  356. edbPars = append(edbPars, v.EdbNameEn)
  357. edbExist, err := data_manage.GetEdbInfoByCondition(edbCondition, edbPars)
  358. if err != nil {
  359. if !utils.IsErrNoRow(err) {
  360. br.Msg = "判断英文指标名称是否存在失败"
  361. br.ErrMsg = "判断英文指标名称是否存在失败,Err:" + err.Error()
  362. return
  363. }
  364. }
  365. if err == nil && edbExist.EdbInfoId > 0 {
  366. br.Msg = edbExist.EdbName + ":" + v.EdbNameEn + "指标名称已存在"
  367. br.ErrMsg = "英文指标名称已存在,请重新填写"
  368. br.IsSendEmail = false
  369. return
  370. }
  371. }
  372. }
  373. if req.ChartNameEn != "" || req.ExtraConfig != `` {
  374. var condition string
  375. var pars []interface{}
  376. condition += " AND chart_info_id<>? "
  377. pars = append(pars, req.ChartInfoId)
  378. /*condition += " AND chart_classify_id=? "
  379. pars = append(pars, chartItem.ChartClassifyId)*/
  380. condition += " AND chart_name_en=? "
  381. pars = append(pars, req.ChartNameEn)
  382. existItem, err := data_manage.GetChartInfoByCondition(condition, pars)
  383. if err != nil {
  384. if !utils.IsErrNoRow(err) {
  385. br.Msg = "判断英文图表名称是否存在失败"
  386. br.ErrMsg = "判断英文图表名称是否存在失败,Err:" + err.Error()
  387. return
  388. }
  389. }
  390. if err == nil && existItem.ChartInfoId > 0 {
  391. br.Msg = existItem.ChartName + ":" + req.ChartNameEn + "图表名称已存在"
  392. return
  393. }
  394. }
  395. err = data_manage.EditChartEnInfoAndEdbEnInfo(&req)
  396. if err != nil {
  397. br.Msg = "保存失败"
  398. br.ErrMsg = "保存失败,Err:" + err.Error()
  399. return
  400. }
  401. //添加es数据
  402. go data.EsAddOrEditChartInfo(chartItem.ChartInfoId)
  403. //修改my eta es数据
  404. go data.EsAddOrEditMyChartInfoByChartInfoId(chartItem.ChartInfoId)
  405. //edbinfo 修改es信息
  406. for _, v := range req.ChartEdbInfoList {
  407. edbInfoId := v.EdbInfoId
  408. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  409. if err != nil {
  410. if utils.IsErrNoRow(err) {
  411. br.Msg = "图表不存在!"
  412. br.ErrMsg = "图表指标不存在,ChartInfoId:" + strconv.Itoa(edbInfoId)
  413. return
  414. } else {
  415. br.Msg = "获取图表信息失败!"
  416. br.ErrMsg = "获取图表的指标信息失败,Err:" + err.Error()
  417. return
  418. }
  419. }
  420. if edbInfo != nil {
  421. go data.AddOrEditEdbInfoToEs(edbInfoId)
  422. }
  423. }
  424. //新增操作日志
  425. {
  426. chartLog := new(data_manage.ChartInfoLog)
  427. chartLog.ChartName = chartItem.ChartName
  428. chartLog.ChartInfoId = req.ChartInfoId
  429. chartLog.ChartClassifyId = chartItem.ChartClassifyId
  430. chartLog.SysUserId = sysUser.AdminId
  431. chartLog.SysUserRealName = sysUser.RealName
  432. chartLog.UniqueCode = chartItem.UniqueCode
  433. chartLog.CreateTime = time.Now()
  434. chartLog.Content = string(this.Ctx.Input.RequestBody)
  435. chartLog.Status = "编辑图表英文信息"
  436. chartLog.Method = this.Ctx.Input.URL()
  437. go data_manage.AddChartInfoLog(chartLog)
  438. }
  439. //清除缓存
  440. if utils.Re == nil && utils.Rc != nil {
  441. utils.Rc.Delete(utils.HZ_CHART_LIB_DETAIL + chartItem.UniqueCode) //图表分享链接缓存
  442. utils.Rc.Delete(data.GetChartInfoDataKey(req.ChartInfoId))
  443. }
  444. br.Ret = 200
  445. br.Success = true
  446. br.Msg = "编辑成功"
  447. br.IsAddLog = true
  448. }
  449. // ChartInfoBaseEdit
  450. // @Title 编辑图表基础信息接口
  451. // @Description 编辑图表基础信息接口
  452. // @Param request body data_manage.EditChartEnInfoBaseReq true "type json string"
  453. // @Success Ret=200 编辑成功
  454. // @router /chart_info/base/edit [post]
  455. func (this *ChartInfoController) ChartInfoBaseEdit() {
  456. br := new(models.BaseResponse).Init()
  457. defer func() {
  458. this.Data["json"] = br
  459. this.ServeJSON()
  460. }()
  461. sysUser := this.SysUser
  462. if sysUser == nil {
  463. br.Msg = "请登录"
  464. br.ErrMsg = "请登录,SysUser Is Empty"
  465. br.Ret = 408
  466. return
  467. }
  468. var req data_manage.EditChartInfoBaseReq
  469. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  470. if err != nil {
  471. br.Msg = "参数解析异常!"
  472. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  473. return
  474. }
  475. req.ChartName = strings.Trim(req.ChartName, " ")
  476. if req.ChartInfoId <= 0 {
  477. br.Msg = "请选择图表"
  478. return
  479. }
  480. //判断指标名称是否存在
  481. chartItem, err := data_manage.GetChartInfoById(req.ChartInfoId)
  482. if err != nil {
  483. if utils.IsErrNoRow(err) {
  484. br.Msg = "图表已被删除,请刷新页面"
  485. br.ErrMsg = "图表已被删除,请刷新页面"
  486. return
  487. }
  488. br.Msg = "获取图表信息失败"
  489. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  490. return
  491. }
  492. // 判断是否有传入对应的指标配置
  493. noEdbInfoType := []int{10}
  494. if len(req.ChartEdbInfoList) <= 0 && !utils.InArrayByInt(noEdbInfoType, chartItem.ChartType) {
  495. br.Msg = "请选择指标!"
  496. return
  497. }
  498. var edbCondition string
  499. var edbPars []interface{}
  500. for _, v := range req.ChartEdbInfoList {
  501. edbInfoId := v.EdbInfoId
  502. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  503. if err != nil {
  504. if utils.IsErrNoRow(err) {
  505. br.Msg = "图表不存在!"
  506. br.ErrMsg = "图表指标不存在,ChartInfoId:" + strconv.Itoa(edbInfoId)
  507. return
  508. } else {
  509. br.Msg = "获取图表信息失败!"
  510. br.ErrMsg = "获取图表的指标信息失败,Err:" + err.Error()
  511. return
  512. }
  513. }
  514. if edbInfo == nil {
  515. br.Msg = "指标不存在!"
  516. br.ErrMsg = "指标不存在,ChartInfoId:" + strconv.Itoa(edbInfoId)
  517. return
  518. }
  519. //判断指标名称是否重复
  520. if v.EdbName != "" {
  521. edbCondition = ""
  522. edbPars = make([]interface{}, 0)
  523. edbCondition += " AND edb_info_id<>? "
  524. edbPars = append(edbPars, edbInfo.EdbInfoId)
  525. switch this.Lang {
  526. case utils.EnLangVersion:
  527. edbCondition += " AND edb_name_en =? "
  528. default:
  529. edbCondition += " AND edb_name =? "
  530. }
  531. edbPars = append(edbPars, v.EdbName)
  532. edbExist, err := data_manage.GetEdbInfoByCondition(edbCondition, edbPars)
  533. if err != nil {
  534. if !utils.IsErrNoRow(err) {
  535. br.Msg = "判断英文指标名称是否存在失败"
  536. br.ErrMsg = "判断英文指标名称是否存在失败,Err:" + err.Error()
  537. return
  538. }
  539. }
  540. if err == nil && edbExist.EdbInfoId > 0 {
  541. br.Msg = edbExist.EdbName + ":" + v.EdbName + "指标名称已存在"
  542. br.ErrMsg = "指标名称已存在,请重新填写"
  543. br.IsSendEmail = false
  544. return
  545. }
  546. }
  547. }
  548. if req.ChartName != "" || req.ExtraConfig != `` {
  549. var condition string
  550. var pars []interface{}
  551. condition += " AND chart_info_id<>? "
  552. pars = append(pars, req.ChartInfoId)
  553. switch this.Lang {
  554. case utils.EnLangVersion:
  555. condition += " AND chart_name_en = ? "
  556. default:
  557. condition += " AND chart_name = ? "
  558. }
  559. pars = append(pars, req.ChartName)
  560. existItem, err := data_manage.GetChartInfoByCondition(condition, pars)
  561. if err != nil {
  562. if !utils.IsErrNoRow(err) {
  563. br.Msg = "判断英文图表名称是否存在失败"
  564. br.ErrMsg = "判断英文图表名称是否存在失败,Err:" + err.Error()
  565. return
  566. }
  567. }
  568. if err == nil && existItem.ChartInfoId > 0 {
  569. br.Msg = existItem.ChartName + ":" + req.ChartName + "图表名称已存在"
  570. return
  571. }
  572. }
  573. err = data_manage.EditChartBaseInfoAndEdbEnInfo(&req, chartItem, this.Lang)
  574. if err != nil {
  575. br.Msg = "保存失败"
  576. br.ErrMsg = "保存失败,Err:" + err.Error()
  577. return
  578. }
  579. //添加es数据
  580. go data.EsAddOrEditChartInfo(chartItem.ChartInfoId)
  581. //修改my eta es数据
  582. go data.EsAddOrEditMyChartInfoByChartInfoId(chartItem.ChartInfoId)
  583. //edbinfo 修改es信息
  584. for _, v := range req.ChartEdbInfoList {
  585. edbInfoId := v.EdbInfoId
  586. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  587. if err != nil {
  588. if utils.IsErrNoRow(err) {
  589. br.Msg = "图表不存在!"
  590. br.ErrMsg = "图表指标不存在,ChartInfoId:" + strconv.Itoa(edbInfoId)
  591. return
  592. } else {
  593. br.Msg = "获取图表信息失败!"
  594. br.ErrMsg = "获取图表的指标信息失败,Err:" + err.Error()
  595. return
  596. }
  597. }
  598. if edbInfo != nil {
  599. go data.AddOrEditEdbInfoToEs(edbInfoId)
  600. }
  601. }
  602. //新增操作日志
  603. {
  604. chartLog := new(data_manage.ChartInfoLog)
  605. chartLog.ChartName = chartItem.ChartName
  606. chartLog.ChartInfoId = req.ChartInfoId
  607. chartLog.ChartClassifyId = chartItem.ChartClassifyId
  608. chartLog.SysUserId = sysUser.AdminId
  609. chartLog.SysUserRealName = sysUser.RealName
  610. chartLog.UniqueCode = chartItem.UniqueCode
  611. chartLog.CreateTime = time.Now()
  612. chartLog.Content = string(this.Ctx.Input.RequestBody)
  613. chartLog.Status = "编辑图表英文信息"
  614. chartLog.Method = this.Ctx.Input.URL()
  615. go data_manage.AddChartInfoLog(chartLog)
  616. }
  617. //清除缓存
  618. if utils.Re == nil && utils.Rc != nil {
  619. utils.Rc.Delete(utils.HZ_CHART_LIB_DETAIL + chartItem.UniqueCode) //图表分享链接缓存
  620. utils.Rc.Delete(data.GetChartInfoDataKey(req.ChartInfoId))
  621. }
  622. br.Ret = 200
  623. br.Success = true
  624. br.Msg = "编辑成功"
  625. br.IsAddLog = true
  626. }
  627. // @Title 获取最新图表接口
  628. // @Description 获取最新图表接口
  629. // @Success 200 {object} data_manage.ChartInfoList
  630. // @router /chart_info/newest [get]
  631. func (this *ChartInfoController) ChartInfoNewest() {
  632. br := new(models.BaseResponse).Init()
  633. defer func() {
  634. this.Data["json"] = br
  635. this.ServeJSON()
  636. }()
  637. item, err := data_manage.GetChartInfoByNewest(1)
  638. if err != nil && !utils.IsErrNoRow(err) {
  639. br.Msg = "获取最新图表失败"
  640. br.ErrMsg = "获取最新图表失败,Err:" + err.Error()
  641. return
  642. }
  643. br.Ret = 200
  644. br.Success = true
  645. br.Msg = "获取成功"
  646. br.Data = item
  647. }
  648. // ChartInfoMove
  649. // @Title 移动图表接口
  650. // @Description 移动图表接口
  651. // @Success 200 {object} data_manage.MoveChartInfoReq
  652. // @router /chart_info/move [post]
  653. func (this *ChartInfoController) ChartInfoMove() {
  654. br := new(models.BaseResponse).Init()
  655. defer func() {
  656. this.Data["json"] = br
  657. this.ServeJSON()
  658. }()
  659. sysUser := this.SysUser
  660. if sysUser == nil {
  661. br.Msg = "请登录"
  662. br.ErrMsg = "请登录,SysUser Is Empty"
  663. br.Ret = 408
  664. return
  665. }
  666. var req data_manage.MoveChartInfoReq
  667. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  668. if err != nil {
  669. br.Msg = "参数解析异常!"
  670. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  671. return
  672. }
  673. if req.ChartInfoId <= 0 {
  674. br.Msg = "参数错误"
  675. br.ErrMsg = "图表id小于等于0"
  676. return
  677. }
  678. if req.ChartClassifyId <= 0 {
  679. br.Msg = "请选择分类"
  680. return
  681. }
  682. //判断分类是否存在
  683. count, _ := data_manage.GetChartClassifyCountById(req.ChartClassifyId)
  684. if count <= 0 {
  685. br.Msg = "分类已被删除,不可移动,请刷新页面"
  686. return
  687. }
  688. chartInfo, err := data_manage.GetChartInfoById(req.ChartInfoId)
  689. if err != nil {
  690. br.Msg = "移动失败"
  691. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  692. return
  693. }
  694. if chartInfo.Source != utils.CHART_SOURCE_DEFAULT {
  695. br.Msg = "图表异常"
  696. br.ErrMsg = "分类异常,不是ETA图库的图表"
  697. return
  698. }
  699. // 数据权限校验
  700. {
  701. haveOperaAuth, err := data_manage_permission.CheckChartPermissionByChartInfoId(chartInfo.ChartInfoId, chartInfo.ChartClassifyId, chartInfo.IsJoinPermission, sysUser.AdminId)
  702. if err != nil {
  703. br.Msg = "移动失败"
  704. br.ErrMsg = "获取图表权限失败,Err:" + err.Error()
  705. return
  706. }
  707. if !haveOperaAuth {
  708. br.Msg = "无操作权限"
  709. br.ErrMsg = "无操作权限"
  710. br.IsSendEmail = false
  711. return
  712. }
  713. }
  714. //如果改变了分类,那么移动该图表数据
  715. if chartInfo.ChartClassifyId != req.ChartClassifyId {
  716. //查询需要修改的分类下是否存在同一个图表名称
  717. tmpChartInfo, tmpErr := data_manage.GetChartInfoByClassifyIdAndName(req.ChartClassifyId, chartInfo.ChartName)
  718. if tmpErr != nil && !utils.IsErrNoRow(tmpErr) {
  719. br.Msg = "移动失败"
  720. br.ErrMsg = "移动失败,Err:" + tmpErr.Error()
  721. return
  722. }
  723. if tmpErr == nil && tmpChartInfo.ChartInfoId > 0 {
  724. br.Msg = "移动失败,同一个分类下图表名称不允许重复"
  725. br.ErrMsg = "移动失败,同一个分类下图表名称不允许重复"
  726. return
  727. }
  728. err = data_manage.MoveChartInfo(req.ChartInfoId, req.ChartClassifyId)
  729. if err != nil {
  730. br.Msg = "移动失败"
  731. br.ErrMsg = "移动失败,Err:" + err.Error()
  732. return
  733. }
  734. }
  735. //移动排序
  736. updateCol := make([]string, 0)
  737. //如果有传入 上一个兄弟节点分类id
  738. if req.PrevChartInfoId > 0 {
  739. prevChartInfo, err := data_manage.GetChartInfoById(req.PrevChartInfoId)
  740. if err != nil {
  741. br.Msg = "移动失败"
  742. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  743. return
  744. }
  745. //如果是移动在两个兄弟节点之间
  746. if req.NextChartInfoId > 0 {
  747. //下一个兄弟节点
  748. nextChartInfo, err := data_manage.GetChartInfoById(req.NextChartInfoId)
  749. if err != nil {
  750. br.Msg = "移动失败"
  751. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  752. return
  753. }
  754. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  755. if prevChartInfo.Sort == nextChartInfo.Sort || prevChartInfo.Sort == chartInfo.Sort {
  756. //变更兄弟节点的排序
  757. updateSortStr := `sort + 2`
  758. _ = data_manage.UpdateChartInfoSortByClassifyId(prevChartInfo.ChartClassifyId, prevChartInfo.Sort, prevChartInfo.ChartInfoId, []int{chartInfo.Source}, updateSortStr)
  759. } else {
  760. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  761. if nextChartInfo.Sort-prevChartInfo.Sort == 1 {
  762. //变更兄弟节点的排序
  763. updateSortStr := `sort + 1`
  764. _ = data_manage.UpdateChartInfoSortByClassifyId(prevChartInfo.ChartClassifyId, prevChartInfo.Sort, prevChartInfo.ChartInfoId, []int{chartInfo.Source}, updateSortStr)
  765. }
  766. }
  767. }
  768. chartInfo.Sort = prevChartInfo.Sort + 1
  769. chartInfo.ModifyTime = time.Now()
  770. updateCol = append(updateCol, "Sort", "ModifyTime")
  771. } else {
  772. firstClassify, err := data_manage.GetFirstChartInfoByClassifyId(req.ChartClassifyId)
  773. if err != nil && !utils.IsErrNoRow(err) {
  774. br.Msg = "移动失败"
  775. br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  776. return
  777. }
  778. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  779. if firstClassify != nil && firstClassify.ChartClassifyId > 0 && firstClassify.Sort == 0 {
  780. updateSortStr := ` sort + 1 `
  781. _ = data_manage.UpdateChartInfoSortByClassifyId(firstClassify.ChartClassifyId, 0, firstClassify.ChartInfoId-1, []int{chartInfo.Source}, updateSortStr)
  782. }
  783. chartInfo.Sort = 0 //那就是排在第一位
  784. chartInfo.ModifyTime = time.Now()
  785. updateCol = append(updateCol, "Sort", "ModifyTime")
  786. }
  787. //更新
  788. if len(updateCol) > 0 {
  789. err = chartInfo.Update(updateCol)
  790. if err != nil {
  791. br.Msg = "移动失败"
  792. br.ErrMsg = "修改失败,Err:" + err.Error()
  793. return
  794. }
  795. }
  796. if err != nil {
  797. br.Msg = "移动失败"
  798. br.ErrMsg = "修改失败,Err:" + err.Error()
  799. return
  800. }
  801. //添加es数据
  802. go data.EsAddOrEditChartInfo(req.ChartInfoId)
  803. //修改my eta es数据
  804. go data.EsAddOrEditMyChartInfoByChartInfoId(req.ChartInfoId)
  805. //新增操作日志
  806. {
  807. chartLog := new(data_manage.ChartInfoLog)
  808. chartLog.ChartName = chartInfo.ChartName
  809. chartLog.ChartInfoId = req.ChartInfoId
  810. chartLog.ChartClassifyId = chartInfo.ChartClassifyId
  811. chartLog.SysUserId = sysUser.AdminId
  812. chartLog.SysUserRealName = sysUser.RealName
  813. chartLog.UniqueCode = chartInfo.UniqueCode
  814. chartLog.CreateTime = time.Now()
  815. chartLog.Content = string(this.Ctx.Input.RequestBody)
  816. chartLog.Status = "移动图表"
  817. chartLog.Method = this.Ctx.Input.URL()
  818. go data_manage.AddChartInfoLog(chartLog)
  819. }
  820. br.Ret = 200
  821. br.Success = true
  822. br.Msg = "移动成功"
  823. }
  824. // ChartInfoDetail
  825. // @Title 获取图表详情
  826. // @Description 获取图表详情接口
  827. // @Param ChartInfoId query int true "图表id"
  828. // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间"
  829. // @Param StartDate query string true "自定义开始日期"
  830. // @Param EndDate query string true "自定义结束日期"
  831. // @Param Calendar query string true "公历/农历"
  832. // @Param SeasonStartDate query string true "季节性图开始日期"
  833. // @Param SeasonEndDate query string true "季节性图结束日期"
  834. // @Param EdbInfoId query string true "指标ID,多个用英文逗号隔开"
  835. // @Param ChartType query int true "生成样式:1:曲线图,2:季节性图"
  836. // @Success 200 {object} data_manage.ChartInfoDetailResp
  837. // @router /chart_info/detail [get]
  838. func (this *ChartInfoController) ChartInfoDetail() {
  839. br := new(models.BaseResponse).Init()
  840. defer func() {
  841. this.Data["json"] = br
  842. this.ServeJSON()
  843. }()
  844. sysUser := this.SysUser
  845. if sysUser == nil {
  846. br.Msg = "请登录"
  847. br.ErrMsg = "请登录,SysUser Is Empty"
  848. br.Ret = 408
  849. return
  850. }
  851. chartInfoId, _ := this.GetInt("ChartInfoId")
  852. dateType, _ := this.GetInt("DateType")
  853. fmt.Println("dateType:", dateType)
  854. if dateType <= 0 {
  855. dateType = 3
  856. }
  857. startDate := this.GetString("StartDate")
  858. endDate := this.GetString("EndDate")
  859. startYear, _ := this.GetInt("StartYear")
  860. edbInfoId := this.GetString("EdbInfoId")
  861. chartType, _ := this.GetInt("ChartType")
  862. calendar := this.GetString("Calendar")
  863. if calendar == "" {
  864. calendar = "公历"
  865. }
  866. var err error
  867. chartInfo := new(data_manage.ChartInfoView)
  868. chartInfo.HaveOperaAuth = true
  869. if chartInfoId > 0 {
  870. chartInfo, err = data_manage.GetChartInfoViewById(chartInfoId)
  871. if err != nil {
  872. if utils.IsErrNoRow(err) {
  873. br.Msg = "该图表已删除,自动查看下一图表"
  874. br.ErrMsg = "该图表已删除,自动查看下一图表,Err:" + err.Error()
  875. br.Ret = 406
  876. return
  877. }
  878. br.Msg = "获取失败"
  879. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  880. return
  881. }
  882. chartType = chartInfo.ChartType
  883. // 获取主题样式
  884. chartTheme, err := data.GetChartThemeConfig(chartInfo.ChartThemeId, chartInfo.Source, chartInfo.ChartType)
  885. if err != nil {
  886. br.Msg = "获取失败"
  887. br.ErrMsg = "获取主题信息失败,Err:" + err.Error()
  888. return
  889. }
  890. chartInfo.ChartThemeStyle = chartTheme.Config
  891. chartInfo.ChartThemeId = chartTheme.ChartThemeId
  892. // 图表数据权限
  893. {
  894. // 图表分类
  895. chartClassify, err := data_manage.GetChartClassifyById(chartInfo.ChartClassifyId)
  896. if err != nil {
  897. br.Msg = "获取失败"
  898. br.ErrMsg = "获取图表分类信息失败,Err:" + err.Error()
  899. return
  900. }
  901. // 已授权分类id
  902. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, chartInfo.ChartInfoId, chartInfo.ChartClassifyId)
  903. if err != nil {
  904. br.Msg = "获取失败"
  905. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  906. return
  907. }
  908. chartInfo.HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartInfo.IsJoinPermission, chartClassify.IsJoinPermission, chartInfo.ChartInfoId, chartInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  909. }
  910. }
  911. resp := new(data_manage.ChartInfoDetailResp)
  912. mappingList := make([]*data_manage.ChartEdbInfoMapping, 0)
  913. if chartInfoId > 0 {
  914. mappingList, err = data_manage.GetChartEdbMappingList(chartInfoId)
  915. if err != nil {
  916. br.Msg = "获取失败"
  917. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  918. return
  919. }
  920. } else {
  921. if edbInfoId != "" {
  922. mappingList, err = data_manage.GetChartEdbMappingListByEdbInfoId(edbInfoId)
  923. if err != nil {
  924. br.Msg = "获取失败"
  925. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  926. return
  927. }
  928. }
  929. }
  930. for _, v := range mappingList {
  931. v.ConvertToResp()
  932. }
  933. // 图表额外数据参数
  934. extraConfigStr := chartInfo.ExtraConfig
  935. // 柱方图的一些配置
  936. var barConfig data_manage.BarChartInfoReq
  937. if chartInfo != nil && chartInfo.ChartType == 7 {
  938. if chartInfo.BarConfig == `` {
  939. br.Msg = "柱方图未配置"
  940. br.ErrMsg = "柱方图未配置"
  941. return
  942. }
  943. err := json.Unmarshal([]byte(chartInfo.BarConfig), &barConfig)
  944. if err != nil {
  945. br.Msg = "柱方图配置异常"
  946. br.ErrMsg = "柱方图配置异常"
  947. return
  948. }
  949. extraConfigStr = chartInfo.BarConfig
  950. }
  951. yearMax := 0
  952. if dateType == utils.DateTypeNYears {
  953. for _, v := range mappingList {
  954. if v.LatestDate != "" {
  955. lastDateT, tErr := time.Parse(utils.FormatDate, v.LatestDate)
  956. if tErr != nil {
  957. br.Msg = "获取失败"
  958. br.ErrMsg = "获取图表日期信息失败,Err:" + tErr.Error()
  959. return
  960. }
  961. if lastDateT.Year() > yearMax {
  962. yearMax = lastDateT.Year()
  963. }
  964. }
  965. }
  966. }
  967. // 开始/结束日期
  968. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, yearMax)
  969. if chartInfo.HaveOperaAuth {
  970. // 获取图表中的指标数据
  971. edbList, xEdbIdValue, yDataList, dataResp, err, errMsg := data.GetChartEdbData(chartInfoId, chartType, calendar, startDate, endDate, mappingList, extraConfigStr, chartInfo.SeasonExtraConfig)
  972. if err != nil {
  973. br.Msg = "获取失败"
  974. if errMsg != `` {
  975. br.Msg = errMsg
  976. }
  977. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  978. return
  979. }
  980. // 指标权限
  981. {
  982. classifyMap := make(map[int]*data_manage.EdbClassify)
  983. // 分类
  984. {
  985. classifyIdList := make([]int, 0)
  986. for _, v := range edbList {
  987. classifyIdList = append(classifyIdList, v.ClassifyId)
  988. }
  989. classifyList, tmpErr := data_manage.GetEdbClassifyByIdList(classifyIdList)
  990. if tmpErr != nil {
  991. br.Msg = "获取失败"
  992. br.ErrMsg = "获取分类列表失败,Err:" + tmpErr.Error()
  993. return
  994. }
  995. for _, v := range classifyList {
  996. classifyMap[v.ClassifyId] = v
  997. }
  998. }
  999. // 获取所有有权限的指标和分类
  1000. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(sysUser.AdminId, 0, 0)
  1001. if err != nil {
  1002. br.Msg = "获取失败"
  1003. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  1004. return
  1005. }
  1006. for _, item := range edbList {
  1007. // 数据权限
  1008. if currClassify, ok := classifyMap[item.ClassifyId]; ok {
  1009. item.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(item.IsJoinPermission, currClassify.IsJoinPermission, item.EdbInfoId, item.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  1010. }
  1011. }
  1012. }
  1013. // 单位
  1014. if chartType == utils.CHART_TYPE_BAR && len(yDataList) > 0 {
  1015. chartInfo.Unit = yDataList[0].Unit
  1016. chartInfo.UnitEn = yDataList[0].UnitEn
  1017. }
  1018. warnEdbList := make([]string, 0)
  1019. for _, v := range edbList {
  1020. if v.IsNullData {
  1021. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  1022. }
  1023. }
  1024. if len(warnEdbList) > 0 {
  1025. chartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  1026. }
  1027. if chartInfoId > 0 && chartInfo != nil {
  1028. //判断是否加入我的图库
  1029. {
  1030. var myChartCondition string
  1031. var myChartPars []interface{}
  1032. myChartCondition += ` AND a.admin_id=? `
  1033. myChartPars = append(myChartPars, sysUser.AdminId)
  1034. myChartCondition += ` AND a.chart_info_id=? `
  1035. myChartPars = append(myChartPars, chartInfo.ChartInfoId)
  1036. myChartList, err := data_manage.GetMyChartByCondition(myChartCondition, myChartPars)
  1037. if err != nil && !utils.IsErrNoRow(err) {
  1038. br.Msg = "获取失败"
  1039. br.ErrMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
  1040. return
  1041. }
  1042. if myChartList != nil && len(myChartList) > 0 {
  1043. chartInfo.IsAdd = true
  1044. chartInfo.MyChartId = myChartList[0].MyChartId
  1045. chartInfo.MyChartClassifyId = myChartList[0].MyChartClassifyId
  1046. }
  1047. }
  1048. if chartInfo.ChartType == 2 {
  1049. if chartInfo.SeasonStartDate != "" {
  1050. chartInfo.StartDate = chartInfo.SeasonStartDate
  1051. chartInfo.EndDate = chartInfo.SeasonEndDate
  1052. if chartInfo.DateType == 3 {
  1053. chartInfo.DateType = 5
  1054. }
  1055. }
  1056. }
  1057. }
  1058. // 图表的指标来源
  1059. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  1060. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  1061. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  1062. //判断是否需要展示英文标识
  1063. chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, edbList, chartInfo.Source, chartInfo.ChartType)
  1064. resp.EdbInfoList = edbList
  1065. resp.XEdbIdValue = xEdbIdValue
  1066. resp.YDataList = yDataList
  1067. resp.DataResp = dataResp
  1068. }
  1069. //图表操作权限
  1070. chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, chartInfo.HaveOperaAuth)
  1071. chartInfo.Button = data_manage.ChartViewButton{
  1072. IsEdit: chartInfo.IsEdit,
  1073. IsEnChart: chartInfo.IsEnChart,
  1074. IsAdd: chartInfo.IsAdd,
  1075. IsCopy: true,
  1076. IsSetName: chartInfo.IsSetName,
  1077. }
  1078. resp.ChartInfo = chartInfo
  1079. resp.BarChartInfo = barConfig
  1080. br.Ret = 200
  1081. br.Success = true
  1082. br.Msg = "获取成功"
  1083. br.Data = resp
  1084. }
  1085. // PreviewChartInfoDetail
  1086. // @Title 获取图表详情(预览)
  1087. // @Description 获取图表详情接口(预览)
  1088. // @Param request body data_manage.PreviewChartInfoReq true "type json string"
  1089. // @Success 200 {object} data_manage.ChartInfoDetailResp
  1090. // @router /chart_info/detail/preview [post]
  1091. func (this *ChartInfoController) PreviewChartInfoDetail() {
  1092. br := new(models.BaseResponse).Init()
  1093. defer func() {
  1094. this.Data["json"] = br
  1095. this.ServeJSON()
  1096. }()
  1097. sysUser := this.SysUser
  1098. if sysUser == nil {
  1099. br.Msg = "请登录"
  1100. br.ErrMsg = "请登录,SysUser Is Empty"
  1101. br.Ret = 408
  1102. return
  1103. }
  1104. var req data_manage.PreviewChartInfoReq
  1105. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1106. if err != nil {
  1107. br.Msg = "参数解析异常!"
  1108. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1109. return
  1110. }
  1111. if req.DateType <= 0 {
  1112. req.DateType = 3
  1113. }
  1114. // edbInfoId 指标id
  1115. if len(req.ChartEdbInfoList) <= 0 {
  1116. br.Msg = "请选择指标"
  1117. br.ErrMsg = "指标为空"
  1118. br.IsSendEmail = false
  1119. return
  1120. }
  1121. calendar := req.Calendar
  1122. if calendar == "" {
  1123. calendar = "公历"
  1124. }
  1125. chartInfo := new(data_manage.ChartInfoView)
  1126. chartInfo.ChartType = req.ChartType
  1127. edbInfoIdList := make([]int, 0)
  1128. edbInfoIdMapping := make(map[int]*data_manage.ChartSaveItem)
  1129. for _, v := range req.ChartEdbInfoList {
  1130. edbInfoIdList = append(edbInfoIdList, v.EdbInfoId)
  1131. edbInfoIdMapping[v.EdbInfoId] = v
  1132. }
  1133. // 区分是否是来自平衡表图表的数据
  1134. var chartInfoDataShow data.ChartInfoDataShow
  1135. if req.ChartSource == utils.CHART_SOURCE_BALANCE_EXCEL { //来自平衡表图表的数据
  1136. excelChartInfoDataShow := new(data.ExcelChartInfoDataShow)
  1137. // 相关联指标
  1138. mappingListTmp, dataListMap, err, errMsg := excel.GetBalanceExcelChartSingle(chartInfo.ChartInfoId, req.ChartEdbInfoList[0].EdbInfoId, "")
  1139. if err != nil {
  1140. br.Msg = errMsg
  1141. br.ErrMsg = err.Error()
  1142. return
  1143. }
  1144. excelChartInfoDataShow.DataListMap = dataListMap
  1145. excelChartInfoDataShow.MappingListTmp = mappingListTmp
  1146. chartInfoDataShow = excelChartInfoDataShow
  1147. } else {
  1148. chartInfoDataShow = &data.BaseChartInfoDataShow{}
  1149. }
  1150. mappingList, err := chartInfoDataShow.GetChartEdbMappingListByEdbInfoIdList(edbInfoIdList)
  1151. if err != nil {
  1152. br.Msg = "获取失败"
  1153. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  1154. return
  1155. }
  1156. yearMax := 0
  1157. for k, v := range mappingList {
  1158. if tmpV, ok := edbInfoIdMapping[v.EdbInfoId]; ok {
  1159. v.EdbInfoType = tmpV.EdbInfoType
  1160. v.MaxData = tmpV.MaxData
  1161. v.MinData = tmpV.MinData
  1162. v.IsOrder = tmpV.IsOrder
  1163. v.IsAxis = tmpV.IsAxis
  1164. v.EdbInfoType = tmpV.EdbInfoType
  1165. v.LeadValue = tmpV.LeadValue
  1166. v.LeadUnit = tmpV.LeadUnit
  1167. v.ChartStyle = tmpV.ChartStyle
  1168. v.ChartColor = tmpV.ChartColor
  1169. v.PredictChartColor = tmpV.PredictChartColor
  1170. v.ChartWidth = tmpV.ChartWidth
  1171. //v.Source = tmpV.Source
  1172. // 得到指标更新的最新的年份
  1173. if req.DateType == utils.DateTypeNYears && v.LatestDate != "" {
  1174. lastDateT, tErr := time.Parse(utils.FormatDate, v.LatestDate)
  1175. if tErr != nil {
  1176. br.Msg = "获取失败"
  1177. br.ErrMsg = "获取图表日期信息失败,Err:" + tErr.Error()
  1178. return
  1179. }
  1180. if lastDateT.Year() > yearMax {
  1181. yearMax = lastDateT.Year()
  1182. }
  1183. }
  1184. }
  1185. if req.ChartEdbInfoList[k].IsConvert == 1 {
  1186. v.IsConvert = 1
  1187. v.ConvertType = req.ChartEdbInfoList[k].ConvertType
  1188. v.ConvertValue = req.ChartEdbInfoList[k].ConvertValue
  1189. v.ConvertUnit = req.ChartEdbInfoList[k].ConvertUnit
  1190. v.ConvertEnUnit = req.ChartEdbInfoList[k].ConvertEnUnit
  1191. }
  1192. mappingList[k] = v
  1193. }
  1194. // 开始/结束日期
  1195. startDate, endDate := utils.GetDateByDateTypeV2(req.DateType, req.StartDate, req.EndDate, req.StartYear, yearMax)
  1196. if startDate == "" {
  1197. br.Msg = "获取失败"
  1198. br.ErrMsg = "获取失败 时间格式错误"
  1199. return
  1200. }
  1201. var seasonExtraConfig string
  1202. if req.ChartType == 2 {
  1203. seasonExtra, tErr := json.Marshal(req.SeasonExtraConfig)
  1204. if tErr != nil {
  1205. br.Msg = "季节性图表配置信息异常"
  1206. br.ErrMsg = "季节性图表配置信息异常,Err:" + tErr.Error()
  1207. return
  1208. }
  1209. seasonExtraConfig = string(seasonExtra)
  1210. }
  1211. // 图表额外数据参数
  1212. extraConfigStr := chartInfo.ExtraConfig
  1213. // 柱方图的一些配置
  1214. var barConfig data_manage.BarChartInfoReq
  1215. if chartInfo != nil && chartInfo.ChartType == 7 {
  1216. if chartInfo.BarConfig == `` {
  1217. br.Msg = "柱方图未配置"
  1218. br.ErrMsg = "柱方图未配置"
  1219. return
  1220. }
  1221. err := json.Unmarshal([]byte(chartInfo.BarConfig), &barConfig)
  1222. if err != nil {
  1223. br.Msg = "柱方图配置异常"
  1224. br.ErrMsg = "柱方图配置异常"
  1225. return
  1226. }
  1227. extraConfigStr = chartInfo.BarConfig
  1228. } else if chartInfo != nil && chartInfo.ChartType == utils.CHART_TYPE_SECTION_COMBINE {
  1229. extraConfigStr = req.ExtraConfig
  1230. }
  1231. // 获取图表中的指标数据
  1232. edbList, xEdbIdValue, yDataList, dataResp, err, errMsg := data.GetChartEdbDataV2(0, req.ChartType, calendar, startDate, endDate, mappingList, extraConfigStr, seasonExtraConfig, chartInfoDataShow)
  1233. if err != nil {
  1234. br.Msg = "获取失败"
  1235. if errMsg != `` {
  1236. br.Msg = errMsg
  1237. }
  1238. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  1239. return
  1240. }
  1241. // 单位
  1242. if req.ChartType == utils.CHART_TYPE_BAR && len(yDataList) > 0 {
  1243. chartInfo.Unit = yDataList[0].Unit
  1244. chartInfo.UnitEn = yDataList[0].UnitEn
  1245. }
  1246. warnEdbList := make([]string, 0)
  1247. for _, v := range edbList {
  1248. if v.IsNullData {
  1249. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  1250. }
  1251. }
  1252. if len(warnEdbList) > 0 {
  1253. chartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  1254. }
  1255. //图表操作权限
  1256. chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, true)
  1257. //判断是否需要展示英文标识
  1258. chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, edbList, chartInfo.Source, chartInfo.ChartType)
  1259. chartInfo.Button = data_manage.ChartViewButton{
  1260. IsEdit: chartInfo.IsEdit,
  1261. IsEnChart: chartInfo.IsEnChart,
  1262. IsAdd: chartInfo.IsAdd,
  1263. IsCopy: true,
  1264. IsSetName: chartInfo.IsSetName,
  1265. }
  1266. // 图表的指标来源
  1267. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  1268. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  1269. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  1270. // 标识线计算
  1271. if req.MarkersLines != "" {
  1272. markerLines := make([]data_manage.MarkersLine, 0)
  1273. err = json.Unmarshal([]byte(req.MarkersLines), &markerLines)
  1274. if err != nil {
  1275. br.Msg = "标识线配置异常"
  1276. br.ErrMsg = "标识线配置异常" + err.Error()
  1277. return
  1278. }
  1279. for i := range markerLines {
  1280. if markerLines[i].EdbType == 0 && markerLines[i].TimeIntervalType == 0 && markerLines[i].Axis != 3 {
  1281. // 图上第一个指标且时间区间跟随图表
  1282. if markerLines[i].MarkLineType == 2 {
  1283. if edbList[0].IsAxis == 1 {
  1284. value, err := data.MarkerLineCalculate(markerLines[i], edbList[0].DataList, chartInfo)
  1285. if err != nil {
  1286. br.Msg = "标识线配置异常"
  1287. br.ErrMsg = "标识线配置异常" + err.Error()
  1288. return
  1289. }
  1290. markerLines[i].Value = value
  1291. } else {
  1292. // 其他的都走指标计算
  1293. edbInfo, err := data_manage.GetEdbInfoById(markerLines[i].EdbInfoId)
  1294. if err != nil {
  1295. br.Msg = "指标计算标识线获取指标信息异常"
  1296. br.ErrMsg = "指标计算标识线获取指标信息异常" + err.Error()
  1297. return
  1298. }
  1299. // 判断时间区间不为跟随图表的情况
  1300. if markerLines[i].TimeIntervalType != 0 {
  1301. startDate = markerLines[i].StartDate.Date
  1302. endDate = markerLines[i].EndDate.Date
  1303. }
  1304. dataList, err := data_manage.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, edbInfo.EdbInfoId, startDate, endDate)
  1305. if err != nil {
  1306. br.Msg = "指标计算标识线获取指标数据异常"
  1307. br.ErrMsg = "指标计算标识线获取指标数据异常" + err.Error()
  1308. return
  1309. }
  1310. value, err := data.MarkerLineCalculate(markerLines[i], dataList, chartInfo)
  1311. if err != nil {
  1312. br.Msg = "标识线配置异常"
  1313. br.ErrMsg = "标识线配置异常" + err.Error()
  1314. return
  1315. }
  1316. markerLines[i].Value = value
  1317. }
  1318. }
  1319. }
  1320. }
  1321. markerLineStr, err := json.Marshal(markerLines)
  1322. if err != nil {
  1323. br.Msg = "标识线配置异常"
  1324. br.ErrMsg = "标识线配置异常" + err.Error()
  1325. return
  1326. }
  1327. chartInfo.MarkersLines = string(markerLineStr)
  1328. }
  1329. resp := new(data_manage.ChartInfoDetailResp)
  1330. resp.ChartInfo = chartInfo
  1331. resp.EdbInfoList = edbList
  1332. resp.XEdbIdValue = xEdbIdValue
  1333. resp.YDataList = yDataList
  1334. resp.BarChartInfo = barConfig
  1335. resp.DataResp = dataResp
  1336. br.Ret = 200
  1337. br.Success = true
  1338. br.Msg = "获取成功"
  1339. br.Data = resp
  1340. }
  1341. // ChartInfoDetailV2
  1342. // @Title 获取图表详情
  1343. // @Description 获取图表详情接口
  1344. // @Param ChartInfoId query int true "图表id"
  1345. // @Success 200 {object} data_manage.ChartInfoDetailResp
  1346. // @router /chart_info/detail/v2 [get]
  1347. func (this *ChartInfoController) ChartInfoDetailV2() {
  1348. br := new(models.BaseResponse).Init()
  1349. defer func() {
  1350. this.Data["json"] = br
  1351. this.ServeJSON()
  1352. }()
  1353. sysUser := this.SysUser
  1354. if sysUser == nil {
  1355. br.Msg = "请登录"
  1356. br.ErrMsg = "请登录,SysUser Is Empty"
  1357. br.Ret = 408
  1358. return
  1359. }
  1360. chartInfoId, _ := this.GetInt("ChartInfoId")
  1361. //startDate = strconv.Itoa(time.Now().Year()) + "-01-01"
  1362. if chartInfoId <= 0 {
  1363. br.Msg = "请选择图表"
  1364. br.IsSendEmail = false
  1365. return
  1366. }
  1367. chartInfo, err := data_manage.GetChartInfoViewById(chartInfoId)
  1368. if err != nil {
  1369. if utils.IsErrNoRow(err) {
  1370. br.Msg = "该图表已删除,自动查看下一图表"
  1371. br.ErrMsg = "该图表已删除,自动查看下一图表,Err:" + err.Error()
  1372. br.Ret = 406
  1373. return
  1374. }
  1375. br.Msg = "获取失败"
  1376. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1377. return
  1378. }
  1379. resp := new(data_manage.ChartInfoDetailResp)
  1380. // 图表数据权限
  1381. {
  1382. // 图表分类
  1383. chartClassify, err := data_manage.GetChartClassifyById(chartInfo.ChartClassifyId)
  1384. if err != nil {
  1385. br.Msg = "获取失败"
  1386. br.ErrMsg = "获取图表分类信息失败,Err:" + err.Error()
  1387. return
  1388. }
  1389. // 已授权分类id
  1390. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, chartInfo.ChartInfoId, chartInfo.ChartClassifyId)
  1391. if err != nil {
  1392. br.Msg = "获取失败"
  1393. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  1394. return
  1395. }
  1396. chartInfo.HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartInfo.IsJoinPermission, chartClassify.IsJoinPermission, chartInfo.ChartInfoId, chartInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  1397. }
  1398. // 获取主题样式
  1399. chartTheme, err := data.GetChartThemeConfig(chartInfo.ChartThemeId, chartInfo.Source, chartInfo.ChartType)
  1400. if err != nil {
  1401. br.Msg = "获取失败"
  1402. br.ErrMsg = "获取主题信息失败,Err:" + err.Error()
  1403. return
  1404. }
  1405. chartInfo.ChartThemeStyle = chartTheme.Config
  1406. chartInfo.ChartThemeId = chartTheme.ChartThemeId
  1407. dateType := chartInfo.DateType
  1408. fmt.Println("dateType:", dateType)
  1409. chartType := chartInfo.ChartType
  1410. startDate := chartInfo.StartDate
  1411. endDate := chartInfo.EndDate
  1412. seasonStartDate := chartInfo.SeasonStartDate
  1413. seasonEndDate := chartInfo.SeasonEndDate
  1414. startYear := chartInfo.StartYear
  1415. calendar := chartInfo.Calendar
  1416. if calendar == "" {
  1417. calendar = "公历"
  1418. }
  1419. // 相关联指标
  1420. mappingList, err := data_manage.GetChartEdbMappingList(chartInfoId)
  1421. if err != nil {
  1422. br.Msg = "获取失败"
  1423. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  1424. return
  1425. }
  1426. if chartType == 2 {
  1427. startDate = seasonStartDate
  1428. endDate = seasonEndDate
  1429. if dateType <= 0 {
  1430. if startDate != "" {
  1431. dateType = 5
  1432. } else {
  1433. dateType = utils.DateTypeNYears
  1434. }
  1435. }
  1436. } else {
  1437. if dateType <= 0 {
  1438. dateType = 3
  1439. }
  1440. }
  1441. yearMax := 0
  1442. if dateType == utils.DateTypeNYears {
  1443. for _, v := range mappingList {
  1444. if v.LatestDate != "" {
  1445. lastDateT, tErr := time.Parse(utils.FormatDate, v.LatestDate)
  1446. if tErr != nil {
  1447. br.Msg = "获取失败"
  1448. br.ErrMsg = "获取图表日期信息失败,Err:" + tErr.Error()
  1449. return
  1450. }
  1451. if lastDateT.Year() > yearMax {
  1452. yearMax = lastDateT.Year()
  1453. }
  1454. }
  1455. }
  1456. }
  1457. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, yearMax)
  1458. if chartInfo.ChartType == 2 {
  1459. chartInfo.StartDate = startDate
  1460. chartInfo.EndDate = endDate
  1461. }
  1462. // 图表额外数据参数
  1463. extraConfigStr := chartInfo.ExtraConfig
  1464. // 柱方图的一些配置
  1465. var barConfig data_manage.BarChartInfoReq
  1466. if chartInfo != nil && chartInfo.ChartType == 7 {
  1467. if chartInfo.BarConfig == `` {
  1468. br.Msg = "柱方图未配置"
  1469. br.ErrMsg = "柱方图未配置"
  1470. return
  1471. }
  1472. err := json.Unmarshal([]byte(chartInfo.BarConfig), &barConfig)
  1473. if err != nil {
  1474. br.Msg = "柱方图配置异常"
  1475. br.ErrMsg = "柱方图配置异常"
  1476. return
  1477. }
  1478. extraConfigStr = chartInfo.BarConfig
  1479. }
  1480. if chartInfo.HaveOperaAuth {
  1481. // 获取图表中的指标数据
  1482. edbList, xEdbIdValue, yDataList, dataResp, err, errMsg := data.GetChartEdbData(chartInfoId, chartType, calendar, startDate, endDate, mappingList, extraConfigStr, chartInfo.SeasonExtraConfig)
  1483. if err != nil {
  1484. br.Msg = "获取失败"
  1485. if errMsg != `` {
  1486. br.Msg = errMsg
  1487. }
  1488. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  1489. return
  1490. }
  1491. // 单位
  1492. if chartType == utils.CHART_TYPE_BAR && len(yDataList) > 0 {
  1493. chartInfo.Unit = yDataList[0].Unit
  1494. chartInfo.UnitEn = yDataList[0].UnitEn
  1495. }
  1496. warnEdbList := make([]string, 0)
  1497. for _, v := range edbList {
  1498. if v.IsNullData {
  1499. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  1500. }
  1501. }
  1502. if len(warnEdbList) > 0 {
  1503. chartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  1504. }
  1505. if chartInfoId > 0 && chartInfo != nil {
  1506. //判断是否加入我的图库
  1507. {
  1508. var myChartCondition string
  1509. var myChartPars []interface{}
  1510. myChartCondition += ` AND a.admin_id=? `
  1511. myChartPars = append(myChartPars, sysUser.AdminId)
  1512. myChartCondition += ` AND a.chart_info_id=? `
  1513. myChartPars = append(myChartPars, chartInfo.ChartInfoId)
  1514. myChartList, err := data_manage.GetMyChartByCondition(myChartCondition, myChartPars)
  1515. if err != nil && !utils.IsErrNoRow(err) {
  1516. br.Msg = "获取失败"
  1517. br.ErrMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
  1518. return
  1519. }
  1520. if myChartList != nil && len(myChartList) > 0 {
  1521. chartInfo.IsAdd = true
  1522. chartInfo.MyChartId = myChartList[0].MyChartId
  1523. chartInfo.MyChartClassifyId = myChartList[0].MyChartClassifyId
  1524. }
  1525. }
  1526. }
  1527. //判断是否需要展示英文标识
  1528. chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, edbList, chartInfo.Source, chartInfo.ChartType)
  1529. // 图表的指标来源
  1530. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  1531. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  1532. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  1533. // 指标权限
  1534. {
  1535. classifyMap := make(map[int]*data_manage.EdbClassify)
  1536. // 分类
  1537. {
  1538. classifyIdList := make([]int, 0)
  1539. for _, v := range edbList {
  1540. classifyIdList = append(classifyIdList, v.ClassifyId)
  1541. }
  1542. classifyList, tmpErr := data_manage.GetEdbClassifyByIdList(classifyIdList)
  1543. if tmpErr != nil {
  1544. br.Msg = "获取失败"
  1545. br.ErrMsg = "获取分类列表失败,Err:" + tmpErr.Error()
  1546. return
  1547. }
  1548. for _, v := range classifyList {
  1549. classifyMap[v.ClassifyId] = v
  1550. }
  1551. }
  1552. // 获取所有有权限的指标和分类
  1553. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(sysUser.AdminId, 0, 0)
  1554. if err != nil {
  1555. br.Msg = "获取失败"
  1556. br.ErrMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  1557. return
  1558. }
  1559. for _, item := range edbList {
  1560. // 数据权限
  1561. if currClassify, ok := classifyMap[item.ClassifyId]; ok {
  1562. item.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(item.IsJoinPermission, currClassify.IsJoinPermission, item.EdbInfoId, item.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  1563. }
  1564. }
  1565. }
  1566. // 没有就返回空数组
  1567. if len(edbList) <= 0 {
  1568. edbList = make([]*data_manage.ChartEdbInfoMapping, 0)
  1569. }
  1570. resp.EdbInfoList = edbList
  1571. resp.XEdbIdValue = xEdbIdValue
  1572. resp.YDataList = yDataList
  1573. resp.DataResp = dataResp
  1574. } else {
  1575. resp.EdbInfoList = mappingList
  1576. }
  1577. //图表操作权限
  1578. chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, chartInfo.HaveOperaAuth)
  1579. chartInfo.Button = data_manage.ChartViewButton{
  1580. IsEdit: chartInfo.IsEdit,
  1581. IsEnChart: chartInfo.IsEnChart,
  1582. IsAdd: chartInfo.IsAdd,
  1583. IsCopy: true,
  1584. IsSetName: chartInfo.IsSetName,
  1585. }
  1586. resp.ChartInfo = chartInfo
  1587. resp.BarChartInfo = barConfig
  1588. br.Ret = 200
  1589. br.Success = true
  1590. br.Msg = "获取成功"
  1591. br.Data = resp
  1592. }
  1593. // @Title 图表指标模糊搜索
  1594. // @Description 图表指标模糊搜索接口
  1595. // @Param KeyWord query string true "指标名称/ID"
  1596. // @Success 200 {object} data_manage.ChartEdbInfo
  1597. // @router /chart_info/edb_info/search [get]
  1598. func (this *ChartInfoController) ChartInfoEdbInfoSearch() {
  1599. br := new(models.BaseResponse).Init()
  1600. defer func() {
  1601. this.Data["json"] = br
  1602. this.ServeJSON()
  1603. }()
  1604. sysUser := this.SysUser
  1605. if sysUser == nil {
  1606. br.Msg = "请登录"
  1607. br.ErrMsg = "请登录,SysUser Is Empty"
  1608. br.Ret = 408
  1609. return
  1610. }
  1611. KeyWord := this.GetString("KeyWord")
  1612. //if KeyWord == "" {
  1613. // br.Msg = "请输入指标名称/指标ID"
  1614. // return
  1615. //}
  1616. var err error
  1617. searchList := make([]*data_manage.ChartEdbInfo, 0)
  1618. searchList, err = data_manage.EdbInfoSearchByKeyWord(KeyWord)
  1619. if err != nil {
  1620. br.Msg = "获取失败"
  1621. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1622. return
  1623. }
  1624. if searchList == nil {
  1625. searchList = make([]*data_manage.ChartEdbInfo, 0)
  1626. }
  1627. lenSearchList := len(searchList)
  1628. for i := 0; i < lenSearchList; i++ {
  1629. searchList[i].EdbNameAlias = searchList[i].EdbName
  1630. }
  1631. for i := 0; i < lenSearchList; i++ {
  1632. for j := 0; j < lenSearchList; j++ {
  1633. if (searchList[i].EdbNameAlias == searchList[j].EdbNameAlias) &&
  1634. (searchList[i].EdbInfoId != searchList[j].EdbInfoId) &&
  1635. !(strings.Contains(searchList[i].EdbName, searchList[i].SourceName)) {
  1636. searchList[i].EdbName = searchList[i].EdbName + "(" + searchList[i].SourceName + ")"
  1637. }
  1638. }
  1639. }
  1640. br.Ret = 200
  1641. br.Success = true
  1642. br.Msg = "获取成功"
  1643. br.Data = searchList
  1644. }
  1645. // @Title 图表-获取指标详情
  1646. // @Description 图表-获取指标详情接口
  1647. // @Param EdbInfoId query int true "指标ID"
  1648. // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:自定义起始时间至今,7:18年至今,8:19年至今,9:20年至今"
  1649. // @Param StartDate query string true "自定义开始日期"
  1650. // @Param EndDate query string true "自定义结束日期"
  1651. // @Param EdbInfoType query int true "1:标准指标,0:领先指标,默认为标准指标"
  1652. // @Param LeadValue query int true "领先值"
  1653. // @Param LeadUnit query string true "领先单位:天,月,季,周"
  1654. // @Success 200 {object} data_manage.ChartEdbInfoDetailResp
  1655. // @router /chart_info/edb_info/detail [get]
  1656. func (this *ChartInfoController) ChartInfoEdbInfoDetail() {
  1657. br := new(models.BaseResponse).Init()
  1658. defer func() {
  1659. this.Data["json"] = br
  1660. this.ServeJSON()
  1661. }()
  1662. sysUser := this.SysUser
  1663. if sysUser == nil {
  1664. br.Msg = "请登录"
  1665. br.ErrMsg = "请登录,SysUser Is Empty"
  1666. br.Ret = 408
  1667. return
  1668. }
  1669. edbInfoId, _ := this.GetInt("EdbInfoId")
  1670. if edbInfoId <= 0 {
  1671. br.Msg = "参数错误"
  1672. return
  1673. }
  1674. dateType, _ := this.GetInt("DateType")
  1675. if dateType <= 0 {
  1676. dateType = 3
  1677. }
  1678. edbInfoType, _ := this.GetInt("EdbInfoType")
  1679. if edbInfoType < 0 {
  1680. edbInfoType = 1
  1681. }
  1682. leadValue, _ := this.GetInt("LeadValue")
  1683. if leadValue < 0 {
  1684. leadValue = 0
  1685. }
  1686. leadUnit := this.GetString("LeadUnit")
  1687. startDate := this.GetString("StartDate")
  1688. endDate := this.GetString("EndDate")
  1689. startYear, _ := this.GetInt("StartYear")
  1690. isTimeBetween := false //是否是时间区间
  1691. if dateType == 5 {
  1692. isTimeBetween = true
  1693. }
  1694. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  1695. if err != nil {
  1696. br.Msg = "获取失败"
  1697. br.Msg = "获取失败,Err:" + err.Error()
  1698. return
  1699. }
  1700. maxYear := 0
  1701. if edbInfo.LatestDate != "" {
  1702. latestDateT, _ := time.Parse(utils.FormatDate, edbInfo.LatestDate)
  1703. maxYear = latestDateT.Year()
  1704. }
  1705. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, maxYear)
  1706. if startDate == "" {
  1707. br.Msg = "参数错误"
  1708. br.Msg = "参数错误,无效的查询日期"
  1709. return
  1710. }
  1711. var startDateReal string
  1712. var diffSeconds int64
  1713. if leadValue > 0 && leadUnit != "" {
  1714. var startTimeRealTemp time.Time
  1715. startDateParse, err := time.Parse(utils.FormatDate, startDate)
  1716. if err != nil {
  1717. br.Msg = "获取数据失败"
  1718. br.ErrMsg = "获取数据失败,日期格式错误:startDate:" + startDate
  1719. return
  1720. }
  1721. switch leadUnit {
  1722. case "天":
  1723. startTimeRealTemp = startDateParse.AddDate(0, 0, -leadValue)
  1724. case "月":
  1725. startTimeRealTemp = startDateParse.AddDate(0, -leadValue, 0)
  1726. case "季":
  1727. startTimeRealTemp = startDateParse.AddDate(0, -3*leadValue, 0)
  1728. case "周":
  1729. startTimeRealTemp = startDateParse.AddDate(0, 0, -7*leadValue)
  1730. case "年":
  1731. startTimeRealTemp = startDateParse.AddDate(-leadValue, 0, 0)
  1732. }
  1733. if startTimeRealTemp.Before(startDateParse) {
  1734. startDateReal = startTimeRealTemp.Format(utils.FormatDate)
  1735. diffSeconds = (int64(startTimeRealTemp.UnixNano()) - int64(startDateParse.UnixNano())) / 1e6
  1736. } else {
  1737. startDateReal = startDate
  1738. diffSeconds = 0
  1739. }
  1740. } else {
  1741. startDateReal = startDate
  1742. }
  1743. var dataList []*data_manage.EdbDataList
  1744. var minData, maxData float64
  1745. switch edbInfo.EdbInfoType {
  1746. case 0: //普通源指标
  1747. dataList, err = data_manage.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, edbInfoId, startDateReal, endDate)
  1748. if err != nil {
  1749. br.Msg = "获取失败"
  1750. br.Msg = "获取失败,Err:" + err.Error()
  1751. return
  1752. }
  1753. //查询区间内最大最小值
  1754. minData, maxData, err = data_manage.GetEdbDataListMinAndMax(edbInfo.Source, edbInfo.SubSource, edbInfoId, startDateReal, endDate)
  1755. if err != nil {
  1756. br.Msg = "获取失败"
  1757. br.Msg = "获取指标最新的最大最小值失败,Err:" + err.Error()
  1758. return
  1759. }
  1760. case 1: //预测指标
  1761. tmpDataList, sourceEdbInfoItem, _, err, _ := data.GetPredictDataListByPredictEdbInfo(edbInfo, startDateReal, endDate, isTimeBetween)
  1762. if err != nil {
  1763. br.Msg = "获取失败"
  1764. br.Msg = "获取失败,Err:" + err.Error()
  1765. return
  1766. }
  1767. dataList = tmpDataList
  1768. // 有预测数据,且为普通的预测指标
  1769. if len(dataList) > 0 && edbInfo.EdbInfoType == 0 {
  1770. //查询区间内最大最小值
  1771. minData, maxData, err = data_manage.GetEdbDataListMinAndMax(sourceEdbInfoItem.Source, sourceEdbInfoItem.SubSource, sourceEdbInfoItem.EdbInfoId, startDateReal, endDate)
  1772. if err != nil {
  1773. br.Msg = "获取失败"
  1774. br.Msg = "获取指标最新的最大最小值失败,Err:" + err.Error()
  1775. return
  1776. }
  1777. tmpValue := dataList[len(dataList)-1]
  1778. // 如果最大值 小于 预测值,那么将预测值作为最大值数据返回
  1779. if edbInfo.MaxValue < tmpValue.Value {
  1780. maxData = tmpValue.Value
  1781. }
  1782. // 如果最小值 大于 预测值,那么将预测值作为最小值数据返回
  1783. if edbInfo.MinValue > tmpValue.Value {
  1784. minData = tmpValue.Value
  1785. }
  1786. }
  1787. }
  1788. moveLatestDate := edbInfo.LatestDate
  1789. if diffSeconds != 0 {
  1790. dataListLen := len(dataList)
  1791. for i := 0; i < dataListLen; i++ {
  1792. dataList[i].DataTimestamp = dataList[i].DataTimestamp - diffSeconds
  1793. }
  1794. day, err := utils.GetDaysBetween2Date(utils.FormatDate, startDate, startDateReal)
  1795. if err != nil {
  1796. br.Msg = "获取失败"
  1797. br.Msg = "获取领先滞后的的日期间隔失败,Err:" + err.Error()
  1798. return
  1799. }
  1800. moveLatestDateTime, err := time.ParseInLocation(utils.FormatDate, moveLatestDate, time.Local)
  1801. if err != nil {
  1802. br.Msg = "获取失败"
  1803. br.Msg = "指标日期转换失败,Err:" + err.Error()
  1804. return
  1805. }
  1806. moveLatestDate = moveLatestDateTime.AddDate(0, 0, day).Format(utils.FormatDate)
  1807. }
  1808. mapping := new(data_manage.ChartEdbInfoMapping)
  1809. mapping.EdbInfoId = edbInfo.EdbInfoId
  1810. mapping.EdbInfoCategoryType = edbInfo.EdbInfoType
  1811. mapping.SourceName = edbInfo.SourceName
  1812. mapping.Source = edbInfo.Source
  1813. mapping.EdbCode = edbInfo.EdbCode
  1814. mapping.EdbName = edbInfo.EdbName
  1815. mapping.EdbType = edbInfo.EdbType
  1816. mapping.Frequency = edbInfo.Frequency
  1817. mapping.Unit = edbInfo.Unit
  1818. mapping.StartDate = utils.TimeToFormatDate(edbInfo.StartDate)
  1819. mapping.EndDate = utils.TimeToFormatDate(edbInfo.EndDate)
  1820. mapping.ChartEdbMappingId = 0
  1821. mapping.ChartInfoId = 0
  1822. mapping.MaxData = maxData
  1823. mapping.MinData = minData
  1824. mapping.IsOrder = false
  1825. mapping.IsAxis = 1
  1826. mapping.EdbInfoType = 1
  1827. mapping.LeadValue = 0
  1828. mapping.LeadUnit = ""
  1829. mapping.LeadUnitEn = ""
  1830. mapping.ChartStyle = ""
  1831. mapping.ChartColor = ""
  1832. mapping.PredictChartColor = ""
  1833. mapping.ChartWidth = 0
  1834. mapping.LatestDate = edbInfo.LatestDate
  1835. mapping.MoveLatestDate = moveLatestDate
  1836. mapping.DataList = dataList
  1837. resp := new(data_manage.ChartEdbInfoDetailResp)
  1838. resp.EdbInfo = mapping
  1839. br.Ret = 200
  1840. br.Success = true
  1841. br.Msg = "获取成功"
  1842. br.Data = resp
  1843. }
  1844. // ChartInfoSearch
  1845. // @Title 图表模糊搜索
  1846. // @Description 图表模糊搜索接口
  1847. // @Param KeyWord query string true "图表名称"
  1848. // @Param IsShowMe query bool true "是否只看我的,true、false"
  1849. // @Success 200 {object} data_manage.ChartInfo
  1850. // @router /chart_info/search [get]
  1851. func (this *ChartInfoController) ChartInfoSearch() {
  1852. br := new(models.BaseResponse).Init()
  1853. defer func() {
  1854. this.Data["json"] = br
  1855. this.ServeJSON()
  1856. }()
  1857. sysUser := this.SysUser
  1858. if sysUser == nil {
  1859. br.Msg = "请登录"
  1860. br.ErrMsg = "请登录,SysUser Is Empty"
  1861. br.Ret = 408
  1862. return
  1863. }
  1864. keyWord := this.GetString("KeyWord")
  1865. searchList := make([]data_manage.ChartInfoMore, 0)
  1866. //var err error
  1867. //if KeyWord == "" {
  1868. // searchList, err = data_manage.ChartInfoSearchByKeyWord(KeyWord)
  1869. // if err != nil && !utils.IsErrNoRow(err) {
  1870. // br.Msg = "获取失败"
  1871. // br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1872. // return
  1873. // }
  1874. //} else {
  1875. // searchList, err = data.EsSearchChartInfo(KeyWord)
  1876. // if err != nil && !utils.IsErrNoRow(err) {
  1877. // br.Msg = "获取失败"
  1878. // br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1879. // return
  1880. // }
  1881. //}
  1882. //只看我的
  1883. isShowMe, _ := this.GetBool("IsShowMe")
  1884. showSysId := 0
  1885. if isShowMe {
  1886. showSysId = sysUser.AdminId
  1887. }
  1888. var keyWordArr []string
  1889. keyWordArr = append(keyWordArr, keyWord)
  1890. if keyWord != "" {
  1891. newKeyWord := strings.Split(keyWord, " ")
  1892. keyWordArr = append(keyWordArr, newKeyWord...)
  1893. }
  1894. existMap := make(map[int]string)
  1895. for _, v := range keyWordArr {
  1896. v = strings.Replace(v, " ", "%", -1)
  1897. newSearchList, err := data_manage.ChartInfoSearchByKeyWord(v, showSysId)
  1898. if err != nil && !utils.IsErrNoRow(err) {
  1899. br.Msg = "获取失败"
  1900. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  1901. return
  1902. }
  1903. for _, nv := range newSearchList {
  1904. if _, ok := existMap[nv.ChartInfoId]; !ok {
  1905. searchList = append(searchList, data_manage.ChartInfoMore{
  1906. ChartInfo: *nv,
  1907. })
  1908. }
  1909. existMap[nv.ChartInfoId] = nv.ChartName
  1910. }
  1911. }
  1912. if searchList == nil {
  1913. searchList = make([]data_manage.ChartInfoMore, 0)
  1914. }
  1915. // 数据权限
  1916. if len(searchList) > 0 {
  1917. // 涉及分类id
  1918. classifyIdList := make([]int, 0)
  1919. for _, v := range searchList {
  1920. classifyIdList = append(classifyIdList, v.ChartClassifyId)
  1921. }
  1922. // 图表分类
  1923. chartClassifyList, err := data_manage.GetChartClassifyByIdList(classifyIdList)
  1924. if err != nil {
  1925. br.Msg = "获取失败"
  1926. br.ErrMsg = "获取图表分类失败,Err:" + err.Error()
  1927. return
  1928. }
  1929. chartClassifyMap := make(map[int]*data_manage.ChartClassify)
  1930. for _, v := range chartClassifyList {
  1931. chartClassifyMap[v.ChartClassifyId] = v
  1932. }
  1933. // 已授权图表和分类id
  1934. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(sysUser.AdminId, 0, 0)
  1935. if err != nil {
  1936. br.Msg = "获取失败"
  1937. br.ErrMsg = "已授权图表和分类id失败,Err:" + err.Error()
  1938. return
  1939. }
  1940. // 权限判断
  1941. for k, v := range searchList {
  1942. if currClassify, ok := chartClassifyMap[v.ChartClassifyId]; ok {
  1943. searchList[k].HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.ChartInfoId, v.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  1944. }
  1945. }
  1946. }
  1947. //新增搜索词记录
  1948. {
  1949. searchKeyword := new(data_manage.SearchKeyword)
  1950. searchKeyword.KeyWord = keyWord
  1951. searchKeyword.CreateTime = time.Now()
  1952. go data_manage.AddSearchKeyword(searchKeyword)
  1953. }
  1954. br.Ret = 200
  1955. br.Success = true
  1956. br.Msg = "获取成功"
  1957. br.Data = searchList
  1958. }
  1959. // ChartInfoSearchByEs
  1960. // @Title 图表模糊搜索(从es获取)
  1961. // @Description 图表模糊搜索(从es获取)
  1962. // @Param Keyword query string true "图表名称"
  1963. // @Param IsShowMe query bool true "是否只看我的,true、false"
  1964. // @Success 200 {object} data_manage.ChartInfo
  1965. // @router /chart_info/search_by_es [get]
  1966. func (this *ChartInfoController) ChartInfoSearchByEs() {
  1967. br := new(models.BaseResponse).Init()
  1968. defer func() {
  1969. this.Data["json"] = br
  1970. this.ServeJSON()
  1971. }()
  1972. sysUser := this.SysUser
  1973. if sysUser == nil {
  1974. br.Msg = "请登录"
  1975. br.ErrMsg = "请登录,SysUser Is Empty"
  1976. br.Ret = 408
  1977. return
  1978. }
  1979. pageSize, _ := this.GetInt("PageSize")
  1980. currentIndex, _ := this.GetInt("CurrentIndex")
  1981. var startSize int
  1982. if pageSize <= 0 {
  1983. pageSize = utils.PageSize20
  1984. }
  1985. if currentIndex <= 0 {
  1986. currentIndex = 1
  1987. }
  1988. startSize = paging.StartIndex(currentIndex, pageSize)
  1989. keyword := this.GetString("Keyword")
  1990. //只看我的
  1991. isShowMe, _ := this.GetBool("IsShowMe")
  1992. showSysId := 0
  1993. if isShowMe {
  1994. showSysId = sysUser.AdminId
  1995. }
  1996. var searchList []*data_manage.ChartInfo
  1997. var total int64
  1998. var err error
  1999. // 获取当前账号的不可见指标
  2000. noPermissionChartIdList := make([]int, 0)
  2001. {
  2002. obj := data_manage.EdbInfoNoPermissionAdmin{}
  2003. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  2004. if err != nil && !utils.IsErrNoRow(err) {
  2005. br.Msg = "获取失败"
  2006. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  2007. return
  2008. }
  2009. for _, v := range confList {
  2010. noPermissionChartIdList = append(noPermissionChartIdList, v.ChartInfoId)
  2011. }
  2012. }
  2013. // 是否走ES
  2014. isEs := false
  2015. if keyword != "" {
  2016. searchList, total, err = data.EsSearchChartInfo(keyword, showSysId, []int{utils.CHART_SOURCE_DEFAULT}, noPermissionChartIdList, startSize, pageSize)
  2017. isEs = true
  2018. } else {
  2019. total, searchList, err = data_manage.ChartInfoSearchByEmptyKeyWord(showSysId, []int{utils.CHART_SOURCE_DEFAULT}, noPermissionChartIdList, startSize, pageSize)
  2020. if err != nil && !utils.IsErrNoRow(err) {
  2021. br.Msg = "获取失败"
  2022. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  2023. return
  2024. }
  2025. }
  2026. finalList := make([]*data_manage.ChartInfoMore, 0)
  2027. if len(searchList) > 0 {
  2028. // 涉及分类id
  2029. classifyIdList := make([]int, 0)
  2030. // 图表id
  2031. chartInfoIdList := make([]int, 0)
  2032. chartInfoIds := ""
  2033. chartEdbMap := make(map[int][]*data_manage.ChartEdbInfoMapping)
  2034. for _, v := range searchList {
  2035. chartInfoIds += strconv.Itoa(v.ChartInfoId) + ","
  2036. classifyIdList = append(classifyIdList, v.ChartClassifyId)
  2037. chartInfoIdList = append(chartInfoIdList, v.ChartInfoId)
  2038. }
  2039. if chartInfoIds != "" {
  2040. chartInfoIds = strings.Trim(chartInfoIds, ",")
  2041. //判断是否需要展示英文标识
  2042. edbList, e := data_manage.GetChartEdbMappingListByChartInfoIds(chartInfoIds)
  2043. if e != nil {
  2044. br.Msg = "获取失败"
  2045. br.ErrMsg = "获取图表,指标信息失败,Err:" + e.Error()
  2046. return
  2047. }
  2048. for _, v := range edbList {
  2049. chartEdbMap[v.ChartInfoId] = append(chartEdbMap[v.ChartInfoId], v)
  2050. }
  2051. }
  2052. // 当前列表中的分类map
  2053. chartClassifyMap := make(map[int]*data_manage.ChartClassify)
  2054. // 图表分类
  2055. {
  2056. chartClassifyList, err := data_manage.GetChartClassifyByIdList(classifyIdList)
  2057. if err != nil {
  2058. br.Msg = "获取失败"
  2059. br.ErrMsg = "获取图表分类失败,Err:" + err.Error()
  2060. return
  2061. }
  2062. for _, v := range chartClassifyList {
  2063. chartClassifyMap[v.ChartClassifyId] = v
  2064. }
  2065. }
  2066. // 图表
  2067. if isEs {
  2068. // 当前列表中的图表map
  2069. chartInfoMap := make(map[int]*data_manage.ChartInfo)
  2070. tmpChartList, err := data_manage.GetChartInfoByIdList(chartInfoIdList)
  2071. if err != nil {
  2072. br.Msg = "获取失败"
  2073. br.ErrMsg = "获取所有有权限的图表失败,Err:" + err.Error()
  2074. return
  2075. }
  2076. for _, tmpChartInfo := range tmpChartList {
  2077. chartInfoMap[tmpChartInfo.ChartInfoId] = tmpChartInfo
  2078. }
  2079. for _, v := range searchList {
  2080. // 图表权限
  2081. chartViewInfo, ok := chartInfoMap[v.ChartInfoId]
  2082. if !ok {
  2083. continue
  2084. }
  2085. v.IsJoinPermission = chartViewInfo.IsJoinPermission
  2086. }
  2087. }
  2088. // 已授权图表和分类id
  2089. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(sysUser.AdminId, 0, 0)
  2090. if err != nil {
  2091. br.Msg = "获取失败"
  2092. br.ErrMsg = "已授权图表和分类id失败,Err:" + err.Error()
  2093. return
  2094. }
  2095. for _, v := range searchList {
  2096. tmp := new(data_manage.ChartInfoMore)
  2097. tmp.ChartInfo = *v
  2098. //判断是否需要展示英文标识
  2099. if edbTmpList, ok := chartEdbMap[v.ChartInfoId]; ok {
  2100. tmp.IsEnChart = data.CheckIsEnChart(v.ChartNameEn, edbTmpList, v.Source, v.ChartType)
  2101. }
  2102. // 图表权限
  2103. if currClassify, ok := chartClassifyMap[v.ChartClassifyId]; ok {
  2104. tmp.HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.ChartInfoId, v.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  2105. }
  2106. finalList = append(finalList, tmp)
  2107. }
  2108. }
  2109. //新增搜索词记录
  2110. {
  2111. searchKeyword := new(data_manage.SearchKeyword)
  2112. searchKeyword.KeyWord = keyword
  2113. searchKeyword.CreateTime = time.Now()
  2114. go data_manage.AddSearchKeyword(searchKeyword)
  2115. }
  2116. page := paging.GetPaging(currentIndex, pageSize, int(total))
  2117. resp := data_manage.ChartInfoListByEsResp{
  2118. Paging: page,
  2119. List: finalList,
  2120. }
  2121. br.Ret = 200
  2122. br.Success = true
  2123. br.Msg = "获取成功"
  2124. br.Data = resp
  2125. }
  2126. // @Title 图表刷新接口
  2127. // @Description 图表刷新接口
  2128. // @Param ChartInfoId query int true "图表id"
  2129. // @Param UniqueCode query string true "唯一code"
  2130. // @Success Ret=200 刷新成功
  2131. // @router /chart_info/refresh [get]
  2132. func (this *EdbInfoController) ChartInfoRefresh() {
  2133. br := new(models.BaseResponse).Init()
  2134. defer func() {
  2135. this.Data["json"] = br
  2136. this.ServeJSON()
  2137. }()
  2138. sysUser := this.SysUser
  2139. if sysUser == nil {
  2140. br.Msg = "请登录"
  2141. br.ErrMsg = "请登录,SysUser Is Empty"
  2142. br.Ret = 408
  2143. return
  2144. }
  2145. chartInfoId, _ := this.GetInt("ChartInfoId")
  2146. uniqueCode := this.GetString("UniqueCode")
  2147. if chartInfoId <= 0 && uniqueCode == `` {
  2148. br.Msg = "参数错误"
  2149. br.ErrMsg = "参数错误:chartInfoId:" + strconv.Itoa(chartInfoId) + ",UniqueCode:" + uniqueCode
  2150. return
  2151. }
  2152. var chartInfo *data_manage.ChartInfo
  2153. var err error
  2154. if chartInfoId > 0 {
  2155. chartInfo, err = data_manage.GetChartInfoById(chartInfoId)
  2156. } else {
  2157. chartInfo, err = data_manage.GetChartInfoByUniqueCode(uniqueCode)
  2158. }
  2159. if err != nil {
  2160. if utils.IsErrNoRow(err) {
  2161. br.Msg = "图表已被删除,无需刷新"
  2162. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2163. return
  2164. }
  2165. br.Msg = "刷新失败"
  2166. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  2167. return
  2168. }
  2169. err, isAsync := data.ChartInfoRefreshV2(chartInfo.ChartInfoId)
  2170. if err != nil {
  2171. br.Msg = "刷新失败"
  2172. br.ErrMsg = "刷新图表关联指标信息失败,Err:" + err.Error()
  2173. return
  2174. }
  2175. /*
  2176. //err = data.ChartInfoRefresh(chartInfo.ChartInfoId)
  2177. //if err != nil {
  2178. // br.Msg = "刷新失败"
  2179. // br.ErrMsg = "刷新图表关联指标信息失败,Err:" + err.Error()
  2180. // return
  2181. //}
  2182. */
  2183. //清除图表缓存
  2184. {
  2185. key := utils.HZ_CHART_LIB_DETAIL + chartInfo.UniqueCode
  2186. _ = utils.Rc.Delete(key)
  2187. }
  2188. br.Ret = 200
  2189. br.Success = true
  2190. br.Msg = "刷新成功"
  2191. if isAsync {
  2192. br.Msg = "图表关联指标较多,请10分钟后刷新页面查看最新数据"
  2193. }
  2194. }
  2195. // @Title 设置图表图片
  2196. // @Description 设置图表图片接口
  2197. // @Param request body data_manage.SetChartInfoImageReq true "type json string"
  2198. // @Success Ret=200 保存成功
  2199. // @router /chart_info/image/set [post]
  2200. func (this *ChartInfoController) ChartInfoImageSet() {
  2201. br := new(models.BaseResponse).Init()
  2202. defer func() {
  2203. this.Data["json"] = br
  2204. this.ServeJSON()
  2205. }()
  2206. sysUser := this.SysUser
  2207. if sysUser == nil {
  2208. br.Msg = "请登录"
  2209. br.ErrMsg = "请登录,SysUser Is Empty"
  2210. br.Ret = 408
  2211. return
  2212. }
  2213. var req data_manage.SetChartInfoImageReq
  2214. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2215. if err != nil {
  2216. br.Msg = "参数解析异常!"
  2217. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2218. return
  2219. }
  2220. if req.ChartInfoId > 0 && req.ImageUrl != "" {
  2221. err = data_manage.EditChartInfoImage(&req)
  2222. if err != nil {
  2223. br.Msg = "保存失败"
  2224. br.ErrMsg = "保存失败,Err:" + err.Error()
  2225. return
  2226. }
  2227. //修改es数据
  2228. go data.EsAddOrEditChartInfo(req.ChartInfoId)
  2229. //修改my eta es数据
  2230. go data.EsAddOrEditMyChartInfoByChartInfoId(req.ChartInfoId)
  2231. }
  2232. br.Ret = 200
  2233. br.Success = true
  2234. br.Msg = "保存成功"
  2235. }
  2236. // ChartInfoDetailFromUniqueCode
  2237. // @Title 根据编码获取图表详情
  2238. // @Description 根据编码获取图表详情接口
  2239. // @Param UniqueCode query int true "图表唯一编码,如果是管理后台访问,传固定字符串:7c69b590249049942070ae9dcd5bf6dc"
  2240. // @Param IsCache query bool true "是否走缓存,默认false"
  2241. // @Success 200 {object} data_manage.ChartInfoDetailFromUniqueCodeResp
  2242. // @router /chart_info/detail/from_unique_code [get]
  2243. func (this *ChartInfoController) ChartInfoDetailFromUniqueCode() {
  2244. br := new(models.BaseResponse).Init()
  2245. defer func() {
  2246. this.Data["json"] = br
  2247. this.ServeJSON()
  2248. }()
  2249. sysUser := this.SysUser
  2250. if sysUser == nil {
  2251. br.Msg = "请登录"
  2252. br.ErrMsg = "请登录,SysUser Is Empty"
  2253. br.Ret = 408
  2254. return
  2255. }
  2256. uniqueCode := this.GetString("UniqueCode")
  2257. if uniqueCode == "" {
  2258. br.Msg = "参数错误"
  2259. br.ErrMsg = "参数错误,uniqueCode is empty"
  2260. return
  2261. }
  2262. //是否走缓存
  2263. isCache, _ := this.GetBool("IsCache")
  2264. status := true
  2265. chartInfo, err := data_manage.GetChartInfoViewByUniqueCode(uniqueCode)
  2266. if err != nil {
  2267. if utils.IsErrNoRow(err) {
  2268. status = false
  2269. } else {
  2270. br.Msg = "获取失败"
  2271. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  2272. return
  2273. }
  2274. }
  2275. if chartInfo == nil {
  2276. status = false
  2277. }
  2278. if !status {
  2279. resp := new(data_manage.ChartInfoDetailFromUniqueCodeResp)
  2280. endInfoList := make([]*data_manage.ChartEdbInfoMapping, 0)
  2281. resp.EdbInfoList = endInfoList
  2282. resp.ChartInfo = chartInfo
  2283. resp.Status = false
  2284. return
  2285. }
  2286. resp, isOk, msg, errMsg := GetChartInfoDetailFromUniqueCode(chartInfo, isCache, sysUser)
  2287. if !isOk {
  2288. br.Msg = msg
  2289. br.ErrMsg = errMsg
  2290. return
  2291. }
  2292. br.Ret = 200
  2293. br.Success = true
  2294. msg = "获取成功"
  2295. br.Data = resp
  2296. }
  2297. func GetChartInfoDetailFromUniqueCode(chartInfo *data_manage.ChartInfoView, isCache bool, sysUser *system.Admin) (resp *data_manage.ChartInfoDetailFromUniqueCodeResp, isOk bool, msg, errMsg string) {
  2298. resp = new(data_manage.ChartInfoDetailFromUniqueCodeResp)
  2299. msg = `获取失败`
  2300. adminId := sysUser.AdminId
  2301. // 图表数据权限
  2302. // 图表分类
  2303. chartClassify, err := data_manage.GetChartClassifyById(chartInfo.ChartClassifyId)
  2304. if err != nil {
  2305. errMsg = "获取图表分类信息失败,Err:" + err.Error()
  2306. return
  2307. }
  2308. // 已授权分类id
  2309. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(adminId, chartInfo.ChartInfoId, chartInfo.ChartClassifyId)
  2310. if err != nil {
  2311. errMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  2312. return
  2313. }
  2314. // 指标数据map
  2315. edbClassifyPermissionMap := make(map[int]data_manage_permission.EdbClassifyPermission)
  2316. defer func() {
  2317. if isOk {
  2318. // 这里跟当前用户相关的信息重新查询写入resp, 不使用缓存中的
  2319. {
  2320. //判断是否加入我的图库
  2321. var myChartCondition string
  2322. var myChartPars []interface{}
  2323. myChartCondition += ` AND a.admin_id=? `
  2324. myChartPars = append(myChartPars, adminId)
  2325. myChartCondition += ` AND a.chart_info_id=? `
  2326. myChartPars = append(myChartPars, chartInfo.ChartInfoId)
  2327. myChartList, err := data_manage.GetMyChartByCondition(myChartCondition, myChartPars)
  2328. if err != nil && !utils.IsErrNoRow(err) {
  2329. msg = "获取失败"
  2330. errMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
  2331. return
  2332. }
  2333. if myChartList != nil && len(myChartList) > 0 {
  2334. chartInfo.IsAdd = true
  2335. chartInfo.MyChartId = myChartList[0].MyChartId
  2336. chartInfo.MyChartClassifyId = myChartList[0].MyChartClassifyId
  2337. }
  2338. }
  2339. // 图表权限校验
  2340. {
  2341. resp.ChartInfo.HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartInfo.IsJoinPermission, chartClassify.IsJoinPermission, chartInfo.ChartInfoId, chartInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  2342. //图表操作权限
  2343. chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, resp.ChartInfo.HaveOperaAuth)
  2344. chartInfo.Button = data_manage.ChartViewButton{
  2345. IsEdit: chartInfo.IsEdit,
  2346. IsEnChart: chartInfo.IsEnChart,
  2347. IsAdd: chartInfo.IsAdd,
  2348. IsCopy: true,
  2349. IsSetName: chartInfo.IsSetName,
  2350. }
  2351. //if !resp.ChartInfo.HaveOperaAuth {
  2352. // for _, v := range resp.EdbInfoList {
  2353. // v.DataList = nil
  2354. // }
  2355. // resp.DataResp = nil
  2356. // resp.XEdbIdValue = []int{}
  2357. // resp.YDataList = []data_manage.YData{}
  2358. //}
  2359. }
  2360. // 指标权限
  2361. {
  2362. classifyMap := make(map[int]*data_manage.EdbClassify)
  2363. // 分类
  2364. {
  2365. classifyIdList := make([]int, 0)
  2366. for _, v := range resp.EdbInfoList {
  2367. classifyIdList = append(classifyIdList, v.ClassifyId)
  2368. }
  2369. classifyList, tmpErr := data_manage.GetEdbClassifyByIdList(classifyIdList)
  2370. if tmpErr != nil {
  2371. errMsg = "获取分类列表失败,Err:" + tmpErr.Error()
  2372. return
  2373. }
  2374. for _, v := range classifyList {
  2375. classifyMap[v.ClassifyId] = v
  2376. }
  2377. }
  2378. // 指标
  2379. if len(edbClassifyPermissionMap) < 0 {
  2380. edbInfoIdList := make([]int, 0)
  2381. for _, v := range resp.EdbInfoList {
  2382. edbInfoIdList = append(edbInfoIdList, v.EdbInfoId)
  2383. }
  2384. edbInfoList, tmpErr := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  2385. if tmpErr != nil {
  2386. errMsg = "获取指标列表失败,Err:" + tmpErr.Error()
  2387. return
  2388. }
  2389. for _, v := range edbInfoList {
  2390. edbClassifyPermissionMap[v.EdbInfoId] = data_manage_permission.EdbClassifyPermission{
  2391. ClassifyId: v.ClassifyId,
  2392. IsJoinPermission: v.IsJoinPermission,
  2393. EdbInfoId: v.EdbInfoId,
  2394. }
  2395. }
  2396. }
  2397. // 获取所有有权限的指标和分类
  2398. permissionEdbIdList, permissionClassifyIdList, err := data_manage_permission.GetUserEdbAndClassifyPermissionList(sysUser.AdminId, 0, 0)
  2399. if err != nil {
  2400. errMsg = "获取所有有权限的指标和分类失败,Err:" + err.Error()
  2401. return
  2402. }
  2403. for _, v := range resp.EdbInfoList {
  2404. // 数据权限
  2405. edbItem, ok := edbClassifyPermissionMap[v.EdbInfoId]
  2406. if !ok {
  2407. continue
  2408. }
  2409. if currClassify, ok := classifyMap[edbItem.ClassifyId]; ok {
  2410. v.HaveOperaAuth = data_manage_permission.CheckEdbPermissionByPermissionIdList(edbItem.IsJoinPermission, currClassify.IsJoinPermission, edbItem.EdbInfoId, edbItem.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  2411. }
  2412. }
  2413. }
  2414. }
  2415. }()
  2416. //判断是否存在缓存,如果存在缓存,那么直接从缓存中获取
  2417. key := data.GetChartInfoDataKey(chartInfo.ChartInfoId)
  2418. if utils.Re == nil && isCache {
  2419. if utils.Re == nil && utils.Rc.IsExist(key) {
  2420. if redisData, err1 := utils.Rc.RedisBytes(key); err1 == nil {
  2421. err := json.Unmarshal(redisData, &resp)
  2422. if err != nil || resp == nil {
  2423. return
  2424. }
  2425. isOk = true
  2426. fmt.Println("source redis")
  2427. return
  2428. }
  2429. }
  2430. }
  2431. // 获取主题样式
  2432. chartTheme, err := data.GetChartThemeConfig(chartInfo.ChartThemeId, chartInfo.Source, chartInfo.ChartType)
  2433. if err != nil {
  2434. msg = "获取失败"
  2435. errMsg = "获取主题信息失败,Err:" + err.Error()
  2436. return
  2437. }
  2438. chartInfo.ChartThemeStyle = chartTheme.Config
  2439. chartInfo.ChartThemeId = chartTheme.ChartThemeId
  2440. chartInfoId := chartInfo.ChartInfoId
  2441. dateType := chartInfo.DateType
  2442. startDate := chartInfo.StartDate
  2443. endDate := chartInfo.EndDate
  2444. startYear := chartInfo.StartYear
  2445. calendar := chartInfo.Calendar
  2446. chartType := chartInfo.ChartType
  2447. if calendar == "" {
  2448. calendar = "公历"
  2449. }
  2450. fmt.Println("a dateType:", dateType)
  2451. mappingList, err := data_manage.GetChartEdbMappingList(chartInfoId)
  2452. if err != nil {
  2453. msg = "获取失败"
  2454. errMsg = "获取图表,指标信息失败,Err:" + err.Error()
  2455. return
  2456. }
  2457. yearMax := 0
  2458. if dateType == utils.DateTypeNYears {
  2459. for _, v := range mappingList {
  2460. if v.LatestDate != "" {
  2461. lastDateT, tErr := time.Parse(utils.FormatDate, v.LatestDate)
  2462. if tErr != nil {
  2463. msg = "获取失败"
  2464. errMsg = "获取图表日期信息失败,Err:" + tErr.Error()
  2465. return
  2466. }
  2467. if lastDateT.Year() > yearMax {
  2468. yearMax = lastDateT.Year()
  2469. }
  2470. }
  2471. }
  2472. }
  2473. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, yearMax)
  2474. extraConfigStr := chartInfo.ExtraConfig //图表额外数据参数
  2475. var barConfig data_manage.BarChartInfoReq
  2476. // 柱方图的一些配置
  2477. if chartInfo != nil && chartInfo.ChartType == 7 {
  2478. if chartInfo.BarConfig == `` {
  2479. msg = "柱方图未配置"
  2480. errMsg = "柱方图未配置"
  2481. return
  2482. }
  2483. err := json.Unmarshal([]byte(chartInfo.BarConfig), &barConfig)
  2484. if err != nil {
  2485. msg = "柱方图配置异常"
  2486. errMsg = "柱方图配置异常"
  2487. return
  2488. }
  2489. extraConfigStr = chartInfo.BarConfig
  2490. }
  2491. // 获取图表中的指标数据
  2492. edbList, xEdbIdValue, yDataList, dataResp, err, errMsg := data.GetChartEdbData(chartInfoId, chartType, calendar, startDate, endDate, mappingList, extraConfigStr, chartInfo.SeasonExtraConfig)
  2493. if err != nil {
  2494. msg = "获取失败"
  2495. if errMsg != `` {
  2496. msg = errMsg
  2497. }
  2498. errMsg = "获取图表,指标信息失败,Err:" + err.Error()
  2499. return
  2500. }
  2501. // 单位
  2502. if chartType == utils.CHART_TYPE_BAR && len(yDataList) > 0 {
  2503. chartInfo.Unit = yDataList[0].Unit
  2504. chartInfo.UnitEn = yDataList[0].UnitEn
  2505. }
  2506. warnEdbList := make([]string, 0)
  2507. for _, v := range edbList {
  2508. if v.IsNullData {
  2509. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  2510. }
  2511. }
  2512. if len(warnEdbList) > 0 {
  2513. chartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  2514. }
  2515. /*
  2516. ChartClassify []*ChartClassifyView
  2517. */
  2518. chartViewClassify, _ := data_manage.GetChartClassifyViewById(chartInfo.ChartClassifyId)
  2519. if chartViewClassify != nil {
  2520. chartClassifyParent, _ := data_manage.GetChartClassifyViewById(chartClassify.ParentId)
  2521. chartInfo.ChartClassify = append(chartInfo.ChartClassify, chartClassifyParent)
  2522. }
  2523. chartInfo.ChartClassify = append(chartInfo.ChartClassify, chartViewClassify)
  2524. // 没有就返回空数组
  2525. if len(edbList) <= 0 {
  2526. edbList = make([]*data_manage.ChartEdbInfoMapping, 0)
  2527. }
  2528. resp.EdbInfoList = edbList
  2529. //判断是否需要展示英文标识
  2530. chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, edbList, chartInfo.Source, chartInfo.ChartType)
  2531. // 图表的指标来源
  2532. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  2533. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  2534. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  2535. resp.ChartInfo = chartInfo
  2536. resp.XEdbIdValue = xEdbIdValue
  2537. resp.YDataList = yDataList
  2538. resp.Status = true
  2539. resp.BarChartInfo = barConfig
  2540. resp.DataResp = dataResp
  2541. // 将数据加入缓存
  2542. if utils.Re == nil {
  2543. data, _ := json.Marshal(resp)
  2544. utils.Rc.Put(key, data, 2*time.Hour)
  2545. }
  2546. isOk = true
  2547. // 遍历到校验map
  2548. for _, v := range edbList {
  2549. edbClassifyPermissionMap[v.EdbInfoId] = data_manage_permission.EdbClassifyPermission{
  2550. ClassifyId: v.ClassifyId,
  2551. IsJoinPermission: v.IsJoinPermission,
  2552. EdbInfoId: v.EdbInfoId,
  2553. }
  2554. }
  2555. return
  2556. }
  2557. // @Param Img query string true "图片"
  2558. // @Success 200 {object} models.ResourceResp
  2559. // @router /chart_info/base64Upload [post]
  2560. func (this *ChartInfoController) ChartInfoBase64Upload() {
  2561. br := new(models.BaseResponse).Init()
  2562. defer func() {
  2563. this.Data["json"] = br
  2564. this.ServeJSON()
  2565. }()
  2566. imgData := this.GetString("Img")
  2567. if imgData == "" {
  2568. br.Msg = "图片参数错误"
  2569. br.ErrMsg = "图片参数错误,Img Is Empty"
  2570. return
  2571. }
  2572. resp := new(models.ResourceResp)
  2573. uploadDir := "static/images/"
  2574. if !utils.FileIsExist(uploadDir) {
  2575. err := os.MkdirAll(uploadDir, utils.DIR_MOD)
  2576. if err != nil {
  2577. br.Msg = "图表保存失败"
  2578. br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
  2579. return
  2580. }
  2581. }
  2582. //var saveToOssPath string
  2583. randStr := utils.GetRandStringNoSpecialChar(28)
  2584. var fileName, outFileName string
  2585. fileName = randStr + ".txt"
  2586. fileName = uploadDir + fileName
  2587. err := utils.SaveToFile(imgData, fileName)
  2588. if err != nil {
  2589. br.Msg = "图片保存失败"
  2590. br.ErrMsg = "图片保存失败,Err:" + err.Error()
  2591. return
  2592. }
  2593. outFileName = randStr + ".png"
  2594. doneChannel := make(chan bool, 1)
  2595. errorChannel := make(chan error, 1)
  2596. cmd := exec.Command("highcharts-export-server", "--infile", fileName, "--constr", "Chart", "--scale", "2", "--workers", "10", "--workLimit", "3", "--outfile", outFileName)
  2597. go func() {
  2598. output, err := cmd.CombinedOutput()
  2599. if err != nil {
  2600. utils.FileLog.Info("execute command failed, output: , error: \n" + string(output) + err.Error())
  2601. errorChannel <- err
  2602. return
  2603. }
  2604. doneChannel <- true
  2605. }()
  2606. select {
  2607. case <-time.After(30 * time.Second):
  2608. utils.FileLog.Info("执行超过30秒 杀死超时进程")
  2609. e := cmd.Process.Kill()
  2610. if e != nil {
  2611. fmt.Println("cmd kill err: ", e.Error())
  2612. utils.FileLog.Info(fmt.Sprintf("cmd kill err: %s", e.Error()))
  2613. br.Msg = "图片生成失败"
  2614. br.ErrMsg = "图片生成失败, 执行超时" + e.Error()
  2615. return
  2616. }
  2617. fmt.Println("timeout kill process")
  2618. case <-doneChannel:
  2619. fmt.Println("done")
  2620. case err := <-errorChannel:
  2621. br.Msg = "文件上传失败"
  2622. br.ErrMsg = fmt.Sprintf("execute command failure err: %s", err.Error())
  2623. fmt.Println("execute command failure err:" + err.Error())
  2624. return
  2625. }
  2626. defer func() {
  2627. os.Remove(fileName)
  2628. os.Remove(outFileName)
  2629. }()
  2630. //saveToOssPath = uploadDir + time.Now().Format("200601/20060102/")
  2631. //saveToOssPath += outFileName
  2632. //上传到阿里云 和 minio
  2633. resourceUrl := ``
  2634. //if utils.ObjectStorageClient == "minio" {
  2635. // err = services.UploadFileToMinIo("", outFileName, saveToOssPath)
  2636. // if err != nil {
  2637. // br.Msg = "文件上传失败"
  2638. // br.ErrMsg = "文件上传失败,Err:" + err.Error()
  2639. // return
  2640. // }
  2641. // resourceUrl = utils.MinIoImghost + saveToOssPath
  2642. //} else {
  2643. // err = services.UploadFileToAliyun("", outFileName, saveToOssPath)
  2644. // if err != nil {
  2645. // br.Msg = "文件上传失败"
  2646. // br.ErrMsg = "文件上传失败,Err:" + err.Error()
  2647. // return
  2648. // }
  2649. // resourceUrl = utils.Imghost + saveToOssPath
  2650. //}
  2651. ossClient := services.NewOssClient()
  2652. if ossClient == nil {
  2653. br.Msg = "上传失败"
  2654. br.ErrMsg = "初始化OSS服务失败"
  2655. return
  2656. }
  2657. resourceUrl, err = ossClient.UploadFile(outFileName, outFileName, "")
  2658. if err != nil {
  2659. br.Msg = "文件上传失败"
  2660. br.ErrMsg = "文件上传失败,Err:" + err.Error()
  2661. return
  2662. }
  2663. resp.ResourceUrl = resourceUrl
  2664. resp.Source = "convert"
  2665. //resp.CacheKey = imgDataKey
  2666. br.Msg = "上传成功"
  2667. br.Ret = 200
  2668. br.Success = true
  2669. br.Data = resp
  2670. return
  2671. }
  2672. // BatchChartInfoRefresh
  2673. // @Title 批量刷新图表接口
  2674. // @Description 批量刷新图表接口
  2675. // @Param request body data_manage.BatchChartRefreshReq true "type json string"
  2676. // @Success Ret=200 刷新成功
  2677. // @router /chart_info/batch_refresh [post]
  2678. func (this *EdbInfoController) BatchChartInfoRefresh() {
  2679. br := new(models.BaseResponse).Init()
  2680. defer func() {
  2681. this.Data["json"] = br
  2682. this.ServeJSON()
  2683. }()
  2684. sysUser := this.SysUser
  2685. if sysUser == nil {
  2686. br.Msg = "请登录"
  2687. br.ErrMsg = "请登录,SysUser Is Empty"
  2688. br.Ret = 408
  2689. return
  2690. }
  2691. var req data_manage.BatchChartRefreshReq
  2692. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2693. if err != nil {
  2694. br.Msg = "参数解析异常!"
  2695. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2696. return
  2697. }
  2698. if req.Source == "" {
  2699. br.Msg = "刷新来源有误"
  2700. return
  2701. }
  2702. if req.PrimaryId <= 0 {
  2703. br.Msg = "刷新对象有误"
  2704. return
  2705. }
  2706. //获取所有的图表列表
  2707. _, chartInfoList, err := data_manage.GetChartInfoListByUniqueCodeSlice(req.ChartInfoCode)
  2708. if len(chartInfoList) <= 0 {
  2709. br.Ret = 200
  2710. br.Success = true
  2711. br.Msg = "刷新成功"
  2712. return
  2713. }
  2714. redisKey := data.GetBatchChartRefreshKey(req.Source, req.PrimaryId, req.SubId)
  2715. // 图表中的指标刷新
  2716. err, isAsync := data.BatchChartInfoRefreshV2(chartInfoList, redisKey)
  2717. if err != nil {
  2718. br.Msg = "刷新失败"
  2719. br.ErrMsg = "刷新图表关联指标信息失败,Err:" + err.Error()
  2720. return
  2721. }
  2722. br.Msg = "刷新成功"
  2723. if isAsync {
  2724. br.Msg = "研报中图表关联指标较多,请10分钟后刷新页面查看最新数据"
  2725. }
  2726. br.Ret = 200
  2727. br.Success = true
  2728. }
  2729. // CopyChartInfo
  2730. // @Title 复制并新增图表接口
  2731. // @Description 新增图表接口
  2732. // @Param request body data_manage.CopyAddChartInfoReq true "type json string"
  2733. // @Success 200 {object} data_manage.AddChartInfoResp
  2734. // @router /chart_info/copy [post]
  2735. func (this *ChartInfoController) CopyChartInfo() {
  2736. br := new(models.BaseResponse).Init()
  2737. defer func() {
  2738. this.Data["json"] = br
  2739. this.ServeJSON()
  2740. }()
  2741. sysUser := this.SysUser
  2742. if sysUser == nil {
  2743. br.Msg = "请登录"
  2744. br.ErrMsg = "请登录,SysUser Is Empty"
  2745. br.Ret = 408
  2746. return
  2747. }
  2748. deleteCache := true
  2749. cacheKey := "CACHE_CHART_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  2750. defer func() {
  2751. if deleteCache {
  2752. utils.Rc.Delete(cacheKey)
  2753. }
  2754. }()
  2755. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  2756. deleteCache = false
  2757. br.Msg = "系统处理中,请稍后重试!"
  2758. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  2759. return
  2760. }
  2761. var req data_manage.CopyAddChartInfoReq
  2762. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2763. if err != nil {
  2764. br.Msg = "参数解析异常!"
  2765. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2766. return
  2767. }
  2768. // 获取原图表信息
  2769. oldChartInfo, err := data_manage.GetChartInfoById(req.ChartInfoId)
  2770. if err != nil {
  2771. br.Msg = "获取原图表信息失败"
  2772. br.ErrMsg = "获取原图表信息失败,Err:" + err.Error()
  2773. return
  2774. }
  2775. //校验图表名称是否重复
  2776. req.ChartName = strings.Trim(req.ChartName, " ")
  2777. if req.ChartName == "" {
  2778. br.Msg = "请填写图表名称!"
  2779. return
  2780. }
  2781. if req.ChartClassifyId <= 0 {
  2782. br.Msg = "分类参数错误!"
  2783. return
  2784. }
  2785. chartClassify, err := data_manage.GetChartClassifyById(req.ChartClassifyId)
  2786. if err != nil {
  2787. if utils.IsErrNoRow(err) {
  2788. br.Msg = "分类不存在"
  2789. br.ErrMsg = "分类不存在"
  2790. return
  2791. }
  2792. br.Msg = "获取分类信息失败"
  2793. br.ErrMsg = "获取分类信息失败,Err:" + err.Error()
  2794. return
  2795. }
  2796. if chartClassify == nil {
  2797. br.Msg = "分类不存在"
  2798. br.ErrMsg = "分类不存在"
  2799. return
  2800. }
  2801. //count, err := data_manage.ChartInfoExist("", edbInfoIdStr)
  2802. //if err != nil && !utils.IsErrNoRow(err) {
  2803. // br.Msg = "保存失败"
  2804. // br.ErrMsg = "判断图表名称是否存在失败,Err:" + err.Error()
  2805. // return
  2806. //}
  2807. //if count > 0 {
  2808. // br.Msg = "所选指标已存在相同指标"
  2809. // return
  2810. //}
  2811. //判断图表是否存在
  2812. var condition string
  2813. var pars []interface{}
  2814. condition += " AND chart_classify_id=? "
  2815. pars = append(pars, req.ChartClassifyId)
  2816. condition += " AND chart_name=? AND source = ? "
  2817. pars = append(pars, req.ChartName, utils.CHART_SOURCE_DEFAULT)
  2818. count, err := data_manage.GetChartInfoCountByCondition(condition, pars)
  2819. if err != nil {
  2820. br.Msg = "判断图表名称是否存在失败"
  2821. br.ErrMsg = "判断图表名称是否存在失败,Err:" + err.Error()
  2822. return
  2823. }
  2824. if count > 0 {
  2825. br.Msg = "图表已存在,请重新填写"
  2826. br.IsSendEmail = false
  2827. return
  2828. }
  2829. //获取原图表关联的指标信息列表
  2830. edbMappingList, err := data_manage.GetChartEdbMappingList(req.ChartInfoId)
  2831. if err != nil {
  2832. br.Msg = "获取图表关联的指标信息失败!"
  2833. return
  2834. }
  2835. //添加图表
  2836. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  2837. chartInfo := &data_manage.ChartInfo{
  2838. ChartInfoId: 0,
  2839. ChartName: req.ChartName,
  2840. ChartClassifyId: req.ChartClassifyId,
  2841. SysUserId: sysUser.AdminId,
  2842. SysUserRealName: sysUser.RealName,
  2843. UniqueCode: utils.MD5(utils.CHART_PREFIX + "_" + timestamp),
  2844. CreateTime: time.Now(),
  2845. ModifyTime: time.Now(),
  2846. DateType: oldChartInfo.DateType,
  2847. StartDate: oldChartInfo.StartDate,
  2848. EndDate: oldChartInfo.EndDate,
  2849. IsSetName: oldChartInfo.IsSetName,
  2850. EdbInfoIds: oldChartInfo.EdbInfoIds,
  2851. ChartType: oldChartInfo.ChartType,
  2852. Calendar: oldChartInfo.Calendar,
  2853. SeasonStartDate: oldChartInfo.SeasonStartDate,
  2854. SeasonEndDate: oldChartInfo.SeasonEndDate,
  2855. ChartImage: oldChartInfo.ChartImage,
  2856. BarConfig: oldChartInfo.BarConfig,
  2857. //Sort: sort,
  2858. LeftMin: oldChartInfo.LeftMin,
  2859. LeftMax: oldChartInfo.LeftMax,
  2860. RightMin: oldChartInfo.RightMin,
  2861. RightMax: oldChartInfo.RightMax,
  2862. Right2Min: oldChartInfo.Right2Min,
  2863. Right2Max: oldChartInfo.Right2Max,
  2864. Disabled: oldChartInfo.Disabled,
  2865. Source: oldChartInfo.Source,
  2866. ExtraConfig: oldChartInfo.ExtraConfig,
  2867. SeasonExtraConfig: oldChartInfo.SeasonExtraConfig,
  2868. StartYear: oldChartInfo.StartYear,
  2869. Unit: oldChartInfo.Unit,
  2870. UnitEn: oldChartInfo.UnitEn,
  2871. ChartThemeId: oldChartInfo.ChartThemeId,
  2872. SourcesFrom: oldChartInfo.SourcesFrom,
  2873. Instructions: oldChartInfo.Instructions,
  2874. MarkersLines: oldChartInfo.MarkersLines,
  2875. MarkersAreas: oldChartInfo.MarkersAreas,
  2876. }
  2877. newId, err := data_manage.AddChartInfo(chartInfo)
  2878. if err != nil {
  2879. br.Msg = "保存失败"
  2880. br.ErrMsg = "保存失败,Err:" + err.Error()
  2881. return
  2882. }
  2883. chartInfo.ChartInfoId = int(newId)
  2884. // 添加图表与指标的关联关系
  2885. {
  2886. mapList := make([]*data_manage.ChartEdbMapping, 0)
  2887. for _, v := range edbMappingList {
  2888. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  2889. mapItem := &data_manage.ChartEdbMapping{
  2890. //ChartEdbMappingId: 0,
  2891. ChartInfoId: chartInfo.ChartInfoId,
  2892. EdbInfoId: v.EdbInfoId,
  2893. CreateTime: time.Now(),
  2894. ModifyTime: time.Now(),
  2895. UniqueCode: utils.MD5(utils.CHART_PREFIX + "_" + timestamp),
  2896. MaxData: v.MaxData,
  2897. MinData: v.MinData,
  2898. IsOrder: v.IsOrder,
  2899. IsAxis: v.IsAxis,
  2900. EdbInfoType: v.EdbInfoType,
  2901. LeadValue: v.LeadValue,
  2902. LeadUnit: v.LeadUnit,
  2903. ChartStyle: v.ChartStyle,
  2904. ChartColor: v.ChartColor,
  2905. ChartWidth: v.ChartWidth,
  2906. Source: v.Source,
  2907. EdbAliasName: v.EdbAliasName,
  2908. IsConvert: v.IsConvert,
  2909. ConvertType: v.ConvertType,
  2910. ConvertValue: v.ConvertValue,
  2911. ConvertUnit: v.ConvertEnUnit,
  2912. ConvertEnUnit: v.ConvertEnUnit,
  2913. }
  2914. mapList = append(mapList, mapItem)
  2915. }
  2916. err = data_manage.AddChartEdbMapping(mapList)
  2917. if err != nil {
  2918. br.Msg = "保存失败"
  2919. br.ErrMsg = "保存失败,Err:" + err.Error()
  2920. return
  2921. }
  2922. }
  2923. if chartInfo.ChartType == utils.CHART_TYPE_SECTION_COMBINE {
  2924. // 查询系列信息并复制
  2925. chartSeriesList, e := data_manage.GetChartSeriesByChartInfoId(oldChartInfo.ChartInfoId)
  2926. if e != nil {
  2927. br.Msg = "获取图表关联的系列信息失败"
  2928. br.ErrMsg = "获取图表关联的系列信息失败,Err:" + e.Error()
  2929. return
  2930. }
  2931. chartSeriesEdbList, e := data_manage.GetChartSeriesEdbByChartInfoId(oldChartInfo.ChartInfoId)
  2932. if err != nil {
  2933. br.Msg = "获取图表关联的系列指标信息失败"
  2934. br.ErrMsg = "获取图表关联的系列指标信息失败,Err:" + err.Error()
  2935. return
  2936. }
  2937. err = data_manage.CopyChartSeriesAndEdbMapping(chartSeriesList, chartSeriesEdbList, chartInfo.ChartInfoId)
  2938. if err != nil {
  2939. br.Msg = "保存失败"
  2940. br.ErrMsg = "保存图表系列失败,Err:" + err.Error()
  2941. return
  2942. }
  2943. }
  2944. //添加es数据
  2945. go data.EsAddOrEditChartInfo(chartInfo.ChartInfoId)
  2946. //修改my eta es数据
  2947. go data.EsAddOrEditMyChartInfoByChartInfoId(chartInfo.ChartInfoId)
  2948. //新增操作日志
  2949. {
  2950. chartLog := new(data_manage.ChartInfoLog)
  2951. chartLog.ChartInfoId = chartInfo.ChartInfoId
  2952. chartLog.ChartName = req.ChartName
  2953. chartLog.ChartClassifyId = req.ChartClassifyId
  2954. chartLog.SysUserId = sysUser.AdminId
  2955. chartLog.SysUserRealName = sysUser.RealName
  2956. chartLog.UniqueCode = chartInfo.UniqueCode
  2957. chartLog.CreateTime = time.Now()
  2958. chartLog.Content = string(this.Ctx.Input.RequestBody)
  2959. chartLog.Status = "新增图表"
  2960. chartLog.Method = this.Ctx.Input.URI()
  2961. go data_manage.AddChartInfoLog(chartLog)
  2962. }
  2963. br.Ret = 200
  2964. br.Success = true
  2965. br.Msg = "保存成功"
  2966. br.Data = data_manage.AddChartInfoResp{
  2967. ChartInfoId: chartInfo.ChartInfoId,
  2968. UniqueCode: chartInfo.UniqueCode,
  2969. ChartType: chartInfo.ChartType,
  2970. }
  2971. br.IsAddLog = true
  2972. }
  2973. // PreviewBarChartInfo
  2974. // @Title 图表-获取预览的柱方图数据
  2975. // @Description 图表-获取指标详情接口
  2976. // @Param request body data_manage.BarChartInfoReq true "type json string"
  2977. // @Success 200 {object} data_manage.ChartEdbInfoDetailResp
  2978. // @router /chart_info/preview_bar [post]
  2979. func (this *ChartInfoController) PreviewBarChartInfo() {
  2980. br := new(models.BaseResponse).Init()
  2981. defer func() {
  2982. this.Data["json"] = br
  2983. this.ServeJSON()
  2984. }()
  2985. var req data_manage.BarChartInfoReq
  2986. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2987. if err != nil {
  2988. br.Msg = "参数解析异常!"
  2989. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2990. return
  2991. }
  2992. sysUser := this.SysUser
  2993. if sysUser == nil {
  2994. br.Msg = "请登录"
  2995. br.ErrMsg = "请登录,SysUser Is Empty"
  2996. br.Ret = 408
  2997. return
  2998. }
  2999. if len(req.EdbInfoIdList) <= 0 {
  3000. br.Msg = "请选择指标"
  3001. return
  3002. }
  3003. if len(req.DateList) <= 0 {
  3004. br.Msg = "请选择日期"
  3005. return
  3006. }
  3007. chartInfo := new(data_manage.ChartInfoView)
  3008. chartType := utils.CHART_TYPE_BAR
  3009. //edbInfoIdList := make([]int, 0)
  3010. edbInfoIdsList := make([]string, 0)
  3011. convertMap := make(map[int]*data_manage.ChartEdbInfoMapping, 0)
  3012. for _, v := range req.EdbInfoIdList {
  3013. edbInfoIdsList = append(edbInfoIdsList, strconv.Itoa(v.EdbInfoId))
  3014. convertMap[v.EdbInfoId] = &data_manage.ChartEdbInfoMapping{
  3015. IsConvert: v.IsConvert,
  3016. ConvertType: v.ConvertType,
  3017. ConvertValue: v.ConvertValue,
  3018. ConvertUnit: v.ConvertUnit,
  3019. ConvertEnUnit: v.ConvertEnUnit,
  3020. }
  3021. }
  3022. mappingList, err := data_manage.GetChartEdbMappingListByEdbInfoId(strings.Join(edbInfoIdsList, ","))
  3023. if err != nil {
  3024. br.Msg = "获取失败"
  3025. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  3026. return
  3027. }
  3028. for i, item := range mappingList {
  3029. if _, ok := convertMap[item.EdbInfoId]; ok {
  3030. mappingList[i].ConvertValue = convertMap[item.EdbInfoId].ConvertValue
  3031. mappingList[i].ConvertUnit = convertMap[item.EdbInfoId].ConvertUnit
  3032. mappingList[i].ConvertEnUnit = convertMap[item.EdbInfoId].ConvertEnUnit
  3033. mappingList[i].ConvertType = convertMap[item.EdbInfoId].ConvertType
  3034. mappingList[i].IsConvert = convertMap[item.EdbInfoId].IsConvert
  3035. }
  3036. }
  3037. // 获取图表中的指标数据
  3038. edbList, xEdbIdValue, yDataList, dataResp, err, errMsg := data.GetChartEdbData(0, chartType, "", "", "", mappingList, string(this.Ctx.Input.RequestBody), "")
  3039. if err != nil {
  3040. br.Msg = "获取失败"
  3041. if errMsg != `` {
  3042. br.Msg = errMsg
  3043. }
  3044. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  3045. return
  3046. }
  3047. // 单位
  3048. if len(yDataList) > 0 {
  3049. chartInfo.Unit = yDataList[0].Unit
  3050. chartInfo.UnitEn = yDataList[0].UnitEn
  3051. }
  3052. warnEdbList := make([]string, 0)
  3053. for _, v := range edbList {
  3054. if v.IsNullData {
  3055. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  3056. }
  3057. for _, reqEdb := range req.EdbInfoIdList {
  3058. if v.EdbInfoId == reqEdb.EdbInfoId {
  3059. v.EdbAliasName = reqEdb.Name
  3060. }
  3061. }
  3062. }
  3063. if len(warnEdbList) > 0 {
  3064. chartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  3065. }
  3066. // 图表的指标来源
  3067. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  3068. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  3069. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  3070. //图表操作权限
  3071. chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, true)
  3072. //判断是否需要展示英文标识
  3073. chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, edbList, chartInfo.Source, chartInfo.ChartType)
  3074. chartInfo.Button = data_manage.ChartViewButton{
  3075. IsEdit: chartInfo.IsEdit,
  3076. IsEnChart: chartInfo.IsEnChart,
  3077. IsAdd: chartInfo.IsAdd,
  3078. IsCopy: true,
  3079. IsSetName: chartInfo.IsSetName,
  3080. }
  3081. // 标识线计算
  3082. if req.MarkersLines != "" {
  3083. markerLines := make([]data_manage.MarkersLine, 0)
  3084. err = json.Unmarshal([]byte(req.MarkersLines), &markerLines)
  3085. if err != nil {
  3086. br.Msg = "标识线配置异常"
  3087. br.ErrMsg = "标识线配置异常" + err.Error()
  3088. return
  3089. }
  3090. for i := range markerLines {
  3091. if markerLines[i].EdbType == 0 && markerLines[i].TimeIntervalType == 0 && markerLines[i].Axis != 3 {
  3092. // 图上第一个指标且时间区间跟随图表
  3093. if markerLines[i].MarkLineType == 2 {
  3094. // 图上第一个指标且时间区间跟随图表
  3095. if edbList[0].IsAxis == 1 {
  3096. value, err := data.MarkerLineCalculate(markerLines[i], edbList[0].DataList, chartInfo)
  3097. if err != nil {
  3098. br.Msg = "标识线配置异常"
  3099. br.ErrMsg = "标识线配置异常" + err.Error()
  3100. return
  3101. }
  3102. markerLines[i].Value = value
  3103. } else {
  3104. // 其他的都走指标计算
  3105. edbInfo, err := data_manage.GetEdbInfoById(markerLines[i].EdbInfoId)
  3106. if err != nil {
  3107. br.Msg = "指标计算标识线获取指标信息异常"
  3108. br.ErrMsg = "指标计算标识线获取指标信息异常" + err.Error()
  3109. return
  3110. }
  3111. dataList, err := data_manage.GetEdbDataList(edbInfo.Source, edbInfo.SubSource, edbInfo.EdbInfoId, "", "")
  3112. if err != nil {
  3113. br.Msg = "指标计算标识线获取指标数据异常"
  3114. br.ErrMsg = "指标计算标识线获取指标数据异常" + err.Error()
  3115. return
  3116. }
  3117. value, err := data.MarkerLineCalculate(markerLines[i], dataList, chartInfo)
  3118. if err != nil {
  3119. br.Msg = "标识线配置异常"
  3120. br.ErrMsg = "标识线配置异常" + err.Error()
  3121. return
  3122. }
  3123. markerLines[i].Value = value
  3124. }
  3125. }
  3126. }
  3127. }
  3128. markerLineStr, err := json.Marshal(markerLines)
  3129. if err != nil {
  3130. br.Msg = "标识线配置异常"
  3131. br.ErrMsg = "标识线配置异常" + err.Error()
  3132. return
  3133. }
  3134. chartInfo.MarkersLines = string(markerLineStr)
  3135. }
  3136. resp := new(data_manage.ChartInfoDetailResp)
  3137. resp.ChartInfo = chartInfo
  3138. resp.EdbInfoList = edbList
  3139. resp.XEdbIdValue = xEdbIdValue
  3140. resp.YDataList = yDataList
  3141. resp.DataResp = dataResp
  3142. br.Ret = 200
  3143. br.Success = true
  3144. br.Msg = "获取成功"
  3145. br.Data = resp
  3146. }
  3147. // PreviewSectionScatterChartInfo
  3148. // @Title 图表-获取预览的截面散点图数据
  3149. // @Description 图表-获取指标详情接口
  3150. // @Param request body data_manage.SectionScatter true "type json string"
  3151. // @Success 200 {object} data_manage.ChartEdbInfoDetailResp
  3152. // @router /chart_info/preview/time_section [post]
  3153. func (this *ChartInfoController) PreviewSectionScatterChartInfo() {
  3154. br := new(models.BaseResponse).Init()
  3155. defer func() {
  3156. this.Data["json"] = br
  3157. this.ServeJSON()
  3158. }()
  3159. var req data_manage.PreviewSectionScatterChartReq
  3160. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  3161. if err != nil {
  3162. br.Msg = "参数解析异常!"
  3163. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  3164. return
  3165. }
  3166. chartInfo := new(data_manage.ChartInfoView)
  3167. sysUser := this.SysUser
  3168. if sysUser == nil {
  3169. br.Msg = "请登录"
  3170. br.ErrMsg = "请登录,SysUser Is Empty"
  3171. br.Ret = 408
  3172. return
  3173. }
  3174. chartType := utils.CHART_TYPE_SECTION_SCATTER
  3175. edbInfoIdArr, err, errMsg := data.CheckChartExtraConfig(chartType, req.ExtraConfig)
  3176. if err != nil {
  3177. br.Msg = errMsg
  3178. br.ErrMsg = "添加失败:" + err.Error()
  3179. return
  3180. }
  3181. mappingList, err := data_manage.GetChartEdbMappingListByEdbInfoIdList(edbInfoIdArr)
  3182. // 获取图表中的指标数据
  3183. edbList, xEdbIdValue, yDataList, dataResp, err, errMsg := data.GetChartEdbData(0, chartType, "", "", "", mappingList, req.ExtraConfig, "")
  3184. if err != nil {
  3185. br.Msg = "获取失败"
  3186. if errMsg != `` {
  3187. br.Msg = errMsg
  3188. }
  3189. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  3190. return
  3191. }
  3192. warnEdbList := make([]string, 0)
  3193. for _, v := range edbList {
  3194. if v.IsNullData {
  3195. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  3196. }
  3197. }
  3198. if len(warnEdbList) > 0 {
  3199. chartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  3200. }
  3201. // 图表的指标来源
  3202. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  3203. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  3204. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  3205. //图表操作权限
  3206. chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, true)
  3207. //判断是否需要展示英文标识
  3208. chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, edbList, utils.CHART_SOURCE_DEFAULT, chartType)
  3209. chartInfo.Button = data_manage.ChartViewButton{
  3210. IsEdit: chartInfo.IsEdit,
  3211. IsEnChart: chartInfo.IsEnChart,
  3212. IsAdd: chartInfo.IsAdd,
  3213. IsCopy: true,
  3214. IsSetName: chartInfo.IsSetName,
  3215. }
  3216. resp := new(data_manage.ChartInfoDetailResp)
  3217. resp.ChartInfo = chartInfo
  3218. resp.EdbInfoList = edbList
  3219. resp.XEdbIdValue = xEdbIdValue
  3220. resp.YDataList = yDataList
  3221. resp.DataResp = dataResp
  3222. br.Ret = 200
  3223. br.Success = true
  3224. br.Msg = "获取成功"
  3225. br.Data = resp
  3226. }
  3227. // GetBatchChartRefreshResult
  3228. // @Title 获取批量刷新图表结果的接口
  3229. // @Description 获取批量刷新图表结果的接口
  3230. // @Param request body data_manage.BatchChartRefreshReq true "type json string"
  3231. // @Success Ret=200 刷新成功
  3232. // @router /chart_info/batch_refresh/result [post]
  3233. func (this *EdbInfoController) GetBatchChartRefreshResult() {
  3234. br := new(models.BaseResponse).Init()
  3235. defer func() {
  3236. this.Data["json"] = br
  3237. this.ServeJSON()
  3238. }()
  3239. sysUser := this.SysUser
  3240. if sysUser == nil {
  3241. br.Msg = "请登录"
  3242. br.ErrMsg = "请登录,SysUser Is Empty"
  3243. br.Ret = 408
  3244. return
  3245. }
  3246. var req data_manage.BatchChartRefreshReq
  3247. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  3248. if err != nil {
  3249. br.Msg = "参数解析异常!"
  3250. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  3251. return
  3252. }
  3253. if req.Source == "" {
  3254. br.Msg = "刷新来源有误"
  3255. return
  3256. }
  3257. if req.PrimaryId <= 0 {
  3258. br.Msg = "刷新对象有误"
  3259. return
  3260. }
  3261. // 刷新结果,默认是刷新完成了
  3262. refreshResult := data.CheckBatchChartRefreshResult(req.Source, req.PrimaryId, req.SubId)
  3263. resp := response.ChartRefreshResp{
  3264. RefreshResult: refreshResult,
  3265. }
  3266. br.Data = resp
  3267. br.Ret = 200
  3268. br.Success = true
  3269. }
  3270. // PreviewRadarChartInfo
  3271. // @Title 图表-获取预览的雷达图
  3272. // @Description 图表-获取预览的雷达图
  3273. // @Param ExtraConfig body data_manage.PreviewRadarChartReq true "type json string"
  3274. // @Success 200 {object} data_manage.ChartEdbInfoDetailResp
  3275. // @router /chart_info/preview/radar [post]
  3276. func (this *ChartInfoController) PreviewRadarChartInfo() {
  3277. br := new(models.BaseResponse).Init()
  3278. defer func() {
  3279. this.Data["json"] = br
  3280. this.ServeJSON()
  3281. }()
  3282. var req data_manage.PreviewRadarChartReq
  3283. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  3284. if err != nil {
  3285. br.Msg = "参数解析异常!"
  3286. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  3287. return
  3288. }
  3289. chartInfo := new(data_manage.ChartInfoView)
  3290. sysUser := this.SysUser
  3291. if sysUser == nil {
  3292. br.Msg = "请登录"
  3293. br.ErrMsg = "请登录,SysUser Is Empty"
  3294. br.Ret = 408
  3295. return
  3296. }
  3297. chartType := utils.CHART_TYPE_RADAR
  3298. if len(req.ChartEdbInfoList) <= 0 {
  3299. br.Msg = "请选择指标"
  3300. return
  3301. }
  3302. edbInfoIdArr := make([]int, 0)
  3303. edbInfoNameMap := make(map[int]string)
  3304. for _, v := range req.ChartEdbInfoList {
  3305. edbInfoIdArr = append(edbInfoIdArr, v.EdbInfoId)
  3306. edbInfoNameMap[v.EdbInfoId] = v.EdbAliasName
  3307. }
  3308. mappingList, err := data_manage.GetChartEdbMappingListByEdbInfoIdList(edbInfoIdArr)
  3309. for _, v := range mappingList {
  3310. if name, ok := edbInfoNameMap[v.EdbInfoId]; ok {
  3311. v.EdbAliasName = name
  3312. }
  3313. }
  3314. // 获取图表中的指标数据
  3315. edbList, xEdbIdValue, yDataList, dataResp, err, errMsg := data.GetChartEdbData(0, chartType, "", "", "", mappingList, req.ExtraConfig, "")
  3316. if err != nil {
  3317. br.Msg = "获取失败"
  3318. if errMsg != `` {
  3319. br.Msg = errMsg
  3320. }
  3321. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  3322. return
  3323. }
  3324. warnEdbList := make([]string, 0)
  3325. for _, v := range edbList {
  3326. if v.IsNullData {
  3327. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  3328. }
  3329. }
  3330. if len(warnEdbList) > 0 {
  3331. chartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  3332. }
  3333. //图表操作权限
  3334. chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, true)
  3335. //判断是否需要展示英文标识
  3336. chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, edbList, utils.CHART_SOURCE_DEFAULT, chartType)
  3337. chartInfo.Button = data_manage.ChartViewButton{
  3338. IsEdit: chartInfo.IsEdit,
  3339. IsEnChart: chartInfo.IsEnChart,
  3340. IsAdd: chartInfo.IsAdd,
  3341. IsCopy: true,
  3342. IsSetName: chartInfo.IsSetName,
  3343. }
  3344. // 图表的指标来源
  3345. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  3346. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  3347. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  3348. resp := new(data_manage.ChartInfoDetailResp)
  3349. resp.ChartInfo = chartInfo
  3350. resp.EdbInfoList = edbList
  3351. resp.XEdbIdValue = xEdbIdValue
  3352. resp.YDataList = yDataList
  3353. resp.DataResp = dataResp
  3354. br.Ret = 200
  3355. br.Success = true
  3356. br.Msg = "获取成功"
  3357. br.Data = resp
  3358. }
  3359. // ChartInfoDetail
  3360. // @Title 获取图表详情-数据转换
  3361. // @Description 获取图表详情接口-数据转换
  3362. // @Param ChartInfoId query int true "图表id"
  3363. // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间"
  3364. // @Param StartDate query string true "自定义开始日期"
  3365. // @Param EndDate query string true "自定义结束日期"
  3366. // @Param Calendar query string true "公历/农历"
  3367. // @Param SeasonStartDate query string true "季节性图开始日期"
  3368. // @Param SeasonEndDate query string true "季节性图结束日期"
  3369. // @Param EdbInfoId query string true "指标ID,多个用英文逗号隔开"
  3370. // @Param ChartType query int true "生成样式:1:曲线图,2:季节性图"
  3371. // @Success 200 {object} data_manage.ChartInfoDetailResp
  3372. // @router /chart_info/convert/detail [get]
  3373. func (this *ChartInfoController) ChartInfoConvertDetail() {
  3374. br := new(models.BaseResponse).Init()
  3375. defer func() {
  3376. this.Data["json"] = br
  3377. this.ServeJSON()
  3378. }()
  3379. sysUser := this.SysUser
  3380. if sysUser == nil {
  3381. br.Msg = "请登录"
  3382. br.ErrMsg = "请登录,SysUser Is Empty"
  3383. br.Ret = 408
  3384. return
  3385. }
  3386. chartInfoId, _ := this.GetInt("ChartInfoId")
  3387. dateType, _ := this.GetInt("DateType")
  3388. fmt.Println("dateType:", dateType)
  3389. if dateType <= 0 {
  3390. dateType = 3
  3391. }
  3392. startDate := this.GetString("StartDate")
  3393. endDate := this.GetString("EndDate")
  3394. startYear, _ := this.GetInt("StartYear")
  3395. edbInfoId := this.GetString("EdbInfoId")
  3396. chartType, _ := this.GetInt("ChartType")
  3397. isAxis, _ := this.GetInt("IsAxis")
  3398. calendar := this.GetString("Calendar")
  3399. if calendar == "" {
  3400. calendar = "公历"
  3401. }
  3402. isConvert, _ := this.GetInt("IsConvert")
  3403. convertType, _ := this.GetInt("ConvertType")
  3404. convertValue, _ := this.GetFloat("ConvertValue")
  3405. convertUnit := this.GetString("ConvertUnit")
  3406. convertEnUnit := this.GetString("ConvertEnUnit")
  3407. resp := new(data_manage.ChartInfoDetailResp)
  3408. var err error
  3409. chartInfo := new(data_manage.ChartInfoView)
  3410. chartInfo.HaveOperaAuth = true
  3411. // 通过id获取详情
  3412. if chartInfoId > 0 {
  3413. chartInfo, err = data_manage.GetChartInfoViewById(chartInfoId)
  3414. if err != nil {
  3415. if utils.IsErrNoRow(err) {
  3416. br.Msg = "该图表已删除,自动查看下一图表"
  3417. br.ErrMsg = "该图表已删除,自动查看下一图表,Err:" + err.Error()
  3418. br.Ret = 406
  3419. return
  3420. }
  3421. br.Msg = "获取失败"
  3422. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  3423. return
  3424. }
  3425. chartType = chartInfo.ChartType
  3426. // 获取主题样式
  3427. chartTheme, err := data.GetChartThemeConfig(chartInfo.ChartThemeId, chartInfo.Source, chartInfo.ChartType)
  3428. if err != nil {
  3429. br.Msg = "获取失败"
  3430. br.ErrMsg = "获取主题信息失败,Err:" + err.Error()
  3431. return
  3432. }
  3433. chartInfo.ChartThemeStyle = chartTheme.Config
  3434. chartInfo.ChartThemeId = chartTheme.ChartThemeId
  3435. // 图表数据权限
  3436. {
  3437. // 图表分类
  3438. chartClassify, err := data_manage.GetChartClassifyById(chartInfo.ChartClassifyId)
  3439. if err != nil {
  3440. br.Msg = "获取失败"
  3441. br.ErrMsg = "获取图表分类信息失败,Err:" + err.Error()
  3442. return
  3443. }
  3444. // 已授权分类id
  3445. permissionChartIdList, permissionClassifyIdList, err := data_manage_permission.GetUserChartAndClassifyPermissionList(this.SysUser.AdminId, chartInfo.ChartInfoId, chartInfo.ChartClassifyId)
  3446. if err != nil {
  3447. br.Msg = "获取失败"
  3448. br.ErrMsg = "获取已授权分类id数据失败,Err:" + err.Error()
  3449. return
  3450. }
  3451. chartInfo.HaveOperaAuth = data_manage_permission.CheckChartPermissionByPermissionIdList(chartInfo.IsJoinPermission, chartClassify.IsJoinPermission, chartInfo.ChartInfoId, chartInfo.ChartClassifyId, permissionChartIdList, permissionClassifyIdList)
  3452. }
  3453. //图表操作权限
  3454. chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, chartInfo.HaveOperaAuth)
  3455. chartInfo.Button = data_manage.ChartViewButton{
  3456. IsEdit: chartInfo.IsEdit,
  3457. IsEnChart: chartInfo.IsEnChart,
  3458. IsAdd: chartInfo.IsAdd,
  3459. IsCopy: true,
  3460. IsSetName: chartInfo.IsSetName,
  3461. }
  3462. }
  3463. // 有数据权限的话,获取图表的数据
  3464. if chartInfo.HaveOperaAuth {
  3465. mappingList := make([]*data_manage.ChartEdbInfoMapping, 0)
  3466. if chartInfoId > 0 {
  3467. mappingList, err = data_manage.GetChartEdbMappingList(chartInfoId)
  3468. if err != nil {
  3469. br.Msg = "获取失败"
  3470. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  3471. return
  3472. }
  3473. } else {
  3474. if edbInfoId != "" {
  3475. mappingList, err = data_manage.GetChartEdbMappingListByEdbInfoId(edbInfoId)
  3476. if err != nil {
  3477. br.Msg = "获取失败"
  3478. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  3479. return
  3480. }
  3481. if isConvert == 1 && len(mappingList) > 0 {
  3482. for i, _ := range mappingList {
  3483. mappingList[i].IsConvert = 1
  3484. mappingList[i].ConvertType = convertType
  3485. mappingList[i].ConvertValue = convertValue
  3486. mappingList[i].ConvertUnit = convertUnit
  3487. mappingList[i].ConvertEnUnit = convertEnUnit
  3488. }
  3489. }
  3490. }
  3491. }
  3492. // 图表额外数据参数
  3493. extraConfigStr := chartInfo.ExtraConfig
  3494. // 柱方图的一些配置
  3495. var barConfig data_manage.BarChartInfoReq
  3496. if chartInfo != nil && chartInfo.ChartType == 7 {
  3497. if chartInfo.BarConfig == `` {
  3498. br.Msg = "柱方图未配置"
  3499. br.ErrMsg = "柱方图未配置"
  3500. return
  3501. }
  3502. err := json.Unmarshal([]byte(chartInfo.BarConfig), &barConfig)
  3503. if err != nil {
  3504. br.Msg = "柱方图配置异常"
  3505. br.ErrMsg = "柱方图配置异常"
  3506. return
  3507. }
  3508. extraConfigStr = chartInfo.BarConfig
  3509. }
  3510. yearMax := 0
  3511. if dateType == utils.DateTypeNYears {
  3512. for _, v := range mappingList {
  3513. if v.LatestDate != "" {
  3514. lastDateT, tErr := time.Parse(utils.FormatDate, v.LatestDate)
  3515. if tErr != nil {
  3516. br.Msg = "获取失败"
  3517. br.ErrMsg = "获取图表日期信息失败,Err:" + tErr.Error()
  3518. return
  3519. }
  3520. if lastDateT.Year() > yearMax {
  3521. yearMax = lastDateT.Year()
  3522. }
  3523. }
  3524. }
  3525. }
  3526. // 开始/结束日期
  3527. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, yearMax)
  3528. // 获取图表中的指标数据
  3529. edbList, xEdbIdValue, yDataList, dataResp, err, errMsg := data.GetChartConvertEdbData(chartInfoId, chartType, calendar, startDate, endDate, mappingList, extraConfigStr, chartInfo.SeasonExtraConfig, isAxis)
  3530. if err != nil {
  3531. br.Msg = "获取失败"
  3532. if errMsg != `` {
  3533. br.Msg = errMsg
  3534. }
  3535. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  3536. return
  3537. }
  3538. // 单位
  3539. if chartType == utils.CHART_TYPE_BAR && len(yDataList) > 0 {
  3540. chartInfo.Unit = yDataList[0].Unit
  3541. chartInfo.UnitEn = yDataList[0].UnitEn
  3542. }
  3543. warnEdbList := make([]string, 0)
  3544. for _, v := range edbList {
  3545. if v.IsNullData {
  3546. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  3547. }
  3548. }
  3549. if len(warnEdbList) > 0 {
  3550. chartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  3551. }
  3552. if chartInfoId > 0 && chartInfo != nil {
  3553. //判断是否加入我的图库
  3554. {
  3555. var myChartCondition string
  3556. var myChartPars []interface{}
  3557. myChartCondition += ` AND a.admin_id=? `
  3558. myChartPars = append(myChartPars, sysUser.AdminId)
  3559. myChartCondition += ` AND a.chart_info_id=? `
  3560. myChartPars = append(myChartPars, chartInfo.ChartInfoId)
  3561. myChartList, err := data_manage.GetMyChartByCondition(myChartCondition, myChartPars)
  3562. if err != nil && !utils.IsErrNoRow(err) {
  3563. br.Msg = "获取失败"
  3564. br.ErrMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
  3565. return
  3566. }
  3567. if myChartList != nil && len(myChartList) > 0 {
  3568. chartInfo.IsAdd = true
  3569. chartInfo.MyChartId = myChartList[0].MyChartId
  3570. chartInfo.MyChartClassifyId = myChartList[0].MyChartClassifyId
  3571. }
  3572. }
  3573. if chartInfo.ChartType == 2 {
  3574. if chartInfo.SeasonStartDate != "" {
  3575. chartInfo.StartDate = chartInfo.SeasonStartDate
  3576. chartInfo.EndDate = chartInfo.SeasonEndDate
  3577. if chartInfo.DateType == 3 {
  3578. chartInfo.DateType = 5
  3579. }
  3580. }
  3581. }
  3582. }
  3583. // 图表的指标来源
  3584. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  3585. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  3586. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  3587. //判断是否需要展示英文标识
  3588. chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, edbList, chartInfo.Source, chartInfo.ChartType)
  3589. resp.EdbInfoList = edbList
  3590. resp.XEdbIdValue = xEdbIdValue
  3591. resp.YDataList = yDataList
  3592. resp.DataResp = dataResp
  3593. resp.BarChartInfo = barConfig
  3594. }
  3595. resp.ChartInfo = chartInfo
  3596. br.Ret = 200
  3597. br.Success = true
  3598. br.Msg = "获取成功"
  3599. br.Data = resp
  3600. }
  3601. // UploadToForum
  3602. // @Title 上传至社区
  3603. // @Description 上传至社区
  3604. // @Param request body data_manage.SetChartInfoImageReq true "type json string"
  3605. // @Success Ret=200 保存成功
  3606. // @router /chart_info/forum/upload [post]
  3607. func (this *ChartInfoController) UploadToForum() {
  3608. br := new(models.BaseResponse).Init()
  3609. defer func() {
  3610. this.Data["json"] = br
  3611. this.ServeJSON()
  3612. }()
  3613. sysUser := this.SysUser
  3614. if sysUser == nil {
  3615. br.Msg = "请登录"
  3616. br.ErrMsg = "请登录,SysUser Is Empty"
  3617. br.Ret = 408
  3618. return
  3619. }
  3620. var req eta_forum.UploadChartToForumReq
  3621. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  3622. if err != nil {
  3623. br.Msg = "参数解析异常!"
  3624. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  3625. return
  3626. }
  3627. if req.ChartInfoId <= 0 {
  3628. br.Msg = "请选择图表"
  3629. return
  3630. }
  3631. err, errMsg := eta_forum.UploadChart(req.ChartInfoId, req.Description, sysUser)
  3632. if err != nil {
  3633. br.Msg = errMsg
  3634. br.ErrMsg = err.Error()
  3635. return
  3636. }
  3637. br.Ret = 200
  3638. br.Success = true
  3639. br.Msg = "保存成功"
  3640. }
  3641. // UpdateToForum
  3642. // @Title 更新社区图表
  3643. // @Description 更新社区图表
  3644. // @Param request body data_manage.SetChartInfoImageReq true "type json string"
  3645. // @Success Ret=200 保存成功
  3646. // @router /chart_info/forum/update [post]
  3647. func (this *ChartInfoController) UpdateToForum() {
  3648. br := new(models.BaseResponse).Init()
  3649. defer func() {
  3650. this.Data["json"] = br
  3651. this.ServeJSON()
  3652. }()
  3653. sysUser := this.SysUser
  3654. if sysUser == nil {
  3655. br.Msg = "请登录"
  3656. br.ErrMsg = "请登录,SysUser Is Empty"
  3657. br.Ret = 408
  3658. return
  3659. }
  3660. var req eta_forum.UpdateChartToForumReq
  3661. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  3662. if err != nil {
  3663. br.Msg = "参数解析异常!"
  3664. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  3665. return
  3666. }
  3667. if req.ChartInfoId <= 0 {
  3668. br.Msg = "请选择图表"
  3669. return
  3670. }
  3671. err, errMsg := eta_forum.UpdateChart(req.ChartInfoId)
  3672. if err != nil {
  3673. br.Msg = errMsg
  3674. br.ErrMsg = err.Error()
  3675. return
  3676. }
  3677. br.Ret = 200
  3678. br.Success = true
  3679. br.Msg = "保存成功"
  3680. }
  3681. // ForumDelete
  3682. // @Title 从社区撤回
  3683. // @Description 从社区撤回
  3684. // @Param request body data_manage.SetChartInfoImageReq true "type json string"
  3685. // @Success Ret=200 保存成功
  3686. // @router /chart_info/forum/delete [post]
  3687. func (this *ChartInfoController) ForumDelete() {
  3688. br := new(models.BaseResponse).Init()
  3689. defer func() {
  3690. this.Data["json"] = br
  3691. this.ServeJSON()
  3692. }()
  3693. sysUser := this.SysUser
  3694. if sysUser == nil {
  3695. br.Msg = "请登录"
  3696. br.ErrMsg = "请登录,SysUser Is Empty"
  3697. br.Ret = 408
  3698. return
  3699. }
  3700. var req eta_forum.DeleteChartReq
  3701. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  3702. if err != nil {
  3703. br.Msg = "参数解析异常!"
  3704. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  3705. return
  3706. }
  3707. if req.ChartInfoId <= 0 {
  3708. br.Msg = "请选择图表"
  3709. return
  3710. }
  3711. err, errMsg := eta_forum.DeleteChart(req.ChartInfoId)
  3712. if err != nil {
  3713. br.Msg = errMsg
  3714. br.ErrMsg = err.Error()
  3715. return
  3716. }
  3717. br.Ret = 200
  3718. br.Success = true
  3719. br.Msg = "操作成功"
  3720. }
  3721. // PreviewSeasonChartInfo
  3722. // @Title 图表-获取预览的季节性图
  3723. // @Description 图表-获取预览的季节性图
  3724. // @Param ExtraConfig body data_manage.PreviewRadarChartReq true "type json string"
  3725. // @Success 200 {object} data_manage.ChartEdbInfoDetailResp
  3726. // @router /chart_info/preview/season [post]
  3727. func (this *ChartInfoController) PreviewSeasonChartInfo() {
  3728. br := new(models.BaseResponse).Init()
  3729. defer func() {
  3730. this.Data["json"] = br
  3731. this.ServeJSON()
  3732. }()
  3733. var req data_manage.PreviewSeasonChartReq
  3734. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  3735. if err != nil {
  3736. br.Msg = "参数解析异常!"
  3737. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  3738. return
  3739. }
  3740. chartInfo := new(data_manage.ChartInfoView)
  3741. sysUser := this.SysUser
  3742. if sysUser == nil {
  3743. br.Msg = "请登录"
  3744. br.ErrMsg = "请登录,SysUser Is Empty"
  3745. br.Ret = 408
  3746. return
  3747. }
  3748. chartType := utils.CHART_TYPE_SEASON
  3749. if len(req.ChartEdbInfoList) <= 0 {
  3750. br.Msg = "请选择指标"
  3751. return
  3752. }
  3753. edbInfoIdArr := make([]int, 0)
  3754. edbInfoNameMap := make(map[int]string)
  3755. for _, v := range req.ChartEdbInfoList {
  3756. edbInfoIdArr = append(edbInfoIdArr, v.EdbInfoId)
  3757. edbInfoNameMap[v.EdbInfoId] = v.EdbAliasName
  3758. }
  3759. mappingList, err := data_manage.GetChartEdbMappingListByEdbInfoIdList(edbInfoIdArr)
  3760. for _, v := range mappingList {
  3761. if name, ok := edbInfoNameMap[v.EdbInfoId]; ok {
  3762. v.EdbAliasName = name
  3763. }
  3764. }
  3765. var seasonExtraConfig string
  3766. seasonExtra, tErr := json.Marshal(req.SeasonExtraConfig)
  3767. if tErr != nil {
  3768. br.Msg = "季节性图表配置信息异常"
  3769. br.ErrMsg = "季节性图表配置信息异常,Err:" + tErr.Error()
  3770. return
  3771. }
  3772. seasonExtraConfig = string(seasonExtra)
  3773. // 获取图表中的指标数据
  3774. edbList, xEdbIdValue, yDataList, dataResp, err, errMsg := data.GetChartEdbData(0, chartType, "", "", "", mappingList, "", seasonExtraConfig)
  3775. if err != nil {
  3776. br.Msg = "获取失败"
  3777. if errMsg != `` {
  3778. br.Msg = errMsg
  3779. }
  3780. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  3781. return
  3782. }
  3783. warnEdbList := make([]string, 0)
  3784. for _, v := range edbList {
  3785. if v.IsNullData {
  3786. warnEdbList = append(warnEdbList, v.EdbName+"("+v.EdbCode+")")
  3787. }
  3788. }
  3789. if len(warnEdbList) > 0 {
  3790. chartInfo.WarnMsg = `图表引用指标异常,异常指标:` + strings.Join(warnEdbList, ",")
  3791. }
  3792. //图表操作权限
  3793. chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId, true)
  3794. //判断是否需要展示英文标识
  3795. chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, edbList, utils.CHART_SOURCE_DEFAULT, chartType)
  3796. chartInfo.Button = data_manage.ChartViewButton{
  3797. IsEdit: chartInfo.IsEdit,
  3798. IsEnChart: chartInfo.IsEnChart,
  3799. IsAdd: chartInfo.IsAdd,
  3800. IsCopy: true,
  3801. IsSetName: chartInfo.IsSetName,
  3802. }
  3803. // 图表的指标来源
  3804. sourceNameList, sourceNameEnList := data.GetEdbSourceByEdbInfoIdList(edbList)
  3805. chartInfo.ChartSource = strings.Join(sourceNameList, ",")
  3806. chartInfo.ChartSourceEn = strings.Join(sourceNameEnList, ",")
  3807. resp := new(data_manage.ChartInfoDetailResp)
  3808. resp.ChartInfo = chartInfo
  3809. resp.EdbInfoList = edbList
  3810. resp.XEdbIdValue = xEdbIdValue
  3811. resp.YDataList = yDataList
  3812. resp.DataResp = dataResp
  3813. br.Ret = 200
  3814. br.Success = true
  3815. br.Msg = "获取成功"
  3816. br.Data = resp
  3817. }
  3818. // ChartInfoImgSetBySvg
  3819. // @Title 图表图片上传
  3820. // @Param Img query string true "图片"
  3821. // @Param ChartInfoId query int true "图表ID"
  3822. // @Success 200 {object} models.ResourceResp
  3823. // @router /chart_info/image/set_by_svg [post]
  3824. func (this *ChartInfoController) ChartInfoImgSetBySvg() {
  3825. br := new(models.BaseResponse).Init()
  3826. defer func() {
  3827. this.Data["json"] = br
  3828. this.ServeJSON()
  3829. }()
  3830. imgData := this.GetString("Img")
  3831. if imgData == "" {
  3832. br.Msg = "图片参数错误"
  3833. br.ErrMsg = "图片参数错误,Img Is Empty"
  3834. return
  3835. }
  3836. chartInfoId, _ := this.GetInt("ChartInfoId", 0)
  3837. if chartInfoId <= 0 {
  3838. br.Msg = "图片参数错误"
  3839. br.ErrMsg = "图片参数错误,ChartInfoId Is Empty"
  3840. return
  3841. }
  3842. resp := new(models.ResourceResp)
  3843. // 通过svg图片生成图片资源地址
  3844. resourceUrl, err, errMsg := services.GetResourceUrlBySvgImg(imgData)
  3845. if err != nil {
  3846. br.Msg = errMsg
  3847. br.ErrMsg = err.Error()
  3848. return
  3849. }
  3850. // 修改图表的缩略图信息
  3851. if chartInfoId > 0 && resourceUrl != "" {
  3852. err = data_manage.EditChartInfoImageV2(chartInfoId, resourceUrl)
  3853. if err != nil {
  3854. br.Msg = "保存失败"
  3855. br.ErrMsg = "保存失败,Err:" + err.Error()
  3856. return
  3857. }
  3858. //修改es数据
  3859. go data.EsAddOrEditChartInfo(chartInfoId)
  3860. //修改my eta es数据
  3861. go data.EsAddOrEditMyChartInfoByChartInfoId(chartInfoId)
  3862. }
  3863. resp.ResourceUrl = resourceUrl
  3864. resp.Source = "convert"
  3865. //resp.CacheKey = imgDataKey
  3866. br.Msg = "上传成功"
  3867. br.Ret = 200
  3868. br.Success = true
  3869. br.Data = resp
  3870. return
  3871. }
  3872. // 修复ES中的指标和图表数据
  3873. //func init() {
  3874. // // 更新ES中的指标数据
  3875. // data.AddOrEditAllEdbInfoToEs()
  3876. // // 更新es中的图表数据
  3877. // data.AddAllChartInfo()
  3878. //
  3879. // fmt.Println("全部es数据修复完成")
  3880. //}