chart_info.go 153 KB

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