chart_info.go 149 KB

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