chart_info.go 148 KB

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