edb_info.go 139 KB

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