chart_info.go 148 KB

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