edb_info.go 109 KB

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