chart_info.go 148 KB

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