edb_info.go 112 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264
  1. package data
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "eta/eta_api/cache"
  6. "eta/eta_api/models"
  7. "eta/eta_api/models/data_manage"
  8. "eta/eta_api/models/data_manage/excel"
  9. "eta/eta_api/models/system"
  10. "eta/eta_api/services/alarm_msg"
  11. "eta/eta_api/services/data/data_manage_permission"
  12. "eta/eta_api/services/elastic"
  13. "eta/eta_api/utils"
  14. "fmt"
  15. "sort"
  16. "strconv"
  17. "strings"
  18. "time"
  19. )
  20. // EdbInfoRefreshAllFromBaseV2 全部刷新指标(切换到edb_lib服务)
  21. func EdbInfoRefreshAllFromBaseV2(edbInfoId int, refreshAll, isRefreshTop bool) (err error, isAsync bool) {
  22. var errmsg string
  23. defer func() {
  24. if err != nil {
  25. fmt.Println("EdbInfoRefreshAllFromBaseV2 Err:" + err.Error() + ";errmsg:" + errmsg)
  26. go alarm_msg.SendAlarmMsg("EdbInfoRefreshFromBaseV2,Err"+err.Error()+";errMsg:"+errmsg, 3)
  27. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "EdbInfoRefreshFromBase:"+errmsg, utils.EmailSendToUsers)
  28. }
  29. }()
  30. err, isAsync = EdbInfoRefreshAllFromBaseV3([]int{edbInfoId}, refreshAll, false, isRefreshTop)
  31. return
  32. }
  33. // EdbInfoRefreshAllFromBaseV3Bak 全部刷新指标(切换到edb_lib服务)
  34. // @author Roc
  35. // @datetime 2022-09-16 11:04:44
  36. // @description 将原有的单个指标刷新,调整为批量多个指标刷新
  37. // DeprecatedTime 2023-10-23 09:38:19废弃
  38. // Deprecated
  39. func EdbInfoRefreshAllFromBaseV3Bak(edbInfoIdList []int, refreshAll, isSync bool) (err error, isAsync bool) {
  40. var errmsg string
  41. defer func() {
  42. if err != nil {
  43. fmt.Println("EdbInfoRefreshAllFromBaseV2 Err:" + err.Error() + ";errmsg:" + errmsg)
  44. go alarm_msg.SendAlarmMsg("EdbInfoRefreshFromBaseV2,Err"+err.Error()+";errMsg:"+errmsg, 3)
  45. }
  46. }()
  47. // 获取关联的基础指标
  48. newBaseEdbInfoArr, newBasePredictEdbInfoArr, newCalculateMap, newPredictCalculateMap, calculateArr, predictCalculateArr, err, errmsg := getRefreshEdbInfoListByIds(edbInfoIdList)
  49. if err != nil {
  50. return
  51. }
  52. // 需要刷新的指标数量
  53. totalEdbInfo := len(newBaseEdbInfoArr) + len(calculateArr) + len(predictCalculateArr)
  54. if totalEdbInfo <= 20 || isSync {
  55. err = edbInfoRefreshAll(refreshAll, newBaseEdbInfoArr, newBasePredictEdbInfoArr, newCalculateMap, newPredictCalculateMap, calculateArr, predictCalculateArr)
  56. } else {
  57. isAsync = true
  58. go edbInfoRefreshAll(refreshAll, newBaseEdbInfoArr, newBasePredictEdbInfoArr, newCalculateMap, newPredictCalculateMap, calculateArr, predictCalculateArr)
  59. }
  60. return
  61. }
  62. // EdbInfoRefreshAllFromBaseV3
  63. //
  64. // @Description: 全部刷新指标(切换到edb_lib服务)
  65. // @author: Roc
  66. // @datetime 2023-10-23 09:57:55
  67. // @param edbInfoIdList []int
  68. // @param refreshAll bool
  69. // @param isSync bool 是否同步执行
  70. // @param isRefreshTop bool 是否刷新上面的指标
  71. // @return err error
  72. // @return isAsync bool 是否异步刷新
  73. func EdbInfoRefreshAllFromBaseV3(edbInfoIdList []int, refreshAll, isSync, isRefreshTop bool) (err error, isAsync bool) {
  74. var errmsg string
  75. defer func() {
  76. if err != nil {
  77. fmt.Println("EdbInfoRefreshAllFromBaseV3 Err:" + err.Error() + ";errmsg:" + errmsg)
  78. go alarm_msg.SendAlarmMsg("EdbInfoRefreshAllFromBaseV3,Err"+err.Error()+";errMsg:"+errmsg, 3)
  79. }
  80. }()
  81. var newBaseEdbInfoArr, newBasePredictEdbInfoArr []*data_manage.EdbInfo
  82. var newCalculateMap, newPredictCalculateMap map[int]*data_manage.EdbInfo
  83. var calculateArr, predictCalculateArr []int
  84. // 获取关联指标
  85. if isRefreshTop {
  86. // 获取所有关联的指标,上下所有的指标
  87. newBaseEdbInfoArr, newBasePredictEdbInfoArr, newCalculateMap, newPredictCalculateMap, calculateArr, predictCalculateArr, err, errmsg = getRefreshEdbInfoListByIds(edbInfoIdList)
  88. if err != nil {
  89. return
  90. }
  91. } else {
  92. // 获取溯源的指标
  93. newBaseEdbInfoArr, newBasePredictEdbInfoArr, newCalculateMap, newPredictCalculateMap, calculateArr, predictCalculateArr = getEdbInfoIdList(edbInfoIdList)
  94. }
  95. // 需要刷新的指标数量
  96. totalEdbInfo := len(newBaseEdbInfoArr) + len(calculateArr) + len(predictCalculateArr) + len(newBasePredictEdbInfoArr)
  97. if totalEdbInfo == 0 {
  98. return
  99. }
  100. if totalEdbInfo <= 20 || isSync {
  101. err = edbInfoRefreshAll(refreshAll, newBaseEdbInfoArr, newBasePredictEdbInfoArr, newCalculateMap, newPredictCalculateMap, calculateArr, predictCalculateArr)
  102. } else {
  103. isAsync = true
  104. go edbInfoRefreshAll(refreshAll, newBaseEdbInfoArr, newBasePredictEdbInfoArr, newCalculateMap, newPredictCalculateMap, calculateArr, predictCalculateArr)
  105. }
  106. return
  107. }
  108. // getEdbInfoIdList
  109. // @Description: 获取待更新的指标列表
  110. // @author: Roc
  111. // @datetime 2023-12-01 16:19:42
  112. // @param edbInfoIdList []int
  113. // @return newBaseEdbInfoArr []*data_manage.EdbInfo
  114. // @return newBasePredictEdbInfoArr []*data_manage.EdbInfo
  115. // @return newCalculateMap map[int]*data_manage.EdbInfo
  116. // @return newPredictCalculateMap map[int]*data_manage.EdbInfo
  117. // @return calculateArr []int
  118. // @return predictCalculateArr []int
  119. func getEdbInfoIdList(edbInfoIdList []int) (newBaseEdbInfoArr, newBasePredictEdbInfoArr []*data_manage.EdbInfo, newCalculateMap, newPredictCalculateMap map[int]*data_manage.EdbInfo, calculateArr, predictCalculateArr []int) {
  120. traceEdbInfoList, err := TraceEdbInfoByEdbInfoIdList(edbInfoIdList)
  121. if err != nil {
  122. return
  123. }
  124. // existEdbInfoIdMap 已经处理了的指标id map
  125. existEdbInfoIdMap := make(map[int]int)
  126. // 基础指标
  127. newBaseEdbInfoArr = make([]*data_manage.EdbInfo, 0)
  128. newBasePredictEdbInfoArr = make([]*data_manage.EdbInfo, 0)
  129. newBaseMap := make(map[int]*data_manage.EdbInfo)
  130. newPredictBaseMap := make(map[int]*data_manage.EdbInfo)
  131. // 计算指标
  132. newCalculateMap = make(map[int]*data_manage.EdbInfo)
  133. newPredictCalculateMap = make(map[int]*data_manage.EdbInfo)
  134. calculateArr = make([]int, 0)
  135. predictCalculateArr = make([]int, 0)
  136. // 获取关联指标
  137. for _, traceEdbInfo := range traceEdbInfoList {
  138. tmpBaseEdbInfoArr, tmpBasePredictEdbInfoArr, tmpCalculateMap, tmpPredictCalculateMap, _, _ := getRefreshEdbInfoListByTraceEdbInfo(traceEdbInfo, existEdbInfoIdMap)
  139. // 普通基础指标
  140. for _, edbInfo := range tmpBaseEdbInfoArr {
  141. if _, ok := newBaseMap[edbInfo.EdbInfoId]; !ok {
  142. newBaseMap[edbInfo.EdbInfoId] = edbInfo
  143. if edbInfo.NoUpdate == 1 {
  144. continue
  145. }
  146. newBaseEdbInfoArr = append(newBaseEdbInfoArr, edbInfo)
  147. }
  148. }
  149. // 预测基础指标
  150. for _, edbInfo := range tmpBasePredictEdbInfoArr {
  151. if _, ok := newPredictBaseMap[edbInfo.EdbInfoId]; !ok {
  152. newPredictBaseMap[edbInfo.EdbInfoId] = edbInfo
  153. newBasePredictEdbInfoArr = append(newBasePredictEdbInfoArr, edbInfo)
  154. }
  155. }
  156. // 普通计算指标
  157. for _, edbInfo := range tmpCalculateMap {
  158. if _, ok := newCalculateMap[edbInfo.EdbInfoId]; !ok {
  159. if edbInfo.NoUpdate == 1 {
  160. continue
  161. }
  162. newCalculateMap[edbInfo.EdbInfoId] = edbInfo
  163. calculateArr = append(calculateArr, edbInfo.EdbInfoId)
  164. }
  165. }
  166. // 预测计算指标
  167. for _, edbInfo := range tmpPredictCalculateMap {
  168. if _, ok := newPredictCalculateMap[edbInfo.EdbInfoId]; !ok {
  169. newPredictCalculateMap[edbInfo.EdbInfoId] = edbInfo
  170. predictCalculateArr = append(predictCalculateArr, edbInfo.EdbInfoId)
  171. }
  172. }
  173. }
  174. // 普通计算指标的id
  175. sort.Ints(calculateArr)
  176. // 预测计算指标的id
  177. sort.Ints(predictCalculateArr)
  178. return
  179. }
  180. // getRefreshEdbInfoListByTraceEdbInfo根据溯源获取关联指标
  181. func getRefreshEdbInfoListByTraceEdbInfo(traceEdbInfo data_manage.TraceEdbInfoResp, existEdbInfoIdMap map[int]int) (newBaseEdbInfoArr, newBasePredictEdbInfoArr []*data_manage.EdbInfo, newCalculateMap, newPredictCalculateMap map[int]*data_manage.EdbInfo, calculateArr, predictCalculateArr []int) {
  182. newBaseEdbInfoArr = make([]*data_manage.EdbInfo, 0)
  183. newBasePredictEdbInfoArr = make([]*data_manage.EdbInfo, 0)
  184. newCalculateMap = make(map[int]*data_manage.EdbInfo)
  185. newPredictCalculateMap = make(map[int]*data_manage.EdbInfo)
  186. calculateArr = make([]int, 0)
  187. predictCalculateArr = make([]int, 0)
  188. _, ok := existEdbInfoIdMap[traceEdbInfo.EdbInfoId]
  189. if ok {
  190. return
  191. }
  192. existEdbInfoIdMap[traceEdbInfo.EdbInfoId] = traceEdbInfo.EdbInfoId
  193. switch traceEdbInfo.EdbInfoType {
  194. //0-普通指标; 1-预测指标
  195. case 0: // 0-普通指标
  196. if traceEdbInfo.EdbType == 1 { //1-基础指标
  197. newBaseEdbInfoArr = append(newBaseEdbInfoArr, traceEdbInfo.EdbInfo)
  198. } else if traceEdbInfo.EdbType == 2 { //2-计算指标
  199. newCalculateMap[traceEdbInfo.EdbInfoId] = traceEdbInfo.EdbInfo
  200. calculateArr = append(calculateArr, traceEdbInfo.EdbInfoId)
  201. }
  202. case 1: // 1-预测指标
  203. if traceEdbInfo.EdbType == 1 { //1-基础指标
  204. newBasePredictEdbInfoArr = append(newBasePredictEdbInfoArr, traceEdbInfo.EdbInfo)
  205. } else if traceEdbInfo.EdbType == 2 { //2-计算指标
  206. newPredictCalculateMap[traceEdbInfo.EdbInfoId] = traceEdbInfo.EdbInfo
  207. predictCalculateArr = append(predictCalculateArr, traceEdbInfo.EdbInfoId)
  208. }
  209. }
  210. if len(traceEdbInfo.Child) > 0 {
  211. for _, v := range traceEdbInfo.Child {
  212. tmpBaseEdbInfoArr, tmpPredictEdbInfoArr, tmpCalculateMap, tmpPredictCalculateMap, tmpCalculateArr, tmpPredictCalculateArr := getRefreshEdbInfoListByTraceEdbInfo(v, existEdbInfoIdMap)
  213. newBaseEdbInfoArr = append(newBaseEdbInfoArr, tmpBaseEdbInfoArr...)
  214. newBasePredictEdbInfoArr = append(newBasePredictEdbInfoArr, tmpPredictEdbInfoArr...)
  215. for k, tmpEdbInfo := range tmpCalculateMap {
  216. newCalculateMap[k] = tmpEdbInfo
  217. }
  218. for k, tmpEdbInfo := range tmpPredictCalculateMap {
  219. newPredictCalculateMap[k] = tmpEdbInfo
  220. }
  221. calculateArr = append(calculateArr, tmpCalculateArr...)
  222. predictCalculateArr = append(predictCalculateArr, tmpPredictCalculateArr...)
  223. }
  224. }
  225. return
  226. }
  227. func edbInfoRefreshAll(refreshAll bool, newBaseEdbInfoArr, newBasePredictEdbInfoArr []*data_manage.EdbInfo, newCalculateMap, newPredictCalculateMap map[int]*data_manage.EdbInfo, calculateArr, predictCalculateArr []int) (err error) {
  228. var errmsg string
  229. defer func() {
  230. if err != nil {
  231. fmt.Println("EdbInfoRefreshAllFromBaseV2 Err:" + err.Error() + ";errmsg:" + errmsg)
  232. go alarm_msg.SendAlarmMsg("EdbInfoRefreshFromBaseV2,Err"+err.Error()+";errMsg:"+errmsg, 3)
  233. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "EdbInfoRefreshFromBase:"+errmsg, utils.EmailSendToUsers)
  234. }
  235. }()
  236. var startDate string
  237. for _, bv := range newBaseEdbInfoArr {
  238. //source := bv.Source
  239. //edbInfoId := bv.EdbInfoId
  240. //edbCode := bv.EdbCode
  241. if bv.StartDate == "0000-00-00" {
  242. continue
  243. }
  244. //开始时间
  245. startDate = ``
  246. if refreshAll { //刷新所有数据,用开始时间作为起始日期去刷新
  247. sTime, err := time.Parse(utils.FormatDate, bv.StartDate)
  248. if err != nil {
  249. return err
  250. }
  251. startDate = sTime.Format(utils.FormatDate)
  252. } else {
  253. sTime, err := time.Parse(utils.FormatDate, bv.EndDate)
  254. if err != nil {
  255. return err
  256. }
  257. frequency := bv.Frequency
  258. var limitDay int
  259. switch frequency {
  260. case "日度":
  261. limitDay = utils.DATA_START_REFRESH_LIMIT
  262. case "周度":
  263. limitDay = utils.DATA_START_REFRESH_LIMIT * 7
  264. case "月度":
  265. limitDay = utils.DATA_START_REFRESH_LIMIT * 30
  266. case "季度":
  267. limitDay = utils.DATA_START_REFRESH_LIMIT * 90
  268. case "年度":
  269. limitDay = utils.DATA_START_REFRESH_LIMIT * 365
  270. default:
  271. limitDay = utils.DATA_START_REFRESH_LIMIT
  272. }
  273. startDate = sTime.AddDate(0, 0, -limitDay).Format(utils.FormatDate)
  274. }
  275. result, err := RefreshEdbData(bv.EdbInfoId, bv.Source, bv.SubSource, bv.EdbCode, startDate)
  276. if err != nil {
  277. fmt.Println(bv.EdbInfoId, "RefreshBaseEdbData err", time.Now())
  278. errmsg = "RefreshBaseEdbData Err:" + err.Error()
  279. return err
  280. }
  281. if result.Ret != 200 {
  282. fmt.Println(bv.EdbInfoId, "RefreshBaseEdbData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  283. errmsg = fmt.Sprint(bv.EdbInfoId, "RefreshBaseEdbData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  284. return fmt.Errorf("刷新失败, err:", errmsg)
  285. }
  286. //maxAndMinItem, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
  287. //if err != nil {
  288. // if err.Error() == utils.ErrNoRow() { //找不到数据,那么就进入到下一条数据做处理
  289. // continue
  290. // }
  291. // return err
  292. //}
  293. //if maxAndMinItem != nil {
  294. // err = data_manage.ModifyEdbInfoMaxAndMinInfo(edbInfoId, maxAndMinItem)
  295. // if err != nil {
  296. // return err
  297. // }
  298. //}
  299. fmt.Println("end newBaseEdbInfoArr:", bv, time.Now())
  300. }
  301. //刷新相关普通计算指标
  302. for _, v := range calculateArr {
  303. edbInfo := newCalculateMap[v]
  304. if edbInfo == nil {
  305. return err
  306. }
  307. //计算指标就不用开始时间了吧,因为存在说开始时间变更的情况
  308. startDate = ``
  309. if !refreshAll { //如果不是全部更新,那么以指标的开始时间作为刷新
  310. startDate = edbInfo.StartDate
  311. source := edbInfo.Source
  312. if startDate == "" || startDate == "0000-00-00" { //如果没有开始日期,说明还没有计算出来数据,那么就往前面推40年吧(也意味着重新计算了)
  313. startDate = time.Now().AddDate(-40, 0, 0).Format(utils.FormatDate)
  314. } else {
  315. if source == utils.DATA_SOURCE_CALCULATE {
  316. sTime, err := time.Parse(utils.FormatDate, edbInfo.EndDate)
  317. if err != nil {
  318. return err
  319. }
  320. frequency := edbInfo.Frequency
  321. var limitDay int
  322. switch frequency {
  323. case "日度":
  324. limitDay = utils.DATA_START_REFRESH_LIMIT
  325. case "周度":
  326. limitDay = utils.DATA_START_REFRESH_LIMIT * 7
  327. case "月度":
  328. limitDay = utils.DATA_START_REFRESH_LIMIT * 30
  329. case "季度":
  330. limitDay = utils.DATA_START_REFRESH_LIMIT * 90
  331. case "年度":
  332. limitDay = utils.DATA_START_REFRESH_LIMIT * 365
  333. default:
  334. limitDay = utils.DATA_START_REFRESH_LIMIT
  335. }
  336. startDate = sTime.AddDate(0, 0, -limitDay).Format(utils.FormatDate)
  337. }
  338. }
  339. }
  340. result, err := RefreshEdbCalculateData(edbInfo.EdbInfoId, edbInfo.EdbCode, startDate)
  341. if err != nil {
  342. fmt.Println(v, "RefreshEdbCalculateData err", time.Now())
  343. errmsg = "RefreshEdbCalculateData Err:" + err.Error()
  344. return err
  345. }
  346. if result.Ret != 200 {
  347. fmt.Println(v, "RefreshEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  348. errmsg = fmt.Sprint(v, "RefreshEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  349. return fmt.Errorf("刷新失败")
  350. }
  351. }
  352. //刷新相关预测计算指标
  353. for _, v := range predictCalculateArr {
  354. edbInfo := newPredictCalculateMap[v]
  355. if edbInfo == nil {
  356. return err
  357. }
  358. startDate = edbInfo.StartDate
  359. source := edbInfo.Source
  360. if startDate == "" || startDate == "0000-00-00" { //如果没有开始日期,说明还没有计算出来数据,那么就往前面推40年吧(也意味着重新计算了)
  361. startDate = time.Now().AddDate(-40, 0, 0).Format(utils.FormatDate)
  362. } else {
  363. if source == utils.DATA_SOURCE_PREDICT_CALCULATE {
  364. startDate = ``
  365. if refreshAll { //刷新所有数据,用开始时间作为起始日期去刷新
  366. startDate = edbInfo.StartDate
  367. } else {
  368. sTime, err := time.Parse(utils.FormatDate, edbInfo.EndDate)
  369. if err != nil {
  370. return err
  371. }
  372. frequency := edbInfo.Frequency
  373. var limitDay int
  374. switch frequency {
  375. case "日度":
  376. limitDay = utils.DATA_START_REFRESH_LIMIT
  377. case "周度":
  378. limitDay = utils.DATA_START_REFRESH_LIMIT * 7
  379. case "月度":
  380. limitDay = utils.DATA_START_REFRESH_LIMIT * 30
  381. case "季度":
  382. limitDay = utils.DATA_START_REFRESH_LIMIT * 90
  383. case "年度":
  384. limitDay = utils.DATA_START_REFRESH_LIMIT * 365
  385. default:
  386. limitDay = utils.DATA_START_REFRESH_LIMIT
  387. }
  388. startDate = sTime.AddDate(0, 0, -limitDay).Format(utils.FormatDate)
  389. }
  390. }
  391. }
  392. result, err := RefreshPredictEdbCalculateData(edbInfo.EdbInfoId, edbInfo.EdbCode, startDate)
  393. if err != nil {
  394. fmt.Println(v, "RefreshEdbCalculateData err", time.Now())
  395. errmsg = "RefreshEdbCalculateData Err:" + err.Error()
  396. return err
  397. }
  398. if result.Ret != 200 {
  399. fmt.Println(v, "RefreshPredictEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  400. errmsg = fmt.Sprint(v, "RefreshPredictEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  401. return fmt.Errorf("刷新失败")
  402. }
  403. }
  404. // 4、更新动态环差值
  405. {
  406. predictEdbInfoIdList := make([]int, 0)
  407. for _, v := range newBasePredictEdbInfoArr {
  408. predictEdbInfoIdList = append(predictEdbInfoIdList, v.EdbInfoId)
  409. }
  410. fmt.Println("predictEdbConfCalculateMappingDetailList:", predictEdbInfoIdList)
  411. predictEdbConfCalculateMappingDetailList, err := data_manage.GetPredictEdbConfCalculateMappingDetailListByEdbInfoId(predictEdbInfoIdList)
  412. if err != nil {
  413. errmsg = fmt.Sprint("更新动态环差值时,获取数据失败:" + err.Error())
  414. return fmt.Errorf("刷新失败, err:", errmsg)
  415. }
  416. for _, bv := range predictEdbConfCalculateMappingDetailList {
  417. result, err := RefreshEdbData(bv.EdbInfoId, utils.DATA_SOURCE_PREDICT, utils.DATA_SUB_SOURCE_EDB, bv.EdbCode, "")
  418. if err != nil {
  419. fmt.Println(bv.EdbInfoId, "RefreshBasePredictEdbData err", time.Now())
  420. errmsg = "RefreshBasePredictEdbData Err:" + err.Error()
  421. return err
  422. }
  423. if result.Ret != 200 {
  424. fmt.Println(bv.EdbInfoId, "RefreshBasePredictEdbData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  425. errmsg = fmt.Sprint(bv.EdbInfoId, "RefreshBasePredictEdbData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  426. return fmt.Errorf("刷新失败, err:%s", errmsg)
  427. }
  428. fmt.Println("end predictEdbConfCalculateMappingDetailList:", bv, time.Now())
  429. }
  430. }
  431. //5、再次刷新相关预测计算指标
  432. for _, v := range predictCalculateArr {
  433. edbInfo := newPredictCalculateMap[v]
  434. if edbInfo == nil {
  435. return err
  436. }
  437. startDate = edbInfo.StartDate
  438. source := edbInfo.Source
  439. if startDate == "" || startDate == "0000-00-00" { //如果没有开始日期,说明还没有计算出来数据,那么就往前面推40年吧(也意味着重新计算了)
  440. startDate = time.Now().AddDate(-40, 0, 0).Format(utils.FormatDate)
  441. } else {
  442. if source == utils.DATA_SOURCE_PREDICT_CALCULATE {
  443. startDate = ``
  444. if refreshAll { //刷新所有数据,用开始时间作为起始日期去刷新
  445. startDate = edbInfo.StartDate
  446. } else {
  447. sTime, err := time.Parse(utils.FormatDate, edbInfo.EndDate)
  448. if err != nil {
  449. return err
  450. }
  451. frequency := edbInfo.Frequency
  452. var limitDay int
  453. switch frequency {
  454. case "日度":
  455. limitDay = utils.DATA_START_REFRESH_LIMIT
  456. case "周度":
  457. limitDay = utils.DATA_START_REFRESH_LIMIT * 7
  458. case "月度":
  459. limitDay = utils.DATA_START_REFRESH_LIMIT * 30
  460. case "季度":
  461. limitDay = utils.DATA_START_REFRESH_LIMIT * 90
  462. case "年度":
  463. limitDay = utils.DATA_START_REFRESH_LIMIT * 365
  464. default:
  465. limitDay = utils.DATA_START_REFRESH_LIMIT
  466. }
  467. startDate = sTime.AddDate(0, 0, -limitDay).Format(utils.FormatDate)
  468. }
  469. }
  470. }
  471. result, err := RefreshPredictEdbCalculateData(edbInfo.EdbInfoId, edbInfo.EdbCode, startDate)
  472. if err != nil {
  473. fmt.Println(v, "RefreshEdbCalculateData err", time.Now())
  474. errmsg = "RefreshEdbCalculateData Err:" + err.Error()
  475. return err
  476. }
  477. if result.Ret != 200 {
  478. fmt.Println(v, "RefreshPredictEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  479. errmsg = fmt.Sprint(v, "RefreshPredictEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  480. return fmt.Errorf("刷新失败")
  481. }
  482. }
  483. return err
  484. }
  485. // EdbInfoRefresh 刷新单个指标,不会刷新关联指标
  486. func EdbInfoRefresh(edbInfo *data_manage.EdbInfoView, refreshAll bool) (err error) {
  487. var errmsg string
  488. defer func() {
  489. if err != nil {
  490. fmt.Println("EdbInfoRefresh Err:" + err.Error() + ";errmsg:" + errmsg)
  491. go alarm_msg.SendAlarmMsg("EdbInfoRefresh,Err"+err.Error()+";errMsg:"+errmsg, 3)
  492. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "EdbInfoRefreshFromBase:"+errmsg, utils.EmailSendToUsers)
  493. }
  494. }()
  495. switch edbInfo.EdbInfoType {
  496. //指标类型,0:普通指标,1:预测指标
  497. case 0:
  498. if edbInfo.StartDate == "0000-00-00" {
  499. return
  500. }
  501. //开始时间
  502. startDate := ``
  503. if edbInfo.EdbType == 1 {
  504. // 基础指标
  505. if refreshAll { //刷新所有数据,用开始时间作为起始日期去刷新
  506. sTime, err := time.Parse(utils.FormatDate, edbInfo.StartDate)
  507. if err != nil {
  508. return err
  509. }
  510. startDate = sTime.Format(utils.FormatDate)
  511. } else {
  512. sTime, err := time.Parse(utils.FormatDate, edbInfo.EndDate)
  513. if err != nil {
  514. return err
  515. }
  516. frequency := edbInfo.Frequency
  517. var limitDay int
  518. switch frequency {
  519. case "日度":
  520. limitDay = utils.DATA_START_REFRESH_LIMIT
  521. case "周度":
  522. limitDay = utils.DATA_START_REFRESH_LIMIT * 7
  523. case "月度":
  524. limitDay = utils.DATA_START_REFRESH_LIMIT * 30
  525. case "季度":
  526. limitDay = utils.DATA_START_REFRESH_LIMIT * 90
  527. case "年度":
  528. limitDay = utils.DATA_START_REFRESH_LIMIT * 365
  529. default:
  530. limitDay = utils.DATA_START_REFRESH_LIMIT
  531. }
  532. startDate = sTime.AddDate(0, 0, -limitDay).Format(utils.FormatDate)
  533. }
  534. result, err := RefreshEdbData(edbInfo.EdbInfoId, edbInfo.Source, edbInfo.SubSource, edbInfo.EdbCode, startDate)
  535. if err != nil {
  536. fmt.Println(edbInfo.EdbInfoId, "RefreshBaseEdbData err", time.Now())
  537. errmsg = "RefreshBaseEdbData Err:" + err.Error()
  538. return err
  539. }
  540. if result.Ret != 200 {
  541. fmt.Println(edbInfo.EdbInfoId, "RefreshBaseEdbData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  542. errmsg = fmt.Sprint(edbInfo.EdbInfoId, "RefreshBaseEdbData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  543. return fmt.Errorf("刷新失败, err:", errmsg)
  544. }
  545. } else { //计算指标
  546. //计算指标就不用开始时间了吧,因为存在说开始时间变更的情况
  547. if !refreshAll { //如果不是全部更新,那么以指标的开始时间作为刷新
  548. startDate = edbInfo.StartDate
  549. source := edbInfo.Source
  550. if startDate == "" || startDate == "0000-00-00" { //如果没有开始日期,说明还没有计算出来数据,那么就往前面推40年吧(也意味着重新计算了)
  551. startDate = time.Now().AddDate(-40, 0, 0).Format(utils.FormatDate)
  552. } else {
  553. if source == utils.DATA_SOURCE_CALCULATE {
  554. sTime, err := time.Parse(utils.FormatDate, edbInfo.EndDate)
  555. if err != nil {
  556. return err
  557. }
  558. frequency := edbInfo.Frequency
  559. var limitDay int
  560. switch frequency {
  561. case "日度":
  562. limitDay = utils.DATA_START_REFRESH_LIMIT
  563. case "周度":
  564. limitDay = utils.DATA_START_REFRESH_LIMIT * 7
  565. case "月度":
  566. limitDay = utils.DATA_START_REFRESH_LIMIT * 30
  567. case "季度":
  568. limitDay = utils.DATA_START_REFRESH_LIMIT * 90
  569. case "年度":
  570. limitDay = utils.DATA_START_REFRESH_LIMIT * 365
  571. default:
  572. limitDay = utils.DATA_START_REFRESH_LIMIT
  573. }
  574. startDate = sTime.AddDate(0, 0, -limitDay).Format(utils.FormatDate)
  575. }
  576. }
  577. }
  578. result, err := RefreshEdbCalculateData(edbInfo.EdbInfoId, edbInfo.EdbCode, startDate)
  579. if err != nil {
  580. fmt.Println(edbInfo.EdbInfoId, "RefreshEdbCalculateData err", time.Now())
  581. errmsg = "RefreshEdbCalculateData Err:" + err.Error()
  582. return err
  583. }
  584. if result.Ret != 200 {
  585. fmt.Println(edbInfo.EdbInfoId, "RefreshEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  586. errmsg = fmt.Sprint(edbInfo.EdbInfoId, "RefreshEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  587. return fmt.Errorf("刷新失败")
  588. }
  589. }
  590. case 1:
  591. startDate := edbInfo.StartDate
  592. var result *models.BaseResponse
  593. if startDate == "" || startDate == "0000-00-00" { //如果没有开始日期,说明还没有计算出来数据,那么就往前面推40年吧(也意味着重新计算了)
  594. startDate = time.Now().AddDate(-40, 0, 0).Format(utils.FormatDate)
  595. } else {
  596. startDate = ``
  597. if refreshAll { //刷新所有数据,用开始时间作为起始日期去刷新
  598. startDate = edbInfo.StartDate
  599. } else {
  600. sTime, err := time.Parse(utils.FormatDate, edbInfo.EndDate)
  601. if err != nil {
  602. return err
  603. }
  604. frequency := edbInfo.Frequency
  605. var limitDay int
  606. switch frequency {
  607. case "日度":
  608. limitDay = utils.DATA_START_REFRESH_LIMIT
  609. case "周度":
  610. limitDay = utils.DATA_START_REFRESH_LIMIT * 7
  611. case "月度":
  612. limitDay = utils.DATA_START_REFRESH_LIMIT * 30
  613. case "季度":
  614. limitDay = utils.DATA_START_REFRESH_LIMIT * 90
  615. case "年度":
  616. limitDay = utils.DATA_START_REFRESH_LIMIT * 365
  617. default:
  618. limitDay = utils.DATA_START_REFRESH_LIMIT
  619. }
  620. startDate = sTime.AddDate(0, 0, -limitDay).Format(utils.FormatDate)
  621. }
  622. }
  623. if edbInfo.EdbType == 1 { //基础指标
  624. result, err = RefreshPredictEdbCalculateData(edbInfo.EdbInfoId, edbInfo.EdbCode, startDate)
  625. } else {
  626. // 预测计算指标
  627. // 4、更新动态环差值
  628. {
  629. predictEdbConfCalculateMappingDetailList, err := data_manage.GetPredictEdbConfCalculateMappingDetailListByEdbInfoId([]int{edbInfo.EdbInfoId})
  630. if err != nil {
  631. errmsg = fmt.Sprint("更新动态环差值时,获取数据失败:" + err.Error())
  632. return fmt.Errorf("刷新失败, err:", errmsg)
  633. }
  634. for _, bv := range predictEdbConfCalculateMappingDetailList {
  635. result, err := RefreshEdbData(bv.EdbInfoId, utils.DATA_SOURCE_PREDICT, utils.DATA_SUB_SOURCE_EDB, bv.EdbCode, "")
  636. if err != nil {
  637. fmt.Println(bv.EdbInfoId, "RefreshBasePredictEdbData err", time.Now())
  638. errmsg = "RefreshBasePredictEdbData Err:" + err.Error()
  639. return err
  640. }
  641. if result.Ret != 200 {
  642. fmt.Println(bv.EdbInfoId, "RefreshBasePredictEdbData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  643. errmsg = fmt.Sprint(bv.EdbInfoId, "RefreshBasePredictEdbData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  644. return fmt.Errorf("刷新失败, err:%s", errmsg)
  645. }
  646. fmt.Println("end predictEdbConfCalculateMappingDetailList:", bv, time.Now())
  647. }
  648. }
  649. }
  650. if err != nil {
  651. fmt.Println(edbInfo.EdbInfoId, "RefreshEdbCalculateData err", time.Now())
  652. errmsg = "RefreshEdbCalculateData Err:" + err.Error()
  653. return err
  654. }
  655. if result.Ret != 200 {
  656. fmt.Println(edbInfo.EdbInfoId, "RefreshPredictEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  657. errmsg = fmt.Sprint(edbInfo.EdbInfoId, "RefreshPredictEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
  658. return fmt.Errorf("刷新失败")
  659. }
  660. }
  661. return err
  662. }
  663. // AddEdbInfo 新增手工指标数据
  664. func AddEdbInfo(secName, unit, frequency, noticeTime, mobile string, classifyId, userId int, userName string) (err error) {
  665. tradeCode, err := models.GetMaxTradeCode()
  666. if err != nil {
  667. return
  668. }
  669. if tradeCode == "" {
  670. err = errors.New("最大编码为空")
  671. return
  672. }
  673. maxTradeCode, err := utils.GetMaxTradeCode(tradeCode)
  674. if err != nil {
  675. err = errors.New("获取编码信息失败,Err:" + err.Error())
  676. return
  677. }
  678. if maxTradeCode == "" {
  679. err = errors.New("编码为空,请联系技术")
  680. return
  681. }
  682. //判断指标名称是否为空
  683. if secName == "" {
  684. err = errors.New("指标名称不能为空")
  685. return
  686. }
  687. item, err := models.GetEdbinfoBySecName(secName)
  688. if err != nil && err.Error() != utils.ErrNoRow() {
  689. err = errors.New("获取信息失败,Err:" + err.Error())
  690. return
  691. }
  692. if item != nil {
  693. err = errors.New("指标名称已存在")
  694. return
  695. }
  696. // 先删除该指标编码的历史数据(避免上海删除指标时,没有删除该指标数据)
  697. _ = models.DeleteAllEdbData(maxTradeCode)
  698. // 先删除历史的操作日志
  699. _ = models.DelEdbinfoOpRecordByTradeCode(maxTradeCode)
  700. // 再次新增指标
  701. err = models.AddEdbinfo(maxTradeCode, secName, unit, "手动", frequency, noticeTime, classifyId, userId, userName)
  702. if err != nil {
  703. err = errors.New("新增失败,Err:" + err.Error())
  704. return
  705. }
  706. err = models.AddEdbinfoUser(maxTradeCode, mobile)
  707. return
  708. }
  709. //全部刷新指标
  710. //func EdbInfoRefreshAllFromBase(edbInfoId int) (err error) {
  711. // var errmsg string
  712. // defer func() {
  713. // if err != nil {
  714. // fmt.Println("EdbInfoRefreshAllFromBase Err:" + err.Error() + ";errmsg:" + errmsg)
  715. // go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "EdbInfoRefreshFromBase:"+errmsg, utils.EmailSendToUsers)
  716. // }
  717. // }()
  718. //
  719. // calculateList, err := data_manage.GetEdbInfoAllCalculate(edbInfoId)
  720. // if err != nil && err.Error() != utils.ErrNoRow() {
  721. // return errors.New("GetEdbInfoAllCalculate Err:" + err.Error())
  722. // }
  723. // baseEdbInfoArr := make([]*data_manage.EdbInfo, 0)
  724. // calculateInfoArr := make([]*data_manage.EdbInfo, 0)
  725. // baseEdbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  726. // if err != nil {
  727. // return errors.New("GetEdbInfoAllCalGetEdbInfoByIdr:" + err.Error())
  728. // }
  729. // baseEdbInfoArr = append(baseEdbInfoArr, baseEdbInfo)
  730. //
  731. // for _, v := range calculateList {
  732. // getBaseEdbInfoArr, getCalculateInfoArr, err := data_manage.GetRefreshEdbInfoFromBase(v.EdbInfoId, v.Source)
  733. // if err != nil {
  734. // fmt.Println("GetRefreshEdbInfoFromBase err:" + err.Error())
  735. // errmsg = "获取需要刷新的指标失败:Err:" + err.Error()
  736. // return err
  737. // }
  738. // baseEdbInfoArr = append(baseEdbInfoArr, getBaseEdbInfoArr...)
  739. // calculateInfoArr = append(calculateInfoArr, getCalculateInfoArr...)
  740. // calculateInfoArr = append(calculateInfoArr, v)
  741. // }
  742. // //取重
  743. // newBaseEdbInfoArr := make([]*data_manage.EdbInfo, 0)
  744. // baseMap := make(map[int]int)
  745. // for _, v := range baseEdbInfoArr {
  746. // if _, ok := baseMap[v.EdbInfoId]; !ok {
  747. // newBaseEdbInfoArr = append(newBaseEdbInfoArr, v)
  748. // }
  749. // baseMap[v.EdbInfoId] = v.EdbInfoId
  750. // }
  751. //
  752. // var calculateArr []int
  753. // newCalculateMap := make(map[int]*data_manage.EdbInfo)
  754. // for _, v := range calculateInfoArr {
  755. // if _, ok := newCalculateMap[v.EdbInfoId]; !ok {
  756. // calculateArr = append(calculateArr, v.EdbInfoId)
  757. // }
  758. // newCalculateMap[v.EdbInfoId] = v
  759. // }
  760. // sort.Ints(calculateArr)
  761. // var startDate string
  762. // for _, bv := range newBaseEdbInfoArr {
  763. // source := bv.Source
  764. // edbInfoId := bv.EdbInfoId
  765. // edbCode := bv.EdbCode
  766. //
  767. // sTime, err := time.Parse(utils.FormatDate, bv.StartDate)
  768. // if err != nil {
  769. // return err
  770. // }
  771. // startDate = sTime.Format(utils.FormatDate)
  772. //
  773. // if source == utils.DATA_SOURCE_THS {
  774. // endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
  775. // err = data_manage.RefreshAllEdbDataByThs(edbInfoId, source, edbCode, startDate, endDate)
  776. // if err != nil {
  777. // errmsg = "RefreshAllEdbDataByThs Err:" + err.Error()
  778. // }
  779. // } else if source == utils.DATA_SOURCE_WIND {
  780. // endDate := time.Now().Format(utils.FormatDate)
  781. // err = data_manage.RefreshAllEdbDataByWind(edbInfoId, source, edbCode, startDate, endDate)
  782. // if err != nil {
  783. // errmsg = "RefreshAllEdbDataByWind Err:" + err.Error()
  784. // }
  785. // } else if source == utils.DATA_SOURCE_PB {
  786. // startDate := sTime.Format(utils.FormatDateUnSpace)
  787. // endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
  788. // err = data_manage.RefreshAllEdbDataByPb(edbInfoId, source, edbCode, startDate, endDate)
  789. // if err != nil {
  790. // errmsg = "RefreshAllEdbDataByPb Err:" + err.Error()
  791. // }
  792. // } else if source == utils.DATA_SOURCE_MANUAL {
  793. // endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
  794. // err = data_manage.RefreshAllEdbDataByManual(edbInfoId, source, edbCode, startDate, endDate)
  795. // if err != nil {
  796. // errmsg = "RefreshAllEdbDataByManual Err:" + err.Error()
  797. // }
  798. // } else if source == utils.DATA_SOURCE_LZ {
  799. // endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
  800. // err = data_manage.RefreshAllEdbDataByLz(edbInfoId, source, edbCode, startDate, endDate)
  801. // if err != nil {
  802. // errmsg = "RefreshAllEdbDataByLz Err:" + err.Error()
  803. // }
  804. // } else if source == utils.DATA_SOURCE_YS {
  805. // endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
  806. // err = data_manage.RefreshAllEdbDataByYs(edbInfoId, source, edbCode, startDate, endDate)
  807. // if err != nil {
  808. // errmsg = "RefreshAllEdbDataByYs Err:" + err.Error()
  809. // }
  810. // } else if source == utils.DATA_SOURCE_GL {
  811. // endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
  812. // err = data_manage.RefreshAllEdbDataByGl(edbInfoId, source, edbCode, startDate, endDate)
  813. // if err != nil {
  814. // errmsg = "RefreshAllEdbDataByGl Err:" + err.Error()
  815. // }
  816. // } else if source == utils.DATA_SOURCE_ZZ {
  817. // endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
  818. // err = data_manage.RefreshAllEdbDataByZz(edbInfoId, source, edbCode, startDate, endDate)
  819. // if err != nil {
  820. // errmsg = "RefreshAllEdbDataByZz Err:" + err.Error()
  821. // }
  822. // } else if source == utils.DATA_SOURCE_DL {
  823. // endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
  824. // err = data_manage.RefreshAllEdbDataByDl(edbInfoId, source, edbCode, startDate, endDate)
  825. // if err != nil {
  826. // errmsg = "RefreshAllEdbDataByDl Err:" + err.Error()
  827. // }
  828. // } else if source == utils.DATA_SOURCE_SH {
  829. // endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
  830. // err = data_manage.RefreshAllEdbDataBySh(edbInfoId, source, edbCode, startDate, endDate)
  831. // if err != nil {
  832. // errmsg = "RefreshAllEdbDataBySh Err:" + err.Error()
  833. // }
  834. // } else if source == utils.DATA_SOURCE_CFFEX {
  835. // endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
  836. // err = data_manage.RefreshAllEdbDataByCffex(edbInfoId, source, edbCode, startDate, endDate)
  837. // if err != nil {
  838. // errmsg = "RefreshAllEdbDataByCffex Err:" + err.Error()
  839. // }
  840. // } else if source == utils.DATA_SOURCE_SHFE {
  841. // endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
  842. // err = data_manage.RefreshAllEdbDataByShfe(edbInfoId, source, edbCode, startDate, endDate)
  843. // if err != nil {
  844. // errmsg = "RefreshAllEdbDataByShfe Err:" + err.Error()
  845. // }
  846. // }
  847. //
  848. // maxAndMinItem, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
  849. // if err != nil {
  850. // return err
  851. // }
  852. // if maxAndMinItem != nil {
  853. // err = data_manage.ModifyEdbInfoMaxAndMinInfo(edbInfoId, maxAndMinItem)
  854. // if err != nil {
  855. // return err
  856. // }
  857. // }
  858. // fmt.Println("end newBaseEdbInfoArr:", bv, time.Now())
  859. // }
  860. //
  861. // endDate := "" //计算指标不限制日期
  862. // //刷新相关计算指标
  863. // for _, v := range calculateArr {
  864. // edbInfo := newCalculateMap[v]
  865. // if edbInfo == nil {
  866. // return err
  867. // }
  868. // edbInfoId := edbInfo.EdbInfoId
  869. // source := edbInfo.Source
  870. // edbCode := edbInfo.EdbCode
  871. //
  872. // if source == utils.DATA_SOURCE_CALCULATE {
  873. // startDate = edbInfo.StartDate
  874. // sTime, err := time.Parse(utils.FormatDate, edbInfo.EndDate)
  875. // if err != nil {
  876. // return err
  877. // }
  878. // startDate = sTime.Format(utils.FormatDate)
  879. //
  880. // var edbInfoIdBytes []string
  881. // calculateMap, err := data_manage.GetEdbInfoCalculateDetail(edbInfoId, edbInfo.Source)
  882. // if err != nil {
  883. // errmsg = "GetEdbInfoCalculateDetail Err:" + err.Error()
  884. // return err
  885. // }
  886. // var formulaStr string
  887. // edbInfoList := make([]*data_manage.EdbInfo, 0)
  888. //
  889. // for _, v := range calculateMap {
  890. // formulaStr += v.FromTag + ","
  891. // edbInfoIdBytes = append(edbInfoIdBytes, v.FromTag)
  892. // edbInfo, _ := data_manage.GetEdbInfoById(v.FromEdbInfoId)
  893. // edbInfoList = append(edbInfoList, edbInfo)
  894. // }
  895. // err = data_manage.RefreshAllCalculate(edbInfoList, int(edbInfoId), source, edbInfo.EdbCode, edbInfo.CalculateFormula, startDate, endDate, edbInfoIdBytes)
  896. // if err != nil {
  897. // errmsg = "RefreshCalculate Err:" + err.Error()
  898. // return err
  899. // }
  900. // } else if source == utils.DATA_SOURCE_CALCULATE_LJZZY { //刷新累计值转月值
  901. // calculateLjzzy, err := data_manage.GetEdbInfoCalculateLjzzyDetail(edbInfoId)
  902. // if err != nil {
  903. // errmsg = "GetEdbInfoCalculateLjzzyDetail Err:" + err.Error()
  904. // return err
  905. // }
  906. // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateLjzzy.FromEdbInfoId)
  907. // if err != nil {
  908. // errmsg = "GetEdbInfoById Err:" + err.Error()
  909. // return err
  910. // }
  911. // startDate = edbInfo.StartDate
  912. // endDate = time.Now().Format(utils.FormatDate)
  913. // err = data_manage.RefreshAllCalculateLjzzy(edbInfoId, source, fromEdbInfo, calculateLjzzy.EdbCode, startDate, endDate)
  914. // if err != nil {
  915. // errmsg = "RefreshAllCalculateLjzzy Err:" + err.Error()
  916. // return err
  917. // }
  918. // } else if source == utils.DATA_SOURCE_CALCULATE_TBZ { //刷新同比值
  919. // calculateTbz, err := data_manage.GetEdbInfoCalculateTbzDetail(edbInfoId)
  920. // if err != nil {
  921. // errmsg = "GetEdbInfoCalculateTbzDetail Err:" + err.Error()
  922. // return err
  923. // }
  924. // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTbz.FromEdbInfoId)
  925. // if err != nil {
  926. // errmsg = "GetEdbInfoById Err:" + err.Error()
  927. // return err
  928. // }
  929. // startDate = edbInfo.StartDate
  930. // endDate = time.Now().Format(utils.FormatDate)
  931. // err = data_manage.RefreshAllCalculateTbz(edbInfoId, source, fromEdbInfo, calculateTbz.EdbCode, startDate, endDate)
  932. // if err != nil {
  933. // errmsg = "RefreshAllCalculateTbz Err:" + err.Error()
  934. // return err
  935. // }
  936. // } else if source == utils.DATA_SOURCE_CALCULATE_TCZ { //同差值
  937. // calculateTcz, err := data_manage.GetEdbInfoCalculateTczDetail(edbInfoId)
  938. // if err != nil {
  939. // errmsg = "GetEdbInfoCalculateTczDetail Err:" + err.Error()
  940. // return err
  941. // }
  942. // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTcz.FromEdbInfoId)
  943. // if err != nil {
  944. // errmsg = "GetEdbInfoById Err:" + err.Error()
  945. // return err
  946. // }
  947. // startDate = edbInfo.StartDate
  948. // endDate = time.Now().Format(utils.FormatDate)
  949. // err = data_manage.RefreshAllCalculateTcz(edbInfoId, source, fromEdbInfo, calculateTcz.EdbCode, startDate, endDate)
  950. // if err != nil {
  951. // errmsg = "RefreshCalculateTcz Err:" + err.Error()
  952. // return err
  953. // }
  954. // } else if source == utils.DATA_SOURCE_CALCULATE_NSZYDPJJS { //N数值移动平均计算
  955. // calculateNszydpjjs, err := data_manage.GetEdbInfoCalculateNszydpjjsDetail(edbInfoId)
  956. // if err != nil {
  957. // errmsg = "GetEdbInfoCalculateNszydpjjsDetail Err:" + err.Error()
  958. // return err
  959. // }
  960. // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateNszydpjjs.FromEdbInfoId)
  961. // if err != nil {
  962. // errmsg = "GetEdbInfoById Err:" + err.Error()
  963. // return err
  964. // }
  965. // formulaInt, _ := strconv.Atoi(edbInfo.CalculateFormula)
  966. // startDate = edbInfo.StartDate
  967. // err = data_manage.RefreshAllCalculateNszydpjjs(edbInfoId, edbInfo.Source, formulaInt, fromEdbInfo, calculateNszydpjjs.EdbCode, startDate)
  968. // if err != nil {
  969. // errmsg = "RefreshCalculateNszydpjjs Err:" + err.Error()
  970. // return err
  971. // }
  972. // } else if source == utils.DATA_SOURCE_CALCULATE_HBZ { //刷新环比值
  973. // calculateTbz, err := data_manage.GetEdbInfoCalculateHbzDetail(edbInfoId)
  974. // if err != nil {
  975. // errmsg = "GetEdbInfoCalculateHbzDetail Err:" + err.Error()
  976. // return err
  977. // }
  978. // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTbz.FromEdbInfoId)
  979. // if err != nil {
  980. // errmsg = "GetEdbInfoById Err:" + err.Error()
  981. // return err
  982. // }
  983. // startDate = edbInfo.StartDate
  984. // endDate = time.Now().Format(utils.FormatDate)
  985. // formulaInt, _ := strconv.Atoi(edbInfo.CalculateFormula)
  986. // err = data_manage.RefreshAllCalculateHbz(edbInfoId, source, fromEdbInfo, calculateTbz.EdbCode, startDate, endDate, formulaInt)
  987. // if err != nil {
  988. // errmsg = "RefreshAllCalculateHbz Err:" + err.Error()
  989. // return err
  990. // }
  991. // } else if source == utils.DATA_SOURCE_CALCULATE_HCZ { //刷新环差值
  992. // calculateTbz, err := data_manage.GetEdbInfoCalculateHczDetail(edbInfoId)
  993. // if err != nil {
  994. // errmsg = "GetEdbInfoCalculateHczDetail Err:" + err.Error()
  995. // return err
  996. // }
  997. // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTbz.FromEdbInfoId)
  998. // if err != nil {
  999. // errmsg = "GetEdbInfoById Err:" + err.Error()
  1000. // return err
  1001. // }
  1002. // startDate = edbInfo.StartDate
  1003. // endDate = time.Now().Format(utils.FormatDate)
  1004. // formulaInt, _ := strconv.Atoi(edbInfo.CalculateFormula)
  1005. // err = data_manage.RefreshAllCalculateHcz(edbInfoId, source, fromEdbInfo, calculateTbz.EdbCode, startDate, endDate, formulaInt)
  1006. // if err != nil {
  1007. // errmsg = "RefreshAllCalculateHcz Err:" + err.Error()
  1008. // return err
  1009. // }
  1010. // } else if source == utils.DATA_SOURCE_CALCULATE_BP { //刷新变频
  1011. // calculateTbz, err := data_manage.GetEdbInfoCalculateBpDetail(edbInfoId)
  1012. // if err != nil {
  1013. // errmsg = "GetEdbInfoCalculateTbzDetail Err:" + err.Error()
  1014. // return err
  1015. // }
  1016. // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTbz.FromEdbInfoId)
  1017. // if err != nil {
  1018. // errmsg = "GetEdbInfoById Err:" + err.Error()
  1019. // return err
  1020. // }
  1021. // startDate = edbInfo.StartDate
  1022. // endDate = time.Now().Format(utils.FormatDate)
  1023. // err = data_manage.RefreshAllCalculateBp(edbInfoId, source, fromEdbInfo, calculateTbz.EdbCode, startDate, endDate)
  1024. // if err != nil {
  1025. // errmsg = "RefreshAllCalculateBp Err:" + err.Error()
  1026. // return err
  1027. // }
  1028. //<<<<<<< HEAD
  1029. // } else if source == utils.DATA_SOURCE_CALCULATE_TIME_SHIFT {
  1030. // calculate, err := data_manage.GetEdbInfoCalculateMappingDetail(edbInfoId)
  1031. // if err != nil {
  1032. // errmsg = "GetEdbInfoCalculateTbzDetail Err:" + err.Error()
  1033. // return err
  1034. // }
  1035. // fromEdbInfo, err := data_manage.GetEdbInfoById(calculate.FromEdbInfoId)
  1036. // if err != nil {
  1037. // errmsg = "GetEdbInfoById Err:" + err.Error()
  1038. // return err
  1039. // }
  1040. // startDate = edbInfo.StartDate
  1041. // endDate = time.Now().Format(utils.FormatDate)
  1042. // formulaInt, _ := strconv.Atoi(calculate.CalculateFormula)
  1043. // err = data_manage.RefreshAllCalculateTimeShift(edbInfoId, source, formulaInt, calculate.MoveType, fromEdbInfo, calculate.EdbCode, startDate, endDate, calculate.MoveFrequency)
  1044. // if err != nil {
  1045. // errmsg = "RefreshAllCalculateTimeShift Err:" + err.Error()
  1046. //=======
  1047. // } else if source == utils.DATA_SOURCE_CALCULATE_ZJPJ { //刷新直接拼接
  1048. // err = data_manage.RefreshAllCalculateZjpj(edbInfo)
  1049. // if err != nil {
  1050. // errmsg = "RefreshAllCalculateBp Err:" + err.Error()
  1051. //>>>>>>> 884fd669cc9e91923781680e1890a519c012d38e
  1052. // return err
  1053. // }
  1054. // }
  1055. //
  1056. // maxAndMinItem, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
  1057. // if err != nil {
  1058. // return err
  1059. // }
  1060. //
  1061. // if maxAndMinItem != nil {
  1062. // err = data_manage.ModifyEdbInfoMaxAndMinInfo(edbInfoId, maxAndMinItem)
  1063. // if err != nil {
  1064. // return err
  1065. // }
  1066. // }
  1067. // fmt.Println("end calculateArr:", v, time.Now())
  1068. // }
  1069. // return err
  1070. //}
  1071. //
  1072. //// AddEdbInfo 新增手工指标数据
  1073. //func AddEdbInfo(secName, unit, frequency, noticeTime, mobile string, classifyId, userId int) (err error) {
  1074. // tradeCode, err := models.GetMaxTradeCode()
  1075. // if err != nil {
  1076. // return
  1077. // }
  1078. //
  1079. // if tradeCode == "" {
  1080. // err = errors.New("最大编码为空")
  1081. // return
  1082. // }
  1083. // maxTradeCode, err := utils.GetMaxTradeCode(tradeCode)
  1084. // if err != nil {
  1085. // err = errors.New("获取编码信息失败,Err:" + err.Error())
  1086. // return
  1087. // }
  1088. // if maxTradeCode == "" {
  1089. // err = errors.New("编码为空,请联系技术")
  1090. // return
  1091. // }
  1092. // //判断指标名称是否为空
  1093. // if secName == "" {
  1094. // err = errors.New("指标名称不能为空")
  1095. // return
  1096. // }
  1097. // item, err := models.GetEdbinfoBySecName(secName)
  1098. // if err != nil && err.Error() != utils.ErrNoRow() {
  1099. // err = errors.New("获取信息失败,Err:" + err.Error())
  1100. // return
  1101. // }
  1102. // if item != nil {
  1103. // err = errors.New("指标名称已存在")
  1104. // return
  1105. // }
  1106. // err = models.AddEdbinfo(maxTradeCode, secName, unit, "手动", frequency, noticeTime, classifyId, userId)
  1107. // if err != nil {
  1108. // err = errors.New("新增失败,Err:" + err.Error())
  1109. // return
  1110. // }
  1111. // err = models.AddEdbinfoUser(maxTradeCode, mobile)
  1112. // return
  1113. //}
  1114. //
  1115. //
  1116. //
  1117. //
  1118. // AddOrEditAllEdbInfoToEs 修复ES中的指标
  1119. func AddOrEditAllEdbInfoToEs() {
  1120. //添加es
  1121. total, itemInfoList, _ := data_manage.GetEdbInfoFilterList("", []interface{}{}, 0, 100000)
  1122. for k, itemInfo := range itemInfoList {
  1123. elastic.EsAddOrEditEdbInfoData(utils.DATA_INDEX_NAME, strconv.Itoa(itemInfo.EdbInfoId), itemInfo)
  1124. fmt.Println("剩余", int(total)-k-1, "条数据")
  1125. }
  1126. }
  1127. // AddOrEditEdbInfoToEs 添加/修改ES中的指标
  1128. func AddOrEditEdbInfoToEs(edbInfoId int) {
  1129. //添加es
  1130. itemInfo, _ := data_manage.GetEdbInfoByCondition("AND edb_info_id=?", []interface{}{edbInfoId})
  1131. go elastic.EsAddOrEditEdbInfoData(utils.DATA_INDEX_NAME, strconv.Itoa(itemInfo.EdbInfoId), itemInfo)
  1132. }
  1133. // DeleteEdbInfoToEs 删除ES中的指标
  1134. func DeleteEdbInfoToEs(edbInfoId int) {
  1135. //添加es
  1136. go elastic.EsDeleteEdbInfoData(utils.DATA_INDEX_NAME, strconv.Itoa(edbInfoId))
  1137. }
  1138. // RefreshManualData 根据手工指标code刷新手工指标数据
  1139. func RefreshManualData(edbCode string) {
  1140. var err error
  1141. defer func() {
  1142. if err != nil {
  1143. go alarm_msg.SendAlarmMsg("导入手工数据后,根据手工指标code刷新手工指标数据失败提醒,Err"+err.Error(), 3)
  1144. //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"导入手工数据后,根据手工指标code刷新手工指标数据失败提醒", "errmsg:"+err.Error(), utils.EmailSendToUsers)
  1145. }
  1146. }()
  1147. edbInfo, err := data_manage.GetEdbInfoByEdbCode(utils.DATA_SOURCE_MANUAL, edbCode)
  1148. if err != nil {
  1149. if err.Error() == utils.ErrNoRow() {
  1150. err = nil
  1151. }
  1152. return
  1153. }
  1154. // 刷新指标库
  1155. err, _ = EdbInfoRefreshAllFromBaseV2(edbInfo.EdbInfoId, true, true)
  1156. return
  1157. }
  1158. // 获取频度的英文版
  1159. func GetFrequencyEn(frequency string) (frequencyEn string) {
  1160. switch frequency {
  1161. case "日度":
  1162. frequencyEn = "day"
  1163. return
  1164. case "周度":
  1165. frequencyEn = "week"
  1166. return
  1167. case "旬度":
  1168. frequencyEn = "ten days"
  1169. return
  1170. case "月度":
  1171. frequencyEn = "month"
  1172. return
  1173. case "季度":
  1174. frequencyEn = "quarter"
  1175. return
  1176. case "年度":
  1177. frequencyEn = "year"
  1178. return
  1179. }
  1180. return
  1181. }
  1182. func GetLeadUnitEn(unit string) (unitEn string) {
  1183. switch unit {
  1184. case "天":
  1185. unitEn = "day"
  1186. return
  1187. case "周":
  1188. unitEn = "week"
  1189. return
  1190. case "月":
  1191. unitEn = "month"
  1192. return
  1193. case "季":
  1194. unitEn = "quarter"
  1195. return
  1196. case "年":
  1197. unitEn = "year"
  1198. return
  1199. }
  1200. return
  1201. }
  1202. // getRefreshEdbInfoList 获取待更新的指标(普通基础指标、普通运算指标,预测运算指标)
  1203. //func getRefreshEdbInfoList(edbInfoId int) (newBaseEdbInfoArr []*data_manage.EdbInfo, newCalculateMap, newPredictCalculateMap map[int]*data_manage.EdbInfo, calculateArr, predictCalculateArr []int, err error, errMsg string) {
  1204. // calculateList, err := data_manage.GetEdbInfoAllCalculate(edbInfoId)
  1205. // if err != nil && err.Error() != utils.ErrNoRow() {
  1206. // err = errors.New("GetEdbInfoAllCalculate Err:" + err.Error())
  1207. // return
  1208. // }
  1209. // // 获取指标信息
  1210. // baseEdbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  1211. // if err != nil {
  1212. // err = errors.New("GetEdbInfoAllCalGetEdbInfoByIdr:" + err.Error())
  1213. // return
  1214. // }
  1215. //
  1216. // baseEdbInfoArr := make([]*data_manage.EdbInfo, 0) // 基础普通指标
  1217. // calculateInfoArr := make([]*data_manage.EdbInfo, 0) //基础运算指标
  1218. // basePredictEdbInfoArr := make([]*data_manage.EdbInfo, 0) // 预测普通指标
  1219. // predictCalculateInfoArr := make([]*data_manage.EdbInfo, 0) //预测运算指标
  1220. //
  1221. // if baseEdbInfo.EdbInfoType == 0 { //普通指标
  1222. // switch baseEdbInfo.EdbType {
  1223. // case 1: //基础指标
  1224. // baseEdbInfoArr = append(baseEdbInfoArr, baseEdbInfo)
  1225. // case 2: //计算指标
  1226. // calculateList = append(calculateList, baseEdbInfo)
  1227. // }
  1228. // } else { //预测指标
  1229. // switch baseEdbInfo.EdbType {
  1230. // case 1: //基础指标
  1231. // basePredictEdbInfoArr = append(basePredictEdbInfoArr, baseEdbInfo)
  1232. // case 2: //计算指标
  1233. // predictCalculateInfoArr = append(predictCalculateInfoArr, baseEdbInfo)
  1234. // }
  1235. // }
  1236. //
  1237. // // 计算指标
  1238. // for _, v := range calculateList {
  1239. // getBaseEdbInfoArr, getCalculateInfoArr, tmpErr := data_manage.GetRefreshEdbInfoFromBase(v.EdbInfoId, v.Source)
  1240. // if tmpErr != nil {
  1241. // err = tmpErr
  1242. // fmt.Println("GetRefreshEdbInfoFromBase err:" + err.Error())
  1243. // errMsg = "获取需要刷新的指标失败:Err:" + err.Error()
  1244. // return
  1245. // }
  1246. // for _, tmpEdbInfo := range getBaseEdbInfoArr {
  1247. // switch tmpEdbInfo.EdbInfoType {
  1248. // case 0: //普通基础指标
  1249. // baseEdbInfoArr = append(baseEdbInfoArr, tmpEdbInfo)
  1250. // case 1: //预测基础指标
  1251. // basePredictEdbInfoArr = append(basePredictEdbInfoArr, tmpEdbInfo)
  1252. // }
  1253. // }
  1254. //
  1255. // for _, tmpEdbInfo := range getCalculateInfoArr {
  1256. // switch tmpEdbInfo.EdbInfoType {
  1257. // case 0: //普通运算指标
  1258. // calculateInfoArr = append(calculateInfoArr, tmpEdbInfo)
  1259. // case 1: //预测运算指标
  1260. // predictCalculateInfoArr = append(predictCalculateInfoArr, tmpEdbInfo)
  1261. // }
  1262. // }
  1263. // switch v.EdbInfoType {
  1264. // case 0: //普通运算指标
  1265. // calculateInfoArr = append(calculateInfoArr, v)
  1266. // case 1: //预测运算指标
  1267. // predictCalculateInfoArr = append(predictCalculateInfoArr, v)
  1268. // }
  1269. // }
  1270. //
  1271. // // 预测计算指标
  1272. // for _, v := range predictCalculateInfoArr {
  1273. // getBaseEdbInfoArr, getCalculateInfoArr, tmpErr := data_manage.GetRefreshEdbInfoFromBase(v.EdbInfoId, v.Source)
  1274. // if tmpErr != nil {
  1275. // err = tmpErr
  1276. // fmt.Println("GetRefreshEdbInfoFromBase err:" + err.Error())
  1277. // errMsg = "获取需要刷新的指标失败:Err:" + err.Error()
  1278. // return
  1279. // }
  1280. // for _, tmpEdbInfo := range getBaseEdbInfoArr {
  1281. // switch tmpEdbInfo.EdbInfoType {
  1282. // case 0: //普通基础指标
  1283. // baseEdbInfoArr = append(baseEdbInfoArr, tmpEdbInfo)
  1284. // case 1: //预测基础指标
  1285. // basePredictEdbInfoArr = append(basePredictEdbInfoArr, tmpEdbInfo)
  1286. // }
  1287. // }
  1288. //
  1289. // for _, tmpEdbInfo := range getCalculateInfoArr {
  1290. // switch tmpEdbInfo.EdbInfoType {
  1291. // case 0: //普通运算指标
  1292. // calculateInfoArr = append(calculateInfoArr, tmpEdbInfo)
  1293. // case 1: //预测运算指标
  1294. // predictCalculateInfoArr = append(predictCalculateInfoArr, tmpEdbInfo)
  1295. // }
  1296. // }
  1297. // switch v.EdbInfoType {
  1298. // case 0: //普通运算指标
  1299. // calculateInfoArr = append(calculateInfoArr, v)
  1300. // case 1: //预测运算指标
  1301. // predictCalculateInfoArr = append(predictCalculateInfoArr, v)
  1302. // }
  1303. // }
  1304. //
  1305. // // 第一次的计算指标map
  1306. // newCalculateMap = make(map[int]*data_manage.EdbInfo)
  1307. // for _, v := range calculateInfoArr {
  1308. // if _, ok := newCalculateMap[v.EdbInfoId]; !ok {
  1309. // calculateArr = append(calculateArr, v.EdbInfoId)
  1310. // }
  1311. // newCalculateMap[v.EdbInfoId] = v
  1312. // }
  1313. //
  1314. // // 基础预测指标
  1315. // if len(basePredictEdbInfoArr) > 0 {
  1316. // basePredictEdbInfoIdList := make([]int, 0)
  1317. // for _, v := range basePredictEdbInfoArr {
  1318. // basePredictEdbInfoIdList = append(basePredictEdbInfoIdList, v.EdbInfoId)
  1319. // }
  1320. // baseEdbInfoList, tmpErr := data_manage.GetPredictEdbInfoAllCalculate(basePredictEdbInfoIdList)
  1321. // if tmpErr != nil {
  1322. // err = tmpErr
  1323. // return
  1324. // }
  1325. //
  1326. // tmpCalculateList := make([]*data_manage.EdbInfo, 0)
  1327. // for _, v := range baseEdbInfoList {
  1328. // switch v.EdbType {
  1329. // case 1:
  1330. // baseEdbInfoArr = append(baseEdbInfoArr, v)
  1331. // case 2:
  1332. // // 如果不在第一次里面,那么在第二次 刷新预测指标的时候 需要加进去
  1333. // if _, ok := newCalculateMap[v.EdbInfoId]; !ok {
  1334. // tmpCalculateList = append(tmpCalculateList, v)
  1335. // }
  1336. // }
  1337. // }
  1338. //
  1339. // // 这里是查询预测指标用到的 普通计算指标
  1340. // for _, v := range tmpCalculateList {
  1341. // getBaseEdbInfoArr, getCalculateInfoArr, tmpErr := data_manage.GetRefreshEdbInfoFromBase(v.EdbInfoId, v.Source)
  1342. // if tmpErr != nil {
  1343. // err = tmpErr
  1344. // fmt.Println("GetRefreshEdbInfoFromBase err:" + err.Error())
  1345. // errMsg = "获取需要刷新的指标失败:Err:" + err.Error()
  1346. // return
  1347. // }
  1348. //
  1349. // // 基础指标
  1350. // for _, tmpEdbInfo := range getBaseEdbInfoArr {
  1351. // switch tmpEdbInfo.EdbInfoType {
  1352. // case 0: //普通基础指标
  1353. // baseEdbInfoArr = append(baseEdbInfoArr, tmpEdbInfo)
  1354. // case 1: //预测基础指标
  1355. // basePredictEdbInfoArr = append(basePredictEdbInfoArr, tmpEdbInfo)
  1356. // }
  1357. // }
  1358. //
  1359. // // 计算指标
  1360. // for _, tmpEdbInfo := range getCalculateInfoArr {
  1361. // switch tmpEdbInfo.EdbInfoType {
  1362. // case 0: //普通运算指标
  1363. // calculateInfoArr = append(calculateInfoArr, tmpEdbInfo)
  1364. // case 1: //预测运算指标
  1365. // predictCalculateInfoArr = append(predictCalculateInfoArr, tmpEdbInfo)
  1366. // }
  1367. // }
  1368. // switch v.EdbInfoType {
  1369. // case 0: //普通运算指标
  1370. // calculateInfoArr = append(calculateInfoArr, v)
  1371. // case 1: //预测运算指标
  1372. // predictCalculateInfoArr = append(predictCalculateInfoArr, v)
  1373. // }
  1374. // }
  1375. //
  1376. // // 第二次计算指标的map
  1377. // for _, v := range calculateInfoArr {
  1378. // if _, ok := newCalculateMap[v.EdbInfoId]; !ok {
  1379. // calculateArr = append(calculateArr, v.EdbInfoId)
  1380. // }
  1381. // newCalculateMap[v.EdbInfoId] = v
  1382. // }
  1383. // }
  1384. //
  1385. // // 普通基础指标去重
  1386. // newBaseEdbInfoArr = make([]*data_manage.EdbInfo, 0)
  1387. // baseMap := make(map[int]int)
  1388. // for _, v := range baseEdbInfoArr {
  1389. // if _, ok := baseMap[v.EdbInfoId]; !ok {
  1390. // newBaseEdbInfoArr = append(newBaseEdbInfoArr, v)
  1391. // }
  1392. // baseMap[v.EdbInfoId] = v.EdbInfoId
  1393. // }
  1394. //
  1395. // // 普通计算指标的id
  1396. // sort.Ints(calculateArr)
  1397. //
  1398. // // 预测计算指标去重
  1399. // newPredictCalculateMap = make(map[int]*data_manage.EdbInfo)
  1400. // for _, v := range predictCalculateInfoArr {
  1401. // if _, ok := newPredictCalculateMap[v.EdbInfoId]; !ok {
  1402. // predictCalculateArr = append(predictCalculateArr, v.EdbInfoId)
  1403. // }
  1404. // newPredictCalculateMap[v.EdbInfoId] = v
  1405. // }
  1406. // // 预测计算指标的id
  1407. // sort.Ints(predictCalculateArr)
  1408. //
  1409. // return
  1410. //}
  1411. // getRefreshEdbInfoList 获取待更新的指标(普通基础指标、普通运算指标,预测运算指标)
  1412. func getRefreshEdbInfoListByIds(edbInfoIdList []int) (newBaseEdbInfoArr, newBasePredictEdbInfoArr []*data_manage.EdbInfo, newCalculateMap, newPredictCalculateMap map[int]*data_manage.EdbInfo, calculateArr, predictCalculateArr []int, err error, errMsg string) {
  1413. calculateList, err := data_manage.GetEdbInfoAllCalculateByEdbInfoIdList(edbInfoIdList)
  1414. if err != nil && err.Error() != utils.ErrNoRow() {
  1415. err = errors.New("GetEdbInfoAllCalculate Err:" + err.Error())
  1416. return
  1417. }
  1418. // 获取指标信息
  1419. edbInfoList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  1420. if err != nil {
  1421. err = errors.New("GetEdbInfoAllCalGetEdbInfoByIdr:" + err.Error())
  1422. return
  1423. }
  1424. baseEdbInfoArr := make([]*data_manage.EdbInfo, 0) // 基础普通指标
  1425. calculateInfoArr := make([]*data_manage.EdbInfo, 0) //基础运算指标
  1426. basePredictEdbInfoArr := make([]*data_manage.EdbInfo, 0) // 预测普通指标
  1427. predictCalculateInfoArr := make([]*data_manage.EdbInfo, 0) //预测运算指标
  1428. for _, baseEdbInfo := range edbInfoList {
  1429. // 指标若停更, 则忽略掉
  1430. if baseEdbInfo.NoUpdate == 1 {
  1431. continue
  1432. }
  1433. if baseEdbInfo.EdbInfoType == 0 { //普通指标
  1434. switch baseEdbInfo.EdbType {
  1435. case 1: //基础指标
  1436. baseEdbInfoArr = append(baseEdbInfoArr, baseEdbInfo)
  1437. case 2: //计算指标
  1438. calculateList = append(calculateList, baseEdbInfo)
  1439. }
  1440. } else { //预测指标
  1441. switch baseEdbInfo.EdbType {
  1442. case 1: //基础指标
  1443. basePredictEdbInfoArr = append(basePredictEdbInfoArr, baseEdbInfo)
  1444. case 2: //计算指标
  1445. predictCalculateInfoArr = append(predictCalculateInfoArr, baseEdbInfo)
  1446. }
  1447. }
  1448. }
  1449. // 计算指标
  1450. for _, v := range calculateList {
  1451. getBaseEdbInfoArr, getCalculateInfoArr, tmpErr := data_manage.GetRefreshEdbInfoFromBase(v.EdbInfoId, v.Source)
  1452. if tmpErr != nil {
  1453. err = tmpErr
  1454. fmt.Println("GetRefreshEdbInfoFromBase err:" + err.Error())
  1455. errMsg = "获取需要刷新的指标失败:Err:" + err.Error()
  1456. return
  1457. }
  1458. for _, tmpEdbInfo := range getBaseEdbInfoArr {
  1459. switch tmpEdbInfo.EdbInfoType {
  1460. case 0: //普通基础指标
  1461. baseEdbInfoArr = append(baseEdbInfoArr, tmpEdbInfo)
  1462. case 1: //预测基础指标
  1463. basePredictEdbInfoArr = append(basePredictEdbInfoArr, tmpEdbInfo)
  1464. }
  1465. }
  1466. for _, tmpEdbInfo := range getCalculateInfoArr {
  1467. switch tmpEdbInfo.EdbInfoType {
  1468. case 0: //普通运算指标
  1469. calculateInfoArr = append(calculateInfoArr, tmpEdbInfo)
  1470. case 1: //预测运算指标
  1471. //predictCalculateInfoArr = append(predictCalculateInfoArr, tmpEdbInfo)
  1472. if tmpEdbInfo.EdbType == 1 { //预测普通指标
  1473. basePredictEdbInfoArr = append(basePredictEdbInfoArr, tmpEdbInfo)
  1474. } else {
  1475. predictCalculateInfoArr = append(predictCalculateInfoArr, tmpEdbInfo)
  1476. }
  1477. }
  1478. }
  1479. switch v.EdbInfoType {
  1480. case 0: //普通运算指标
  1481. calculateInfoArr = append(calculateInfoArr, v)
  1482. case 1: //预测指标
  1483. if v.EdbType == 1 { //预测普通指标
  1484. basePredictEdbInfoArr = append(basePredictEdbInfoArr, v)
  1485. } else {
  1486. predictCalculateInfoArr = append(predictCalculateInfoArr, v)
  1487. }
  1488. }
  1489. }
  1490. // 预测计算指标
  1491. for _, v := range predictCalculateInfoArr {
  1492. getBaseEdbInfoArr, getCalculateInfoArr, tmpErr := data_manage.GetRefreshEdbInfoFromBase(v.EdbInfoId, v.Source)
  1493. if tmpErr != nil {
  1494. err = tmpErr
  1495. fmt.Println("GetRefreshEdbInfoFromBase err:" + err.Error())
  1496. errMsg = "获取需要刷新的指标失败:Err:" + err.Error()
  1497. return
  1498. }
  1499. for _, tmpEdbInfo := range getBaseEdbInfoArr {
  1500. switch tmpEdbInfo.EdbInfoType {
  1501. case 0: //普通基础指标
  1502. baseEdbInfoArr = append(baseEdbInfoArr, tmpEdbInfo)
  1503. case 1: //预测基础指标
  1504. if tmpEdbInfo.EdbType == 1 { //预测普通指标
  1505. basePredictEdbInfoArr = append(basePredictEdbInfoArr, tmpEdbInfo)
  1506. } else {
  1507. predictCalculateInfoArr = append(predictCalculateInfoArr, tmpEdbInfo)
  1508. }
  1509. //basePredictEdbInfoArr = append(basePredictEdbInfoArr, tmpEdbInfo)
  1510. }
  1511. }
  1512. for _, tmpEdbInfo := range getCalculateInfoArr {
  1513. switch tmpEdbInfo.EdbInfoType {
  1514. case 0: //普通运算指标
  1515. calculateInfoArr = append(calculateInfoArr, tmpEdbInfo)
  1516. case 1: //预测运算指标
  1517. if tmpEdbInfo.EdbType == 1 { //预测普通指标
  1518. basePredictEdbInfoArr = append(basePredictEdbInfoArr, tmpEdbInfo)
  1519. } else {
  1520. predictCalculateInfoArr = append(predictCalculateInfoArr, tmpEdbInfo)
  1521. }
  1522. //predictCalculateInfoArr = append(predictCalculateInfoArr, tmpEdbInfo)
  1523. }
  1524. }
  1525. switch v.EdbInfoType {
  1526. case 0: //普通运算指标
  1527. calculateInfoArr = append(calculateInfoArr, v)
  1528. case 1: //预测指标
  1529. if v.EdbType == 1 { //预测普通指标
  1530. basePredictEdbInfoArr = append(basePredictEdbInfoArr, v)
  1531. } else {
  1532. predictCalculateInfoArr = append(predictCalculateInfoArr, v)
  1533. }
  1534. }
  1535. }
  1536. // 第一次的计算指标map
  1537. newCalculateMap = make(map[int]*data_manage.EdbInfo)
  1538. for _, v := range calculateInfoArr {
  1539. if _, ok := newCalculateMap[v.EdbInfoId]; !ok {
  1540. calculateArr = append(calculateArr, v.EdbInfoId)
  1541. }
  1542. newCalculateMap[v.EdbInfoId] = v
  1543. }
  1544. // 基础预测指标
  1545. if len(basePredictEdbInfoArr) > 0 {
  1546. basePredictEdbInfoIdList := make([]int, 0)
  1547. for _, v := range basePredictEdbInfoArr {
  1548. basePredictEdbInfoIdList = append(basePredictEdbInfoIdList, v.EdbInfoId)
  1549. }
  1550. baseEdbInfoList, tmpErr := data_manage.GetPredictEdbInfoAllCalculate(basePredictEdbInfoIdList)
  1551. if tmpErr != nil {
  1552. err = tmpErr
  1553. return
  1554. }
  1555. tmpCalculateList := make([]*data_manage.EdbInfo, 0)
  1556. for _, v := range baseEdbInfoList {
  1557. switch v.EdbType {
  1558. case 1:
  1559. baseEdbInfoArr = append(baseEdbInfoArr, v)
  1560. case 2:
  1561. // 如果不在第一次里面,那么在第二次 刷新预测指标的时候 需要加进去
  1562. if _, ok := newCalculateMap[v.EdbInfoId]; !ok {
  1563. tmpCalculateList = append(tmpCalculateList, v)
  1564. }
  1565. }
  1566. }
  1567. // 这里是查询预测指标用到的 普通计算指标
  1568. for _, v := range tmpCalculateList {
  1569. getBaseEdbInfoArr, getCalculateInfoArr, tmpErr := data_manage.GetRefreshEdbInfoFromBase(v.EdbInfoId, v.Source)
  1570. if tmpErr != nil {
  1571. err = tmpErr
  1572. fmt.Println("GetRefreshEdbInfoFromBase err:" + err.Error())
  1573. errMsg = "获取需要刷新的指标失败:Err:" + err.Error()
  1574. return
  1575. }
  1576. // 基础指标
  1577. for _, tmpEdbInfo := range getBaseEdbInfoArr {
  1578. switch tmpEdbInfo.EdbInfoType {
  1579. case 0: //普通基础指标
  1580. baseEdbInfoArr = append(baseEdbInfoArr, tmpEdbInfo)
  1581. case 1: //预测基础指标
  1582. basePredictEdbInfoArr = append(basePredictEdbInfoArr, tmpEdbInfo)
  1583. }
  1584. }
  1585. // 计算指标
  1586. for _, tmpEdbInfo := range getCalculateInfoArr {
  1587. switch tmpEdbInfo.EdbInfoType {
  1588. case 0: //普通运算指标
  1589. calculateInfoArr = append(calculateInfoArr, tmpEdbInfo)
  1590. case 1: //预测运算指标
  1591. if v.EdbType == 1 { //预测普通指标
  1592. basePredictEdbInfoArr = append(basePredictEdbInfoArr, tmpEdbInfo)
  1593. } else {
  1594. predictCalculateInfoArr = append(predictCalculateInfoArr, tmpEdbInfo)
  1595. }
  1596. }
  1597. }
  1598. switch v.EdbInfoType {
  1599. case 0: //普通运算指标
  1600. calculateInfoArr = append(calculateInfoArr, v)
  1601. case 1: //预测指标
  1602. if v.EdbType == 1 { //预测普通指标
  1603. basePredictEdbInfoArr = append(basePredictEdbInfoArr, v)
  1604. } else { //预测运算指标
  1605. predictCalculateInfoArr = append(predictCalculateInfoArr, v)
  1606. }
  1607. }
  1608. }
  1609. // 第二次计算指标的map
  1610. for _, v := range calculateInfoArr {
  1611. if _, ok := newCalculateMap[v.EdbInfoId]; !ok {
  1612. calculateArr = append(calculateArr, v.EdbInfoId)
  1613. }
  1614. newCalculateMap[v.EdbInfoId] = v
  1615. }
  1616. }
  1617. // 普通基础指标去重
  1618. newBaseEdbInfoArr = make([]*data_manage.EdbInfo, 0)
  1619. baseMap := make(map[int]int)
  1620. for _, v := range baseEdbInfoArr {
  1621. if _, ok := baseMap[v.EdbInfoId]; !ok {
  1622. newBaseEdbInfoArr = append(newBaseEdbInfoArr, v)
  1623. }
  1624. baseMap[v.EdbInfoId] = v.EdbInfoId
  1625. }
  1626. // 普通计算指标的id
  1627. sort.Ints(calculateArr)
  1628. // 普通预测指标去重
  1629. newBasePredictEdbInfoArr = make([]*data_manage.EdbInfo, 0)
  1630. basePredictMap := make(map[int]int)
  1631. for _, v := range basePredictEdbInfoArr {
  1632. if _, ok := basePredictMap[v.EdbInfoId]; !ok {
  1633. newBasePredictEdbInfoArr = append(newBasePredictEdbInfoArr, v)
  1634. }
  1635. basePredictMap[v.EdbInfoId] = v.EdbInfoId
  1636. }
  1637. // 预测计算指标去重
  1638. newPredictCalculateMap = make(map[int]*data_manage.EdbInfo)
  1639. for _, v := range predictCalculateInfoArr {
  1640. if _, ok := newPredictCalculateMap[v.EdbInfoId]; !ok {
  1641. predictCalculateArr = append(predictCalculateArr, v.EdbInfoId)
  1642. }
  1643. newPredictCalculateMap[v.EdbInfoId] = v
  1644. }
  1645. // 预测计算指标的id
  1646. sort.Ints(predictCalculateArr)
  1647. return
  1648. }
  1649. type AddEdbBaseInfoReq struct {
  1650. EdbCode string `description:"指标编码"`
  1651. EdbName string `description:"指标名称"`
  1652. Unit string `description:"单位"`
  1653. ClassifyId int `description:"所属分类"`
  1654. SysUserId int `description:"用户id"`
  1655. SysUserRealName string `description:"用户真实名称"`
  1656. }
  1657. // EdbInfoAdd 添加指标到指标库
  1658. func EdbInfoAdd(source, subSource, classifyId int, edbCode, edbName, frequency, unit, startDate, endDate string, sysUserId int, sysUserRealName, lang string) (edbInfo *data_manage.EdbInfo, err error, errMsg string, isSendEmail bool) {
  1659. // 有些指标的添加是走的指标公共服务
  1660. if source == utils.DATA_SOURCE_BUSINESS {
  1661. req2 := AddEdbBaseInfoReq{
  1662. EdbCode: edbCode,
  1663. EdbName: edbName,
  1664. Unit: unit,
  1665. ClassifyId: classifyId,
  1666. SysUserId: sysUserId,
  1667. SysUserRealName: sysUserRealName,
  1668. }
  1669. reqJson, tmpErr := json.Marshal(req2)
  1670. if tmpErr != nil {
  1671. err = tmpErr
  1672. return
  1673. }
  1674. respItem, tmpErr := AddBaseEdbInfo(string(reqJson), source, subSource, lang)
  1675. if tmpErr != nil {
  1676. errMsg = "添加失败"
  1677. err = tmpErr
  1678. return
  1679. }
  1680. isSendEmail = respItem.IsSendEmail
  1681. if respItem.Ret != 200 {
  1682. errMsg = respItem.Msg
  1683. err = errors.New(respItem.ErrMsg)
  1684. } else {
  1685. edbInfo, err = data_manage.GetEdbInfoById(respItem.Data.EdbInfoId)
  1686. }
  1687. return
  1688. }
  1689. isSendEmail = true
  1690. //判断指标名称是否存在
  1691. {
  1692. var count int
  1693. var condition string
  1694. var pars []interface{}
  1695. //condition += " AND source=? "
  1696. //pars = append(pars, source)
  1697. switch lang {
  1698. case utils.EnLangVersion:
  1699. condition += " AND edb_name_en = ? "
  1700. default:
  1701. condition += " AND edb_name=? "
  1702. }
  1703. pars = append(pars, edbName)
  1704. count, err = data_manage.GetEdbInfoCountByCondition(condition, pars)
  1705. if err != nil {
  1706. errMsg = "判断指标名称是否存在失败"
  1707. err = errors.New("判断指标名称是否存在失败,Err:" + err.Error())
  1708. return
  1709. }
  1710. if count > 0 {
  1711. errMsg = "指标名称已存在,请重新填写"
  1712. err = errors.New(errMsg)
  1713. isSendEmail = false
  1714. return
  1715. }
  1716. }
  1717. edbInfo = new(data_manage.EdbInfo)
  1718. edbInfo.Source = source
  1719. sourceNameMap := map[int]string{
  1720. utils.DATA_SOURCE_THS: "同花顺",
  1721. utils.DATA_SOURCE_WIND: "wind",
  1722. utils.DATA_SOURCE_PB: "彭博",
  1723. utils.DATA_SOURCE_PB_FINANCE: "彭博财务",
  1724. utils.DATA_SOURCE_MANUAL: "手工数据",
  1725. utils.DATA_SOURCE_LZ: "隆众",
  1726. utils.DATA_SOURCE_YS: "SMM",
  1727. utils.DATA_SOURCE_GL: "钢联",
  1728. utils.DATA_SOURCE_ZZ: "郑商所",
  1729. utils.DATA_SOURCE_DL: "大商所",
  1730. utils.DATA_SOURCE_SH: "上期所",
  1731. utils.DATA_SOURCE_CFFEX: "中金所",
  1732. utils.DATA_SOURCE_SHFE: "上期能源",
  1733. utils.DATA_SOURCE_GIE: "欧洲天然气",
  1734. utils.DATA_SOURCE_LT: "路透",
  1735. utils.DATA_SOURCE_COAL: "中国煤炭市场网",
  1736. utils.DATA_SOURCE_GOOGLE_TRAVEL: "our world in data",
  1737. utils.DATA_SOURCE_MYSTEEL_CHEMICAL: "钢联",
  1738. utils.DATA_SOURCE_EIA_STEO: "EIA STEO报告",
  1739. utils.DATA_SOURCE_COM_TRADE: "UN",
  1740. utils.DATA_SOURCE_SCI: "SCI",
  1741. utils.DATA_SOURCE_BAIINFO: "BAIINFO",
  1742. utils.DATA_SOURCE_STOCK_PLANT: "存量装置",
  1743. utils.DATA_SOURCE_NATIONAL_STATISTICS: "国家统计局",
  1744. utils.DATA_SOURCE_FUBAO: "富宝数据",
  1745. utils.DATA_SOURCE_GFEX: "广期所",
  1746. utils.DATA_SOURCE_SCI_HQ: "卓创红期",
  1747. utils.DATA_SOURCE_LY: "粮油商务网",
  1748. utils.DATA_SOURCE_TRADE_ANALYSIS: "持仓分析",
  1749. utils.DATA_SOURCE_CALCULATE_STL: "STL趋势分解",
  1750. }
  1751. sourceName, ok := sourceNameMap[source]
  1752. if !ok {
  1753. edbSource := data_manage.EdbSourceIdMap[source]
  1754. if edbSource != nil {
  1755. sourceName = edbSource.SourceName
  1756. }
  1757. if sourceName == "" {
  1758. errMsg = "指标来源异常"
  1759. err = errors.New(errMsg)
  1760. return
  1761. }
  1762. }
  1763. edbInfo.SourceName = sourceName
  1764. edbType := 1 //基础指标
  1765. if source == utils.DATA_SOURCE_STOCK_PLANT {
  1766. edbType = 2 //计算指标
  1767. }
  1768. // 从缓存中获取
  1769. terminalCode, serverUrl, sourceIndexName, e := GetEdbTerminalCodeBySource(edbInfo.Source, edbInfo.EdbCode, edbInfo.StockCode)
  1770. if e != nil {
  1771. errMsg = "获取可以使用的终端地址失败"
  1772. err = errors.New("获取可以使用的终端地址失败,Err:" + e.Error())
  1773. return
  1774. }
  1775. //获取该层级下最大的排序数
  1776. maxSort, err := GetEdbClassifyMaxSort(classifyId, 0)
  1777. if err != nil {
  1778. errMsg = "获取失败"
  1779. err = errors.New("查询排序信息失败,Err:" + err.Error())
  1780. return
  1781. }
  1782. edbInfo.EdbCode = edbCode
  1783. edbInfo.EdbName = edbName
  1784. edbInfo.EdbNameEn = edbName
  1785. edbInfo.EdbNameSource = edbName
  1786. edbInfo.Frequency = frequency
  1787. edbInfo.Unit = unit
  1788. edbInfo.UnitEn = unit
  1789. edbInfo.StartDate = startDate
  1790. edbInfo.EndDate = endDate
  1791. edbInfo.ClassifyId = classifyId
  1792. edbInfo.SysUserId = sysUserId
  1793. edbInfo.SysUserRealName = sysUserRealName
  1794. edbInfo.CreateTime = time.Now()
  1795. edbInfo.ModifyTime = time.Now()
  1796. edbInfo.ServerUrl = serverUrl
  1797. edbInfo.Sort = maxSort + 1
  1798. edbInfo.DataDateType = `交易日`
  1799. edbInfo.TerminalCode = terminalCode
  1800. edbInfo.SourceIndexName = sourceIndexName
  1801. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  1802. edbInfo.UniqueCode = utils.MD5(utils.DATA_PREFIX + "_" + timestamp)
  1803. itemVal, err := data_manage.GetEdbInfoMaxAndMinInfo(source, subSource, edbCode)
  1804. if itemVal != nil && err == nil {
  1805. edbInfo.MaxValue = itemVal.MaxValue
  1806. edbInfo.MinValue = itemVal.MinValue
  1807. }
  1808. edbInfo.EdbType = edbType
  1809. edbInfoId, err := data_manage.AddEdbInfo(edbInfo)
  1810. if err != nil {
  1811. errMsg = "保存失败"
  1812. err = errors.New("保存失败,Err:" + err.Error())
  1813. return
  1814. }
  1815. edbInfo.EdbInfoId = int(edbInfoId)
  1816. //保存数据
  1817. data_manage.ModifyEdbInfoDataStatus(edbInfoId, source, subSource, edbCode)
  1818. maxAndMinItem, _ := data_manage.GetEdbInfoMaxAndMinInfo(source, subSource, edbCode)
  1819. if maxAndMinItem != nil {
  1820. err = data_manage.ModifyEdbInfoMaxAndMinInfo(int(edbInfoId), maxAndMinItem)
  1821. }
  1822. //添加es
  1823. AddOrEditEdbInfoToEs(int(edbInfoId))
  1824. go handleByAddEdbInfo(edbInfo)
  1825. return
  1826. }
  1827. // TraceEdbInfoByEdbInfoId 指标追溯
  1828. func TraceEdbInfoByEdbInfoId(edbInfoId, sysUserId int) (traceEdbInfo data_manage.TraceEdbInfoResp, err error) {
  1829. edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
  1830. if err != nil {
  1831. return
  1832. }
  1833. edbInfoRuleMap := make(map[int]string, 0)
  1834. edbMappingMap := make(map[int][]*data_manage.EdbInfoCalculateMappingInfo)
  1835. //edbInfoRuleMap[edbInfoId] = getEdbRuleTitle(edbInfo)
  1836. traceEdbInfo = data_manage.TraceEdbInfoResp{
  1837. //EdbInfoId: edbInfo.EdbInfoId,
  1838. EdbInfoId: edbInfoId,
  1839. EdbInfoType: edbInfo.EdbInfoType,
  1840. EdbName: edbInfo.EdbName,
  1841. EdbNameEn: edbInfo.EdbNameEn,
  1842. EdbType: edbInfo.EdbType,
  1843. //Source: edbInfo.Source,
  1844. UniqueCode: edbInfo.UniqueCode,
  1845. ClassifyId: edbInfo.ClassifyId,
  1846. IsStop: edbInfo.NoUpdate,
  1847. EdbInfo: edbInfo,
  1848. }
  1849. findIdMap := make(map[int]int)
  1850. findIdMap[edbInfoId] = edbInfoId
  1851. existMap := make(map[int]data_manage.TraceEdbInfoResp)
  1852. traceEdbInfo.Child, err = traceEdbInfoByEdbInfoId(edbInfoId, traceEdbInfo, edbInfoRuleMap, findIdMap, existMap, edbMappingMap)
  1853. edbInfoIdList := make([]int, 0)
  1854. for _, v := range findIdMap {
  1855. edbInfoIdList = append(edbInfoIdList, v)
  1856. }
  1857. classifyIdList := make([]int, 0)
  1858. edbInfoList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  1859. if err != nil {
  1860. return
  1861. }
  1862. edbInfoMap := make(map[int]*data_manage.EdbInfo)
  1863. for _, tmpEdbInfo := range edbInfoList {
  1864. edbInfoMap[tmpEdbInfo.EdbInfoId] = tmpEdbInfo
  1865. classifyIdList = append(classifyIdList, tmpEdbInfo.ClassifyId)
  1866. }
  1867. // 指标权限Map
  1868. edbInfoIdPermissionMap := make(map[int]bool)
  1869. // 指标权限
  1870. {
  1871. // 当前的分类
  1872. classifyMap := make(map[int]*data_manage.EdbClassify)
  1873. classifyList, tmpErr := data_manage.GetEdbClassifyByIdList(classifyIdList)
  1874. if tmpErr != nil {
  1875. err = tmpErr
  1876. return
  1877. }
  1878. for _, v := range classifyList {
  1879. classifyMap[v.ClassifyId] = v
  1880. }
  1881. // 获取所有有权限的指标和分类
  1882. permissionEdbIdList, permissionClassifyIdList, tmpErr := data_manage_permission.GetUserEdbAndClassifyPermissionList(sysUserId, 0, 0)
  1883. if tmpErr != nil {
  1884. err = tmpErr
  1885. return
  1886. }
  1887. for _, v := range edbInfoMap {
  1888. if currClassify, ok := classifyMap[v.ClassifyId]; ok {
  1889. edbInfoIdPermissionMap[v.EdbInfoId] = data_manage_permission.CheckEdbPermissionByPermissionIdList(v.IsJoinPermission, currClassify.IsJoinPermission, v.EdbInfoId, v.ClassifyId, permissionEdbIdList, permissionClassifyIdList)
  1890. }
  1891. }
  1892. }
  1893. traceEdbInfo, err = handleTraceEdbInfo(traceEdbInfo, 0, edbInfoMap, edbMappingMap, edbInfoIdPermissionMap)
  1894. // 权限校验
  1895. return
  1896. }
  1897. // TraceEdbInfoByEdbInfoIdList 指标追溯
  1898. func TraceEdbInfoByEdbInfoIdList(edbInfoIdList []int) (traceEdbInfoList []data_manage.TraceEdbInfoResp, err error) {
  1899. traceEdbInfoList = make([]data_manage.TraceEdbInfoResp, 0)
  1900. edbInfoList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
  1901. if err != nil {
  1902. return
  1903. }
  1904. edbInfoRuleMap := make(map[int]string, 0)
  1905. edbMappingMap := make(map[int][]*data_manage.EdbInfoCalculateMappingInfo)
  1906. findIdMap := make(map[int]int)
  1907. existMap := make(map[int]data_manage.TraceEdbInfoResp)
  1908. for _, edbInfo := range edbInfoList {
  1909. findIdMap[edbInfo.EdbInfoId] = edbInfo.EdbInfoId
  1910. //edbInfoRuleMap[edbInfoId] = getEdbRuleTitle(edbInfo)
  1911. traceEdbInfo := data_manage.TraceEdbInfoResp{
  1912. //EdbInfoId: edbInfo.EdbInfoId,
  1913. EdbInfoId: edbInfo.EdbInfoId,
  1914. EdbInfoType: edbInfo.EdbInfoType,
  1915. EdbName: edbInfo.EdbName,
  1916. EdbNameEn: edbInfo.EdbNameEn,
  1917. EdbType: edbInfo.EdbType,
  1918. //Source: edbInfo.Source,
  1919. UniqueCode: edbInfo.UniqueCode,
  1920. ClassifyId: edbInfo.ClassifyId,
  1921. IsStop: edbInfo.NoUpdate,
  1922. EdbInfo: edbInfo,
  1923. }
  1924. traceEdbInfo.Child, err = traceEdbInfoByEdbInfoId(edbInfo.EdbInfoId, traceEdbInfo, edbInfoRuleMap, findIdMap, existMap, edbMappingMap)
  1925. traceEdbInfoList = append(traceEdbInfoList, traceEdbInfo)
  1926. }
  1927. //findEdbInfoIdList := make([]int, 0)
  1928. //for _, v := range findIdMap {
  1929. // findEdbInfoIdList = append(findEdbInfoIdList, v)
  1930. //}
  1931. //findEdbInfoList, err := data_manage.GetEdbInfoByIdList(findEdbInfoIdList)
  1932. //if err != nil {
  1933. // return
  1934. //}
  1935. //edbInfoMap := make(map[int]*data_manage.EdbInfo)
  1936. //for _, tmpEdbInfo := range findEdbInfoList {
  1937. // edbInfoMap[tmpEdbInfo.EdbInfoId] = tmpEdbInfo
  1938. //}
  1939. //for k, traceEdbInfo := range traceEdbInfoList {
  1940. // traceEdbInfoList[k], err = handleTraceEdbInfo(traceEdbInfo, 0, edbInfoMap, edbMappingMap)
  1941. //}
  1942. return
  1943. }
  1944. // traceEdbInfoByEdbInfoId 指标追溯
  1945. func traceEdbInfoByEdbInfoId(edbInfoId int, traceEdbInfo data_manage.TraceEdbInfoResp, edbInfoRuleMap map[int]string, findIdMap map[int]int, existMap map[int]data_manage.TraceEdbInfoResp, edbMappingMap map[int][]*data_manage.EdbInfoCalculateMappingInfo) (child []data_manage.TraceEdbInfoResp, err error) {
  1946. traceEdbInfo, ok := existMap[edbInfoId]
  1947. if ok {
  1948. return
  1949. }
  1950. child = make([]data_manage.TraceEdbInfoResp, 0)
  1951. edbInfoMappingList, e := data_manage.GetEdbInfoCalculateMappingListByEdbInfoId(edbInfoId)
  1952. if e != nil {
  1953. err = fmt.Errorf("GetEdbInfoCalculateMappingListByEdbInfoId err: %s", e.Error())
  1954. return
  1955. }
  1956. // 指标信息map
  1957. edbInfoMap := make(map[int]*data_manage.EdbInfo)
  1958. if len(edbInfoMappingList) > 0 {
  1959. fromEdbInfoIdList := make([]int, 0)
  1960. for _, v := range edbInfoMappingList {
  1961. fromEdbInfoIdList = append(fromEdbInfoIdList, v.FromEdbInfoId)
  1962. }
  1963. edbInfoList, tmpErr := data_manage.GetEdbInfoByIdList(fromEdbInfoIdList)
  1964. if tmpErr != nil {
  1965. err = fmt.Errorf("traceEdbInfoByEdbInfoId GetEdbInfoByIdList err: %s", tmpErr.Error())
  1966. return
  1967. }
  1968. for _, v := range edbInfoList {
  1969. edbInfoMap[v.EdbInfoId] = v
  1970. }
  1971. }
  1972. edbMappingMap[edbInfoId] = edbInfoMappingList
  1973. for _, v := range edbInfoMappingList {
  1974. tmpEdbInfoId := v.FromEdbInfoId
  1975. tmpTraceEdbInfo := data_manage.TraceEdbInfoResp{
  1976. EdbInfoId: tmpEdbInfoId,
  1977. EdbInfoType: v.FromEdbInfoType,
  1978. EdbType: v.FromEdbType,
  1979. UniqueCode: v.FromUniqueCode,
  1980. ClassifyId: v.FromClassifyId,
  1981. IsStop: v.NoUpdate,
  1982. EdbInfo: edbInfoMap[v.FromEdbInfoId],
  1983. }
  1984. // 计算指标/预测指标继续溯源
  1985. if edbInfoId != v.FromEdbInfoId && (v.FromEdbType == 2 || v.FromEdbInfoType == 1) {
  1986. // 查过了就不查了
  1987. if _, ok2 := findIdMap[tmpEdbInfoId]; !ok2 {
  1988. tmpTraceEdbInfo.Child, e = traceEdbInfoByEdbInfoId(tmpEdbInfoId, tmpTraceEdbInfo, edbInfoRuleMap, findIdMap, existMap, edbMappingMap)
  1989. if e != nil {
  1990. err = fmt.Errorf("traceEdbInfoByEdbInfoId err: %s", e.Error())
  1991. return
  1992. }
  1993. }
  1994. }
  1995. child = append(child, tmpTraceEdbInfo)
  1996. findIdMap[tmpEdbInfoId] = tmpEdbInfoId
  1997. }
  1998. existMap[edbInfoId] = traceEdbInfo
  1999. return
  2000. }
  2001. func handleTraceEdbInfo(traceEdbInfoResp data_manage.TraceEdbInfoResp, parentEdbInfoId int, edbInfoMap map[int]*data_manage.EdbInfo, edbMappingMap map[int][]*data_manage.EdbInfoCalculateMappingInfo, edbInfoIdPermissionMap map[int]bool) (newTraceEdbInfoResp data_manage.TraceEdbInfoResp, err error) {
  2002. edbInfo, ok := edbInfoMap[traceEdbInfoResp.EdbInfoId]
  2003. if !ok {
  2004. err = errors.New("指标异常")
  2005. return
  2006. }
  2007. var parentEdbInfo *data_manage.EdbInfo
  2008. if parentEdbInfoId > 0 {
  2009. parentEdbInfo, ok = edbInfoMap[parentEdbInfoId]
  2010. if !ok {
  2011. err = errors.New("指标异常")
  2012. return
  2013. }
  2014. }
  2015. //traceEdbInfoResp.EdbName = edbInfo.EdbName
  2016. traceEdbInfoResp.EdbName, traceEdbInfoResp.EdbNameEn, traceEdbInfoResp.RuleTitle, traceEdbInfoResp.RuleTitleEn = getEdbRuleTitle(edbInfo, parentEdbInfo, traceEdbInfoResp.Child, edbInfoMap, edbMappingMap)
  2017. if traceEdbInfoResp.Child != nil && len(traceEdbInfoResp.Child) > 0 {
  2018. for k, v := range traceEdbInfoResp.Child {
  2019. traceEdbInfoResp.Child[k], err = handleTraceEdbInfo(v, traceEdbInfoResp.EdbInfoId, edbInfoMap, edbMappingMap, edbInfoIdPermissionMap)
  2020. if err != nil {
  2021. return
  2022. }
  2023. }
  2024. }
  2025. // 指标权限
  2026. traceEdbInfoResp.HaveOperaAuth, _ = edbInfoIdPermissionMap[traceEdbInfoResp.EdbInfoId]
  2027. newTraceEdbInfoResp = traceEdbInfoResp
  2028. return
  2029. }
  2030. // getEdbRule 获取规则名称
  2031. func getEdbRuleTitle(edbInfo, parentEdbInfo *data_manage.EdbInfo, childList []data_manage.TraceEdbInfoResp, edbInfoMap map[int]*data_manage.EdbInfo, edbMappingMap map[int][]*data_manage.EdbInfoCalculateMappingInfo) (edbName, edbNameEn, ruleTitle, ruleTitleEn string) {
  2032. edbName = edbInfo.EdbName
  2033. edbNameEn = edbInfo.EdbNameEn
  2034. ruleTitle = `来源于` + edbInfo.SourceName
  2035. ruleTitleEn = `Source From: ` + edbInfo.SourceName
  2036. if parentEdbInfo != nil {
  2037. edbMappingList, ok := edbMappingMap[parentEdbInfo.EdbInfoId]
  2038. if !ok {
  2039. edbMappingList = []*data_manage.EdbInfoCalculateMappingInfo{}
  2040. }
  2041. // 指标名称
  2042. switch parentEdbInfo.Source {
  2043. case utils.DATA_SOURCE_CALCULATE, utils.DATA_SOURCE_PREDICT_CALCULATE:
  2044. for _, v := range edbMappingList {
  2045. if v.FromEdbInfoId == edbInfo.EdbInfoId {
  2046. edbName = fmt.Sprintf("%s(%s)", edbInfo.EdbName, v.FromTag)
  2047. edbNameEn = fmt.Sprintf("%s(%s)", edbInfo.EdbNameEn, v.FromTag)
  2048. }
  2049. }
  2050. case utils.DATA_SOURCE_CALCULATE_ZJPJ, utils.DATA_SOURCE_PREDICT_CALCULATE_ZJPJ, utils.DATA_SOURCE_CALCULATE_LJZTBPJ, utils.DATA_SOURCE_PREDICT_CALCULATE_LJZTBPJ: // 直接拼接 ,累计值同比拼接
  2051. for _, v := range edbMappingList {
  2052. if v.FromEdbInfoId == edbInfo.EdbInfoId {
  2053. tmpName := ``
  2054. tmpNameEn := ``
  2055. if v.FromTag == `A` {
  2056. tmpName = `拼接日期前`
  2057. tmpNameEn = `Before Concatenation Date:`
  2058. } else if v.FromTag == `B` {
  2059. tmpName = `拼接日期后`
  2060. tmpNameEn = `After Concatenation Date:`
  2061. }
  2062. edbName = fmt.Sprintf("%s(%s)", edbInfo.EdbName, tmpName)
  2063. edbNameEn = fmt.Sprintf("%s(%s)", edbInfo.EdbNameEn, tmpNameEn)
  2064. }
  2065. }
  2066. case utils.DATA_SOURCE_CALCULATE_NHCC, utils.DATA_SOURCE_PREDICT_CALCULATE_NHCC: //计算指标(拟合残差)
  2067. for _, v := range edbMappingList {
  2068. //(需对上游指标+自变量,领先10天/因变量)
  2069. if v.FromEdbInfoId == edbInfo.EdbInfoId {
  2070. tmpName := ``
  2071. tmpNameEn := ``
  2072. if v.FromTag == `A` {
  2073. tmpName = fmt.Sprintf(`自变量,领先%d天`, v.MoveValue)
  2074. tmpNameEn = fmt.Sprintf(`Independent Variable, Lead %d Days:`, v.MoveValue)
  2075. } else if v.FromTag == `B` {
  2076. tmpName = `因变量`
  2077. tmpNameEn = `Dependent Variable`
  2078. }
  2079. edbName = fmt.Sprintf("%s(%s)", edbInfo.EdbName, tmpName)
  2080. edbNameEn = fmt.Sprintf("%s(%s)", edbInfo.EdbNameEn, tmpNameEn)
  2081. }
  2082. }
  2083. case utils.DATA_SOURCE_CALCULATE_CORRELATION: // 滚动相关性
  2084. for _, v := range edbMappingList {
  2085. if v.FromEdbInfoId == edbInfo.EdbInfoId {
  2086. edbName = fmt.Sprintf("%s(%s)", edbInfo.EdbName, v.FromTag)
  2087. edbNameEn = fmt.Sprintf("%s(%s)", edbInfo.EdbNameEn, v.FromTag)
  2088. }
  2089. }
  2090. }
  2091. }
  2092. if edbInfo.EdbType == 1 {
  2093. // 基础指标的话,直接返回来源名称
  2094. //ruleTitle = `来源于`+edbInfo.SourceName
  2095. return
  2096. }
  2097. // 规则
  2098. switch edbInfo.Source {
  2099. case utils.DATA_SOURCE_CALCULATE, utils.DATA_SOURCE_PREDICT_CALCULATE:
  2100. ruleTitle = formatCalculateFormula(edbInfo.CalculateFormula)
  2101. case utils.DATA_SOURCE_CALCULATE_LJZZY, utils.DATA_SOURCE_PREDICT_CALCULATE_LJZZY:
  2102. ruleTitle = `累计转月值计算`
  2103. ruleTitleEn = `Cumulative to Monthly Calculation`
  2104. case utils.DATA_SOURCE_CALCULATE_TBZ, utils.DATA_SOURCE_PREDICT_CALCULATE_TBZ:
  2105. ruleTitle = `同比值计算`
  2106. ruleTitleEn = `Year-on-Year Value Calculation`
  2107. case utils.DATA_SOURCE_CALCULATE_TCZ, utils.DATA_SOURCE_PREDICT_CALCULATE_TCZ:
  2108. ruleTitle = `同差值计算`
  2109. ruleTitleEn = `Yearly Difference Calculation`
  2110. case utils.DATA_SOURCE_CALCULATE_NSZYDPJJS, utils.DATA_SOURCE_PREDICT_CALCULATE_NSZYDPJJS:
  2111. ruleTitle = fmt.Sprintf("N数值移动均值计算(N=%s)", edbInfo.CalculateFormula)
  2112. ruleTitleEn = fmt.Sprintf("N-Value Moving Average Calculation(N=%s)", edbInfo.CalculateFormula)
  2113. case utils.DATA_SOURCE_CALCULATE_HBZ, utils.DATA_SOURCE_PREDICT_CALCULATE_HBZ:
  2114. ruleTitle = fmt.Sprintf("N数值环比值计算(N=%s)", edbInfo.CalculateFormula)
  2115. ruleTitleEn = fmt.Sprintf("N-Value Sequential Comparison Calculation(N=%s)", edbInfo.CalculateFormula)
  2116. case utils.DATA_SOURCE_CALCULATE_HCZ, utils.DATA_SOURCE_PREDICT_CALCULATE_HCZ:
  2117. ruleTitle = fmt.Sprintf("N数值环差值计算(N=%s)", edbInfo.CalculateFormula)
  2118. ruleTitleEn = fmt.Sprintf("N-Value Sequential Difference Calculation(N=%s)", edbInfo.CalculateFormula)
  2119. case utils.DATA_SOURCE_CALCULATE_TIME_SHIFT, utils.DATA_SOURCE_PREDICT_CALCULATE_TIME_SHIFT:
  2120. moveType := `领先`
  2121. moveTypeEn := `Lead`
  2122. if edbInfo.MoveType == 2 {
  2123. moveType = "滞后"
  2124. moveTypeEn = `Lag`
  2125. }
  2126. ruleTitle = fmt.Sprintf("时间移位计算(%s%s%s)", moveType, edbInfo.CalculateFormula, edbInfo.MoveFrequency)
  2127. ruleTitleEn = fmt.Sprintf("Time Shift Calculation(%s%s%s)", moveTypeEn, edbInfo.CalculateFormula, edbInfo.MoveFrequency)
  2128. case utils.DATA_SOURCE_CALCULATE_BP, utils.DATA_SOURCE_PREDICT_CALCULATE_BP: // 变频
  2129. childFrequency := ``
  2130. if len(childList) > 0 {
  2131. if childEdbInfo, ok := edbInfoMap[childList[0].EdbInfoId]; ok {
  2132. childFrequency = childEdbInfo.Frequency
  2133. }
  2134. }
  2135. ruleTitle = fmt.Sprintf("升频计算(%s转%s)", childFrequency, edbInfo.Frequency)
  2136. ruleTitleEn = fmt.Sprintf("Upsampling Calculation(%s转%s)", childFrequency, edbInfo.Frequency)
  2137. case utils.DATA_SOURCE_CALCULATE_ZJPJ, utils.DATA_SOURCE_PREDICT_CALCULATE_ZJPJ: // 直接拼接
  2138. ruleTitle = fmt.Sprintf("直接拼接计算(%s)", edbInfo.CalculateFormula)
  2139. ruleTitleEn = fmt.Sprintf("Direct Concatenation Calculation(%s)", edbInfo.CalculateFormula)
  2140. case utils.DATA_SOURCE_CALCULATE_LJZTBPJ, utils.DATA_SOURCE_PREDICT_CALCULATE_LJZTBPJ: // 累计值同比拼
  2141. ruleTitle = fmt.Sprintf("累计值同比值拼接计算(%s)", edbInfo.CalculateFormula)
  2142. ruleTitleEn = fmt.Sprintf("Cumulative Year-on-Year Concatenation Calculation(%s)", edbInfo.CalculateFormula)
  2143. case utils.DATA_SOURCE_PYTHON:
  2144. ruleTitle = `代码运算`
  2145. ruleTitleEn = `Code Computation`
  2146. case utils.DATA_SOURCE_CALCULATE_CJJX, utils.DATA_SOURCE_PREDICT_CALCULATE_CJJX:
  2147. ruleTitle = fmt.Sprintf("超季节性计算(N=%s,%s)", edbInfo.CalculateFormula, edbInfo.Calendar)
  2148. ruleTitleEn = fmt.Sprintf("Super Seasonality Calculation(N=%s,%s)", edbInfo.CalculateFormula, edbInfo.Calendar)
  2149. case utils.DATA_SOURCE_CALCULATE_NHCC, utils.DATA_SOURCE_PREDICT_CALCULATE_NHCC: //计算指标(拟合残差)
  2150. var startDate, endDate string
  2151. dateList := strings.Split(edbInfo.CalculateFormula, ",")
  2152. if len(dateList) == 2 {
  2153. startDate = dateList[0]
  2154. endDate = dateList[1]
  2155. }
  2156. ruleTitle = fmt.Sprintf("拟合残差计算(%s至%s)", startDate, endDate)
  2157. ruleTitleEn = fmt.Sprintf("Fit Residual Calculation(%s至%s)", startDate, endDate)
  2158. case utils.DATA_SOURCE_CALCULATE_ADJUST:
  2159. ruleTitle = `数据调整`
  2160. ruleTitleEn = `Data Adjustment`
  2161. case utils.DATA_SOURCE_CALCULATE_NH, utils.DATA_SOURCE_PREDICT_CALCULATE_NH:
  2162. ruleTitle = `年化计算`
  2163. ruleTitleEn = `Annualization Calculation`
  2164. case utils.DATA_SOURCE_CALCULATE_KSZS, utils.DATA_SOURCE_PREDICT_CALCULATE_KSZS: // 扩散指数->53
  2165. type KszsConfig struct {
  2166. DateType int `description:"扩散指标日期;1:全部指标日期并集;2:部分指标日期并集"`
  2167. CheckList []string `description:"选中的数据,A,B,C"`
  2168. }
  2169. var config KszsConfig
  2170. err := json.Unmarshal([]byte(edbInfo.CalculateFormula), &config)
  2171. if err != nil {
  2172. return
  2173. }
  2174. var startDate, endDate time.Time
  2175. childEdbInfoIdList := make([]int, 0)
  2176. if config.DateType == 1 {
  2177. for _, v := range childList {
  2178. childEdbInfoIdList = append(childEdbInfoIdList, v.EdbInfoId)
  2179. }
  2180. } else {
  2181. if parentEdbInfo != nil {
  2182. edbMappingList, ok := edbMappingMap[parentEdbInfo.EdbInfoId]
  2183. if !ok {
  2184. edbMappingList = []*data_manage.EdbInfoCalculateMappingInfo{}
  2185. }
  2186. tagMap := make(map[string]int)
  2187. for _, v := range edbMappingList {
  2188. tagMap[v.FromTag] = v.FromEdbInfoId
  2189. }
  2190. for _, v := range config.CheckList {
  2191. if tmpEdbInfoId, ok := tagMap[v]; ok {
  2192. childEdbInfoIdList = append(childEdbInfoIdList, tmpEdbInfoId)
  2193. }
  2194. }
  2195. }
  2196. }
  2197. for _, v := range childEdbInfoIdList {
  2198. if childEdbInfo, ok := edbInfoMap[v]; ok {
  2199. tmpStartDate, tmpErr := time.ParseInLocation(utils.FormatDate, childEdbInfo.StartDate, time.Local)
  2200. if tmpErr != nil {
  2201. return
  2202. }
  2203. if startDate.IsZero() || startDate.After(tmpStartDate) {
  2204. startDate = tmpStartDate
  2205. }
  2206. tmpEndDate, tmpErr := time.ParseInLocation(utils.FormatDate, childEdbInfo.EndDate, time.Local)
  2207. if tmpErr != nil {
  2208. return
  2209. }
  2210. if endDate.IsZero() || endDate.Before(tmpEndDate) {
  2211. endDate = tmpEndDate
  2212. }
  2213. }
  2214. }
  2215. ruleTitle = fmt.Sprintf("扩散指数计算(%s至%s)", startDate.Format(utils.FormatDate), endDate.Format(utils.FormatDate))
  2216. ruleTitleEn = fmt.Sprintf("Diffusion Index Calculation(%s to %s)", startDate.Format(utils.FormatDate), endDate.Format(utils.FormatDate))
  2217. case utils.DATA_SOURCE_STOCK_PLANT:
  2218. ruleTitle = `来源于装置分析`
  2219. ruleTitleEn = `Derived from Plant Analysis`
  2220. case utils.DATA_SOURCE_CALCULATE_CORRELATION:
  2221. type EdbCalculateFormula struct {
  2222. BaseCalculateValue int `description:"基础计算窗口"`
  2223. BaseCalculateUnit string `description:"基础计算频度"`
  2224. LeadValue int `description:"领先期数"`
  2225. LeadUnit string `description:"频度"`
  2226. CalculateValue int `description:"计算窗口"`
  2227. CalculateUnit string `description:"计算频度"`
  2228. }
  2229. var correlationConf EdbCalculateFormula
  2230. err := json.Unmarshal([]byte(edbInfo.CalculateFormula), &correlationConf)
  2231. if err != nil {
  2232. return
  2233. }
  2234. ruleTitle = fmt.Sprintf("滚动相关性(计算窗口%d%s,B领先A%d%s)", correlationConf.CalculateValue, correlationConf.CalculateUnit, correlationConf.LeadValue, correlationConf.LeadUnit)
  2235. ruleTitleEn = fmt.Sprintf("Rolling Correlation (Calculation Window %d%s, B Leads A %d%s)", correlationConf.CalculateValue, correlationConf.CalculateUnit, correlationConf.LeadValue, correlationConf.LeadUnit)
  2236. case utils.DATA_SOURCE_CALCULATE_JP, utils.DATA_SOURCE_PREDICT_CALCULATE_JP:
  2237. childFrequency := ``
  2238. if len(childList) > 0 {
  2239. if childEdbInfo, ok := edbInfoMap[childList[0].EdbInfoId]; ok {
  2240. childFrequency = childEdbInfo.Frequency
  2241. }
  2242. }
  2243. ruleTitle = fmt.Sprintf("降频计算(%s转%s,%s)", childFrequency, edbInfo.Frequency, edbInfo.CalculateFormula)
  2244. ruleTitleEn = fmt.Sprintf("Downsampling Calculation(%s to %s,%s)", childFrequency, edbInfo.Frequency, edbInfo.CalculateFormula)
  2245. case utils.DATA_SOURCE_CALCULATE_STANDARD_DEVIATION:
  2246. ruleTitle = fmt.Sprintf("标准差(滚动%s期)", edbInfo.CalculateFormula)
  2247. ruleTitleEn = fmt.Sprintf("Standard Deviation (Rolling %s Periods)", edbInfo.CalculateFormula)
  2248. case utils.DATA_SOURCE_CALCULATE_PERCENTILE, utils.DATA_SOURCE_PREDICT_CALCULATE_PERCENTILE:
  2249. type TempCalculate struct {
  2250. CalculateValue int `description:"计算窗口"`
  2251. CalculateUnit string `description:"计算频度"`
  2252. }
  2253. cf := TempCalculate{}
  2254. if e := json.Unmarshal([]byte(edbInfo.CalculateFormula), &cf); e != nil {
  2255. return
  2256. }
  2257. ruleTitle = fmt.Sprintf("百分位(时间长度%d%s)", cf.CalculateValue, cf.CalculateUnit)
  2258. ruleTitle = fmt.Sprintf("Percentile (Time Length %d%s)", cf.CalculateValue, cf.CalculateUnit)
  2259. case utils.DATA_SOURCE_CALCULATE_ZSXY, utils.DATA_SOURCE_PREDICT_CALCULATE_ZSXY:
  2260. ruleTitle = `指数修匀计算`
  2261. ruleTitle = `Index Smoothing Calculation`
  2262. }
  2263. return
  2264. }
  2265. func formatCalculateFormula(calculateFormula string) (ruleTitle string) {
  2266. var tmpCalculateFormula []map[string]string
  2267. if e := json.Unmarshal([]byte(calculateFormula), &tmpCalculateFormula); e != nil {
  2268. ruleTitle = "=" + calculateFormula
  2269. return
  2270. }
  2271. newCalculateFormula := make([]map[string]string, 0)
  2272. sort.Slice(tmpCalculateFormula, func(i, j int) bool {
  2273. return compareDates(tmpCalculateFormula[i]["d"], tmpCalculateFormula[j]["d"])
  2274. })
  2275. for i, entry := range tmpCalculateFormula {
  2276. if formula, ok := entry["f"]; ok {
  2277. singleFormula := make(map[string]string)
  2278. singleFormula["公式"] = formula
  2279. singleFormula["日期"] = determineDateRange(i, len(tmpCalculateFormula), tmpCalculateFormula)
  2280. newCalculateFormula = append(newCalculateFormula, singleFormula)
  2281. }
  2282. }
  2283. if b, e := json.Marshal(newCalculateFormula); e != nil {
  2284. ruleTitle = "=" + calculateFormula
  2285. } else {
  2286. ruleTitle = "=" + string(b)
  2287. }
  2288. return
  2289. }
  2290. // compareDates 日期比较 date1 < date2 --> true
  2291. func compareDates(date1, date2 string) bool {
  2292. if date1 == "" {
  2293. return true
  2294. }
  2295. if date2 == "" {
  2296. return false
  2297. }
  2298. date1Parsed, err := time.Parse(utils.FormatDate, date1)
  2299. if err != nil {
  2300. return false
  2301. }
  2302. date2Parsed, err := time.Parse(utils.FormatDate, date2)
  2303. if err != nil {
  2304. return false
  2305. }
  2306. return date1Parsed.Before(date2Parsed)
  2307. }
  2308. func determineDateRange(index, totalLength int, formulas []map[string]string) string {
  2309. if totalLength == 1 {
  2310. return "全部"
  2311. }
  2312. currentDate := formulas[index]["d"]
  2313. if index == 0 {
  2314. return formulas[totalLength-1]["d"] + "(含)之后"
  2315. }
  2316. if index == totalLength-1 {
  2317. return formulas[1]["d"] + "之前"
  2318. }
  2319. if index >= 1 && index < totalLength-1 {
  2320. return fmt.Sprintf("%s(含)——%s", currentDate, formulas[index+1]["d"])
  2321. }
  2322. return ""
  2323. }
  2324. // GetEdbChartAdminList
  2325. // @param source 来源 :1:手工数据指标 2:钢联化工数据库 3:ETA指标库 4:ETA预测指标 5:图库 6:ETA表格
  2326. func GetEdbChartAdminList(source int) (list []int, err error) {
  2327. switch source {
  2328. case 1: //手工数据指标
  2329. list, err = models.GetEdbInfoAdminList()
  2330. if err != nil {
  2331. return
  2332. }
  2333. case 2: //钢联化工数据库
  2334. list, err = data_manage.GetMysteelChemicalIndexAdminList()
  2335. if err != nil {
  2336. return
  2337. }
  2338. case 3: //ETA指标库
  2339. list, err = data_manage.GetEdbInfoAdminList(0)
  2340. if err != nil {
  2341. return
  2342. }
  2343. case 4: //ETA预测指标
  2344. list, err = data_manage.GetEdbInfoAdminList(1)
  2345. if err != nil {
  2346. return
  2347. }
  2348. case 5: //图库
  2349. list, err = data_manage.GetChartInfoAdminList()
  2350. if err != nil {
  2351. return
  2352. }
  2353. default:
  2354. return
  2355. }
  2356. return
  2357. }
  2358. // EdbInfoReplace 替换指标v2版本(更换时间:2022年01月05日15:33:42)
  2359. func EdbInfoReplace(oldEdbInfo, newEdbInfo *data_manage.EdbInfo, sysAdminId int, sysAdminRealName string) (replaceChartTotal, replaceCalculateTotal int, err error) {
  2360. defer func() {
  2361. if err != nil {
  2362. fmt.Println("ERR:", err.Error())
  2363. }
  2364. }()
  2365. // 替换关联表中的source_edb_info_id
  2366. relationEdbInfoIdList, replaceChartTotal, replaceCalculateTotal, err := data_manage.ReplaceChartEdb(oldEdbInfo, newEdbInfo)
  2367. if err != nil {
  2368. return
  2369. }
  2370. //加入到缓存队列中处理
  2371. go cache.AddReplaceEdbInfo(oldEdbInfo, newEdbInfo)
  2372. // 更新所有的关联指标
  2373. err, _ = EdbInfoRefreshAllFromBaseV3(relationEdbInfoIdList, true, true, true)
  2374. return
  2375. }
  2376. func GetTerminalFromBaseIndex(source int, edbCode string) (terminalCode string, sourceIndexName string, err error) {
  2377. tbName := GetBaseIndexTableName(source)
  2378. if tbName != "" {
  2379. var item data_manage.BaseIndexTerminalCode
  2380. item, err = data_manage.GetBaseIndexTerminalCode(edbCode, tbName)
  2381. if err != nil {
  2382. err = fmt.Errorf("查询数据源指标信息失败, Err: %s", err)
  2383. return
  2384. }
  2385. terminalCode = item.TerminalCode
  2386. sourceIndexName = item.IndexName
  2387. }
  2388. return
  2389. }
  2390. func GetBaseIndexTableName(source int) (tableName string) {
  2391. switch source {
  2392. case utils.DATA_SOURCE_YS:
  2393. tableName = "base_from_smm_index"
  2394. case utils.DATA_SOURCE_MYSTEEL_CHEMICAL:
  2395. tableName = "base_from_mysteel_chemical_index"
  2396. case utils.DATA_SOURCE_SCI:
  2397. tableName = "base_from_sci_index"
  2398. case utils.DATA_SOURCE_BAIINFO:
  2399. tableName = "base_from_baiinfo_index"
  2400. default:
  2401. }
  2402. return
  2403. }
  2404. // EdbInfoWsdAdd 添加指标到指标库
  2405. func EdbInfoWsdAdd(item *data_manage.EdbInfo) (edbInfo *data_manage.EdbInfo, err error, errMsg string, isSendEmail bool) {
  2406. isSendEmail = true
  2407. //判断指标名称是否存在
  2408. var condition string
  2409. var pars []interface{}
  2410. condition += " AND edb_name=? "
  2411. pars = append(pars, item.EdbName)
  2412. count, err := data_manage.GetEdbInfoCountByCondition(condition, pars)
  2413. if err != nil {
  2414. errMsg = "判断指标名称是否存在失败"
  2415. err = errors.New("判断指标名称是否存在失败,Err:" + err.Error())
  2416. return
  2417. }
  2418. if count > 0 {
  2419. errMsg = "指标名称已存在,请重新填写"
  2420. err = errors.New(errMsg)
  2421. isSendEmail = false
  2422. return
  2423. }
  2424. source := item.Source
  2425. edbInfo = new(data_manage.EdbInfo)
  2426. edbInfo.Source = source
  2427. sourceNameMap := map[int]string{
  2428. utils.DATA_SOURCE_THS: "同花顺",
  2429. utils.DATA_SOURCE_WIND: "wind",
  2430. utils.DATA_SOURCE_PB: "彭博",
  2431. utils.DATA_SOURCE_PB_FINANCE: "彭博财务",
  2432. utils.DATA_SOURCE_MANUAL: "手工数据",
  2433. utils.DATA_SOURCE_LZ: "隆众",
  2434. utils.DATA_SOURCE_YS: "SMM",
  2435. utils.DATA_SOURCE_GL: "钢联",
  2436. utils.DATA_SOURCE_ZZ: "郑商所",
  2437. utils.DATA_SOURCE_DL: "大商所",
  2438. utils.DATA_SOURCE_SH: "上期所",
  2439. utils.DATA_SOURCE_CFFEX: "中金所",
  2440. utils.DATA_SOURCE_SHFE: "上期能源",
  2441. utils.DATA_SOURCE_GIE: "欧洲天然气",
  2442. utils.DATA_SOURCE_LT: "路透",
  2443. utils.DATA_SOURCE_COAL: "中国煤炭市场网",
  2444. utils.DATA_SOURCE_GOOGLE_TRAVEL: "our world in data",
  2445. utils.DATA_SOURCE_MYSTEEL_CHEMICAL: "钢联",
  2446. utils.DATA_SOURCE_EIA_STEO: "EIA STEO报告",
  2447. utils.DATA_SOURCE_COM_TRADE: "UN",
  2448. utils.DATA_SOURCE_SCI: "SCI",
  2449. utils.DATA_SOURCE_BAIINFO: "BAIINFO",
  2450. utils.DATA_SOURCE_STOCK_PLANT: "存量装置",
  2451. utils.DATA_SOURCE_NATIONAL_STATISTICS: "国家统计局",
  2452. utils.DATA_SOURCE_FUBAO: "富宝数据",
  2453. }
  2454. sourceName, ok := sourceNameMap[source]
  2455. if !ok {
  2456. edbSource := data_manage.EdbSourceIdMap[source]
  2457. if edbSource != nil {
  2458. sourceName = edbSource.SourceName
  2459. }
  2460. if sourceName == "" {
  2461. errMsg = "指标来源异常"
  2462. err = errors.New(errMsg)
  2463. return
  2464. }
  2465. }
  2466. edbInfo.SourceName = sourceName
  2467. edbType := 1 //基础指标
  2468. if source == utils.DATA_SOURCE_STOCK_PLANT {
  2469. edbType = 2 //计算指标
  2470. }
  2471. //获取该层级下最大的排序数
  2472. maxSort, err := GetEdbClassifyMaxSort(item.ClassifyId, 0)
  2473. if err != nil {
  2474. errMsg = "获取失败"
  2475. err = errors.New("查询排序信息失败,Err:" + err.Error())
  2476. return
  2477. }
  2478. edbInfo.EdbCode = item.EdbCode
  2479. edbInfo.EdbName = item.EdbName
  2480. edbInfo.EdbNameSource = item.EdbName
  2481. edbInfo.EdbNameEn = item.EdbNameEn
  2482. edbInfo.Frequency = item.Frequency
  2483. edbInfo.Unit = item.Unit
  2484. edbInfo.UnitEn = item.UnitEn
  2485. edbInfo.ClassifyId = item.ClassifyId
  2486. edbInfo.SysUserId = item.SysUserId
  2487. edbInfo.SysUserRealName = item.SysUserRealName
  2488. edbInfo.CreateTime = time.Now()
  2489. edbInfo.ModifyTime = time.Now()
  2490. edbInfo.ServerUrl = item.ServerUrl
  2491. edbInfo.Sort = maxSort + 1
  2492. edbInfo.DataDateType = `交易日`
  2493. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  2494. edbInfo.UniqueCode = utils.MD5(utils.DATA_PREFIX + "_" + timestamp)
  2495. edbInfo.EdbType = edbType
  2496. edbInfo.SubSource = item.SubSource
  2497. edbInfo.SubSourceName = "日期序列"
  2498. edbInfo.IndicatorCode = item.IndicatorCode
  2499. edbInfo.StockCode = item.StockCode
  2500. edbInfo.TerminalCode = item.TerminalCode
  2501. edbInfo.Extra = item.Extra
  2502. edbInfoId, err := data_manage.AddEdbInfo(edbInfo)
  2503. if err != nil {
  2504. errMsg = "保存失败"
  2505. err = errors.New("保存失败,Err:" + err.Error())
  2506. return
  2507. }
  2508. edbInfo.EdbInfoId = int(edbInfoId)
  2509. //保存数据
  2510. err = data_manage.ModifyEdbInfoWindWsdDataStatus(source, item.SubSource, edbInfoId, item.EdbCode)
  2511. if err != nil {
  2512. errMsg = "保存失败"
  2513. err = errors.New("修改数据对应指标ID失败,Err:" + err.Error())
  2514. return
  2515. }
  2516. maxAndMinItem, _ := data_manage.GetEdbInfoWsdMaxAndMinInfo(source, item.SubSource, item.EdbCode)
  2517. if maxAndMinItem != nil {
  2518. err = data_manage.ModifyEdbInfoMaxAndMinInfo(int(edbInfoId), maxAndMinItem)
  2519. }
  2520. //添加es
  2521. AddOrEditEdbInfoToEs(int(edbInfoId))
  2522. return
  2523. }
  2524. // BatchRefreshEdbByEdbIds 批量刷新指标
  2525. func BatchRefreshEdbByEdbIds(edbIdList []int, redisKey string, refreshKeys []string) (syncing bool, err error) {
  2526. if len(edbIdList) <= 0 {
  2527. return
  2528. }
  2529. // 设置刷新缓存
  2530. if redisKey != `` {
  2531. // 设置最多10分钟缓存
  2532. utils.Rc.SetNX(redisKey, 1, time.Minute*10)
  2533. }
  2534. // 获取需要刷新的指标列表
  2535. newBaseEdbInfoArr, newBasePredictEdbInfoArr, newCalculateMap, newPredictCalculateMap, calculateArr, predictCalculateArr := getEdbInfoIdList(edbIdList)
  2536. // 需要刷新的指标数量
  2537. totalEdbInfo := len(newBaseEdbInfoArr) + len(calculateArr) + len(predictCalculateArr)
  2538. // 关联指标过多的时候, 异步刷新
  2539. if totalEdbInfo > 20 {
  2540. syncing = true
  2541. //go func() {
  2542. // defer func() {
  2543. // if err != nil {
  2544. // alarm_msg.SendAlarmMsg("BatchRefreshEdbByEdbIds, ErrMsg: "+err.Error(), 3)
  2545. // }
  2546. // }()
  2547. //
  2548. // err = edbInfoRefreshAll(false, newBaseEdbInfoArr, newBasePredictEdbInfoArr, newCalculateMap, newPredictCalculateMap, calculateArr, predictCalculateArr)
  2549. //
  2550. // if redisKey != `` {
  2551. // _ = utils.Rc.Delete(redisKey)
  2552. // }
  2553. // if len(refreshKeys) > 0 {
  2554. // for _, v := range refreshKeys {
  2555. // _ = utils.Rc.Delete(v)
  2556. // }
  2557. // }
  2558. //}()
  2559. // 加入队列刷新
  2560. var refreshItem EdbQueueRefreshReq
  2561. refreshItem.RefreshKey = redisKey
  2562. refreshItem.ItemRefreshKeys = refreshKeys
  2563. refreshItem.BaseEdbInfoArr = newBaseEdbInfoArr
  2564. refreshItem.BasePredictEdbInfoArr = newBasePredictEdbInfoArr
  2565. refreshItem.CalculateMap = newCalculateMap
  2566. refreshItem.PredictCalculateMap = newPredictCalculateMap
  2567. refreshItem.CalculateArr = calculateArr
  2568. refreshItem.PredictCalculateArr = predictCalculateArr
  2569. go PushEdb2Refresh(refreshItem)
  2570. return
  2571. }
  2572. // 同步刷新
  2573. err = edbInfoRefreshAll(false, newBaseEdbInfoArr, newBasePredictEdbInfoArr, newCalculateMap, newPredictCalculateMap, calculateArr, predictCalculateArr)
  2574. if redisKey != `` {
  2575. _ = utils.Rc.Delete(redisKey)
  2576. }
  2577. if len(refreshKeys) > 0 {
  2578. for _, v := range refreshKeys {
  2579. _ = utils.Rc.Delete(v)
  2580. }
  2581. }
  2582. return
  2583. }
  2584. // EdbInfoSmmApiAdd 添加指标到指标库
  2585. func EdbInfoSmmApiAdd(item *data_manage.EdbInfo) (edbInfo *data_manage.EdbInfo, err error, errMsg string, isSendEmail bool) {
  2586. isSendEmail = true
  2587. //判断指标名称是否存在
  2588. var condition string
  2589. var pars []interface{}
  2590. condition += " AND edb_name=? "
  2591. pars = append(pars, item.EdbName)
  2592. count, err := data_manage.GetEdbInfoCountByCondition(condition, pars)
  2593. if err != nil {
  2594. errMsg = "判断指标名称是否存在失败"
  2595. err = errors.New("判断指标名称是否存在失败,Err:" + err.Error())
  2596. return
  2597. }
  2598. if count > 0 {
  2599. errMsg = "指标名称已存在,请重新填写"
  2600. err = errors.New(errMsg)
  2601. isSendEmail = false
  2602. return
  2603. }
  2604. source := item.Source
  2605. edbInfo = new(data_manage.EdbInfo)
  2606. edbInfo.Source = source
  2607. sourceNameMap := map[int]string{
  2608. utils.DATA_SOURCE_THS: "同花顺",
  2609. utils.DATA_SOURCE_WIND: "wind",
  2610. utils.DATA_SOURCE_PB: "彭博",
  2611. utils.DATA_SOURCE_PB_FINANCE: "彭博财务",
  2612. utils.DATA_SOURCE_MANUAL: "手工数据",
  2613. utils.DATA_SOURCE_LZ: "隆众",
  2614. utils.DATA_SOURCE_YS: "SMM",
  2615. utils.DATA_SOURCE_GL: "钢联",
  2616. utils.DATA_SOURCE_ZZ: "郑商所",
  2617. utils.DATA_SOURCE_DL: "大商所",
  2618. utils.DATA_SOURCE_SH: "上期所",
  2619. utils.DATA_SOURCE_CFFEX: "中金所",
  2620. utils.DATA_SOURCE_SHFE: "上期能源",
  2621. utils.DATA_SOURCE_GIE: "欧洲天然气",
  2622. utils.DATA_SOURCE_LT: "路透",
  2623. utils.DATA_SOURCE_COAL: "中国煤炭市场网",
  2624. utils.DATA_SOURCE_GOOGLE_TRAVEL: "our world in data",
  2625. utils.DATA_SOURCE_MYSTEEL_CHEMICAL: "钢联",
  2626. utils.DATA_SOURCE_EIA_STEO: "EIA STEO报告",
  2627. utils.DATA_SOURCE_COM_TRADE: "UN",
  2628. utils.DATA_SOURCE_SCI: "SCI",
  2629. utils.DATA_SOURCE_BAIINFO: "BAIINFO",
  2630. utils.DATA_SOURCE_STOCK_PLANT: "存量装置",
  2631. utils.DATA_SOURCE_NATIONAL_STATISTICS: "国家统计局",
  2632. utils.DATA_SOURCE_FUBAO: "富宝数据",
  2633. }
  2634. sourceName, ok := sourceNameMap[source]
  2635. if !ok {
  2636. edbSource := data_manage.EdbSourceIdMap[source]
  2637. if edbSource != nil {
  2638. sourceName = edbSource.SourceName
  2639. }
  2640. if sourceName == "" {
  2641. errMsg = "指标来源异常"
  2642. err = errors.New(errMsg)
  2643. return
  2644. }
  2645. }
  2646. edbInfo.SourceName = sourceName
  2647. edbType := 1 //基础指标
  2648. if source == utils.DATA_SOURCE_STOCK_PLANT {
  2649. edbType = 2 //计算指标
  2650. }
  2651. //从缓存中获取
  2652. serverUrl := ``
  2653. if edbInfo.Source == utils.DATA_SOURCE_WIND {
  2654. windCacheKey := utils.CACHE_WIND_URL + ":" + item.EdbCode
  2655. serverUrl, _ = utils.Rc.RedisString(windCacheKey)
  2656. if serverUrl == `` {
  2657. if len(utils.Hz_Data_WIND_Url_List) >= 1 {
  2658. serverUrl = utils.Hz_Data_WIND_Url_List[len(utils.Hz_Data_WIND_Url_List)-1] //默认是最后一个服务器地址
  2659. }
  2660. }
  2661. }
  2662. //获取该层级下最大的排序数
  2663. maxSort, err := GetEdbClassifyMaxSort(item.ClassifyId, 0)
  2664. if err != nil {
  2665. errMsg = "获取失败"
  2666. err = errors.New("查询排序信息失败,Err:" + err.Error())
  2667. return
  2668. }
  2669. edbInfo.EdbCode = item.EdbCode
  2670. edbInfo.EdbName = item.EdbName
  2671. edbInfo.EdbNameSource = item.EdbName
  2672. edbInfo.Frequency = item.Frequency
  2673. edbInfo.Unit = item.Unit
  2674. edbInfo.ClassifyId = item.ClassifyId
  2675. edbInfo.SysUserId = item.SysUserId
  2676. edbInfo.SysUserRealName = item.SysUserRealName
  2677. edbInfo.CreateTime = time.Now()
  2678. edbInfo.ModifyTime = time.Now()
  2679. edbInfo.ServerUrl = serverUrl
  2680. edbInfo.Sort = maxSort + 1
  2681. edbInfo.DataDateType = `交易日`
  2682. timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
  2683. edbInfo.UniqueCode = utils.MD5(utils.DATA_PREFIX + "_" + timestamp)
  2684. edbInfo.EdbType = edbType
  2685. edbInfo.SubSource = item.SubSource
  2686. edbInfo.SubSourceName = ""
  2687. edbInfo.IndicatorCode = item.IndicatorCode
  2688. edbInfo.StockCode = item.StockCode
  2689. edbInfoId, err := data_manage.AddEdbInfo(edbInfo)
  2690. if err != nil {
  2691. errMsg = "保存失败"
  2692. err = errors.New("保存失败,Err:" + err.Error())
  2693. return
  2694. }
  2695. edbInfo.EdbInfoId = int(edbInfoId)
  2696. //保存数据
  2697. err = data_manage.ModifyEdbInfoWindWsdDataStatus(source, item.SubSource, edbInfoId, item.EdbCode)
  2698. if err != nil {
  2699. errMsg = "保存失败"
  2700. err = errors.New("修改数据对应指标ID失败,Err:" + err.Error())
  2701. return
  2702. }
  2703. maxAndMinItem, _ := data_manage.GetEdbInfoWsdMaxAndMinInfo(source, item.SubSource, item.EdbCode)
  2704. if maxAndMinItem != nil {
  2705. err = data_manage.ModifyEdbInfoMaxAndMinInfo(int(edbInfoId), maxAndMinItem)
  2706. }
  2707. //添加es
  2708. AddOrEditEdbInfoToEs(int(edbInfoId))
  2709. return
  2710. }
  2711. // GetEdbTerminal 获取终端信息
  2712. func GetEdbTerminal(source int, oldTerminalCode string) (edbTerminal *data_manage.EdbTerminal, err error) {
  2713. if source == utils.DATA_SOURCE_WIND && oldTerminalCode == "" {
  2714. tmpConfig := new(data_manage.EdbConfig)
  2715. tmpConfig, err = data_manage.GetConfigDetailByCode("wind_terminal_code")
  2716. if err != nil && err.Error() != utils.ErrNoRow() {
  2717. err = errors.New("获取配置的wind地址失败,err:" + err.Error())
  2718. return
  2719. }
  2720. err = nil
  2721. if tmpConfig != nil {
  2722. oldTerminalCode = tmpConfig.ConfigValue
  2723. //return
  2724. }
  2725. }
  2726. if oldTerminalCode != "" {
  2727. edbTerminal, err = data_manage.GetEdbTerminalByCode(oldTerminalCode)
  2728. if err != nil {
  2729. return
  2730. }
  2731. return
  2732. }
  2733. // 配置中没有的话,那么就从分组获取,
  2734. list, err := data_manage.GetEdbCountGroupByTerminal(source)
  2735. if err != nil {
  2736. return
  2737. }
  2738. //windUrlNum := 0
  2739. //获取对应的配置url
  2740. terminalNumMap := make(map[string]int)
  2741. for _, v := range list {
  2742. terminalNumMap[v.TerminalCode] = v.Total
  2743. }
  2744. terminalList, err := data_manage.GetEdbTerminalListBySource(source)
  2745. if err != nil {
  2746. return
  2747. }
  2748. if len(terminalList) == 0 {
  2749. err = errors.New("终端地址未配置")
  2750. return
  2751. }
  2752. num := 0
  2753. for _, v := range terminalList {
  2754. tmpNum := terminalNumMap[v.TerminalCode]
  2755. if edbTerminal == nil {
  2756. edbTerminal = v
  2757. num = tmpNum
  2758. } else if tmpNum < num {
  2759. edbTerminal = v
  2760. num = tmpNum
  2761. }
  2762. }
  2763. if edbTerminal == nil {
  2764. err = errors.New("获取配置的终端地址失败")
  2765. return
  2766. }
  2767. /*if edbTerminal != nil {
  2768. windUrl = edbTerminal.ServerUrl
  2769. terminalCode = edbTerminal.TerminalCode
  2770. }*/
  2771. return
  2772. }
  2773. func GetEdbTerminalCodeBySource(source int, edbCode, stockCode string) (terminalCode, serverUrl, sourceIndexName string, err error) {
  2774. var e error
  2775. if stockCode != "" {
  2776. terminalCodeCacheKey := utils.CACHE_EDB_TERMINAL_CODE_URL + stockCode
  2777. terminalCode, e = utils.Rc.RedisString(terminalCodeCacheKey)
  2778. if e != nil {
  2779. utils.FileLog.Info(fmt.Sprintf("从缓存中获取数据源终端信息失败, Err: %s", e))
  2780. }
  2781. terminalInfo, e := GetEdbTerminal(source, terminalCode)
  2782. if e != nil {
  2783. err = errors.New("获取可以使用的终端失败,Err:" + e.Error())
  2784. return
  2785. }
  2786. serverUrl = terminalInfo.ServerUrl
  2787. terminalCode = terminalInfo.TerminalCode
  2788. return
  2789. }
  2790. // 获取终端信息
  2791. terminalCodeCacheKey := utils.CACHE_EDB_TERMINAL_CODE_URL + edbCode
  2792. terminalCode, tE := utils.Rc.RedisString(terminalCodeCacheKey)
  2793. if tE != nil {
  2794. utils.FileLog.Info(fmt.Sprintf("从缓存中获取数据源终端信息失败, Err: %s", tE))
  2795. }
  2796. var terminalCodeOrigin string
  2797. terminalCodeOrigin, sourceIndexName, tE = GetTerminalFromBaseIndex(source, edbCode)
  2798. if tE != nil {
  2799. utils.FileLog.Info(fmt.Sprintf("获取数据源终端信息失败, Err: %s", tE))
  2800. }
  2801. if terminalCodeOrigin != "" {
  2802. terminalCode = terminalCodeOrigin
  2803. }
  2804. if source == utils.DATA_SOURCE_WIND || source == utils.DATA_SOURCE_THS {
  2805. terminalInfo, e := GetEdbTerminal(source, terminalCode)
  2806. if e != nil {
  2807. err = errors.New("获取可以使用的终端失败,Err:" + e.Error())
  2808. return
  2809. }
  2810. serverUrl = terminalInfo.ServerUrl
  2811. terminalCode = terminalInfo.TerminalCode
  2812. }
  2813. return
  2814. }
  2815. // handleByAddEdbInfo
  2816. // @Description: 添加指标后的处理操作
  2817. // @author: Roc
  2818. // @datetime 2024-07-22 13:06:36
  2819. // @param edbInfo *data_manage.EdbInfo
  2820. func handleByAddEdbInfo(edbInfo *data_manage.EdbInfo) {
  2821. // 更新钢联化工状态为启用
  2822. if edbInfo.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
  2823. // 启动钢联的刷新
  2824. _ = data_manage.UpdateMysteelChemicalRefreshStatus(edbInfo.EdbCode, 0)
  2825. }
  2826. // 如果是手工数据,那么需要标记手工数据为已加入指标库
  2827. if edbInfo.Source == utils.DATA_SOURCE_MANUAL {
  2828. _ = models.UpdateManualIsJoinEdbStatus(edbInfo.EdbCode, 1)
  2829. }
  2830. }
  2831. // handleByDelEdbInfo
  2832. // @Description: 删除指标后的处理操作
  2833. // @author: Roc
  2834. // @datetime 2024-07-22 13:06:36
  2835. // @param edbInfo *data_manage.EdbInfo
  2836. func handleByDelEdbInfo(edbInfo *data_manage.EdbInfo) {
  2837. // 如果删除的指标是自定义分析的来源,那么还需要删除指标与excel的关系
  2838. if edbInfo.Source == utils.DATA_SOURCE_CALCULATE_ZDYFX {
  2839. err := excel.DeleteCustomAnalysisExcelEdbMappingByEdbInfoId(edbInfo.EdbInfoId)
  2840. if err != nil {
  2841. utils.FileLog.Error(fmt.Sprintf("删除指标时,需要删除与自定义分析的关系失败,指标ID:%d,Err:%s", edbInfo.EdbInfoId, err.Error()), 3)
  2842. }
  2843. }
  2844. // 如果是手工数据,那么需要标记手工数据为未加入指标库
  2845. if edbInfo.Source == utils.DATA_SOURCE_MANUAL {
  2846. _ = models.UpdateManualIsJoinEdbStatus(edbInfo.EdbCode, 0)
  2847. }
  2848. if edbInfo.EdbInfoType == utils.PREDICT_EDB_INFO_TYPE && edbInfo.EdbType == 1 {
  2849. // 删除图表中的指标引用
  2850. _ = data_manage.DeleteEdbRelationByObjectId(edbInfo.EdbInfoId, utils.EDB_RELATION_PREDICT_EDB)
  2851. }
  2852. }
  2853. func EditBaseEdbInfo(req data_manage.EditEdbInfoReq, sysUser *system.Admin, lang, requestBody, uri string) (isSendEmail bool, err error, errMsg string) {
  2854. isSendEmail = true
  2855. edbInfo, err := data_manage.GetEdbInfoById(req.EdbInfoId)
  2856. if err != nil {
  2857. errMsg = "修改失败"
  2858. err = fmt.Errorf("获取指标信息失败,Err:" + err.Error())
  2859. return
  2860. }
  2861. // 记录旧的指标基本信息
  2862. oldEdbName := edbInfo.EdbName
  2863. oldFrequency := edbInfo.Frequency
  2864. oldUnit := edbInfo.Unit
  2865. var haveOperaAuth bool
  2866. // 权限校验
  2867. {
  2868. haveOperaAuth, err = data_manage_permission.CheckEdbPermissionByEdbInfoId(edbInfo.EdbInfoId, edbInfo.ClassifyId, edbInfo.IsJoinPermission, sysUser.AdminId)
  2869. if err != nil {
  2870. errMsg = err.Error()
  2871. err = fmt.Errorf("校验指标权限失败,err:" + err.Error())
  2872. return
  2873. }
  2874. }
  2875. // 编辑权限校验
  2876. button := GetEdbOpButton(sysUser, edbInfo.SysUserId, edbInfo.EdbType, edbInfo.EdbInfoType, haveOperaAuth)
  2877. if !button.OpButton {
  2878. errMsg = "无权限操作"
  2879. isSendEmail = false
  2880. return
  2881. }
  2882. //判断指标名称是否存在
  2883. var condition string
  2884. var pars []interface{}
  2885. condition += " AND edb_info_id<>? "
  2886. pars = append(pars, req.EdbInfoId)
  2887. //condition += " AND source=? "
  2888. //pars = append(pars, edbInfo.Source)
  2889. updateCols := make([]string, 0)
  2890. switch lang {
  2891. case utils.EnLangVersion:
  2892. condition += " AND edb_name_en = ? "
  2893. edbInfo.EdbNameEn = req.EdbName
  2894. edbInfo.Frequency = req.Frequency
  2895. edbInfo.UnitEn = req.Unit
  2896. edbInfo.ClassifyId = req.ClassifyId
  2897. updateCols = append(updateCols, "EdbNameEn", "Frequency", "UnitEn", "ClassifyId")
  2898. default:
  2899. condition += " AND edb_name=? "
  2900. edbInfo.EdbName = req.EdbName
  2901. edbInfo.EdbNameSource = req.EdbName
  2902. edbInfo.Frequency = req.Frequency
  2903. edbInfo.Unit = req.Unit
  2904. edbInfo.ClassifyId = req.ClassifyId
  2905. updateCols = append(updateCols, "EdbName", "EdbNameSource", "Frequency", "Unit", "ClassifyId")
  2906. }
  2907. pars = append(pars, req.EdbName)
  2908. count, err := data_manage.GetEdbInfoCountByCondition(condition, pars)
  2909. if err != nil {
  2910. errMsg = "判断指标名称是否存在失败"
  2911. err = fmt.Errorf("判断指标名称是否存在失败,Err:" + err.Error())
  2912. return
  2913. }
  2914. if count > 0 {
  2915. errMsg = "指标名称已存在,请重新填写"
  2916. err = fmt.Errorf("指标名称已存在,请重新填写")
  2917. isSendEmail = false
  2918. return
  2919. }
  2920. if len(updateCols) > 0 {
  2921. err = edbInfo.Update(updateCols)
  2922. if err != nil {
  2923. errMsg = "保存失败"
  2924. err = fmt.Errorf("修改失败,Err:" + err.Error())
  2925. return
  2926. }
  2927. }
  2928. // 新增保存记录日志
  2929. oldEdbInfo := new(data_manage.EdbInfo)
  2930. oldEdbInfo.EdbInfoId = edbInfo.EdbInfoId
  2931. oldEdbInfo.EdbName = oldEdbName
  2932. oldEdbInfo.Frequency = oldFrequency
  2933. oldEdbInfo.Unit = oldUnit
  2934. newEdbInfoRecord := new(data_manage.EdbInfoEditRecord)
  2935. newEdbInfoRecord.EdbName = req.EdbName
  2936. newEdbInfoRecord.Frequency = req.Frequency
  2937. newEdbInfoRecord.Unit = req.Unit
  2938. newEdbInfoRecord.OperateUserId = sysUser.AdminId
  2939. newEdbInfoRecord.OperateUserRealName = sysUser.RealName
  2940. go AddEditEdbInfoRcord(oldEdbInfo, newEdbInfoRecord)
  2941. //新增操作日志
  2942. {
  2943. edbLog := new(data_manage.EdbInfoLog)
  2944. edbLog.EdbInfoId = edbInfo.EdbInfoId
  2945. edbLog.SourceName = edbInfo.SourceName
  2946. edbLog.Source = edbInfo.Source
  2947. edbLog.EdbCode = edbInfo.EdbCode
  2948. edbLog.EdbName = edbInfo.EdbName
  2949. edbLog.ClassifyId = edbInfo.ClassifyId
  2950. edbLog.SysUserId = sysUser.AdminId
  2951. edbLog.SysUserRealName = sysUser.RealName
  2952. edbLog.CreateTime = time.Now()
  2953. edbLog.Content = requestBody
  2954. edbLog.Status = "编辑指标"
  2955. edbLog.Method = uri
  2956. go data_manage.AddEdbInfoLog(edbLog)
  2957. }
  2958. //添加es
  2959. AddOrEditEdbInfoToEs(req.EdbInfoId)
  2960. switch lang {
  2961. case utils.EnLangVersion:
  2962. // 修改关联的预测指标基础信息
  2963. go ModifyPredictEdbEnBaseInfoBySourceEdb(edbInfo, req.Unit)
  2964. default:
  2965. // 修改关联的预测指标基础信息
  2966. go ModifyPredictEdbBaseInfoBySourceEdb(edbInfo, req.Frequency, req.Unit)
  2967. }
  2968. return
  2969. }
  2970. // GetIsSupplierStop
  2971. // @Description: 获取是否供应商停更
  2972. // @author: Roc
  2973. // @datetime 2024-08-27 10:28:19
  2974. // @param source int
  2975. // @param edbCode string
  2976. // @return isSupplierStop int
  2977. func GetIsSupplierStop(source int, edbCode string) (isSupplierStop int) {
  2978. switch source {
  2979. case utils.DATA_SOURCE_MYSTEEL_CHEMICAL:
  2980. item, err := data_manage.GetBaseFromMysteelChemicalIndexByCode(edbCode)
  2981. if err != nil {
  2982. return
  2983. }
  2984. isSupplierStop = item.IsSupplierStop
  2985. }
  2986. return
  2987. }
  2988. // GetMySteelSourceByEdbCode
  2989. // @Description: 根据钢联的指标编码,获取该数据应该从哪个数据源查询
  2990. // @author: Roc
  2991. // @datetime 2024-09-10 13:25:07
  2992. // @param edbCode string
  2993. // @return source int
  2994. // @return item *data_manage.EdbInfo
  2995. // @return err error
  2996. func GetMySteelSourceByEdbCode(edbCode string) (source int, item *data_manage.EdbInfo, err error) {
  2997. // 先判断在指标库的“上海钢联”中是否存在,存在就直接返回
  2998. source = utils.DATA_SOURCE_MYSTEEL_CHEMICAL
  2999. item, err = data_manage.GetEdbInfoByEdbCode(utils.DATA_SOURCE_MYSTEEL_CHEMICAL, edbCode)
  3000. if err != nil {
  3001. if err.Error() != utils.ErrNoRow() {
  3002. return
  3003. }
  3004. err = nil
  3005. }
  3006. if item != nil {
  3007. source = utils.DATA_SOURCE_MYSTEEL_CHEMICAL
  3008. return
  3009. }
  3010. // 再判断在指标库的“钢联原始”中是否存在,存在就直接返回
  3011. item, err = data_manage.GetEdbInfoByEdbCode(utils.DATA_SOURCE_GL, edbCode)
  3012. if err != nil {
  3013. if err.Error() != utils.ErrNoRow() {
  3014. return
  3015. }
  3016. err = nil
  3017. }
  3018. if item != nil {
  3019. source = utils.DATA_SOURCE_GL
  3020. return
  3021. }
  3022. // 再没有就判断下是否处于 《上海钢联》 数据源里面
  3023. {
  3024. tmpInfo, tmpErr := data_manage.GetBaseFromMysteelChemicalIndexByCode(edbCode)
  3025. if tmpErr != nil {
  3026. if tmpErr.Error() != utils.ErrNoRow() {
  3027. err = tmpErr
  3028. return
  3029. }
  3030. }
  3031. if tmpInfo != nil {
  3032. source = utils.DATA_SOURCE_MYSTEEL_CHEMICAL
  3033. return
  3034. }
  3035. }
  3036. // 再没有就判断下是否处于 《钢联原始》 数据源里面
  3037. {
  3038. tmpInfo, tmpErr := data_manage.GetGlIndexByCode(edbCode)
  3039. if tmpErr != nil {
  3040. if tmpErr.Error() != utils.ErrNoRow() {
  3041. err = tmpErr
  3042. return
  3043. }
  3044. }
  3045. if tmpInfo != nil {
  3046. source = utils.DATA_SOURCE_GL
  3047. return
  3048. }
  3049. }
  3050. return
  3051. }