123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020 |
- package data_manage
- import (
- "encoding/json"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/paging"
- "hongze/hz_eta_api/controllers"
- "hongze/hz_eta_api/models"
- "hongze/hz_eta_api/models/data_manage"
- "hongze/hz_eta_api/services/alarm_msg"
- "hongze/hz_eta_api/services/data"
- "hongze/hz_eta_api/services/elastic"
- "hongze/hz_eta_api/utils"
- "strconv"
- "strings"
- "sync"
- "time"
- )
- // 数据管理
- type EdbInfoController struct {
- controllers.BaseAuthController
- }
- // @Title 新增指标-查询指标信息接口
- // @Description 新增指标-查询指标信息接口
- // @Param Source query int true "来源:1:同花顺,2:wind,3:彭博"
- // @Param EdbCode query string false "指标编码"
- // @Success 200 {object} data_manage.EdbInfoSearchResp
- // @router /edb_info/search [get]
- func (this *EdbInfoController) EdbInfoSearch() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- source, _ := this.GetInt("Source")
- edbCode := this.GetString("EdbCode")
- edbCode = strings.Trim(edbCode, "\t")
- edbCode = strings.Trim(edbCode, " ")
- edbCode = strings.Replace(edbCode, "\t", "", -1)
- if source <= 0 {
- br.Msg = "无效的数据来源"
- return
- }
- if edbCode == "" {
- br.Msg = "请输入指标ID"
- return
- }
- //如果是彭博财务指标,那么需要传入客户code
- if source == utils.DATA_SOURCE_PB_FINANCE {
- companyCode := this.GetString("CompanyCode")
- companyCode = strings.Trim(companyCode, "\t")
- companyCode = strings.Trim(companyCode, " ")
- companyCode = strings.Replace(companyCode, "\t", "", -1)
- // 如果财务数据,那么需要拼接上客户code
- edbCode = companyCode + "&&" + edbCode
- }
- resp := new(data_manage.EdbInfoSearchResp)
- //判断指标是否存在
- var item *data_manage.EdbInfo
- var err error
- if source == utils.DATA_SOURCE_GL {
- // 如果是钢联的话,那么就先判断是不是存在钢联化工
- item, err = data_manage.GetEdbInfoByEdbCode(utils.DATA_SOURCE_MYSTEEL_CHEMICAL, edbCode)
- if err != nil {
- if err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- }
- err = nil
- if item != nil {
- source = utils.DATA_SOURCE_MYSTEEL_CHEMICAL
- } else {
- // 判断是不是已经在钢联这边已经存在了
- item, err = data_manage.GetEdbInfoByEdbCode(utils.DATA_SOURCE_GL, edbCode)
- if err != nil {
- if err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- }
- err = nil
- // 如果在钢联来源也没找到,那么就需要再判断下是否处于 《钢联化工》 数据源里面
- if item == nil {
- tmpInfo, err := data_manage.GetBaseFromMysteelChemicalIndexByCode(edbCode)
- if err != nil {
- if err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- }
- err = nil
- if tmpInfo != nil {
- source = utils.DATA_SOURCE_MYSTEEL_CHEMICAL
- }
- }
- }
- }
- if item == nil {
- item, err = data_manage.GetEdbInfoByEdbCode(source, edbCode)
- }
- if err != nil {
- if err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- }
- var isAdd bool
- var isInEdb bool //是否在指标库中
- if item != nil && item.EdbInfoId > 0 {
- isInEdb = true //在指标库中
- resp.Status = 1
- searchItem := new(data_manage.EdbInfoSearch)
- searchItem.EdbCode = item.EdbCode
- searchItem.StartDate = item.StartDate
- searchItem.EndDate = item.EndDate
- searchItem.EdbName = item.EdbName
- resp.SearchItem = searchItem
- //查询目录
- resultList, _ := data_manage.GetClassifyAllByClassifyId(item.ClassifyId)
- resp.ClassifyList = resultList
- // 查询该指标是否有权限
- obj := data_manage.EdbInfoNoPermissionAdmin{}
- conf, err := obj.GetByEdbInfoIdAndAdminId(this.SysUser.AdminId, item.EdbInfoId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取当前账号的不可见指标配置失败,err:" + err.Error()
- return
- }
- if conf != nil {
- resp.Status = 3
- }
- } else {
- //dateNow := time.Now()
- //startDate := dateNow.AddDate(-30, 0, 0).Format(utils.FormatDate)
- searchItem := new(data_manage.EdbInfoSearch)
- if source == utils.DATA_SOURCE_THS {
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_THS, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取Ths已存在信息失败,Err:" + err.Error()
- return
- }
- fmt.Println("ths len:", len(dataItems))
- if len(dataItems) > 0 {
- fmt.Println("ths data exist")
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataThsMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取Ths日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
- //searchItem, err = data.GetEdbDataByThs(edbCode, startDate, endDate)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,Err:" + err.Error()
- // return
- //}
- respItem, err := data.AddEdbData(source, edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- } else if source == utils.DATA_SOURCE_WIND {
- fmt.Println("wind data exist")
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_WIND, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取Wind已存在信息失败,Err:" + err.Error()
- return
- }
- fmt.Println("wind dataItems:", len(dataItems))
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataWindMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取wind日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //endDate := dateNow.Format(utils.FormatDate)
- //searchItem, err = data.GetEdbDataByWind(edbCode, startDate, endDate)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "wind 获取失败,Err:" + err.Error()
- // return
- //}
- respItem, err := data.AddEdbData(source, edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- if respItem.Ret == 421 {
- br.Msg = "该渠道已超过添加上限"
- } else {
- br.Msg = "未搜索到该指标"
- }
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- } else if source == utils.DATA_SOURCE_PB || source == utils.DATA_SOURCE_PB_FINANCE {
- fmt.Println("pb data exist")
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取Pb已存在信息失败,Err:" + err.Error()
- return
- }
- fmt.Println("pb dataItems:", len(dataItems))
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataPbMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取Pb日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
- //startDate := dateNow.AddDate(-30, 0, 0).Format(utils.FormatDateUnSpace)
- //searchItem, err = data.GetEdbDataByPb(edbCode, startDate, endDate)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "彭博数据获取失败,Err:" + err.Error()
- // return
- //}
- respItem, err := data.AddEdbData(source, edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- } else if source == utils.DATA_SOURCE_MANUAL { //手工数据指标
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_MANUAL, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取Ths已存在信息失败,Err:" + err.Error()
- return
- }
- fmt.Println("ths len:", len(dataItems))
- if len(dataItems) > 0 {
- fmt.Println("ths data exist")
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataManualMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取Ths日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //searchItem, err = data_manage.GetEdbDataByManual(edbCode, startDate, endDate)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,Err:" + err.Error()
- // return
- //}
- respItem, err := data.AddEdbData(source, edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- manualInfo, err := models.GetEdbinfoByTradeCode(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取手工指标详情失败,Err:" + err.Error()
- return
- }
- if manualInfo != nil {
- searchItem.Frequency = manualInfo.Frequency
- searchItem.Unit = manualInfo.Unit
- searchItem.EdbName = manualInfo.SecName
- }
- } else if source == utils.DATA_SOURCE_LZ {
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_LZ, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取隆众已存在信息失败,Err:" + err.Error()
- return
- }
- fmt.Println("ths len:", len(dataItems))
- if len(dataItems) > 0 {
- fmt.Println("ths data exist")
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataLzMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取隆众日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
- //searchItem, err = data_manage.GetEdbDataByLz(edbCode, startDate, endDate)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取隆众数据失败,Err:" + err.Error()
- // return
- //}
- respItem, err := data.AddEdbData(source, edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- lzInfo, err := data_manage.GetLongzhongSurveyProductByCode(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取手工指标详情失败,Err:" + err.Error()
- return
- }
- if lzInfo != nil {
- frequency := lzInfo.Frequency
- var frequencyStr string
- if frequency == 1 {
- frequencyStr = "日度"
- } else if frequency == 2 {
- frequencyStr = "周度"
- } else if frequency == 3 {
- frequencyStr = "月度"
- } else if frequency == 4 {
- frequencyStr = "季度"
- } else if frequency == 5 {
- frequencyStr = "年度"
- } else if frequency == 99 {
- frequencyStr = "无固定频率"
- }
- searchItem.Frequency = frequencyStr
- searchItem.Unit = lzInfo.UnitName
- searchItem.EdbName = lzInfo.SampleName + lzInfo.BreedName + lzInfo.QuotaName
- }
- } else if source == utils.DATA_SOURCE_YS { //有色网
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_YS, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取Ys已存在信息失败,Err:" + err.Error()
- return
- }
- fmt.Println("dataItems:", len(dataItems))
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataYsMaxAndMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取YS日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
- //searchItem, err = data_manage.GetEdbDataByYs(edbCode, startDate, endDate)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,GetEdbDataByYs Err:" + err.Error()
- // return
- //}
- //if searchItem.StartDate == "" {
- // minDate, maxDate, _ := data_manage.GetEdbDataYsMaxAndMinDate(edbCode)
- // searchItem.StartDate = minDate
- // searchItem.EndDate = maxDate
- //}
- respItem, err := data.AddEdbData(source, edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- smmInfo, err := data_manage.GetBaseFromSmmIndexByIndexCode(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取有色指标详情失败,Err:" + err.Error()
- return
- }
- if smmInfo != nil {
- searchItem.Frequency = smmInfo.Frequency
- searchItem.Unit = smmInfo.Unit
- searchItem.EdbName = smmInfo.IndexName
- }
- } else if source == utils.DATA_SOURCE_GL { //钢联
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取钢联已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataGlMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取钢联日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
- //searchItem, err = data_manage.GetEdbDataByGl(edbCode, startDate, endDate)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取钢联数据失败,Err:" + err.Error()
- // return
- //}
- respItem, err := data.AddEdbData(source, edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- glInfo, err := data_manage.GetGlIndexByCode(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取钢联指标详情失败,Err:" + err.Error()
- return
- }
- if glInfo != nil {
- searchItem.Frequency = glInfo.FrequencyName
- searchItem.Unit = glInfo.UnitName
- searchItem.EdbName = glInfo.IndexName
- }
- } else if source == utils.DATA_SOURCE_ZZ { //郑商所
- var suffix string
- if strings.Contains(edbCode, "deal") {
- suffix = "deal"
- } else if strings.Contains(edbCode, "buy") {
- suffix = "buy"
- } else if strings.Contains(edbCode, "sold") {
- suffix = "sold"
- } else {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = "指标code异常"
- return
- }
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取郑商所已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataZzMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取郑商所日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //searchItem, err = data_manage.GetEdbDataByZz(edbCode, suffix, startDate, "")
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,GetEdbDataByZz Err:" + err.Error()
- // return
- //}
- //if searchItem.StartDate == "" {
- // minDate, maxDate, _ := data_manage.GetEdbDataZzMaxOrMinDate(edbCode)
- // searchItem.StartDate = minDate
- // searchItem.EndDate = maxDate
- //}
- respItem, err := data.AddEdbData(source, edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- allInfo, err := data_manage.GetBaseInfoFromZhengzhouByIndexCode(edbCode, suffix)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取郑商所指标详情失败,Err:" + err.Error()
- return
- }
- var zzInfo *data_manage.BaseInfoFromZz
- if allInfo != nil {
- zzInfo = allInfo[0]
- }
- if zzInfo != nil {
- searchItem.Frequency = "日度"
- searchItem.Unit = "手"
- if suffix == "deal" {
- searchItem.EdbName = zzInfo.DealName
- } else if suffix == "buy" {
- searchItem.EdbName = zzInfo.BuyName
- } else {
- searchItem.EdbName = zzInfo.SoldName
- }
- }
- } else if source == utils.DATA_SOURCE_DL { //大商所
- var suffix string
- if strings.Contains(edbCode, "deal") {
- suffix = "deal"
- } else if strings.Contains(edbCode, "buy") {
- suffix = "buy"
- } else if strings.Contains(edbCode, "sold") {
- suffix = "sold"
- } else {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = "指标code异常"
- return
- }
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取大商所已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataDlMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取大商所日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //searchItem, err = data_manage.GetEdbDataByDl(edbCode, suffix, startDate, "")
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,GetEdbDataByDl Err:" + err.Error()
- // return
- //}
- //if searchItem.StartDate == "" {
- // minDate, maxDate, _ := data_manage.GetEdbDataDlMaxOrMinDate(edbCode)
- // searchItem.StartDate = minDate
- // searchItem.EndDate = maxDate
- //}
- respItem, err := data.AddEdbData(source, edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- allInfo, err := data_manage.GetBaseInfoFromDalianByIndexCode(edbCode, suffix)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取大商所指标详情失败,Err:" + err.Error()
- return
- }
- var dlInfo *data_manage.BaseInfoFromDl
- if allInfo != nil {
- dlInfo = allInfo[0]
- }
- if dlInfo != nil {
- searchItem.Frequency = "日度"
- searchItem.Unit = "手"
- if suffix == "deal" {
- searchItem.EdbName = dlInfo.DealName
- } else if suffix == "buy" {
- searchItem.EdbName = dlInfo.BuyName
- } else {
- searchItem.EdbName = dlInfo.SoldName
- }
- }
- } else if source == utils.DATA_SOURCE_SH { //上期所
- var suffix string
- if strings.Contains(edbCode, "deal") {
- suffix = "deal"
- } else if strings.Contains(edbCode, "buy") {
- suffix = "buy"
- } else if strings.Contains(edbCode, "sold") {
- suffix = "sold"
- } else {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = "指标code异常"
- return
- }
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取上期所已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataShMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取上期所日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //searchItem, err = data_manage.GetEdbDataBySh(edbCode, suffix, startDate, "")
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,GetEdbDataBySh Err:" + err.Error()
- // return
- //}
- //if searchItem.StartDate == "" {
- // minDate, maxDate, _ := data_manage.GetEdbDataShMaxOrMinDate(edbCode)
- // searchItem.StartDate = minDate
- // searchItem.EndDate = maxDate
- //}
- respItem, err := data.AddEdbData(source, edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- allInfo, err := data_manage.GetBaseInfoFromShByIndexCode(edbCode, suffix)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取上期所指标详情失败,Err:" + err.Error()
- return
- }
- var shInfo *data_manage.BaseInfoFromSh
- if allInfo != nil {
- shInfo = allInfo[0]
- }
- if shInfo != nil {
- searchItem.Frequency = "日度"
- searchItem.Unit = "手"
- if suffix == "deal" {
- searchItem.EdbName = shInfo.DealName
- } else if suffix == "buy" {
- searchItem.EdbName = shInfo.BuyName
- } else {
- searchItem.EdbName = shInfo.SoldName
- }
- }
- } else if source == utils.DATA_SOURCE_CFFEX { //中金所
- var suffix string
- if strings.Contains(edbCode, "deal") {
- suffix = "deal"
- } else if strings.Contains(edbCode, "buy") {
- suffix = "buy"
- } else if strings.Contains(edbCode, "sold") {
- suffix = "sold"
- } else {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = "指标code异常"
- return
- }
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取中金所已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataCffexMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取中金所日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //searchItem, err = data_manage.GetEdbDataByCffex(edbCode, suffix, startDate, "")
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,GetEdbDataByCffex Err:" + err.Error()
- // return
- //}
- //if searchItem.StartDate == "" {
- // minDate, maxDate, _ := data_manage.GetEdbDataCffexMaxOrMinDate(edbCode)
- // searchItem.StartDate = minDate
- // searchItem.EndDate = maxDate
- //}
- respItem, err := data.AddEdbData(source, edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- allInfo, err := data_manage.GetBaseInfoFromCffexByIndexCode(edbCode, suffix)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取中金所指标详情失败,Err:" + err.Error()
- return
- }
- var cffexInfo *data_manage.BaseInfoFromCffex
- if allInfo != nil {
- cffexInfo = allInfo[0]
- }
- if cffexInfo != nil {
- searchItem.Frequency = "日度"
- searchItem.Unit = "手"
- if suffix == "deal" {
- searchItem.EdbName = cffexInfo.DealName
- } else if suffix == "buy" {
- searchItem.EdbName = cffexInfo.BuyName
- } else {
- searchItem.EdbName = cffexInfo.SoldName
- }
- }
- } else if source == utils.DATA_SOURCE_SHFE { //上期能源
- var suffix string
- if strings.Contains(edbCode, "deal") {
- suffix = "deal"
- } else if strings.Contains(edbCode, "buy") {
- suffix = "buy"
- } else if strings.Contains(edbCode, "sold") {
- suffix = "sold"
- } else {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = "指标code异常"
- return
- }
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取上期能源已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataShfeMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取上期能源日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //searchItem, err = data_manage.GetEdbDataByShfe(edbCode, suffix, startDate, "")
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,GetEdbDataByShfe Err:" + err.Error()
- // return
- //}
- //if searchItem.StartDate == "" {
- // minDate, maxDate, _ := data_manage.GetEdbDataShfeMaxOrMinDate(edbCode)
- // searchItem.StartDate = minDate
- // searchItem.EndDate = maxDate
- //}
- respItem, err := data.AddEdbData(source, edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- allInfo, err := data_manage.GetBaseInfoFromShfeByIndexCode(edbCode, suffix)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取上期能源指标详情失败,Err:" + err.Error()
- return
- }
- var shfeInfo *data_manage.BaseInfoFromShfe
- if allInfo != nil {
- shfeInfo = allInfo[0]
- }
- if shfeInfo != nil {
- searchItem.Frequency = "日度"
- searchItem.Unit = "手"
- if suffix == "deal" {
- searchItem.EdbName = shfeInfo.DealName
- } else if suffix == "buy" {
- searchItem.EdbName = shfeInfo.BuyName
- } else {
- searchItem.EdbName = shfeInfo.SoldName
- }
- }
- } else if source == utils.DATA_SOURCE_GIE { //欧洲天然气
- var suffix string
- l := len(edbCode)
- if strings.Contains(edbCode[l-2:], "GS") {
- suffix = "GS"
- } else if strings.Contains(edbCode[l-2:], "CF") {
- suffix = "CF"
- } else if strings.Contains(edbCode[l-1:], "T") {
- suffix = "T"
- } else if strings.Contains(edbCode[l-2:], "In") {
- suffix = "In"
- } else if strings.Contains(edbCode[l-3:], "Out") {
- suffix = "Out"
- } else if strings.Contains(edbCode[l-3:], "WGV") {
- suffix = "WGV"
- } else if strings.Contains(edbCode[l-2:], "IC") {
- suffix = "IC"
- } else if strings.Contains(edbCode[l-2:], "WC") {
- suffix = "WC"
- } else if strings.Contains(edbCode[l-1:], "F") {
- suffix = "F"
- } else if strings.Contains(edbCode[l-1:], "C") {
- suffix = "C"
- } else {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = "指标code异常"
- return
- }
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取欧洲天然气已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataGieMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取欧洲天然气日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //searchItem, err = data_manage.GetEdbDataByGie(edbCode, suffix, startDate, "")
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,GetEdbDataByGie Err:" + err.Error()
- // return
- //}
- //if searchItem.StartDate == "" {
- // minDate, maxDate, _ := data_manage.GetEdbDataGieMaxOrMinDate(edbCode)
- // searchItem.StartDate = minDate
- // searchItem.EndDate = maxDate
- //}
- respItem, err := data.AddEdbData(source, edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- allInfo, err := data_manage.GetBaseFromEicDataAllByIndexCodeV2(edbCode, suffix)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取欧洲天然气指标详情失败,Err:" + err.Error()
- return
- }
- var eicInfo *data_manage.BaseFromTradeEicIndexV2
- if allInfo != nil {
- eicInfo = allInfo[0]
- }
- var name string
- if eicInfo != nil {
- searchItem.Frequency = "日度"
- if suffix == "GS" {
- name = eicInfo.Name + "_gas_in_storage"
- searchItem.EdbName = name
- searchItem.Unit = "TWh"
- } else if suffix == "C" {
- name = eicInfo.Name + "_consumption"
- searchItem.EdbName = name
- searchItem.Unit = "TWh"
- } else if suffix == "CF" {
- name = eicInfo.Name + "_consumption_full"
- searchItem.EdbName = name
- searchItem.Unit = "百分比"
- } else if suffix == "F" {
- name = eicInfo.Name + "_full"
- searchItem.EdbName = name
- searchItem.Unit = "百分比"
- } else if suffix == "T" {
- name = eicInfo.Name + "_trend"
- searchItem.EdbName = name
- searchItem.Unit = "百分比"
- } else if suffix == "In" {
- name = eicInfo.Name + "_injection"
- searchItem.EdbName = name
- searchItem.Unit = "GWH/d"
- } else if suffix == "Out" {
- name = eicInfo.Name + "_withdrawal"
- searchItem.EdbName = name
- searchItem.Unit = "GWH/d"
- } else if suffix == "WGV" {
- name = eicInfo.Name + "_working_gas_volume"
- searchItem.EdbName = name
- searchItem.Unit = "TWh"
- } else if suffix == "IC" {
- name = eicInfo.Name + "_injection_capacity"
- searchItem.EdbName = name
- searchItem.Unit = "GWh/d"
- } else if suffix == "WC" {
- name = eicInfo.Name + "_withdrawal_capacity"
- searchItem.EdbName = name
- searchItem.Unit = "GWh/d"
- }
- }
- } else if source == utils.DATA_SOURCE_LT {
- fmt.Println("lt data exist")
- if strings.Contains(edbCode, "=") {
- br.Msg = "暂不支持编码中含有=的指标"
- br.ErrMsg = "暂不支持编码中含有=的指标"
- return
- }
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_LT, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取 lt 已存在信息失败,Err:" + err.Error()
- return
- }
- fmt.Println("lt dataItems:", len(dataItems))
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- edbInfoMaxAndMinInfo, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取lt日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = edbInfoMaxAndMinInfo.MinDate
- searchItem.EndDate = edbInfoMaxAndMinInfo.MaxDate
- } else {
- //endDate := dateNow.Format(utils.FormatDate)
- //searchItem, err = data.GetEdbDataByLt(edbCode, startDate, endDate)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "lt 获取失败,Err:" + err.Error()
- // return
- //}
- respItem, err := data.AddEdbData(source, edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = respItem.Msg
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- } else if source == utils.DATA_SOURCE_COAL { //中国煤炭网
- var suffix string
- if strings.Contains(edbCode, "jsm") {
- suffix = "jsm_index"
- } else if strings.Contains(edbCode, "company") {
- suffix = "company_index"
- } else if strings.Contains(edbCode, "firm") {
- suffix = "firm_index"
- } else if strings.Contains(edbCode, "coastal") {
- suffix = "coastal_index"
- } else if strings.Contains(edbCode, "inland") {
- suffix = "inland_index"
- } else {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = "指标code异常"
- return
- }
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取煤炭网已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataCoalMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取煤炭网日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //searchItem, err = data_manage.GetEdbDataByCffex(edbCode, suffix, startDate, "")
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,GetEdbDataByCffex Err:" + err.Error()
- // return
- //}
- //if searchItem.StartDate == "" {
- // minDate, maxDate, _ := data_manage.GetEdbDataCffexMaxOrMinDate(edbCode)
- // searchItem.StartDate = minDate
- // searchItem.EndDate = maxDate
- //}
- respItem, err := data.AddEdbData(source, edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- allInfo, err := data_manage.GetBaseInfoFromCoalByIndexCode(edbCode, suffix)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取煤炭网指标详情失败,Err:" + err.Error()
- return
- }
- var coalInfo *data_manage.BaseInfoFromCoal
- if allInfo != nil {
- coalInfo = allInfo[0]
- }
- if coalInfo != nil {
- searchItem.Frequency = coalInfo.Frequency
- searchItem.Unit = coalInfo.Unit
- searchItem.EdbName = coalInfo.IndexName
- }
- } else if source == utils.DATA_SOURCE_GOOGLE_TRAVEL { //谷歌出行数据
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取煤炭网已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- item, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取煤炭网日期信息失败,Err:" + err.Error()
- return
- }
- if item != nil {
- searchItem.DataList = dataItems
- searchItem.StartDate = item.MinDate
- searchItem.EndDate = item.MaxDate
- }
- } else {
- respItem, err := data.AddEdbData(source, edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- } else if source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL { //钢联化工
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取钢联已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataMysteelChemicalMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取钢联日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
- //searchItem, err = data_manage.GetEdbDataByGl(edbCode, startDate, endDate)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取钢联数据失败,Err:" + err.Error()
- // return
- //}
- respItem, err := data.AddEdbData(source, edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- glInfo, err := data_manage.GetBaseFromMysteelChemicalIndexByCode(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取钢联指标详情失败,Err:" + err.Error()
- return
- }
- if glInfo != nil {
- searchItem.Frequency = glInfo.Frequency
- searchItem.Unit = glInfo.Unit
- searchItem.EdbName = glInfo.IndexName
- }
- } else if source == utils.DATA_SOURCE_EIA_STEO { //eia steo报告
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取钢联已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- item, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取eia steo日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = item.MinDate
- searchItem.EndDate = item.MaxDate
- } else {
- respItem, err := data.AddEdbData(source, edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- eiasteoInfo, err := data_manage.GetBaseFromEiaSteoIndexByCode(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取钢联指标详情失败,Err:" + err.Error()
- return
- }
- if eiasteoInfo != nil {
- searchItem.Frequency = eiasteoInfo.Frequency
- searchItem.Unit = eiasteoInfo.Unit
- searchItem.EdbName = eiasteoInfo.IndexName
- }
- } else if source == utils.DATA_SOURCE_COM_TRADE { // un数据源
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取联合国商品贸易数据已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- item, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取联合国商品贸易数据日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = item.MinDate
- searchItem.EndDate = item.MaxDate
- } else {
- respItem, err := data.AddEdbData(source, edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- eiasteoInfo, err := data_manage.GetComTradeIndex(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取钢联指标详情失败,Err:" + err.Error()
- return
- }
- if eiasteoInfo != nil {
- //eiasteoInfo.
- if eiasteoInfo.Type <= 2 {
- searchItem.Frequency = `年度`
- } else {
- searchItem.Frequency = `月度`
- }
- if eiasteoInfo.Type == 1 || eiasteoInfo.Type == 3 {
- searchItem.Unit = "美元"
- } else {
- searchItem.Unit = "千克"
- }
- searchItem.EdbName = eiasteoInfo.Name
- }
- } else if source == utils.DATA_SOURCE_SCI { //卓创数据(红桃三)
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取SCI已存在信息失败,Err:" + err.Error()
- return
- }
- fmt.Println("dataItems:", len(dataItems))
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataSciMaxAndMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取SCI日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
- //searchItem, err = data_manage.GetEdbDataByYs(edbCode, startDate, endDate)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,GetEdbDataByYs Err:" + err.Error()
- // return
- //}
- //if searchItem.StartDate == "" {
- // minDate, maxDate, _ := data_manage.GetEdbDataYsMaxAndMinDate(edbCode)
- // searchItem.StartDate = minDate
- // searchItem.EndDate = maxDate
- //}
- respItem, err := data.AddEdbData(source, edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- smmInfo, err := data_manage.GetBaseFromSciIndexByIndexCode(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取Sci指标详情失败,Err:" + err.Error()
- return
- }
- if smmInfo != nil {
- searchItem.Frequency = smmInfo.Frequency
- searchItem.Unit = smmInfo.Unit
- searchItem.EdbName = smmInfo.IndexName
- }
- } else if source == utils.DATA_SOURCE_BAIINFO { //百川盈孚
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取BAIINFO已存在信息失败,Err:" + err.Error()
- return
- }
- fmt.Println("dataItems:", len(dataItems))
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataBaiinfoMaxAndMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取BAIINFO日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- //endDate := dateNow.AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
- //searchItem, err = data_manage.GetEdbDataByYs(edbCode, startDate, endDate)
- //if err != nil {
- // br.Msg = "获取失败"
- // br.ErrMsg = "获取失败,GetEdbDataByYs Err:" + err.Error()
- // return
- //}
- //if searchItem.StartDate == "" {
- // minDate, maxDate, _ := data_manage.GetEdbDataYsMaxAndMinDate(edbCode)
- // searchItem.StartDate = minDate
- // searchItem.EndDate = maxDate
- //}
- respItem, err := data.AddEdbData(source, edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- baiInfo, err := data_manage.GetBaseFromBaiinfoIndexByIndexCode(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取Baiinfo指标详情失败,Err:" + err.Error()
- return
- }
- if baiInfo != nil {
- searchItem.Frequency = baiInfo.Frequency
- searchItem.Unit = baiInfo.Unit
- searchItem.EdbName = baiInfo.IndexName
- }
- } else if source == utils.DATA_SOURCE_NATIONAL_STATISTICS { // 国家统计局
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取国家统计局已存在信息失败,Err:" + err.Error()
- return
- }
- if len(dataItems) > 0 {
- searchItem.EdbCode = edbCode
- item, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取国家统计局日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = item.MinDate
- searchItem.EndDate = item.MaxDate
- } else {
- respItem, err := data.AddEdbData(source, edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标"
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- //获取指标信息
- nationalInfo, err := data_manage.GetBaseFromNationalStatisticsIndexByIndexCode(edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取国家统计局详情失败,Err:" + err.Error()
- return
- }
- if nationalInfo != nil {
- searchItem.Frequency = nationalInfo.Frequency
- searchItem.Unit = nationalInfo.Unit
- searchItem.EdbName = fmt.Sprintf("%s%s", nationalInfo.Reg, nationalInfo.IndexName)
- }
- } else if source == utils.DATA_SOURCE_FUBAO { //数宝
- dataItems, err := data_manage.GetEdbDataAllByEdbCode(edbCode, utils.DATA_SOURCE_FUBAO, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取Fubao已存在信息失败,Err:" + err.Error()
- return
- }
- fmt.Println("fubao len:", len(dataItems))
- if len(dataItems) > 0 {
- fmt.Println("fubao data exist")
- searchItem.EdbCode = edbCode
- minDate, maxDate, err := data_manage.GetEdbDataFubaoMaxOrMinDate(edbCode)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取Ths日期信息失败,Err:" + err.Error()
- return
- }
- searchItem.DataList = dataItems
- searchItem.StartDate = minDate
- searchItem.EndDate = maxDate
- } else {
- respItem, err := data.AddEdbData(source, edbCode)
- if err != nil {
- br.Msg = "获取失败," + respItem.Msg
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if respItem.Ret != 200 {
- br.Msg = "未搜索到该指标," + respItem.Msg
- br.ErrMsg = respItem.ErrMsg + ";EdbCode:" + edbCode
- return
- }
- isAdd = true
- }
- } else {
- br.Msg = "无效的数据来源"
- return
- }
- if isAdd {
- dataList, err := data_manage.GetEdbDataAllByEdbCode(edbCode, source, utils.EDB_DATA_LIMIT)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,GetEdbDataAllByEdbCode Err:" + err.Error()
- return
- }
- searchItem.DataList = dataList
- edbInfoMaxAndMinInfo, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,GetEdbInfoMaxAndMinInfo Err:" + err.Error()
- return
- }
- searchItem.EdbCode = edbCode
- searchItem.DataList = dataList
- if edbInfoMaxAndMinInfo != nil {
- searchItem.StartDate = edbInfoMaxAndMinInfo.MinDate
- searchItem.EndDate = edbInfoMaxAndMinInfo.MaxDate
- }
- //edb指标信息
- edbInfoItem, err := data_manage.GetEdbInfoByEdbCode(source, edbCode)
- if edbInfoItem != nil {
- searchItem.EdbName = edbInfoItem.EdbName
- }
- }
- resp.Status = 2
- resp.SearchItem = searchItem
- }
- //如果不在指标库中,且不是新增
- if !isInEdb && !isAdd {
- if resp.SearchItem.DataList == nil || len(resp.SearchItem.DataList) <= 0 {
- br.Msg = "目标指标无有效值,请重新搜索"
- br.Data = resp
- return
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 指标列表接口
- // @Description 指标列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param EdbInfoId query int true "指标id"
- // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
- // @Success 200 {object} data_manage.EdbInfoListResp
- // @router /edb_info/list [get]
- func (this *EdbInfoController) EdbInfoList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- edbInfoId, _ := this.GetInt("EdbInfoId")
- keyWord := this.GetString("KeyWord")
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var total int
- page := paging.GetPaging(currentIndex, pageSize, total)
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- //if edbInfoId <= 0 && keyWord == "" {
- // br.Msg = "参数错误"
- // return
- //}
- // 指标类型,0:普通指标,1:预测指标
- condition += " AND edb_info_type=? "
- pars = append(pars, 0)
- if edbInfoId > 0 {
- condition += " AND edb_info_id=? "
- pars = append(pars, edbInfoId)
- // 获取当前账号的不可见指标配置
- obj := data_manage.EdbInfoNoPermissionAdmin{}
- conf, err := obj.GetByEdbInfoIdAndAdminId(this.SysUser.AdminId, edbInfoId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取当前账号的不可见指标配置失败,err:" + err.Error()
- return
- }
- if conf != nil {
- br.Msg = "无权限,请联系管理员"
- br.IsSendEmail = false
- return
- }
- }
- if keyWord != "" {
- condition += ` AND ( edb_code LIKE '%` + keyWord + `%' OR edb_name LIKE '%` + keyWord + `%' )`
- //pars = append(pars, keyWord)
- //pars = append(pars, keyWord)
- }
- resp := new(data_manage.EdbInfoListResp)
- if condition == "" {
- item := new(data_manage.EdbInfoList)
- resp.Paging = page
- resp.Item = item
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- return
- }
- //获取指标信息
- edbInfoItem, err := data_manage.GetEdbInfoByCondition(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Success = true
- br.Msg = "获取指标信息失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- if edbInfoItem == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
- item := new(data_manage.EdbInfoList)
- resp.Paging = page
- resp.Item = item
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- return
- }
- //获取英文频度
- edbInfoItem.FrequencyEn = data.GetFrequencyEn(edbInfoItem.Frequency)
- //获取指标数据
- var dataCondition string
- var dataPars []interface{}
- dataCondition += ` AND edb_info_id=? `
- dataPars = append(dataPars, edbInfoItem.EdbInfoId)
- dataCount, err := data_manage.GetEdbDataCountByCondition(dataCondition, dataPars, edbInfoItem.Source)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取指标信息失败"
- br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
- return
- }
- page = paging.GetPaging(currentIndex, pageSize, dataCount)
- dataList, err := data_manage.GetEdbDataListByCondition(dataCondition, dataPars, edbInfoItem.Source, pageSize, startSize)
- if err != nil {
- br.Msg = "获取指标信息失败"
- br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
- return
- }
- edbInfoItem.DataList = dataList
- // 获取指标插入配置
- {
- edbDataInsertConfig, err := data_manage.GetEdbDataInsertConfigByEdbId(edbInfoId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取指标信息失败"
- br.ErrMsg = "获取指标数据失败,Err:" + err.Error()
- return
- }
- if edbDataInsertConfig != nil {
- edbInfoItem.DataInsertConfig.Date = edbDataInsertConfig.Date.Format(utils.FormatDate)
- edbInfoItem.DataInsertConfig.RealDate = edbDataInsertConfig.RealDate.Format(utils.FormatDate)
- edbInfoItem.DataInsertConfig.Value = edbDataInsertConfig.Value
- }
- }
- // 按钮校验
- button := data.GetEdbOpButton(this.SysUser, edbInfoItem.SysUserId, edbInfoItem.EdbType, edbInfoItem.EdbInfoType)
- button.AddButton = false
- edbInfoItem.Button = button
- //是否展示英文标识
- edbInfoItem.IsEnEdb = data.CheckIsEnEdb(edbInfoItem.EdbNameEn, edbInfoItem.Unit, edbInfoItem.UnitEn)
- //查询目录
- resultList, _ := data_manage.GetClassifyAllByClassifyId(edbInfoItem.ClassifyId)
- resp.Paging = page
- resp.Item = edbInfoItem
- resp.ClassifyList = resultList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 新增指标接口
- // @Description 新增指标接口
- // @Param request body data_manage.AddEdbInfoReq true "type json string"
- // @Success Ret=200 保存成功
- // @router /edb_info/add [post]
- func (this *EdbInfoController) EdbInfoAdd() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- deleteCache := true
- cacheKey := "CACHE_EDB_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
- defer func() {
- if deleteCache {
- utils.Rc.Delete(cacheKey)
- }
- }()
- if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
- deleteCache = false
- br.Msg = "系统处理中,请稍后重试!"
- br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
- return
- }
- var req data_manage.AddEdbInfoReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- source := req.Source
- if source <= 0 {
- br.Msg = "无效的数据来源"
- return
- }
- req.EdbName = strings.Trim(req.EdbName, " ")
- req.EdbCode = strings.Trim(req.EdbCode, " ")
- if req.EdbCode == "" {
- br.Msg = "指标ID不能为空"
- return
- }
- if req.EdbName == "" {
- br.Msg = "指标名称不能为空"
- return
- }
- if req.Frequency == "" {
- br.Msg = "频率不能为空"
- return
- }
- if req.Unit == "" {
- br.Msg = "单位不能为空"
- return
- }
- if req.ClassifyId <= 0 {
- br.Msg = "请选择分类"
- return
- }
- //if req.StartDate == "" || req.EndDate == "" {
- // br.Msg = "日期不能为空"
- // return
- //}
- // 兼容钢联与钢联化工数据
- if source == utils.DATA_SOURCE_GL {
- // 如果是钢联的话,那么就先判断是不是存在钢联化工
- tmpInfo, err := data_manage.GetBaseFromMysteelChemicalIndexByCode(req.EdbCode)
- if err != nil {
- if err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- }
- if tmpInfo != nil {
- source = utils.DATA_SOURCE_MYSTEEL_CHEMICAL
- req.Source = utils.DATA_SOURCE_MYSTEEL_CHEMICAL
- }
- }
- // 指标入库
- 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)
- if err != nil {
- br.Msg = "保存失败"
- if errMsg != `` {
- br.Msg = errMsg
- }
- br.ErrMsg = err.Error()
- br.IsSendEmail = isSendEmail
- return
- }
- //新增操作日志
- {
- edbLog := new(data_manage.EdbInfoLog)
- edbLog.EdbInfoId = edbInfo.EdbInfoId
- edbLog.SourceName = edbInfo.SourceName
- edbLog.Source = edbInfo.Source
- edbLog.EdbCode = edbInfo.EdbCode
- edbLog.EdbName = edbInfo.EdbName
- edbLog.ClassifyId = edbInfo.ClassifyId
- edbLog.SysUserId = sysUser.AdminId
- edbLog.SysUserRealName = sysUser.RealName
- edbLog.CreateTime = time.Now()
- edbLog.Content = string(this.Ctx.Input.RequestBody)
- edbLog.Status = "新增指标"
- edbLog.Method = this.Ctx.Input.URI()
- go data_manage.AddEdbInfoLog(edbLog)
- }
- resp := new(data_manage.AddEdbInfoResp)
- resp.EdbInfoId = edbInfo.EdbInfoId
- resp.UniqueCode = edbInfo.UniqueCode
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.Data = resp
- br.IsAddLog = true
- }
- // @Title 编辑指标接口
- // @Description 编辑指标接口
- // @Success 200 {object} data_manage.EditEdbInfoReq
- // @router /edb_info/edit [post]
- func (this *EdbInfoController) EdbInfoEdit() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req data_manage.EditEdbInfoReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- req.EdbName = strings.Trim(req.EdbName, " ")
- if req.EdbInfoId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "指标id小于等于0"
- return
- }
- if req.EdbName == "" {
- br.Msg = "指标名称不能为空"
- return
- }
- if req.Frequency == "" {
- br.Msg = "频率不能为空"
- return
- }
- if req.Unit == "" {
- br.Msg = "单位不能为空"
- return
- }
- if req.ClassifyId <= 0 {
- br.Msg = "请选择分类"
- return
- }
- edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
- if err != nil {
- br.Msg = "修改失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- // 编辑权限校验
- button := data.GetEdbOpButton(this.SysUser, edbInfo.SysUserId, edbInfo.EdbType, edbInfo.EdbInfoType)
- if !button.OpButton {
- br.Msg = "无权限操作"
- br.IsSendEmail = false
- return
- }
- //判断指标名称是否存在
- var condition string
- var pars []interface{}
- condition += " AND edb_info_id<>? "
- pars = append(pars, req.EdbInfoId)
- //condition += " AND source=? "
- //pars = append(pars, edbInfo.Source)
- condition += " AND edb_name=? "
- pars = append(pars, req.EdbName)
- count, err := data_manage.GetEdbInfoCountByCondition(condition, pars)
- if err != nil {
- br.Msg = "判断指标名称是否存在失败"
- br.ErrMsg = "判断指标名称是否存在失败,Err:" + err.Error()
- return
- }
- if count > 0 {
- br.Msg = "指标名称已存在,请重新填写"
- br.ErrMsg = "指标名称已存在,请重新填写"
- br.IsSendEmail = false
- return
- }
- err = data_manage.ModifyEdbInfo(&req)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "修改失败,Err:" + err.Error()
- return
- }
- //处理同名指标
- //{
- // edbNameList, err := data_manage.GetEdbInfoByName(req.EdbName)
- // if err != nil {
- // br.Msg = "保存失败"
- // br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- // return
- // }
- // if len(edbNameList) >= 2 {
- // for _, v := range edbNameList {
- // edbName := v.EdbName + "(" + v.SourceName + ")"
- // err = data_manage.ModifyEdbInfoNameSource(edbName, v.EdbInfoId)
- // if err != nil {
- // br.Msg = "保存失败"
- // br.ErrMsg = "修改指标名称失败,Err:" + err.Error()
- // return
- // }
- // }
- // }
- //}
- //新增操作日志
- {
- edbLog := new(data_manage.EdbInfoLog)
- edbLog.EdbInfoId = edbInfo.EdbInfoId
- edbLog.SourceName = edbInfo.SourceName
- edbLog.Source = edbInfo.Source
- edbLog.EdbCode = edbInfo.EdbCode
- edbLog.EdbName = edbInfo.EdbName
- edbLog.ClassifyId = edbInfo.ClassifyId
- edbLog.SysUserId = sysUser.AdminId
- edbLog.SysUserRealName = sysUser.RealName
- edbLog.CreateTime = time.Now()
- edbLog.Content = string(this.Ctx.Input.RequestBody)
- edbLog.Status = "编辑指标"
- edbLog.Method = this.Ctx.Input.URI()
- go data_manage.AddEdbInfoLog(edbLog)
- }
- //添加es
- data.AddOrEditEdbInfoToEs(req.EdbInfoId)
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.IsAddLog = true
- }
- // @Title 编辑指标英文信息接口
- // @Description 编辑指标英文信息接口
- // @Success 200 {object} data_manage.EditEdbEnInfoReq
- // @router /edb_info/en/edit [post]
- func (this *EdbInfoController) EdbEnInfoEdit() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req data_manage.EditEdbEnInfoReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- req.EdbNameEn = strings.Trim(req.EdbNameEn, " ")
- req.UnitEn = strings.Trim(req.UnitEn, " ")
- if req.EdbInfoId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "指标id小于等于0"
- return
- }
- edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
- if err != nil {
- br.Msg = "获取指标信息失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- if req.EdbNameEn != "" {
- //判断指标名称是否存在
- var condition string
- var pars []interface{}
- condition += " AND edb_info_id<>? "
- pars = append(pars, req.EdbInfoId)
- /*condition += " AND source=? "
- pars = append(pars, edbInfo.Source)*/
- condition += " AND edb_name_en=? "
- pars = append(pars, req.EdbNameEn)
- edbExist, err := data_manage.GetEdbInfoByCondition(condition, pars)
- if err != nil {
- if err.Error() != utils.ErrNoRow() {
- br.Msg = "判断英文指标名称是否存在失败"
- br.ErrMsg = "判断英文指标名称是否存在失败,Err:" + err.Error()
- return
- }
- }
- if err == nil && edbExist.EdbInfoId > 0 {
- br.Msg = edbExist.EdbName + ":" + req.EdbNameEn + "指标名称已存在"
- br.ErrMsg = "英文指标名称已存在,请重新填写"
- br.IsSendEmail = false
- return
- }
- }
- err = data_manage.ModifyEdbEnInfo(&req)
- if err != nil {
- br.Msg = "保存失败"
- br.ErrMsg = "修改失败,Err:" + err.Error()
- return
- }
- //新增操作日志
- {
- edbLog := new(data_manage.EdbInfoLog)
- edbLog.EdbInfoId = edbInfo.EdbInfoId
- edbLog.SourceName = edbInfo.SourceName
- edbLog.Source = edbInfo.Source
- edbLog.EdbCode = edbInfo.EdbCode
- edbLog.EdbName = edbInfo.EdbName
- edbLog.ClassifyId = edbInfo.ClassifyId
- edbLog.SysUserId = sysUser.AdminId
- edbLog.SysUserRealName = sysUser.RealName
- edbLog.CreateTime = time.Now()
- edbLog.Content = string(this.Ctx.Input.RequestBody)
- edbLog.Status = "编辑指标英文信息"
- edbLog.Method = this.Ctx.Input.URI()
- go data_manage.AddEdbInfoLog(edbLog)
- }
- //添加es
- data.AddOrEditEdbInfoToEs(req.EdbInfoId)
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.IsAddLog = true
- }
- // @Title 获取最新指标接口
- // @Description 获取最新指标接口
- // @Success 200 {object} data_manage.EdbInfoList
- // @router /edb_info/newest [get]
- func (this *EdbInfoController) EdbInfoNewest() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- item, err := data_manage.GetEdbInfoByNewest()
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取最新指标失败"
- br.ErrMsg = "获取最新指标失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = item
- }
- // @Title 指标刷新接口
- // @Description 指标刷新接口
- // @Param EdbInfoId query int true "指标id"
- // @Success Ret=200 刷新成功
- // @router /edb_info/refresh [get]
- func (this *EdbInfoController) EdbInfoRefresh() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- edbInfoId, _ := this.GetInt("EdbInfoId")
- if edbInfoId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误"
- return
- }
- _, err := data_manage.GetEdbInfoById(edbInfoId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "数据已被删除,请刷新页面"
- br.ErrMsg = "数据已被删除,请刷新页面,edbInfoId:" + strconv.Itoa(edbInfoId)
- return
- }
- br.Msg = "刷新失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- err = data.EdbInfoRefreshAllFromBaseV2(edbInfoId, false)
- if err != nil {
- br.Msg = "刷新失败"
- br.ErrMsg = "刷新指标失败,EdbInfoRefresh Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "刷新成功"
- br.IsAddLog = true
- }
- // @Title 移动指标接口
- // @Description 移动指标接口
- // @Success 200 {object} data_manage.MoveEdbInfoReq
- // @router /edb_info/move [post]
- func (this *EdbInfoController) EdbInfoMove() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req data_manage.MoveEdbInfoReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.EdbInfoId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "指标id小于等于0"
- return
- }
- if req.ClassifyId <= 0 {
- br.Msg = "请选择分类"
- return
- }
- //判断分类是否存在
- count, _ := data_manage.GetEdbClassifyCountById(req.ClassifyId)
- if count <= 0 {
- br.Msg = "分类已被删除,不可移动,请刷新页面"
- return
- }
- edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- // 移动权限校验
- button := data.GetEdbOpButton(this.SysUser, edbInfo.SysUserId, edbInfo.EdbType, edbInfo.EdbInfoType)
- if !button.MoveButton {
- br.Msg = "无权限操作"
- br.IsSendEmail = false
- return
- }
- //如果改变了分类,那么移动该指标数据
- if edbInfo.ClassifyId != req.ClassifyId {
- err = data_manage.MoveEdbInfo(req.EdbInfoId, req.ClassifyId)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "移动指标失败,Err:" + err.Error()
- return
- }
- }
- updateCol := make([]string, 0)
- //如果有传入 上一个兄弟节点分类id
- if req.PrevEdbInfoId > 0 {
- prevEdbInfo, err := data_manage.GetEdbInfoById(req.PrevEdbInfoId)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "获取上一个兄弟节点分类信息失败,Err:" + err.Error()
- return
- }
- //如果是移动在两个兄弟节点之间
- if req.NextEdbInfoId > 0 {
- //下一个兄弟节点
- nextEdbInfo, err := data_manage.GetEdbInfoById(req.NextEdbInfoId)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "获取下一个兄弟节点分类信息失败,Err:" + err.Error()
- return
- }
- //如果上一个兄弟与下一个兄弟的排序权重是一致的,那么需要将下一个兄弟(以及下个兄弟的同样排序权重)的排序权重+2,自己变成上一个兄弟的排序权重+1
- if prevEdbInfo.Sort == nextEdbInfo.Sort || prevEdbInfo.Sort == edbInfo.Sort {
- //变更兄弟节点的排序
- updateSortStr := `sort + 2`
- _ = data_manage.UpdateEdbInfoSortByClassifyId(prevEdbInfo.ClassifyId, prevEdbInfo.Sort, prevEdbInfo.EdbInfoId, updateSortStr)
- } else {
- //如果下一个兄弟的排序权重正好是上个兄弟节点的下一层,那么需要再加一层了
- if nextEdbInfo.Sort-prevEdbInfo.Sort == 1 {
- //变更兄弟节点的排序
- updateSortStr := `sort + 1`
- _ = data_manage.UpdateEdbInfoSortByClassifyId(prevEdbInfo.ClassifyId, prevEdbInfo.Sort, prevEdbInfo.EdbInfoId, updateSortStr)
- }
- }
- }
- edbInfo.Sort = prevEdbInfo.Sort + 1
- edbInfo.ModifyTime = time.Now()
- updateCol = append(updateCol, "Sort", "ModifyTime")
- } else {
- firstClassify, err := data_manage.GetFirstEdbInfoByClassifyId(req.ClassifyId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "移动失败"
- br.ErrMsg = "获取获取当前父级分类下的排序第一条的分类信息失败,Err:" + err.Error()
- return
- }
- //如果该分类下存在其他分类,且第一个其他分类的排序等于0,那么需要调整排序
- if firstClassify != nil && firstClassify.Sort == 0 {
- updateSortStr := ` sort + 1 `
- _ = data_manage.UpdateEdbInfoSortByClassifyId(firstClassify.ClassifyId, 0, firstClassify.EdbInfoId-1, updateSortStr)
- }
- edbInfo.Sort = 0 //那就是排在第一位
- edbInfo.ModifyTime = time.Now()
- updateCol = append(updateCol, "Sort", "ModifyTime")
- }
- //更新
- if len(updateCol) > 0 {
- err = edbInfo.Update(updateCol)
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "修改失败,Err:" + err.Error()
- return
- }
- }
- if err != nil {
- br.Msg = "移动失败"
- br.ErrMsg = "修改失败,Err:" + err.Error()
- return
- }
- //新增操作日志
- {
- edbLog := new(data_manage.EdbInfoLog)
- edbLog.EdbInfoId = edbInfo.EdbInfoId
- edbLog.SourceName = edbInfo.SourceName
- edbLog.Source = edbInfo.Source
- edbLog.EdbCode = edbInfo.EdbCode
- edbLog.EdbName = edbInfo.EdbName
- edbLog.ClassifyId = edbInfo.ClassifyId
- edbLog.SysUserId = sysUser.AdminId
- edbLog.SysUserRealName = sysUser.RealName
- edbLog.CreateTime = time.Now()
- edbLog.Content = string(this.Ctx.Input.RequestBody)
- edbLog.Status = "移动指标"
- edbLog.Method = this.Ctx.Input.URI()
- go data_manage.AddEdbInfoLog(edbLog)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "移动成功"
- }
- // @Title 获取指标详情
- // @Description 获取指标详情接口
- // @Param EdbInfoId query int true "指标id"
- // @Success 200 {object} data_manage.EdbInfo
- // @router /edb_info/detail [get]
- func (this *EdbInfoController) EdbInfoDetail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- edbInfoId, _ := this.GetInt("EdbInfoId")
- if edbInfoId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误"
- return
- }
- edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = edbInfo
- }
- // EdbInfoFilter
- // @Title 指标筛选接口
- // @Description 指标筛选接口
- // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
- // @Param FilterSource query int false "搜索来源:1:其他搜索,2:累计值转月值搜索,3:变频,4:基础指标"
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Success 200 {object} data_manage.EdbInfoList
- // @router /edb_info/filter [get]
- func (this *EdbInfoController) EdbInfoFilter() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- keyWord := this.GetString("KeyWord")
- filterSource, _ := this.GetInt("FilterSource")
- if filterSource <= 0 {
- filterSource = 1
- }
- var pars []interface{}
- noPermissionEdbInfoIdList := make([]int, 0) //无权限指标
- // 获取当前账号的不可见指标
- {
- obj := data_manage.EdbInfoNoPermissionAdmin{}
- confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
- return
- }
- for _, v := range confList {
- noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
- }
- }
- var keyWordArr []string
- keyWordArr = append(keyWordArr, keyWord)
- if keyWord != "" {
- newKeyWord := strings.Split(keyWord, " ")
- keyWordArr = append(keyWordArr, newKeyWord...)
- }
- //var err error
- edbInfoList := make([]*data_manage.EdbInfoList, 0)
- //if keyWord == "" {
- // edbInfoList, err = data_manage.GetEdbInfoFilter(condition, pars)
- // if err != nil && err.Error() != utils.ErrNoRow() {
- // br.Success = true
- // br.Msg = "获取指标信息失败"
- // br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- // return
- // }
- //} else {
- // //获取指标信息
- // indexName := utils.DATA_INDEX_NAME
- // edbInfoList, err = data.EsSearchEdbInfo(indexName, keyWord,filterSource)
- // if err != nil && err.Error() != utils.ErrNoRow() {
- // br.Success = true
- // br.Msg = "获取指标信息失败"
- // br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- // return
- // }
- //}
- var baseCondition string
- // 无权限指标id
- lenNoPermissionEdbInfoIdList := len(noPermissionEdbInfoIdList)
- if lenNoPermissionEdbInfoIdList > 0 {
- baseCondition = ` AND edb_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionEdbInfoIdList) + `) `
- pars = append(pars, noPermissionEdbInfoIdList)
- }
- existMap := make(map[int]string)
- for _, v := range keyWordArr {
- v = strings.Replace(v, " ", "%", -1)
- var condition string
- if filterSource == 2 {
- condition += ` AND frequency='月度' `
- }
- if filterSource == 3 {
- condition += ` AND frequency <> '日度' `
- }
- if filterSource == 4 {
- condition += ` AND edb_type = 1 `
- }
- conditionWhere := `AND ( edb_code LIKE '%` + v + `%' OR edb_name LIKE '%` + v + `%' )`
- condition += conditionWhere + baseCondition
- newEdbInfoList, err := data_manage.GetEdbInfoFilter(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Success = true
- br.Msg = "获取指标信息失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- for _, nv := range newEdbInfoList {
- if _, ok := existMap[nv.EdbInfoId]; !ok {
- edbInfoList = append(edbInfoList, nv)
- }
- existMap[nv.EdbInfoId] = nv.EdbCode
- }
- }
- if edbInfoList == nil {
- edbInfoList = make([]*data_manage.EdbInfoList, 0)
- }
- edbInfoListLen := len(edbInfoList)
- for i := 0; i < edbInfoListLen; i++ {
- edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName
- }
- for i := 0; i < edbInfoListLen; i++ {
- for j := 0; j < edbInfoListLen; j++ {
- if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
- (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
- !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
- edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
- }
- }
- }
- //新增搜索词记录
- {
- searchKeyword := new(data_manage.SearchKeyword)
- searchKeyword.KeyWord = keyWord
- searchKeyword.CreateTime = time.Now()
- go data_manage.AddSearchKeyword(searchKeyword)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = edbInfoList
- }
- // EdbInfoFilterByEs
- // @Title 指标筛选接口
- // @Description 指标筛选接口
- // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
- // @Param FilterSource query int false "搜索来源:1:其他搜索,2:累计值转月值搜索,3:变频,4:基础指标,5:同比"
- // @Param Frequency query string false "频度"
- // @Param IsAddPredictEdb query bool false "是否查询添加预测指标"
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Success 200 {object} data_manage.EdbInfoList
- // @router /edb_info/filter_by_es [get]
- func (this *EdbInfoController) EdbInfoFilterByEs() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var total int64
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- keyWord := this.GetString("KeyWord")
- keyWord = strings.TrimSpace(keyWord) //移除字符串首尾空格
- filterSource, _ := this.GetInt("FilterSource")
- if filterSource <= 0 {
- filterSource = 1
- }
- //指标来源
- source, _ := this.GetInt("Source")
- frequency := this.GetString("Frequency") //频度
- isAddPredictEdb, _ := this.GetBool("IsAddPredictEdb") //是否查询添加预测指标
- var edbInfoList []*data_manage.EdbInfoList
- var err error
- noPermissionEdbInfoIdList := make([]int, 0) //无权限指标
- // 获取当前账号的不可见指标
- {
- obj := data_manage.EdbInfoNoPermissionAdmin{}
- confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
- return
- }
- for _, v := range confList {
- noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
- }
- }
- if keyWord != "" {
- var keyWordArr []string
- keyWordArr = append(keyWordArr, keyWord)
- newKeyWord := strings.Split(keyWord, " ")
- keyWordArr = append(keyWordArr, newKeyWord...)
- // 普通的搜索
- if !isAddPredictEdb {
- total, edbInfoList, err = elastic.SearchEdbInfoData(utils.DATA_INDEX_NAME, keyWord, startSize, pageSize, filterSource, source, 0, frequency, noPermissionEdbInfoIdList)
- } else {
- // 允许添加预测指标的搜索
- total, edbInfoList, err = elastic.SearchAddPredictEdbInfoData(utils.DATA_INDEX_NAME, keyWord, noPermissionEdbInfoIdList, startSize, pageSize)
- }
- } else {
- var condition string
- var pars []interface{}
- // 普通指标
- condition += ` AND edb_info_type = ? `
- pars = append(pars, 0)
- // 无权限指标id
- lenNoPermissionEdbInfoIdList := len(noPermissionEdbInfoIdList)
- if lenNoPermissionEdbInfoIdList > 0 {
- condition += ` AND edb_info_id not in (` + utils.GetOrmInReplace(lenNoPermissionEdbInfoIdList) + `) `
- pars = append(pars, noPermissionEdbInfoIdList)
- }
- switch filterSource {
- case 2:
- condition += ` AND frequency='月度' `
- case 3:
- condition += ` AND frequency <> '日度' `
- case 4:
- condition += ` AND edb_type = 1 `
- case 5:
- condition += ` AND source = 6 ` //来源(同比值)
- case 6:
- condition += ` AND frequency != ? `
- pars = append(pars, "年度")
- }
- //频度
- if frequency != "" {
- condition += ` AND frequency = ? `
- pars = append(pars, frequency)
- }
- // 查询只允许添加预测指标的搜索
- if isAddPredictEdb {
- condition += ` AND frequency in ("日度","周度","月度") `
- }
- total, edbInfoList, err = data_manage.GetEdbInfoFilterList(condition, pars, startSize, pageSize)
- }
- if err != nil {
- edbInfoList = make([]*data_manage.EdbInfoList, 0)
- }
- page := paging.GetPaging(currentIndex, pageSize, int(total))
- edbInfoListLen := len(edbInfoList)
- for i := 0; i < edbInfoListLen; i++ {
- edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName
- }
- for i := 0; i < edbInfoListLen; i++ {
- for j := 0; j < edbInfoListLen; j++ {
- if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
- (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
- !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
- edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
- }
- }
- }
- //新增搜索词记录
- {
- searchKeyword := new(data_manage.SearchKeyword)
- searchKeyword.KeyWord = keyWord
- searchKeyword.CreateTime = time.Now()
- go data_manage.AddSearchKeyword(searchKeyword)
- }
- resp := data_manage.EdbInfoFilterDataResp{
- Paging: page,
- List: edbInfoList,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- func (this *EdbInfoController) EdbInfoFilter2() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- keyWord := this.GetString("KeyWord")
- keyWord = strings.TrimSpace(keyWord) //移除字符串首尾空格
- filterSource, _ := this.GetInt("FilterSource")
- if filterSource <= 0 {
- filterSource = 1
- }
- var pars []interface{}
- //if keyWord != "" {
- // condition += ` AND ( edb_code LIKE '%` + keyWord + `%' OR edb_name LIKE '%` + keyWord + `%' )`
- //}
- var keyWordArr []string
- keyWordArr = append(keyWordArr, keyWord)
- if keyWord != "" {
- newKeyWord := strings.Split(keyWord, " ")
- keyWordArr = append(keyWordArr, newKeyWord...)
- }
- keywordLen := len(keyWordArr)
- ch := make(chan map[int][]*data_manage.EdbInfoList, keywordLen)
- searchWait := sync.WaitGroup{}
- searchWait.Add(keywordLen)
- for index, v := range keyWordArr {
- v = strings.Replace(v, " ", "%", -1)
- var condition string
- if filterSource == 2 {
- condition += ` AND frequency='月度' `
- }
- if filterSource == 3 {
- condition += ` AND frequency <> '日度' `
- }
- if filterSource == 4 {
- condition += ` AND edb_type = 1 `
- }
- conditionWhere := `AND ( edb_code LIKE '%` + v + `%' OR edb_name LIKE '%` + v + `%' )`
- condition += conditionWhere
- go searchEdbInfoFilter(condition, pars, index, ch, &searchWait)
- }
- searchWait.Wait()
- newEdbInfoListMap := make(map[int][]*data_manage.EdbInfoList)
- i := 0
- for tmpEdbInfoList := range ch {
- i++
- for k, v := range tmpEdbInfoList {
- newEdbInfoListMap[k] = v
- }
- if i == keywordLen {
- break
- }
- }
- close(ch)
- edbInfoList := make([]*data_manage.EdbInfoList, 0)
- existMap := make(map[int]string)
- for i := 0; i < keywordLen; i++ {
- if newEdbInfoList, ok := newEdbInfoListMap[i]; ok {
- for _, nv := range newEdbInfoList {
- if _, ok := existMap[nv.EdbInfoId]; !ok {
- edbInfoList = append(edbInfoList, nv)
- }
- existMap[nv.EdbInfoId] = nv.EdbCode
- }
- }
- }
- if edbInfoList == nil {
- edbInfoList = make([]*data_manage.EdbInfoList, 0)
- }
- edbInfoListLen := len(edbInfoList)
- for i := 0; i < edbInfoListLen; i++ {
- edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName
- }
- for i := 0; i < edbInfoListLen; i++ {
- for j := 0; j < edbInfoListLen; j++ {
- if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
- (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
- !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
- edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
- }
- }
- }
- //新增搜索词记录
- {
- searchKeyword := new(data_manage.SearchKeyword)
- searchKeyword.KeyWord = keyWord
- searchKeyword.CreateTime = time.Now()
- go data_manage.AddSearchKeyword(searchKeyword)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = edbInfoList
- }
- 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) {
- newEdbInfoListMap = make(map[int][]*data_manage.EdbInfoList)
- defer func() {
- if err != nil {
- go alarm_msg.SendAlarmMsg("查询近6个月的客户增量数据异常:"+err.Error(), 3)
- //go utils.SendEmail(utils.APPNAME+"查询近6个月的客户增量数据异常:"+time.Now().Format("2006-01-02 15:04:05"), err.Error(), utils.EmailSendToUsers)
- }
- ch <- newEdbInfoListMap
- searchWait.Done()
- }()
- newEdbInfoList, err := data_manage.GetEdbInfoFilter(condition, pars)
- newEdbInfoListMap[i] = newEdbInfoList
- return
- }
- // @Title 指标全部刷新接口
- // @Description 指标全部刷新接口
- // @Param EdbInfoId query int true "指标id"
- // @Success Ret=200 全部刷新成功
- // @router /edb_info/refresh/all [get]
- func (this *EdbInfoController) EdbInfoAllRefresh() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- edbInfoId, _ := this.GetInt("EdbInfoId")
- if edbInfoId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误"
- return
- }
- edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- br.Msg = "数据已被删除,请刷新页面"
- br.ErrMsg = "数据已被删除,请刷新页面,edbInfoId:" + strconv.Itoa(edbInfoId)
- return
- }
- br.Msg = "刷新失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- if edbInfo == nil {
- br.Msg = "数据已被删除,请刷新页面"
- br.ErrMsg = "数据已被删除,请刷新页面,edbInfoId:" + strconv.Itoa(edbInfoId)
- return
- }
- err = data.EdbInfoRefreshAllFromBaseV2(edbInfoId, true)
- if err != nil {
- br.Msg = "刷新失败"
- br.ErrMsg = "刷新指标失败,EdbInfoRefreshAllFromBase Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "刷新成功"
- }
- // @Title 获取指标数据
- // @Description 获取指标数据
- // @Param EdbInfoId query int true "指标ID"
- // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:自定义起始时间至今,7:18年至今,8:19年至今,9:20年至今,10:全部"
- // @Param StartDate query string true "自定义开始日期"
- // @Param EndDate query string true "自定义结束日期"
- // @Success 200 {object} data_manage.EdbInfoDataResp
- // @router /edb_info/data [get]
- func (this *ChartInfoController) EdbInfoData() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- edbInfoId, _ := this.GetInt("EdbInfoId")
- if edbInfoId <= 0 {
- br.Msg = "参数错误"
- return
- }
- dateType, _ := this.GetInt("DateType")
- if dateType <= 0 {
- dateType = 3
- }
- edbInfoType, _ := this.GetInt("EdbInfoType")
- if edbInfoType < 0 {
- edbInfoType = 1
- }
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- startDate, endDate = utils.GetDateByDateType(dateType, startDate, endDate)
- edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
- if err != nil {
- br.Msg = "获取失败"
- br.Msg = "获取失败,Err:" + err.Error()
- return
- }
- dataList, err := data_manage.GetEdbDataList(edbInfo.Source, edbInfoId, startDate, endDate)
- if err != nil {
- br.Msg = "获取失败"
- br.Msg = "获取失败,Err:" + err.Error()
- return
- }
- resp := new(data_manage.EdbInfoDataResp)
- resp.EdbInfo = edbInfo
- resp.DataList = dataList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 指标一键刷新接口
- // @Description 指标一键刷新接口
- // @Success Ret=200 更新成功
- // @router /edb_info/replace/check [post]
- func (this *EdbInfoController) EdbInfoReplaceCheck() {
- br := new(models.BaseResponse).Init()
- setNxKey := "EDB_INFO_REPLACE"
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- status := 0
- if utils.Rc.IsExist(setNxKey) {
- status = 1
- } else {
- status = 2
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "检测成功"
- br.Data = status
- }
- // EdbInfoReplace
- // @Title 替换指标
- // @Description 替换指标
- // @Param request body data_manage.EdbInfoReplaceReq true "type json string"
- // @Success 200 {object} data_manage.EdbInfoDataResp
- // @router /edb_info/replace [post]
- func (this *ChartInfoController) EdbInfoReplace() {
- br := new(models.BaseResponse).Init()
- setNxKey := "EDB_INFO_REPLACE"
- deleteCache := true
- defer func() {
- if deleteCache {
- utils.Rc.Delete(setNxKey)
- }
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- if !utils.Rc.SetNX(setNxKey, 1, 30*time.Minute) {
- deleteCache = false
- br.Msg = "当前正在替换中,请耐心等待!"
- br.IsSendEmail = false
- return
- }
- var req data_manage.EdbInfoReplaceReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.OldEdbInfoId <= 0 || req.NewEdbInfoId <= 0 {
- br.Msg = "参数错误!"
- br.ErrMsg = "参数错误,指标id为0"
- return
- }
- oldEdbInfo, err := data_manage.GetEdbInfoById(req.OldEdbInfoId)
- if err != nil {
- br.Msg = "替换失败!"
- br.ErrMsg = "获取原指标失败,Err:" + err.Error()
- return
- }
- newEdbInfo, err := data_manage.GetEdbInfoById(req.NewEdbInfoId)
- if err != nil {
- br.Msg = "替换失败!"
- br.ErrMsg = "获取替换目标指标失败,Err:" + err.Error()
- return
- }
- //if oldEdbInfo.EdbType != 1 {
- // br.Msg = "原指标为计算指标,不可替换!"
- // br.ErrMsg = "原指标为计算指标,不可替换!"
- // return
- //}
- //
- //if newEdbInfo.EdbType != 1 {
- // br.Msg = "替换指标为计算指标,不可替换!"
- // br.ErrMsg = "替换指标为计算指标,不可替换!"
- // return
- //}
- if oldEdbInfo.Frequency != newEdbInfo.Frequency {
- br.Msg = "原指标频度为:" + oldEdbInfo.Frequency + " 替换指标频度为:" + newEdbInfo.Frequency + ",频度不同,不可进行替换操作!"
- br.ErrMsg = "原指标频度为:" + oldEdbInfo.Frequency + " 替换指标频度为:" + newEdbInfo.Frequency + ",频度不同,不可进行替换操作!"
- return
- }
- sysAdminId := sysUser.AdminId
- //replaceChartTotal, replaceCalculateTotal, err := data.EdbInfoReplace(oldEdbInfo, newEdbInfo, sysAdminId, sysUser.RealName)
- _, _, err = data_manage.EdbInfoReplaceV2(oldEdbInfo, newEdbInfo, sysAdminId, sysUser.RealName)
- //msgContent := ``
- isFail := false
- var errmsg string
- if err != nil {
- //msgContent = oldEdbInfo.EdbName + "指标替换" + newEdbInfo.EdbName + "指标,全部替换失败,涉及" + strconv.Itoa(replaceChartTotal) + "张图表,\n\n " + strconv.Itoa(replaceCalculateTotal) + "个计算指标"
- isFail = true
- errmsg = "replace err:" + err.Error()
- } else {
- //msgContent = oldEdbInfo.EdbName + "指标替换" + newEdbInfo.EdbName + "指标,全部替换成功,涉及" + strconv.Itoa(replaceChartTotal) + "张图表,\n\n" + strconv.Itoa(replaceCalculateTotal) + "个计算指标"
- isFail = false
- }
- // 添加站内信息
- //{
- // msgItem := new(company.CompanyApprovalMessage)
- // msgItem.CreateUserId = sysAdminId
- // msgItem.ReceiveUserId = sysAdminId
- // msgItem.MessageStatus = 0
- // msgItem.Remark = "指标替换"
- // msgItem.OperationStatus = 1
- // msgItem.Content = msgContent
- // msgItem.CreateTime = time.Now()
- // msgItem.ModifyTime = time.Now()
- // msgItem.MessageType = 3 //1:申请消息,2:审批结果,3:文字消息
- // msgItem.SourceType = 4 //消息来源
- // err = company.AddCompanyApprovalMessage(msgItem)
- //}
- if isFail {
- br.Msg = "替换失败"
- br.ErrMsg = "替换失败 err:" + errmsg
- } else {
- br.Msg = "替换成功"
- br.ErrMsg = "替换成功"
- br.Ret = 200
- }
- br.IsAddLog = true
- return
- }
- // RelationChartList
- // @Title 获取ETA指标关联的图表列表接口
- // @Description 获取ETA指标关联的图表列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param EdbInfoId query int true "指标id"
- // @Param IsShowMe query bool true "是否只看我的,true、false"
- // @Success 200 {object} data_manage.ChartListResp
- // @router /edb_info/relation/chart_list [get]
- func (this *EdbInfoController) RelationChartList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- edbInfoId, _ := this.GetInt("EdbInfoId")
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- resp := data_manage.ChartListResp{}
- var total int
- page := paging.GetPaging(currentIndex, pageSize, total)
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- if edbInfoId <= 0 {
- br.Msg = "请选择指标"
- br.ErrMsg = "请选择指标"
- br.IsSendEmail = false
- return
- }
- // 关联指标
- condition += ` AND b.edb_info_id = ? `
- pars = append(pars, edbInfoId)
- //只看我的
- isShowMe, _ := this.GetBool("IsShowMe")
- if isShowMe {
- condition += ` AND a.sys_user_id = ? `
- pars = append(pars, sysUser.AdminId)
- }
- // 获取当前账号的不可见图表
- noPermissionChartIdList := make([]int, 0)
- {
- obj := data_manage.EdbInfoNoPermissionAdmin{}
- confList, err := obj.GetAllChartListByAdminId(this.SysUser.AdminId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
- return
- }
- for _, v := range confList {
- noPermissionChartIdList = append(noPermissionChartIdList, v.ChartInfoId)
- }
- }
- noPermissionChartIdNum := len(noPermissionChartIdList)
- if noPermissionChartIdNum > 0 {
- condition += ` AND a.chart_info_id not in (` + utils.GetOrmInReplace(noPermissionChartIdNum) + `) `
- pars = append(pars, noPermissionChartIdList)
- }
- //获取关联图表列表
- list, err := data_manage.GetRelationChartListByCondition(condition, pars, startSize, pageSize)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Success = true
- br.Msg = "获取图表信息失败"
- br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
- return
- }
- if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
- items := make([]*data_manage.ChartInfoView, 0)
- resp.Paging = page
- resp.List = items
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- return
- }
- // 获取关联图表总数
- dataCount, err := data_manage.GetRelationChartListCountByCondition(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取指标信息失败"
- br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
- return
- }
- // 获取MY ETA 图表,用来判断是否加入我的图库
- myChartList, err := data_manage.GetMyChartListByAdminId(sysUser.AdminId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取图表信息失败"
- br.ErrMsg = "获取我的图表信息失败,Err:" + err.Error()
- return
- }
- myChartMap := make(map[int]*data_manage.MyChartView)
- for _, v := range myChartList {
- myChartMap[v.ChartInfoId] = v
- }
- listLen := len(list)
- for i := 0; i < listLen; i++ {
- if existItem, ok := myChartMap[list[i].ChartInfoId]; ok {
- list[i].IsAdd = true
- list[i].MyChartId = existItem.MyChartId
- list[i].MyChartClassifyId = existItem.MyChartClassifyId
- }
- }
- page = paging.GetPaging(currentIndex, pageSize, dataCount)
- resp.Paging = page
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // RelationEdbList
- // @Title 获取ETA指标关联的指标列表接口
- // @Description 获取ETA指标关联的指标列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param EdbInfoId query int true "指标id"
- // @Param IsShowMe query bool true "是否只看我的,true、false"
- // @Success 200 {object} data_manage.ChartListResp
- // @router /edb_info/relation/edbinfo_list [get]
- func (this *EdbInfoController) RelationEdbList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- edbInfoId, _ := this.GetInt("EdbInfoId")
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- resp := data_manage.RelationEdbInfoListResp{}
- var total int
- page := paging.GetPaging(currentIndex, pageSize, total)
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- var condition string
- var pars []interface{}
- if edbInfoId <= 0 {
- br.Msg = "请选择指标"
- br.ErrMsg = "请选择指标"
- br.IsSendEmail = false
- return
- }
- // 关联指标
- condition += ` AND b.from_edb_info_id = ? `
- pars = append(pars, edbInfoId)
- //只看我的
- isShowMe, _ := this.GetBool("IsShowMe")
- if isShowMe {
- condition += ` AND a.sys_user_id = ? `
- pars = append(pars, sysUser.AdminId)
- }
- // 获取当前账号的不可见图表
- noPermissionEdbIdList := make([]int, 0)
- {
- obj := data_manage.EdbInfoNoPermissionAdmin{}
- confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
- return
- }
- for _, v := range confList {
- noPermissionEdbIdList = append(noPermissionEdbIdList, v.EdbInfoId)
- }
- }
- noPermissionEdbIdNum := len(noPermissionEdbIdList)
- if noPermissionEdbIdNum > 0 {
- condition += ` AND a.edb_info_id not in (` + utils.GetOrmInReplace(noPermissionEdbIdNum) + `) `
- pars = append(pars, noPermissionEdbIdList)
- }
- //获取关联图表列表
- list, err := data_manage.GetRelationEdbInfoListByCondition(condition, pars, startSize, pageSize)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Success = true
- br.Msg = "获取图表信息失败"
- br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
- return
- }
- if list == nil || len(list) <= 0 || (err != nil && err.Error() == utils.ErrNoRow()) {
- items := make([]*data_manage.ChartEdbInfoMapping, 0)
- resp.Paging = page
- resp.List = items
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- return
- }
- // 获取关联图表总数
- dataCount, err := data_manage.GetRelationEdbInfoListCountByCondition(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取指标信息失败"
- br.ErrMsg = "获取指标数据总数失败,Err:" + err.Error()
- return
- }
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
- return
- }
- edbList := make([]*data_manage.ChartEdbInfoMapping, 0)
- for _, v := range list {
- item := new(data_manage.ChartEdbInfoMapping)
- item.EdbInfoId = v.EdbInfoId
- item.SourceName = v.SourceName
- item.Source = v.Source
- item.EdbCode = v.EdbCode
- item.EdbName = v.EdbName
- item.EdbNameEn = v.EdbNameEn
- item.Frequency = v.Frequency
- item.FrequencyEn = data.GetFrequencyEn(v.Frequency)
- if v.Unit != `无` {
- item.Unit = v.Unit
- }
- item.UnitEn = v.UnitEn
- item.StartDate = v.StartDate
- item.EndDate = v.EndDate
- item.ModifyTime = v.ModifyTime
- item.IsAxis = 1
- item.LeadValue = 0
- item.LeadUnit = ""
- item.ChartEdbMappingId = 0
- item.ChartInfoId = 0
- item.IsOrder = false
- item.EdbInfoType = v.EdbInfoType
- item.EdbInfoCategoryType = v.EdbInfoType
- item.ChartStyle = ""
- item.ChartColor = ""
- item.ChartWidth = 0
- item.MaxData = v.MaxValue
- item.MinData = v.MinValue
- item.LatestValue = v.LatestValue
- item.LatestDate = v.LatestDate
- item.UniqueCode = v.UniqueCode
- item.ClassifyId = v.ClassifyId
- dataList := make([]*data_manage.EdbDataList, 0)
- if v.EdbInfoType == 0 {
- dataList, err = data_manage.GetEdbDataList(v.Source, v.EdbInfoId, "", "")
- } else {
- _, dataList, _, _, err, _ = data.GetPredictDataListByPredictEdbInfoId(v.EdbInfoId, "", "", false)
- }
- if err != nil {
- br.Msg = "获取失败"
- br.Msg = "获取失败,Err:" + err.Error()
- return
- }
- item.DataList = dataList
- edbList = append(edbList, item)
- }
- page = paging.GetPaging(currentIndex, pageSize, dataCount)
- resp.Paging = page
- resp.List = edbList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // MoveEdbChartList
- // @Title 获取指标/图表创建人列表数据接口
- // @Description 获取指标/图表创建人列表数据接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param Source query int false "来源 :1:手工数据指标 2:钢联化工数据库 3:ETA指标库 4:ETA预测指标 5:图库"
- // @Param Keyword query string false "关键字,code或者名称"
- // @Param Classify query string false "分类id"
- // @Param UserId query int false "创建人id"
- // @Success 200 {object} data_manage.ChartListResp
- // @router /edb_chart/list [get]
- func (this *EdbInfoController) MoveEdbChartList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- source, _ := this.GetInt("Source")
- if source <= 0 || source > 5 {
- br.Msg = "错误的来源"
- br.IsSendEmail = false
- return
- }
- userId, _ := this.GetInt("UserId")
- keyword := this.GetString("Keyword")
- classify := this.GetString("Classify")
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- resp := data_manage.MoveEdbChartListResp{}
- var total int
- page := paging.GetPaging(currentIndex, pageSize, total)
- defaultList := make([]data_manage.MoveEdbChartList, 0)
- resp.List = defaultList
- resp.Paging = page
- // 没有传入条件,那就默认自动返回
- if userId <= 0 && keyword == `` && classify == `` {
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- }
- list, total, err := data.GetMoveEdbChartList(source, userId, keyword, classify, startSize, pageSize)
- if err != nil {
- //br.Success = true
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if list == nil {
- list = defaultList
- }
- page = paging.GetPaging(currentIndex, pageSize, total)
- resp.Paging = page
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // MoveEdbChartUser
- // @Title 指标/图表创建人变更接口
- // @Description 指标/图表创建人变更接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param EdbInfoId query int true "指标id"
- // @Param IsShowMe query bool true "是否只看我的,true、false"
- // @Success 200 {object} data_manage.ChartListResp
- // @router /edb_chart/change_user [post]
- func (this *EdbInfoController) MoveEdbChartUser() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req data_manage.MoveEdbChartReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.Source <= 0 || req.Source > 5 {
- br.Msg = "错误的来源"
- br.IsSendEmail = false
- return
- }
- if len(req.DataIdList) <= 0 {
- br.Msg = "请勾选数据项"
- br.IsSendEmail = false
- return
- }
- if req.NewUserId <= 0 {
- br.Msg = "请选择新的创建人"
- br.IsSendEmail = false
- return
- }
- err, errMsg := data.MoveEdbChart(req.Source, req.NewUserId, req.DataIdList)
- if err != nil {
- //br.Success = true
- br.Msg = "获取失败"
- if errMsg != `` {
- br.Msg = errMsg
- }
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.IsAddLog = true
- br.Success = true
- br.Msg = "修改成功"
- }
- // MoveEdbChartList
- // @Title 获取指标/图表分类列表数据接口
- // @Description 获取指标/图表分类列表数据接口
- // @Param Source query int false "来源 :1:手工数据指标 2:钢联化工数据库 3:ETA指标库 4:ETA预测指标 5:图库"
- // @Success 200 {object} data_manage.ChartListResp
- // @router /edb_chart/classify [get]
- func (this *EdbInfoController) EdbChartClassifyList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- source, _ := this.GetInt("Source")
- if source <= 0 || source > 5 {
- br.Msg = "错误的来源"
- br.IsSendEmail = false
- return
- }
- list, err := data.GetEdbChartClassifyList(source)
- if err != nil {
- //br.Success = true
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = list
- }
- // EdbInfoDataTb
- // @Title 获取指标数据同比值
- // @Description 获取指标数据
- // @Param EdbInfoId query int true "指标ID"
- // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:自定义起始时间至今,7:18年至今,8:19年至今,9:20年至今,10:全部"
- // @Param StartDate query string true "自定义开始日期"
- // @Param EndDate query string true "自定义结束日期"
- // @Success 200 {object} data_manage.EdbInfoDataResp
- // @router /edb_info/data/tb [get]
- func (this *ChartInfoController) EdbInfoDataTb() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- edbInfoId, _ := this.GetInt("EdbInfoId")
- if edbInfoId <= 0 {
- br.Msg = "参数错误"
- return
- }
- dateType, _ := this.GetInt("DateType")
- if dateType <= 0 {
- dateType = 3
- }
- edbInfoType, _ := this.GetInt("EdbInfoType")
- if edbInfoType < 0 {
- edbInfoType = 1
- }
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- startDate, endDate = utils.GetDateByDateType(dateType, startDate, endDate)
- edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
- if err != nil {
- br.Msg = "获取失败"
- br.Msg = "获取失败,Err:" + err.Error()
- return
- }
- var startDateTime time.Time
- if startDate != `` {
- startDateTime, err = time.ParseInLocation(utils.FormatDate, startDate, time.Local)
- if err != nil {
- br.Msg = "开始日期异常"
- br.Msg = "开始日期异常,Err:" + err.Error()
- return
- }
- //同比值的计算方式,是需要与去年同期对比,所以如果用户需要某个时间段的数据的话,获取基础数据时,需要往前面推(1年+兼容的日期频度(目前是35天))
- startDate = startDateTime.AddDate(-1, 0, -35).Format(utils.FormatDate)
- }
- tmpDataList, err := data_manage.GetEdbDataList(edbInfo.Source, edbInfoId, startDate, endDate)
- if err != nil {
- br.Msg = "获取失败"
- br.Msg = "获取失败,Err:" + err.Error()
- return
- }
- // 计算同比值
- dataList, minValue, maxValue, err := data.GetEdbDataTbz(edbInfo, tmpDataList, startDateTime)
- if err != nil {
- br.Msg = "获取失败"
- br.Msg = "计算同比值失败,Err:" + err.Error()
- return
- }
- edbInfo.MaxValue = maxValue
- edbInfo.MinValue = minValue
- resp := new(data_manage.EdbInfoDataResp)
- resp.EdbInfo = edbInfo
- resp.DataList = dataList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // EdbInfoDataSeasonal
- // @Title 获取指标数据(季节性)
- // @Description 获取指标数据
- // @Param EdbInfoId query int true "指标ID"
- // @Param DateType query int true "日期类型:1:00年至今,2:10年至今,3:15年至今,4:年初至今,5:自定义时间,6:自定义起始时间至今,7:18年至今,8:19年至今,9:20年至今,10:全部"
- // @Param StartDate query string true "自定义开始日期"
- // @Param EndDate query string true "自定义结束日期"
- // @Param Calendar query string true "公历/农历"
- // @Success 200 {object} data_manage.EdbInfoDataResp
- // @router /edb_info/data/seasonal [get]
- func (this *ChartInfoController) EdbInfoDataSeasonal() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- startDate := this.GetString("StartDate")
- endDate := this.GetString("EndDate")
- edbInfoIdStr := this.GetString("EdbInfoId")
- edbInfoId, err := strconv.Atoi(edbInfoIdStr)
- if err != nil {
- br.Msg = "指标id异常"
- br.Msg = "指标id转换异常,Err:" + err.Error()
- return
- }
- fmt.Println("startDate:", startDate)
- fmt.Println("endDate:", endDate)
- calendar := this.GetString("Calendar")
- if calendar == "" {
- calendar = "公历"
- }
- if startDate != `` {
- startDate = startDate + "-01"
- } else {
- fivePre := time.Now().AddDate(-4, 0, 0).Year()
- startDate = strconv.Itoa(fivePre) + "-01-01"
- }
- if endDate != `` {
- seasonEndDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, endDate+"-01", time.Local)
- if tmpErr != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取图表,指标信息失败,Err:" + tmpErr.Error()
- return
- }
- endDate = seasonEndDateTime.AddDate(0, 1, -1).Format(utils.FormatDate)
- }
- edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
- if err != nil {
- br.Msg = "获取失败"
- br.Msg = "获取失败,Err:" + err.Error()
- return
- }
- dataList, err := data.GetChartEdbSeasonalData(calendar, startDate, endDate, edbInfo)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
- return
- }
- resp := new(data_manage.EdbInfoDataSeasonalResp)
- resp.EdbInfo = edbInfo
- resp.DataList = dataList
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // SetEdbDataInsertConfig 设置插入值
- // @Title 设置插入值接口
- // @Description 设置插入值接口
- // @Success 200 {object} data_manage.EditEdbEnInfoReq
- // @router /edb_info/insert_config/set [post]
- func (this *EdbInfoController) SetEdbDataInsertConfig() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var req data_manage.SetEdbDataInsertConfigReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- dateStr := req.Date
- if dateStr == `` {
- br.Msg = "请选择日期"
- br.IsSendEmail = false
- return
- }
- date, err := time.ParseInLocation(utils.FormatDate, dateStr, time.Local)
- if err != nil {
- br.Msg = "日期异常"
- br.ErrMsg = "日期异常,err:" + err.Error()
- br.IsSendEmail = false
- return
- }
- edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
- if err != nil {
- br.Msg = "获取指标信息失败"
- br.ErrMsg = "获取指标信息失败,Err:" + err.Error()
- return
- }
- err, errMsg, isSendEmail := data_manage.CreateEdbDataInsertConfigAndData(edbInfo, date, req.Value)
- if err != nil {
- br.Msg = "设置失败"
- if errMsg != `` {
- br.Msg = errMsg
- }
- br.ErrMsg = "修改失败,Err:" + err.Error()
- br.IsSendEmail = isSendEmail
- return
- }
- //新增操作日志
- {
- edbLog := new(data_manage.EdbInfoLog)
- edbLog.EdbInfoId = edbInfo.EdbInfoId
- edbLog.SourceName = edbInfo.SourceName
- edbLog.Source = edbInfo.Source
- edbLog.EdbCode = edbInfo.EdbCode
- edbLog.EdbName = edbInfo.EdbName
- edbLog.ClassifyId = edbInfo.ClassifyId
- edbLog.SysUserId = sysUser.AdminId
- edbLog.SysUserRealName = sysUser.RealName
- edbLog.CreateTime = time.Now()
- edbLog.Content = string(this.Ctx.Input.RequestBody)
- edbLog.Status = "设置插入值"
- edbLog.Method = this.Ctx.Input.URI()
- go data_manage.AddEdbInfoLog(edbLog)
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "保存成功"
- br.IsAddLog = true
- }
- // TraceEdbInfo
- // @Title 指标溯源接口
- // @Description 指标溯源接口
- // @Param EdbInfoId query int true "指标id"
- // @Success 200 {object} data_manage.ChartListResp
- // @router /edb_info/trace [get]
- func (this *EdbInfoController) TraceEdbInfo() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- sysUser := this.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- edbInfoId, _ := this.GetInt("EdbInfoId")
- if edbInfoId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误"
- return
- }
- resp, err := data.TraceEdbInfoByEdbInfoId(edbInfoId)
- if err != nil {
- br.Msg = "获取失败"
- br.Msg = "获取失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Data = resp
- br.Success = true
- br.Msg = "刷新成功"
- }
- // AllEdbInfoByEs
- // @Title 所有指标筛选接口
- // @Description 所有指标筛选接口
- // @Param KeyWord query string false "搜索关键词:指标ID/指标名称"
- // @Param FilterSource query int false "搜索来源:1:其他搜索,2:累计值转月值搜索,3:变频,4:基础指标,5:同比"
- // @Param Frequency query string false "频度"
- // @Param IsAddPredictEdb query bool false "是否查询添加预测指标"
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Success 200 {object} data_manage.EdbInfoList
- // @router /edb_info/filter_by_es/all [get]
- func (this *EdbInfoController) AllEdbInfoByEs() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var total int64
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- keyWord := this.GetString("KeyWord")
- keyWord = strings.TrimSpace(keyWord) //移除字符串首尾空格
- filterSource, _ := this.GetInt("FilterSource")
- if filterSource <= 0 {
- filterSource = 1
- }
- //指标来源
- source, _ := this.GetInt("Source")
- var edbInfoList []*data_manage.EdbInfoList
- var err error
- noPermissionEdbInfoIdList := make([]int, 0) //无权限指标
- // 获取当前账号的不可见指标
- {
- obj := data_manage.EdbInfoNoPermissionAdmin{}
- confList, err := obj.GetAllListByAdminId(this.SysUser.AdminId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "获取不可见指标配置数据失败,Err:" + err.Error()
- return
- }
- for _, v := range confList {
- noPermissionEdbInfoIdList = append(noPermissionEdbInfoIdList, v.EdbInfoId)
- }
- }
- if keyWord != "" {
- var keyWordArr []string
- keyWordArr = append(keyWordArr, keyWord)
- newKeyWord := strings.Split(keyWord, " ")
- keyWordArr = append(keyWordArr, newKeyWord...)
- // 普通的搜索
- total, edbInfoList, err = elastic.SearchEdbInfoData(utils.DATA_INDEX_NAME, keyWord, startSize, pageSize, filterSource, source, -1, ``, noPermissionEdbInfoIdList)
- }
- if err != nil {
- edbInfoList = make([]*data_manage.EdbInfoList, 0)
- }
- page := paging.GetPaging(currentIndex, pageSize, int(total))
- edbInfoListLen := len(edbInfoList)
- for i := 0; i < edbInfoListLen; i++ {
- edbInfoList[i].EdbNameAlias = edbInfoList[i].EdbName
- }
- for i := 0; i < edbInfoListLen; i++ {
- for j := 0; j < edbInfoListLen; j++ {
- if (edbInfoList[i].EdbNameAlias == edbInfoList[j].EdbNameAlias) &&
- (edbInfoList[i].EdbInfoId != edbInfoList[j].EdbInfoId) &&
- !(strings.Contains(edbInfoList[i].EdbName, edbInfoList[i].SourceName)) {
- edbInfoList[i].EdbName = edbInfoList[i].EdbName + "(" + edbInfoList[i].SourceName + ")"
- }
- }
- }
- //新增搜索词记录
- {
- searchKeyword := new(data_manage.SearchKeyword)
- searchKeyword.KeyWord = keyWord
- searchKeyword.CreateTime = time.Now()
- go data_manage.AddSearchKeyword(searchKeyword)
- }
- resp := data_manage.EdbInfoFilterDataResp{
- Paging: page,
- List: edbInfoList,
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // GetEdbDateData
- // @Title 所有指标筛选接口
- // @Description 所有指标筛选接口
- // @Param EdbInfoId query int false "指标id"
- // @Param Date query string false "日期"
- // @Param query string false "频度"
- // @Success 200 {object} data_manage.EdbInfoList
- // @router /edb_info/date_data [get]
- func (this *EdbInfoController) GetEdbDateData() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- edbInfoId, _ := this.GetInt("EdbInfoId")
- date := this.GetString("Date")
- if edbInfoId <= 0 {
- br.Msg = "请选择指标"
- br.IsSendEmail = false
- return
- }
- if date == `` {
- br.Msg = "请选择日期"
- br.IsSendEmail = false
- return
- }
- edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprint("获取指标信息失败,Err:", err.Error())
- return
- }
- val, err := data.GetDateData(edbInfo, date)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprint("获取指数据失败,Err:", err.Error())
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = val
- }
|