chart_info.go 145 KB

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