edb_info.go 133 KB

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