edb_info.go 99 KB

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