edb_info.go 118 KB

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