chart_info.go 131 KB

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