chart_info.go 133 KB

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