12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939 |
- package data
- import (
- "encoding/json"
- "errors"
- "fmt"
- "hongze/hz_crm_api/models"
- "hongze/hz_crm_api/models/data_manage"
- "hongze/hz_crm_api/models/system"
- "hongze/hz_crm_api/services/alarm_msg"
- "hongze/hz_crm_api/services/elastic"
- "hongze/hz_crm_api/utils"
- "sort"
- "strconv"
- "strings"
- "time"
- )
- // EdbInfoRefreshAllFromBaseV2 全部刷新指标(切换到edb_lib服务)
- func EdbInfoRefreshAllFromBaseV2(edbInfoId int, refreshAll bool) (err error) {
- var errmsg string
- defer func() {
- if err != nil {
- fmt.Println("EdbInfoRefreshAllFromBaseV2 Err:" + err.Error() + ";errmsg:" + errmsg)
- go alarm_msg.SendAlarmMsg("EdbInfoRefreshFromBaseV2,Err"+err.Error()+";errMsg:"+errmsg, 3)
- //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "EdbInfoRefreshFromBase:"+errmsg, utils.EmailSendToUsers)
- }
- }()
- err = EdbInfoRefreshAllFromBaseV3([]int{edbInfoId}, refreshAll)
- return
- //// 获取关联的基础指标
- //newBaseEdbInfoArr, newCalculateMap, newPredictCalculateMap, calculateArr, predictCalculateArr, err, errmsg := getRefreshEdbInfoList(edbInfoId)
- //if err != nil {
- // return
- //}
- //
- //var startDate string
- //for _, bv := range newBaseEdbInfoArr {
- // //source := bv.Source
- // //edbInfoId := bv.EdbInfoId
- // //edbCode := bv.EdbCode
- // if bv.StartDate == "0000-00-00" {
- // continue
- // }
- // //开始时间
- // startDate = ``
- // if refreshAll { //刷新所有数据,用开始时间作为起始日期去刷新
- // sTime, err := time.Parse(utils.FormatDate, bv.StartDate)
- // if err != nil {
- // return err
- // }
- // startDate = sTime.Format(utils.FormatDate)
- // } else {
- // sTime, err := time.Parse(utils.FormatDate, bv.EndDate)
- // if err != nil {
- // return err
- // }
- // frequency := bv.Frequency
- // var limitDay int
- // switch frequency {
- // case "日度":
- // limitDay = utils.DATA_START_REFRESH_LIMIT
- // case "周度":
- // limitDay = utils.DATA_START_REFRESH_LIMIT * 7
- // case "月度":
- // limitDay = utils.DATA_START_REFRESH_LIMIT * 30
- // case "季度":
- // limitDay = utils.DATA_START_REFRESH_LIMIT * 90
- // case "年度":
- // limitDay = utils.DATA_START_REFRESH_LIMIT * 365
- // default:
- // limitDay = utils.DATA_START_REFRESH_LIMIT
- // }
- // startDate = sTime.AddDate(0, 0, -limitDay).Format(utils.FormatDate)
- // }
- // result, err := RefreshEdbData(bv.EdbInfoId, bv.Source, bv.EdbCode, startDate)
- // if err != nil {
- // fmt.Println(bv.EdbInfoId, "RefreshBaseEdbData err", time.Now())
- // errmsg = "RefreshBaseEdbData Err:" + err.Error()
- // return err
- // }
- // if result.Ret != 200 {
- // fmt.Println(bv.EdbInfoId, "RefreshBaseEdbData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
- // errmsg = fmt.Sprint(bv.EdbInfoId, "RefreshBaseEdbData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
- // return fmt.Errorf("刷新失败, err:", errmsg)
- // }
- //
- // //maxAndMinItem, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
- // //if err != nil {
- // // if err.Error() == utils.ErrNoRow() { //找不到数据,那么就进入到下一条数据做处理
- // // continue
- // // }
- // // return err
- // //}
- // //if maxAndMinItem != nil {
- // // err = data_manage.ModifyEdbInfoMaxAndMinInfo(edbInfoId, maxAndMinItem)
- // // if err != nil {
- // // return err
- // // }
- // //}
- // fmt.Println("end newBaseEdbInfoArr:", bv, time.Now())
- //}
- //
- ////刷新相关普通计算指标
- //for _, v := range calculateArr {
- // edbInfo := newCalculateMap[v]
- // if edbInfo == nil {
- // return err
- // }
- // startDate = edbInfo.StartDate
- // source := edbInfo.Source
- // if startDate == "" || startDate == "0000-00-00" { //如果没有开始日期,说明还没有计算出来数据,那么就往前面推40年吧(也意味着重新计算了)
- // startDate = time.Now().AddDate(-40, 0, 0).Format(utils.FormatDate)
- // } else {
- // if source == utils.DATA_SOURCE_CALCULATE {
- // startDate = ``
- // if refreshAll { //刷新所有数据,用开始时间作为起始日期去刷新
- // startDate = edbInfo.StartDate
- // } else {
- // sTime, err := time.Parse(utils.FormatDate, edbInfo.EndDate)
- // if err != nil {
- // return err
- // }
- // frequency := edbInfo.Frequency
- // var limitDay int
- // switch frequency {
- // case "日度":
- // limitDay = utils.DATA_START_REFRESH_LIMIT
- // case "周度":
- // limitDay = utils.DATA_START_REFRESH_LIMIT * 7
- // case "月度":
- // limitDay = utils.DATA_START_REFRESH_LIMIT * 30
- // case "季度":
- // limitDay = utils.DATA_START_REFRESH_LIMIT * 90
- // case "年度":
- // limitDay = utils.DATA_START_REFRESH_LIMIT * 365
- // default:
- // limitDay = utils.DATA_START_REFRESH_LIMIT
- // }
- // startDate = sTime.AddDate(0, 0, -limitDay).Format(utils.FormatDate)
- // }
- // }
- // }
- //
- // result, err := RefreshEdbCalculateData(edbInfo.EdbInfoId, edbInfo.EdbCode, startDate)
- // if err != nil {
- // fmt.Println(v, "RefreshEdbCalculateData err", time.Now())
- // errmsg = "RefreshEdbCalculateData Err:" + err.Error()
- // return err
- // }
- // if result.Ret != 200 {
- // fmt.Println(v, "RefreshEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
- // errmsg = fmt.Sprint(v, "RefreshEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
- // return fmt.Errorf("刷新失败")
- // }
- //}
- //
- ////刷新相关预测计算指标
- //for _, v := range predictCalculateArr {
- // edbInfo := newPredictCalculateMap[v]
- // if edbInfo == nil {
- // return err
- // }
- // startDate = edbInfo.StartDate
- // source := edbInfo.Source
- // if startDate == "" || startDate == "0000-00-00" { //如果没有开始日期,说明还没有计算出来数据,那么就往前面推40年吧(也意味着重新计算了)
- // startDate = time.Now().AddDate(-40, 0, 0).Format(utils.FormatDate)
- // } else {
- // if source == utils.DATA_SOURCE_PREDICT_CALCULATE {
- // startDate = ``
- // if refreshAll { //刷新所有数据,用开始时间作为起始日期去刷新
- // startDate = edbInfo.StartDate
- // } else {
- // sTime, err := time.Parse(utils.FormatDate, edbInfo.EndDate)
- // if err != nil {
- // return err
- // }
- // frequency := edbInfo.Frequency
- // var limitDay int
- // switch frequency {
- // case "日度":
- // limitDay = utils.DATA_START_REFRESH_LIMIT
- // case "周度":
- // limitDay = utils.DATA_START_REFRESH_LIMIT * 7
- // case "月度":
- // limitDay = utils.DATA_START_REFRESH_LIMIT * 30
- // case "季度":
- // limitDay = utils.DATA_START_REFRESH_LIMIT * 90
- // case "年度":
- // limitDay = utils.DATA_START_REFRESH_LIMIT * 365
- // default:
- // limitDay = utils.DATA_START_REFRESH_LIMIT
- // }
- // startDate = sTime.AddDate(0, 0, -limitDay).Format(utils.FormatDate)
- // }
- // }
- // }
- //
- // result, err := RefreshPredictEdbCalculateData(edbInfo.EdbInfoId, edbInfo.EdbCode, startDate)
- // if err != nil {
- // fmt.Println(v, "RefreshEdbCalculateData err", time.Now())
- // errmsg = "RefreshEdbCalculateData Err:" + err.Error()
- // return err
- // }
- // if result.Ret != 200 {
- // fmt.Println(v, "RefreshEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
- // errmsg = fmt.Sprint(v, "RefreshEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
- // return fmt.Errorf("刷新失败")
- // }
- //}
- //return err
- }
- // EdbInfoRefreshAllFromBaseV3 全部刷新指标(切换到edb_lib服务)
- // @author Roc
- // @datetime 2022-09-16 11:04:44
- // @description 将原有的单个指标刷新,调整为批量多个指标刷新
- func EdbInfoRefreshAllFromBaseV3(edbInfoIdList []int, refreshAll bool) (err error) {
- var errmsg string
- defer func() {
- if err != nil {
- fmt.Println("EdbInfoRefreshAllFromBaseV2 Err:" + err.Error() + ";errmsg:" + errmsg)
- go alarm_msg.SendAlarmMsg("EdbInfoRefreshFromBaseV2,Err"+err.Error()+";errMsg:"+errmsg, 3)
- //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "EdbInfoRefreshFromBase:"+errmsg, utils.EmailSendToUsers)
- }
- }()
- // 获取关联的基础指标
- newBaseEdbInfoArr, newBasePredictEdbInfoArr, newCalculateMap, newPredictCalculateMap, calculateArr, predictCalculateArr, err, errmsg := getRefreshEdbInfoListByIds(edbInfoIdList)
- if err != nil {
- return
- }
- var startDate string
- for _, bv := range newBaseEdbInfoArr {
- //source := bv.Source
- //edbInfoId := bv.EdbInfoId
- //edbCode := bv.EdbCode
- if bv.StartDate == "0000-00-00" {
- continue
- }
- //开始时间
- startDate = ``
- if refreshAll { //刷新所有数据,用开始时间作为起始日期去刷新
- sTime, err := time.Parse(utils.FormatDate, bv.StartDate)
- if err != nil {
- return err
- }
- startDate = sTime.Format(utils.FormatDate)
- } else {
- sTime, err := time.Parse(utils.FormatDate, bv.EndDate)
- if err != nil {
- return err
- }
- frequency := bv.Frequency
- var limitDay int
- switch frequency {
- case "日度":
- limitDay = utils.DATA_START_REFRESH_LIMIT
- case "周度":
- limitDay = utils.DATA_START_REFRESH_LIMIT * 7
- case "月度":
- limitDay = utils.DATA_START_REFRESH_LIMIT * 30
- case "季度":
- limitDay = utils.DATA_START_REFRESH_LIMIT * 90
- case "年度":
- limitDay = utils.DATA_START_REFRESH_LIMIT * 365
- default:
- limitDay = utils.DATA_START_REFRESH_LIMIT
- }
- startDate = sTime.AddDate(0, 0, -limitDay).Format(utils.FormatDate)
- }
- result, err := RefreshEdbData(bv.EdbInfoId, bv.Source, bv.EdbCode, startDate)
- if err != nil {
- fmt.Println(bv.EdbInfoId, "RefreshBaseEdbData err", time.Now())
- errmsg = "RefreshBaseEdbData Err:" + err.Error()
- return err
- }
- if result.Ret != 200 {
- fmt.Println(bv.EdbInfoId, "RefreshBaseEdbData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
- errmsg = fmt.Sprint(bv.EdbInfoId, "RefreshBaseEdbData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
- return fmt.Errorf("刷新失败, err:", errmsg)
- }
- //maxAndMinItem, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
- //if err != nil {
- // if err.Error() == utils.ErrNoRow() { //找不到数据,那么就进入到下一条数据做处理
- // continue
- // }
- // return err
- //}
- //if maxAndMinItem != nil {
- // err = data_manage.ModifyEdbInfoMaxAndMinInfo(edbInfoId, maxAndMinItem)
- // if err != nil {
- // return err
- // }
- //}
- fmt.Println("end newBaseEdbInfoArr:", bv, time.Now())
- }
- //刷新相关普通计算指标
- for _, v := range calculateArr {
- edbInfo := newCalculateMap[v]
- if edbInfo == nil {
- return err
- }
- //计算指标就不用开始时间了吧,因为存在说开始时间变更的情况
- startDate = ``
- if !refreshAll { //如果不是全部更新,那么以指标的开始时间作为刷新
- startDate = edbInfo.StartDate
- source := edbInfo.Source
- if startDate == "" || startDate == "0000-00-00" { //如果没有开始日期,说明还没有计算出来数据,那么就往前面推40年吧(也意味着重新计算了)
- startDate = time.Now().AddDate(-40, 0, 0).Format(utils.FormatDate)
- } else {
- if source == utils.DATA_SOURCE_CALCULATE {
- sTime, err := time.Parse(utils.FormatDate, edbInfo.EndDate)
- if err != nil {
- return err
- }
- frequency := edbInfo.Frequency
- var limitDay int
- switch frequency {
- case "日度":
- limitDay = utils.DATA_START_REFRESH_LIMIT
- case "周度":
- limitDay = utils.DATA_START_REFRESH_LIMIT * 7
- case "月度":
- limitDay = utils.DATA_START_REFRESH_LIMIT * 30
- case "季度":
- limitDay = utils.DATA_START_REFRESH_LIMIT * 90
- case "年度":
- limitDay = utils.DATA_START_REFRESH_LIMIT * 365
- default:
- limitDay = utils.DATA_START_REFRESH_LIMIT
- }
- startDate = sTime.AddDate(0, 0, -limitDay).Format(utils.FormatDate)
- }
- }
- }
- result, err := RefreshEdbCalculateData(edbInfo.EdbInfoId, edbInfo.EdbCode, startDate)
- if err != nil {
- fmt.Println(v, "RefreshEdbCalculateData err", time.Now())
- errmsg = "RefreshEdbCalculateData Err:" + err.Error()
- return err
- }
- if result.Ret != 200 {
- fmt.Println(v, "RefreshEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
- errmsg = fmt.Sprint(v, "RefreshEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
- return fmt.Errorf("刷新失败")
- }
- }
- //刷新相关预测计算指标
- for _, v := range predictCalculateArr {
- edbInfo := newPredictCalculateMap[v]
- if edbInfo == nil {
- return err
- }
- startDate = edbInfo.StartDate
- source := edbInfo.Source
- if startDate == "" || startDate == "0000-00-00" { //如果没有开始日期,说明还没有计算出来数据,那么就往前面推40年吧(也意味着重新计算了)
- startDate = time.Now().AddDate(-40, 0, 0).Format(utils.FormatDate)
- } else {
- if source == utils.DATA_SOURCE_PREDICT_CALCULATE {
- startDate = ``
- if refreshAll { //刷新所有数据,用开始时间作为起始日期去刷新
- startDate = edbInfo.StartDate
- } else {
- sTime, err := time.Parse(utils.FormatDate, edbInfo.EndDate)
- if err != nil {
- return err
- }
- frequency := edbInfo.Frequency
- var limitDay int
- switch frequency {
- case "日度":
- limitDay = utils.DATA_START_REFRESH_LIMIT
- case "周度":
- limitDay = utils.DATA_START_REFRESH_LIMIT * 7
- case "月度":
- limitDay = utils.DATA_START_REFRESH_LIMIT * 30
- case "季度":
- limitDay = utils.DATA_START_REFRESH_LIMIT * 90
- case "年度":
- limitDay = utils.DATA_START_REFRESH_LIMIT * 365
- default:
- limitDay = utils.DATA_START_REFRESH_LIMIT
- }
- startDate = sTime.AddDate(0, 0, -limitDay).Format(utils.FormatDate)
- }
- }
- }
- result, err := RefreshPredictEdbCalculateData(edbInfo.EdbInfoId, edbInfo.EdbCode, startDate)
- if err != nil {
- fmt.Println(v, "RefreshEdbCalculateData err", time.Now())
- errmsg = "RefreshEdbCalculateData Err:" + err.Error()
- return err
- }
- if result.Ret != 200 {
- fmt.Println(v, "RefreshPredictEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
- errmsg = fmt.Sprint(v, "RefreshPredictEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
- return fmt.Errorf("刷新失败")
- }
- }
- // 4、更新动态环差值
- {
- predictEdbInfoIdList := make([]int, 0)
- for _, v := range newBasePredictEdbInfoArr {
- predictEdbInfoIdList = append(predictEdbInfoIdList, v.EdbInfoId)
- }
- fmt.Println("predictEdbConfCalculateMappingDetailList:", predictEdbInfoIdList)
- predictEdbConfCalculateMappingDetailList, err := data_manage.GetPredictEdbConfCalculateMappingDetailListByEdbInfoId(predictEdbInfoIdList)
- if err != nil {
- errmsg = fmt.Sprint("更新动态环差值时,获取数据失败:" + err.Error())
- return fmt.Errorf("刷新失败, err:", errmsg)
- }
- for _, bv := range predictEdbConfCalculateMappingDetailList {
- result, err := RefreshEdbData(bv.EdbInfoId, utils.DATA_SOURCE_PREDICT, bv.EdbCode, "")
- if err != nil {
- fmt.Println(bv.EdbInfoId, "RefreshBasePredictEdbData err", time.Now())
- errmsg = "RefreshBasePredictEdbData Err:" + err.Error()
- return err
- }
- if result.Ret != 200 {
- fmt.Println(bv.EdbInfoId, "RefreshBasePredictEdbData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
- errmsg = fmt.Sprint(bv.EdbInfoId, "RefreshBasePredictEdbData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
- return fmt.Errorf("刷新失败, err:%s", errmsg)
- }
- fmt.Println("end predictEdbConfCalculateMappingDetailList:", bv, time.Now())
- }
- }
- //5、再次刷新相关预测计算指标
- for _, v := range predictCalculateArr {
- edbInfo := newPredictCalculateMap[v]
- if edbInfo == nil {
- return err
- }
- startDate = edbInfo.StartDate
- source := edbInfo.Source
- if startDate == "" || startDate == "0000-00-00" { //如果没有开始日期,说明还没有计算出来数据,那么就往前面推40年吧(也意味着重新计算了)
- startDate = time.Now().AddDate(-40, 0, 0).Format(utils.FormatDate)
- } else {
- if source == utils.DATA_SOURCE_PREDICT_CALCULATE {
- startDate = ``
- if refreshAll { //刷新所有数据,用开始时间作为起始日期去刷新
- startDate = edbInfo.StartDate
- } else {
- sTime, err := time.Parse(utils.FormatDate, edbInfo.EndDate)
- if err != nil {
- return err
- }
- frequency := edbInfo.Frequency
- var limitDay int
- switch frequency {
- case "日度":
- limitDay = utils.DATA_START_REFRESH_LIMIT
- case "周度":
- limitDay = utils.DATA_START_REFRESH_LIMIT * 7
- case "月度":
- limitDay = utils.DATA_START_REFRESH_LIMIT * 30
- case "季度":
- limitDay = utils.DATA_START_REFRESH_LIMIT * 90
- case "年度":
- limitDay = utils.DATA_START_REFRESH_LIMIT * 365
- default:
- limitDay = utils.DATA_START_REFRESH_LIMIT
- }
- startDate = sTime.AddDate(0, 0, -limitDay).Format(utils.FormatDate)
- }
- }
- }
- result, err := RefreshPredictEdbCalculateData(edbInfo.EdbInfoId, edbInfo.EdbCode, startDate)
- if err != nil {
- fmt.Println(v, "RefreshEdbCalculateData err", time.Now())
- errmsg = "RefreshEdbCalculateData Err:" + err.Error()
- return err
- }
- if result.Ret != 200 {
- fmt.Println(v, "RefreshPredictEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
- errmsg = fmt.Sprint(v, "RefreshPredictEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
- return fmt.Errorf("刷新失败")
- }
- }
- return err
- }
- // EdbInfoRefresh 刷新单个指标,不会刷新关联指标
- func EdbInfoRefresh(edbInfo *data_manage.EdbInfoView, refreshAll bool) (err error) {
- var errmsg string
- defer func() {
- if err != nil {
- fmt.Println("EdbInfoRefresh Err:" + err.Error() + ";errmsg:" + errmsg)
- go alarm_msg.SendAlarmMsg("EdbInfoRefresh,Err"+err.Error()+";errMsg:"+errmsg, 3)
- //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "EdbInfoRefreshFromBase:"+errmsg, utils.EmailSendToUsers)
- }
- }()
- switch edbInfo.EdbInfoType {
- //指标类型,0:普通指标,1:预测指标
- case 0:
- if edbInfo.StartDate == "0000-00-00" {
- return
- }
- //开始时间
- startDate := ``
- if edbInfo.EdbType == 1 {
- // 基础指标
- if refreshAll { //刷新所有数据,用开始时间作为起始日期去刷新
- sTime, err := time.Parse(utils.FormatDate, edbInfo.StartDate)
- if err != nil {
- return err
- }
- startDate = sTime.Format(utils.FormatDate)
- } else {
- sTime, err := time.Parse(utils.FormatDate, edbInfo.EndDate)
- if err != nil {
- return err
- }
- frequency := edbInfo.Frequency
- var limitDay int
- switch frequency {
- case "日度":
- limitDay = utils.DATA_START_REFRESH_LIMIT
- case "周度":
- limitDay = utils.DATA_START_REFRESH_LIMIT * 7
- case "月度":
- limitDay = utils.DATA_START_REFRESH_LIMIT * 30
- case "季度":
- limitDay = utils.DATA_START_REFRESH_LIMIT * 90
- case "年度":
- limitDay = utils.DATA_START_REFRESH_LIMIT * 365
- default:
- limitDay = utils.DATA_START_REFRESH_LIMIT
- }
- startDate = sTime.AddDate(0, 0, -limitDay).Format(utils.FormatDate)
- }
- result, err := RefreshEdbData(edbInfo.EdbInfoId, edbInfo.Source, edbInfo.EdbCode, startDate)
- if err != nil {
- fmt.Println(edbInfo.EdbInfoId, "RefreshBaseEdbData err", time.Now())
- errmsg = "RefreshBaseEdbData Err:" + err.Error()
- return err
- }
- if result.Ret != 200 {
- fmt.Println(edbInfo.EdbInfoId, "RefreshBaseEdbData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
- errmsg = fmt.Sprint(edbInfo.EdbInfoId, "RefreshBaseEdbData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
- return fmt.Errorf("刷新失败, err:", errmsg)
- }
- } else { //计算指标
- //计算指标就不用开始时间了吧,因为存在说开始时间变更的情况
- if !refreshAll { //如果不是全部更新,那么以指标的开始时间作为刷新
- startDate = edbInfo.StartDate
- source := edbInfo.Source
- if startDate == "" || startDate == "0000-00-00" { //如果没有开始日期,说明还没有计算出来数据,那么就往前面推40年吧(也意味着重新计算了)
- startDate = time.Now().AddDate(-40, 0, 0).Format(utils.FormatDate)
- } else {
- if source == utils.DATA_SOURCE_CALCULATE {
- sTime, err := time.Parse(utils.FormatDate, edbInfo.EndDate)
- if err != nil {
- return err
- }
- frequency := edbInfo.Frequency
- var limitDay int
- switch frequency {
- case "日度":
- limitDay = utils.DATA_START_REFRESH_LIMIT
- case "周度":
- limitDay = utils.DATA_START_REFRESH_LIMIT * 7
- case "月度":
- limitDay = utils.DATA_START_REFRESH_LIMIT * 30
- case "季度":
- limitDay = utils.DATA_START_REFRESH_LIMIT * 90
- case "年度":
- limitDay = utils.DATA_START_REFRESH_LIMIT * 365
- default:
- limitDay = utils.DATA_START_REFRESH_LIMIT
- }
- startDate = sTime.AddDate(0, 0, -limitDay).Format(utils.FormatDate)
- }
- }
- }
- result, err := RefreshEdbCalculateData(edbInfo.EdbInfoId, edbInfo.EdbCode, startDate)
- if err != nil {
- fmt.Println(edbInfo.EdbInfoId, "RefreshEdbCalculateData err", time.Now())
- errmsg = "RefreshEdbCalculateData Err:" + err.Error()
- return err
- }
- if result.Ret != 200 {
- fmt.Println(edbInfo.EdbInfoId, "RefreshEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
- errmsg = fmt.Sprint(edbInfo.EdbInfoId, "RefreshEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
- return fmt.Errorf("刷新失败")
- }
- }
- case 1:
- startDate := edbInfo.StartDate
- var result *models.BaseResponse
- if startDate == "" || startDate == "0000-00-00" { //如果没有开始日期,说明还没有计算出来数据,那么就往前面推40年吧(也意味着重新计算了)
- startDate = time.Now().AddDate(-40, 0, 0).Format(utils.FormatDate)
- } else {
- startDate = ``
- if refreshAll { //刷新所有数据,用开始时间作为起始日期去刷新
- startDate = edbInfo.StartDate
- } else {
- sTime, err := time.Parse(utils.FormatDate, edbInfo.EndDate)
- if err != nil {
- return err
- }
- frequency := edbInfo.Frequency
- var limitDay int
- switch frequency {
- case "日度":
- limitDay = utils.DATA_START_REFRESH_LIMIT
- case "周度":
- limitDay = utils.DATA_START_REFRESH_LIMIT * 7
- case "月度":
- limitDay = utils.DATA_START_REFRESH_LIMIT * 30
- case "季度":
- limitDay = utils.DATA_START_REFRESH_LIMIT * 90
- case "年度":
- limitDay = utils.DATA_START_REFRESH_LIMIT * 365
- default:
- limitDay = utils.DATA_START_REFRESH_LIMIT
- }
- startDate = sTime.AddDate(0, 0, -limitDay).Format(utils.FormatDate)
- }
- }
- if edbInfo.EdbType == 1 { //基础指标
- result, err = RefreshPredictEdbCalculateData(edbInfo.EdbInfoId, edbInfo.EdbCode, startDate)
- } else {
- // 预测计算指标
- // 4、更新动态环差值
- {
- predictEdbConfCalculateMappingDetailList, err := data_manage.GetPredictEdbConfCalculateMappingDetailListByEdbInfoId([]int{edbInfo.EdbInfoId})
- if err != nil {
- errmsg = fmt.Sprint("更新动态环差值时,获取数据失败:" + err.Error())
- return fmt.Errorf("刷新失败, err:", errmsg)
- }
- for _, bv := range predictEdbConfCalculateMappingDetailList {
- result, err := RefreshEdbData(bv.EdbInfoId, utils.DATA_SOURCE_PREDICT, bv.EdbCode, "")
- if err != nil {
- fmt.Println(bv.EdbInfoId, "RefreshBasePredictEdbData err", time.Now())
- errmsg = "RefreshBasePredictEdbData Err:" + err.Error()
- return err
- }
- if result.Ret != 200 {
- fmt.Println(bv.EdbInfoId, "RefreshBasePredictEdbData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
- errmsg = fmt.Sprint(bv.EdbInfoId, "RefreshBasePredictEdbData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
- return fmt.Errorf("刷新失败, err:%s", errmsg)
- }
- fmt.Println("end predictEdbConfCalculateMappingDetailList:", bv, time.Now())
- }
- }
- }
- if err != nil {
- fmt.Println(edbInfo.EdbInfoId, "RefreshEdbCalculateData err", time.Now())
- errmsg = "RefreshEdbCalculateData Err:" + err.Error()
- return err
- }
- if result.Ret != 200 {
- fmt.Println(edbInfo.EdbInfoId, "RefreshPredictEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
- errmsg = fmt.Sprint(edbInfo.EdbInfoId, "RefreshPredictEdbCalculateData err;msg:", result.Msg, ";errMsg:", result.ErrMsg)
- return fmt.Errorf("刷新失败")
- }
- }
- return err
- }
- // AddEdbInfo 新增手工指标数据
- func AddEdbInfo(secName, unit, frequency, noticeTime, mobile string, classifyId, userId int) (err error) {
- tradeCode, err := models.GetMaxTradeCode()
- if err != nil {
- return
- }
- if tradeCode == "" {
- err = errors.New("最大编码为空")
- return
- }
- maxTradeCode, err := utils.GetMaxTradeCode(tradeCode)
- if err != nil {
- err = errors.New("获取编码信息失败,Err:" + err.Error())
- return
- }
- if maxTradeCode == "" {
- err = errors.New("编码为空,请联系技术")
- return
- }
- //判断指标名称是否为空
- if secName == "" {
- err = errors.New("指标名称不能为空")
- return
- }
- item, err := models.GetEdbinfoBySecName(secName)
- if err != nil && err.Error() != utils.ErrNoRow() {
- err = errors.New("获取信息失败,Err:" + err.Error())
- return
- }
- if item != nil {
- err = errors.New("指标名称已存在")
- return
- }
- // 先删除该指标编码的历史数据(避免上海删除指标时,没有删除该指标数据)
- _ = models.DeleteAllEdbData(maxTradeCode)
- // 再次新增指标
- err = models.AddEdbinfo(maxTradeCode, secName, unit, "手动", frequency, noticeTime, classifyId, userId)
- if err != nil {
- err = errors.New("新增失败,Err:" + err.Error())
- return
- }
- err = models.AddEdbinfoUser(maxTradeCode, mobile)
- return
- }
- //全部刷新指标
- //func EdbInfoRefreshAllFromBase(edbInfoId int) (err error) {
- // var errmsg string
- // defer func() {
- // if err != nil {
- // fmt.Println("EdbInfoRefreshAllFromBase Err:" + err.Error() + ";errmsg:" + errmsg)
- // go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "EdbInfoRefreshFromBase:"+errmsg, utils.EmailSendToUsers)
- // }
- // }()
- //
- // calculateList, err := data_manage.GetEdbInfoAllCalculate(edbInfoId)
- // if err != nil && err.Error() != utils.ErrNoRow() {
- // return errors.New("GetEdbInfoAllCalculate Err:" + err.Error())
- // }
- // baseEdbInfoArr := make([]*data_manage.EdbInfo, 0)
- // calculateInfoArr := make([]*data_manage.EdbInfo, 0)
- // baseEdbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
- // if err != nil {
- // return errors.New("GetEdbInfoAllCalGetEdbInfoByIdr:" + err.Error())
- // }
- // baseEdbInfoArr = append(baseEdbInfoArr, baseEdbInfo)
- //
- // for _, v := range calculateList {
- // getBaseEdbInfoArr, getCalculateInfoArr, err := data_manage.GetRefreshEdbInfoFromBase(v.EdbInfoId, v.Source)
- // if err != nil {
- // fmt.Println("GetRefreshEdbInfoFromBase err:" + err.Error())
- // errmsg = "获取需要刷新的指标失败:Err:" + err.Error()
- // return err
- // }
- // baseEdbInfoArr = append(baseEdbInfoArr, getBaseEdbInfoArr...)
- // calculateInfoArr = append(calculateInfoArr, getCalculateInfoArr...)
- // calculateInfoArr = append(calculateInfoArr, v)
- // }
- // //取重
- // newBaseEdbInfoArr := make([]*data_manage.EdbInfo, 0)
- // baseMap := make(map[int]int)
- // for _, v := range baseEdbInfoArr {
- // if _, ok := baseMap[v.EdbInfoId]; !ok {
- // newBaseEdbInfoArr = append(newBaseEdbInfoArr, v)
- // }
- // baseMap[v.EdbInfoId] = v.EdbInfoId
- // }
- //
- // var calculateArr []int
- // newCalculateMap := make(map[int]*data_manage.EdbInfo)
- // for _, v := range calculateInfoArr {
- // if _, ok := newCalculateMap[v.EdbInfoId]; !ok {
- // calculateArr = append(calculateArr, v.EdbInfoId)
- // }
- // newCalculateMap[v.EdbInfoId] = v
- // }
- // sort.Ints(calculateArr)
- // var startDate string
- // for _, bv := range newBaseEdbInfoArr {
- // source := bv.Source
- // edbInfoId := bv.EdbInfoId
- // edbCode := bv.EdbCode
- //
- // sTime, err := time.Parse(utils.FormatDate, bv.StartDate)
- // if err != nil {
- // return err
- // }
- // startDate = sTime.Format(utils.FormatDate)
- //
- // if source == utils.DATA_SOURCE_THS {
- // endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
- // err = data_manage.RefreshAllEdbDataByThs(edbInfoId, source, edbCode, startDate, endDate)
- // if err != nil {
- // errmsg = "RefreshAllEdbDataByThs Err:" + err.Error()
- // }
- // } else if source == utils.DATA_SOURCE_WIND {
- // endDate := time.Now().Format(utils.FormatDate)
- // err = data_manage.RefreshAllEdbDataByWind(edbInfoId, source, edbCode, startDate, endDate)
- // if err != nil {
- // errmsg = "RefreshAllEdbDataByWind Err:" + err.Error()
- // }
- // } else if source == utils.DATA_SOURCE_PB {
- // startDate := sTime.Format(utils.FormatDateUnSpace)
- // endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
- // err = data_manage.RefreshAllEdbDataByPb(edbInfoId, source, edbCode, startDate, endDate)
- // if err != nil {
- // errmsg = "RefreshAllEdbDataByPb Err:" + err.Error()
- // }
- // } else if source == utils.DATA_SOURCE_MANUAL {
- // endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
- // err = data_manage.RefreshAllEdbDataByManual(edbInfoId, source, edbCode, startDate, endDate)
- // if err != nil {
- // errmsg = "RefreshAllEdbDataByManual Err:" + err.Error()
- // }
- // } else if source == utils.DATA_SOURCE_LZ {
- // endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
- // err = data_manage.RefreshAllEdbDataByLz(edbInfoId, source, edbCode, startDate, endDate)
- // if err != nil {
- // errmsg = "RefreshAllEdbDataByLz Err:" + err.Error()
- // }
- // } else if source == utils.DATA_SOURCE_YS {
- // endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
- // err = data_manage.RefreshAllEdbDataByYs(edbInfoId, source, edbCode, startDate, endDate)
- // if err != nil {
- // errmsg = "RefreshAllEdbDataByYs Err:" + err.Error()
- // }
- // } else if source == utils.DATA_SOURCE_GL {
- // endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
- // err = data_manage.RefreshAllEdbDataByGl(edbInfoId, source, edbCode, startDate, endDate)
- // if err != nil {
- // errmsg = "RefreshAllEdbDataByGl Err:" + err.Error()
- // }
- // } else if source == utils.DATA_SOURCE_ZZ {
- // endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
- // err = data_manage.RefreshAllEdbDataByZz(edbInfoId, source, edbCode, startDate, endDate)
- // if err != nil {
- // errmsg = "RefreshAllEdbDataByZz Err:" + err.Error()
- // }
- // } else if source == utils.DATA_SOURCE_DL {
- // endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
- // err = data_manage.RefreshAllEdbDataByDl(edbInfoId, source, edbCode, startDate, endDate)
- // if err != nil {
- // errmsg = "RefreshAllEdbDataByDl Err:" + err.Error()
- // }
- // } else if source == utils.DATA_SOURCE_SH {
- // endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
- // err = data_manage.RefreshAllEdbDataBySh(edbInfoId, source, edbCode, startDate, endDate)
- // if err != nil {
- // errmsg = "RefreshAllEdbDataBySh Err:" + err.Error()
- // }
- // } else if source == utils.DATA_SOURCE_CFFEX {
- // endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
- // err = data_manage.RefreshAllEdbDataByCffex(edbInfoId, source, edbCode, startDate, endDate)
- // if err != nil {
- // errmsg = "RefreshAllEdbDataByCffex Err:" + err.Error()
- // }
- // } else if source == utils.DATA_SOURCE_SHFE {
- // endDate := time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
- // err = data_manage.RefreshAllEdbDataByShfe(edbInfoId, source, edbCode, startDate, endDate)
- // if err != nil {
- // errmsg = "RefreshAllEdbDataByShfe Err:" + err.Error()
- // }
- // }
- //
- // maxAndMinItem, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
- // if err != nil {
- // return err
- // }
- // if maxAndMinItem != nil {
- // err = data_manage.ModifyEdbInfoMaxAndMinInfo(edbInfoId, maxAndMinItem)
- // if err != nil {
- // return err
- // }
- // }
- // fmt.Println("end newBaseEdbInfoArr:", bv, time.Now())
- // }
- //
- // endDate := "" //计算指标不限制日期
- // //刷新相关计算指标
- // for _, v := range calculateArr {
- // edbInfo := newCalculateMap[v]
- // if edbInfo == nil {
- // return err
- // }
- // edbInfoId := edbInfo.EdbInfoId
- // source := edbInfo.Source
- // edbCode := edbInfo.EdbCode
- //
- // if source == utils.DATA_SOURCE_CALCULATE {
- // startDate = edbInfo.StartDate
- // sTime, err := time.Parse(utils.FormatDate, edbInfo.EndDate)
- // if err != nil {
- // return err
- // }
- // startDate = sTime.Format(utils.FormatDate)
- //
- // var edbInfoIdBytes []string
- // calculateMap, err := data_manage.GetEdbInfoCalculateDetail(edbInfoId, edbInfo.Source)
- // if err != nil {
- // errmsg = "GetEdbInfoCalculateDetail Err:" + err.Error()
- // return err
- // }
- // var formulaStr string
- // edbInfoList := make([]*data_manage.EdbInfo, 0)
- //
- // for _, v := range calculateMap {
- // formulaStr += v.FromTag + ","
- // edbInfoIdBytes = append(edbInfoIdBytes, v.FromTag)
- // edbInfo, _ := data_manage.GetEdbInfoById(v.FromEdbInfoId)
- // edbInfoList = append(edbInfoList, edbInfo)
- // }
- // err = data_manage.RefreshAllCalculate(edbInfoList, int(edbInfoId), source, edbInfo.EdbCode, edbInfo.CalculateFormula, startDate, endDate, edbInfoIdBytes)
- // if err != nil {
- // errmsg = "RefreshCalculate Err:" + err.Error()
- // return err
- // }
- // } else if source == utils.DATA_SOURCE_CALCULATE_LJZZY { //刷新累计值转月值
- // calculateLjzzy, err := data_manage.GetEdbInfoCalculateLjzzyDetail(edbInfoId)
- // if err != nil {
- // errmsg = "GetEdbInfoCalculateLjzzyDetail Err:" + err.Error()
- // return err
- // }
- // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateLjzzy.FromEdbInfoId)
- // if err != nil {
- // errmsg = "GetEdbInfoById Err:" + err.Error()
- // return err
- // }
- // startDate = edbInfo.StartDate
- // endDate = time.Now().Format(utils.FormatDate)
- // err = data_manage.RefreshAllCalculateLjzzy(edbInfoId, source, fromEdbInfo, calculateLjzzy.EdbCode, startDate, endDate)
- // if err != nil {
- // errmsg = "RefreshAllCalculateLjzzy Err:" + err.Error()
- // return err
- // }
- // } else if source == utils.DATA_SOURCE_CALCULATE_TBZ { //刷新同比值
- // calculateTbz, err := data_manage.GetEdbInfoCalculateTbzDetail(edbInfoId)
- // if err != nil {
- // errmsg = "GetEdbInfoCalculateTbzDetail Err:" + err.Error()
- // return err
- // }
- // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTbz.FromEdbInfoId)
- // if err != nil {
- // errmsg = "GetEdbInfoById Err:" + err.Error()
- // return err
- // }
- // startDate = edbInfo.StartDate
- // endDate = time.Now().Format(utils.FormatDate)
- // err = data_manage.RefreshAllCalculateTbz(edbInfoId, source, fromEdbInfo, calculateTbz.EdbCode, startDate, endDate)
- // if err != nil {
- // errmsg = "RefreshAllCalculateTbz Err:" + err.Error()
- // return err
- // }
- // } else if source == utils.DATA_SOURCE_CALCULATE_TCZ { //同差值
- // calculateTcz, err := data_manage.GetEdbInfoCalculateTczDetail(edbInfoId)
- // if err != nil {
- // errmsg = "GetEdbInfoCalculateTczDetail Err:" + err.Error()
- // return err
- // }
- // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTcz.FromEdbInfoId)
- // if err != nil {
- // errmsg = "GetEdbInfoById Err:" + err.Error()
- // return err
- // }
- // startDate = edbInfo.StartDate
- // endDate = time.Now().Format(utils.FormatDate)
- // err = data_manage.RefreshAllCalculateTcz(edbInfoId, source, fromEdbInfo, calculateTcz.EdbCode, startDate, endDate)
- // if err != nil {
- // errmsg = "RefreshCalculateTcz Err:" + err.Error()
- // return err
- // }
- // } else if source == utils.DATA_SOURCE_CALCULATE_NSZYDPJJS { //N数值移动平均计算
- // calculateNszydpjjs, err := data_manage.GetEdbInfoCalculateNszydpjjsDetail(edbInfoId)
- // if err != nil {
- // errmsg = "GetEdbInfoCalculateNszydpjjsDetail Err:" + err.Error()
- // return err
- // }
- // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateNszydpjjs.FromEdbInfoId)
- // if err != nil {
- // errmsg = "GetEdbInfoById Err:" + err.Error()
- // return err
- // }
- // formulaInt, _ := strconv.Atoi(edbInfo.CalculateFormula)
- // startDate = edbInfo.StartDate
- // err = data_manage.RefreshAllCalculateNszydpjjs(edbInfoId, edbInfo.Source, formulaInt, fromEdbInfo, calculateNszydpjjs.EdbCode, startDate)
- // if err != nil {
- // errmsg = "RefreshCalculateNszydpjjs Err:" + err.Error()
- // return err
- // }
- // } else if source == utils.DATA_SOURCE_CALCULATE_HBZ { //刷新环比值
- // calculateTbz, err := data_manage.GetEdbInfoCalculateHbzDetail(edbInfoId)
- // if err != nil {
- // errmsg = "GetEdbInfoCalculateHbzDetail Err:" + err.Error()
- // return err
- // }
- // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTbz.FromEdbInfoId)
- // if err != nil {
- // errmsg = "GetEdbInfoById Err:" + err.Error()
- // return err
- // }
- // startDate = edbInfo.StartDate
- // endDate = time.Now().Format(utils.FormatDate)
- // formulaInt, _ := strconv.Atoi(edbInfo.CalculateFormula)
- // err = data_manage.RefreshAllCalculateHbz(edbInfoId, source, fromEdbInfo, calculateTbz.EdbCode, startDate, endDate, formulaInt)
- // if err != nil {
- // errmsg = "RefreshAllCalculateHbz Err:" + err.Error()
- // return err
- // }
- // } else if source == utils.DATA_SOURCE_CALCULATE_HCZ { //刷新环差值
- // calculateTbz, err := data_manage.GetEdbInfoCalculateHczDetail(edbInfoId)
- // if err != nil {
- // errmsg = "GetEdbInfoCalculateHczDetail Err:" + err.Error()
- // return err
- // }
- // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTbz.FromEdbInfoId)
- // if err != nil {
- // errmsg = "GetEdbInfoById Err:" + err.Error()
- // return err
- // }
- // startDate = edbInfo.StartDate
- // endDate = time.Now().Format(utils.FormatDate)
- // formulaInt, _ := strconv.Atoi(edbInfo.CalculateFormula)
- // err = data_manage.RefreshAllCalculateHcz(edbInfoId, source, fromEdbInfo, calculateTbz.EdbCode, startDate, endDate, formulaInt)
- // if err != nil {
- // errmsg = "RefreshAllCalculateHcz Err:" + err.Error()
- // return err
- // }
- // } else if source == utils.DATA_SOURCE_CALCULATE_BP { //刷新变频
- // calculateTbz, err := data_manage.GetEdbInfoCalculateBpDetail(edbInfoId)
- // if err != nil {
- // errmsg = "GetEdbInfoCalculateTbzDetail Err:" + err.Error()
- // return err
- // }
- // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTbz.FromEdbInfoId)
- // if err != nil {
- // errmsg = "GetEdbInfoById Err:" + err.Error()
- // return err
- // }
- // startDate = edbInfo.StartDate
- // endDate = time.Now().Format(utils.FormatDate)
- // err = data_manage.RefreshAllCalculateBp(edbInfoId, source, fromEdbInfo, calculateTbz.EdbCode, startDate, endDate)
- // if err != nil {
- // errmsg = "RefreshAllCalculateBp Err:" + err.Error()
- // return err
- // }
- //<<<<<<< HEAD
- // } else if source == utils.DATA_SOURCE_CALCULATE_TIME_SHIFT {
- // calculate, err := data_manage.GetEdbInfoCalculateMappingDetail(edbInfoId)
- // if err != nil {
- // errmsg = "GetEdbInfoCalculateTbzDetail Err:" + err.Error()
- // return err
- // }
- // fromEdbInfo, err := data_manage.GetEdbInfoById(calculate.FromEdbInfoId)
- // if err != nil {
- // errmsg = "GetEdbInfoById Err:" + err.Error()
- // return err
- // }
- // startDate = edbInfo.StartDate
- // endDate = time.Now().Format(utils.FormatDate)
- // formulaInt, _ := strconv.Atoi(calculate.CalculateFormula)
- // err = data_manage.RefreshAllCalculateTimeShift(edbInfoId, source, formulaInt, calculate.MoveType, fromEdbInfo, calculate.EdbCode, startDate, endDate, calculate.MoveFrequency)
- // if err != nil {
- // errmsg = "RefreshAllCalculateTimeShift Err:" + err.Error()
- //=======
- // } else if source == utils.DATA_SOURCE_CALCULATE_ZJPJ { //刷新直接拼接
- // err = data_manage.RefreshAllCalculateZjpj(edbInfo)
- // if err != nil {
- // errmsg = "RefreshAllCalculateBp Err:" + err.Error()
- //>>>>>>> 884fd669cc9e91923781680e1890a519c012d38e
- // return err
- // }
- // }
- //
- // maxAndMinItem, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
- // if err != nil {
- // return err
- // }
- //
- // if maxAndMinItem != nil {
- // err = data_manage.ModifyEdbInfoMaxAndMinInfo(edbInfoId, maxAndMinItem)
- // if err != nil {
- // return err
- // }
- // }
- // fmt.Println("end calculateArr:", v, time.Now())
- // }
- // return err
- //}
- //
- //// AddEdbInfo 新增手工指标数据
- //func AddEdbInfo(secName, unit, frequency, noticeTime, mobile string, classifyId, userId int) (err error) {
- // tradeCode, err := models.GetMaxTradeCode()
- // if err != nil {
- // return
- // }
- //
- // if tradeCode == "" {
- // err = errors.New("最大编码为空")
- // return
- // }
- // maxTradeCode, err := utils.GetMaxTradeCode(tradeCode)
- // if err != nil {
- // err = errors.New("获取编码信息失败,Err:" + err.Error())
- // return
- // }
- // if maxTradeCode == "" {
- // err = errors.New("编码为空,请联系技术")
- // return
- // }
- // //判断指标名称是否为空
- // if secName == "" {
- // err = errors.New("指标名称不能为空")
- // return
- // }
- // item, err := models.GetEdbinfoBySecName(secName)
- // if err != nil && err.Error() != utils.ErrNoRow() {
- // err = errors.New("获取信息失败,Err:" + err.Error())
- // return
- // }
- // if item != nil {
- // err = errors.New("指标名称已存在")
- // return
- // }
- // err = models.AddEdbinfo(maxTradeCode, secName, unit, "手动", frequency, noticeTime, classifyId, userId)
- // if err != nil {
- // err = errors.New("新增失败,Err:" + err.Error())
- // return
- // }
- // err = models.AddEdbinfoUser(maxTradeCode, mobile)
- // return
- //}
- //
- //
- //
- //
- // AddOrEditAllEdbInfoToEs 修复ES中的指标
- func AddOrEditAllEdbInfoToEs() {
- //添加es
- total, itemInfoList, _ := data_manage.GetEdbInfoFilterList("", []interface{}{}, 0, 100000)
- for k, itemInfo := range itemInfoList {
- elastic.EsAddOrEditEdbInfoData(utils.DATA_INDEX_NAME, strconv.Itoa(itemInfo.EdbInfoId), itemInfo)
- fmt.Println("剩余", int(total)-k-1, "条数据")
- }
- }
- // AddOrEditEdbInfoToEs 添加/修改ES中的指标
- func AddOrEditEdbInfoToEs(edbInfoId int) {
- //添加es
- itemInfo, _ := data_manage.GetEdbInfoByCondition("AND edb_info_id=?", []interface{}{edbInfoId})
- go elastic.EsAddOrEditEdbInfoData(utils.DATA_INDEX_NAME, strconv.Itoa(itemInfo.EdbInfoId), itemInfo)
- }
- // DeleteEdbInfoToEs 删除ES中的指标
- func DeleteEdbInfoToEs(edbInfoId int) {
- //添加es
- go elastic.EsDeleteEdbInfoData(utils.DATA_INDEX_NAME, strconv.Itoa(edbInfoId))
- }
- // RefreshManualData 根据手工指标code刷新手工指标数据
- func RefreshManualData(edbCode string) {
- var err error
- defer func() {
- if err != nil {
- go alarm_msg.SendAlarmMsg("导入手工数据后,根据手工指标code刷新手工指标数据失败提醒,Err"+err.Error(), 3)
- //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"导入手工数据后,根据手工指标code刷新手工指标数据失败提醒", "errmsg:"+err.Error(), utils.EmailSendToUsers)
- }
- }()
- edbInfo, err := data_manage.GetEdbInfoByEdbCode(utils.DATA_SOURCE_MANUAL, edbCode)
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- err = nil
- }
- return
- }
- // 刷新指标库
- err = EdbInfoRefreshAllFromBaseV2(edbInfo.EdbInfoId, true)
- return
- }
- // EdbInfoReplace 替换指标v2版本(更换时间:2022年01月05日15:33:42)
- func EdbInfoReplace(oldEdbInfo, newEdbInfo *data_manage.EdbInfo, sysAdminId int, sysAdminRealName string) (replaceChartTotal, replaceCalculateTotal int, err error) {
- defer func() {
- if err != nil {
- fmt.Println("ERR:", err.Error())
- }
- }()
- mappingList, replaceChartTotal, replaceCalculateTotal, err := data_manage.ReplaceChartEdb(oldEdbInfo, newEdbInfo)
- if err != nil {
- return
- }
- //更新指标
- err = replaceRelationEdbInfo(mappingList, oldEdbInfo, newEdbInfo, sysAdminId, sysAdminRealName)
- return
- }
- // replaceRelationEdbInfo 刷新指标
- func replaceRelationEdbInfo(mappingList []*data_manage.EdbInfoCalculateMapping, oldEdbInfo, newEdbInfo *data_manage.EdbInfo, sysAdminId int, sysAdminRealName string) (err error) {
- errmsg := ``
- defer func() {
- if errmsg != "" {
- fmt.Println("errmsg:" + errmsg)
- }
- if err != nil && errmsg != "" {
- go alarm_msg.SendAlarmMsg("替换关联指标失败提醒,errmsg:"+errmsg, 3)
- //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"替换指标失败提醒", "errmsg:"+errmsg, utils.EmailSendToUsers)
- }
- }()
- //获取计算指标关联指标
- allMappingList := make([]*data_manage.EdbInfoCalculateMapping, 0)
- allMapping := make(map[int]int)
- tmpMapping := make(map[int]int)
- for _, v := range mappingList {
- if _, ok := allMapping[v.EdbInfoId]; !ok {
- allMappingList = append(allMappingList, v)
- }
- newList, _ := data_manage.GetAllCalculateV2(v.EdbInfoId, newEdbInfo.EdbInfoId, tmpMapping)
- for _, nv := range newList {
- if _, ok := allMapping[v.EdbInfoId]; !ok {
- allMappingList = append(allMappingList, nv)
- }
- allMapping[v.EdbInfoId] = v.EdbInfoId
- }
- allMapping[v.EdbInfoId] = v.EdbInfoId
- }
- for mk, mv := range allMappingList { //原指标关联的所有计算指标
- fmt.Println("mk/mv", mk, mv)
- //重新计算计算指标
- {
- edbInfo, tmpErr := data_manage.GetEdbInfoById(mv.EdbInfoId) //计算指标
- err = tmpErr
- if err != nil {
- if err.Error() == utils.ErrNoRow() {
- errmsg = "计算指标已被删除"
- } else {
- errmsg = "获取计算指标失败:err:" + err.Error()
- }
- return
- }
- fromEdbInfoList, tmpErr := data_manage.GetEdbInfoCalculateDetail(mv.EdbInfoId, edbInfo.Source)
- err = tmpErr
- if err != nil {
- errmsg = "获取计算指标失败:err:" + err.Error()
- return
- }
- if len(fromEdbInfoList) <= 0 {
- errmsg = "计算指标所依赖指标不存在"
- err = fmt.Errorf("计算指标所依赖指标不存在")
- return
- }
- fromEdbInfoItem := fromEdbInfoList[0]
- if fromEdbInfoItem == nil {
- return
- }
- fromEdbInfo, tmpErr := data_manage.GetEdbInfoById(fromEdbInfoItem.FromEdbInfoId)
- err = tmpErr
- if err != nil {
- errmsg = "获取计算指标 来源指标失败:err:" + err.Error()
- return
- }
- edbCode := edbInfo.EdbCode
- //uniqueCode := edbInfo.UniqueCode
- sourName := edbInfo.SourceName
- source := edbInfo.Source
- edbInfoId := edbInfo.EdbInfoId
- req := &data_manage.EdbInfoCalculateBatchSaveReqByEdbLib{
- AdminId: sysAdminId,
- AdminName: sysAdminRealName,
- EdbInfoId: edbInfoId,
- EdbName: edbInfo.EdbName,
- Frequency: edbInfo.Frequency,
- Unit: edbInfo.Unit,
- ClassifyId: edbInfo.ClassifyId,
- Formula: edbInfo.CalculateFormula, //N数值移动平均计算、环比值、环差值
- FromEdbInfoId: fromEdbInfoList[0].FromEdbInfoId,
- Source: edbInfo.Source,
- MoveType: edbInfo.MoveType,
- MoveFrequency: edbInfo.MoveFrequency,
- CalculateFormula: edbInfo.CalculateFormula,
- EdbInfoIdArr: nil,
- }
- if source == utils.DATA_SOURCE_CALCULATE_ZJPJ {
- edbInfoIdArr := make([]data_manage.EdbInfoFromTag, 0)
- //A指标
- aFromEdbInfoId := fromEdbInfoList[0].FromEdbInfoId
- //找出需要替换的指标
- {
- for _, v := range fromEdbInfoList {
- if v.FromTag == "A" {
- if v.FromEdbInfoId == oldEdbInfo.EdbInfoId {
- aFromEdbInfoId = newEdbInfo.EdbInfoId
- } else {
- aFromEdbInfoId = fromEdbInfoList[0].FromEdbInfoId
- }
- }
- if v.FromTag == "B" {
- if v.FromEdbInfoId == oldEdbInfo.EdbInfoId {
- edbInfoIdArr = append(edbInfoIdArr, data_manage.EdbInfoFromTag{
- EdbInfoId: newEdbInfo.EdbInfoId,
- FromTag: v.FromTag,
- })
- } else {
- edbInfoIdArr = append(edbInfoIdArr, data_manage.EdbInfoFromTag{
- EdbInfoId: v.FromEdbInfoId,
- FromTag: v.FromTag,
- })
- }
- }
- }
- }
- req.FromEdbInfoId = aFromEdbInfoId
- req.EdbInfoIdArr = edbInfoIdArr
- sourName = "直接拼接"
- if len(req.EdbInfoIdArr) != 1 {
- errmsg = "请传入拼接日期之后的指标"
- err = fmt.Errorf("请传入拼接日期之后的指标")
- return
- }
- secondEdbInfoReq := req.EdbInfoIdArr[0]
- secondEdbInfo, tmpErr := data_manage.GetEdbInfoById(secondEdbInfoReq.EdbInfoId)
- err = tmpErr
- if err != nil {
- errmsg = "获取拼接日期之后的指标信息失败:Err:" + err.Error()
- err = fmt.Errorf("获取拼接日期之后的指标信息失败:Err:" + err.Error())
- return
- }
- if fromEdbInfo.EdbInfoId == secondEdbInfo.EdbInfoId {
- errmsg = "两个指标不允许为同一个"
- err = fmt.Errorf("两个指标不允许为同一个")
- return
- }
- } else if source == utils.DATA_SOURCE_CALCULATE_LJZTBPJ { //累计值同比拼接
- edbInfoIdArr := make([]data_manage.EdbInfoFromTag, 0)
- //A指标
- aFromEdbInfoId := fromEdbInfoList[0].FromEdbInfoId
- // 找出需要替换的指标
- {
- for _, v := range fromEdbInfoList {
- if v.FromTag == "A" {
- if v.FromEdbInfoId == oldEdbInfo.EdbInfoId {
- aFromEdbInfoId = newEdbInfo.EdbInfoId
- } else {
- aFromEdbInfoId = fromEdbInfoList[0].FromEdbInfoId
- }
- }
- if v.FromTag == "B" {
- if v.FromEdbInfoId == oldEdbInfo.EdbInfoId {
- edbInfoIdArr = append(edbInfoIdArr, data_manage.EdbInfoFromTag{
- EdbInfoId: newEdbInfo.EdbInfoId,
- FromTag: v.FromTag,
- })
- } else {
- edbInfoIdArr = append(edbInfoIdArr, data_manage.EdbInfoFromTag{
- EdbInfoId: v.FromEdbInfoId,
- FromTag: v.FromTag,
- })
- }
- }
- }
- }
- req.FromEdbInfoId = aFromEdbInfoId
- req.EdbInfoIdArr = edbInfoIdArr
- sourName = "累计值同比拼接"
- if fromEdbInfo.Frequency != "月度" {
- errmsg = "累计值同比拼接,待拼接指标只能筛选月度指标"
- err = fmt.Errorf("累计值同比拼接,待拼接指标只能筛选月度指标")
- return
- }
- if len(req.EdbInfoIdArr) != 1 {
- errmsg = "请传入同比值指标"
- err = fmt.Errorf("请传入同比值指标")
- return
- }
- secondEdbInfoReq := req.EdbInfoIdArr[0]
- tbzEdbInfo, tmpErr := data_manage.GetEdbInfoById(secondEdbInfoReq.EdbInfoId)
- err = tmpErr
- if err != nil {
- errmsg = "获取同比值指标信息失败:Err:" + err.Error()
- err = fmt.Errorf("获取同比值指标信息失败:Err:" + err.Error())
- return
- }
- if tbzEdbInfo.Source != utils.DATA_SOURCE_CALCULATE_TBZ {
- errmsg = "指标必须是传入同比值指标类型"
- err = fmt.Errorf("指标必须是传入同比值指标类型")
- return
- }
- if tbzEdbInfo.Frequency != "月度" {
- errmsg = "同比值指标只能筛选月度指标"
- err = fmt.Errorf("同比值指标只能筛选月度指标")
- return
- }
- if fromEdbInfo.EdbInfoId == tbzEdbInfo.EdbInfoId {
- errmsg = "两个指标不允许为同一个"
- err = fmt.Errorf("两个指标不允许为同一个")
- return
- }
- } else {
- errmsg = "无效计算方式,source:" + strconv.Itoa(source)
- err = fmt.Errorf("无效计算方式,source:" + strconv.Itoa(source))
- return
- }
- // 调用指标库去更新
- reqJson, tmpErr := json.Marshal(req)
- if tmpErr == nil {
- respItem, tmpErr := EditEdbCalculateData(string(reqJson))
- if err != nil {
- err = tmpErr
- return
- }
- if respItem.Ret != 200 {
- err = errors.New("修改失败")
- return
- }
- } else {
- err = tmpErr
- }
- maxAndMinItem, tmpErr := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
- err = tmpErr
- if err != nil && err.Error() != utils.ErrNoRow() {
- errmsg = "生成" + sourName + "失败,GetEdbInfoMaxAndMinInfo Err:" + err.Error()
- err = fmt.Errorf("生成" + sourName + "失败,GetEdbInfoMaxAndMinInfo Err:" + err.Error())
- return
- }
- if maxAndMinItem != nil {
- err = data_manage.ModifyEdbInfoMaxAndMinInfo(edbInfoId, maxAndMinItem)
- }
- }
- }
- return
- }
- // 获取频度的英文版
- func GetFrequencyEn(frequency string) (frequencyEn string) {
- switch frequency {
- case "日度":
- frequencyEn = "day"
- return
- case "周度":
- frequencyEn = "week"
- return
- case "旬度":
- frequencyEn = "ten days"
- return
- case "月度":
- frequencyEn = "month"
- return
- case "季度":
- frequencyEn = "quarter"
- return
- case "年度":
- frequencyEn = "year"
- return
- }
- return
- }
- func GetLeadUnitEn(unit string) (unitEn string) {
- switch unit {
- case "天":
- unitEn = "day"
- return
- case "周":
- unitEn = "week"
- return
- case "月":
- unitEn = "month"
- return
- case "季":
- unitEn = "quarter"
- return
- case "年":
- unitEn = "year"
- return
- }
- return
- }
- // getRefreshEdbInfoList 获取待更新的指标(普通基础指标、普通运算指标,预测运算指标)
- //func getRefreshEdbInfoList(edbInfoId int) (newBaseEdbInfoArr []*data_manage.EdbInfo, newCalculateMap, newPredictCalculateMap map[int]*data_manage.EdbInfo, calculateArr, predictCalculateArr []int, err error, errMsg string) {
- // calculateList, err := data_manage.GetEdbInfoAllCalculate(edbInfoId)
- // if err != nil && err.Error() != utils.ErrNoRow() {
- // err = errors.New("GetEdbInfoAllCalculate Err:" + err.Error())
- // return
- // }
- // // 获取指标信息
- // baseEdbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
- // if err != nil {
- // err = errors.New("GetEdbInfoAllCalGetEdbInfoByIdr:" + err.Error())
- // return
- // }
- //
- // baseEdbInfoArr := make([]*data_manage.EdbInfo, 0) // 基础普通指标
- // calculateInfoArr := make([]*data_manage.EdbInfo, 0) //基础运算指标
- // basePredictEdbInfoArr := make([]*data_manage.EdbInfo, 0) // 预测普通指标
- // predictCalculateInfoArr := make([]*data_manage.EdbInfo, 0) //预测运算指标
- //
- // if baseEdbInfo.EdbInfoType == 0 { //普通指标
- // switch baseEdbInfo.EdbType {
- // case 1: //基础指标
- // baseEdbInfoArr = append(baseEdbInfoArr, baseEdbInfo)
- // case 2: //计算指标
- // calculateList = append(calculateList, baseEdbInfo)
- // }
- // } else { //预测指标
- // switch baseEdbInfo.EdbType {
- // case 1: //基础指标
- // basePredictEdbInfoArr = append(basePredictEdbInfoArr, baseEdbInfo)
- // case 2: //计算指标
- // predictCalculateInfoArr = append(predictCalculateInfoArr, baseEdbInfo)
- // }
- // }
- //
- // // 计算指标
- // for _, v := range calculateList {
- // getBaseEdbInfoArr, getCalculateInfoArr, tmpErr := data_manage.GetRefreshEdbInfoFromBase(v.EdbInfoId, v.Source)
- // if tmpErr != nil {
- // err = tmpErr
- // fmt.Println("GetRefreshEdbInfoFromBase err:" + err.Error())
- // errMsg = "获取需要刷新的指标失败:Err:" + err.Error()
- // return
- // }
- // for _, tmpEdbInfo := range getBaseEdbInfoArr {
- // switch tmpEdbInfo.EdbInfoType {
- // case 0: //普通基础指标
- // baseEdbInfoArr = append(baseEdbInfoArr, tmpEdbInfo)
- // case 1: //预测基础指标
- // basePredictEdbInfoArr = append(basePredictEdbInfoArr, tmpEdbInfo)
- // }
- // }
- //
- // for _, tmpEdbInfo := range getCalculateInfoArr {
- // switch tmpEdbInfo.EdbInfoType {
- // case 0: //普通运算指标
- // calculateInfoArr = append(calculateInfoArr, tmpEdbInfo)
- // case 1: //预测运算指标
- // predictCalculateInfoArr = append(predictCalculateInfoArr, tmpEdbInfo)
- // }
- // }
- // switch v.EdbInfoType {
- // case 0: //普通运算指标
- // calculateInfoArr = append(calculateInfoArr, v)
- // case 1: //预测运算指标
- // predictCalculateInfoArr = append(predictCalculateInfoArr, v)
- // }
- // }
- //
- // // 预测计算指标
- // for _, v := range predictCalculateInfoArr {
- // getBaseEdbInfoArr, getCalculateInfoArr, tmpErr := data_manage.GetRefreshEdbInfoFromBase(v.EdbInfoId, v.Source)
- // if tmpErr != nil {
- // err = tmpErr
- // fmt.Println("GetRefreshEdbInfoFromBase err:" + err.Error())
- // errMsg = "获取需要刷新的指标失败:Err:" + err.Error()
- // return
- // }
- // for _, tmpEdbInfo := range getBaseEdbInfoArr {
- // switch tmpEdbInfo.EdbInfoType {
- // case 0: //普通基础指标
- // baseEdbInfoArr = append(baseEdbInfoArr, tmpEdbInfo)
- // case 1: //预测基础指标
- // basePredictEdbInfoArr = append(basePredictEdbInfoArr, tmpEdbInfo)
- // }
- // }
- //
- // for _, tmpEdbInfo := range getCalculateInfoArr {
- // switch tmpEdbInfo.EdbInfoType {
- // case 0: //普通运算指标
- // calculateInfoArr = append(calculateInfoArr, tmpEdbInfo)
- // case 1: //预测运算指标
- // predictCalculateInfoArr = append(predictCalculateInfoArr, tmpEdbInfo)
- // }
- // }
- // switch v.EdbInfoType {
- // case 0: //普通运算指标
- // calculateInfoArr = append(calculateInfoArr, v)
- // case 1: //预测运算指标
- // predictCalculateInfoArr = append(predictCalculateInfoArr, v)
- // }
- // }
- //
- // // 第一次的计算指标map
- // newCalculateMap = make(map[int]*data_manage.EdbInfo)
- // for _, v := range calculateInfoArr {
- // if _, ok := newCalculateMap[v.EdbInfoId]; !ok {
- // calculateArr = append(calculateArr, v.EdbInfoId)
- // }
- // newCalculateMap[v.EdbInfoId] = v
- // }
- //
- // // 基础预测指标
- // if len(basePredictEdbInfoArr) > 0 {
- // basePredictEdbInfoIdList := make([]int, 0)
- // for _, v := range basePredictEdbInfoArr {
- // basePredictEdbInfoIdList = append(basePredictEdbInfoIdList, v.EdbInfoId)
- // }
- // baseEdbInfoList, tmpErr := data_manage.GetPredictEdbInfoAllCalculate(basePredictEdbInfoIdList)
- // if tmpErr != nil {
- // err = tmpErr
- // return
- // }
- //
- // tmpCalculateList := make([]*data_manage.EdbInfo, 0)
- // for _, v := range baseEdbInfoList {
- // switch v.EdbType {
- // case 1:
- // baseEdbInfoArr = append(baseEdbInfoArr, v)
- // case 2:
- // // 如果不在第一次里面,那么在第二次 刷新预测指标的时候 需要加进去
- // if _, ok := newCalculateMap[v.EdbInfoId]; !ok {
- // tmpCalculateList = append(tmpCalculateList, v)
- // }
- // }
- // }
- //
- // // 这里是查询预测指标用到的 普通计算指标
- // for _, v := range tmpCalculateList {
- // getBaseEdbInfoArr, getCalculateInfoArr, tmpErr := data_manage.GetRefreshEdbInfoFromBase(v.EdbInfoId, v.Source)
- // if tmpErr != nil {
- // err = tmpErr
- // fmt.Println("GetRefreshEdbInfoFromBase err:" + err.Error())
- // errMsg = "获取需要刷新的指标失败:Err:" + err.Error()
- // return
- // }
- //
- // // 基础指标
- // for _, tmpEdbInfo := range getBaseEdbInfoArr {
- // switch tmpEdbInfo.EdbInfoType {
- // case 0: //普通基础指标
- // baseEdbInfoArr = append(baseEdbInfoArr, tmpEdbInfo)
- // case 1: //预测基础指标
- // basePredictEdbInfoArr = append(basePredictEdbInfoArr, tmpEdbInfo)
- // }
- // }
- //
- // // 计算指标
- // for _, tmpEdbInfo := range getCalculateInfoArr {
- // switch tmpEdbInfo.EdbInfoType {
- // case 0: //普通运算指标
- // calculateInfoArr = append(calculateInfoArr, tmpEdbInfo)
- // case 1: //预测运算指标
- // predictCalculateInfoArr = append(predictCalculateInfoArr, tmpEdbInfo)
- // }
- // }
- // switch v.EdbInfoType {
- // case 0: //普通运算指标
- // calculateInfoArr = append(calculateInfoArr, v)
- // case 1: //预测运算指标
- // predictCalculateInfoArr = append(predictCalculateInfoArr, v)
- // }
- // }
- //
- // // 第二次计算指标的map
- // for _, v := range calculateInfoArr {
- // if _, ok := newCalculateMap[v.EdbInfoId]; !ok {
- // calculateArr = append(calculateArr, v.EdbInfoId)
- // }
- // newCalculateMap[v.EdbInfoId] = v
- // }
- // }
- //
- // // 普通基础指标去重
- // newBaseEdbInfoArr = make([]*data_manage.EdbInfo, 0)
- // baseMap := make(map[int]int)
- // for _, v := range baseEdbInfoArr {
- // if _, ok := baseMap[v.EdbInfoId]; !ok {
- // newBaseEdbInfoArr = append(newBaseEdbInfoArr, v)
- // }
- // baseMap[v.EdbInfoId] = v.EdbInfoId
- // }
- //
- // // 普通计算指标的id
- // sort.Ints(calculateArr)
- //
- // // 预测计算指标去重
- // newPredictCalculateMap = make(map[int]*data_manage.EdbInfo)
- // for _, v := range predictCalculateInfoArr {
- // if _, ok := newPredictCalculateMap[v.EdbInfoId]; !ok {
- // predictCalculateArr = append(predictCalculateArr, v.EdbInfoId)
- // }
- // newPredictCalculateMap[v.EdbInfoId] = v
- // }
- // // 预测计算指标的id
- // sort.Ints(predictCalculateArr)
- //
- // return
- //}
- // getRefreshEdbInfoList 获取待更新的指标(普通基础指标、普通运算指标,预测运算指标)
- func getRefreshEdbInfoListByIds(edbInfoIdList []int) (newBaseEdbInfoArr, newBasePredictEdbInfoArr []*data_manage.EdbInfo, newCalculateMap, newPredictCalculateMap map[int]*data_manage.EdbInfo, calculateArr, predictCalculateArr []int, err error, errMsg string) {
- calculateList, err := data_manage.GetEdbInfoAllCalculateByEdbInfoIdList(edbInfoIdList)
- if err != nil && err.Error() != utils.ErrNoRow() {
- err = errors.New("GetEdbInfoAllCalculate Err:" + err.Error())
- return
- }
- // 获取指标信息
- edbInfoList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
- if err != nil {
- err = errors.New("GetEdbInfoAllCalGetEdbInfoByIdr:" + err.Error())
- return
- }
- baseEdbInfoArr := make([]*data_manage.EdbInfo, 0) // 基础普通指标
- calculateInfoArr := make([]*data_manage.EdbInfo, 0) //基础运算指标
- basePredictEdbInfoArr := make([]*data_manage.EdbInfo, 0) // 预测普通指标
- predictCalculateInfoArr := make([]*data_manage.EdbInfo, 0) //预测运算指标
- for _, baseEdbInfo := range edbInfoList {
- if baseEdbInfo.EdbInfoType == 0 { //普通指标
- switch baseEdbInfo.EdbType {
- case 1: //基础指标
- baseEdbInfoArr = append(baseEdbInfoArr, baseEdbInfo)
- case 2: //计算指标
- calculateList = append(calculateList, baseEdbInfo)
- }
- } else { //预测指标
- switch baseEdbInfo.EdbType {
- case 1: //基础指标
- basePredictEdbInfoArr = append(basePredictEdbInfoArr, baseEdbInfo)
- case 2: //计算指标
- predictCalculateInfoArr = append(predictCalculateInfoArr, baseEdbInfo)
- }
- }
- }
- // 计算指标
- for _, v := range calculateList {
- getBaseEdbInfoArr, getCalculateInfoArr, tmpErr := data_manage.GetRefreshEdbInfoFromBase(v.EdbInfoId, v.Source)
- if tmpErr != nil {
- err = tmpErr
- fmt.Println("GetRefreshEdbInfoFromBase err:" + err.Error())
- errMsg = "获取需要刷新的指标失败:Err:" + err.Error()
- return
- }
- for _, tmpEdbInfo := range getBaseEdbInfoArr {
- switch tmpEdbInfo.EdbInfoType {
- case 0: //普通基础指标
- baseEdbInfoArr = append(baseEdbInfoArr, tmpEdbInfo)
- case 1: //预测基础指标
- basePredictEdbInfoArr = append(basePredictEdbInfoArr, tmpEdbInfo)
- }
- }
- for _, tmpEdbInfo := range getCalculateInfoArr {
- switch tmpEdbInfo.EdbInfoType {
- case 0: //普通运算指标
- calculateInfoArr = append(calculateInfoArr, tmpEdbInfo)
- case 1: //预测运算指标
- //predictCalculateInfoArr = append(predictCalculateInfoArr, tmpEdbInfo)
- if tmpEdbInfo.EdbType == 1 { //预测普通指标
- basePredictEdbInfoArr = append(basePredictEdbInfoArr, tmpEdbInfo)
- } else {
- predictCalculateInfoArr = append(predictCalculateInfoArr, tmpEdbInfo)
- }
- }
- }
- switch v.EdbInfoType {
- case 0: //普通运算指标
- calculateInfoArr = append(calculateInfoArr, v)
- case 1: //预测指标
- if v.EdbType == 1 { //预测普通指标
- basePredictEdbInfoArr = append(basePredictEdbInfoArr, v)
- } else {
- predictCalculateInfoArr = append(predictCalculateInfoArr, v)
- }
- }
- }
- // 预测计算指标
- for _, v := range predictCalculateInfoArr {
- getBaseEdbInfoArr, getCalculateInfoArr, tmpErr := data_manage.GetRefreshEdbInfoFromBase(v.EdbInfoId, v.Source)
- if tmpErr != nil {
- err = tmpErr
- fmt.Println("GetRefreshEdbInfoFromBase err:" + err.Error())
- errMsg = "获取需要刷新的指标失败:Err:" + err.Error()
- return
- }
- for _, tmpEdbInfo := range getBaseEdbInfoArr {
- switch tmpEdbInfo.EdbInfoType {
- case 0: //普通基础指标
- baseEdbInfoArr = append(baseEdbInfoArr, tmpEdbInfo)
- case 1: //预测基础指标
- if tmpEdbInfo.EdbType == 1 { //预测普通指标
- basePredictEdbInfoArr = append(basePredictEdbInfoArr, tmpEdbInfo)
- } else {
- predictCalculateInfoArr = append(predictCalculateInfoArr, tmpEdbInfo)
- }
- //basePredictEdbInfoArr = append(basePredictEdbInfoArr, tmpEdbInfo)
- }
- }
- for _, tmpEdbInfo := range getCalculateInfoArr {
- switch tmpEdbInfo.EdbInfoType {
- case 0: //普通运算指标
- calculateInfoArr = append(calculateInfoArr, tmpEdbInfo)
- case 1: //预测运算指标
- if tmpEdbInfo.EdbType == 1 { //预测普通指标
- basePredictEdbInfoArr = append(basePredictEdbInfoArr, tmpEdbInfo)
- } else {
- predictCalculateInfoArr = append(predictCalculateInfoArr, tmpEdbInfo)
- }
- //predictCalculateInfoArr = append(predictCalculateInfoArr, tmpEdbInfo)
- }
- }
- switch v.EdbInfoType {
- case 0: //普通运算指标
- calculateInfoArr = append(calculateInfoArr, v)
- case 1: //预测指标
- if v.EdbType == 1 { //预测普通指标
- basePredictEdbInfoArr = append(basePredictEdbInfoArr, v)
- } else {
- predictCalculateInfoArr = append(predictCalculateInfoArr, v)
- }
- }
- }
- // 第一次的计算指标map
- newCalculateMap = make(map[int]*data_manage.EdbInfo)
- for _, v := range calculateInfoArr {
- if _, ok := newCalculateMap[v.EdbInfoId]; !ok {
- calculateArr = append(calculateArr, v.EdbInfoId)
- }
- newCalculateMap[v.EdbInfoId] = v
- }
- // 基础预测指标
- if len(basePredictEdbInfoArr) > 0 {
- basePredictEdbInfoIdList := make([]int, 0)
- for _, v := range basePredictEdbInfoArr {
- basePredictEdbInfoIdList = append(basePredictEdbInfoIdList, v.EdbInfoId)
- }
- baseEdbInfoList, tmpErr := data_manage.GetPredictEdbInfoAllCalculate(basePredictEdbInfoIdList)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- tmpCalculateList := make([]*data_manage.EdbInfo, 0)
- for _, v := range baseEdbInfoList {
- switch v.EdbType {
- case 1:
- baseEdbInfoArr = append(baseEdbInfoArr, v)
- case 2:
- // 如果不在第一次里面,那么在第二次 刷新预测指标的时候 需要加进去
- if _, ok := newCalculateMap[v.EdbInfoId]; !ok {
- tmpCalculateList = append(tmpCalculateList, v)
- }
- }
- }
- // 这里是查询预测指标用到的 普通计算指标
- for _, v := range tmpCalculateList {
- getBaseEdbInfoArr, getCalculateInfoArr, tmpErr := data_manage.GetRefreshEdbInfoFromBase(v.EdbInfoId, v.Source)
- if tmpErr != nil {
- err = tmpErr
- fmt.Println("GetRefreshEdbInfoFromBase err:" + err.Error())
- errMsg = "获取需要刷新的指标失败:Err:" + err.Error()
- return
- }
- // 基础指标
- for _, tmpEdbInfo := range getBaseEdbInfoArr {
- switch tmpEdbInfo.EdbInfoType {
- case 0: //普通基础指标
- baseEdbInfoArr = append(baseEdbInfoArr, tmpEdbInfo)
- case 1: //预测基础指标
- basePredictEdbInfoArr = append(basePredictEdbInfoArr, tmpEdbInfo)
- }
- }
- // 计算指标
- for _, tmpEdbInfo := range getCalculateInfoArr {
- switch tmpEdbInfo.EdbInfoType {
- case 0: //普通运算指标
- calculateInfoArr = append(calculateInfoArr, tmpEdbInfo)
- case 1: //预测运算指标
- if v.EdbType == 1 { //预测普通指标
- basePredictEdbInfoArr = append(basePredictEdbInfoArr, tmpEdbInfo)
- } else {
- predictCalculateInfoArr = append(predictCalculateInfoArr, tmpEdbInfo)
- }
- }
- }
- switch v.EdbInfoType {
- case 0: //普通运算指标
- calculateInfoArr = append(calculateInfoArr, v)
- case 1: //预测指标
- if v.EdbType == 1 { //预测普通指标
- basePredictEdbInfoArr = append(basePredictEdbInfoArr, v)
- } else { //预测运算指标
- predictCalculateInfoArr = append(predictCalculateInfoArr, v)
- }
- }
- }
- // 第二次计算指标的map
- for _, v := range calculateInfoArr {
- if _, ok := newCalculateMap[v.EdbInfoId]; !ok {
- calculateArr = append(calculateArr, v.EdbInfoId)
- }
- newCalculateMap[v.EdbInfoId] = v
- }
- }
- // 普通基础指标去重
- newBaseEdbInfoArr = make([]*data_manage.EdbInfo, 0)
- baseMap := make(map[int]int)
- for _, v := range baseEdbInfoArr {
- if _, ok := baseMap[v.EdbInfoId]; !ok {
- newBaseEdbInfoArr = append(newBaseEdbInfoArr, v)
- }
- baseMap[v.EdbInfoId] = v.EdbInfoId
- }
- // 普通计算指标的id
- sort.Ints(calculateArr)
- // 普通预测指标去重
- newBasePredictEdbInfoArr = make([]*data_manage.EdbInfo, 0)
- basePredictMap := make(map[int]int)
- for _, v := range basePredictEdbInfoArr {
- if _, ok := basePredictMap[v.EdbInfoId]; !ok {
- newBasePredictEdbInfoArr = append(newBasePredictEdbInfoArr, v)
- }
- basePredictMap[v.EdbInfoId] = v.EdbInfoId
- }
- // 预测计算指标去重
- newPredictCalculateMap = make(map[int]*data_manage.EdbInfo)
- for _, v := range predictCalculateInfoArr {
- if _, ok := newPredictCalculateMap[v.EdbInfoId]; !ok {
- predictCalculateArr = append(predictCalculateArr, v.EdbInfoId)
- }
- newPredictCalculateMap[v.EdbInfoId] = v
- }
- // 预测计算指标的id
- sort.Ints(predictCalculateArr)
- return
- }
- // GetMoveEdbChartList 获取待转移的指标/图表列表
- // @param source 来源 :1:手工数据指标 2:钢联化工数据库 3:ETA指标库 4:ETA预测指标 5:图库
- func GetMoveEdbChartList(source, userId int, keyword, classify string, startSize, pageSize int) (list []data_manage.MoveEdbChartList, total int, err error) {
- var condition string
- var pars []interface{}
- switch source {
- case 1: //手工数据指标
- if keyword != "" {
- condition += ` AND (a.SEC_NAME LIKE ? OR a.TRADE_CODE like ? ) `
- pars = append(pars, `%`+keyword+`%`, `%`+keyword+`%`)
- }
- if userId > 0 {
- condition += ` AND a.user_id = ? `
- pars = append(pars, userId)
- }
- if classify != "" {
- condition += ` AND a.classify_id IN (` + classify + `) `
- }
- total, err = models.GetEdbinfoListCount(condition, pars, "", 0)
- if err != nil {
- return
- }
- tmpList, tmpErr := models.GetEdbinfoList(condition, pars, startSize, pageSize, "", 0)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- if len(tmpList) > 0 {
- adminIdList := make([]int, 0)
- for _, v := range tmpList {
- adminIdList = append(adminIdList, v.UserId)
- }
- adminList, tmpErr := system.GetAdminListByIdListWithoutEnable(adminIdList)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- adminMap := make(map[int]string)
- for _, adminInfo := range adminList {
- adminMap[adminInfo.AdminId] = adminInfo.RealName
- }
- for _, v := range tmpList {
- list = append(list, data_manage.MoveEdbChartList{
- DataId: v.TradeCode,
- Code: v.TradeCode,
- Name: v.SecName,
- ClassifyName: v.ClassifyName,
- CreateUserId: v.UserId,
- CreateUserName: adminMap[v.UserId],
- })
- }
- }
- case 2: //钢联化工数据库
- if keyword != `` {
- condition += " AND (index_name like ? OR index_code like ?) "
- pars = append(pars, "%"+keyword+"%", "%"+keyword+"%")
- }
- if userId > 0 {
- condition += ` AND sys_user_id = ? `
- pars = append(pars, userId)
- }
- if classify != "" {
- condition += ` AND base_from_mysteel_chemical_classify_id IN (` + classify + `) `
- }
- total, err = data_manage.GetMysteelChemicalIndexCount(condition, pars)
- if err != nil {
- return
- }
- tmpList, tmpErr := data_manage.GetMysteelChemicalIndexList(condition, pars, startSize, pageSize)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- for _, v := range tmpList {
- list = append(list, data_manage.MoveEdbChartList{
- DataId: strconv.Itoa(v.BaseFromMysteelChemicalIndexId),
- Code: v.IndexCode,
- Name: v.IndexName,
- //ClassifyName: v.,
- CreateUserId: v.SysUserId,
- CreateUserName: v.SysUserRealName,
- })
- }
- case 3, 4: //ETA指标库、ETA预测指标
- if keyword != `` {
- condition += " AND (edb_code like ? OR edb_name like ?) "
- pars = append(pars, "%"+keyword+"%", "%"+keyword+"%")
- }
- if userId > 0 {
- condition += ` AND sys_user_id = ? `
- pars = append(pars, userId)
- }
- if classify != "" {
- condition += ` AND classify_id IN (` + classify + `) `
- }
- edbInfoType := 0 //ETA指标库
- if source == 4 { //ETA预测指标
- edbInfoType = 1
- }
- condition += ` AND edb_info_type = ? `
- pars = append(pars, edbInfoType)
- total, err = data_manage.GetEdbInfoByConditionCount(condition, pars)
- if err != nil {
- return
- }
- tmpList, tmpErr := data_manage.GetEdbInfoListByCondition(condition, pars, startSize, pageSize)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- for _, v := range tmpList {
- list = append(list, data_manage.MoveEdbChartList{
- DataId: strconv.Itoa(v.EdbInfoId),
- Code: v.EdbCode,
- Name: v.EdbName,
- //ClassifyName: v.,
- CreateUserId: v.SysUserId,
- CreateUserName: v.SysUserRealName,
- })
- }
- case 5: //图库
- if keyword != `` {
- condition += " AND chart_name like ? "
- pars = append(pars, "%"+keyword+"%")
- }
- if userId > 0 {
- condition += ` AND sys_user_id = ? `
- pars = append(pars, userId)
- }
- if classify != "" {
- condition += ` AND chart_classify_id IN (` + classify + `) `
- }
- total, err = data_manage.GetChartInfoCountByCondition(condition, pars)
- if err != nil {
- return
- }
- tmpList, tmpErr := data_manage.GetChartInfoListByCondition(condition, pars, startSize, pageSize)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- // 获取所有的图表分类
- firstClassifyList, tmpErr := data_manage.GetChartClassifyByParentId(0, 1)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- firstClassifyNameMap := make(map[int]string)
- for _, v := range firstClassifyList {
- firstClassifyNameMap[v.ChartClassifyId] = v.ChartClassifyName
- }
- secondClassList, tmpErr := data_manage.GetChartClassifyAll(1)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- secondClassifyNameMap := make(map[int]string)
- for _, v := range secondClassList {
- firstName := firstClassifyNameMap[v.ParentId]
- if firstName != `` {
- firstName = firstName + " / "
- }
- secondClassifyNameMap[v.ChartClassifyId] = firstName + v.ChartClassifyName
- }
- for _, v := range tmpList {
- list = append(list, data_manage.MoveEdbChartList{
- DataId: strconv.Itoa(v.ChartInfoId),
- Name: v.ChartName,
- ClassifyName: secondClassifyNameMap[v.ChartClassifyId],
- CreateUserId: v.SysUserId,
- CreateUserName: v.SysUserRealName,
- })
- }
- default:
- return
- }
- return
- }
- // MoveEdbChart 转移指标/图表创建人
- // @param source 来源 :1:手工数据指标 2:钢联化工数据库 3:ETA指标库 4:ETA预测指标 5:图库
- func MoveEdbChart(source, userId int, dataId []string) (err error, errMsg string) {
- adminInfo, err := system.GetSysAdminById(userId)
- if err != nil {
- return
- }
- switch source {
- case 1: //手工数据指标
- tmpList, tmpErr := models.GetEdbinfoListByCodeListGroupByUserId(dataId)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- if len(tmpList) > 0 {
- for _, v := range tmpList {
- if v.UserId == userId {
- errMsg = "新创建人不可和原创建人一致"
- err = errors.New(errMsg)
- return
- }
- }
- // 修改创建人
- err = models.ModifyEdbinfoUserIdByCodeList(dataId, userId)
- }
- case 2: //钢联化工数据库
- tmpList, tmpErr := data_manage.GetMysteelChemicalIndexListGroupByUserId(dataId)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- if len(tmpList) > 0 {
- for _, v := range tmpList {
- if v.SysUserId == userId {
- errMsg = "新创建人不可和原创建人一致"
- err = errors.New(errMsg)
- return
- }
- }
- // 修改创建人
- err = data_manage.ModifyMysteelChemicalIndexUserIdByCodeList(dataId, adminInfo.AdminId, adminInfo.RealName)
- }
- case 3, 4: //ETA指标库、ETA预测指标
- tmpList, tmpErr := data_manage.GetEdbInfoListGroupByUserId(dataId)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- if len(tmpList) > 0 {
- for _, v := range tmpList {
- if v.SysUserId == userId {
- errMsg = "新创建人不可和原创建人一致"
- err = errors.New(errMsg)
- return
- }
- }
- // 修改创建人
- err = data_manage.ModifyEdbInfoUserIdByCodeList(dataId, adminInfo.AdminId, adminInfo.RealName)
- // 移除当前用户的不可操作权限
- {
- obj := data_manage.EdbInfoNoPermissionAdmin{}
- for _, v := range dataId {
- edbInfoId, _ := strconv.Atoi(v)
- go obj.DeleteByEdbInfoIdAndAdminId(edbInfoId, adminInfo.AdminId)
- }
- }
- }
- case 5: //图库
- tmpList, tmpErr := data_manage.GetChartInfoListGroupByUserId(dataId)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- if len(tmpList) > 0 {
- for _, v := range tmpList {
- if v.SysUserId == userId {
- errMsg = "新创建人不可和原创建人一致"
- err = errors.New(errMsg)
- return
- }
- }
- // 修改创建人
- err = data_manage.ModifyChartInfoUserIdByCodeList(dataId, adminInfo.AdminId, adminInfo.RealName)
- }
- default:
- return
- }
- return
- }
- func GetEdbChartClassifyList(source int) (resp data_manage.EdbChartClassifyResp, err error) {
- switch source {
- case 1: //手工数据指标
- list, e := models.GetEdbdataClassify(0)
- if e != nil {
- err = e
- return
- }
- for _, v := range list {
- item := data_manage.EdbChartClassify{
- ClassifyId: v.ClassifyId,
- ClassifyName: v.ClassifyName,
- ParentId: v.ParentId,
- }
- for _, v2 := range v.Child {
- child := data_manage.EdbChartClassify{
- ClassifyId: v2.ClassifyId,
- ClassifyName: v2.ClassifyName,
- ParentId: v2.ParentId,
- }
- item.Child = append(item.Child, &child)
- }
- resp.List = append(resp.List, &item)
- }
- case 2: //钢联化工数据库
- rootList, e := data_manage.GetBaseFromMysteelChemicalClassifyByParentId(0)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = e
- return
- }
- classifyAll, e := data_manage.GetAllBaseFromMysteelChemicalClassify()
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = e
- return
- }
- rootChildMap := make(map[int][]*data_manage.BaseFromMysteelChemicalClassifyItems)
- for _, v := range classifyAll {
- rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
- }
- nodeAll := make([]*data_manage.BaseFromMysteelChemicalClassifyItems, 0)
- for _, v := range rootList {
- if existItems, ok := rootChildMap[v.BaseFromMysteelChemicalClassifyId]; ok {
- v.Children = existItems
- } else {
- items := make([]*data_manage.BaseFromMysteelChemicalClassifyItems, 0)
- v.Children = items
- }
- nodeAll = append(nodeAll, v)
- }
- for _, v := range nodeAll {
- item := data_manage.EdbChartClassify{
- ClassifyId: v.BaseFromMysteelChemicalClassifyId,
- ClassifyName: v.ClassifyName,
- ParentId: v.ParentId,
- }
- for _, v2 := range v.Children {
- child := data_manage.EdbChartClassify{
- ClassifyId: v2.BaseFromMysteelChemicalClassifyId,
- ClassifyName: v2.ClassifyName,
- ParentId: v2.ParentId,
- }
- item.Child = append(item.Child, &child)
- }
- resp.List = append(resp.List, &item)
- }
- case 3: //ETA指标库
- rootList, e := data_manage.GetEdbClassifyByParentId(0, 0)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = e
- return
- }
- classifyAll, e := data_manage.GetEdbClassifyAll()
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = e
- return
- }
- rootChildMap := make(map[int][]*data_manage.EdbClassifyItems)
- for _, v := range classifyAll {
- rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
- }
- nodeAll := make([]*data_manage.EdbClassifyItems, 0)
- for _, v := range rootList {
- if existItems, ok := rootChildMap[v.ClassifyId]; ok {
- v.Children = existItems
- } else {
- items := make([]*data_manage.EdbClassifyItems, 0)
- v.Children = items
- }
- nodeAll = append(nodeAll, v)
- }
- for _, v := range nodeAll {
- item := data_manage.EdbChartClassify{
- ClassifyId: v.ClassifyId,
- ClassifyName: v.ClassifyName,
- ParentId: v.ParentId,
- }
- for _, v2 := range v.Children {
- child := data_manage.EdbChartClassify{
- ClassifyId: v2.ClassifyId,
- ClassifyName: v2.ClassifyName,
- ParentId: v2.ParentId,
- }
- item.Child = append(item.Child, &child)
- }
- resp.List = append(resp.List, &item)
- }
- case 4: //ETA预测指标
- rootList, e := data_manage.GetEdbClassifyByParentId(0, 1)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = e
- return
- }
- nodeAll := make([]*data_manage.EdbClassifyItems, 0)
- for _, v := range rootList {
- nodeAll = append(nodeAll, v)
- }
- for _, v := range nodeAll {
- item := data_manage.EdbChartClassify{
- ClassifyId: v.ClassifyId,
- ClassifyName: v.ClassifyName,
- ParentId: v.ParentId,
- }
- for _, v2 := range v.Children {
- child := data_manage.EdbChartClassify{
- ClassifyId: v2.ClassifyId,
- ClassifyName: v2.ClassifyName,
- ParentId: v2.ParentId,
- }
- item.Child = append(item.Child, &child)
- }
- resp.List = append(resp.List, &item)
- }
- case 5: //图库
- //判断是否存在缓存,如果存在缓存,那么直接从缓存中获取
- key := utils.CACHE_CHART_CLASSIFY
- if utils.Re == nil {
- if utils.Re == nil && utils.Rc.IsExist(key) {
- rep := new(data_manage.ChartClassifyListResp)
- if data, err1 := utils.Rc.RedisBytes(key); err1 == nil {
- e := json.Unmarshal(data, &rep)
- if e == nil && rep != nil {
- for _, v := range rep.AllNodes {
- item := data_manage.EdbChartClassify{
- ClassifyId: v.ChartClassifyId,
- ClassifyName: v.ChartClassifyName,
- ParentId: v.ParentId,
- }
- for _, v2 := range v.Children {
- child := data_manage.EdbChartClassify{
- ClassifyId: v2.ChartClassifyId,
- ClassifyName: v2.ChartClassifyName,
- ParentId: v2.ParentId,
- }
- item.Child = append(item.Child, &child)
- }
- resp.List = append(resp.List, &item)
- }
- fmt.Println("source redis")
- return
- }
- }
- }
- }
- rootList, e := data_manage.GetChartClassifyByParentIdFromETA(0)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = e
- return
- }
- classifyAll, e := data_manage.GetChartClassifyAllFromETA()
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = e
- return
- }
- rootChildMap := make(map[int][]*data_manage.ChartClassifyItems)
- for _, v := range classifyAll {
- rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
- }
- nodeAll := make([]*data_manage.ChartClassifyItems, 0)
- for _, v := range rootList {
- if existItems, ok := rootChildMap[v.ChartClassifyId]; ok {
- v.Children = existItems
- } else {
- items := make([]*data_manage.ChartClassifyItems, 0)
- v.Children = items
- }
- nodeAll = append(nodeAll, v)
- }
- for _, v := range nodeAll {
- item := data_manage.EdbChartClassify{
- ClassifyId: v.ChartClassifyId,
- ClassifyName: v.ChartClassifyName,
- ParentId: v.ParentId,
- }
- for _, v2 := range v.Children {
- child := data_manage.EdbChartClassify{
- ClassifyId: v2.ChartClassifyId,
- ClassifyName: v2.ChartClassifyName,
- ParentId: v2.ParentId,
- }
- item.Child = append(item.Child, &child)
- }
- resp.List = append(resp.List, &item)
- }
- // 将数据加入缓存
- if utils.Re == nil {
- utils.Rc.Delete(key)
- }
- default:
- return
- }
- return
- }
- // EdbInfoAdd 添加指标到指标库
- 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) {
- isSendEmail = true
- //判断指标名称是否存在
- var condition string
- var pars []interface{}
- //condition += " AND source=? "
- //pars = append(pars, source)
- condition += " AND edb_name=? "
- pars = append(pars, edbName)
- count, err := data_manage.GetEdbInfoCountByCondition(condition, pars)
- if err != nil {
- errMsg = "判断指标名称是否存在失败"
- err = errors.New("判断指标名称是否存在失败,Err:" + err.Error())
- return
- }
- if count > 0 {
- errMsg = "指标名称已存在,请重新填写"
- err = errors.New(errMsg)
- isSendEmail = false
- return
- }
- edbInfo = new(data_manage.EdbInfo)
- edbInfo.Source = source
- sourceNameMap := map[int]string{
- utils.DATA_SOURCE_THS: "同花顺",
- utils.DATA_SOURCE_WIND: "wind",
- utils.DATA_SOURCE_PB: "彭博",
- utils.DATA_SOURCE_PB_FINANCE: "彭博财务",
- utils.DATA_SOURCE_MANUAL: "手工数据",
- utils.DATA_SOURCE_LZ: "隆众",
- utils.DATA_SOURCE_YS: "SMM",
- utils.DATA_SOURCE_GL: "钢联",
- utils.DATA_SOURCE_ZZ: "郑商所",
- utils.DATA_SOURCE_DL: "大商所",
- utils.DATA_SOURCE_SH: "上期所",
- utils.DATA_SOURCE_CFFEX: "中金所",
- utils.DATA_SOURCE_SHFE: "上期能源",
- utils.DATA_SOURCE_GIE: "欧洲天然气",
- utils.DATA_SOURCE_LT: "路透",
- utils.DATA_SOURCE_COAL: "中国煤炭网",
- utils.DATA_SOURCE_GOOGLE_TRAVEL: "our world in data",
- utils.DATA_SOURCE_MYSTEEL_CHEMICAL: "钢联化工",
- utils.DATA_SOURCE_EIA_STEO: "EIA STEO报告",
- utils.DATA_SOURCE_COM_TRADE: "UN",
- utils.DATA_SOURCE_SCI: "SCI",
- utils.DATA_SOURCE_BAIINFO: "BAIINFO",
- utils.DATA_SOURCE_STOCK_PLANT: "存量装置",
- utils.DATA_SOURCE_NATIONAL_STATISTICS: "国家统计局",
- utils.DATA_SOURCE_FUBAO: "富宝数据",
- }
- sourceName, ok := sourceNameMap[source]
- if !ok {
- errMsg = "指标来源异常"
- err = errors.New(errMsg)
- return
- }
- edbInfo.SourceName = sourceName
- edbType := 1 //基础指标
- if source == utils.DATA_SOURCE_STOCK_PLANT {
- edbType = 2 //计算指标
- }
- //从缓存中获取
- serverUrl := ``
- if edbInfo.Source == utils.DATA_SOURCE_WIND {
- windCacheKey := utils.CACHE_WIND_URL + ":" + edbCode
- serverUrl, _ = utils.Rc.RedisString(windCacheKey)
- if serverUrl == `` {
- if len(utils.Hz_Data_WIND_Url_List) >= 1 {
- serverUrl = utils.Hz_Data_WIND_Url_List[len(utils.Hz_Data_WIND_Url_List)-1] //默认是最后一个服务器地址
- }
- }
- }
- edbInfo.EdbCode = edbCode
- edbInfo.EdbName = edbName
- edbInfo.EdbNameSource = edbName
- edbInfo.Frequency = frequency
- edbInfo.Unit = unit
- edbInfo.StartDate = startDate
- edbInfo.EndDate = endDate
- edbInfo.ClassifyId = classifyId
- edbInfo.SysUserId = sysUserId
- edbInfo.SysUserRealName = sysUserRealName
- edbInfo.CreateTime = time.Now()
- edbInfo.ModifyTime = time.Now()
- edbInfo.ServerUrl = serverUrl
- timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
- edbInfo.UniqueCode = utils.MD5(utils.DATA_PREFIX + "_" + timestamp)
- itemVal, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
- if itemVal != nil && err == nil {
- edbInfo.MaxValue = itemVal.MaxValue
- edbInfo.MinValue = itemVal.MinValue
- }
- edbInfo.EdbType = edbType
- edbInfoId, err := data_manage.AddEdbInfo(edbInfo)
- if err != nil {
- errMsg = "保存失败"
- err = errors.New("保存失败,Err:" + err.Error())
- return
- }
- edbInfo.EdbInfoId = int(edbInfoId)
- //保存数据
- data_manage.ModifyEdbInfoDataStatus(edbInfoId, source, edbCode)
- //处理同名指标
- //{
- // edbNameList, tmpErr := data_manage.GetEdbInfoByName(edbName)
- // if tmpErr != nil {
- // errMsg = "保存失败"
- // err = errors.New("获取指标信息失败,Err:" + tmpErr.Error())
- // return
- // }
- // if len(edbNameList) >= 2 {
- // for _, v := range edbNameList {
- // edbName := v.EdbName + "(" + v.SourceName + ")"
- // err = data_manage.ModifyEdbInfoNameSource(edbName, v.EdbInfoId)
- // if err != nil {
- // errMsg = "保存失败"
- // err = errors.New("修改指标名称失败,Err:" + err.Error())
- // return
- // }
- // }
- // }
- //}
- //上传到ES
- //indexName := utils.DATA_INDEX_NAME
- //docId := strconv.Itoa(int(edbInfoId))
- //
- //go data.EsAddOrEditEdbInfo(indexName, docId, edbInfo)
- maxAndMinItem, _ := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
- if maxAndMinItem != nil {
- err = data_manage.ModifyEdbInfoMaxAndMinInfo(int(edbInfoId), maxAndMinItem)
- }
- //添加es
- AddOrEditEdbInfoToEs(int(edbInfoId))
- return
- }
- // TraceEdbInfoByEdbInfoId 指标追溯
- func TraceEdbInfoByEdbInfoId(edbInfoId int) (traceEdbInfo data_manage.TraceEdbInfoResp, err error) {
- edbInfo, err := data_manage.GetEdbInfoById(edbInfoId)
- if err != nil {
- return
- }
- edbInfoRuleMap := make(map[int]string, 0)
- edbMappingMap := make(map[int][]*data_manage.EdbInfoCalculateMappingInfo)
- //edbInfoRuleMap[edbInfoId] = getEdbRuleTitle(edbInfo)
- traceEdbInfo = data_manage.TraceEdbInfoResp{
- //EdbInfoId: edbInfo.EdbInfoId,
- EdbInfoId: edbInfoId,
- EdbInfoType: edbInfo.EdbInfoType,
- EdbName: edbInfo.EdbName,
- EdbType: edbInfo.EdbType,
- //Source: edbInfo.Source,
- UniqueCode: edbInfo.UniqueCode,
- ClassifyId: edbInfo.ClassifyId,
- }
- findIdMap := make(map[int]int)
- findIdMap[edbInfoId] = edbInfoId
- existMap := make(map[int]data_manage.TraceEdbInfoResp)
- traceEdbInfo.Child, err = traceEdbInfoByEdbInfoId(edbInfoId, traceEdbInfo, edbInfoRuleMap, findIdMap, existMap, edbMappingMap)
- edbInfoIdList := make([]int, 0)
- for _, v := range findIdMap {
- edbInfoIdList = append(edbInfoIdList, v)
- }
- edbInfoList, err := data_manage.GetEdbInfoByIdList(edbInfoIdList)
- if err != nil {
- return
- }
- edbInfoMap := make(map[int]*data_manage.EdbInfo)
- for _, tmpEdbInfo := range edbInfoList {
- edbInfoMap[tmpEdbInfo.EdbInfoId] = tmpEdbInfo
- }
- traceEdbInfo, err = handleTraceEdbInfo(traceEdbInfo, 0, edbInfoMap, edbMappingMap)
- return
- }
- // traceEdbInfoByEdbInfoId 指标追溯
- 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) {
- traceEdbInfo, ok := existMap[edbInfoId]
- if ok {
- return
- }
- child = make([]data_manage.TraceEdbInfoResp, 0)
- edbInfoMappingList, e := data_manage.GetEdbInfoCalculateMappingListByEdbInfoId(edbInfoId)
- if e != nil {
- err = fmt.Errorf("GetEdbInfoCalculateMappingListByEdbInfoId err: %s", e.Error())
- return
- }
- edbMappingMap[edbInfoId] = edbInfoMappingList
- for _, v := range edbInfoMappingList {
- tmpEdbInfoId := v.FromEdbInfoId
- tmpTraceEdbInfo := data_manage.TraceEdbInfoResp{
- EdbInfoId: tmpEdbInfoId,
- EdbInfoType: v.FromEdbInfoType,
- EdbType: v.FromEdbType,
- UniqueCode: v.FromUniqueCode,
- ClassifyId: v.FromClassifyId,
- }
- // 计算指标/预测指标继续溯源
- if v.FromEdbType == 2 || v.FromEdbInfoType == 1 {
- // 查过了就不查了
- if _, ok2 := findIdMap[tmpEdbInfoId]; !ok2 {
- tmpTraceEdbInfo.Child, e = traceEdbInfoByEdbInfoId(tmpEdbInfoId, tmpTraceEdbInfo, edbInfoRuleMap, findIdMap, existMap, edbMappingMap)
- if e != nil {
- err = fmt.Errorf("traceEdbInfoByEdbInfoId err: %s", e.Error())
- return
- }
- }
- }
- child = append(child, tmpTraceEdbInfo)
- findIdMap[tmpEdbInfoId] = tmpEdbInfoId
- }
- existMap[edbInfoId] = traceEdbInfo
- return
- }
- 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) {
- edbInfo, ok := edbInfoMap[traceEdbInfoResp.EdbInfoId]
- if !ok {
- err = errors.New("指标异常")
- return
- }
- var parentEdbInfo *data_manage.EdbInfo
- if parentEdbInfoId > 0 {
- parentEdbInfo, ok = edbInfoMap[parentEdbInfoId]
- if !ok {
- err = errors.New("指标异常")
- return
- }
- }
- //traceEdbInfoResp.EdbName = edbInfo.EdbName
- traceEdbInfoResp.EdbName, traceEdbInfoResp.RuleTitle = getEdbRuleTitle(edbInfo, parentEdbInfo, traceEdbInfoResp.Child, edbInfoMap, edbMappingMap)
- if traceEdbInfoResp.Child != nil && len(traceEdbInfoResp.Child) > 0 {
- for k, v := range traceEdbInfoResp.Child {
- traceEdbInfoResp.Child[k], err = handleTraceEdbInfo(v, traceEdbInfoResp.EdbInfoId, edbInfoMap, edbMappingMap)
- if err != nil {
- return
- }
- }
- }
- newTraceEdbInfoResp = traceEdbInfoResp
- return
- }
- // getEdbRule 获取规则名称
- 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) {
- edbName = edbInfo.EdbName
- ruleTitle = `来源于` + edbInfo.SourceName
- if parentEdbInfo != nil {
- edbMappingList, ok := edbMappingMap[parentEdbInfo.EdbInfoId]
- if !ok {
- edbMappingList = []*data_manage.EdbInfoCalculateMappingInfo{}
- }
- // 指标名称
- switch parentEdbInfo.Source {
- case utils.DATA_SOURCE_CALCULATE, utils.DATA_SOURCE_PREDICT_CALCULATE:
- for _, v := range edbMappingList {
- if v.FromEdbInfoId == edbInfo.EdbInfoId {
- edbName = fmt.Sprintf("%s(%s)", edbInfo.EdbName, v.FromTag)
- }
- }
- case utils.DATA_SOURCE_CALCULATE_ZJPJ, utils.DATA_SOURCE_PREDICT_CALCULATE_ZJPJ, utils.DATA_SOURCE_CALCULATE_LJZTBPJ, utils.DATA_SOURCE_PREDICT_CALCULATE_LJZTBPJ: // 直接拼接 ,累计值同比拼接
- for _, v := range edbMappingList {
- if v.FromEdbInfoId == edbInfo.EdbInfoId {
- tmpName := ``
- if v.FromTag == `A` {
- tmpName = `拼接日期前`
- } else if v.FromTag == `B` {
- tmpName = `拼接日期后`
- }
- edbName = fmt.Sprintf("%s(%s)", edbInfo.EdbName, tmpName)
- }
- }
- case utils.DATA_SOURCE_CALCULATE_NHCC, utils.DATA_SOURCE_PREDICT_CALCULATE_NHCC: //计算指标(拟合残差)
- for _, v := range edbMappingList {
- //(需对上游指标+自变量,领先10天/因变量)
- if v.FromEdbInfoId == edbInfo.EdbInfoId {
- tmpName := ``
- if v.FromTag == `A` {
- tmpName = fmt.Sprintf(`自变量,领先%d天`, v.MoveValue)
- } else if v.FromTag == `B` {
- tmpName = `因变量`
- }
- edbName = fmt.Sprintf("%s(%s)", edbInfo.EdbName, tmpName)
- }
- }
- case utils.DATA_SOURCE_CALCULATE_CORRELATION: // 滚动相关性
- for _, v := range edbMappingList {
- if v.FromEdbInfoId == edbInfo.EdbInfoId {
- edbName = fmt.Sprintf("%s(%s)", edbInfo.EdbName, v.FromTag)
- }
- }
- }
- }
- if edbInfo.EdbType == 1 {
- // 基础指标的话,直接返回来源名称
- //ruleTitle = `来源于`+edbInfo.SourceName
- return
- }
- // 规则
- switch edbInfo.Source {
- case utils.DATA_SOURCE_CALCULATE, utils.DATA_SOURCE_PREDICT_CALCULATE:
- ruleTitle = "=" + edbInfo.CalculateFormula
- case utils.DATA_SOURCE_CALCULATE_LJZZY, utils.DATA_SOURCE_PREDICT_CALCULATE_LJZZY:
- ruleTitle = `累计转月值计算`
- case utils.DATA_SOURCE_CALCULATE_TBZ, utils.DATA_SOURCE_PREDICT_CALCULATE_TBZ:
- ruleTitle = `同比值计算`
- case utils.DATA_SOURCE_CALCULATE_TCZ, utils.DATA_SOURCE_PREDICT_CALCULATE_TCZ:
- ruleTitle = `同差值计算`
- case utils.DATA_SOURCE_CALCULATE_NSZYDPJJS, utils.DATA_SOURCE_PREDICT_CALCULATE_NSZYDPJJS:
- ruleTitle = fmt.Sprintf("N数值移动均值计算(N=%s)", edbInfo.CalculateFormula)
- case utils.DATA_SOURCE_CALCULATE_HBZ, utils.DATA_SOURCE_PREDICT_CALCULATE_HBZ:
- ruleTitle = fmt.Sprintf("N数值环比值计算(N=%s)", edbInfo.CalculateFormula)
- case utils.DATA_SOURCE_CALCULATE_HCZ, utils.DATA_SOURCE_PREDICT_CALCULATE_HCZ:
- ruleTitle = fmt.Sprintf("N数值环差值计算(N=%s)", edbInfo.CalculateFormula)
- case utils.DATA_SOURCE_CALCULATE_TIME_SHIFT, utils.DATA_SOURCE_PREDICT_CALCULATE_TIME_SHIFT:
- moveType := `领先`
- if edbInfo.MoveType == 2 {
- moveType = "滞后"
- }
- ruleTitle = fmt.Sprintf("时间移位计算(%s%s%s)", moveType, edbInfo.CalculateFormula, edbInfo.MoveFrequency)
- case utils.DATA_SOURCE_CALCULATE_BP, utils.DATA_SOURCE_PREDICT_CALCULATE_BP: // 变频
- childFrequency := ``
- if len(childList) > 0 {
- if childEdbInfo, ok := edbInfoMap[childList[0].EdbInfoId]; ok {
- childFrequency = childEdbInfo.Frequency
- }
- }
- ruleTitle = fmt.Sprintf("升频计算(%s转%s)", childFrequency, edbInfo.Frequency)
- case utils.DATA_SOURCE_CALCULATE_ZJPJ, utils.DATA_SOURCE_PREDICT_CALCULATE_ZJPJ: // 直接拼接
- ruleTitle = fmt.Sprintf("直接拼接计算(%s)", edbInfo.CalculateFormula)
- case utils.DATA_SOURCE_CALCULATE_LJZTBPJ, utils.DATA_SOURCE_PREDICT_CALCULATE_LJZTBPJ: // 累计值同比拼
- ruleTitle = fmt.Sprintf("累计值同比值拼接计算(%s)", edbInfo.CalculateFormula)
- case utils.DATA_SOURCE_PYTHON:
- ruleTitle = `代码运算`
- case utils.DATA_SOURCE_CALCULATE_CJJX, utils.DATA_SOURCE_PREDICT_CALCULATE_CJJX:
- ruleTitle = fmt.Sprintf("超季节性计算(N=%s,%s)", edbInfo.CalculateFormula, edbInfo.Calendar)
- case utils.DATA_SOURCE_CALCULATE_NHCC, utils.DATA_SOURCE_PREDICT_CALCULATE_NHCC: //计算指标(拟合残差)
- var startDate, endDate string
- dateList := strings.Split(edbInfo.CalculateFormula, ",")
- if len(dateList) == 2 {
- startDate = dateList[0]
- endDate = dateList[1]
- }
- ruleTitle = fmt.Sprintf("拟合残差计算(%s至%s)", startDate, endDate)
- case utils.DATA_SOURCE_CALCULATE_ADJUST:
- ruleTitle = `数据调整`
- case utils.DATA_SOURCE_CALCULATE_NH, utils.DATA_SOURCE_PREDICT_CALCULATE_NH:
- ruleTitle = `年化计算`
- case utils.DATA_SOURCE_CALCULATE_KSZS, utils.DATA_SOURCE_PREDICT_CALCULATE_KSZS: // 扩散指数->53
- type KszsConfig struct {
- DateType int `description:"扩散指标日期;1:全部指标日期并集;2:部分指标日期并集"`
- CheckList []string `description:"选中的数据,A,B,C"`
- }
- var config KszsConfig
- err := json.Unmarshal([]byte(edbInfo.CalculateFormula), &config)
- if err != nil {
- return
- }
- var startDate, endDate time.Time
- childEdbInfoIdList := make([]int, 0)
- if config.DateType == 1 {
- for _, v := range childList {
- childEdbInfoIdList = append(childEdbInfoIdList, v.EdbInfoId)
- }
- } else {
- edbMappingList, ok := edbMappingMap[parentEdbInfo.EdbInfoId]
- if !ok {
- edbMappingList = []*data_manage.EdbInfoCalculateMappingInfo{}
- }
- tagMap := make(map[string]int)
- for _, v := range edbMappingList {
- tagMap[v.FromTag] = v.FromEdbInfoId
- }
- for _, v := range config.CheckList {
- if tmpEdbInfoId, ok := tagMap[v]; ok {
- childEdbInfoIdList = append(childEdbInfoIdList, tmpEdbInfoId)
- }
- }
- }
- for _, v := range childEdbInfoIdList {
- if childEdbInfo, ok := edbInfoMap[v]; ok {
- tmpStartDate, tmpErr := time.ParseInLocation(utils.FormatDate, childEdbInfo.StartDate, time.Local)
- if tmpErr != nil {
- return
- }
- if startDate.IsZero() || startDate.After(tmpStartDate) {
- startDate = tmpStartDate
- }
- tmpEndDate, tmpErr := time.ParseInLocation(utils.FormatDate, childEdbInfo.EndDate, time.Local)
- if tmpErr != nil {
- return
- }
- if endDate.IsZero() || endDate.Before(tmpEndDate) {
- endDate = tmpEndDate
- }
- }
- }
- ruleTitle = fmt.Sprintf("扩散指数计算(%s至%s)", startDate.Format(utils.FormatDate), endDate.Format(utils.FormatDate))
- case utils.DATA_SOURCE_STOCK_PLANT:
- ruleTitle = `来源于装置分析`
- case utils.DATA_SOURCE_CALCULATE_CORRELATION:
- type EdbCalculateFormula struct {
- BaseCalculateValue int `description:"基础计算窗口"`
- BaseCalculateUnit string `description:"基础计算频度"`
- LeadValue int `description:"领先期数"`
- LeadUnit string `description:"频度"`
- CalculateValue int `description:"计算窗口"`
- CalculateUnit string `description:"计算频度"`
- }
- var correlationConf EdbCalculateFormula
- err := json.Unmarshal([]byte(edbInfo.CalculateFormula), &correlationConf)
- if err != nil {
- return
- }
- ruleTitle = fmt.Sprintf("滚动相关性(计算窗口%d%s,B领先A%d%s)", correlationConf.CalculateValue, correlationConf.CalculateUnit, correlationConf.LeadValue, correlationConf.LeadUnit)
- case utils.DATA_SOURCE_CALCULATE_JP, utils.DATA_SOURCE_PREDICT_CALCULATE_JP:
- childFrequency := ``
- if len(childList) > 0 {
- if childEdbInfo, ok := edbInfoMap[childList[0].EdbInfoId]; ok {
- childFrequency = childEdbInfo.Frequency
- }
- }
- ruleTitle = fmt.Sprintf("降频计算(%s转%s,%s)", childFrequency, edbInfo.Frequency, edbInfo.CalculateFormula)
- case utils.DATA_SOURCE_CALCULATE_STANDARD_DEVIATION:
- ruleTitle = fmt.Sprintf("标准差(滚动%s期)", edbInfo.CalculateFormula)
- case utils.DATA_SOURCE_CALCULATE_PERCENTILE, utils.DATA_SOURCE_PREDICT_CALCULATE_PERCENTILE:
- type TempCalculate struct {
- CalculateValue int `description:"计算窗口"`
- CalculateUnit string `description:"计算频度"`
- }
- cf := TempCalculate{}
- if e := json.Unmarshal([]byte(edbInfo.CalculateFormula), &cf); e != nil {
- return
- }
- ruleTitle = fmt.Sprintf("百分位(时间长度%d%s)", cf.CalculateValue, cf.CalculateUnit)
- }
- return
- }
|