edb_info.go 101 KB

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