chart_info.go 151 KB

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