chart_info.go 150 KB

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