edb_info.go 144 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976
  1. package data_manage
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/controllers"
  5. "eta/eta_api/models"
  6. "eta/eta_api/models/company"
  7. "eta/eta_api/models/data_manage"
  8. "eta/eta_api/models/data_manage/request"
  9. "eta/eta_api/models/data_manage/response"
  10. "eta/eta_api/models/system"
  11. "eta/eta_api/services/alarm_msg"
  12. "eta/eta_api/services/data"
  13. "eta/eta_api/services/data_stat"
  14. "eta/eta_api/services/elastic"
  15. etaTrialService "eta/eta_api/services/eta_trial"
  16. "eta/eta_api/utils"
  17. "fmt"
  18. "github.com/rdlucklib/rdluck_tools/paging"
  19. "strconv"
  20. "strings"
  21. "sync"
  22. "time"
  23. )
  24. // EdbInfoController 数据管理
  25. type EdbInfoController struct {
  26. controllers.BaseAuthController
  27. }
  28. // EdbInfoSearch
  29. // @Title 新增指标-查询指标信息接口
  30. // @Description 新增指标-查询指标信息接口
  31. // @Param Source query int true "来源:1:同花顺,2:wind,3:彭博"
  32. // @Param SubSource query int true "子数据来源:0:经济数据库,1:日期序列"
  33. // @Param EdbCode query string false "指标编码/指标代码"
  34. // @Param SecuritiesCode query string false "证券代码"
  35. // @Success 200 {object} data_manage.EdbInfoSearchResp
  36. // @router /edb_info/search [get]
  37. func (this *EdbInfoController) EdbInfoSearch() {
  38. br := new(models.BaseResponse).Init()
  39. defer func() {
  40. this.Data["json"] = br
  41. this.ServeJSON()
  42. }()
  43. source, _ := this.GetInt("Source")
  44. edbCode := this.GetString("EdbCode")
  45. edbCode = strings.Trim(edbCode, "\t")
  46. edbCode = strings.Trim(edbCode, " ")
  47. edbCode = strings.Replace(edbCode, "\t", "", -1)
  48. subSource, _ := this.GetInt("SubSource")
  49. securitiesCode := this.GetString("SecuritiesCode")
  50. if source <= 0 {
  51. br.Msg = "无效的数据来源"
  52. return
  53. }
  54. if edbCode == "" {
  55. br.Msg = "请输入指标ID"
  56. return
  57. }
  58. //如果是彭博财务指标,那么需要传入客户code
  59. if source == utils.DATA_SOURCE_PB_FINANCE {
  60. companyCode := this.GetString("CompanyCode")
  61. companyCode = strings.Trim(companyCode, "\t")
  62. companyCode = strings.Trim(companyCode, " ")
  63. companyCode = strings.Replace(companyCode, "\t", "", -1)
  64. // 如果财务数据,那么需要拼接上客户code
  65. edbCode = companyCode + "&&" + edbCode
  66. }
  67. resp := new(data_manage.EdbInfoSearchResp)
  68. //判断指标是否存在
  69. var item *data_manage.EdbInfo
  70. var err error
  71. if source == utils.DATA_SOURCE_GL {
  72. // 如果是钢联的话,那么就先判断是不是存在钢联化工
  73. item, err = data_manage.GetEdbInfoByEdbCode(utils.DATA_SOURCE_MYSTEEL_CHEMICAL, edbCode)
  74. if err != nil {
  75. if err.Error() != utils.ErrNoRow() {
  76. br.Msg = "获取失败"
  77. br.ErrMsg = "获取失败,Err:" + err.Error()
  78. return
  79. }
  80. }
  81. err = nil
  82. if item != nil {
  83. source = utils.DATA_SOURCE_MYSTEEL_CHEMICAL
  84. } else {
  85. // 判断是不是已经在钢联这边已经存在了
  86. item, err = data_manage.GetEdbInfoByEdbCode(utils.DATA_SOURCE_GL, edbCode)
  87. if err != nil {
  88. if err.Error() != utils.ErrNoRow() {
  89. br.Msg = "获取失败"
  90. br.ErrMsg = "获取失败,Err:" + err.Error()
  91. return
  92. }
  93. }
  94. err = nil
  95. // 如果在钢联来源也没找到,那么就需要再判断下是否处于 《钢联化工》 数据源里面
  96. if item == nil {
  97. tmpInfo, err := data_manage.GetBaseFromMysteelChemicalIndexByCode(edbCode)
  98. if err != nil {
  99. if err.Error() != utils.ErrNoRow() {
  100. br.Msg = "获取失败"
  101. br.ErrMsg = "获取失败,Err:" + err.Error()
  102. return
  103. }
  104. }
  105. err = nil
  106. if tmpInfo != nil {
  107. source = utils.DATA_SOURCE_MYSTEEL_CHEMICAL
  108. }
  109. }
  110. }
  111. }
  112. if item == nil {
  113. item, err = data_manage.GetEdbInfoByEdbCode(source, edbCode)
  114. }
  115. if err != nil {
  116. if err.Error() != utils.ErrNoRow() {
  117. br.Msg = "获取失败"
  118. br.ErrMsg = "获取失败,Err:" + err.Error()
  119. return
  120. }
  121. }
  122. var isAdd bool
  123. var isInEdb bool //是否在指标库中
  124. if item != nil && item.EdbInfoId > 0 {
  125. isInEdb = true //在指标库中
  126. resp.Status = 1
  127. searchItem := new(data_manage.EdbInfoSearch)
  128. searchItem.EdbCode = item.EdbCode
  129. searchItem.StartDate = item.StartDate
  130. searchItem.EndDate = item.EndDate
  131. searchItem.EdbName = item.EdbName
  132. resp.SearchItem = searchItem
  133. //查询目录
  134. resultList, _ := data_manage.GetClassifyAllByClassifyId(item.ClassifyId)
  135. resp.ClassifyList = resultList
  136. // 查询该指标是否有权限
  137. obj := data_manage.EdbInfoNoPermissionAdmin{}
  138. conf, err := obj.GetByEdbInfoIdAndAdminId(this.SysUser.AdminId, item.EdbInfoId)
  139. if err != nil && err.Error() != utils.ErrNoRow() {
  140. br.Msg = "获取失败"
  141. br.ErrMsg = "获取当前账号的不可见指标配置失败,err:" + err.Error()
  142. return
  143. }
  144. if conf != nil {
  145. resp.Status = 3
  146. }
  147. } else {
  148. //dateNow := time.Now()
  149. //startDate := dateNow.AddDate(-30, 0, 0).Format(utils.FormatDate)
  150. searchItem := new(data_manage.EdbInfoSearch)
  151. if source == utils.DATA_SOURCE_THS {
  152. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_THS, utils.EDB_DATA_LIMIT)
  153. if err != nil && err.Error() != utils.ErrNoRow() {
  154. br.Msg = "获取失败"
  155. br.ErrMsg = "获取Ths已存在信息失败,Err:" + err.Error()
  156. return
  157. }
  158. fmt.Println("ths len:", len(dataItems))
  159. if len(dataItems) > 0 {
  160. fmt.Println("ths data exist")
  161. searchItem.EdbCode = edbCode
  162. minDate, maxDate, err := data_manage.GetEdbDataThsMaxOrMinDate(edbCode)
  163. if err != nil {
  164. br.Msg = "获取失败"
  165. br.ErrMsg = "获取Ths日期信息失败,Err:" + err.Error()
  166. return
  167. }
  168. searchItem.DataList = dataItems
  169. searchItem.StartDate = minDate
  170. searchItem.EndDate = maxDate
  171. } else {
  172. //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
  173. //searchItem, err = data.GetEdbDataByThs(edbCode, startDate, endDate)
  174. //if err != nil {
  175. // br.Msg = "获取失败"
  176. // br.ErrMsg = "获取失败,Err:" + err.Error()
  177. // return
  178. //}
  179. respItem, err := data.AddEdbData(source, edbCode)
  180. if err != nil {
  181. br.Msg = "获取失败"
  182. br.ErrMsg = "获取失败,Err:" + err.Error()
  183. return
  184. }
  185. if respItem.Ret != 200 {
  186. br.Msg = "未搜索到该指标"
  187. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  188. return
  189. }
  190. isAdd = true
  191. }
  192. } else if source == utils.DATA_SOURCE_WIND {
  193. if subSource == utils.DATA_SUB_SOURCE_EDB {
  194. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_WIND, utils.EDB_DATA_LIMIT)
  195. if err != nil && err.Error() != utils.ErrNoRow() {
  196. br.Msg = "获取失败"
  197. br.ErrMsg = "获取Wind已存在信息失败,Err:" + err.Error()
  198. return
  199. }
  200. fmt.Println("wind dataItems:", len(dataItems))
  201. if len(dataItems) > 0 {
  202. searchItem.EdbCode = edbCode
  203. minDate, maxDate, err := data_manage.GetEdbDataWindMaxOrMinDate(edbCode)
  204. if err != nil {
  205. br.Msg = "获取失败"
  206. br.ErrMsg = "获取wind日期信息失败,Err:" + err.Error()
  207. return
  208. }
  209. searchItem.DataList = dataItems
  210. searchItem.StartDate = minDate
  211. searchItem.EndDate = maxDate
  212. } else {
  213. //endDate := dateNow.Format(utils.FormatDate)
  214. //searchItem, err = data.GetEdbDataByWind(edbCode, startDate, endDate)
  215. //if err != nil {
  216. // br.Msg = "获取失败"
  217. // br.ErrMsg = "wind 获取失败,Err:" + err.Error()
  218. // return
  219. //}
  220. respItem, err := data.AddEdbData(source, edbCode)
  221. if err != nil {
  222. br.Msg = "获取失败"
  223. br.ErrMsg = "获取失败,Err:" + err.Error()
  224. return
  225. }
  226. if respItem.Ret != 200 {
  227. if respItem.Ret == 421 {
  228. br.Msg = "该渠道已超过添加上限"
  229. } else if respItem.Ret == 4052 {
  230. br.Msg = "该指标已下架"
  231. } else {
  232. br.Msg = "未搜索到该指标"
  233. }
  234. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  235. return
  236. }
  237. isAdd = true
  238. }
  239. } else if subSource == utils.DATA_SUB_SOURCE_DATE {
  240. if securitiesCode == "" {
  241. br.Msg = "请输入证券代码"
  242. return
  243. }
  244. if edbCode == "" {
  245. br.Msg = "请输入指标代码"
  246. return
  247. }
  248. respItem, err := data.AddEdbDataWindWsd(source, securitiesCode, edbCode)
  249. if err != nil {
  250. br.Msg = "获取失败"
  251. br.ErrMsg = "获取失败,Err:" + err.Error()
  252. return
  253. }
  254. if respItem.Ret != 200 {
  255. if respItem.Ret == 421 {
  256. br.Msg = "该渠道已超过添加上限"
  257. } else if respItem.Ret == 4052 {
  258. br.Msg = "该指标已下架"
  259. } else {
  260. br.Msg = "未搜索到该指标"
  261. }
  262. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  263. return
  264. }
  265. isAdd = true
  266. } else {
  267. }
  268. } else if source == utils.DATA_SOURCE_PB || source == utils.DATA_SOURCE_PB_FINANCE {
  269. fmt.Println("pb data exist")
  270. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
  271. if err != nil && err.Error() != utils.ErrNoRow() {
  272. br.Msg = "获取失败"
  273. br.ErrMsg = "获取Pb已存在信息失败,Err:" + err.Error()
  274. return
  275. }
  276. fmt.Println("pb dataItems:", len(dataItems))
  277. if len(dataItems) > 0 {
  278. searchItem.EdbCode = edbCode
  279. minDate, maxDate, err := data_manage.GetEdbDataPbMaxOrMinDate(edbCode)
  280. if err != nil {
  281. br.Msg = "获取失败"
  282. br.ErrMsg = "获取Pb日期信息失败,Err:" + err.Error()
  283. return
  284. }
  285. searchItem.DataList = dataItems
  286. searchItem.StartDate = minDate
  287. searchItem.EndDate = maxDate
  288. } else {
  289. //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
  290. //startDate := dateNow.AddDate(-30, 0, 0).Format(utils.FormatDateUnSpace)
  291. //searchItem, err = data.GetEdbDataByPb(edbCode, startDate, endDate)
  292. //if err != nil {
  293. // br.Msg = "获取失败"
  294. // br.ErrMsg = "彭博数据获取失败,Err:" + err.Error()
  295. // return
  296. //}
  297. respItem, err := data.AddEdbData(source, edbCode)
  298. if err != nil {
  299. br.Msg = "获取失败"
  300. br.ErrMsg = "获取失败,Err:" + err.Error()
  301. return
  302. }
  303. if respItem.Ret != 200 {
  304. br.Msg = "未搜索到该指标"
  305. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  306. return
  307. }
  308. isAdd = true
  309. }
  310. } else if source == utils.DATA_SOURCE_MANUAL { //手工数据指标
  311. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_MANUAL, utils.EDB_DATA_LIMIT)
  312. if err != nil && err.Error() != utils.ErrNoRow() {
  313. br.Msg = "获取失败"
  314. br.ErrMsg = "获取Ths已存在信息失败,Err:" + err.Error()
  315. return
  316. }
  317. fmt.Println("ths len:", len(dataItems))
  318. if len(dataItems) > 0 {
  319. fmt.Println("ths data exist")
  320. searchItem.EdbCode = edbCode
  321. minDate, maxDate, err := data_manage.GetEdbDataManualMaxOrMinDate(edbCode)
  322. if err != nil {
  323. br.Msg = "获取失败"
  324. br.ErrMsg = "获取Ths日期信息失败,Err:" + err.Error()
  325. return
  326. }
  327. searchItem.DataList = dataItems
  328. searchItem.StartDate = minDate
  329. searchItem.EndDate = maxDate
  330. } else {
  331. //searchItem, err = data_manage.GetEdbDataByManual(edbCode, startDate, endDate)
  332. //if err != nil {
  333. // br.Msg = "获取失败"
  334. // br.ErrMsg = "获取失败,Err:" + err.Error()
  335. // return
  336. //}
  337. respItem, err := data.AddEdbData(source, edbCode)
  338. if err != nil {
  339. br.Msg = "获取失败"
  340. br.ErrMsg = "获取失败,Err:" + err.Error()
  341. return
  342. }
  343. if respItem.Ret != 200 {
  344. br.Msg = "未搜索到该指标"
  345. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  346. return
  347. }
  348. isAdd = true
  349. }
  350. //获取指标信息
  351. manualInfo, err := models.GetEdbinfoByTradeCode(edbCode)
  352. if err != nil && err.Error() != utils.ErrNoRow() {
  353. br.Msg = "获取失败"
  354. br.ErrMsg = "获取手工指标详情失败,Err:" + err.Error()
  355. return
  356. }
  357. if manualInfo != nil {
  358. searchItem.Frequency = manualInfo.Frequency
  359. searchItem.Unit = manualInfo.Unit
  360. searchItem.EdbName = manualInfo.SecName
  361. }
  362. } else if source == utils.DATA_SOURCE_LZ {
  363. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_LZ, utils.EDB_DATA_LIMIT)
  364. if err != nil && err.Error() != utils.ErrNoRow() {
  365. br.Msg = "获取失败"
  366. br.ErrMsg = "获取隆众已存在信息失败,Err:" + err.Error()
  367. return
  368. }
  369. fmt.Println("ths len:", len(dataItems))
  370. if len(dataItems) > 0 {
  371. fmt.Println("ths data exist")
  372. searchItem.EdbCode = edbCode
  373. minDate, maxDate, err := data_manage.GetEdbDataLzMaxOrMinDate(edbCode)
  374. if err != nil {
  375. br.Msg = "获取失败"
  376. br.ErrMsg = "获取隆众日期信息失败,Err:" + err.Error()
  377. return
  378. }
  379. searchItem.DataList = dataItems
  380. searchItem.StartDate = minDate
  381. searchItem.EndDate = maxDate
  382. } else {
  383. //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
  384. //searchItem, err = data_manage.GetEdbDataByLz(edbCode, startDate, endDate)
  385. //if err != nil {
  386. // br.Msg = "获取失败"
  387. // br.ErrMsg = "获取隆众数据失败,Err:" + err.Error()
  388. // return
  389. //}
  390. respItem, err := data.AddEdbData(source, edbCode)
  391. if err != nil {
  392. br.Msg = "获取失败"
  393. br.ErrMsg = "获取失败,Err:" + err.Error()
  394. return
  395. }
  396. if respItem.Ret != 200 {
  397. br.Msg = "未搜索到该指标"
  398. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  399. return
  400. }
  401. isAdd = true
  402. }
  403. //获取指标信息
  404. lzInfo, err := data_manage.GetLongzhongSurveyProductByCode(edbCode)
  405. if err != nil && err.Error() != utils.ErrNoRow() {
  406. br.Msg = "获取失败"
  407. br.ErrMsg = "获取手工指标详情失败,Err:" + err.Error()
  408. return
  409. }
  410. if lzInfo != nil {
  411. frequency := lzInfo.Frequency
  412. var frequencyStr string
  413. if frequency == 1 {
  414. frequencyStr = "日度"
  415. } else if frequency == 2 {
  416. frequencyStr = "周度"
  417. } else if frequency == 3 {
  418. frequencyStr = "月度"
  419. } else if frequency == 4 {
  420. frequencyStr = "季度"
  421. } else if frequency == 5 {
  422. frequencyStr = "年度"
  423. } else if frequency == 99 {
  424. frequencyStr = "无固定频率"
  425. }
  426. searchItem.Frequency = frequencyStr
  427. searchItem.Unit = lzInfo.UnitName
  428. searchItem.EdbName = lzInfo.SampleName + lzInfo.BreedName + lzInfo.QuotaName
  429. }
  430. } else if source == utils.DATA_SOURCE_YS { //有色网
  431. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_YS, utils.EDB_DATA_LIMIT)
  432. if err != nil && err.Error() != utils.ErrNoRow() {
  433. br.Msg = "获取失败"
  434. br.ErrMsg = "获取Ys已存在信息失败,Err:" + err.Error()
  435. return
  436. }
  437. fmt.Println("dataItems:", len(dataItems))
  438. if len(dataItems) > 0 {
  439. searchItem.EdbCode = edbCode
  440. minDate, maxDate, err := data_manage.GetEdbDataYsMaxAndMinDate(edbCode)
  441. if err != nil {
  442. br.Msg = "获取失败"
  443. br.ErrMsg = "获取YS日期信息失败,Err:" + err.Error()
  444. return
  445. }
  446. searchItem.DataList = dataItems
  447. searchItem.StartDate = minDate
  448. searchItem.EndDate = maxDate
  449. } else {
  450. //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
  451. //searchItem, err = data_manage.GetEdbDataByYs(edbCode, startDate, endDate)
  452. //if err != nil {
  453. // br.Msg = "获取失败"
  454. // br.ErrMsg = "获取失败,GetEdbDataByYs Err:" + err.Error()
  455. // return
  456. //}
  457. //if searchItem.StartDate == "" {
  458. // minDate, maxDate, _ := data_manage.GetEdbDataYsMaxAndMinDate(edbCode)
  459. // searchItem.StartDate = minDate
  460. // searchItem.EndDate = maxDate
  461. //}
  462. respItem, err := data.AddEdbData(source, edbCode)
  463. if err != nil {
  464. br.Msg = "获取失败"
  465. br.ErrMsg = "获取失败,Err:" + err.Error()
  466. return
  467. }
  468. if respItem.Ret != 200 {
  469. br.Msg = "未搜索到该指标"
  470. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  471. return
  472. }
  473. isAdd = true
  474. }
  475. //获取指标信息
  476. smmInfo, err := data_manage.GetBaseFromSmmIndexByIndexCode(edbCode)
  477. if err != nil && err.Error() != utils.ErrNoRow() {
  478. br.Msg = "获取失败"
  479. br.ErrMsg = "获取有色指标详情失败,Err:" + err.Error()
  480. return
  481. }
  482. if smmInfo != nil {
  483. searchItem.Frequency = smmInfo.Frequency
  484. searchItem.Unit = smmInfo.Unit
  485. searchItem.EdbName = smmInfo.IndexName
  486. }
  487. } else if source == utils.DATA_SOURCE_GL { //钢联
  488. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
  489. if err != nil && err.Error() != utils.ErrNoRow() {
  490. br.Msg = "获取失败"
  491. br.ErrMsg = "获取钢联已存在信息失败,Err:" + err.Error()
  492. return
  493. }
  494. if len(dataItems) > 0 {
  495. searchItem.EdbCode = edbCode
  496. minDate, maxDate, err := data_manage.GetEdbDataGlMaxOrMinDate(edbCode)
  497. if err != nil {
  498. br.Msg = "获取失败"
  499. br.ErrMsg = "获取钢联日期信息失败,Err:" + err.Error()
  500. return
  501. }
  502. searchItem.DataList = dataItems
  503. searchItem.StartDate = minDate
  504. searchItem.EndDate = maxDate
  505. } else {
  506. //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
  507. //searchItem, err = data_manage.GetEdbDataByGl(edbCode, startDate, endDate)
  508. //if err != nil {
  509. // br.Msg = "获取失败"
  510. // br.ErrMsg = "获取钢联数据失败,Err:" + err.Error()
  511. // return
  512. //}
  513. respItem, err := data.AddEdbData(source, edbCode)
  514. if err != nil {
  515. br.Msg = "获取失败"
  516. br.ErrMsg = "获取失败,Err:" + err.Error()
  517. return
  518. }
  519. if respItem.Ret != 200 {
  520. br.Msg = "未搜索到该指标"
  521. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  522. return
  523. }
  524. isAdd = true
  525. }
  526. //获取指标信息
  527. glInfo, err := data_manage.GetGlIndexByCode(edbCode)
  528. if err != nil && err.Error() != utils.ErrNoRow() {
  529. br.Msg = "获取失败"
  530. br.ErrMsg = "获取钢联指标详情失败,Err:" + err.Error()
  531. return
  532. }
  533. if glInfo != nil {
  534. searchItem.Frequency = glInfo.FrequencyName
  535. searchItem.Unit = glInfo.UnitName
  536. searchItem.EdbName = glInfo.IndexName
  537. }
  538. } else if source == utils.DATA_SOURCE_ZZ { //郑商所
  539. var suffix string
  540. if strings.Contains(edbCode, "deal") {
  541. suffix = "deal"
  542. } else if strings.Contains(edbCode, "buy") {
  543. suffix = "buy"
  544. } else if strings.Contains(edbCode, "sold") {
  545. suffix = "sold"
  546. } else {
  547. br.Msg = "未搜索到该指标"
  548. br.ErrMsg = "指标code异常"
  549. return
  550. }
  551. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
  552. if err != nil && err.Error() != utils.ErrNoRow() {
  553. br.Msg = "获取失败"
  554. br.ErrMsg = "获取郑商所已存在信息失败,Err:" + err.Error()
  555. return
  556. }
  557. if len(dataItems) > 0 {
  558. searchItem.EdbCode = edbCode
  559. minDate, maxDate, err := data_manage.GetEdbDataZzMaxOrMinDate(edbCode)
  560. if err != nil {
  561. br.Msg = "获取失败"
  562. br.ErrMsg = "获取郑商所日期信息失败,Err:" + err.Error()
  563. return
  564. }
  565. searchItem.DataList = dataItems
  566. searchItem.StartDate = minDate
  567. searchItem.EndDate = maxDate
  568. } else {
  569. //searchItem, err = data_manage.GetEdbDataByZz(edbCode, suffix, startDate, "")
  570. //if err != nil {
  571. // br.Msg = "获取失败"
  572. // br.ErrMsg = "获取失败,GetEdbDataByZz Err:" + err.Error()
  573. // return
  574. //}
  575. //if searchItem.StartDate == "" {
  576. // minDate, maxDate, _ := data_manage.GetEdbDataZzMaxOrMinDate(edbCode)
  577. // searchItem.StartDate = minDate
  578. // searchItem.EndDate = maxDate
  579. //}
  580. respItem, err := data.AddEdbData(source, edbCode)
  581. if err != nil {
  582. br.Msg = "获取失败"
  583. br.ErrMsg = "获取失败,Err:" + err.Error()
  584. return
  585. }
  586. if respItem.Ret != 200 {
  587. br.Msg = "未搜索到该指标"
  588. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  589. return
  590. }
  591. isAdd = true
  592. }
  593. //获取指标信息
  594. allInfo, err := data_manage.GetBaseInfoFromZhengzhouByIndexCode(edbCode, suffix)
  595. if err != nil && err.Error() != utils.ErrNoRow() {
  596. br.Msg = "获取失败"
  597. br.ErrMsg = "获取郑商所指标详情失败,Err:" + err.Error()
  598. return
  599. }
  600. var zzInfo *data_manage.BaseInfoFromZz
  601. if allInfo != nil {
  602. zzInfo = allInfo[0]
  603. }
  604. if zzInfo != nil {
  605. searchItem.Frequency = "日度"
  606. searchItem.Unit = "手"
  607. if suffix == "deal" {
  608. searchItem.EdbName = zzInfo.DealName
  609. } else if suffix == "buy" {
  610. searchItem.EdbName = zzInfo.BuyName
  611. } else {
  612. searchItem.EdbName = zzInfo.SoldName
  613. }
  614. }
  615. } else if source == utils.DATA_SOURCE_DL { //大商所
  616. var suffix string
  617. if strings.Contains(edbCode, "deal") {
  618. suffix = "deal"
  619. } else if strings.Contains(edbCode, "buy") {
  620. suffix = "buy"
  621. } else if strings.Contains(edbCode, "sold") {
  622. suffix = "sold"
  623. } else {
  624. br.Msg = "未搜索到该指标"
  625. br.ErrMsg = "指标code异常"
  626. return
  627. }
  628. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
  629. if err != nil && err.Error() != utils.ErrNoRow() {
  630. br.Msg = "获取失败"
  631. br.ErrMsg = "获取大商所已存在信息失败,Err:" + err.Error()
  632. return
  633. }
  634. if len(dataItems) > 0 {
  635. searchItem.EdbCode = edbCode
  636. minDate, maxDate, err := data_manage.GetEdbDataDlMaxOrMinDate(edbCode)
  637. if err != nil {
  638. br.Msg = "获取失败"
  639. br.ErrMsg = "获取大商所日期信息失败,Err:" + err.Error()
  640. return
  641. }
  642. searchItem.DataList = dataItems
  643. searchItem.StartDate = minDate
  644. searchItem.EndDate = maxDate
  645. } else {
  646. //searchItem, err = data_manage.GetEdbDataByDl(edbCode, suffix, startDate, "")
  647. //if err != nil {
  648. // br.Msg = "获取失败"
  649. // br.ErrMsg = "获取失败,GetEdbDataByDl Err:" + err.Error()
  650. // return
  651. //}
  652. //if searchItem.StartDate == "" {
  653. // minDate, maxDate, _ := data_manage.GetEdbDataDlMaxOrMinDate(edbCode)
  654. // searchItem.StartDate = minDate
  655. // searchItem.EndDate = maxDate
  656. //}
  657. respItem, err := data.AddEdbData(source, edbCode)
  658. if err != nil {
  659. br.Msg = "获取失败"
  660. br.ErrMsg = "获取失败,Err:" + err.Error()
  661. return
  662. }
  663. if respItem.Ret != 200 {
  664. br.Msg = "未搜索到该指标"
  665. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  666. return
  667. }
  668. isAdd = true
  669. }
  670. //获取指标信息
  671. allInfo, err := data_manage.GetBaseInfoFromDalianByIndexCode(edbCode, suffix)
  672. if err != nil && err.Error() != utils.ErrNoRow() {
  673. br.Msg = "获取失败"
  674. br.ErrMsg = "获取大商所指标详情失败,Err:" + err.Error()
  675. return
  676. }
  677. var dlInfo *data_manage.BaseInfoFromDl
  678. if allInfo != nil {
  679. dlInfo = allInfo[0]
  680. }
  681. if dlInfo != nil {
  682. searchItem.Frequency = "日度"
  683. searchItem.Unit = "手"
  684. if suffix == "deal" {
  685. searchItem.EdbName = dlInfo.DealName
  686. } else if suffix == "buy" {
  687. searchItem.EdbName = dlInfo.BuyName
  688. } else {
  689. searchItem.EdbName = dlInfo.SoldName
  690. }
  691. }
  692. } else if source == utils.DATA_SOURCE_SH { //上期所
  693. var suffix string
  694. if strings.Contains(edbCode, "deal") {
  695. suffix = "deal"
  696. } else if strings.Contains(edbCode, "buy") {
  697. suffix = "buy"
  698. } else if strings.Contains(edbCode, "sold") {
  699. suffix = "sold"
  700. } else {
  701. br.Msg = "未搜索到该指标"
  702. br.ErrMsg = "指标code异常"
  703. return
  704. }
  705. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
  706. if err != nil && err.Error() != utils.ErrNoRow() {
  707. br.Msg = "获取失败"
  708. br.ErrMsg = "获取上期所已存在信息失败,Err:" + err.Error()
  709. return
  710. }
  711. if len(dataItems) > 0 {
  712. searchItem.EdbCode = edbCode
  713. minDate, maxDate, err := data_manage.GetEdbDataShMaxOrMinDate(edbCode)
  714. if err != nil {
  715. br.Msg = "获取失败"
  716. br.ErrMsg = "获取上期所日期信息失败,Err:" + err.Error()
  717. return
  718. }
  719. searchItem.DataList = dataItems
  720. searchItem.StartDate = minDate
  721. searchItem.EndDate = maxDate
  722. } else {
  723. //searchItem, err = data_manage.GetEdbDataBySh(edbCode, suffix, startDate, "")
  724. //if err != nil {
  725. // br.Msg = "获取失败"
  726. // br.ErrMsg = "获取失败,GetEdbDataBySh Err:" + err.Error()
  727. // return
  728. //}
  729. //if searchItem.StartDate == "" {
  730. // minDate, maxDate, _ := data_manage.GetEdbDataShMaxOrMinDate(edbCode)
  731. // searchItem.StartDate = minDate
  732. // searchItem.EndDate = maxDate
  733. //}
  734. respItem, err := data.AddEdbData(source, edbCode)
  735. if err != nil {
  736. br.Msg = "获取失败"
  737. br.ErrMsg = "获取失败,Err:" + err.Error()
  738. return
  739. }
  740. if respItem.Ret != 200 {
  741. br.Msg = "未搜索到该指标"
  742. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  743. return
  744. }
  745. isAdd = true
  746. }
  747. //获取指标信息
  748. allInfo, err := data_manage.GetBaseInfoFromShByIndexCode(edbCode, suffix)
  749. if err != nil && err.Error() != utils.ErrNoRow() {
  750. br.Msg = "获取失败"
  751. br.ErrMsg = "获取上期所指标详情失败,Err:" + err.Error()
  752. return
  753. }
  754. var shInfo *data_manage.BaseInfoFromSh
  755. if allInfo != nil {
  756. shInfo = allInfo[0]
  757. }
  758. if shInfo != nil {
  759. searchItem.Frequency = "日度"
  760. searchItem.Unit = "手"
  761. if suffix == "deal" {
  762. searchItem.EdbName = shInfo.DealName
  763. } else if suffix == "buy" {
  764. searchItem.EdbName = shInfo.BuyName
  765. } else {
  766. searchItem.EdbName = shInfo.SoldName
  767. }
  768. }
  769. } else if source == utils.DATA_SOURCE_CFFEX { //中金所
  770. var suffix string
  771. if strings.Contains(edbCode, "deal") {
  772. suffix = "deal"
  773. } else if strings.Contains(edbCode, "buy") {
  774. suffix = "buy"
  775. } else if strings.Contains(edbCode, "sold") {
  776. suffix = "sold"
  777. } else {
  778. br.Msg = "未搜索到该指标"
  779. br.ErrMsg = "指标code异常"
  780. return
  781. }
  782. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
  783. if err != nil && err.Error() != utils.ErrNoRow() {
  784. br.Msg = "获取失败"
  785. br.ErrMsg = "获取中金所已存在信息失败,Err:" + err.Error()
  786. return
  787. }
  788. if len(dataItems) > 0 {
  789. searchItem.EdbCode = edbCode
  790. minDate, maxDate, err := data_manage.GetEdbDataCffexMaxOrMinDate(edbCode)
  791. if err != nil {
  792. br.Msg = "获取失败"
  793. br.ErrMsg = "获取中金所日期信息失败,Err:" + err.Error()
  794. return
  795. }
  796. searchItem.DataList = dataItems
  797. searchItem.StartDate = minDate
  798. searchItem.EndDate = maxDate
  799. } else {
  800. //searchItem, err = data_manage.GetEdbDataByCffex(edbCode, suffix, startDate, "")
  801. //if err != nil {
  802. // br.Msg = "获取失败"
  803. // br.ErrMsg = "获取失败,GetEdbDataByCffex Err:" + err.Error()
  804. // return
  805. //}
  806. //if searchItem.StartDate == "" {
  807. // minDate, maxDate, _ := data_manage.GetEdbDataCffexMaxOrMinDate(edbCode)
  808. // searchItem.StartDate = minDate
  809. // searchItem.EndDate = maxDate
  810. //}
  811. respItem, err := data.AddEdbData(source, edbCode)
  812. if err != nil {
  813. br.Msg = "获取失败"
  814. br.ErrMsg = "获取失败,Err:" + err.Error()
  815. return
  816. }
  817. if respItem.Ret != 200 {
  818. br.Msg = "未搜索到该指标"
  819. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  820. return
  821. }
  822. isAdd = true
  823. }
  824. //获取指标信息
  825. allInfo, err := data_manage.GetBaseInfoFromCffexByIndexCode(edbCode, suffix)
  826. if err != nil && err.Error() != utils.ErrNoRow() {
  827. br.Msg = "获取失败"
  828. br.ErrMsg = "获取中金所指标详情失败,Err:" + err.Error()
  829. return
  830. }
  831. var cffexInfo *data_manage.BaseInfoFromCffex
  832. if allInfo != nil {
  833. cffexInfo = allInfo[0]
  834. }
  835. if cffexInfo != nil {
  836. searchItem.Frequency = "日度"
  837. searchItem.Unit = "手"
  838. if suffix == "deal" {
  839. searchItem.EdbName = cffexInfo.DealName
  840. } else if suffix == "buy" {
  841. searchItem.EdbName = cffexInfo.BuyName
  842. } else {
  843. searchItem.EdbName = cffexInfo.SoldName
  844. }
  845. }
  846. } else if source == utils.DATA_SOURCE_SHFE { //上期能源
  847. var suffix string
  848. if strings.Contains(edbCode, "deal") {
  849. suffix = "deal"
  850. } else if strings.Contains(edbCode, "buy") {
  851. suffix = "buy"
  852. } else if strings.Contains(edbCode, "sold") {
  853. suffix = "sold"
  854. } else {
  855. br.Msg = "未搜索到该指标"
  856. br.ErrMsg = "指标code异常"
  857. return
  858. }
  859. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
  860. if err != nil && err.Error() != utils.ErrNoRow() {
  861. br.Msg = "获取失败"
  862. br.ErrMsg = "获取上期能源已存在信息失败,Err:" + err.Error()
  863. return
  864. }
  865. if len(dataItems) > 0 {
  866. searchItem.EdbCode = edbCode
  867. minDate, maxDate, err := data_manage.GetEdbDataShfeMaxOrMinDate(edbCode)
  868. if err != nil {
  869. br.Msg = "获取失败"
  870. br.ErrMsg = "获取上期能源日期信息失败,Err:" + err.Error()
  871. return
  872. }
  873. searchItem.DataList = dataItems
  874. searchItem.StartDate = minDate
  875. searchItem.EndDate = maxDate
  876. } else {
  877. //searchItem, err = data_manage.GetEdbDataByShfe(edbCode, suffix, startDate, "")
  878. //if err != nil {
  879. // br.Msg = "获取失败"
  880. // br.ErrMsg = "获取失败,GetEdbDataByShfe Err:" + err.Error()
  881. // return
  882. //}
  883. //if searchItem.StartDate == "" {
  884. // minDate, maxDate, _ := data_manage.GetEdbDataShfeMaxOrMinDate(edbCode)
  885. // searchItem.StartDate = minDate
  886. // searchItem.EndDate = maxDate
  887. //}
  888. respItem, err := data.AddEdbData(source, edbCode)
  889. if err != nil {
  890. br.Msg = "获取失败"
  891. br.ErrMsg = "获取失败,Err:" + err.Error()
  892. return
  893. }
  894. if respItem.Ret != 200 {
  895. br.Msg = "未搜索到该指标"
  896. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  897. return
  898. }
  899. isAdd = true
  900. }
  901. //获取指标信息
  902. allInfo, err := data_manage.GetBaseInfoFromShfeByIndexCode(edbCode, suffix)
  903. if err != nil && err.Error() != utils.ErrNoRow() {
  904. br.Msg = "获取失败"
  905. br.ErrMsg = "获取上期能源指标详情失败,Err:" + err.Error()
  906. return
  907. }
  908. var shfeInfo *data_manage.BaseInfoFromShfe
  909. if allInfo != nil {
  910. shfeInfo = allInfo[0]
  911. }
  912. if shfeInfo != nil {
  913. searchItem.Frequency = "日度"
  914. searchItem.Unit = "手"
  915. if suffix == "deal" {
  916. searchItem.EdbName = shfeInfo.DealName
  917. } else if suffix == "buy" {
  918. searchItem.EdbName = shfeInfo.BuyName
  919. } else {
  920. searchItem.EdbName = shfeInfo.SoldName
  921. }
  922. }
  923. } else if source == utils.DATA_SOURCE_GIE { //欧洲天然气
  924. var suffix string
  925. l := len(edbCode)
  926. if strings.Contains(edbCode[l-2:], "GS") {
  927. suffix = "GS"
  928. } else if strings.Contains(edbCode[l-2:], "CF") {
  929. suffix = "CF"
  930. } else if strings.Contains(edbCode[l-1:], "T") {
  931. suffix = "T"
  932. } else if strings.Contains(edbCode[l-2:], "In") {
  933. suffix = "In"
  934. } else if strings.Contains(edbCode[l-3:], "Out") {
  935. suffix = "Out"
  936. } else if strings.Contains(edbCode[l-3:], "WGV") {
  937. suffix = "WGV"
  938. } else if strings.Contains(edbCode[l-2:], "IC") {
  939. suffix = "IC"
  940. } else if strings.Contains(edbCode[l-2:], "WC") {
  941. suffix = "WC"
  942. } else if strings.Contains(edbCode[l-1:], "F") {
  943. suffix = "F"
  944. } else if strings.Contains(edbCode[l-1:], "C") {
  945. suffix = "C"
  946. } else {
  947. br.Msg = "未搜索到该指标"
  948. br.ErrMsg = "指标code异常"
  949. return
  950. }
  951. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
  952. if err != nil && err.Error() != utils.ErrNoRow() {
  953. br.Msg = "获取失败"
  954. br.ErrMsg = "获取欧洲天然气已存在信息失败,Err:" + err.Error()
  955. return
  956. }
  957. if len(dataItems) > 0 {
  958. searchItem.EdbCode = edbCode
  959. minDate, maxDate, err := data_manage.GetEdbDataGieMaxOrMinDate(edbCode)
  960. if err != nil {
  961. br.Msg = "获取失败"
  962. br.ErrMsg = "获取欧洲天然气日期信息失败,Err:" + err.Error()
  963. return
  964. }
  965. searchItem.DataList = dataItems
  966. searchItem.StartDate = minDate
  967. searchItem.EndDate = maxDate
  968. } else {
  969. //searchItem, err = data_manage.GetEdbDataByGie(edbCode, suffix, startDate, "")
  970. //if err != nil {
  971. // br.Msg = "获取失败"
  972. // br.ErrMsg = "获取失败,GetEdbDataByGie Err:" + err.Error()
  973. // return
  974. //}
  975. //if searchItem.StartDate == "" {
  976. // minDate, maxDate, _ := data_manage.GetEdbDataGieMaxOrMinDate(edbCode)
  977. // searchItem.StartDate = minDate
  978. // searchItem.EndDate = maxDate
  979. //}
  980. respItem, err := data.AddEdbData(source, edbCode)
  981. if err != nil {
  982. br.Msg = "获取失败"
  983. br.ErrMsg = "获取失败,Err:" + err.Error()
  984. return
  985. }
  986. if respItem.Ret != 200 {
  987. br.Msg = "未搜索到该指标"
  988. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  989. return
  990. }
  991. isAdd = true
  992. }
  993. //获取指标信息
  994. allInfo, err := data_manage.GetBaseFromEicDataAllByIndexCodeV2(edbCode, suffix)
  995. if err != nil && err.Error() != utils.ErrNoRow() {
  996. br.Msg = "获取失败"
  997. br.ErrMsg = "获取欧洲天然气指标详情失败,Err:" + err.Error()
  998. return
  999. }
  1000. var eicInfo *data_manage.BaseFromTradeEicIndexV2
  1001. if allInfo != nil {
  1002. eicInfo = allInfo[0]
  1003. }
  1004. var name string
  1005. if eicInfo != nil {
  1006. searchItem.Frequency = "日度"
  1007. if suffix == "GS" {
  1008. name = eicInfo.Name + "_gas_in_storage"
  1009. searchItem.EdbName = name
  1010. searchItem.Unit = "TWh"
  1011. } else if suffix == "C" {
  1012. name = eicInfo.Name + "_consumption"
  1013. searchItem.EdbName = name
  1014. searchItem.Unit = "TWh"
  1015. } else if suffix == "CF" {
  1016. name = eicInfo.Name + "_consumption_full"
  1017. searchItem.EdbName = name
  1018. searchItem.Unit = "百分比"
  1019. } else if suffix == "F" {
  1020. name = eicInfo.Name + "_full"
  1021. searchItem.EdbName = name
  1022. searchItem.Unit = "百分比"
  1023. } else if suffix == "T" {
  1024. name = eicInfo.Name + "_trend"
  1025. searchItem.EdbName = name
  1026. searchItem.Unit = "百分比"
  1027. } else if suffix == "In" {
  1028. name = eicInfo.Name + "_injection"
  1029. searchItem.EdbName = name
  1030. searchItem.Unit = "GWH/d"
  1031. } else if suffix == "Out" {
  1032. name = eicInfo.Name + "_withdrawal"
  1033. searchItem.EdbName = name
  1034. searchItem.Unit = "GWH/d"
  1035. } else if suffix == "WGV" {
  1036. name = eicInfo.Name + "_working_gas_volume"
  1037. searchItem.EdbName = name
  1038. searchItem.Unit = "TWh"
  1039. } else if suffix == "IC" {
  1040. name = eicInfo.Name + "_injection_capacity"
  1041. searchItem.EdbName = name
  1042. searchItem.Unit = "GWh/d"
  1043. } else if suffix == "WC" {
  1044. name = eicInfo.Name + "_withdrawal_capacity"
  1045. searchItem.EdbName = name
  1046. searchItem.Unit = "GWh/d"
  1047. }
  1048. }
  1049. } else if source == utils.DATA_SOURCE_LT {
  1050. fmt.Println("lt data exist")
  1051. if strings.Contains(edbCode, "=") {
  1052. br.Msg = "暂不支持编码中含有=的指标"
  1053. br.ErrMsg = "暂不支持编码中含有=的指标"
  1054. return
  1055. }
  1056. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_LT, utils.EDB_DATA_LIMIT)
  1057. if err != nil && err.Error() != utils.ErrNoRow() {
  1058. br.Msg = "获取失败"
  1059. br.ErrMsg = "获取 lt 已存在信息失败,Err:" + err.Error()
  1060. return
  1061. }
  1062. fmt.Println("lt dataItems:", len(dataItems))
  1063. if len(dataItems) > 0 {
  1064. searchItem.EdbCode = edbCode
  1065. edbInfoMaxAndMinInfo, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
  1066. if err != nil {
  1067. br.Msg = "获取失败"
  1068. br.ErrMsg = "获取lt日期信息失败,Err:" + err.Error()
  1069. return
  1070. }
  1071. searchItem.DataList = dataItems
  1072. searchItem.StartDate = edbInfoMaxAndMinInfo.MinDate
  1073. searchItem.EndDate = edbInfoMaxAndMinInfo.MaxDate
  1074. } else {
  1075. //endDate := dateNow.Format(utils.FormatDate)
  1076. //searchItem, err = data.GetEdbDataByLt(edbCode, startDate, endDate)
  1077. //if err != nil {
  1078. // br.Msg = "获取失败"
  1079. // br.ErrMsg = "lt 获取失败,Err:" + err.Error()
  1080. // return
  1081. //}
  1082. respItem, err := data.AddEdbData(source, edbCode)
  1083. if err != nil {
  1084. br.Msg = "获取失败"
  1085. br.ErrMsg = "获取失败,Err:" + err.Error()
  1086. return
  1087. }
  1088. if respItem.Ret != 200 {
  1089. br.Msg = respItem.Msg
  1090. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1091. return
  1092. }
  1093. isAdd = true
  1094. }
  1095. } else if source == utils.DATA_SOURCE_COAL { //中国煤炭网
  1096. var suffix string
  1097. if strings.Contains(edbCode, "jsm") {
  1098. suffix = "jsm_index"
  1099. } else if strings.Contains(edbCode, "company") {
  1100. suffix = "company_index"
  1101. } else if strings.Contains(edbCode, "firm") {
  1102. suffix = "firm_index"
  1103. } else if strings.Contains(edbCode, "coastal") {
  1104. suffix = "coastal_index"
  1105. } else if strings.Contains(edbCode, "inland") {
  1106. suffix = "inland_index"
  1107. } else {
  1108. br.Msg = "未搜索到该指标"
  1109. br.ErrMsg = "指标code异常"
  1110. return
  1111. }
  1112. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
  1113. if err != nil && err.Error() != utils.ErrNoRow() {
  1114. br.Msg = "获取失败"
  1115. br.ErrMsg = "获取煤炭网已存在信息失败,Err:" + err.Error()
  1116. return
  1117. }
  1118. if len(dataItems) > 0 {
  1119. searchItem.EdbCode = edbCode
  1120. minDate, maxDate, err := data_manage.GetEdbDataCoalMaxOrMinDate(edbCode)
  1121. if err != nil {
  1122. br.Msg = "获取失败"
  1123. br.ErrMsg = "获取煤炭网日期信息失败,Err:" + err.Error()
  1124. return
  1125. }
  1126. searchItem.DataList = dataItems
  1127. searchItem.StartDate = minDate
  1128. searchItem.EndDate = maxDate
  1129. } else {
  1130. //searchItem, err = data_manage.GetEdbDataByCffex(edbCode, suffix, startDate, "")
  1131. //if err != nil {
  1132. // br.Msg = "获取失败"
  1133. // br.ErrMsg = "获取失败,GetEdbDataByCffex Err:" + err.Error()
  1134. // return
  1135. //}
  1136. //if searchItem.StartDate == "" {
  1137. // minDate, maxDate, _ := data_manage.GetEdbDataCffexMaxOrMinDate(edbCode)
  1138. // searchItem.StartDate = minDate
  1139. // searchItem.EndDate = maxDate
  1140. //}
  1141. respItem, err := data.AddEdbData(source, edbCode)
  1142. if err != nil {
  1143. br.Msg = "获取失败"
  1144. br.ErrMsg = "获取失败,Err:" + err.Error()
  1145. return
  1146. }
  1147. if respItem.Ret != 200 {
  1148. br.Msg = "未搜索到该指标"
  1149. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1150. return
  1151. }
  1152. isAdd = true
  1153. }
  1154. //获取指标信息
  1155. allInfo, err := data_manage.GetBaseInfoFromCoalByIndexCode(edbCode, suffix)
  1156. if err != nil && err.Error() != utils.ErrNoRow() {
  1157. br.Msg = "获取失败"
  1158. br.ErrMsg = "获取煤炭网指标详情失败,Err:" + err.Error()
  1159. return
  1160. }
  1161. var coalInfo *data_manage.BaseInfoFromCoal
  1162. if allInfo != nil {
  1163. coalInfo = allInfo[0]
  1164. }
  1165. if coalInfo != nil {
  1166. searchItem.Frequency = coalInfo.Frequency
  1167. searchItem.Unit = coalInfo.Unit
  1168. searchItem.EdbName = coalInfo.IndexName
  1169. }
  1170. } else if source == utils.DATA_SOURCE_GOOGLE_TRAVEL { //谷歌出行数据
  1171. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
  1172. if err != nil && err.Error() != utils.ErrNoRow() {
  1173. br.Msg = "获取失败"
  1174. br.ErrMsg = "获取煤炭网已存在信息失败,Err:" + err.Error()
  1175. return
  1176. }
  1177. if len(dataItems) > 0 {
  1178. searchItem.EdbCode = edbCode
  1179. item, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
  1180. if err != nil {
  1181. br.Msg = "获取失败"
  1182. br.ErrMsg = "获取煤炭网日期信息失败,Err:" + err.Error()
  1183. return
  1184. }
  1185. if item != nil {
  1186. searchItem.DataList = dataItems
  1187. searchItem.StartDate = item.MinDate
  1188. searchItem.EndDate = item.MaxDate
  1189. }
  1190. } else {
  1191. respItem, err := data.AddEdbData(source, edbCode)
  1192. if err != nil {
  1193. br.Msg = "获取失败"
  1194. br.ErrMsg = "获取失败,Err:" + err.Error()
  1195. return
  1196. }
  1197. if respItem.Ret != 200 {
  1198. br.Msg = "未搜索到该指标"
  1199. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1200. return
  1201. }
  1202. isAdd = true
  1203. }
  1204. } else if source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL { //钢联化工
  1205. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
  1206. if err != nil && err.Error() != utils.ErrNoRow() {
  1207. br.Msg = "获取失败"
  1208. br.ErrMsg = "获取钢联已存在信息失败,Err:" + err.Error()
  1209. return
  1210. }
  1211. if len(dataItems) > 0 {
  1212. searchItem.EdbCode = edbCode
  1213. minDate, maxDate, err := data_manage.GetEdbDataMysteelChemicalMaxOrMinDate(edbCode)
  1214. if err != nil {
  1215. br.Msg = "获取失败"
  1216. br.ErrMsg = "获取钢联日期信息失败,Err:" + err.Error()
  1217. return
  1218. }
  1219. searchItem.DataList = dataItems
  1220. searchItem.StartDate = minDate
  1221. searchItem.EndDate = maxDate
  1222. } else {
  1223. //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
  1224. //searchItem, err = data_manage.GetEdbDataByGl(edbCode, startDate, endDate)
  1225. //if err != nil {
  1226. // br.Msg = "获取失败"
  1227. // br.ErrMsg = "获取钢联数据失败,Err:" + err.Error()
  1228. // return
  1229. //}
  1230. respItem, err := data.AddEdbData(source, edbCode)
  1231. if err != nil {
  1232. br.Msg = "获取失败"
  1233. br.ErrMsg = "获取失败,Err:" + err.Error()
  1234. return
  1235. }
  1236. if respItem.Ret != 200 {
  1237. br.Msg = "未搜索到该指标"
  1238. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1239. return
  1240. }
  1241. isAdd = true
  1242. }
  1243. //获取指标信息
  1244. glInfo, err := data_manage.GetBaseFromMysteelChemicalIndexByCode(edbCode)
  1245. if err != nil && err.Error() != utils.ErrNoRow() {
  1246. br.Msg = "获取失败"
  1247. br.ErrMsg = "获取钢联指标详情失败,Err:" + err.Error()
  1248. return
  1249. }
  1250. if glInfo != nil {
  1251. searchItem.Frequency = glInfo.Frequency
  1252. searchItem.Unit = glInfo.Unit
  1253. searchItem.EdbName = glInfo.IndexName
  1254. }
  1255. } else if source == utils.DATA_SOURCE_EIA_STEO { //eia steo报告
  1256. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
  1257. if err != nil && err.Error() != utils.ErrNoRow() {
  1258. br.Msg = "获取失败"
  1259. br.ErrMsg = "获取钢联已存在信息失败,Err:" + err.Error()
  1260. return
  1261. }
  1262. if len(dataItems) > 0 {
  1263. searchItem.EdbCode = edbCode
  1264. item, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
  1265. if err != nil {
  1266. br.Msg = "获取失败"
  1267. br.ErrMsg = "获取eia steo日期信息失败,Err:" + err.Error()
  1268. return
  1269. }
  1270. searchItem.DataList = dataItems
  1271. searchItem.StartDate = item.MinDate
  1272. searchItem.EndDate = item.MaxDate
  1273. } else {
  1274. respItem, err := data.AddEdbData(source, edbCode)
  1275. if err != nil {
  1276. br.Msg = "获取失败"
  1277. br.ErrMsg = "获取失败,Err:" + err.Error()
  1278. return
  1279. }
  1280. if respItem.Ret != 200 {
  1281. br.Msg = "未搜索到该指标"
  1282. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1283. return
  1284. }
  1285. isAdd = true
  1286. }
  1287. //获取指标信息
  1288. eiasteoInfo, err := data_manage.GetBaseFromEiaSteoIndexByCode(edbCode)
  1289. if err != nil && err.Error() != utils.ErrNoRow() {
  1290. br.Msg = "获取失败"
  1291. br.ErrMsg = "获取钢联指标详情失败,Err:" + err.Error()
  1292. return
  1293. }
  1294. if eiasteoInfo != nil {
  1295. searchItem.Frequency = eiasteoInfo.Frequency
  1296. searchItem.Unit = eiasteoInfo.Unit
  1297. searchItem.EdbName = eiasteoInfo.IndexName
  1298. }
  1299. } else if source == utils.DATA_SOURCE_COM_TRADE { // un数据源
  1300. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
  1301. if err != nil && err.Error() != utils.ErrNoRow() {
  1302. br.Msg = "获取失败"
  1303. br.ErrMsg = "获取联合国商品贸易数据已存在信息失败,Err:" + err.Error()
  1304. return
  1305. }
  1306. if len(dataItems) > 0 {
  1307. searchItem.EdbCode = edbCode
  1308. item, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
  1309. if err != nil {
  1310. br.Msg = "获取失败"
  1311. br.ErrMsg = "获取联合国商品贸易数据日期信息失败,Err:" + err.Error()
  1312. return
  1313. }
  1314. searchItem.DataList = dataItems
  1315. searchItem.StartDate = item.MinDate
  1316. searchItem.EndDate = item.MaxDate
  1317. } else {
  1318. respItem, err := data.AddEdbData(source, edbCode)
  1319. if err != nil {
  1320. br.Msg = "获取失败"
  1321. br.ErrMsg = "获取失败,Err:" + err.Error()
  1322. return
  1323. }
  1324. if respItem.Ret != 200 {
  1325. br.Msg = "未搜索到该指标"
  1326. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1327. return
  1328. }
  1329. isAdd = true
  1330. }
  1331. //获取指标信息
  1332. eiasteoInfo, err := data_manage.GetComTradeIndex(edbCode)
  1333. if err != nil && err.Error() != utils.ErrNoRow() {
  1334. br.Msg = "获取失败"
  1335. br.ErrMsg = "获取钢联指标详情失败,Err:" + err.Error()
  1336. return
  1337. }
  1338. if eiasteoInfo != nil {
  1339. //eiasteoInfo.
  1340. if eiasteoInfo.Type <= 2 {
  1341. searchItem.Frequency = `年度`
  1342. } else {
  1343. searchItem.Frequency = `月度`
  1344. }
  1345. if eiasteoInfo.Type == 1 || eiasteoInfo.Type == 3 {
  1346. searchItem.Unit = "美元"
  1347. } else {
  1348. searchItem.Unit = "千克"
  1349. }
  1350. searchItem.EdbName = eiasteoInfo.Name
  1351. }
  1352. } else if source == utils.DATA_SOURCE_SCI { //卓创数据(红桃三)
  1353. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
  1354. if err != nil && err.Error() != utils.ErrNoRow() {
  1355. br.Msg = "获取失败"
  1356. br.ErrMsg = "获取SCI已存在信息失败,Err:" + err.Error()
  1357. return
  1358. }
  1359. fmt.Println("dataItems:", len(dataItems))
  1360. if len(dataItems) > 0 {
  1361. searchItem.EdbCode = edbCode
  1362. minDate, maxDate, err := data_manage.GetEdbDataSciMaxAndMinDate(edbCode)
  1363. if err != nil {
  1364. br.Msg = "获取失败"
  1365. br.ErrMsg = "获取SCI日期信息失败,Err:" + err.Error()
  1366. return
  1367. }
  1368. searchItem.DataList = dataItems
  1369. searchItem.StartDate = minDate
  1370. searchItem.EndDate = maxDate
  1371. } else {
  1372. //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
  1373. //searchItem, err = data_manage.GetEdbDataByYs(edbCode, startDate, endDate)
  1374. //if err != nil {
  1375. // br.Msg = "获取失败"
  1376. // br.ErrMsg = "获取失败,GetEdbDataByYs Err:" + err.Error()
  1377. // return
  1378. //}
  1379. //if searchItem.StartDate == "" {
  1380. // minDate, maxDate, _ := data_manage.GetEdbDataYsMaxAndMinDate(edbCode)
  1381. // searchItem.StartDate = minDate
  1382. // searchItem.EndDate = maxDate
  1383. //}
  1384. respItem, err := data.AddEdbData(source, edbCode)
  1385. if err != nil {
  1386. br.Msg = "获取失败"
  1387. br.ErrMsg = "获取失败,Err:" + err.Error()
  1388. return
  1389. }
  1390. if respItem.Ret != 200 {
  1391. br.Msg = "未搜索到该指标"
  1392. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1393. return
  1394. }
  1395. isAdd = true
  1396. }
  1397. //获取指标信息
  1398. smmInfo, err := data_manage.GetBaseFromSciIndexByIndexCode(edbCode)
  1399. if err != nil && err.Error() != utils.ErrNoRow() {
  1400. br.Msg = "获取失败"
  1401. br.ErrMsg = "获取Sci指标详情失败,Err:" + err.Error()
  1402. return
  1403. }
  1404. if smmInfo != nil {
  1405. searchItem.Frequency = smmInfo.Frequency
  1406. searchItem.Unit = smmInfo.Unit
  1407. searchItem.EdbName = smmInfo.IndexName
  1408. }
  1409. } else if source == utils.DATA_SOURCE_BAIINFO { //百川盈孚
  1410. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
  1411. if err != nil && err.Error() != utils.ErrNoRow() {
  1412. br.Msg = "获取失败"
  1413. br.ErrMsg = "获取BAIINFO已存在信息失败,Err:" + err.Error()
  1414. return
  1415. }
  1416. fmt.Println("dataItems:", len(dataItems))
  1417. if len(dataItems) > 0 {
  1418. searchItem.EdbCode = edbCode
  1419. minDate, maxDate, err := data_manage.GetEdbDataBaiinfoMaxAndMinDate(edbCode)
  1420. if err != nil {
  1421. br.Msg = "获取失败"
  1422. br.ErrMsg = "获取BAIINFO日期信息失败,Err:" + err.Error()
  1423. return
  1424. }
  1425. searchItem.DataList = dataItems
  1426. searchItem.StartDate = minDate
  1427. searchItem.EndDate = maxDate
  1428. } else {
  1429. //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
  1430. //searchItem, err = data_manage.GetEdbDataByYs(edbCode, startDate, endDate)
  1431. //if err != nil {
  1432. // br.Msg = "获取失败"
  1433. // br.ErrMsg = "获取失败,GetEdbDataByYs Err:" + err.Error()
  1434. // return
  1435. //}
  1436. //if searchItem.StartDate == "" {
  1437. // minDate, maxDate, _ := data_manage.GetEdbDataYsMaxAndMinDate(edbCode)
  1438. // searchItem.StartDate = minDate
  1439. // searchItem.EndDate = maxDate
  1440. //}
  1441. respItem, err := data.AddEdbData(source, edbCode)
  1442. if err != nil {
  1443. br.Msg = "获取失败"
  1444. br.ErrMsg = "获取失败,Err:" + err.Error()
  1445. return
  1446. }
  1447. if respItem.Ret != 200 {
  1448. br.Msg = "未搜索到该指标"
  1449. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1450. return
  1451. }
  1452. isAdd = true
  1453. }
  1454. //获取指标信息
  1455. baiInfo, err := data_manage.GetBaseFromBaiinfoIndexByIndexCode(edbCode)
  1456. if err != nil && err.Error() != utils.ErrNoRow() {
  1457. br.Msg = "获取失败"
  1458. br.ErrMsg = "获取Baiinfo指标详情失败,Err:" + err.Error()
  1459. return
  1460. }
  1461. if baiInfo != nil {
  1462. searchItem.Frequency = baiInfo.Frequency
  1463. searchItem.Unit = baiInfo.Unit
  1464. searchItem.EdbName = baiInfo.IndexName
  1465. }
  1466. } else if source == utils.DATA_SOURCE_NATIONAL_STATISTICS { // 国家统计局
  1467. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
  1468. if err != nil && err.Error() != utils.ErrNoRow() {
  1469. br.Msg = "获取失败"
  1470. br.ErrMsg = "获取国家统计局已存在信息失败,Err:" + err.Error()
  1471. return
  1472. }
  1473. if len(dataItems) > 0 {
  1474. searchItem.EdbCode = edbCode
  1475. item, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
  1476. if err != nil {
  1477. br.Msg = "获取失败"
  1478. br.ErrMsg = "获取国家统计局日期信息失败,Err:" + err.Error()
  1479. return
  1480. }
  1481. searchItem.DataList = dataItems
  1482. searchItem.StartDate = item.MinDate
  1483. searchItem.EndDate = item.MaxDate
  1484. } else {
  1485. respItem, err := data.AddEdbData(source, edbCode)
  1486. if err != nil {
  1487. br.Msg = "获取失败"
  1488. br.ErrMsg = "获取失败,Err:" + err.Error()
  1489. return
  1490. }
  1491. if respItem.Ret != 200 {
  1492. br.Msg = "未搜索到该指标"
  1493. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1494. return
  1495. }
  1496. isAdd = true
  1497. }
  1498. //获取指标信息
  1499. nationalInfo, err := data_manage.GetBaseFromNationalStatisticsIndexByIndexCode(edbCode)
  1500. if err != nil && err.Error() != utils.ErrNoRow() {
  1501. br.Msg = "获取失败"
  1502. br.ErrMsg = "获取国家统计局详情失败,Err:" + err.Error()
  1503. return
  1504. }
  1505. if nationalInfo != nil {
  1506. searchItem.Frequency = nationalInfo.Frequency
  1507. searchItem.Unit = nationalInfo.Unit
  1508. searchItem.EdbName = fmt.Sprintf("%s%s", nationalInfo.Reg, nationalInfo.IndexName)
  1509. }
  1510. } else if source == utils.DATA_SOURCE_FUBAO { //数宝
  1511. dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_FUBAO, utils.EDB_DATA_LIMIT)
  1512. if err != nil && err.Error() != utils.ErrNoRow() {
  1513. br.Msg = "获取失败"
  1514. br.ErrMsg = "获取Fubao已存在信息失败,Err:" + err.Error()
  1515. return
  1516. }
  1517. fmt.Println("fubao len:", len(dataItems))
  1518. if len(dataItems) > 0 {
  1519. fmt.Println("fubao data exist")
  1520. searchItem.EdbCode = edbCode
  1521. minDate, maxDate, err := data_manage.GetEdbDataFubaoMaxOrMinDate(edbCode)
  1522. if err != nil {
  1523. br.Msg = "获取失败"
  1524. br.ErrMsg = "获取Ths日期信息失败,Err:" + err.Error()
  1525. return
  1526. }
  1527. searchItem.DataList = dataItems
  1528. searchItem.StartDate = minDate
  1529. searchItem.EndDate = maxDate
  1530. } else {
  1531. respItem, err := data.AddEdbData(source, edbCode)
  1532. if err != nil {
  1533. br.Msg = "获取失败," + respItem.Msg
  1534. br.ErrMsg = "获取失败,Err:" + err.Error()
  1535. return
  1536. }
  1537. if respItem.Ret != 200 {
  1538. br.Msg = "未搜索到该指标," + respItem.Msg
  1539. br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
  1540. return
  1541. }
  1542. isAdd = true
  1543. }
  1544. } else {
  1545. // 代码中没有的来源那么从edb_source中找是否有对应的
  1546. sourceItem := data_manage.EdbSourceIdMap[source]
  1547. if sourceItem == nil {
  1548. br.Msg = "无效指标来源"
  1549. return
  1550. }
  1551. // 获取指标数据
  1552. dataList, e := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
  1553. if e != nil {
  1554. br.Msg = "获取失败"
  1555. br.ErrMsg = "获取指标数据失败, Err: " + e.Error()
  1556. return
  1557. }
  1558. if len(dataList) > 0 {
  1559. searchItem.EdbCode = edbCode
  1560. searchItem.DataList = dataList
  1561. // 获取最大最小值
  1562. edbInfoMaxAndMinInfo, e := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
  1563. if e != nil && e.Error() != utils.ErrNoRow() {
  1564. br.Msg = "获取失败"
  1565. br.ErrMsg = "获取数据失败, GetEdbInfoMaxAndMinInfo Err:" + e.Error()
  1566. return
  1567. }
  1568. if edbInfoMaxAndMinInfo != nil {
  1569. searchItem.StartDate = edbInfoMaxAndMinInfo.MinDate
  1570. searchItem.EndDate = edbInfoMaxAndMinInfo.MaxDate
  1571. }
  1572. } else {
  1573. // 新增指标数据
  1574. addRes, e := data.AddEdbData(source, edbCode)
  1575. if e != nil {
  1576. br.Msg = "获取失败"
  1577. br.ErrMsg = "获取失败,Err:" + e.Error()
  1578. return
  1579. }
  1580. if addRes == nil {
  1581. br.Msg = "获取失败"
  1582. br.ErrMsg = "新增指标数据失败, addRes nil"
  1583. return
  1584. }
  1585. if addRes.Ret != 200 {
  1586. br.Msg = "未搜索到该指标, " + addRes.Msg
  1587. //br.ErrMsg = addRes.ErrMsg + ";EdbCode:" + edbCode
  1588. br.Success = true
  1589. return
  1590. }
  1591. isAdd = true
  1592. }
  1593. // 指标来源于桥接服务: 桥接服务获取指标取频度信息等
  1594. if sourceItem.BridgeFlag != "" {
  1595. bridgeOb := data.InitBridgeOB(sourceItem.BridgeFlag)
  1596. if bridgeOb != nil {
  1597. var r data.GetIndexFromBridgeReq
  1598. r.IndexCode = edbCode
  1599. r.Source = sourceItem.EdbSourceId
  1600. r.SourceExtend = sourceItem.SourceExtend
  1601. r.IndexCodeRequired = sourceItem.EdbCodeRequired
  1602. bridgeIndex, e := bridgeOb.GetIndex(r)
  1603. if e != nil {
  1604. br.Msg = "获取失败"
  1605. br.ErrMsg = "桥接服务获取指标信息失败, Err: " + e.Error()
  1606. return
  1607. }
  1608. searchItem.EdbName = bridgeIndex.IndexName
  1609. searchItem.Frequency = bridgeIndex.Frequency
  1610. searchItem.Unit = bridgeIndex.Unit
  1611. }
  1612. }
  1613. }
  1614. if isAdd {
  1615. dataList, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
  1616. if err != nil && err.Error() != utils.ErrNoRow() {
  1617. br.Msg = "获取失败"
  1618. br.ErrMsg = "获取数据失败,GetEdbDataAllByEdbCode Err:" + err.Error()
  1619. return
  1620. }
  1621. searchItem.DataList = dataList
  1622. edbInfoMaxAndMinInfo, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
  1623. if err != nil && err.Error() != utils.ErrNoRow() {
  1624. br.Msg = "获取失败"
  1625. br.ErrMsg = "获取数据失败,GetEdbInfoMaxAndMinInfo Err:" + err.Error()
  1626. return
  1627. }
  1628. searchItem.EdbCode = edbCode
  1629. searchItem.DataList = dataList
  1630. if edbInfoMaxAndMinInfo != nil {
  1631. searchItem.StartDate = edbInfoMaxAndMinInfo.MinDate
  1632. searchItem.EndDate = edbInfoMaxAndMinInfo.MaxDate
  1633. }
  1634. //edb指标信息
  1635. edbInfoItem, err := data_manage.GetEdbInfoByEdbCode(source, edbCode)
  1636. if edbInfoItem != nil {
  1637. searchItem.EdbName = edbInfoItem.EdbName
  1638. }
  1639. }
  1640. resp.Status = 2
  1641. resp.SearchItem = searchItem
  1642. }
  1643. //如果不在指标库中,且不是新增
  1644. if !isInEdb && !isAdd {
  1645. if resp.SearchItem.DataList == nil || len(resp.SearchItem.DataList) <= 0 {
  1646. br.Msg = "目标指标无有效值,请重新搜索"
  1647. br.Data = resp
  1648. return
  1649. }
  1650. }
  1651. br.Ret = 200
  1652. br.Success = true
  1653. br.Msg = "获取成功"
  1654. br.Data = resp
  1655. }
  1656. // EdbInfoList
  1657. // @Title 指标列表接口
  1658. // @Description 指标列表接口
  1659. // @Param PageSize query int true "每页数据条数"
  1660. // @Param CurrentIndex query int true "当前页页码,从1开始"
  1661. // @Param EdbInfoId query int true "指标id"
  1662. // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
  1663. // @Success 200 {object} data_manage.EdbInfoListResp
  1664. // @router /edb_info/list [get]
  1665. func (this *EdbInfoController) EdbInfoList() {
  1666. br := new(models.BaseResponse).Init()
  1667. defer func() {
  1668. this.Data["json"] = br
  1669. this.ServeJSON()
  1670. }()
  1671. edbInfoId, _ := this.GetInt("EdbInfoId")
  1672. keyWord := this.GetString("KeyWord")
  1673. pageSize, _ := this.GetInt("PageSize")
  1674. currentIndex, _ := this.GetInt("CurrentIndex")
  1675. var total int
  1676. page := paging.GetPaging(currentIndex, pageSize, total)
  1677. var startSize int
  1678. if pageSize <= 0 {
  1679. pageSize = utils.PageSize20
  1680. }
  1681. if currentIndex <= 0 {
  1682. currentIndex = 1
  1683. }
  1684. startSize = paging.StartIndex(currentIndex, pageSize)
  1685. var condition string
  1686. var pars []interface{}
  1687. //if edbInfoId <= 0 && keyWord == "" {
  1688. // br.Msg = "参数错误"
  1689. // return
  1690. //}
  1691. // 指标类型,0:普通指标,1:预测指标
  1692. condition += " AND edb_info_type=? "
  1693. pars = append(pars, 0)
  1694. if edbInfoId > 0 {
  1695. condition += " AND edb_info_id=? "
  1696. pars = append(pars, edbInfoId)
  1697. // 获取当前账号的不可见指标配置
  1698. obj := data_manage.EdbInfoNoPermissionAdmin{}
  1699. conf, err := obj.GetByEdbInfoIdAndAdminId(this.SysUser.AdminId, edbInfoId)
  1700. if err != nil && err.Error() != utils.ErrNoRow() {
  1701. br.Msg = "获取失败"
  1702. br.ErrMsg = "获取当前账号的不可见指标配置失败,err:" + err.Error()
  1703. return
  1704. }
  1705. if conf != nil {
  1706. br.Msg = "无权限,请联系管理员"
  1707. br.IsSendEmail = false
  1708. return
  1709. }
  1710. }
  1711. if keyWord != "" {
  1712. condition += ` AND ( edb_code LIKE '%` + keyWord + `%' OR edb_name LIKE '%` + keyWord + `%' )`
  1713. //pars = append(pars, keyWord)
  1714. //pars = append(pars, keyWord)
  1715. }
  1716. resp := new(data_manage.EdbInfoListResp)
  1717. if condition == "" {
  1718. item := new(data_manage.EdbInfoList)
  1719. resp.Paging = page
  1720. resp.Item = item
  1721. br.Ret = 200
  1722. br.Success = true
  1723. br.Msg = "获取成功"
  1724. return
  1725. }
  1726. //获取指标信息
  1727. edbInfoItem, err := data_manage.GetEdbInfoByCondition(condition, pars)
  1728. if err != nil && err.Error() != utils.ErrNoRow() {
  1729. br.Success = true
  1730. br.Msg = "获取指标信息失败"
  1731. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  1732. return
  1733. }
  1734. if edbInfoItem == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
  1735. item := new(data_manage.EdbInfoList)
  1736. resp.Paging = page
  1737. resp.Item = item
  1738. br.Ret = 200
  1739. br.Success = true
  1740. br.Msg = "获取成功"
  1741. return
  1742. }
  1743. //获取英文频度
  1744. edbInfoItem.FrequencyEn = data.GetFrequencyEn(edbInfoItem.Frequency)
  1745. //获取指标数据
  1746. var dataCondition string
  1747. var dataPars []interface{}
  1748. dataCondition += ` AND edb_info_id=? `
  1749. dataPars = append(dataPars, edbInfoItem.EdbInfoId)
  1750. dataCount, err := data_manage.GetEdbDataCountByCondition(dataCondition, dataPars, edbInfoItem.Source)
  1751. if err != nil && err.Error() != utils.ErrNoRow() {
  1752. br.Msg = "获取指标信息失败"
  1753. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  1754. return
  1755. }
  1756. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  1757. dataList, err := data_manage.GetEdbDataListByCondition(dataCondition, dataPars, edbInfoItem.Source, pageSize, startSize)
  1758. if err != nil {
  1759. br.Msg = "获取指标信息失败"
  1760. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  1761. return
  1762. }
  1763. edbInfoItem.DataList = dataList
  1764. // 获取指标插入配置
  1765. {
  1766. edbDataInsertConfig, err := data_manage.GetEdbDataInsertConfigByEdbId(edbInfoId)
  1767. if err != nil && err.Error() != utils.ErrNoRow() {
  1768. br.Msg = "获取指标信息失败"
  1769. br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
  1770. return
  1771. }
  1772. if edbDataInsertConfig != nil {
  1773. edbInfoItem.DataInsertConfig.Date = edbDataInsertConfig.Date.Format(utils.FormatDate)
  1774. edbInfoItem.DataInsertConfig.RealDate = edbDataInsertConfig.RealDate.Format(utils.FormatDate)
  1775. edbInfoItem.DataInsertConfig.Value = edbDataInsertConfig.Value
  1776. }
  1777. }
  1778. // 按钮校验
  1779. button := data.GetEdbOpButton(this.SysUser, edbInfoItem.SysUserId, edbInfoItem.EdbType, edbInfoItem.EdbInfoType)
  1780. button.AddButton = false
  1781. edbInfoItem.Button = button
  1782. //是否展示英文标识
  1783. edbInfoItem.IsEnEdb = data.CheckIsEnEdb(edbInfoItem.EdbNameEn, edbInfoItem.Unit, edbInfoItem.UnitEn)
  1784. //查询目录
  1785. classifyList, err, errMsg := data.GetFullClassifyByClassifyId(edbInfoItem.ClassifyId)
  1786. if err != nil {
  1787. br.Msg = err.Error()
  1788. br.ErrMsg = errMsg
  1789. return
  1790. }
  1791. resp.Paging = page
  1792. resp.Item = edbInfoItem
  1793. resp.ClassifyList = classifyList
  1794. br.Ret = 200
  1795. br.Success = true
  1796. br.Msg = "获取成功"
  1797. br.Data = resp
  1798. }
  1799. // EdbInfoAdd
  1800. // @Title 新增指标接口
  1801. // @Description 新增指标接口
  1802. // @Param request body data_manage.AddEdbInfoReq true "type json string"
  1803. // @Success Ret=200 保存成功
  1804. // @router /edb_info/add [post]
  1805. func (this *EdbInfoController) EdbInfoAdd() {
  1806. br := new(models.BaseResponse).Init()
  1807. defer func() {
  1808. this.Data["json"] = br
  1809. this.ServeJSON()
  1810. }()
  1811. sysUser := this.SysUser
  1812. if sysUser == nil {
  1813. br.Msg = "请登录"
  1814. br.ErrMsg = "请登录,SysUser Is Empty"
  1815. br.Ret = 408
  1816. return
  1817. }
  1818. deleteCache := true
  1819. cacheKey := "CACHE_EDB_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
  1820. defer func() {
  1821. if deleteCache {
  1822. utils.Rc.Delete(cacheKey)
  1823. }
  1824. }()
  1825. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  1826. deleteCache = false
  1827. br.Msg = "系统处理中,请稍后重试!"
  1828. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  1829. return
  1830. }
  1831. var req data_manage.AddEdbInfoReq
  1832. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1833. if err != nil {
  1834. br.Msg = "参数解析异常!"
  1835. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1836. return
  1837. }
  1838. source := req.Source
  1839. if source <= 0 {
  1840. br.Msg = "无效的数据来源"
  1841. return
  1842. }
  1843. req.EdbName = strings.Trim(req.EdbName, " ")
  1844. req.EdbCode = strings.Trim(req.EdbCode, " ")
  1845. if req.EdbCode == "" {
  1846. br.Msg = "指标ID不能为空"
  1847. return
  1848. }
  1849. if req.EdbName == "" {
  1850. br.Msg = "指标名称不能为空"
  1851. return
  1852. }
  1853. if req.Frequency == "" {
  1854. br.Msg = "频率不能为空"
  1855. return
  1856. }
  1857. if req.Unit == "" {
  1858. br.Msg = "单位不能为空"
  1859. return
  1860. }
  1861. if req.ClassifyId <= 0 {
  1862. br.Msg = "请选择分类"
  1863. return
  1864. }
  1865. //if req.StartDate == "" || req.EndDate == "" {
  1866. // br.Msg = "日期不能为空"
  1867. // return
  1868. //}
  1869. // 兼容钢联与钢联化工数据
  1870. if source == utils.DATA_SOURCE_GL {
  1871. // 如果是钢联的话,那么就先判断是不是存在钢联化工
  1872. tmpInfo, err := data_manage.GetBaseFromMysteelChemicalIndexByCode(req.EdbCode)
  1873. if err != nil {
  1874. if err.Error() != utils.ErrNoRow() {
  1875. br.Msg = "获取失败"
  1876. br.ErrMsg = "获取失败,Err:" + err.Error()
  1877. return
  1878. }
  1879. }
  1880. if tmpInfo != nil {
  1881. source = utils.DATA_SOURCE_MYSTEEL_CHEMICAL
  1882. req.Source = utils.DATA_SOURCE_MYSTEEL_CHEMICAL
  1883. }
  1884. }
  1885. // 指标入库
  1886. edbInfo, err, errMsg, isSendEmail := data.EdbInfoAdd(source, req.ClassifyId, req.EdbCode, req.EdbName, req.Frequency, req.Unit, req.StartDate, req.EndDate, sysUser.AdminId, sysUser.RealName)
  1887. if err != nil {
  1888. br.Msg = "保存失败"
  1889. if errMsg != `` {
  1890. br.Msg = errMsg
  1891. }
  1892. br.ErrMsg = err.Error()
  1893. br.IsSendEmail = isSendEmail
  1894. return
  1895. }
  1896. // 试用平台更新用户累计新增指标数
  1897. adminItem, e := system.GetSysAdminById(sysUser.AdminId)
  1898. if e != nil {
  1899. br.Msg = "操作失败"
  1900. br.ErrMsg = "获取系统用户数据失败,Err:" + err.Error()
  1901. return
  1902. }
  1903. if utils.BusinessCode == utils.BusinessCodeSandbox && adminItem.DepartmentName == "ETA试用客户" {
  1904. go func() {
  1905. var r etaTrialService.EtaTrialUserReq
  1906. r.Mobile = adminItem.Mobile
  1907. _, _ = etaTrialService.UpdateUserIndexNum(r)
  1908. }()
  1909. }
  1910. //新增操作日志
  1911. {
  1912. edbLog := new(data_manage.EdbInfoLog)
  1913. edbLog.EdbInfoId = edbInfo.EdbInfoId
  1914. edbLog.SourceName = edbInfo.SourceName
  1915. edbLog.Source = edbInfo.Source
  1916. edbLog.EdbCode = edbInfo.EdbCode
  1917. edbLog.EdbName = edbInfo.EdbName
  1918. edbLog.ClassifyId = edbInfo.ClassifyId
  1919. edbLog.SysUserId = sysUser.AdminId
  1920. edbLog.SysUserRealName = sysUser.RealName
  1921. edbLog.CreateTime = time.Now()
  1922. edbLog.Content = string(this.Ctx.Input.RequestBody)
  1923. edbLog.Status = "新增指标"
  1924. edbLog.Method = this.Ctx.Input.URI()
  1925. go data_manage.AddEdbInfoLog(edbLog)
  1926. }
  1927. resp := new(data_manage.AddEdbInfoResp)
  1928. resp.EdbInfoId = edbInfo.EdbInfoId
  1929. resp.UniqueCode = edbInfo.UniqueCode
  1930. br.Ret = 200
  1931. br.Success = true
  1932. br.Msg = "保存成功"
  1933. br.Data = resp
  1934. br.IsAddLog = true
  1935. }
  1936. // EdbInfoEdit
  1937. // @Title 编辑指标接口
  1938. // @Description 编辑指标接口
  1939. // @Success 200 {object} data_manage.EditEdbInfoReq
  1940. // @router /edb_info/edit [post]
  1941. func (this *EdbInfoController) EdbInfoEdit() {
  1942. br := new(models.BaseResponse).Init()
  1943. defer func() {
  1944. this.Data["json"] = br
  1945. this.ServeJSON()
  1946. }()
  1947. sysUser := this.SysUser
  1948. if sysUser == nil {
  1949. br.Msg = "请登录"
  1950. br.ErrMsg = "请登录,SysUser Is Empty"
  1951. br.Ret = 408
  1952. return
  1953. }
  1954. var req data_manage.EditEdbInfoReq
  1955. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1956. if err != nil {
  1957. br.Msg = "参数解析异常!"
  1958. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1959. return
  1960. }
  1961. req.EdbName = strings.Trim(req.EdbName, " ")
  1962. if req.EdbInfoId <= 0 {
  1963. br.Msg = "参数错误"
  1964. br.ErrMsg = "指标id小于等于0"
  1965. return
  1966. }
  1967. if req.EdbName == "" {
  1968. br.Msg = "指标名称不能为空"
  1969. return
  1970. }
  1971. if req.Frequency == "" {
  1972. br.Msg = "频率不能为空"
  1973. return
  1974. }
  1975. if req.Unit == "" {
  1976. br.Msg = "单位不能为空"
  1977. return
  1978. }
  1979. if req.ClassifyId <= 0 {
  1980. br.Msg = "请选择分类"
  1981. return
  1982. }
  1983. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  1984. if err != nil {
  1985. br.Msg = "修改失败"
  1986. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  1987. return
  1988. }
  1989. // 编辑权限校验
  1990. button := data.GetEdbOpButton(this.SysUser, edbInfo.SysUserId, edbInfo.EdbType, edbInfo.EdbInfoType)
  1991. if !button.OpButton {
  1992. br.Msg = "无权限操作"
  1993. br.IsSendEmail = false
  1994. return
  1995. }
  1996. //判断指标名称是否存在
  1997. var condition string
  1998. var pars []interface{}
  1999. condition += " AND edb_info_id<>? "
  2000. pars = append(pars, req.EdbInfoId)
  2001. //condition += " AND source=? "
  2002. //pars = append(pars, edbInfo.Source)
  2003. condition += " AND edb_name=? "
  2004. pars = append(pars, req.EdbName)
  2005. count, err := data_manage.GetEdbInfoCountByCondition(condition, pars)
  2006. if err != nil {
  2007. br.Msg = "判断指标名称是否存在失败"
  2008. br.ErrMsg = "判断指标名称是否存在失败,Err:" + err.Error()
  2009. return
  2010. }
  2011. if count > 0 {
  2012. br.Msg = "指标名称已存在,请重新填写"
  2013. br.ErrMsg = "指标名称已存在,请重新填写"
  2014. br.IsSendEmail = false
  2015. return
  2016. }
  2017. err = data_manage.ModifyEdbInfo(&req)
  2018. if err != nil {
  2019. br.Msg = "保存失败"
  2020. br.ErrMsg = "修改失败,Err:" + err.Error()
  2021. return
  2022. }
  2023. //处理同名指标
  2024. //{
  2025. // edbNameList, err := data_manage.GetEdbInfoByName(req.EdbName)
  2026. // if err != nil {
  2027. // br.Msg = "保存失败"
  2028. // br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2029. // return
  2030. // }
  2031. // if len(edbNameList) >= 2 {
  2032. // for _, v := range edbNameList {
  2033. // edbName := v.EdbName + "(" + v.SourceName + ")"
  2034. // err = data_manage.ModifyEdbInfoNameSource(edbName, v.EdbInfoId)
  2035. // if err != nil {
  2036. // br.Msg = "保存失败"
  2037. // br.ErrMsg = "修改指标名称失败,Err:" + err.Error()
  2038. // return
  2039. // }
  2040. // }
  2041. // }
  2042. //}
  2043. //新增操作日志
  2044. {
  2045. edbLog := new(data_manage.EdbInfoLog)
  2046. edbLog.EdbInfoId = edbInfo.EdbInfoId
  2047. edbLog.SourceName = edbInfo.SourceName
  2048. edbLog.Source = edbInfo.Source
  2049. edbLog.EdbCode = edbInfo.EdbCode
  2050. edbLog.EdbName = edbInfo.EdbName
  2051. edbLog.ClassifyId = edbInfo.ClassifyId
  2052. edbLog.SysUserId = sysUser.AdminId
  2053. edbLog.SysUserRealName = sysUser.RealName
  2054. edbLog.CreateTime = time.Now()
  2055. edbLog.Content = string(this.Ctx.Input.RequestBody)
  2056. edbLog.Status = "编辑指标"
  2057. edbLog.Method = this.Ctx.Input.URI()
  2058. go data_manage.AddEdbInfoLog(edbLog)
  2059. }
  2060. //添加es
  2061. data.AddOrEditEdbInfoToEs(req.EdbInfoId)
  2062. // 修改关联的预测指标基础信息
  2063. go data.ModifyPredictEdbBaseInfoBySourceEdb(edbInfo)
  2064. // 添加钢联指标更新日志
  2065. if edbInfo.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
  2066. go data_stat.AddEdbInfoUpdateLog(req.EdbInfoId, 1, "", sysUser)
  2067. }
  2068. br.Ret = 200
  2069. br.Success = true
  2070. br.Msg = "保存成功"
  2071. br.IsAddLog = true
  2072. }
  2073. // EdbEnInfoEdit
  2074. // @Title 编辑指标英文信息接口
  2075. // @Description 编辑指标英文信息接口
  2076. // @Success 200 {object} data_manage.EditEdbEnInfoReq
  2077. // @router /edb_info/en/edit [post]
  2078. func (this *EdbInfoController) EdbEnInfoEdit() {
  2079. br := new(models.BaseResponse).Init()
  2080. defer func() {
  2081. this.Data["json"] = br
  2082. this.ServeJSON()
  2083. }()
  2084. sysUser := this.SysUser
  2085. if sysUser == nil {
  2086. br.Msg = "请登录"
  2087. br.ErrMsg = "请登录,SysUser Is Empty"
  2088. br.Ret = 408
  2089. return
  2090. }
  2091. var req data_manage.EditEdbEnInfoReq
  2092. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2093. if err != nil {
  2094. br.Msg = "参数解析异常!"
  2095. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2096. return
  2097. }
  2098. req.EdbNameEn = strings.Trim(req.EdbNameEn, " ")
  2099. req.UnitEn = strings.Trim(req.UnitEn, " ")
  2100. if req.EdbInfoId <= 0 {
  2101. br.Msg = "参数错误"
  2102. br.ErrMsg = "指标id小于等于0"
  2103. return
  2104. }
  2105. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  2106. if err != nil {
  2107. br.Msg = "获取指标信息失败"
  2108. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2109. return
  2110. }
  2111. if req.EdbNameEn != "" {
  2112. //判断指标名称是否存在
  2113. var condition string
  2114. var pars []interface{}
  2115. condition += " AND edb_info_id<>? "
  2116. pars = append(pars, req.EdbInfoId)
  2117. /*condition += " AND source=? "
  2118. pars = append(pars, edbInfo.Source)*/
  2119. condition += " AND edb_name_en=? "
  2120. pars = append(pars, req.EdbNameEn)
  2121. edbExist, err := data_manage.GetEdbInfoByCondition(condition, pars)
  2122. if err != nil {
  2123. if err.Error() != utils.ErrNoRow() {
  2124. br.Msg = "判断英文指标名称是否存在失败"
  2125. br.ErrMsg = "判断英文指标名称是否存在失败,Err:" + err.Error()
  2126. return
  2127. }
  2128. }
  2129. if err == nil && edbExist.EdbInfoId > 0 {
  2130. br.Msg = edbExist.EdbName + ":" + req.EdbNameEn + "指标名称已存在"
  2131. br.ErrMsg = "英文指标名称已存在,请重新填写"
  2132. br.IsSendEmail = false
  2133. return
  2134. }
  2135. }
  2136. err = data_manage.ModifyEdbEnInfo(&req)
  2137. if err != nil {
  2138. br.Msg = "保存失败"
  2139. br.ErrMsg = "修改失败,Err:" + err.Error()
  2140. return
  2141. }
  2142. //新增操作日志
  2143. {
  2144. edbLog := new(data_manage.EdbInfoLog)
  2145. edbLog.EdbInfoId = edbInfo.EdbInfoId
  2146. edbLog.SourceName = edbInfo.SourceName
  2147. edbLog.Source = edbInfo.Source
  2148. edbLog.EdbCode = edbInfo.EdbCode
  2149. edbLog.EdbName = edbInfo.EdbName
  2150. edbLog.ClassifyId = edbInfo.ClassifyId
  2151. edbLog.SysUserId = sysUser.AdminId
  2152. edbLog.SysUserRealName = sysUser.RealName
  2153. edbLog.CreateTime = time.Now()
  2154. edbLog.Content = string(this.Ctx.Input.RequestBody)
  2155. edbLog.Status = "编辑指标英文信息"
  2156. edbLog.Method = this.Ctx.Input.URI()
  2157. go data_manage.AddEdbInfoLog(edbLog)
  2158. }
  2159. //添加es
  2160. data.AddOrEditEdbInfoToEs(req.EdbInfoId)
  2161. // 修改关联的预测指标基础信息
  2162. if edbInfo.EdbInfoType == 0 {
  2163. go data.ModifyPredictEdbEnBaseInfoBySourceEdb(edbInfo)
  2164. }
  2165. br.Ret = 200
  2166. br.Success = true
  2167. br.Msg = "保存成功"
  2168. br.IsAddLog = true
  2169. }
  2170. // EdbInfoNewest
  2171. // @Title 获取最新指标接口
  2172. // @Description 获取最新指标接口
  2173. // @Success 200 {object} data_manage.EdbInfoList
  2174. // @router /edb_info/newest [get]
  2175. func (this *EdbInfoController) EdbInfoNewest() {
  2176. br := new(models.BaseResponse).Init()
  2177. defer func() {
  2178. this.Data["json"] = br
  2179. this.ServeJSON()
  2180. }()
  2181. item, err := data_manage.GetEdbInfoByNewest()
  2182. if err != nil && err.Error() != utils.ErrNoRow() {
  2183. br.Msg = "获取最新指标失败"
  2184. br.ErrMsg = "获取最新指标失败,Err:" + err.Error()
  2185. return
  2186. }
  2187. br.Ret = 200
  2188. br.Success = true
  2189. br.Msg = "获取成功"
  2190. br.Data = item
  2191. }
  2192. // EdbInfoRefresh
  2193. // @Title 指标刷新接口
  2194. // @Description 指标刷新接口
  2195. // @Param EdbInfoId query int true "指标id"
  2196. // @Success Ret=200 刷新成功
  2197. // @router /edb_info/refresh [get]
  2198. func (this *EdbInfoController) EdbInfoRefresh() {
  2199. br := new(models.BaseResponse).Init()
  2200. defer func() {
  2201. this.Data["json"] = br
  2202. this.ServeJSON()
  2203. }()
  2204. sysUser := this.SysUser
  2205. if sysUser == nil {
  2206. br.Msg = "请登录"
  2207. br.ErrMsg = "请登录,SysUser Is Empty"
  2208. br.Ret = 408
  2209. return
  2210. }
  2211. edbInfoId, _ := this.GetInt("EdbInfoId")
  2212. if edbInfoId <= 0 {
  2213. br.Msg = "参数错误"
  2214. br.ErrMsg = "参数错误"
  2215. return
  2216. }
  2217. _, err := data_manage.GetEdbInfoById(edbInfoId)
  2218. if err != nil {
  2219. if err.Error() == utils.ErrNoRow() {
  2220. br.Msg = "数据已被删除,请刷新页面"
  2221. br.ErrMsg = "数据已被删除,请刷新页面,edbInfoId:" + strconv.Itoa(edbInfoId)
  2222. return
  2223. }
  2224. br.Msg = "刷新失败"
  2225. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2226. return
  2227. }
  2228. err, isAsync := data.EdbInfoRefreshAllFromBaseV2(edbInfoId, false)
  2229. if err != nil {
  2230. br.Msg = "刷新失败"
  2231. br.ErrMsg = "刷新指标失败,EdbInfoRefresh Err:" + err.Error()
  2232. return
  2233. }
  2234. br.Ret = 200
  2235. br.Msg = "刷新成功"
  2236. if isAsync {
  2237. br.Msg = "该指标关联指标较多,请10分钟后刷新页面查看最新数据"
  2238. }
  2239. br.Success = true
  2240. br.IsAddLog = true
  2241. }
  2242. // EdbInfoMove
  2243. // @Title 移动指标接口
  2244. // @Description 移动指标接口
  2245. // @Success 200 {object} data_manage.MoveEdbInfoReq
  2246. // @router /edb_info/move [post]
  2247. func (this *EdbInfoController) EdbInfoMove() {
  2248. br := new(models.BaseResponse).Init()
  2249. defer func() {
  2250. this.Data["json"] = br
  2251. this.ServeJSON()
  2252. }()
  2253. sysUser := this.SysUser
  2254. if sysUser == nil {
  2255. br.Msg = "请登录"
  2256. br.ErrMsg = "请登录,SysUser Is Empty"
  2257. br.Ret = 408
  2258. return
  2259. }
  2260. var req data_manage.MoveEdbInfoReq
  2261. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2262. if err != nil {
  2263. br.Msg = "参数解析异常!"
  2264. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2265. return
  2266. }
  2267. if req.EdbInfoId <= 0 {
  2268. br.Msg = "参数错误"
  2269. br.ErrMsg = "指标id小于等于0"
  2270. return
  2271. }
  2272. if req.ClassifyId <= 0 {
  2273. br.Msg = "请选择分类"
  2274. return
  2275. }
  2276. //判断分类是否存在
  2277. count, _ := data_manage.GetEdbClassifyCountById(req.ClassifyId)
  2278. if count <= 0 {
  2279. br.Msg = "分类已被删除,不可移动,请刷新页面"
  2280. return
  2281. }
  2282. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  2283. if err != nil {
  2284. br.Msg = "移动失败"
  2285. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2286. return
  2287. }
  2288. // 移动权限校验
  2289. button := data.GetEdbOpButton(this.SysUser, edbInfo.SysUserId, edbInfo.EdbType, edbInfo.EdbInfoType)
  2290. if !button.MoveButton {
  2291. br.Msg = "无权限操作"
  2292. br.IsSendEmail = false
  2293. return
  2294. }
  2295. //如果改变了分类,那么移动该指标数据
  2296. if edbInfo.ClassifyId != req.ClassifyId {
  2297. err = data_manage.MoveEdbInfo(req.EdbInfoId, req.ClassifyId)
  2298. if err != nil {
  2299. br.Msg = "移动失败"
  2300. br.ErrMsg = "移动指标失败,Err:" + err.Error()
  2301. return
  2302. }
  2303. }
  2304. updateCol := make([]string, 0)
  2305. //如果有传入 上一个兄弟节点分类id
  2306. if req.PrevEdbInfoId > 0 {
  2307. prevEdbInfo, err := data_manage.GetEdbInfoById(req.PrevEdbInfoId)
  2308. if err != nil {
  2309. br.Msg = "移动失败"
  2310. br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
  2311. return
  2312. }
  2313. //如果是移动在两个兄弟节点之间
  2314. if req.NextEdbInfoId > 0 {
  2315. //下一个兄弟节点
  2316. nextEdbInfo, err := data_manage.GetEdbInfoById(req.NextEdbInfoId)
  2317. if err != nil {
  2318. br.Msg = "移动失败"
  2319. br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
  2320. return
  2321. }
  2322. //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
  2323. if prevEdbInfo.Sort == nextEdbInfo.Sort || prevEdbInfo.Sort == edbInfo.Sort {
  2324. //变更兄弟节点的排序
  2325. updateSortStr := `sort + 2`
  2326. _ = data_manage.UpdateEdbInfoSortByClassifyId(prevEdbInfo.ClassifyId, prevEdbInfo.Sort, prevEdbInfo.EdbInfoId, updateSortStr)
  2327. } else {
  2328. //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
  2329. if nextEdbInfo.Sort-prevEdbInfo.Sort == 1 {
  2330. //变更兄弟节点的排序
  2331. updateSortStr := `sort + 1`
  2332. _ = data_manage.UpdateEdbInfoSortByClassifyId(prevEdbInfo.ClassifyId, prevEdbInfo.Sort, prevEdbInfo.EdbInfoId, updateSortStr)
  2333. }
  2334. }
  2335. }
  2336. edbInfo.Sort = prevEdbInfo.Sort + 1
  2337. edbInfo.ModifyTime = time.Now()
  2338. updateCol = append(updateCol, "Sort", "ModifyTime")
  2339. } else {
  2340. firstClassify, err := data_manage.GetFirstEdbInfoByClassifyId(req.ClassifyId)
  2341. if err != nil && err.Error() != utils.ErrNoRow() {
  2342. br.Msg = "移动失败"
  2343. br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
  2344. return
  2345. }
  2346. //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
  2347. if firstClassify != nil && firstClassify.Sort == 0 {
  2348. updateSortStr := ` sort + 1 `
  2349. _ = data_manage.UpdateEdbInfoSortByClassifyId(firstClassify.ClassifyId, 0, firstClassify.EdbInfoId-1, updateSortStr)
  2350. }
  2351. edbInfo.Sort = 0 //那就是排在第一位
  2352. edbInfo.ModifyTime = time.Now()
  2353. updateCol = append(updateCol, "Sort", "ModifyTime")
  2354. }
  2355. //更新
  2356. if len(updateCol) > 0 {
  2357. err = edbInfo.Update(updateCol)
  2358. if err != nil {
  2359. br.Msg = "移动失败"
  2360. br.ErrMsg = "修改失败,Err:" + err.Error()
  2361. return
  2362. }
  2363. }
  2364. if err != nil {
  2365. br.Msg = "移动失败"
  2366. br.ErrMsg = "修改失败,Err:" + err.Error()
  2367. return
  2368. }
  2369. //新增操作日志
  2370. {
  2371. edbLog := new(data_manage.EdbInfoLog)
  2372. edbLog.EdbInfoId = edbInfo.EdbInfoId
  2373. edbLog.SourceName = edbInfo.SourceName
  2374. edbLog.Source = edbInfo.Source
  2375. edbLog.EdbCode = edbInfo.EdbCode
  2376. edbLog.EdbName = edbInfo.EdbName
  2377. edbLog.ClassifyId = edbInfo.ClassifyId
  2378. edbLog.SysUserId = sysUser.AdminId
  2379. edbLog.SysUserRealName = sysUser.RealName
  2380. edbLog.CreateTime = time.Now()
  2381. edbLog.Content = string(this.Ctx.Input.RequestBody)
  2382. edbLog.Status = "移动指标"
  2383. edbLog.Method = this.Ctx.Input.URI()
  2384. go data_manage.AddEdbInfoLog(edbLog)
  2385. }
  2386. br.Ret = 200
  2387. br.Success = true
  2388. br.Msg = "移动成功"
  2389. }
  2390. // EdbInfoDetail
  2391. // @Title 获取指标详情
  2392. // @Description 获取指标详情接口
  2393. // @Param EdbInfoId query int true "指标id"
  2394. // @Success 200 {object} data_manage.EdbInfo
  2395. // @router /edb_info/detail [get]
  2396. func (this *EdbInfoController) EdbInfoDetail() {
  2397. br := new(models.BaseResponse).Init()
  2398. defer func() {
  2399. this.Data["json"] = br
  2400. this.ServeJSON()
  2401. }()
  2402. sysUser := this.SysUser
  2403. if sysUser == nil {
  2404. br.Msg = "请登录"
  2405. br.ErrMsg = "请登录,SysUser Is Empty"
  2406. br.Ret = 408
  2407. return
  2408. }
  2409. edbInfoId, _ := this.GetInt("EdbInfoId")
  2410. if edbInfoId <= 0 {
  2411. br.Msg = "参数错误"
  2412. br.ErrMsg = "参数错误"
  2413. return
  2414. }
  2415. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  2416. if err != nil {
  2417. br.Msg = "获取失败"
  2418. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2419. return
  2420. }
  2421. var resp data_manage.EdbInfoFullClassify
  2422. classifyList, err, errMsg := data.GetFullClassifyByClassifyId(edbInfo.ClassifyId)
  2423. if err != nil {
  2424. br.Msg = err.Error()
  2425. br.ErrMsg = errMsg
  2426. return
  2427. }
  2428. resp.EdbInfo = edbInfo
  2429. resp.ClassifyList = classifyList
  2430. br.Ret = 200
  2431. br.Success = true
  2432. br.Msg = "获取成功"
  2433. br.Data = resp
  2434. }
  2435. // EdbInfoFilter
  2436. // @Title 指标筛选接口
  2437. // @Description 指标筛选接口
  2438. // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
  2439. // @Param FilterSource query int false "搜索来源:1:其他搜索,2:累计值转月值搜索,3:变频,4:基础指标"
  2440. // @Param PageSize query int true "每页数据条数"
  2441. // @Param CurrentIndex query int true "当前页页码,从1开始"
  2442. // @Success 200 {object} data_manage.EdbInfoList
  2443. // @router /edb_info/filter [get]
  2444. func (this *EdbInfoController) EdbInfoFilter() {
  2445. br := new(models.BaseResponse).Init()
  2446. defer func() {
  2447. this.Data["json"] = br
  2448. this.ServeJSON()
  2449. }()
  2450. keyWord := this.GetString("KeyWord")
  2451. filterSource, _ := this.GetInt("FilterSource")
  2452. if filterSource <= 0 {
  2453. filterSource = 1
  2454. }
  2455. var pars []interface{}
  2456. noPermissionEdbInfoIdList := make([]int, 0) //无权限指标
  2457. // 获取当前账号的不可见指标
  2458. {
  2459. obj := data_manage.EdbInfoNoPermissionAdmin{}
  2460. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  2461. if err != nil && err.Error() != utils.ErrNoRow() {
  2462. br.Msg = "获取失败"
  2463. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  2464. return
  2465. }
  2466. for _, v := range confList {
  2467. noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
  2468. }
  2469. }
  2470. var keyWordArr []string
  2471. keyWordArr = append(keyWordArr, keyWord)
  2472. if keyWord != "" {
  2473. newKeyWord := strings.Split(keyWord, " ")
  2474. keyWordArr = append(keyWordArr, newKeyWord...)
  2475. }
  2476. //var err error
  2477. edbInfoList := make([]*data_manage.EdbInfoList, 0)
  2478. //if keyWord == "" {
  2479. // edbInfoList, err = data_manage.GetEdbInfoFilter(condition, pars)
  2480. // if err != nil && err.Error() != utils.ErrNoRow() {
  2481. // br.Success = true
  2482. // br.Msg = "获取指标信息失败"
  2483. // br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2484. // return
  2485. // }
  2486. //} else {
  2487. // //获取指标信息
  2488. // indexName := utils.DATA_INDEX_NAME
  2489. // edbInfoList, err = data.EsSearchEdbInfo(indexName, keyWord,filterSource)
  2490. // if err != nil && err.Error() != utils.ErrNoRow() {
  2491. // br.Success = true
  2492. // br.Msg = "获取指标信息失败"
  2493. // br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2494. // return
  2495. // }
  2496. //}
  2497. var baseCondition string
  2498. // 无权限指标id
  2499. lenNoPermissionEdbInfoIdList := len(noPermissionEdbInfoIdList)
  2500. if lenNoPermissionEdbInfoIdList > 0 {
  2501. baseCondition = ` AND edb_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionEdbInfoIdList) + `) `
  2502. pars = append(pars, noPermissionEdbInfoIdList)
  2503. }
  2504. existMap := make(map[int]string)
  2505. for _, v := range keyWordArr {
  2506. v = strings.Replace(v, " ", "%", -1)
  2507. var condition string
  2508. if filterSource == 2 {
  2509. condition += ` AND frequency='月度' `
  2510. }
  2511. if filterSource == 3 {
  2512. condition += ` AND frequency <> '日度' `
  2513. }
  2514. if filterSource == 4 {
  2515. condition += ` AND edb_type = 1 `
  2516. }
  2517. conditionWhere := `AND ( edb_code LIKE '%` + v + `%' OR edb_name LIKE '%` + v + `%' )`
  2518. condition += conditionWhere + baseCondition
  2519. newEdbInfoList, err := data_manage.GetEdbInfoFilter(condition, pars)
  2520. if err != nil && err.Error() != utils.ErrNoRow() {
  2521. br.Success = true
  2522. br.Msg = "获取指标信息失败"
  2523. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2524. return
  2525. }
  2526. for _, nv := range newEdbInfoList {
  2527. if _, ok := existMap[nv.EdbInfoId]; !ok {
  2528. edbInfoList = append(edbInfoList, nv)
  2529. }
  2530. existMap[nv.EdbInfoId] = nv.EdbCode
  2531. }
  2532. }
  2533. if edbInfoList == nil {
  2534. edbInfoList = make([]*data_manage.EdbInfoList, 0)
  2535. }
  2536. edbInfoListLen := len(edbInfoList)
  2537. for i := 0; i < edbInfoListLen; i++ {
  2538. edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName
  2539. }
  2540. for i := 0; i < edbInfoListLen; i++ {
  2541. for j := 0; j < edbInfoListLen; j++ {
  2542. if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
  2543. (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
  2544. !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
  2545. edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
  2546. }
  2547. }
  2548. }
  2549. //新增搜索词记录
  2550. {
  2551. searchKeyword := new(data_manage.SearchKeyword)
  2552. searchKeyword.KeyWord = keyWord
  2553. searchKeyword.CreateTime = time.Now()
  2554. go data_manage.AddSearchKeyword(searchKeyword)
  2555. }
  2556. br.Ret = 200
  2557. br.Success = true
  2558. br.Msg = "获取成功"
  2559. br.Data = edbInfoList
  2560. }
  2561. // EdbInfoFilterByEs
  2562. // @Title 指标筛选接口
  2563. // @Description 指标筛选接口
  2564. // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
  2565. // @Param FilterSource query int false "搜索来源:1:其他搜索,2:累计值转月值搜索,3:变频,4:基础指标,5:同比"
  2566. // @Param Frequency query string false "频度"
  2567. // @Param IsAddPredictEdb query bool false "是否查询添加预测指标"
  2568. // @Param PageSize query int true "每页数据条数"
  2569. // @Param CurrentIndex query int true "当前页页码,从1开始"
  2570. // @Success 200 {object} data_manage.EdbInfoList
  2571. // @router /edb_info/filter_by_es [get]
  2572. func (this *EdbInfoController) EdbInfoFilterByEs() {
  2573. br := new(models.BaseResponse).Init()
  2574. defer func() {
  2575. this.Data["json"] = br
  2576. this.ServeJSON()
  2577. }()
  2578. pageSize, _ := this.GetInt("PageSize")
  2579. currentIndex, _ := this.GetInt("CurrentIndex")
  2580. var total int64
  2581. var startSize int
  2582. if pageSize <= 0 {
  2583. pageSize = utils.PageSize20
  2584. }
  2585. if currentIndex <= 0 {
  2586. currentIndex = 1
  2587. }
  2588. startSize = paging.StartIndex(currentIndex, pageSize)
  2589. keyWord := this.GetString("KeyWord")
  2590. keyWord = strings.TrimSpace(keyWord) //移除字符串首尾空格
  2591. filterSource, _ := this.GetInt("FilterSource")
  2592. if filterSource <= 0 {
  2593. filterSource = 1
  2594. }
  2595. //指标来源
  2596. source, _ := this.GetInt("Source")
  2597. frequency := this.GetString("Frequency") //频度
  2598. isAddPredictEdb, _ := this.GetBool("IsAddPredictEdb") //是否查询添加预测指标
  2599. var edbInfoList []*data_manage.EdbInfoList
  2600. var err error
  2601. noPermissionEdbInfoIdList := make([]int, 0) //无权限指标
  2602. // 获取当前账号的不可见指标
  2603. {
  2604. obj := data_manage.EdbInfoNoPermissionAdmin{}
  2605. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  2606. if err != nil && err.Error() != utils.ErrNoRow() {
  2607. br.Msg = "获取失败"
  2608. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  2609. return
  2610. }
  2611. for _, v := range confList {
  2612. noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
  2613. }
  2614. }
  2615. if keyWord != "" {
  2616. var keyWordArr []string
  2617. keyWordArr = append(keyWordArr, keyWord)
  2618. newKeyWord := strings.Split(keyWord, " ")
  2619. keyWordArr = append(keyWordArr, newKeyWord...)
  2620. // 普通的搜索
  2621. if !isAddPredictEdb {
  2622. total, edbInfoList, err = elastic.SearchEdbInfoData(utils.DATA_INDEX_NAME, keyWord, startSize, pageSize, filterSource, source, 0, frequency, noPermissionEdbInfoIdList)
  2623. } else {
  2624. // 允许添加预测指标的搜索
  2625. total, edbInfoList, err = elastic.SearchAddPredictEdbInfoData(utils.DATA_INDEX_NAME, keyWord, noPermissionEdbInfoIdList, startSize, pageSize)
  2626. }
  2627. } else {
  2628. var condition string
  2629. var pars []interface{}
  2630. // 普通指标
  2631. condition += ` AND edb_info_type = ? `
  2632. pars = append(pars, 0)
  2633. // 无权限指标id
  2634. lenNoPermissionEdbInfoIdList := len(noPermissionEdbInfoIdList)
  2635. if lenNoPermissionEdbInfoIdList > 0 {
  2636. condition += ` AND edb_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionEdbInfoIdList) + `) `
  2637. pars = append(pars, noPermissionEdbInfoIdList)
  2638. }
  2639. switch filterSource {
  2640. case 2:
  2641. condition += ` AND frequency='月度' `
  2642. case 3:
  2643. condition += ` AND frequency <> '日度' `
  2644. case 4:
  2645. condition += ` AND edb_type = 1 `
  2646. case 5:
  2647. condition += ` AND source = 6 ` //来源(同比值)
  2648. case 6:
  2649. condition += ` AND frequency != ? `
  2650. pars = append(pars, "年度")
  2651. }
  2652. //频度
  2653. if frequency != "" {
  2654. condition += ` AND frequency = ? `
  2655. pars = append(pars, frequency)
  2656. }
  2657. // 查询只允许添加预测指标的搜索
  2658. if isAddPredictEdb {
  2659. condition += ` AND frequency in ("日度","周度","月度") `
  2660. }
  2661. total, edbInfoList, err = data_manage.GetEdbInfoFilterList(condition, pars, startSize, pageSize)
  2662. }
  2663. if err != nil {
  2664. edbInfoList = make([]*data_manage.EdbInfoList, 0)
  2665. }
  2666. page := paging.GetPaging(currentIndex, pageSize, int(total))
  2667. edbInfoListLen := len(edbInfoList)
  2668. for i := 0; i < edbInfoListLen; i++ {
  2669. edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName
  2670. }
  2671. for i := 0; i < edbInfoListLen; i++ {
  2672. for j := 0; j < edbInfoListLen; j++ {
  2673. if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
  2674. (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
  2675. !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
  2676. edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
  2677. }
  2678. }
  2679. }
  2680. //新增搜索词记录
  2681. {
  2682. searchKeyword := new(data_manage.SearchKeyword)
  2683. searchKeyword.KeyWord = keyWord
  2684. searchKeyword.CreateTime = time.Now()
  2685. go data_manage.AddSearchKeyword(searchKeyword)
  2686. }
  2687. resp := data_manage.EdbInfoFilterDataResp{
  2688. Paging: page,
  2689. List: edbInfoList,
  2690. }
  2691. br.Ret = 200
  2692. br.Success = true
  2693. br.Msg = "获取成功"
  2694. br.Data = resp
  2695. }
  2696. func (this *EdbInfoController) EdbInfoFilter2() {
  2697. br := new(models.BaseResponse).Init()
  2698. defer func() {
  2699. this.Data["json"] = br
  2700. this.ServeJSON()
  2701. }()
  2702. keyWord := this.GetString("KeyWord")
  2703. keyWord = strings.TrimSpace(keyWord) //移除字符串首尾空格
  2704. filterSource, _ := this.GetInt("FilterSource")
  2705. if filterSource <= 0 {
  2706. filterSource = 1
  2707. }
  2708. var pars []interface{}
  2709. //if keyWord != "" {
  2710. // condition += ` AND ( edb_code LIKE '%` + keyWord + `%' OR edb_name LIKE '%` + keyWord + `%' )`
  2711. //}
  2712. var keyWordArr []string
  2713. keyWordArr = append(keyWordArr, keyWord)
  2714. if keyWord != "" {
  2715. newKeyWord := strings.Split(keyWord, " ")
  2716. keyWordArr = append(keyWordArr, newKeyWord...)
  2717. }
  2718. keywordLen := len(keyWordArr)
  2719. ch := make(chan map[int][]*data_manage.EdbInfoList, keywordLen)
  2720. searchWait := sync.WaitGroup{}
  2721. searchWait.Add(keywordLen)
  2722. for index, v := range keyWordArr {
  2723. v = strings.Replace(v, " ", "%", -1)
  2724. var condition string
  2725. if filterSource == 2 {
  2726. condition += ` AND frequency='月度' `
  2727. }
  2728. if filterSource == 3 {
  2729. condition += ` AND frequency <> '日度' `
  2730. }
  2731. if filterSource == 4 {
  2732. condition += ` AND edb_type = 1 `
  2733. }
  2734. conditionWhere := `AND ( edb_code LIKE '%` + v + `%' OR edb_name LIKE '%` + v + `%' )`
  2735. condition += conditionWhere
  2736. go searchEdbInfoFilter(condition, pars, index, ch, &searchWait)
  2737. }
  2738. searchWait.Wait()
  2739. newEdbInfoListMap := make(map[int][]*data_manage.EdbInfoList)
  2740. i := 0
  2741. for tmpEdbInfoList := range ch {
  2742. i++
  2743. for k, v := range tmpEdbInfoList {
  2744. newEdbInfoListMap[k] = v
  2745. }
  2746. if i == keywordLen {
  2747. break
  2748. }
  2749. }
  2750. close(ch)
  2751. edbInfoList := make([]*data_manage.EdbInfoList, 0)
  2752. existMap := make(map[int]string)
  2753. for i := 0; i < keywordLen; i++ {
  2754. if newEdbInfoList, ok := newEdbInfoListMap[i]; ok {
  2755. for _, nv := range newEdbInfoList {
  2756. if _, ok := existMap[nv.EdbInfoId]; !ok {
  2757. edbInfoList = append(edbInfoList, nv)
  2758. }
  2759. existMap[nv.EdbInfoId] = nv.EdbCode
  2760. }
  2761. }
  2762. }
  2763. if edbInfoList == nil {
  2764. edbInfoList = make([]*data_manage.EdbInfoList, 0)
  2765. }
  2766. edbInfoListLen := len(edbInfoList)
  2767. for i := 0; i < edbInfoListLen; i++ {
  2768. edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName
  2769. }
  2770. for i := 0; i < edbInfoListLen; i++ {
  2771. for j := 0; j < edbInfoListLen; j++ {
  2772. if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
  2773. (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
  2774. !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
  2775. edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
  2776. }
  2777. }
  2778. }
  2779. //新增搜索词记录
  2780. {
  2781. searchKeyword := new(data_manage.SearchKeyword)
  2782. searchKeyword.KeyWord = keyWord
  2783. searchKeyword.CreateTime = time.Now()
  2784. go data_manage.AddSearchKeyword(searchKeyword)
  2785. }
  2786. br.Ret = 200
  2787. br.Success = true
  2788. br.Msg = "获取成功"
  2789. br.Data = edbInfoList
  2790. }
  2791. func searchEdbInfoFilter(condition string, pars []interface{}, i int, ch chan map[int][]*data_manage.EdbInfoList, searchWait *sync.WaitGroup) (newEdbInfoListMap map[int][]*data_manage.EdbInfoList, err error) {
  2792. newEdbInfoListMap = make(map[int][]*data_manage.EdbInfoList)
  2793. defer func() {
  2794. if err != nil {
  2795. go alarm_msg.SendAlarmMsg("查询近6个月的客户增量数据异常:"+err.Error(), 3)
  2796. //go utils.SendEmail(utils.APPNAME+"查询近6个月的客户增量数据异常:"+time.Now().Format("2006-01-02 15:04:05"), err.Error(), utils.EmailSendToUsers)
  2797. }
  2798. ch <- newEdbInfoListMap
  2799. searchWait.Done()
  2800. }()
  2801. newEdbInfoList, err := data_manage.GetEdbInfoFilter(condition, pars)
  2802. newEdbInfoListMap[i] = newEdbInfoList
  2803. return
  2804. }
  2805. // EdbInfoAllRefresh
  2806. // @Title 指标全部刷新接口
  2807. // @Description 指标全部刷新接口
  2808. // @Param EdbInfoId query int true "指标id"
  2809. // @Success Ret=200 全部刷新成功
  2810. // @router /edb_info/refresh/all [get]
  2811. func (this *EdbInfoController) EdbInfoAllRefresh() {
  2812. br := new(models.BaseResponse).Init()
  2813. defer func() {
  2814. this.Data["json"] = br
  2815. this.ServeJSON()
  2816. }()
  2817. sysUser := this.SysUser
  2818. if sysUser == nil {
  2819. br.Msg = "请登录"
  2820. br.ErrMsg = "请登录,SysUser Is Empty"
  2821. br.Ret = 408
  2822. return
  2823. }
  2824. edbInfoId, _ := this.GetInt("EdbInfoId")
  2825. if edbInfoId <= 0 {
  2826. br.Msg = "参数错误"
  2827. br.ErrMsg = "参数错误"
  2828. return
  2829. }
  2830. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  2831. if err != nil {
  2832. if err.Error() == utils.ErrNoRow() {
  2833. br.Msg = "数据已被删除,请刷新页面"
  2834. br.ErrMsg = "数据已被删除,请刷新页面,edbInfoId:" + strconv.Itoa(edbInfoId)
  2835. return
  2836. }
  2837. br.Msg = "刷新失败"
  2838. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  2839. return
  2840. }
  2841. if edbInfo == nil {
  2842. br.Msg = "数据已被删除,请刷新页面"
  2843. br.ErrMsg = "数据已被删除,请刷新页面,edbInfoId:" + strconv.Itoa(edbInfoId)
  2844. return
  2845. }
  2846. err, isAsync := data.EdbInfoRefreshAllFromBaseV2(edbInfoId, true)
  2847. if err != nil {
  2848. br.Msg = "刷新失败"
  2849. br.ErrMsg = "刷新指标失败,EdbInfoRefreshAllFromBase Err:" + err.Error()
  2850. return
  2851. }
  2852. br.Ret = 200
  2853. br.Success = true
  2854. br.Msg = "刷新成功"
  2855. if isAsync {
  2856. br.Msg = "该指标关联指标较多,请10分钟后刷新页面查看最新数据"
  2857. }
  2858. }
  2859. // EdbInfoData
  2860. // @Title 获取指标数据
  2861. // @Description 获取指标数据
  2862. // @Param EdbInfoId query int true "指标ID"
  2863. // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:自定义起始时间至今,7:18年至今,8:19年至今,9:20年至今,10:全部"
  2864. // @Param StartDate query string true "自定义开始日期"
  2865. // @Param EndDate query string true "自定义结束日期"
  2866. // @Success 200 {object} data_manage.EdbInfoDataResp
  2867. // @router /edb_info/data [get]
  2868. func (this *ChartInfoController) EdbInfoData() {
  2869. br := new(models.BaseResponse).Init()
  2870. defer func() {
  2871. this.Data["json"] = br
  2872. this.ServeJSON()
  2873. }()
  2874. sysUser := this.SysUser
  2875. if sysUser == nil {
  2876. br.Msg = "请登录"
  2877. br.ErrMsg = "请登录,SysUser Is Empty"
  2878. br.Ret = 408
  2879. return
  2880. }
  2881. edbInfoId, _ := this.GetInt("EdbInfoId")
  2882. if edbInfoId <= 0 {
  2883. br.Msg = "参数错误"
  2884. return
  2885. }
  2886. dateType, _ := this.GetInt("DateType")
  2887. if dateType <= 0 {
  2888. dateType = 3
  2889. }
  2890. edbInfoType, _ := this.GetInt("EdbInfoType")
  2891. if edbInfoType < 0 {
  2892. edbInfoType = 1
  2893. }
  2894. startDate := this.GetString("StartDate")
  2895. endDate := this.GetString("EndDate")
  2896. startYear, _ := this.GetInt("StartYear")
  2897. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  2898. if err != nil {
  2899. if err.Error() == utils.ErrNoRow() {
  2900. br.Ret = 200
  2901. return
  2902. }
  2903. br.Msg = "获取失败"
  2904. br.ErrMsg = "获取失败,Err:" + err.Error()
  2905. return
  2906. }
  2907. maxYear := 0
  2908. if edbInfo.LatestDate != "" {
  2909. latestDateT, _ := time.Parse(utils.FormatDate, edbInfo.LatestDate)
  2910. maxYear = latestDateT.Year()
  2911. }
  2912. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, maxYear)
  2913. dataList, err := data_manage.GetEdbDataList(edbInfo.Source, edbInfoId, startDate, endDate)
  2914. if err != nil {
  2915. br.Msg = "获取失败"
  2916. br.ErrMsg = "获取失败,Err:" + err.Error()
  2917. return
  2918. }
  2919. fullEdb := new(data_manage.EdbInfoFullClassify)
  2920. resp := new(data_manage.EdbInfoDataFullClassifyResp)
  2921. classifyList, err, errMsg := data.GetFullClassifyByClassifyId(edbInfo.ClassifyId)
  2922. if err != nil {
  2923. br.Msg = err.Error()
  2924. br.ErrMsg = errMsg
  2925. return
  2926. }
  2927. fullEdb.EdbInfo = edbInfo
  2928. fullEdb.ClassifyList = classifyList
  2929. resp.EdbInfo = fullEdb
  2930. resp.DataList = dataList
  2931. br.Ret = 200
  2932. br.Success = true
  2933. br.Msg = "获取成功"
  2934. br.Data = resp
  2935. }
  2936. // EdbInfoReplaceCheck
  2937. // @Title 指标一键刷新接口
  2938. // @Description 指标一键刷新接口
  2939. // @Success Ret=200 更新成功
  2940. // @router /edb_info/replace/check [post]
  2941. func (this *EdbInfoController) EdbInfoReplaceCheck() {
  2942. br := new(models.BaseResponse).Init()
  2943. setNxKey := "EDB_INFO_REPLACE"
  2944. defer func() {
  2945. this.Data["json"] = br
  2946. this.ServeJSON()
  2947. }()
  2948. status := 0
  2949. if utils.Rc.IsExist(setNxKey) {
  2950. status = 1
  2951. } else {
  2952. status = 2
  2953. }
  2954. br.Ret = 200
  2955. br.Success = true
  2956. br.Msg = "检测成功"
  2957. br.Data = status
  2958. }
  2959. // EdbInfoReplace
  2960. // @Title 替换指标
  2961. // @Description 替换指标
  2962. // @Param request body data_manage.EdbInfoReplaceReq true "type json string"
  2963. // @Success 200 {object} data_manage.EdbInfoDataResp
  2964. // @router /edb_info/replace [post]
  2965. func (this *ChartInfoController) EdbInfoReplace() {
  2966. br := new(models.BaseResponse).Init()
  2967. setNxKey := "EDB_INFO_REPLACE"
  2968. deleteCache := true
  2969. defer func() {
  2970. if deleteCache {
  2971. utils.Rc.Delete(setNxKey)
  2972. }
  2973. this.Data["json"] = br
  2974. this.ServeJSON()
  2975. }()
  2976. sysUser := this.SysUser
  2977. if sysUser == nil {
  2978. br.Msg = "请登录"
  2979. br.ErrMsg = "请登录,SysUser Is Empty"
  2980. br.Ret = 408
  2981. return
  2982. }
  2983. if !utils.Rc.SetNX(setNxKey, 1, 30*time.Minute) {
  2984. deleteCache = false
  2985. br.Msg = "当前正在替换中,请耐心等待!"
  2986. br.IsSendEmail = false
  2987. return
  2988. }
  2989. var req data_manage.EdbInfoReplaceReq
  2990. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2991. if err != nil {
  2992. br.Msg = "参数解析异常!"
  2993. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2994. return
  2995. }
  2996. if req.OldEdbInfoId <= 0 || req.NewEdbInfoId <= 0 {
  2997. br.Msg = "参数错误!"
  2998. br.ErrMsg = "参数错误,指标id为0"
  2999. return
  3000. }
  3001. oldEdbInfo, err := data_manage.GetEdbInfoById(req.OldEdbInfoId)
  3002. if err != nil {
  3003. br.Msg = "替换失败!"
  3004. br.ErrMsg = "获取原指标失败,Err:" + err.Error()
  3005. return
  3006. }
  3007. newEdbInfo, err := data_manage.GetEdbInfoById(req.NewEdbInfoId)
  3008. if err != nil {
  3009. br.Msg = "替换失败!"
  3010. br.ErrMsg = "获取替换目标指标失败,Err:" + err.Error()
  3011. return
  3012. }
  3013. //if oldEdbInfo.EdbType != 1 {
  3014. // br.Msg = "原指标为计算指标,不可替换!"
  3015. // br.ErrMsg = "原指标为计算指标,不可替换!"
  3016. // return
  3017. //}
  3018. //
  3019. //if newEdbInfo.EdbType != 1 {
  3020. // br.Msg = "替换指标为计算指标,不可替换!"
  3021. // br.ErrMsg = "替换指标为计算指标,不可替换!"
  3022. // return
  3023. //}
  3024. if oldEdbInfo.Frequency != newEdbInfo.Frequency {
  3025. br.Msg = "原指标频度为:" + oldEdbInfo.Frequency + " 替换指标频度为:" + newEdbInfo.Frequency + ",频度不同,不可进行替换操作!"
  3026. br.ErrMsg = "原指标频度为:" + oldEdbInfo.Frequency + " 替换指标频度为:" + newEdbInfo.Frequency + ",频度不同,不可进行替换操作!"
  3027. return
  3028. }
  3029. sysAdminId := sysUser.AdminId
  3030. //replaceChartTotal, replaceCalculateTotal, err := data.EdbInfoReplace(oldEdbInfo, newEdbInfo, sysAdminId, sysUser.RealName)
  3031. _, _, err = data.EdbInfoReplace(oldEdbInfo, newEdbInfo, sysAdminId, sysUser.RealName)
  3032. //msgContent := ``
  3033. isFail := false
  3034. var errmsg string
  3035. if err != nil {
  3036. //msgContent = oldEdbInfo.EdbName + "指标替换" + newEdbInfo.EdbName + "指标,全部替换失败,涉及" + strconv.Itoa(replaceChartTotal) + "张图表,\n\n " + strconv.Itoa(replaceCalculateTotal) + "个计算指标"
  3037. isFail = true
  3038. errmsg = "replace err:" + err.Error()
  3039. } else {
  3040. //msgContent = oldEdbInfo.EdbName + "指标替换" + newEdbInfo.EdbName + "指标,全部替换成功,涉及" + strconv.Itoa(replaceChartTotal) + "张图表,\n\n" + strconv.Itoa(replaceCalculateTotal) + "个计算指标"
  3041. isFail = false
  3042. }
  3043. // 添加站内信息
  3044. //{
  3045. // msgItem := new(company.CompanyApprovalMessage)
  3046. // msgItem.CreateUserId = sysAdminId
  3047. // msgItem.ReceiveUserId = sysAdminId
  3048. // msgItem.MessageStatus = 0
  3049. // msgItem.Remark = "指标替换"
  3050. // msgItem.OperationStatus = 1
  3051. // msgItem.Content = msgContent
  3052. // msgItem.CreateTime = time.Now()
  3053. // msgItem.ModifyTime = time.Now()
  3054. // msgItem.MessageType = 3 //1:申请消息,2:审批结果,3:文字消息
  3055. // msgItem.SourceType = 4 //消息来源
  3056. // err = company.AddCompanyApprovalMessage(msgItem)
  3057. //}
  3058. if isFail {
  3059. br.Msg = "替换失败"
  3060. br.ErrMsg = "替换失败 err:" + errmsg
  3061. } else {
  3062. br.Msg = "替换成功"
  3063. br.ErrMsg = "替换成功"
  3064. br.Ret = 200
  3065. }
  3066. br.IsAddLog = true
  3067. return
  3068. }
  3069. // RelationChartList
  3070. // @Title 获取ETA指标关联的图表列表接口
  3071. // @Description 获取ETA指标关联的图表列表接口
  3072. // @Param PageSize query int true "每页数据条数"
  3073. // @Param CurrentIndex query int true "当前页页码,从1开始"
  3074. // @Param EdbInfoId query int true "指标id"
  3075. // @Param IsShowMe query bool true "是否只看我的,true、false"
  3076. // @Success 200 {object} data_manage.ChartListResp
  3077. // @router /edb_info/relation/chart_list [get]
  3078. func (this *EdbInfoController) RelationChartList() {
  3079. br := new(models.BaseResponse).Init()
  3080. defer func() {
  3081. this.Data["json"] = br
  3082. this.ServeJSON()
  3083. }()
  3084. sysUser := this.SysUser
  3085. if sysUser == nil {
  3086. br.Msg = "请登录"
  3087. br.ErrMsg = "请登录,SysUser Is Empty"
  3088. br.Ret = 408
  3089. return
  3090. }
  3091. edbInfoId, _ := this.GetInt("EdbInfoId")
  3092. pageSize, _ := this.GetInt("PageSize")
  3093. currentIndex, _ := this.GetInt("CurrentIndex")
  3094. resp := data_manage.ChartListResp{}
  3095. var total int
  3096. page := paging.GetPaging(currentIndex, pageSize, total)
  3097. var startSize int
  3098. if pageSize <= 0 {
  3099. pageSize = utils.PageSize20
  3100. }
  3101. if currentIndex <= 0 {
  3102. currentIndex = 1
  3103. }
  3104. startSize = paging.StartIndex(currentIndex, pageSize)
  3105. var condition string
  3106. var pars []interface{}
  3107. if edbInfoId <= 0 {
  3108. br.Msg = "请选择指标"
  3109. br.ErrMsg = "请选择指标"
  3110. br.IsSendEmail = false
  3111. return
  3112. }
  3113. // 关联指标
  3114. condition += ` AND b.edb_info_id = ? `
  3115. pars = append(pars, edbInfoId)
  3116. //只看我的
  3117. isShowMe, _ := this.GetBool("IsShowMe")
  3118. if isShowMe {
  3119. condition += ` AND a.sys_user_id = ? `
  3120. pars = append(pars, sysUser.AdminId)
  3121. }
  3122. // 获取当前账号的不可见图表
  3123. noPermissionChartIdList := make([]int, 0)
  3124. {
  3125. obj := data_manage.EdbInfoNoPermissionAdmin{}
  3126. confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
  3127. if err != nil && err.Error() != utils.ErrNoRow() {
  3128. br.Msg = "获取失败"
  3129. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  3130. return
  3131. }
  3132. for _, v := range confList {
  3133. noPermissionChartIdList = append(noPermissionChartIdList, v.ChartInfoId)
  3134. }
  3135. }
  3136. noPermissionChartIdNum := len(noPermissionChartIdList)
  3137. if noPermissionChartIdNum > 0 {
  3138. condition += ` AND a.chart_info_id not in (` + utils.GetOrmInReplace(noPermissionChartIdNum) + `) `
  3139. pars = append(pars, noPermissionChartIdList)
  3140. }
  3141. //获取关联图表列表
  3142. list, err := data_manage.GetRelationChartListByCondition(condition, pars, startSize, pageSize)
  3143. if err != nil && err.Error() != utils.ErrNoRow() {
  3144. br.Success = true
  3145. br.Msg = "获取图表信息失败"
  3146. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  3147. return
  3148. }
  3149. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  3150. items := make([]*data_manage.ChartInfoView, 0)
  3151. resp.Paging = page
  3152. resp.List = items
  3153. br.Ret = 200
  3154. br.Success = true
  3155. br.Msg = "获取成功"
  3156. return
  3157. }
  3158. // 获取关联图表总数
  3159. dataCount, err := data_manage.GetRelationChartListCountByCondition(condition, pars)
  3160. if err != nil && err.Error() != utils.ErrNoRow() {
  3161. br.Msg = "获取指标信息失败"
  3162. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  3163. return
  3164. }
  3165. // 获取MY ETA 图表,用来判断是否加入我的图库
  3166. myChartList, err := data_manage.GetMyChartListByAdminId(sysUser.AdminId)
  3167. if err != nil && err.Error() != utils.ErrNoRow() {
  3168. br.Msg = "获取图表信息失败"
  3169. br.ErrMsg = "获取我的图表信息失败,Err:" + err.Error()
  3170. return
  3171. }
  3172. myChartMap := make(map[int]*data_manage.MyChartView)
  3173. for _, v := range myChartList {
  3174. myChartMap[v.ChartInfoId] = v
  3175. }
  3176. listLen := len(list)
  3177. for i := 0; i < listLen; i++ {
  3178. if existItem, ok := myChartMap[list[i].ChartInfoId]; ok {
  3179. list[i].IsAdd = true
  3180. list[i].MyChartId = existItem.MyChartId
  3181. list[i].MyChartClassifyId = existItem.MyChartClassifyId
  3182. }
  3183. }
  3184. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  3185. resp.Paging = page
  3186. resp.List = list
  3187. br.Ret = 200
  3188. br.Success = true
  3189. br.Msg = "获取成功"
  3190. br.Data = resp
  3191. }
  3192. // RelationEdbList
  3193. // @Title 获取ETA指标关联的指标列表接口
  3194. // @Description 获取ETA指标关联的指标列表接口
  3195. // @Param PageSize query int true "每页数据条数"
  3196. // @Param CurrentIndex query int true "当前页页码,从1开始"
  3197. // @Param EdbInfoId query int true "指标id"
  3198. // @Param IsShowMe query bool true "是否只看我的,true、false"
  3199. // @Success 200 {object} data_manage.ChartListResp
  3200. // @router /edb_info/relation/edbinfo_list [get]
  3201. func (this *EdbInfoController) RelationEdbList() {
  3202. br := new(models.BaseResponse).Init()
  3203. defer func() {
  3204. this.Data["json"] = br
  3205. this.ServeJSON()
  3206. }()
  3207. sysUser := this.SysUser
  3208. if sysUser == nil {
  3209. br.Msg = "请登录"
  3210. br.ErrMsg = "请登录,SysUser Is Empty"
  3211. br.Ret = 408
  3212. return
  3213. }
  3214. edbInfoId, _ := this.GetInt("EdbInfoId")
  3215. pageSize, _ := this.GetInt("PageSize")
  3216. currentIndex, _ := this.GetInt("CurrentIndex")
  3217. resp := data_manage.RelationEdbInfoListResp{}
  3218. var total int
  3219. page := paging.GetPaging(currentIndex, pageSize, total)
  3220. var startSize int
  3221. if pageSize <= 0 {
  3222. pageSize = utils.PageSize20
  3223. }
  3224. if currentIndex <= 0 {
  3225. currentIndex = 1
  3226. }
  3227. startSize = paging.StartIndex(currentIndex, pageSize)
  3228. var condition string
  3229. var pars []interface{}
  3230. if edbInfoId <= 0 {
  3231. br.Msg = "请选择指标"
  3232. br.ErrMsg = "请选择指标"
  3233. br.IsSendEmail = false
  3234. return
  3235. }
  3236. // 关联指标
  3237. condition += ` AND b.from_edb_info_id = ? `
  3238. pars = append(pars, edbInfoId)
  3239. //只看我的
  3240. isShowMe, _ := this.GetBool("IsShowMe")
  3241. if isShowMe {
  3242. condition += ` AND a.sys_user_id = ? `
  3243. pars = append(pars, sysUser.AdminId)
  3244. }
  3245. // 获取当前账号的不可见图表
  3246. noPermissionEdbIdList := make([]int, 0)
  3247. {
  3248. obj := data_manage.EdbInfoNoPermissionAdmin{}
  3249. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  3250. if err != nil && err.Error() != utils.ErrNoRow() {
  3251. br.Msg = "获取失败"
  3252. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  3253. return
  3254. }
  3255. for _, v := range confList {
  3256. noPermissionEdbIdList = append(noPermissionEdbIdList, v.EdbInfoId)
  3257. }
  3258. }
  3259. noPermissionEdbIdNum := len(noPermissionEdbIdList)
  3260. if noPermissionEdbIdNum > 0 {
  3261. condition += ` AND a.edb_info_id not in (` + utils.GetOrmInReplace(noPermissionEdbIdNum) + `) `
  3262. pars = append(pars, noPermissionEdbIdList)
  3263. }
  3264. //获取关联图表列表
  3265. list, err := data_manage.GetRelationEdbInfoListByCondition(condition, pars, startSize, pageSize)
  3266. if err != nil && err.Error() != utils.ErrNoRow() {
  3267. br.Success = true
  3268. br.Msg = "获取图表信息失败"
  3269. br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
  3270. return
  3271. }
  3272. if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
  3273. items := make([]*data_manage.ChartEdbInfoMapping, 0)
  3274. resp.Paging = page
  3275. resp.List = items
  3276. br.Ret = 200
  3277. br.Success = true
  3278. br.Msg = "获取成功"
  3279. return
  3280. }
  3281. // 获取关联图表总数
  3282. dataCount, err := data_manage.GetRelationEdbInfoListCountByCondition(condition, pars)
  3283. if err != nil && err.Error() != utils.ErrNoRow() {
  3284. br.Msg = "获取指标信息失败"
  3285. br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
  3286. return
  3287. }
  3288. if err != nil {
  3289. br.Msg = "获取失败"
  3290. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  3291. return
  3292. }
  3293. edbList := make([]*data_manage.ChartEdbInfoMapping, 0)
  3294. for _, v := range list {
  3295. item := new(data_manage.ChartEdbInfoMapping)
  3296. item.EdbInfoId = v.EdbInfoId
  3297. item.SourceName = v.SourceName
  3298. item.Source = v.Source
  3299. item.EdbCode = v.EdbCode
  3300. item.EdbName = v.EdbName
  3301. item.EdbNameEn = v.EdbNameEn
  3302. item.Frequency = v.Frequency
  3303. item.FrequencyEn = data.GetFrequencyEn(v.Frequency)
  3304. if v.Unit != `无` {
  3305. item.Unit = v.Unit
  3306. }
  3307. item.UnitEn = v.UnitEn
  3308. item.StartDate = v.StartDate
  3309. item.EndDate = v.EndDate
  3310. item.ModifyTime = v.ModifyTime
  3311. item.IsAxis = 1
  3312. item.LeadValue = 0
  3313. item.LeadUnit = ""
  3314. item.ChartEdbMappingId = 0
  3315. item.ChartInfoId = 0
  3316. item.IsOrder = false
  3317. item.EdbInfoType = v.EdbInfoType
  3318. item.EdbInfoCategoryType = v.EdbInfoType
  3319. item.ChartStyle = ""
  3320. item.ChartColor = ""
  3321. item.ChartWidth = 0
  3322. item.MaxData = v.MaxValue
  3323. item.MinData = v.MinValue
  3324. item.LatestValue = v.LatestValue
  3325. item.LatestDate = v.LatestDate
  3326. item.UniqueCode = v.UniqueCode
  3327. item.ClassifyId = v.ClassifyId
  3328. dataList := make([]*data_manage.EdbDataList, 0)
  3329. if v.EdbInfoType == 0 {
  3330. dataList, err = data_manage.GetEdbDataList(v.Source, v.EdbInfoId, "", "")
  3331. } else {
  3332. _, dataList, _, _, err, _ = data.GetPredictDataListByPredictEdbInfoId(v.EdbInfoId, "", "", false)
  3333. }
  3334. if err != nil {
  3335. br.Msg = "获取失败"
  3336. br.Msg = "获取失败,Err:" + err.Error()
  3337. return
  3338. }
  3339. item.DataList = dataList
  3340. edbList = append(edbList, item)
  3341. }
  3342. page = paging.GetPaging(currentIndex, pageSize, dataCount)
  3343. resp.Paging = page
  3344. resp.List = edbList
  3345. br.Ret = 200
  3346. br.Success = true
  3347. br.Msg = "获取成功"
  3348. br.Data = resp
  3349. }
  3350. // MoveEdbChartList
  3351. // @Title 获取指标/图表创建人列表数据接口
  3352. // @Description 获取指标/图表创建人列表数据接口
  3353. // @Param PageSize query int true "每页数据条数"
  3354. // @Param CurrentIndex query int true "当前页页码,从1开始"
  3355. // @Param Source query int false "来源 :1:手工数据指标 2:钢联化工数据库 3:ETA指标库 4:ETA预测指标 5:图库"
  3356. // @Param Keyword query string false "关键字,code或者名称"
  3357. // @Param Classify query string false "分类id"
  3358. // @Param UserId query int false "创建人id"
  3359. // @Success 200 {object} data_manage.ChartListResp
  3360. // @router /edb_chart/list [get]
  3361. func (this *EdbInfoController) MoveEdbChartList() {
  3362. br := new(models.BaseResponse).Init()
  3363. defer func() {
  3364. this.Data["json"] = br
  3365. this.ServeJSON()
  3366. }()
  3367. sysUser := this.SysUser
  3368. if sysUser == nil {
  3369. br.Msg = "请登录"
  3370. br.ErrMsg = "请登录,SysUser Is Empty"
  3371. br.Ret = 408
  3372. return
  3373. }
  3374. source, _ := this.GetInt("Source")
  3375. if source <= 0 || source > 5 {
  3376. br.Msg = "错误的来源"
  3377. br.IsSendEmail = false
  3378. return
  3379. }
  3380. userId, _ := this.GetInt("UserId")
  3381. keyword := this.GetString("Keyword")
  3382. classify := this.GetString("Classify")
  3383. pageSize, _ := this.GetInt("PageSize")
  3384. currentIndex, _ := this.GetInt("CurrentIndex")
  3385. var startSize int
  3386. if pageSize <= 0 {
  3387. pageSize = utils.PageSize20
  3388. }
  3389. if currentIndex <= 0 {
  3390. currentIndex = 1
  3391. }
  3392. startSize = paging.StartIndex(currentIndex, pageSize)
  3393. resp := data_manage.MoveEdbChartListResp{}
  3394. var total int
  3395. page := paging.GetPaging(currentIndex, pageSize, total)
  3396. defaultList := make([]data_manage.MoveEdbChartList, 0)
  3397. resp.List = defaultList
  3398. resp.Paging = page
  3399. // 没有传入条件,那就默认自动返回
  3400. if userId <= 0 && keyword == `` && classify == `` {
  3401. br.Ret = 200
  3402. br.Success = true
  3403. br.Msg = "获取成功"
  3404. br.Data = resp
  3405. return
  3406. }
  3407. list, total, err := data.GetMoveEdbChartList(source, userId, keyword, classify, startSize, pageSize)
  3408. if err != nil {
  3409. //br.Success = true
  3410. br.Msg = "获取失败"
  3411. br.ErrMsg = "获取失败,Err:" + err.Error()
  3412. return
  3413. }
  3414. if list == nil {
  3415. list = defaultList
  3416. }
  3417. page = paging.GetPaging(currentIndex, pageSize, total)
  3418. resp.Paging = page
  3419. resp.List = list
  3420. br.Ret = 200
  3421. br.Success = true
  3422. br.Msg = "获取成功"
  3423. br.Data = resp
  3424. }
  3425. // MoveEdbChartUser
  3426. // @Title 指标/图表创建人变更接口
  3427. // @Description 指标/图表创建人变更接口
  3428. // @Param PageSize query int true "每页数据条数"
  3429. // @Param CurrentIndex query int true "当前页页码,从1开始"
  3430. // @Param EdbInfoId query int true "指标id"
  3431. // @Param IsShowMe query bool true "是否只看我的,true、false"
  3432. // @Success 200 {object} data_manage.ChartListResp
  3433. // @router /edb_chart/change_user [post]
  3434. func (this *EdbInfoController) MoveEdbChartUser() {
  3435. br := new(models.BaseResponse).Init()
  3436. defer func() {
  3437. this.Data["json"] = br
  3438. this.ServeJSON()
  3439. }()
  3440. sysUser := this.SysUser
  3441. if sysUser == nil {
  3442. br.Msg = "请登录"
  3443. br.ErrMsg = "请登录,SysUser Is Empty"
  3444. br.Ret = 408
  3445. return
  3446. }
  3447. var req data_manage.MoveEdbChartReq
  3448. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  3449. if err != nil {
  3450. br.Msg = "参数解析异常!"
  3451. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  3452. return
  3453. }
  3454. if req.Source <= 0 || req.Source > 5 {
  3455. br.Msg = "错误的来源"
  3456. br.IsSendEmail = false
  3457. return
  3458. }
  3459. if len(req.DataIdList) <= 0 {
  3460. br.Msg = "请勾选数据项"
  3461. br.IsSendEmail = false
  3462. return
  3463. }
  3464. if req.NewUserId <= 0 {
  3465. br.Msg = "请选择新的创建人"
  3466. br.IsSendEmail = false
  3467. return
  3468. }
  3469. err, errMsg := data.MoveEdbChart(req.Source, req.NewUserId, req.DataIdList)
  3470. if err != nil {
  3471. //br.Success = true
  3472. br.Msg = "获取失败"
  3473. if errMsg != `` {
  3474. br.Msg = errMsg
  3475. }
  3476. br.ErrMsg = "获取失败,Err:" + err.Error()
  3477. return
  3478. }
  3479. br.Ret = 200
  3480. br.IsAddLog = true
  3481. br.Success = true
  3482. br.Msg = "修改成功"
  3483. }
  3484. // EdbChartClassifyList
  3485. // @Title 获取指标/图表分类列表数据接口
  3486. // @Description 获取指标/图表分类列表数据接口
  3487. // @Param Source query int false "来源 :1:手工数据指标 2:钢联化工数据库 3:ETA指标库 4:ETA预测指标 5:图库"
  3488. // @Success 200 {object} data_manage.ChartListResp
  3489. // @router /edb_chart/classify [get]
  3490. func (this *EdbInfoController) EdbChartClassifyList() {
  3491. br := new(models.BaseResponse).Init()
  3492. defer func() {
  3493. this.Data["json"] = br
  3494. this.ServeJSON()
  3495. }()
  3496. sysUser := this.SysUser
  3497. if sysUser == nil {
  3498. br.Msg = "请登录"
  3499. br.ErrMsg = "请登录,SysUser Is Empty"
  3500. br.Ret = 408
  3501. return
  3502. }
  3503. source, _ := this.GetInt("Source")
  3504. if source <= 0 || source > 5 {
  3505. br.Msg = "错误的来源"
  3506. br.IsSendEmail = false
  3507. return
  3508. }
  3509. list, err := data.GetEdbChartClassifyList(source)
  3510. if err != nil {
  3511. //br.Success = true
  3512. br.Msg = "获取失败"
  3513. br.ErrMsg = "获取失败,Err:" + err.Error()
  3514. return
  3515. }
  3516. br.Ret = 200
  3517. br.Success = true
  3518. br.Msg = "获取成功"
  3519. br.Data = list
  3520. }
  3521. // EdbInfoDataTb
  3522. // @Title 获取指标数据同比值
  3523. // @Description 获取指标数据
  3524. // @Param EdbInfoId query int true "指标ID"
  3525. // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:自定义起始时间至今,7:18年至今,8:19年至今,9:20年至今,10:全部"
  3526. // @Param StartDate query string true "自定义开始日期"
  3527. // @Param EndDate query string true "自定义结束日期"
  3528. // @Success 200 {object} data_manage.EdbInfoDataResp
  3529. // @router /edb_info/data/tb [get]
  3530. func (this *ChartInfoController) EdbInfoDataTb() {
  3531. br := new(models.BaseResponse).Init()
  3532. defer func() {
  3533. this.Data["json"] = br
  3534. this.ServeJSON()
  3535. }()
  3536. sysUser := this.SysUser
  3537. if sysUser == nil {
  3538. br.Msg = "请登录"
  3539. br.ErrMsg = "请登录,SysUser Is Empty"
  3540. br.Ret = 408
  3541. return
  3542. }
  3543. edbInfoId, _ := this.GetInt("EdbInfoId")
  3544. if edbInfoId <= 0 {
  3545. br.Msg = "参数错误"
  3546. return
  3547. }
  3548. dateType, _ := this.GetInt("DateType")
  3549. if dateType <= 0 {
  3550. dateType = 3
  3551. }
  3552. edbInfoType, _ := this.GetInt("EdbInfoType")
  3553. if edbInfoType < 0 {
  3554. edbInfoType = 1
  3555. }
  3556. startDate := this.GetString("StartDate")
  3557. endDate := this.GetString("EndDate")
  3558. startYear, _ := this.GetInt("StartYear")
  3559. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  3560. if err != nil {
  3561. br.Msg = "获取失败"
  3562. br.Msg = "获取失败,Err:" + err.Error()
  3563. return
  3564. }
  3565. maxYear := 0
  3566. if edbInfo.LatestDate != "" {
  3567. latestDateT, _ := time.Parse(utils.FormatDate, edbInfo.LatestDate)
  3568. maxYear = latestDateT.Year()
  3569. }
  3570. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, maxYear)
  3571. var startDateTime time.Time
  3572. if startDate != `` {
  3573. startDateTime, err = time.ParseInLocation(utils.FormatDate, startDate, time.Local)
  3574. if err != nil {
  3575. br.Msg = "开始日期异常"
  3576. br.Msg = "开始日期异常,Err:" + err.Error()
  3577. return
  3578. }
  3579. //同比值的计算方式,是需要与去年同期对比,所以如果用户需要某个时间段的数据的话,获取基础数据时,需要往前面推(1年+兼容的日期频度(目前是35天))
  3580. startDate = startDateTime.AddDate(-1, 0, -35).Format(utils.FormatDate)
  3581. }
  3582. tmpDataList, err := data_manage.GetEdbDataList(edbInfo.Source, edbInfoId, startDate, endDate)
  3583. if err != nil {
  3584. br.Msg = "获取失败"
  3585. br.Msg = "获取失败,Err:" + err.Error()
  3586. return
  3587. }
  3588. // 计算同比值
  3589. dataList, minValue, maxValue, err := data.GetEdbDataTbz(edbInfo, tmpDataList, startDateTime)
  3590. if err != nil {
  3591. br.Msg = "获取失败"
  3592. br.Msg = "计算同比值失败,Err:" + err.Error()
  3593. return
  3594. }
  3595. edbInfo.MaxValue = maxValue
  3596. edbInfo.MinValue = minValue
  3597. resp := new(data_manage.EdbInfoDataResp)
  3598. resp.EdbInfo = edbInfo
  3599. resp.DataList = dataList
  3600. br.Ret = 200
  3601. br.Success = true
  3602. br.Msg = "获取成功"
  3603. br.Data = resp
  3604. }
  3605. // EdbInfoDataSeasonal
  3606. // @Title 获取指标数据(季节性)
  3607. // @Description 获取指标数据
  3608. // @Param EdbInfoId query int true "指标ID"
  3609. // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:自定义起始时间至今,7:18年至今,8:19年至今,9:20年至今,10:全部"
  3610. // @Param StartDate query string true "自定义开始日期"
  3611. // @Param EndDate query string true "自定义结束日期"
  3612. // @Param Calendar query string true "公历/农历"
  3613. // @Success 200 {object} data_manage.EdbInfoDataResp
  3614. // @router /edb_info/data/seasonal [get]
  3615. func (this *ChartInfoController) EdbInfoDataSeasonal() {
  3616. br := new(models.BaseResponse).Init()
  3617. defer func() {
  3618. this.Data["json"] = br
  3619. this.ServeJSON()
  3620. }()
  3621. sysUser := this.SysUser
  3622. if sysUser == nil {
  3623. br.Msg = "请登录"
  3624. br.ErrMsg = "请登录,SysUser Is Empty"
  3625. br.Ret = 408
  3626. return
  3627. }
  3628. dateType, _ := this.GetInt("DateType")
  3629. startDate := this.GetString("StartDate")
  3630. endDate := this.GetString("EndDate")
  3631. startYear, _ := this.GetInt("StartYear")
  3632. edbInfoIdStr := this.GetString("EdbInfoId")
  3633. edbInfoId, err := strconv.Atoi(edbInfoIdStr)
  3634. if err != nil {
  3635. br.Msg = "指标id异常"
  3636. br.Msg = "指标id转换异常,Err:" + err.Error()
  3637. return
  3638. }
  3639. fmt.Println("startDate:", startDate)
  3640. fmt.Println("endDate:", endDate)
  3641. calendar := this.GetString("Calendar")
  3642. if calendar == "" {
  3643. calendar = "公历"
  3644. }
  3645. if dateType == 0 {
  3646. if startDate == "" {
  3647. dateType = utils.DateTypeNYears
  3648. } else {
  3649. dateType = 5
  3650. }
  3651. }
  3652. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  3653. if err != nil {
  3654. br.Msg = "获取失败"
  3655. br.Msg = "获取失败,Err:" + err.Error()
  3656. return
  3657. }
  3658. maxYear := 0
  3659. if edbInfo.LatestDate != "" {
  3660. latestDateT, _ := time.Parse(utils.FormatDate, edbInfo.LatestDate)
  3661. maxYear = latestDateT.Year()
  3662. }
  3663. startDate, endDate = utils.GetDateByDateTypeV2(dateType, startDate, endDate, startYear, maxYear)
  3664. dataList, err := data.GetChartEdbSeasonalData(calendar, startDate, endDate, edbInfo)
  3665. if err != nil {
  3666. br.Msg = "获取失败"
  3667. br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
  3668. return
  3669. }
  3670. resp := new(data_manage.EdbInfoDataSeasonalResp)
  3671. resp.EdbInfo = edbInfo
  3672. resp.DataList = dataList
  3673. br.Ret = 200
  3674. br.Success = true
  3675. br.Msg = "获取成功"
  3676. br.Data = resp
  3677. }
  3678. // SetEdbDataInsertConfig 设置插入值
  3679. // @Title 设置插入值接口
  3680. // @Description 设置插入值接口
  3681. // @Success 200 {object} data_manage.EditEdbEnInfoReq
  3682. // @router /edb_info/insert_config/set [post]
  3683. func (this *EdbInfoController) SetEdbDataInsertConfig() {
  3684. br := new(models.BaseResponse).Init()
  3685. defer func() {
  3686. this.Data["json"] = br
  3687. this.ServeJSON()
  3688. }()
  3689. sysUser := this.SysUser
  3690. if sysUser == nil {
  3691. br.Msg = "请登录"
  3692. br.ErrMsg = "请登录,SysUser Is Empty"
  3693. br.Ret = 408
  3694. return
  3695. }
  3696. var req data_manage.SetEdbDataInsertConfigReq
  3697. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  3698. if err != nil {
  3699. br.Msg = "参数解析异常!"
  3700. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  3701. return
  3702. }
  3703. dateStr := req.Date
  3704. if dateStr == `` {
  3705. br.Msg = "请选择日期"
  3706. br.IsSendEmail = false
  3707. return
  3708. }
  3709. date, err := time.ParseInLocation(utils.FormatDate, dateStr, time.Local)
  3710. if err != nil {
  3711. br.Msg = "日期异常"
  3712. br.ErrMsg = "日期异常,err:" + err.Error()
  3713. br.IsSendEmail = false
  3714. return
  3715. }
  3716. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  3717. if err != nil {
  3718. br.Msg = "获取指标信息失败"
  3719. br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
  3720. return
  3721. }
  3722. err, errMsg, isSendEmail := data_manage.CreateEdbDataInsertConfigAndData(edbInfo, date, req.Value)
  3723. if err != nil {
  3724. br.Msg = "设置失败"
  3725. if errMsg != `` {
  3726. br.Msg = errMsg
  3727. }
  3728. br.ErrMsg = "修改失败,Err:" + err.Error()
  3729. br.IsSendEmail = isSendEmail
  3730. return
  3731. }
  3732. //新增操作日志
  3733. {
  3734. edbLog := new(data_manage.EdbInfoLog)
  3735. edbLog.EdbInfoId = edbInfo.EdbInfoId
  3736. edbLog.SourceName = edbInfo.SourceName
  3737. edbLog.Source = edbInfo.Source
  3738. edbLog.EdbCode = edbInfo.EdbCode
  3739. edbLog.EdbName = edbInfo.EdbName
  3740. edbLog.ClassifyId = edbInfo.ClassifyId
  3741. edbLog.SysUserId = sysUser.AdminId
  3742. edbLog.SysUserRealName = sysUser.RealName
  3743. edbLog.CreateTime = time.Now()
  3744. edbLog.Content = string(this.Ctx.Input.RequestBody)
  3745. edbLog.Status = "设置插入值"
  3746. edbLog.Method = this.Ctx.Input.URI()
  3747. go data_manage.AddEdbInfoLog(edbLog)
  3748. }
  3749. br.Ret = 200
  3750. br.Success = true
  3751. br.Msg = "保存成功"
  3752. br.IsAddLog = true
  3753. }
  3754. // TraceEdbInfo
  3755. // @Title 指标溯源接口
  3756. // @Description 指标溯源接口
  3757. // @Param EdbInfoId query int true "指标id"
  3758. // @Success 200 {object} data_manage.ChartListResp
  3759. // @router /edb_info/trace [get]
  3760. func (this *EdbInfoController) TraceEdbInfo() {
  3761. br := new(models.BaseResponse).Init()
  3762. defer func() {
  3763. this.Data["json"] = br
  3764. this.ServeJSON()
  3765. }()
  3766. sysUser := this.SysUser
  3767. if sysUser == nil {
  3768. br.Msg = "请登录"
  3769. br.ErrMsg = "请登录,SysUser Is Empty"
  3770. br.Ret = 408
  3771. return
  3772. }
  3773. edbInfoId, _ := this.GetInt("EdbInfoId")
  3774. if edbInfoId <= 0 {
  3775. br.Msg = "参数错误"
  3776. br.ErrMsg = "参数错误"
  3777. return
  3778. }
  3779. resp, err := data.TraceEdbInfoByEdbInfoId(edbInfoId)
  3780. if err != nil {
  3781. br.Msg = "获取失败"
  3782. br.Msg = "获取失败,Err:" + err.Error()
  3783. return
  3784. }
  3785. br.Ret = 200
  3786. br.Data = resp
  3787. br.Success = true
  3788. br.Msg = "刷新成功"
  3789. }
  3790. // AllEdbInfoByEs
  3791. // @Title 所有指标筛选接口
  3792. // @Description 所有指标筛选接口
  3793. // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
  3794. // @Param FilterSource query int false "搜索来源:1:其他搜索,2:累计值转月值搜索,3:变频,4:基础指标,5:同比"
  3795. // @Param Frequency query string false "频度"
  3796. // @Param IsAddPredictEdb query bool false "是否查询添加预测指标"
  3797. // @Param PageSize query int true "每页数据条数"
  3798. // @Param CurrentIndex query int true "当前页页码,从1开始"
  3799. // @Success 200 {object} data_manage.EdbInfoList
  3800. // @router /edb_info/filter_by_es/all [get]
  3801. func (this *EdbInfoController) AllEdbInfoByEs() {
  3802. br := new(models.BaseResponse).Init()
  3803. defer func() {
  3804. this.Data["json"] = br
  3805. this.ServeJSON()
  3806. }()
  3807. pageSize, _ := this.GetInt("PageSize")
  3808. currentIndex, _ := this.GetInt("CurrentIndex")
  3809. var total int64
  3810. var startSize int
  3811. if pageSize <= 0 {
  3812. pageSize = utils.PageSize20
  3813. }
  3814. if currentIndex <= 0 {
  3815. currentIndex = 1
  3816. }
  3817. startSize = paging.StartIndex(currentIndex, pageSize)
  3818. keyWord := this.GetString("KeyWord")
  3819. keyWord = strings.TrimSpace(keyWord) //移除字符串首尾空格
  3820. filterSource, _ := this.GetInt("FilterSource")
  3821. if filterSource <= 0 {
  3822. filterSource = 1
  3823. }
  3824. //指标来源
  3825. source, _ := this.GetInt("Source")
  3826. frequency := this.GetString("Frequency") //频度
  3827. isAddPredictEdb, _ := this.GetBool("IsAddPredictEdb") //是否查询添加预测指标
  3828. var edbInfoList []*data_manage.EdbInfoList
  3829. var err error
  3830. noPermissionEdbInfoIdList := make([]int, 0) //无权限指标
  3831. // 获取当前账号的不可见指标
  3832. {
  3833. obj := data_manage.EdbInfoNoPermissionAdmin{}
  3834. confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
  3835. if err != nil && err.Error() != utils.ErrNoRow() {
  3836. br.Msg = "获取失败"
  3837. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
  3838. return
  3839. }
  3840. for _, v := range confList {
  3841. noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
  3842. }
  3843. }
  3844. if keyWord != "" {
  3845. var keyWordArr []string
  3846. keyWordArr = append(keyWordArr, keyWord)
  3847. newKeyWord := strings.Split(keyWord, " ")
  3848. keyWordArr = append(keyWordArr, newKeyWord...)
  3849. // 普通的搜索
  3850. total, edbInfoList, err = elastic.SearchEdbInfoData(utils.DATA_INDEX_NAME, keyWord, startSize, pageSize, filterSource, source, -1, ``, noPermissionEdbInfoIdList)
  3851. } else {
  3852. var condition string
  3853. var pars []interface{}
  3854. // 普通指标
  3855. condition += ` AND edb_info_type = ? `
  3856. pars = append(pars, 0)
  3857. // 无权限指标id
  3858. lenNoPermissionEdbInfoIdList := len(noPermissionEdbInfoIdList)
  3859. if lenNoPermissionEdbInfoIdList > 0 {
  3860. condition += ` AND edb_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionEdbInfoIdList) + `) `
  3861. pars = append(pars, noPermissionEdbInfoIdList)
  3862. }
  3863. switch filterSource {
  3864. case 2:
  3865. condition += ` AND frequency='月度' `
  3866. case 3:
  3867. condition += ` AND frequency <> '日度' `
  3868. case 4:
  3869. condition += ` AND edb_type = 1 `
  3870. case 5:
  3871. condition += ` AND source = 6 ` //来源(同比值)
  3872. case 6:
  3873. condition += ` AND frequency != ? `
  3874. pars = append(pars, "年度")
  3875. }
  3876. //频度
  3877. if frequency != "" {
  3878. condition += ` AND frequency = ? `
  3879. pars = append(pars, frequency)
  3880. }
  3881. // 查询只允许添加预测指标的搜索
  3882. if isAddPredictEdb {
  3883. condition += ` AND frequency in ("日度","周度","月度") `
  3884. }
  3885. total, edbInfoList, err = data_manage.GetEdbInfoFilterList(condition, pars, startSize, pageSize)
  3886. }
  3887. if err != nil {
  3888. edbInfoList = make([]*data_manage.EdbInfoList, 0)
  3889. }
  3890. page := paging.GetPaging(currentIndex, pageSize, int(total))
  3891. edbInfoListLen := len(edbInfoList)
  3892. for i := 0; i < edbInfoListLen; i++ {
  3893. edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName
  3894. }
  3895. for i := 0; i < edbInfoListLen; i++ {
  3896. for j := 0; j < edbInfoListLen; j++ {
  3897. if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
  3898. (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
  3899. !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
  3900. edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
  3901. }
  3902. }
  3903. }
  3904. //新增搜索词记录
  3905. {
  3906. searchKeyword := new(data_manage.SearchKeyword)
  3907. searchKeyword.KeyWord = keyWord
  3908. searchKeyword.CreateTime = time.Now()
  3909. go data_manage.AddSearchKeyword(searchKeyword)
  3910. }
  3911. resp := data_manage.EdbInfoFilterDataResp{
  3912. Paging: page,
  3913. List: edbInfoList,
  3914. }
  3915. br.Ret = 200
  3916. br.Success = true
  3917. br.Msg = "获取成功"
  3918. br.Data = resp
  3919. }
  3920. // GetEdbDateData
  3921. // @Title 根据指标ID和具体日期获取对应日期的数据值
  3922. // @Description 根据指标ID和具体日期获取对应日期的数据值
  3923. // @Param EdbInfoId query int false "指标id"
  3924. // @Param Date query string false "日期"
  3925. // @Success 200 {object} data_manage.EdbInfoList
  3926. // @router /edb_info/date_data [get]
  3927. func (this *EdbInfoController) GetEdbDateData() {
  3928. br := new(models.BaseResponse).Init()
  3929. defer func() {
  3930. this.Data["json"] = br
  3931. this.ServeJSON()
  3932. }()
  3933. edbInfoId, _ := this.GetInt("EdbInfoId")
  3934. date := this.GetString("Date")
  3935. if edbInfoId <= 0 {
  3936. br.Msg = "请选择指标"
  3937. br.IsSendEmail = false
  3938. return
  3939. }
  3940. if date == `` {
  3941. br.Msg = "请选择日期"
  3942. br.IsSendEmail = false
  3943. return
  3944. }
  3945. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  3946. if err != nil {
  3947. br.Msg = "获取失败"
  3948. br.ErrMsg = fmt.Sprint("获取指标信息失败,Err:", err.Error())
  3949. return
  3950. }
  3951. startDate := date
  3952. endDate := date
  3953. dateType := "day"
  3954. //如果填写的是月度日期
  3955. if strings.Count(date, "-") == 1 {
  3956. startDate = date + "-01"
  3957. endDate = ``
  3958. dateType = "month"
  3959. }
  3960. dataItem, err := data.GetDateData(edbInfo, startDate, endDate)
  3961. if err != nil {
  3962. br.Msg = "获取失败"
  3963. br.ErrMsg = fmt.Sprint("获取指数据失败,Err:", err.Error())
  3964. return
  3965. }
  3966. val := ``
  3967. if dataItem != nil {
  3968. switch dateType {
  3969. case "month":
  3970. dateTime, _ := time.ParseInLocation(utils.FormatDate, dataItem.DataTime, time.Local)
  3971. dateTimeStr := dateTime.Format(utils.FormatYearMonthDate)
  3972. if dateTimeStr != date {
  3973. val = ``
  3974. }
  3975. }
  3976. val = fmt.Sprint(dataItem.Value)
  3977. }
  3978. br.Ret = 200
  3979. br.Success = true
  3980. br.Msg = "获取成功"
  3981. br.Data = val
  3982. }
  3983. // GetEdbBeforeAndAfterDateData
  3984. // @Title 根据指标ID和具体日期获取对应日期的数据值+前后几期
  3985. // @Description 根据指标ID和具体日期获取对应日期的数据值+前后几期
  3986. // @Param EdbInfoId query int false "指标id"
  3987. // @Param Date query string false "日期"
  3988. // @Param Num query int false "前后几期数据"
  3989. // @Success 200 {object} data_manage.EdbInfoList
  3990. // @router /edb_info/date_data/before_after [get]
  3991. func (this *EdbInfoController) GetEdbBeforeAndAfterDateData() {
  3992. br := new(models.BaseResponse).Init()
  3993. defer func() {
  3994. this.Data["json"] = br
  3995. this.ServeJSON()
  3996. }()
  3997. edbInfoId, _ := this.GetInt("EdbInfoId")
  3998. date := this.GetString("Date")
  3999. num, _ := this.GetInt("Num")
  4000. // 默认2期数据
  4001. if num <= 0 {
  4002. num = 2
  4003. }
  4004. if edbInfoId <= 0 {
  4005. br.Msg = "请选择指标"
  4006. br.IsSendEmail = false
  4007. return
  4008. }
  4009. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  4010. if err != nil {
  4011. br.Msg = "获取失败"
  4012. br.ErrMsg = fmt.Sprint("获取指标信息失败,Err:", err.Error())
  4013. return
  4014. }
  4015. // 当前日期
  4016. var currDate string
  4017. // 是否查找之后的数据
  4018. isFindAfter := true
  4019. if date == `` {
  4020. currDate = edbInfo.EndDate
  4021. isFindAfter = false
  4022. if num <= 0 {
  4023. num = 4 //默认获取前面的几期数据
  4024. }
  4025. }
  4026. dataList := make([]*data_manage.EdbDataList, 0)
  4027. startDate := date
  4028. // 指定日期的类型
  4029. dateType := "day"
  4030. //如果填写的是月度日期
  4031. if strings.Count(date, "-") == 1 {
  4032. startDate = date + "-01"
  4033. dateType = "month"
  4034. }
  4035. resp := data_manage.BeforeAndAfterDateDataResp{
  4036. List: dataList,
  4037. Date: "",
  4038. }
  4039. // 后面的数据
  4040. afterList := make([]*data_manage.EdbDataList, 0)
  4041. if isFindAfter {
  4042. afterList, err = data.GetEdbBeforeAndAfterDateData(edbInfo, startDate, "", 2, num)
  4043. if err != nil {
  4044. br.Msg = "获取失败"
  4045. br.ErrMsg = fmt.Sprint("获取后面的指数据失败,Err:", err.Error())
  4046. return
  4047. }
  4048. lenBeforeList := len(afterList)
  4049. if lenBeforeList <= 0 {
  4050. br.Ret = 200
  4051. br.Success = true
  4052. br.Msg = "所选指标所选日期无值"
  4053. br.Data = resp
  4054. return
  4055. } else {
  4056. var dateTimeStr string
  4057. switch dateType {
  4058. case "month":
  4059. dateTime, _ := time.ParseInLocation(utils.FormatDate, afterList[0].DataTime, time.Local)
  4060. dateTimeStr = dateTime.Format(utils.FormatYearMonthDate)
  4061. case "day":
  4062. dateTimeStr = afterList[0].DataTime
  4063. }
  4064. currDate = afterList[0].DataTime
  4065. // 如果对应日期找不到,那么就直接返回吧
  4066. if dateTimeStr != date {
  4067. br.Ret = 200
  4068. br.Success = true
  4069. br.Msg = "所选指标所选日期无值"
  4070. br.Data = resp
  4071. return
  4072. }
  4073. }
  4074. }
  4075. // 前面的数据
  4076. beforeList, err := data.GetEdbBeforeAndAfterDateData(edbInfo, "", currDate, 1, num)
  4077. if err != nil {
  4078. br.Msg = "获取失败"
  4079. br.ErrMsg = fmt.Sprint("获取前面的指数据失败,Err:", err.Error())
  4080. return
  4081. }
  4082. dataList = append(dataList, beforeList...)
  4083. // 后面的数据
  4084. if len(afterList) > 0 {
  4085. if len(beforeList) > 0 {
  4086. dataList = append(dataList, afterList[1:]...)
  4087. } else {
  4088. dataList = append(dataList, afterList...)
  4089. }
  4090. }
  4091. // 数据翻转
  4092. for i, j := 0, len(dataList)-1; i < j; i, j = i+1, j-1 {
  4093. dataList[i], dataList[j] = dataList[j], dataList[i]
  4094. }
  4095. resp.List = dataList
  4096. // 前端不传入日期的时候,这个J皮不让返回这个字段,要不然他会颜色标记
  4097. if date != `` {
  4098. resp.Date = currDate
  4099. }
  4100. br.Ret = 200
  4101. br.Success = true
  4102. br.Msg = "获取成功"
  4103. br.Data = resp
  4104. }
  4105. // EdbChartAdminList
  4106. // @Title 获取创建人员分组
  4107. // @Description 获取创建人员分组
  4108. // @Param Source query int false "来源 :1:手工数据指标 2:钢联化工数据库 3:ETA指标库 4:ETA预测指标 5:图库"
  4109. // @Success 200 {object} company.DepartmentGroupSellersResp
  4110. // @router /edb_chart/adminList [get]
  4111. func (this *EdbInfoController) EdbChartAdminList() {
  4112. br := new(models.BaseResponse).Init()
  4113. defer func() {
  4114. this.Data["json"] = br
  4115. this.ServeJSON()
  4116. }()
  4117. sysUser := this.SysUser
  4118. if sysUser == nil {
  4119. br.Msg = "请登录"
  4120. br.ErrMsg = "请登录,SysUser Is Empty"
  4121. br.Ret = 408
  4122. return
  4123. }
  4124. source, _ := this.GetInt("Source", 0)
  4125. if source <= 0 || source > 5 {
  4126. br.Msg = "错误的来源"
  4127. br.IsSendEmail = false
  4128. return
  4129. }
  4130. idList, err := data.GetEdbChartAdminList(source)
  4131. if err != nil {
  4132. //br.Success = true
  4133. br.Msg = "获取失败"
  4134. br.ErrMsg = "获取失败,Err:" + err.Error()
  4135. return
  4136. }
  4137. fmt.Println("idlist:", idList)
  4138. systemAdminMap := make(map[int]*system.Admin)
  4139. departmentMap := make(map[string]string)
  4140. departmentAdminMap := make(map[int]string)
  4141. groupMap := make(map[string]string)
  4142. systemAdminList, err := system.GetAdminListByIdListWithoutEnable(idList)
  4143. if err != nil {
  4144. br.Msg = "获取用户列表失败"
  4145. br.ErrMsg = "获取用户列表失败,Err:" + err.Error()
  4146. return
  4147. }
  4148. for _, v := range systemAdminList {
  4149. systemAdminMap[v.AdminId] = v
  4150. departmentMap[v.DepartmentName] = v.DepartmentName
  4151. departmentAdminMap[v.AdminId] = v.DepartmentName
  4152. groupMap[v.GroupName+v.DepartmentName] = v.DepartmentName
  4153. }
  4154. depList := make([]company.DepartmentGroupAdmins, 0)
  4155. i := 1
  4156. for _, v := range departmentMap {
  4157. item := company.DepartmentGroupAdmins{
  4158. AdminId: "dep_" + strconv.Itoa(i),
  4159. RealName: v,
  4160. }
  4161. i++
  4162. depList = append(depList, item)
  4163. }
  4164. for k := 0; k < len(depList); k++ {
  4165. for k1, v1 := range groupMap {
  4166. if v1 == depList[k].RealName && v1 != "" {
  4167. item := &company.DepartmentGroupAdmins{
  4168. AdminId: "group_" + strconv.Itoa(k),
  4169. RealName: strings.Replace(k1, v1, "", -1),
  4170. }
  4171. depList[k].ChildrenList = append(depList[k].ChildrenList, item)
  4172. }
  4173. }
  4174. }
  4175. for _, admin := range systemAdminList {
  4176. for i, v := range depList {
  4177. for k, group := range v.ChildrenList {
  4178. if admin.GroupName == group.RealName && admin.DepartmentName == v.RealName {
  4179. item := &company.DepartmentGroupAdmins{
  4180. AdminId: strconv.Itoa(admin.AdminId),
  4181. RealName: admin.RealName,
  4182. RoleTypeCode: admin.RoleTypeCode,
  4183. Authority: admin.Authority,
  4184. }
  4185. if group.RealName != "" {
  4186. depList[i].ChildrenList[k].ChildrenList = append(depList[i].ChildrenList[k].ChildrenList, item)
  4187. } else {
  4188. depList[i].ChildrenList = append(depList[i].ChildrenList, item)
  4189. }
  4190. }
  4191. }
  4192. }
  4193. }
  4194. for i, groupList := range depList {
  4195. for k, v := range groupList.ChildrenList {
  4196. if v.RealName == "" {
  4197. newChildrenList := append(groupList.ChildrenList[:k], groupList.ChildrenList[k+1:]...)
  4198. depList[i].ChildrenList = newChildrenList
  4199. }
  4200. }
  4201. }
  4202. br.Ret = 200
  4203. br.Success = true
  4204. br.Msg = "获取成功"
  4205. br.Data = depList
  4206. }
  4207. // EdbSourceList
  4208. // @Title 指标来源列表
  4209. // @Description 指标来源列表
  4210. // @Param IsBase query int false "是否为基础指标: 1-是"
  4211. // @Success 200 {object} data_manage.EdbInfoListResp
  4212. // @router /edb_source/list [get]
  4213. func (this *EdbInfoController) EdbSourceList() {
  4214. br := new(models.BaseResponse).Init()
  4215. defer func() {
  4216. if br.ErrMsg == "" {
  4217. br.IsSendEmail = false
  4218. }
  4219. this.Data["json"] = br
  4220. this.ServeJSON()
  4221. }()
  4222. isBase, _ := this.GetInt("IsBase", 0)
  4223. cond := ``
  4224. if isBase > 0 {
  4225. cond = ` AND is_base = 1`
  4226. }
  4227. pars := make([]interface{}, 0)
  4228. list, e := data_manage.GetEdbSourceItemsByCondition(cond, pars, []string{}, "")
  4229. if e != nil {
  4230. br.Msg = "获取失败"
  4231. br.ErrMsg = "获取指标来源列表失败, Err: " + e.Error()
  4232. return
  4233. }
  4234. br.Data = list
  4235. br.Ret = 200
  4236. br.Success = true
  4237. br.Msg = "获取成功"
  4238. }
  4239. // EdbSourceListByPython
  4240. // @Title 指标来源列表
  4241. // @Description 指标来源列表
  4242. // @Param IsBase query int false "是否为基础指标: 1-是"
  4243. // @Success 200 {object} data_manage.EdbInfoListResp
  4244. // @router /edb_source/list/python [get]
  4245. func (this *EdbInfoController) EdbSourceListByPython() {
  4246. br := new(models.BaseResponse).Init()
  4247. defer func() {
  4248. if br.ErrMsg == "" {
  4249. br.IsSendEmail = false
  4250. }
  4251. this.Data["json"] = br
  4252. this.ServeJSON()
  4253. }()
  4254. isBase, _ := this.GetInt("IsBase", 0)
  4255. cond := ``
  4256. if isBase > 0 {
  4257. cond = ` AND is_base = 1`
  4258. }
  4259. pars := make([]interface{}, 0)
  4260. list, e := data_manage.GetEdbSourceItemsByCondition(cond, pars, []string{}, "")
  4261. if e != nil {
  4262. br.Msg = "获取失败"
  4263. br.ErrMsg = "获取指标来源列表失败, Err: " + e.Error()
  4264. return
  4265. }
  4266. baseEdbList := make([]data_manage.EdbSourceChild, 0)
  4267. calEdbList := make([]data_manage.EdbSourceChild, 0)
  4268. for _, v := range list {
  4269. switch v.IsBase {
  4270. case 1:
  4271. baseEdbList = append(baseEdbList, data_manage.EdbSourceChild{
  4272. EdbSourceId: v.EdbSourceId,
  4273. SourceName: v.SourceName,
  4274. IsBase: v.IsBase,
  4275. TableName: v.TableName,
  4276. Child: []data_manage.EdbSourceChild{},
  4277. })
  4278. case 2:
  4279. calEdbList = append(calEdbList, data_manage.EdbSourceChild{
  4280. EdbSourceId: v.EdbSourceId,
  4281. SourceName: v.SourceName,
  4282. IsBase: v.IsBase,
  4283. TableName: v.TableName,
  4284. Child: []data_manage.EdbSourceChild{},
  4285. })
  4286. }
  4287. }
  4288. resp := []data_manage.EdbSourceChild{
  4289. {
  4290. EdbSourceId: 0,
  4291. SourceName: "基础指标",
  4292. IsBase: 1,
  4293. Child: baseEdbList,
  4294. },
  4295. {
  4296. EdbSourceId: 0,
  4297. SourceName: "计算指标",
  4298. IsBase: 1,
  4299. Child: calEdbList,
  4300. },
  4301. }
  4302. br.Data = resp
  4303. br.Ret = 200
  4304. br.Success = true
  4305. br.Msg = "获取成功"
  4306. }
  4307. // EdbChartList
  4308. // @Title 指标缩略图列表接口
  4309. // @Description 指标缩略图列表接口
  4310. // @Param PageSize query int true "每页数据条数"
  4311. // @Param CurrentIndex query int true "当前页页码,从1开始"
  4312. // @Param ClassifyId query int true "分类id"
  4313. // @Param AdminId query int false "创建人id"
  4314. // @Param IsOnlyMe query bool false "是否只看我的"
  4315. // @Success 200 {object} response.EdbInfoChartListResp
  4316. // @router /edb_info/chart/list [get]
  4317. func (this *EdbInfoController) EdbChartList() {
  4318. br := new(models.BaseResponse).Init()
  4319. defer func() {
  4320. if br.ErrMsg == "" {
  4321. br.IsSendEmail = false
  4322. }
  4323. this.Data["json"] = br
  4324. this.ServeJSON()
  4325. }()
  4326. sysUser := this.SysUser
  4327. if sysUser == nil {
  4328. br.Msg = "请登录"
  4329. br.ErrMsg = "请登录,SysUser Is Empty"
  4330. br.Ret = 408
  4331. return
  4332. }
  4333. // 分页
  4334. pageSize, _ := this.GetInt("PageSize")
  4335. currentIndex, _ := this.GetInt("CurrentIndex")
  4336. var total int
  4337. page := paging.GetPaging(currentIndex, pageSize, total)
  4338. var startSize int
  4339. if pageSize <= 0 {
  4340. pageSize = utils.PageSize20
  4341. }
  4342. if currentIndex <= 0 {
  4343. currentIndex = 1
  4344. }
  4345. startSize = paging.StartIndex(currentIndex, pageSize)
  4346. // 基础指标
  4347. var condition string
  4348. var pars []interface{}
  4349. condition += ` AND edb_info_type = ? `
  4350. pars = append(pars, 0)
  4351. // 分类筛选
  4352. classifyId, _ := this.GetInt("ClassifyId")
  4353. if classifyId > 0 {
  4354. childClassify, e, _ := data.GetChildClassifyByClassifyId(classifyId)
  4355. if e != nil && e.Error() != utils.ErrNoRow() {
  4356. br.Msg = "获取失败"
  4357. br.ErrMsg = "获取分类信息失败, GetEdbClassify,Err:" + e.Error()
  4358. return
  4359. }
  4360. var classifyIds []int
  4361. for _, v := range childClassify {
  4362. classifyIds = append(classifyIds, v.ClassifyId)
  4363. }
  4364. condition += fmt.Sprintf(` AND classify_id IN (%s) `, utils.GetOrmInReplace(len(classifyIds)))
  4365. pars = append(pars, classifyIds)
  4366. }
  4367. // 创建人
  4368. adminId, _ := this.GetInt("AdminId")
  4369. if adminId > 0 {
  4370. condition += ` AND sys_user_id = ? `
  4371. pars = append(pars, adminId)
  4372. }
  4373. // 只看我的
  4374. isOnlyMe, _ := this.GetBool("IsOnlyMe")
  4375. if isOnlyMe {
  4376. condition += ` AND sys_user_id = ? `
  4377. pars = append(pars, sysUser.AdminId)
  4378. }
  4379. // 获取当前账号的不可见指标
  4380. obj := data_manage.EdbInfoNoPermissionAdmin{}
  4381. confList, e := obj.GetAllListByAdminId(this.SysUser.AdminId)
  4382. if e != nil {
  4383. br.Msg = "获取失败"
  4384. br.ErrMsg = "获取不可见指标配置数据失败,Err:" + e.Error()
  4385. return
  4386. }
  4387. noPermissionEdbInfoIdList := make([]int, 0)
  4388. for _, v := range confList {
  4389. noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
  4390. }
  4391. noPermissionEdbInfoIdNum := len(noPermissionEdbInfoIdList)
  4392. if noPermissionEdbInfoIdNum > 0 {
  4393. condition += ` AND edb_info_id NOT IN (` + utils.GetOrmInReplace(noPermissionEdbInfoIdNum) + `) `
  4394. pars = append(pars, noPermissionEdbInfoIdList)
  4395. }
  4396. // 获取指标信息
  4397. dataCount, list, e := data_manage.GetEdbInfoFilterList(condition, pars, startSize, pageSize)
  4398. if e != nil {
  4399. br.Msg = "获取失败"
  4400. br.ErrMsg = "获取普通指标列表失败, Err:" + e.Error()
  4401. return
  4402. }
  4403. if len(list) == 0 {
  4404. list = make([]*data_manage.EdbInfoList, 0)
  4405. } else {
  4406. for _, v := range list {
  4407. v.Button = data.GetEdbOpButton(sysUser, v.SysUserId, v.EdbType, v.EdbInfoType)
  4408. }
  4409. page = paging.GetPaging(currentIndex, pageSize, int(dataCount))
  4410. }
  4411. resp := response.EdbInfoChartListResp{
  4412. Paging: page,
  4413. List: list,
  4414. }
  4415. br.Ret = 200
  4416. br.Success = true
  4417. br.Msg = "获取成功"
  4418. br.Data = resp
  4419. }
  4420. // Modify
  4421. // @Title 修改指标信息接口
  4422. // @Description 编辑指标接口
  4423. // @Success 200 string "操作成功"
  4424. // @router /edb_info/modify [post]
  4425. func (this *EdbInfoController) Modify() {
  4426. br := new(models.BaseResponse).Init()
  4427. defer func() {
  4428. if br.ErrMsg == "" {
  4429. br.IsSendEmail = false
  4430. }
  4431. this.Data["json"] = br
  4432. this.ServeJSON()
  4433. }()
  4434. sysUser := this.SysUser
  4435. if sysUser == nil {
  4436. br.Msg = "请登录"
  4437. br.ErrMsg = "请登录,SysUser Is Empty"
  4438. br.Ret = 408
  4439. return
  4440. }
  4441. var req request.ModifyEdbInfoReq
  4442. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  4443. if err != nil {
  4444. br.Msg = "参数解析异常!"
  4445. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  4446. return
  4447. }
  4448. edbInfoId := req.EdbInfoId
  4449. if edbInfoId <= 0 {
  4450. br.Msg = "请选择指标"
  4451. br.IsSendEmail = false
  4452. return
  4453. }
  4454. edbInfo, e := data_manage.GetEdbInfoById(req.EdbInfoId)
  4455. if e != nil {
  4456. br.Msg = "操作失败"
  4457. br.ErrMsg = "获取指标信息失败, Err:" + err.Error()
  4458. return
  4459. }
  4460. // 编辑权限校验
  4461. button := data.GetEdbOpButton(this.SysUser, edbInfo.SysUserId, edbInfo.EdbType, edbInfo.EdbInfoType)
  4462. if !button.OpButton {
  4463. br.Msg = "无权限操作"
  4464. return
  4465. }
  4466. edbInfo.MaxValue = req.MaxValue
  4467. edbInfo.MinValue = req.MinValue
  4468. edbInfo.ManualSave = 1
  4469. edbInfo.ModifyTime = time.Now()
  4470. err = edbInfo.Update([]string{"MaxValue", "MinValue", "ManualSave", "ModifyTime"})
  4471. if err != nil {
  4472. br.Msg = "获取失败"
  4473. br.ErrMsg = "获取失败,Err:" + err.Error()
  4474. return
  4475. }
  4476. //修改es
  4477. data.AddOrEditEdbInfoToEs(edbInfo.EdbInfoId)
  4478. br.Ret = 200
  4479. br.Success = true
  4480. br.Msg = "修改成功"
  4481. br.IsAddLog = true
  4482. }
  4483. // ChartImageSet
  4484. // @Title 设置指标的图表图片
  4485. // @Description 设置指标的图表图片接口
  4486. // @Param request body data_manage.SetChartInfoImageReq true "type json string"
  4487. // @Success Ret=200 保存成功
  4488. // @router /edb_info/image/set [post]
  4489. func (this *EdbInfoController) ChartImageSet() {
  4490. br := new(models.BaseResponse).Init()
  4491. defer func() {
  4492. if br.ErrMsg == "" {
  4493. br.IsSendEmail = false
  4494. }
  4495. this.Data["json"] = br
  4496. this.ServeJSON()
  4497. }()
  4498. sysUser := this.SysUser
  4499. if sysUser == nil {
  4500. br.Msg = "请登录"
  4501. br.ErrMsg = "请登录,SysUser Is Empty"
  4502. br.Ret = 408
  4503. return
  4504. }
  4505. var req data_manage.SetEdbInfoImageReq
  4506. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  4507. br.Msg = "参数解析异常!"
  4508. br.ErrMsg = "参数解析失败,Err:" + e.Error()
  4509. return
  4510. }
  4511. if req.EdbInfoId <= 0 || req.ImageUrl == "" {
  4512. br.Ret = 200
  4513. br.Success = true
  4514. br.Msg = "保存成功"
  4515. return
  4516. }
  4517. edbInfo, e := data_manage.GetEdbInfoById(req.EdbInfoId)
  4518. if e != nil {
  4519. if e.Error() == utils.ErrNoRow() {
  4520. br.Msg = "找不到该指标"
  4521. return
  4522. }
  4523. br.Msg = "保存失败"
  4524. br.ErrMsg = "获取指标失败, Err:" + e.Error()
  4525. return
  4526. }
  4527. edbInfo.ChartImage = req.ImageUrl
  4528. if e = edbInfo.Update([]string{"ChartImage"}); e != nil {
  4529. br.Msg = "保存失败"
  4530. br.ErrMsg = "更新指标缩略图失败, Err:" + e.Error()
  4531. return
  4532. }
  4533. // 修改es数据
  4534. go data.AddOrEditEdbInfoToEs(req.EdbInfoId)
  4535. br.Ret = 200
  4536. br.Success = true
  4537. br.Msg = "保存成功"
  4538. }
  4539. // EdbInfoExistCheck
  4540. // @Title 新增指标-检验指标是否存在接口
  4541. // @Description 新增指标-检验指标是否存在接口
  4542. // @Param Source query int true "来源:1:同花顺,2:wind"
  4543. // @Param SubSource query int true "子数据来源:0:经济数据库,1:日期序列"
  4544. // @Param EdbCode query string false "指标编码/指标代码"
  4545. // @Param StockCode query string false "证券代码"
  4546. // @Success 200 {object} data_manage.EdbInfoExistCheckResp
  4547. // @router /edb_info/exist/check [get]
  4548. func (this *EdbInfoController) EdbInfoExistCheck() {
  4549. br := new(models.BaseResponse).Init()
  4550. defer func() {
  4551. this.Data["json"] = br
  4552. this.ServeJSON()
  4553. }()
  4554. source, _ := this.GetInt("Source")
  4555. edbCode := this.GetString("EdbCode")
  4556. edbCode = strings.Trim(edbCode, "\t")
  4557. edbCode = strings.Trim(edbCode, " ")
  4558. edbCode = strings.Replace(edbCode, "\t", "", -1)
  4559. subSource, _ := this.GetInt("SubSource")
  4560. stockCode := this.GetString("StockCode")
  4561. if source <= 0 {
  4562. br.Msg = "无效的数据来源"
  4563. return
  4564. }
  4565. if edbCode == "" {
  4566. br.Msg = "请输入指标ID"
  4567. return
  4568. }
  4569. if source != utils.DATA_SOURCE_WIND {
  4570. br.Msg = "无效的数据来源"
  4571. return
  4572. }
  4573. if subSource != utils.DATA_SUB_SOURCE_DATE {
  4574. br.Msg = "无效的数据库来源"
  4575. return
  4576. }
  4577. var indexCodeArr []string
  4578. edbCodeArr := strings.Split(edbCode, ",")
  4579. stockCodeArr := strings.Split(stockCode, ",")
  4580. for _, sv := range stockCodeArr {
  4581. for _, ev := range edbCodeArr {
  4582. indexCode := utils.WindDbWsd + sv + ev
  4583. indexCodeArr = append(indexCodeArr, indexCode)
  4584. }
  4585. }
  4586. indexList, err := data_manage.GetEdbInfoByEdbCodeList(source, indexCodeArr)
  4587. if err != nil && err.Error() != utils.ErrNoRow() {
  4588. br.Msg = "校验指标是否存在失败"
  4589. br.ErrMsg = "校验指标是否存在失败,Err:" + err.Error()
  4590. return
  4591. }
  4592. var existStockCodeArr []string
  4593. var existEdbCodeArr []string
  4594. for _, indexItem := range indexList {
  4595. for _, sv := range stockCodeArr {
  4596. for _, ev := range edbCodeArr {
  4597. if strings.Contains(indexItem.EdbCode, sv) {
  4598. existStockCodeArr = append(existStockCodeArr, sv)
  4599. }
  4600. if strings.Contains(indexItem.EdbCode, ev) {
  4601. existEdbCodeArr = append(existEdbCodeArr, ev)
  4602. }
  4603. }
  4604. }
  4605. }
  4606. resp := new(data_manage.EdbInfoExistCheckResp)
  4607. if len(indexList) > 0 {
  4608. resp.IndexExist = true
  4609. }
  4610. resp.ExistEdbCodeArr = existEdbCodeArr
  4611. resp.ExistStockCodeArr = existStockCodeArr
  4612. br.Ret = 200
  4613. br.Success = true
  4614. br.Msg = "获取成功"
  4615. }