chart_info.go 147 KB

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