12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006 |
- package data
- import (
- "context"
- "errors"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/http"
- "hongze/hongze_task/models/data_manage"
- "hongze/hongze_task/services/alarm_msg"
- "hongze/hongze_task/utils"
- "strings"
- "sync"
- )
- // 刷新同花顺数据
- func RefreshDataFromThs(wg *sync.WaitGroup) (err error) {
- defer func() {
- if err != nil {
- fmt.Println("RefreshDataFromThs Err:" + err.Error())
- //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromThs ErrMsg:"+err.Error(), utils.EmailSendToUsers)
- go alarm_msg.SendAlarmMsg("RefreshDataFromThs ErrMsg:"+err.Error(), 3)
- }
- wg.Done()
- }()
- var condition string
- var pars []interface{}
- condition += " AND source=? "
- pars = append(pars, utils.DATA_SOURCE_THS)
- items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
- if err != nil {
- err = errors.New("GetEdbInfoByCondition:" + err.Error())
- return
- }
- //var endDate string
- //endDate = time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDate)
- for _, v := range items {
- startDate := ""
- if v.Frequency == "日度" {
- startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- } else if v.Frequency == "周度" {
- startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
- } else if v.Frequency == "月度" {
- startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
- } else if v.Frequency == "季度" {
- startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
- } else if v.Frequency == "年度" {
- startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
- } else {
- startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- }
- //err = SyncEdbDataByThs(int64(v.EdbInfoId), v.EdbCode, startDate, endDate)
- //if err != nil {
- // err = errors.New("SyncEdbDataByThs Err:" + err.Error())
- // return err
- //}
- resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
- if err != nil {
- return errors.New("RefreshEdbData Err:" + err.Error())
- }
- if resp.Ret != 200 {
- return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
- }
- //item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
- //if err != nil {
- // err = errors.New("GetEdbInfoMaxAndMinInfo Err:" + err.Error())
- // return err
- //}
- //if item != nil {
- // err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
- // if err != nil {
- // err = errors.New("ModifyEdbInfoMaxAndMinInfo Err:" + err.Error())
- // return err
- // }
- //}
- }
- return err
- }
- // 刷新万得数据
- func RefreshDataFromWind(wg *sync.WaitGroup) (err error) {
- defer func() {
- if err != nil {
- fmt.Println("RefreshDataFromWind Err:" + err.Error())
- //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromWind ErrMsg:"+err.Error(), utils.EmailSendToUsers)
- go alarm_msg.SendAlarmMsg("RefreshDataFromWind ErrMsg:"+err.Error(), 3)
- }
- wg.Done()
- }()
- var condition string
- var pars []interface{}
- condition += ` AND source=? AND no_update = 0 `
- pars = append(pars, utils.DATA_SOURCE_WIND)
- items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
- if err != nil {
- return err
- }
- //var endDate string
- //endDate = time.Now().Format(utils.FormatDate)
- for _, v := range items {
- startDate := ""
- if v.Frequency == "日度" {
- startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- } else if v.Frequency == "周度" {
- startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
- } else if v.Frequency == "月度" {
- startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
- } else if v.Frequency == "季度" {
- startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
- } else if v.Frequency == "年度" {
- startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
- } else {
- startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- }
- //err = SyncEdbDataByWind(int64(v.EdbInfoId), v.EdbCode, startDate, endDate)
- //if err != nil {
- // return err
- //}
- //edbInfoId, source int, edbCode, startDate string) (resp *models.BaseResponse, err error) {
- resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
- if err != nil {
- return errors.New("RefreshEdbData Err:" + err.Error())
- }
- if resp.Ret != 200 {
- return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
- }
- //item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
- //if err != nil {
- // return err
- //}
- //if item != nil {
- // err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
- // if err != nil {
- // return err
- // }
- //}
- }
- return err
- }
- // 刷新彭博数据
- func RefreshDataFromPb(wg *sync.WaitGroup) (err error) {
- defer func() {
- if err != nil {
- fmt.Println("RefreshDataFromPb Err:" + err.Error())
- //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromPb ErrMsg:"+err.Error(), utils.EmailSendToUsers)
- go alarm_msg.SendAlarmMsg("RefreshDataFromPb ErrMsg:"+err.Error(), 3)
- }
- wg.Done()
- }()
- var condition string
- var pars []interface{}
- condition += " AND source=? "
- pars = append(pars, utils.DATA_SOURCE_PB)
- items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
- if err != nil {
- return errors.New("GetEdbInfoByCondition:" + err.Error())
- }
- //var endDate string
- //endDate = time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
- for _, v := range items {
- startDate := ""
- if v.Frequency == "日度" {
- startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- } else if v.Frequency == "周度" {
- startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
- } else if v.Frequency == "月度" {
- startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
- } else if v.Frequency == "季度" {
- startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
- } else if v.Frequency == "年度" {
- startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
- } else {
- startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- }
- //err = SyncEdbDataByPb(int64(v.EdbInfoId), v.EdbCode, startDate, endDate)
- //if err != nil {
- // return errors.New("SyncEdbDataByPb:" + err.Error())
- //}
- resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
- if err != nil {
- return errors.New("RefreshEdbData Err:" + err.Error())
- }
- if resp.Ret != 200 {
- return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
- }
- //item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
- //if err != nil {
- // return err
- //}
- //if item != nil {
- // err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
- // if err != nil {
- // return err
- // }
- //}
- //minDate, maxDate, err := data.GetEdbDataPbMaxOrMinDate(v.EdbInfoId)
- //if err != nil {
- // return errors.New("GetEdbDataThsMaxOrMinDate:" + err.Error())
- //}
- //fmt.Println("minDate:" + minDate + ";maxDate:" + maxDate)
- //err = data.ModifyEdbDataInfoDate(v.EdbInfoId, maxDate)
- //if err != nil {
- // return errors.New("ModifyEdbDataInfoDate:" + err.Error())
- //}
- }
- return err
- }
- // RefreshDataFromPbFinance 刷新彭博财务指标数据
- func RefreshDataFromPbFinance(wg *sync.WaitGroup) (err error) {
- defer func() {
- if err != nil {
- fmt.Println("RefreshDataFromPb Err:" + err.Error())
- //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromPb ErrMsg:"+err.Error(), utils.EmailSendToUsers)
- go alarm_msg.SendAlarmMsg("RefreshDataFromPb ErrMsg:"+err.Error(), 3)
- }
- wg.Done()
- }()
- var condition string
- var pars []interface{}
- condition += " AND source=? "
- pars = append(pars, utils.DATA_SOURCE_PB_FINANCE)
- items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
- if err != nil {
- return errors.New("GetEdbInfoByCondition:" + err.Error())
- }
- //var endDate string
- //endDate = time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
- for _, v := range items {
- startDate := ""
- if v.Frequency == "日度" {
- startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- } else if v.Frequency == "周度" {
- startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
- } else if v.Frequency == "月度" {
- startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
- } else if v.Frequency == "季度" {
- startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
- } else if v.Frequency == "年度" {
- startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
- } else {
- startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- }
- //err = SyncEdbDataByPb(int64(v.EdbInfoId), v.EdbCode, startDate, endDate)
- //if err != nil {
- // return errors.New("SyncEdbDataByPb:" + err.Error())
- //}
- resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
- if err != nil {
- return errors.New("RefreshEdbData Err:" + err.Error())
- }
- if resp.Ret != 200 {
- return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
- }
- //item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
- //if err != nil {
- // return err
- //}
- //if item != nil {
- // err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
- // if err != nil {
- // return err
- // }
- //}
- //minDate, maxDate, err := data.GetEdbDataPbMaxOrMinDate(v.EdbInfoId)
- //if err != nil {
- // return errors.New("GetEdbDataThsMaxOrMinDate:" + err.Error())
- //}
- //fmt.Println("minDate:" + minDate + ";maxDate:" + maxDate)
- //err = data.ModifyEdbDataInfoDate(v.EdbInfoId, maxDate)
- //if err != nil {
- // return errors.New("ModifyEdbDataInfoDate:" + err.Error())
- //}
- }
- return err
- }
- func CheckPbDataInterface(cont context.Context) (err error) {
- go func() {
- checkUrl := utils.Hz_Data_PB_Url + `hz_server`
- body, err := http.Get(checkUrl)
- if err != nil {
- //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"检测数据接口:失败提醒", "CheckPbDataInterface ErrMsg:"+err.Error(), utils.EmailSendToUsers)
- msg := "检测彭博数据服务器失败:CheckPbDataInterface ErrMsg:" + err.Error()
- go alarm_msg.SendAlarmMsg(msg, 3)
- } else {
- result := string(body)
- if result != "1" {
- //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"检测数据接口:失败提醒", "CheckPbDataInterface ErrMsg:"+string(body), utils.EmailSendToUsers)
- msg := "检测彭博数据服务器失败:CheckPbDataInterface ErrMsg:" + string(body)
- go alarm_msg.SendAlarmMsg(msg, 3)
- }
- }
- }()
- return
- }
- // CheckLtDataInterface 检测路透数据服务器
- func CheckLtDataInterface(cont context.Context) (err error) {
- go func() {
- checkUrl := utils.Hz_Data_LT_Url + `hz_server`
- body, err := http.Get(checkUrl)
- if err != nil {
- //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"检测数据接口:失败提醒", "检测路透数据服务器失败:CheckLtDataInterface ErrMsg:"+err.Error(), utils.EmailSendToUsers)
- msg := "检测路透数据服务器失败:CheckLtDataInterface ErrMsg:" + err.Error()
- go alarm_msg.SendAlarmMsg(msg, 3)
- } else {
- result := string(body)
- if result != `"ek true"` {
- //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"检测数据接口:失败提醒", "检测路透数据服务器失败:CheckLtDataInterface ErrMsg:"+string(body), utils.EmailSendToUsers)
- msg := "检测路透数据服务器失败:CheckLtDataInterface ErrMsg:" + string(body)
- go alarm_msg.SendAlarmMsg(msg, 3)
- }
- }
- }()
- return
- }
- // CheckThsDataInterface 检测同花顺数据服务器
- func CheckThsDataInterface(cont context.Context) (err error) {
- go func() {
- checkUrl := utils.Hz_Server_Data_Url + `hz_server`
- body, err := http.Get(checkUrl)
- if err != nil {
- //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"检测数据接口:失败提醒", "CheckPbDataInterface ErrMsg:"+err.Error(), utils.EmailSendToUsers)
- msg := "检测同花顺数据服务器失败:CheckThsDataInterface ErrMsg:" + err.Error()
- go alarm_msg.SendAlarmMsg(msg, 3)
- } else {
- result := string(body)
- if result != "1" {
- //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"检测数据接口:失败提醒", "CheckPbDataInterface ErrMsg:"+string(body), utils.EmailSendToUsers)
- msg := "检测同花顺数据服务器失败:CheckThsDataInterface ErrMsg:" + string(body)
- go alarm_msg.SendAlarmMsg(msg, 3)
- }
- }
- }()
- return
- }
- ////刷新所有计算指标
- //func RefreshDataFromCalculateAll() (err error) {
- // defer func() {
- // if err != nil {
- // utils.FileLog.Info("RefreshDataFromCalculateAll Err:" + err.Error())
- // go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromCalculateAll ErrMsg:"+err.Error(), utils.EmailSendToUsers)
- // }
- // }()
- // var condition string
- // var pars []interface{}
- // condition += " AND edb_type=? "
- // pars = append(pars, 2)
- //
- // //condition += " AND is_update=1 "
- //
- // items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
- // if err != nil {
- // return err
- // }
- // for _, v := range items {
- // edbInfoId := v.EdbInfoId
- // edbCode := v.EdbCode
- // source := v.Source
- // fmt.Println(v.EdbInfoId, v.EdbCode, v.EdbName, v.SourceName, source)
- // if source == utils.DATA_SOURCE_CALCULATE {
- // startDate := ""
- // if v.Frequency == "日度" {
- // startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- // } else if v.Frequency == "周度" {
- // startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
- // } else if v.Frequency == "月度" {
- // startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
- // } else if v.Frequency == "季度" {
- // startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
- // } else if v.Frequency == "年度" {
- // startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
- // } else {
- // startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- // }
- // endDate := time.Now().Format(utils.FormatDate)
- // var edbInfoIdBytes []string
- // calculateMap, err := data_manage.GetEdbInfoCalculateDetail(int(v.EdbInfoId))
- // if err != nil {
- // return errors.New("GetEdbInfoCalculateDetail Err:" + err.Error())
- // }
- // 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)
- // }
- // //endDate = ""
- // err = RefreshCalculate(edbInfoList, edbInfoId, edbCode, v.CalculateFormula, startDate, endDate, edbInfoIdBytes)
- // if err != nil {
- // return errors.New("RefreshCalculate Err:" + err.Error())
- // }
- // } else if source == utils.DATA_SOURCE_CALCULATE_LJZZY {
- // calculateLjzzy, err := data_manage.GetEdbInfoCalculateLjzzyDetail(edbInfoId)
- // if err != nil {
- // if err.Error() == utils.ErrNoRow() {
- // continue
- // }
- // return errors.New("GetEdbInfoCalculateLjzzyDetail Err:" + err.Error())
- // }
- // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateLjzzy.FromEdbInfoId)
- // if err != nil {
- // if err.Error() == utils.ErrNoRow() {
- // continue
- // }
- // return errors.New("GetEdbInfoById Err:" + err.Error())
- // }
- // year := time.Now().Year() - 1
- // startDate := strconv.Itoa(year) + "-01" + "-01"
- // endDate := "" //time.Now().Format(utils.FormatDate)
- // err = data_manage.RefreshCalculateLjzzy(edbInfoId, fromEdbInfo, edbCode, startDate, endDate)
- // if err != nil {
- // return errors.New("RefreshCalculateLjzzy Err:" + err.Error())
- // }
- // } else if source == utils.DATA_SOURCE_CALCULATE_TBZ {
- // calculateTbz, err := data_manage.GetEdbInfoCalculateTbzDetail(edbInfoId)
- // if err != nil {
- // return errors.New("GetEdbInfoCalculateTbzDetail Err:" + err.Error())
- // }
- // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTbz.FromEdbInfoId)
- // if err != nil {
- // if err.Error() == utils.ErrNoRow() {
- // continue
- // }
- // return errors.New("GetEdbInfoById Err:" + err.Error())
- // }
- // startDate := time.Now().AddDate(-2, -2, 0).Format(utils.FormatDate)
- // endDate := "" //time.Now().Format(utils.FormatDate)
- // err = data_manage.RefreshCalculateTbz(edbInfoId, fromEdbInfo, calculateTbz.EdbCode, startDate, endDate)
- // if err != nil {
- // return errors.New("RefreshCalculateTbz Err:" + err.Error())
- // }
- // } else if source == utils.DATA_SOURCE_CALCULATE_TCZ {
- // calculateTcz, err := data_manage.GetEdbInfoCalculateTczDetail(edbInfoId)
- // if err != nil {
- // return errors.New("GetEdbInfoCalculateTczDetail Err:" + err.Error())
- // }
- // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTcz.FromEdbInfoId)
- // if err != nil {
- // if err.Error() == utils.ErrNoRow() {
- // continue
- // }
- // return errors.New("GetEdbInfoById Err:" + err.Error())
- // }
- // startDate := time.Now().AddDate(-2, -2, 0).Format(utils.FormatDate)
- // endDate := "" //time.Now().Format(utils.FormatDate)
- // err = data_manage.RefreshCalculateTcz(edbInfoId, fromEdbInfo, calculateTcz.EdbCode, startDate, endDate)
- // if err != nil {
- // return errors.New("RefreshCalculateTcz Err:" + err.Error())
- // }
- // } else if source == utils.DATA_SOURCE_CALCULATE_NSZYDPJJS {
- // calculateNszydpjjs, err := data_manage.GetEdbInfoCalculateNszydpjjsDetail(edbInfoId)
- // if err != nil {
- // return errors.New("GetEdbInfoCalculateNszydpjjsDetail Err:" + err.Error())
- // }
- // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateNszydpjjs.FromEdbInfoId)
- // if err != nil {
- // if err.Error() == utils.ErrNoRow() {
- // continue
- // }
- // return errors.New("GetEdbInfoById Err:" + err.Error())
- // }
- // formulaInt, _ := strconv.Atoi(v.CalculateFormula)
- // err = data_manage.RefreshCalculateNszydpjjs(edbInfoId, v.Source, formulaInt, fromEdbInfo, calculateNszydpjjs.EdbCode)
- // if err != nil {
- // return errors.New("RefreshCalculateNszydpjjs Err:" + err.Error())
- // }
- // } else if source == utils.DATA_SOURCE_CALCULATE_HBZ {
- // calculateHbz, err := data_manage.GetEdbInfoCalculateHbzDetail(edbInfoId)
- // if err != nil {
- // return errors.New("GetEdbInfoCalculateHbzDetail Err:" + err.Error())
- // }
- // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateHbz.FromEdbInfoId)
- // if err != nil {
- // if err.Error() == utils.ErrNoRow() {
- // continue
- // }
- // return errors.New("GetEdbInfoById Err:" + err.Error())
- // }
- // startDate := time.Now().AddDate(-2, -2, 0).Format(utils.FormatDate)
- // endDate := "" //time.Now().Format(utils.FormatDate)
- // formulaInt, _ := strconv.Atoi(v.CalculateFormula)
- // err = data_manage.RefreshCalculateHbz(edbInfoId, source, fromEdbInfo, calculateHbz.EdbCode, startDate, endDate, formulaInt)
- // if err != nil {
- // return errors.New("RefreshCalculateTbz Err:" + err.Error())
- // }
- // } else if source == utils.DATA_SOURCE_CALCULATE_HCZ {
- // calculateHcz, err := data_manage.GetEdbInfoCalculateHczDetail(edbInfoId)
- // if err != nil {
- // return errors.New("GetEdbInfoCalculateHczDetail Err:" + err.Error())
- // }
- // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateHcz.FromEdbInfoId)
- // if err != nil {
- // if err.Error() == utils.ErrNoRow() {
- // continue
- // }
- // return errors.New("GetEdbInfoById Err:" + err.Error())
- // }
- // startDate := time.Now().AddDate(-2, -2, 0).Format(utils.FormatDate)
- // endDate := "" //time.Now().Format(utils.FormatDate)
- // err = data_manage.RefreshCalculateHcz(edbInfoId, source, fromEdbInfo, calculateHcz.EdbCode, startDate, endDate)
- // if err != nil {
- // return errors.New("RefreshCalculateTbz Err:" + err.Error())
- // }
- // } else if source == utils.DATA_SOURCE_CALCULATE_BP {
- // calculateBp, err := data_manage.GetEdbInfoCalculateBpDetail(edbInfoId)
- // if err != nil && err.Error() != utils.ErrNoRow() {
- // return errors.New("GetEdbInfoCalculateBpDetail Err:" + err.Error())
- // }
- // if calculateBp != nil {
- // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateBp.FromEdbInfoId)
- // if err != nil {
- // if err.Error() == utils.ErrNoRow() {
- // continue
- // }
- // return errors.New("GetEdbInfoById Err:" + err.Error())
- // }
- // startDate := time.Now().AddDate(-2, -2, 0).Format(utils.FormatDate)
- // endDate := "" //time.Now().Format(utils.FormatDate)
- // err = data_manage.RefreshCalculateBp(edbInfoId, fromEdbInfo, calculateBp.EdbCode, startDate, endDate)
- // if err != nil {
- // return errors.New("RefreshCalculateTbz Err:" + err.Error())
- // }
- // }
- // } else if source == utils.DATA_SOURCE_CALCULATE_TIME_SHIFT {
- // calculate, err := data_manage.GetEdbInfoCalculateMappingDetail(edbInfoId)
- // if err != nil {
- // return fmt.Errorf("GetEdbInfoCalculateTbzDetail Err:" + err.Error())
- // }
- // fromEdbInfo, err := data_manage.GetEdbInfoById(calculate.FromEdbInfoId)
- // if err != nil {
- // if err.Error() == utils.ErrNoRow() {
- // continue
- // }
- // return fmt.Errorf("GetEdbInfoById Err:" + err.Error())
- // }
- // //startDate := v.StartDate.Format(utils.FormatDate)
- // //endDate := time.Now().Format(utils.FormatDate)
- // formulaInt, _ := strconv.Atoi(calculate.CalculateFormula)
- // err = data_manage.RefreshAllCalculateTimeShift(edbInfoId, source, formulaInt, calculate.MoveType, fromEdbInfo, calculate.EdbCode, calculate.MoveFrequency)
- // if err != nil {
- // return fmt.Errorf("RefreshAllCalculateTimeShift Err:" + err.Error())
- // }
- //
- // } else if source == utils.DATA_SOURCE_CALCULATE_ZJPJ { //刷新直接拼接
- // tmpEdbInfo, err := data_manage.GetEdbInfoById(v.EdbInfoId)
- // if err != nil {
- // if err.Error() == utils.ErrNoRow() {
- // continue
- // }
- // return fmt.Errorf("GetEdbInfoById Err:" + err.Error())
- // }
- // err = data_manage.RefreshAllCalculateZjpj(tmpEdbInfo)
- // if err != nil {
- // return fmt.Errorf("RefreshAllCalculateZjpj Err:" + err.Error())
- // }
- // } else if source == utils.DATA_SOURCE_CALCULATE_LJZTBPJ { //刷新累计值同比拼接
- // tmpEdbInfo, err := data_manage.GetEdbInfoById(v.EdbInfoId)
- // if err != nil {
- // if err.Error() == utils.ErrNoRow() {
- // continue
- // }
- // return fmt.Errorf("GetEdbInfoById Err:" + err.Error())
- // }
- // err = data_manage.RefreshAllCalculateLjztbpj(tmpEdbInfo)
- // if err != nil {
- // return fmt.Errorf("RefreshAllCalculateLjztbpj Err:" + err.Error())
- // }
- // } else {
- // msg := "刷新失败,无效的指标渠道:source:" + strconv.Itoa(source) + " EdbCode:" + v.EdbCode
- // err = errors.New(msg)
- // return err
- // }
- //
- // maxAndMinItem, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
- // if err != nil {
- // fmt.Println("GetEdbInfoMaxAndMinInfo Err:" + err.Error() + ";source:" + strconv.Itoa(source) + ";edbCode:" + edbCode)
- // err = errors.New("GetEdbInfoMaxAndMinInfo Err:" + err.Error() + ";source:" + strconv.Itoa(source) + ";edbCode:" + edbCode)
- // return err
- // }
- // if maxAndMinItem != nil {
- // err = data_manage.ModifyEdbInfoMaxAndMinInfo(edbInfoId, maxAndMinItem)
- // if err != nil {
- // return err
- // }
- // }
- // }
- // return err
- //}
- // RefreshDataFromCalculateAll 刷新所有计算指标
- func RefreshDataFromCalculateAll() (err error) {
- var errmsg string
- defer func() {
- if err != nil {
- utils.FileLog.Info("RefreshDataFromCalculateAll Err:" + err.Error())
- //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromCalculateAll ErrMsg:"+err.Error(), utils.EmailSendToUsers)
- go alarm_msg.SendAlarmMsg("RefreshDataFromCalculateAll ErrMsg:"+err.Error(), 3)
- }
- }()
- var condition string
- var pars []interface{}
- // 查询 普通指标的计算指标
- condition += " AND edb_type=? AND edb_info_type=? "
- pars = append(pars, 2, 0)
- //condition += " AND modify_time<? "
- //pars = append(pars, "2022-03-02 17:03:52")
- //condition += " AND is_update=1 "
- items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
- if err != nil {
- return err
- }
- for _, v := range items {
- //edbInfoId := v.EdbInfoId
- //edbCode := v.EdbCode
- source := v.Source
- startDate := v.StartDate.Format(utils.FormatDate)
- if startDate == "0001-01-01" {
- continue
- }
- fmt.Println(v.EdbInfoId, v.EdbCode, v.EdbName, v.SourceName, source)
- //if source == utils.DATA_SOURCE_CALCULATE {
- // startDate := ""
- // if v.Frequency == "日度" {
- // startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- // } else if v.Frequency == "周度" {
- // startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
- // } else if v.Frequency == "月度" {
- // startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
- // } else if v.Frequency == "季度" {
- // startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
- // } else if v.Frequency == "年度" {
- // startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
- // } else {
- // startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- // }
- // endDate := time.Now().Format(utils.FormatDate)
- // var edbInfoIdBytes []string
- // calculateMap, err := data_manage.GetEdbInfoCalculateDetail(int(v.EdbInfoId))
- // if err != nil {
- // return errors.New("GetEdbInfoCalculateDetail Err:" + err.Error())
- // }
- // 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)
- // }
- // //endDate = ""
- // err = RefreshCalculate(edbInfoList, edbInfoId, edbCode, v.CalculateFormula, startDate, endDate, edbInfoIdBytes)
- // if err != nil {
- // return errors.New("RefreshCalculate Err:" + err.Error())
- // }
- //} else if source == utils.DATA_SOURCE_CALCULATE_LJZZY {
- // calculateLjzzy, err := data_manage.GetEdbInfoCalculateLjzzyDetail(edbInfoId)
- // if err != nil {
- // if err.Error() == utils.ErrNoRow() {
- // continue
- // }
- // return errors.New("GetEdbInfoCalculateLjzzyDetail Err:" + err.Error())
- // }
- // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateLjzzy.FromEdbInfoId)
- // if err != nil {
- // if err.Error() == utils.ErrNoRow() {
- // continue
- // }
- // return errors.New("GetEdbInfoById Err:" + err.Error())
- // }
- // year := time.Now().Year() - 1
- // startDate := strconv.Itoa(year) + "-01" + "-01"
- // endDate := "" //time.Now().Format(utils.FormatDate)
- // err = data_manage.RefreshCalculateLjzzy(edbInfoId, fromEdbInfo, edbCode, startDate, endDate)
- // if err != nil {
- // return errors.New("RefreshCalculateLjzzy Err:" + err.Error())
- // }
- //} else if source == utils.DATA_SOURCE_CALCULATE_TBZ {
- // calculateTbz, err := data_manage.GetEdbInfoCalculateTbzDetail(edbInfoId)
- // if err != nil {
- // return errors.New("GetEdbInfoCalculateTbzDetail Err:" + err.Error())
- // }
- // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTbz.FromEdbInfoId)
- // if err != nil {
- // if err.Error() == utils.ErrNoRow() {
- // continue
- // }
- // return errors.New("GetEdbInfoById Err:" + err.Error())
- // }
- // startDate := time.Now().AddDate(-2, -2, 0).Format(utils.FormatDate)
- // endDate := "" //time.Now().Format(utils.FormatDate)
- // err = data_manage.RefreshCalculateTbz(edbInfoId, fromEdbInfo, calculateTbz.EdbCode, startDate, endDate)
- // if err != nil {
- // return errors.New("RefreshCalculateTbz Err:" + err.Error())
- // }
- //} else if source == utils.DATA_SOURCE_CALCULATE_TCZ {
- // calculateTcz, err := data_manage.GetEdbInfoCalculateTczDetail(edbInfoId)
- // if err != nil {
- // return errors.New("GetEdbInfoCalculateTczDetail Err:" + err.Error())
- // }
- // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateTcz.FromEdbInfoId)
- // if err != nil {
- // if err.Error() == utils.ErrNoRow() {
- // continue
- // }
- // return errors.New("GetEdbInfoById Err:" + err.Error())
- // }
- // startDate := time.Now().AddDate(-2, -2, 0).Format(utils.FormatDate)
- // endDate := "" //time.Now().Format(utils.FormatDate)
- // err = data_manage.RefreshCalculateTcz(edbInfoId, fromEdbInfo, calculateTcz.EdbCode, startDate, endDate)
- // if err != nil {
- // return errors.New("RefreshCalculateTcz Err:" + err.Error())
- // }
- //} else if source == utils.DATA_SOURCE_CALCULATE_NSZYDPJJS {
- // calculateNszydpjjs, err := data_manage.GetEdbInfoCalculateNszydpjjsDetail(edbInfoId)
- // if err != nil {
- // return errors.New("GetEdbInfoCalculateNszydpjjsDetail Err:" + err.Error())
- // }
- // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateNszydpjjs.FromEdbInfoId)
- // if err != nil {
- // if err.Error() == utils.ErrNoRow() {
- // continue
- // }
- // return errors.New("GetEdbInfoById Err:" + err.Error())
- // }
- // formulaInt, _ := strconv.Atoi(v.CalculateFormula)
- // err = data_manage.RefreshCalculateNszydpjjs(edbInfoId, v.Source, formulaInt, fromEdbInfo, calculateNszydpjjs.EdbCode)
- // if err != nil {
- // return errors.New("RefreshCalculateNszydpjjs Err:" + err.Error())
- // }
- //} else if source == utils.DATA_SOURCE_CALCULATE_HBZ {
- // calculateHbz, err := data_manage.GetEdbInfoCalculateHbzDetail(edbInfoId)
- // if err != nil {
- // return errors.New("GetEdbInfoCalculateHbzDetail Err:" + err.Error())
- // }
- // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateHbz.FromEdbInfoId)
- // if err != nil {
- // if err.Error() == utils.ErrNoRow() {
- // continue
- // }
- // return errors.New("GetEdbInfoById Err:" + err.Error())
- // }
- // startDate := time.Now().AddDate(-2, -2, 0).Format(utils.FormatDate)
- // endDate := "" //time.Now().Format(utils.FormatDate)
- // formulaInt, _ := strconv.Atoi(v.CalculateFormula)
- // err = data_manage.RefreshCalculateHbz(edbInfoId, source, fromEdbInfo, calculateHbz.EdbCode, startDate, endDate, formulaInt)
- // if err != nil {
- // return errors.New("RefreshCalculateTbz Err:" + err.Error())
- // }
- //} else if source == utils.DATA_SOURCE_CALCULATE_HCZ {
- // calculateHcz, err := data_manage.GetEdbInfoCalculateHczDetail(edbInfoId)
- // if err != nil {
- // return errors.New("GetEdbInfoCalculateHczDetail Err:" + err.Error())
- // }
- // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateHcz.FromEdbInfoId)
- // if err != nil {
- // if err.Error() == utils.ErrNoRow() {
- // continue
- // }
- // return errors.New("GetEdbInfoById Err:" + err.Error())
- // }
- // startDate := time.Now().AddDate(-2, -2, 0).Format(utils.FormatDate)
- // endDate := "" //time.Now().Format(utils.FormatDate)
- // err = data_manage.RefreshCalculateHcz(edbInfoId, source, fromEdbInfo, calculateHcz.EdbCode, startDate, endDate)
- // if err != nil {
- // return errors.New("RefreshCalculateTbz Err:" + err.Error())
- // }
- //} else if source == utils.DATA_SOURCE_CALCULATE_BP {
- // calculateBp, err := data_manage.GetEdbInfoCalculateBpDetail(edbInfoId)
- // if err != nil && err.Error() != utils.ErrNoRow() {
- // return errors.New("GetEdbInfoCalculateBpDetail Err:" + err.Error())
- // }
- // if calculateBp != nil {
- // fromEdbInfo, err := data_manage.GetEdbInfoById(calculateBp.FromEdbInfoId)
- // if err != nil {
- // if err.Error() == utils.ErrNoRow() {
- // continue
- // }
- // return errors.New("GetEdbInfoById Err:" + err.Error())
- // }
- // startDate := time.Now().AddDate(-2, -2, 0).Format(utils.FormatDate)
- // endDate := "" //time.Now().Format(utils.FormatDate)
- // err = data_manage.RefreshCalculateBp(edbInfoId, fromEdbInfo, calculateBp.EdbCode, startDate, endDate)
- // if err != nil {
- // return errors.New("RefreshCalculateTbz Err:" + err.Error())
- // }
- // }
- //} else if source == utils.DATA_SOURCE_CALCULATE_TIME_SHIFT {
- // calculate, err := data_manage.GetEdbInfoCalculateMappingDetail(edbInfoId)
- // if err != nil {
- // return fmt.Errorf("GetEdbInfoCalculateTbzDetail Err:" + err.Error())
- // }
- // fromEdbInfo, err := data_manage.GetEdbInfoById(calculate.FromEdbInfoId)
- // if err != nil {
- // if err.Error() == utils.ErrNoRow() {
- // continue
- // }
- // return fmt.Errorf("GetEdbInfoById Err:" + err.Error())
- // }
- // //startDate := v.StartDate.Format(utils.FormatDate)
- // //endDate := time.Now().Format(utils.FormatDate)
- // formulaInt, _ := strconv.Atoi(calculate.CalculateFormula)
- // err = data_manage.RefreshAllCalculateTimeShift(edbInfoId, source, formulaInt, calculate.MoveType, fromEdbInfo, calculate.EdbCode, calculate.MoveFrequency)
- // if err != nil {
- // return fmt.Errorf("RefreshAllCalculateTimeShift Err:" + err.Error())
- // }
- //
- //} else if source == utils.DATA_SOURCE_CALCULATE_ZJPJ { //刷新直接拼接
- // tmpEdbInfo, err := data_manage.GetEdbInfoById(v.EdbInfoId)
- // if err != nil {
- // if err.Error() == utils.ErrNoRow() {
- // continue
- // }
- // return fmt.Errorf("GetEdbInfoById Err:" + err.Error())
- // }
- // err = data_manage.RefreshAllCalculateZjpj(tmpEdbInfo)
- // if err != nil {
- // return fmt.Errorf("RefreshAllCalculateZjpj Err:" + err.Error())
- // }
- //} else if source == utils.DATA_SOURCE_CALCULATE_LJZTBPJ { //刷新累计值同比拼接
- // tmpEdbInfo, err := data_manage.GetEdbInfoById(v.EdbInfoId)
- // if err != nil {
- // if err.Error() == utils.ErrNoRow() {
- // continue
- // }
- // return fmt.Errorf("GetEdbInfoById Err:" + err.Error())
- // }
- // err = data_manage.RefreshAllCalculateLjztbpj(tmpEdbInfo)
- // if err != nil {
- // return fmt.Errorf("RefreshAllCalculateLjztbpj Err:" + err.Error())
- // }
- //} else {
- // msg := "刷新失败,无效的指标渠道:source:" + strconv.Itoa(source) + " EdbCode:" + v.EdbCode
- // err = errors.New(msg)
- // return err
- //}
- fmt.Println("RefreshEdbCalculateData", v.EdbInfoId, v.EdbCode, startDate)
- result, err := RefreshEdbCalculateData(v.EdbInfoId, v.EdbCode, startDate)
- if err != nil {
- errmsg += v.EdbCode + ","
- err = errors.New("RefreshEdbCalculateData Err:" + err.Error())
- //return err
- continue
- }
- if result.Ret != 200 {
- errmsg += v.EdbCode + ","
- err = errors.New("RefreshEdbCalculateData err;msg:" + result.Msg + ";errMsg:" + result.ErrMsg)
- //return err
- continue
- }
- //maxAndMinItem, err := data_manage.GetEdbInfoMaxAndMinInfo(source, edbCode)
- //if err != nil {
- // fmt.Println("GetEdbInfoMaxAndMinInfo Err:" + err.Error() + ";source:" + strconv.Itoa(source) + ";edbCode:" + edbCode)
- // err = errors.New("GetEdbInfoMaxAndMinInfo Err:" + err.Error() + ";source:" + strconv.Itoa(source) + ";edbCode:" + edbCode)
- // return err
- //}
- //if maxAndMinItem != nil {
- // err = data_manage.ModifyEdbInfoMaxAndMinInfo(edbInfoId, maxAndMinItem)
- // if err != nil {
- // return err
- // }
- //}
- }
- return err
- }
- // RefreshPredictDataFromCalculateAll 刷新所有预测计算指标
- func RefreshPredictDataFromCalculateAll() (err error) {
- defer func() {
- if err != nil {
- utils.FileLog.Info("RefreshDataFromCalculateAll Err:" + err.Error())
- //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromCalculateAll ErrMsg:"+err.Error(), utils.EmailSendToUsers)
- go alarm_msg.SendAlarmMsg("RefreshDataFromCalculateAll ErrMsg:"+err.Error(), 3)
- }
- }()
- var condition string
- var pars []interface{}
- // 查询 普通指标的计算指标
- condition += " AND edb_type=? AND edb_info_type=? "
- pars = append(pars, 2, 1)
- //condition += " AND modify_time<? "
- //pars = append(pars, "2022-03-02 17:03:52")
- //condition += " AND is_update=1 "
- items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
- if err != nil {
- return err
- }
- for _, v := range items {
- //edbInfoId := v.EdbInfoId
- //edbCode := v.EdbCode
- source := v.Source
- startDate := v.StartDate.Format(utils.FormatDate)
- if startDate == "0001-01-01" {
- continue
- }
- fmt.Println(v.EdbInfoId, v.EdbCode, v.EdbName, v.SourceName, source, "======RefreshPredictEdbCalculateData:", startDate)
- result, err := RefreshPredictEdbCalculateData(v.EdbInfoId, v.EdbCode, startDate)
- if err != nil {
- err = errors.New("RefreshPredictEdbCalculateData Err:" + err.Error())
- return err
- }
- if result.Ret != 200 {
- err = errors.New("RefreshPredictEdbCalculateData err;msg:" + result.Msg + ";errMsg:" + result.ErrMsg)
- return err
- }
- }
- return err
- }
- // 刷新手工指标数据
- func RefreshDataFromManual(wg *sync.WaitGroup) (err error) {
- defer func() {
- if err != nil {
- fmt.Println("RefreshDataFromManual Err:" + err.Error())
- //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromManual ErrMsg:"+err.Error(), utils.EmailSendToUsers)
- go alarm_msg.SendAlarmMsg("RefreshDataFromManual ErrMsg:"+err.Error(), 3)
- }
- wg.Done()
- }()
- var condition string
- var pars []interface{}
- condition += " AND source=? "
- pars = append(pars, utils.DATA_SOURCE_MANUAL)
- items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
- if err != nil {
- return errors.New("GetEdbInfoByCondition:" + err.Error())
- }
- for _, v := range items {
- //err = data_manage.RefreshManual(v)
- //if err != nil {
- // return errors.New("RefreshManual:edbCode:" + v.EdbCode + ":" + err.Error())
- //}
- startDate := ``
- if !v.StartDate.IsZero() {
- startDate = v.StartDate.Format(utils.FormatDate)
- }
- resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
- if err != nil {
- return errors.New("RefreshEdbData Err:" + err.Error())
- }
- if resp.Ret != 200 {
- return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
- }
- //item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
- //if err != nil {
- // if err.Error() != utils.ErrNoRow() {
- // return err
- // } else {
- // err = nil
- // }
- //} else {
- // if item != nil {
- // err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
- // if err != nil {
- // return err
- // }
- // }
- //}
- }
- return err
- }
- // 刷新隆众数据
- func RefreshDataFromLz(wg *sync.WaitGroup) (err error) {
- defer func() {
- if err != nil {
- fmt.Println("RefreshDataFromLz Err:" + err.Error())
- //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromLz ErrMsg:"+err.Error(), utils.EmailSendToUsers)
- go alarm_msg.SendAlarmMsg("RefreshDataFromLz ErrMsg:"+err.Error(), 3)
- }
- wg.Done()
- }()
- var condition string
- var pars []interface{}
- condition += " AND source=? "
- pars = append(pars, utils.DATA_SOURCE_LZ)
- items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
- if err != nil {
- return errors.New("GetEdbInfoByCondition:" + err.Error())
- }
- //var endDate string
- //endDate = time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
- for _, v := range items {
- startDate := ""
- if v.Frequency == "日度" {
- startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- } else if v.Frequency == "周度" {
- startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
- } else if v.Frequency == "月度" {
- startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
- } else if v.Frequency == "季度" {
- startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
- } else if v.Frequency == "年度" {
- startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
- } else {
- startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- }
- //fmt.Println(startDate, endDate)
- //err = data_manage.RefreshEdbDataByLz(v.EdbInfoId, v.EdbCode, startDate, endDate)
- //if err != nil {
- // return errors.New("RefreshEdbDataByLz:" + err.Error())
- //}
- resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
- if err != nil {
- return errors.New("RefreshEdbData Err:" + err.Error())
- }
- if resp.Ret != 200 {
- return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
- }
- //item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
- //if err != nil {
- // return err
- //}
- //if item != nil {
- // err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
- // if err != nil {
- // return err
- // }
- //}
- }
- return err
- }
- // 刷新有色数据
- func RefreshDataFromYs(wg *sync.WaitGroup) (err error) {
- defer func() {
- if err != nil {
- fmt.Println("RefreshDataFromYs Err:" + err.Error())
- //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromYs ErrMsg:"+err.Error(), utils.EmailSendToUsers)
- go alarm_msg.SendAlarmMsg("RefreshDataFromYs ErrMsg:"+err.Error(), 3)
- }
- wg.Done()
- }()
- var condition string
- var pars []interface{}
- condition += " AND source=? "
- pars = append(pars, utils.DATA_SOURCE_YS)
- items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
- if err != nil {
- return errors.New("GetEdbInfoByCondition:" + err.Error())
- }
- //var endDate string
- //endDate = time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
- for _, v := range items {
- startDate := ""
- if v.Frequency == "日度" {
- startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- } else if v.Frequency == "周度" {
- startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
- } else if v.Frequency == "月度" {
- startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
- } else if v.Frequency == "季度" {
- startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
- } else if v.Frequency == "年度" {
- startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
- } else {
- startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- }
- //fmt.Println(startDate, endDate)
- //err = data_manage.RefreshEdbDataByYs(v.EdbInfoId, v.EdbCode, startDate, endDate)
- //if err != nil {
- // return errors.New("RefreshEdbDataByYs:" + err.Error())
- //}
- resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
- if err != nil {
- return errors.New("RefreshEdbData Err:" + err.Error())
- }
- if resp.Ret != 200 {
- return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
- }
- //item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
- //if err != nil {
- // return err
- //}
- //if item != nil {
- // err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
- // if err != nil {
- // return err
- // }
- //}
- }
- return err
- }
- // 刷新钢联数据
- func RefreshDataFromGl(wg *sync.WaitGroup) (err error) {
- defer func() {
- if err != nil {
- fmt.Println("RefreshDataFromGl Err:" + err.Error())
- //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromGl ErrMsg:"+err.Error(), utils.EmailSendToUsers)
- go alarm_msg.SendAlarmMsg("RefreshDataFromGl ErrMsg:"+err.Error(), 3)
- }
- wg.Done()
- }()
- var condition string
- var pars []interface{}
- condition += " AND source=? "
- pars = append(pars, utils.DATA_SOURCE_GL)
- items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
- if err != nil {
- return errors.New("GetEdbInfoByCondition:" + err.Error())
- }
- //var endDate string
- //endDate = time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
- for _, v := range items {
- startDate := ""
- if v.Frequency == "日度" {
- startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- } else if v.Frequency == "周度" {
- startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
- } else if v.Frequency == "月度" {
- startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
- } else if v.Frequency == "季度" {
- startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
- } else if v.Frequency == "年度" {
- startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
- } else {
- startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- }
- //fmt.Println(startDate, endDate)
- //err = data_manage.RefreshEdbDataByGl(v.EdbInfoId, v.EdbCode, startDate, endDate)
- //if err != nil {
- // return errors.New("RefreshEdbDataByGl:" + err.Error())
- //}
- resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
- if err != nil {
- return errors.New("RefreshEdbData Err:" + err.Error())
- }
- if resp.Ret != 200 {
- return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
- }
- //item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
- //if err != nil {
- // return err
- //}
- //if item != nil {
- // err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
- // if err != nil {
- // return err
- // }
- //}
- }
- return err
- }
- // RefreshDataFromSh 刷新上期所数据
- func RefreshDataFromSh(wg *sync.WaitGroup) (err error) {
- defer func() {
- if err != nil {
- fmt.Println("RefreshDataFromSh Err:" + err.Error())
- //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromSh ErrMsg:"+err.Error(), utils.EmailSendToUsers)
- go alarm_msg.SendAlarmMsg("RefreshDataFromSh ErrMsg:"+err.Error(), 3)
- }
- wg.Done()
- }()
- var condition string
- var pars []interface{}
- condition += " AND source=? "
- pars = append(pars, utils.DATA_SOURCE_SH)
- items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
- if err != nil {
- return errors.New("GetEdbInfoByCondition:" + err.Error())
- }
- //var endDate string
- //endDate = time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
- for _, v := range items {
- startDate := ""
- if v.Frequency == "日度" {
- startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- } else if v.Frequency == "周度" {
- startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
- } else if v.Frequency == "月度" {
- startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
- } else if v.Frequency == "季度" {
- startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
- } else if v.Frequency == "年度" {
- startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
- } else {
- startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- }
- //fmt.Println(startDate, endDate)
- //err = data_manage.RefreshEdbDataBySh(v.EdbInfoId, v.EdbCode, startDate, endDate)
- //if err != nil {
- // return errors.New("RefreshEdbDataBySh:" + err.Error())
- //}
- resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
- if err != nil {
- return errors.New("RefreshEdbData Err:" + err.Error())
- }
- if resp.Ret != 200 {
- return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
- }
- //item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
- //if err != nil {
- // return err
- //}
- //if item != nil {
- // err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
- // if err != nil {
- // return err
- // }
- //}
- }
- return err
- }
- // RefreshDataFromDl 刷新大商所数据
- func RefreshDataFromDl(wg *sync.WaitGroup) (err error) {
- defer func() {
- if err != nil {
- fmt.Println("RefreshDataFromDl Err:" + err.Error())
- //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromDl ErrMsg:"+err.Error(), utils.EmailSendToUsers)
- go alarm_msg.SendAlarmMsg("RefreshDataFromDl ErrMsg:"+err.Error(), 3)
- }
- wg.Done()
- }()
- var condition string
- var pars []interface{}
- condition += " AND source=? "
- pars = append(pars, utils.DATA_SOURCE_DL)
- items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
- if err != nil {
- return errors.New("GetEdbInfoByCondition:" + err.Error())
- }
- //var endDate string
- //endDate = time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
- for _, v := range items {
- startDate := ""
- if v.Frequency == "日度" {
- startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- } else if v.Frequency == "周度" {
- startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
- } else if v.Frequency == "月度" {
- startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
- } else if v.Frequency == "季度" {
- startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
- } else if v.Frequency == "年度" {
- startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
- } else {
- startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- }
- //fmt.Println(startDate, endDate)
- //err = data_manage.RefreshEdbDataByDl(v.EdbInfoId, v.EdbCode, startDate, endDate)
- //if err != nil {
- // return errors.New("RefreshEdbDataByDl:" + err.Error())
- //}
- resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
- if err != nil {
- return errors.New("RefreshEdbData Err:" + err.Error())
- }
- if resp.Ret != 200 {
- return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
- }
- //item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
- //if err != nil {
- // return err
- //}
- //if item != nil {
- // err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
- // if err != nil {
- // return err
- // }
- //}
- }
- return err
- }
- // RefreshDataFromShfe 刷新上期能源数据
- func RefreshDataFromShfe(wg *sync.WaitGroup) (err error) {
- defer func() {
- if err != nil {
- fmt.Println("RefreshDataFromShfe Err:" + err.Error())
- //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromShfe ErrMsg:"+err.Error(), utils.EmailSendToUsers)
- go alarm_msg.SendAlarmMsg("RefreshDataFromShfe ErrMsg:"+err.Error(), 3)
- }
- wg.Done()
- }()
- var condition string
- var pars []interface{}
- condition += " AND source=? "
- pars = append(pars, utils.DATA_SOURCE_SHFE)
- items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
- if err != nil {
- return errors.New("GetEdbInfoByCondition:" + err.Error())
- }
- //var endDate string
- //endDate = time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
- for _, v := range items {
- startDate := ""
- if v.Frequency == "日度" {
- startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- } else if v.Frequency == "周度" {
- startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
- } else if v.Frequency == "月度" {
- startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
- } else if v.Frequency == "季度" {
- startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
- } else if v.Frequency == "年度" {
- startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
- } else {
- startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- }
- //fmt.Println(startDate, endDate)
- //err = data_manage.RefreshEdbDataByShfe(v.EdbInfoId, v.EdbCode, startDate, endDate)
- //if err != nil {
- // return errors.New("RefreshEdbDataByShfe:" + err.Error())
- //}
- resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
- if err != nil {
- return errors.New("RefreshEdbData Err:" + err.Error())
- }
- if resp.Ret != 200 {
- return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
- }
- //item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
- //if err != nil {
- // return err
- //}
- //if item != nil {
- // err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
- // if err != nil {
- // return err
- // }
- //}
- }
- return err
- }
- // RefreshDataFromCffex 刷新中金所数据
- func RefreshDataFromCffex(wg *sync.WaitGroup) (err error) {
- defer func() {
- if err != nil {
- fmt.Println("RefreshDataFromCffex Err:" + err.Error())
- //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromCffex ErrMsg:"+err.Error(), utils.EmailSendToUsers)
- go alarm_msg.SendAlarmMsg("RefreshDataFromCffex ErrMsg:"+err.Error(), 3)
- }
- wg.Done()
- }()
- var condition string
- var pars []interface{}
- condition += " AND source=? "
- pars = append(pars, utils.DATA_SOURCE_CFFEX)
- items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
- if err != nil {
- return errors.New("GetEdbInfoByCondition:" + err.Error())
- }
- //var endDate string
- //endDate = time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
- for _, v := range items {
- startDate := ""
- if v.Frequency == "日度" {
- startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- } else if v.Frequency == "周度" {
- startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
- } else if v.Frequency == "月度" {
- startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
- } else if v.Frequency == "季度" {
- startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
- } else if v.Frequency == "年度" {
- startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
- } else {
- startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- }
- //fmt.Println(startDate, endDate)
- //err = data_manage.RefreshEdbDataByCffex(v.EdbInfoId, v.EdbCode, startDate, endDate)
- //if err != nil {
- // return errors.New("RefreshEdbDataByCffex:" + err.Error())
- //}
- resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
- if err != nil {
- return errors.New("RefreshEdbData Err:" + err.Error())
- }
- if resp.Ret != 200 {
- return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
- }
- //item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
- //if err != nil {
- // return err
- //}
- //if item != nil {
- // err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
- // if err != nil {
- // return err
- // }
- //}
- }
- return err
- }
- // RefreshDataFromZz 刷新郑商所数据
- func RefreshDataFromZz(wg *sync.WaitGroup) (err error) {
- defer func() {
- if err != nil {
- fmt.Println("RefreshDataFromZz Err:" + err.Error())
- //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromZz ErrMsg:"+err.Error(), utils.EmailSendToUsers)
- go alarm_msg.SendAlarmMsg("RefreshDataFromZz ErrMsg:"+err.Error(), 3)
- }
- wg.Done()
- }()
- var condition string
- var pars []interface{}
- condition += " AND source=? "
- pars = append(pars, utils.DATA_SOURCE_ZZ)
- items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
- if err != nil {
- return errors.New("GetEdbInfoByCondition:" + err.Error())
- }
- //var endDate string
- //endDate = time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
- for _, v := range items {
- startDate := ""
- if v.Frequency == "日度" {
- startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- } else if v.Frequency == "周度" {
- startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
- } else if v.Frequency == "月度" {
- startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
- } else if v.Frequency == "季度" {
- startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
- } else if v.Frequency == "年度" {
- startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
- } else {
- startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- }
- //fmt.Println(startDate, endDate)
- //err = data_manage.RefreshEdbDataByZz(v.EdbInfoId, v.EdbCode, startDate, endDate)
- //if err != nil {
- // return errors.New("RefreshEdbDataByZz:" + err.Error())
- //}
- resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
- if err != nil {
- return errors.New("RefreshEdbData Err:" + err.Error())
- }
- if resp.Ret != 200 {
- return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
- }
- //item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
- //if err != nil {
- // return err
- //}
- //if item != nil {
- // err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
- // if err != nil {
- // return err
- // }
- //}
- }
- return err
- }
- // RefreshDataFromLt 刷新路透数据
- func RefreshDataFromLt(wg *sync.WaitGroup) (err error) {
- errMsgList := make([]string, 0)
- defer func() {
- //if err != nil {
- // fmt.Println("RefreshDataFromLt Err:" + err.Error())
- // //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromLt ErrMsg:"+err.Error(), utils.EmailSendToUsers)
- // go alarm_msg.SendAlarmMsg("RefreshDataFromLt ErrMsg:"+err.Error(), 3)
- //}
- if len(errMsgList) > 0 {
- fmt.Println("RefreshDataFromLt Err:", errMsgList)
- //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromLt ErrMsg:"+err.Error(), utils.EmailSendToUsers)
- go alarm_msg.SendAlarmMsg("RefreshDataFromLt ErrMsg:"+strings.Join(errMsgList, `<br/>`), 3)
- }
- wg.Done()
- }()
- var condition string
- var pars []interface{}
- condition += " AND source=? "
- pars = append(pars, utils.DATA_SOURCE_LT)
- items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
- if err != nil {
- errMsgList = append(errMsgList, "GetEdbInfoByCondition:"+err.Error())
- return errors.New("GetEdbInfoByCondition:" + err.Error())
- }
- //endDate := time.Now().Format(utils.FormatDate)
- for _, v := range items {
- startDate := v.StartDate.Format(utils.FormatDate)
- //err = data_manage.RefreshAllEdbDataByLt(v.EdbInfoId, utils.DATA_SOURCE_LT, v.EdbCode, startDate, endDate)
- //if err != nil {
- // return errors.New("RefreshEdbDataByLt:" + err.Error())
- //}
- resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
- if err != nil {
- errMsgList = append(errMsgList, "RefreshEdbData Err:"+err.Error())
- continue
- }
- if resp.Ret != 200 {
- errMsgList = append(errMsgList, "RefreshEdbData Err:"+resp.Msg+";ErrMsg:"+resp.ErrMsg)
- continue
- }
- //更新指标的最新数据
- //item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
- //if err != nil {
- // return err
- //}
- //if item != nil {
- // err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
- // if err != nil {
- // return err
- // }
- //}
- }
- return err
- }
- func ResetEdbInfoIsUpdate(cont context.Context) (err error) {
- go data_manage.ResetEdbInfoIsUpdate()
- return nil
- }
- // CheckWindDataInterface 检测wind数据服务器
- func CheckWindDataInterface(cont context.Context) (err error) {
- for _, hzDataWindUrl := range utils.Hz_Data_WIND_Url_List {
- go func(urlStr string) {
- checkUrl := urlStr + `hz_server`
- body, err := http.Get(checkUrl)
- if err != nil {
- msg := fmt.Sprintf("检测:%s ;失败:CheckWindDataInterface ErrMsg:%s", checkUrl, err.Error())
- //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"检测数据接口:失败提醒", "检测路透数据服务器失败:CheckLtDataInterface ErrMsg:"+err.Error(), utils.EmailSendToUsers)
- go alarm_msg.SendAlarmMsg(msg, 3)
- } else {
- result := string(body)
- if result != `1` {
- //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"检测数据接口:失败提醒", "检测路透数据服务器失败:CheckLtDataInterface ErrMsg:"+string(body), utils.EmailSendToUsers)
- //msg := "检测Wind数据服务器2失败:CheckWindDataInterface ErrMsg:" + string(body)
- msg := fmt.Sprintf("检测%s ;失败:CheckWindDataInterface ErrMsg:%s", checkUrl, string(body))
- go alarm_msg.SendAlarmMsg(msg, 3)
- }
- }
- }(hzDataWindUrl)
- }
- return
- }
- // RefreshDataFromCoal 刷新煤炭网数据
- func RefreshDataFromCoal(wg *sync.WaitGroup) (err error) {
- defer func() {
- if err != nil {
- fmt.Println("RefreshDataFromCoal Err:" + err.Error())
- //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromCoal ErrMsg:"+err.Error(), utils.EmailSendToUsers)
- go alarm_msg.SendAlarmMsg("RefreshDataFromCoal ErrMsg:"+err.Error(), 3)
- }
- wg.Done()
- }()
- var condition string
- var pars []interface{}
- condition += " AND source=? "
- pars = append(pars, utils.DATA_SOURCE_COAL)
- items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
- if err != nil {
- return errors.New("GetEdbInfoByCondition:" + err.Error())
- }
- //var endDate string
- //endDate = time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
- for _, v := range items {
- startDate := ""
- if v.Frequency == "日度" {
- startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- } else if v.Frequency == "周度" {
- startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
- } else if v.Frequency == "月度" {
- startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
- } else if v.Frequency == "季度" {
- startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
- } else if v.Frequency == "年度" {
- startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
- } else {
- startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- }
- //fmt.Println(startDate, endDate)
- //err = data_manage.RefreshEdbDataByZz(v.EdbInfoId, v.EdbCode, startDate, endDate)
- //if err != nil {
- // return errors.New("RefreshEdbDataByZz:" + err.Error())
- //}
- resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
- if err != nil {
- return errors.New("RefreshEdbData Err:" + err.Error())
- }
- if resp.Ret != 200 {
- return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
- }
- //item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
- //if err != nil {
- // return err
- //}
- //if item != nil {
- // err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
- // if err != nil {
- // return err
- // }
- //}
- }
- return err
- }
- // RefreshDataFromEic 刷欧洲天然气数据
- func RefreshDataFromEic(wg *sync.WaitGroup) (err error) {
- defer func() {
- if err != nil {
- fmt.Println("RefreshDataFromEic Err:" + err.Error())
- //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromCoal ErrMsg:"+err.Error(), utils.EmailSendToUsers)
- go alarm_msg.SendAlarmMsg("RefreshDataFromEic ErrMsg:"+err.Error(), 3)
- }
- wg.Done()
- }()
- var condition string
- var pars []interface{}
- condition += " AND source=? "
- pars = append(pars, utils.DATA_SOURCE_GIE)
- items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
- if err != nil {
- return errors.New("GetEdbInfoByCondition:" + err.Error())
- }
- //var endDate string
- //endDate = time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
- for _, v := range items {
- startDate := ""
- if v.Frequency == "日度" {
- startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- } else if v.Frequency == "周度" {
- startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
- } else if v.Frequency == "月度" {
- startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
- } else if v.Frequency == "季度" {
- startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
- } else if v.Frequency == "年度" {
- startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
- } else {
- startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- }
- //fmt.Println(startDate, endDate)
- //err = data_manage.RefreshEdbDataByZz(v.EdbInfoId, v.EdbCode, startDate, endDate)
- //if err != nil {
- // return errors.New("RefreshEdbDataByZz:" + err.Error())
- //}
- resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
- if err != nil {
- return errors.New("RefreshEdbData Err:" + err.Error())
- }
- if resp.Ret != 200 {
- return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
- }
- //item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
- //if err != nil {
- // return err
- //}
- //if item != nil {
- // err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
- // if err != nil {
- // return err
- // }
- //}
- }
- return err
- }
- // RefreshDataFromEic 刷新谷歌出行数据
- func RefreshDataFromGoogleTravel(wg *sync.WaitGroup) (err error) {
- defer func() {
- if err != nil {
- fmt.Println("RefreshDataFromGoogleTravel Err:" + err.Error())
- go alarm_msg.SendAlarmMsg("RefreshDataFromGoogleTravel ErrMsg:"+err.Error(), 3)
- }
- wg.Done()
- }()
- var condition string
- var pars []interface{}
- condition += " AND source=? "
- pars = append(pars, utils.DATA_SOURCE_GOOGLE_TRAVEL)
- items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
- if err != nil {
- return errors.New("GetEdbInfoByCondition:" + err.Error())
- }
- for _, v := range items {
- startDate := ""
- if v.Frequency == "日度" {
- startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- } else if v.Frequency == "周度" {
- startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
- } else if v.Frequency == "月度" {
- startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
- } else if v.Frequency == "季度" {
- startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
- } else if v.Frequency == "年度" {
- startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
- } else {
- startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- }
- resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
- if err != nil {
- return errors.New("RefreshEdbData Err:" + err.Error())
- }
- if resp.Ret != 200 {
- return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
- }
- //item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
- //if err != nil {
- // return err
- //}
- //if item != nil {
- // err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
- // if err != nil {
- // return err
- // }
- //}
- }
- return err
- }
- // RefreshDataFromMysteelChemical 刷新钢联化工数据
- func RefreshDataFromMysteelChemical(wg *sync.WaitGroup) (err error) {
- defer func() {
- if err != nil {
- fmt.Println("RefreshDataFromMysteelChemical Err:" + err.Error())
- //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromGl ErrMsg:"+err.Error(), utils.EmailSendToUsers)
- go alarm_msg.SendAlarmMsg("RefreshDataFromMysteelChemical ErrMsg:"+err.Error(), 3)
- }
- wg.Done()
- }()
- var condition string
- var pars []interface{}
- condition += " AND source=? "
- pars = append(pars, utils.DATA_SOURCE_MYSTEEL_CHEMICAL)
- items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
- if err != nil {
- return errors.New("GetEdbInfoByCondition:" + err.Error())
- }
- //var endDate string
- //endDate = time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
- for _, v := range items {
- startDate := ""
- if v.Frequency == "日度" {
- startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- } else if v.Frequency == "周度" {
- startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
- } else if v.Frequency == "月度" {
- startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
- } else if v.Frequency == "季度" {
- startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
- } else if v.Frequency == "年度" {
- startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
- } else {
- startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- }
- //fmt.Println(startDate, endDate)
- //err = data_manage.RefreshEdbDataByGl(v.EdbInfoId, v.EdbCode, startDate, endDate)
- //if err != nil {
- // return errors.New("RefreshEdbDataByGl:" + err.Error())
- //}
- resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
- if err != nil {
- return errors.New("RefreshEdbData Err:" + err.Error())
- }
- if resp.Ret != 200 {
- return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
- }
- //item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
- //if err != nil {
- // return err
- //}
- //if item != nil {
- // err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
- // if err != nil {
- // return err
- // }
- //}
- }
- return err
- }
- // RefreshDataFromEiaSteo 刷新eia steo 报告数据
- func RefreshDataFromEiaSteo(wg *sync.WaitGroup) (err error) {
- defer func() {
- if err != nil {
- fmt.Println("RefreshDataFromEiaSteo Err:" + err.Error())
- //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromGl ErrMsg:"+err.Error(), utils.EmailSendToUsers)
- go alarm_msg.SendAlarmMsg("RefreshDataFromEiaSteo ErrMsg:"+err.Error(), 3)
- }
- wg.Done()
- }()
- var condition string
- var pars []interface{}
- condition += " AND source=? "
- pars = append(pars, utils.DATA_SOURCE_EIA_STEO)
- items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
- if err != nil {
- return errors.New("GetEdbInfoByCondition:" + err.Error())
- }
- //var endDate string
- //endDate = time.Now().AddDate(utils.DATA_END_DATE_LIMIT, 0, 0).Format(utils.FormatDateUnSpace)
- for _, v := range items {
- startDate := ""
- if v.Frequency == "日度" {
- startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- } else if v.Frequency == "周度" {
- startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
- } else if v.Frequency == "月度" {
- startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
- } else if v.Frequency == "季度" {
- startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
- } else if v.Frequency == "年度" {
- startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
- } else {
- startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- }
- resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
- if err != nil {
- return errors.New("RefreshDataFromEiaSteoData Err:" + err.Error())
- }
- if resp.Ret != 200 {
- return errors.New("RefreshDataFromEiaSteoData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
- }
- //item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
- //if err != nil {
- // return err
- //}
- //if item != nil {
- // err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
- // if err != nil {
- // return err
- // }
- //}
- }
- return err
- }
- // RefreshDataFromComTrade 刷新 UN 数据
- func RefreshDataFromComTrade(wg *sync.WaitGroup) (err error) {
- defer func() {
- if err != nil {
- fmt.Println("RefreshDataFromComTrade Err:" + err.Error())
- //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromGl ErrMsg:"+err.Error(), utils.EmailSendToUsers)
- go alarm_msg.SendAlarmMsg("RefreshDataFromComTrade ErrMsg:"+err.Error(), 3)
- }
- wg.Done()
- }()
- var condition string
- var pars []interface{}
- condition += " AND source=? "
- pars = append(pars, utils.DATA_SOURCE_COM_TRADE)
- items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
- if err != nil {
- return errors.New("GetEdbInfoByCondition:" + err.Error())
- }
- for _, v := range items {
- startDate := ""
- if v.Frequency == "日度" {
- startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- } else if v.Frequency == "周度" {
- startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
- } else if v.Frequency == "月度" {
- startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
- } else if v.Frequency == "季度" {
- startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
- } else if v.Frequency == "年度" {
- startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
- } else {
- startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- }
- resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
- if err != nil {
- return errors.New("RefreshDataFromComTrade Err:" + err.Error())
- }
- if resp.Ret != 200 {
- return errors.New("RefreshDataFromComTrade Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
- }
- }
- return err
- }
- // RefreshDataFromSci 刷新 卓创 数据
- func RefreshDataFromSci(wg *sync.WaitGroup) (err error) {
- defer func() {
- if err != nil {
- fmt.Println("RefreshDataFromSci Err:" + err.Error())
- //go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "RefreshDataFromGl ErrMsg:"+err.Error(), utils.EmailSendToUsers)
- go alarm_msg.SendAlarmMsg("RefreshDataFromSci ErrMsg:"+err.Error(), 3)
- }
- wg.Done()
- }()
- var condition string
- var pars []interface{}
- condition += " AND source=? "
- pars = append(pars, utils.DATA_SOURCE_SCI)
- items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
- if err != nil {
- return errors.New("GetEdbInfoByCondition:" + err.Error())
- }
- for _, v := range items {
- startDate := ""
- if v.Frequency == "日度" {
- startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- } else if v.Frequency == "周度" {
- startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
- } else if v.Frequency == "月度" {
- startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
- } else if v.Frequency == "季度" {
- startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
- } else if v.Frequency == "年度" {
- startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
- } else {
- startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- }
- resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
- if err != nil {
- return errors.New("RefreshDataFromSci Err:" + err.Error())
- }
- if resp.Ret != 200 {
- return errors.New("RefreshDataFromSci Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
- }
- }
- return err
- }
- // RefreshDataFromNationalStatistics 刷新统计局数据
- func RefreshDataFromNationalStatistics(wg *sync.WaitGroup) (err error) {
- defer func() {
- if err != nil {
- fmt.Println("RefreshDataFromNationalStatistics Err:" + err.Error())
- go alarm_msg.SendAlarmMsg("RefreshDataFromNationalStatistics ErrMsg:"+err.Error(), 3)
- }
- wg.Done()
- }()
- var condition string
- var pars []interface{}
- condition += ` AND source = ? `
- pars = append(pars, utils.DATA_SOURCE_NATIONAL_STATISTICS)
- items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
- if err != nil {
- return errors.New("GetEdbInfoByCondition:" + err.Error())
- }
- for _, v := range items {
- startDate := ""
- if v.Frequency == "日度" {
- startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- } else if v.Frequency == "周度" {
- startDate = v.EndDate.AddDate(0, 0, -(utils.DATA_REFRESH * 7)).Format(utils.FormatDate)
- } else if v.Frequency == "月度" {
- startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH, 0).Format(utils.FormatDate)
- } else if v.Frequency == "季度" {
- startDate = v.EndDate.AddDate(0, -utils.DATA_REFRESH*3, 0).Format(utils.FormatDate)
- } else if v.Frequency == "年度" {
- startDate = v.EndDate.AddDate(-utils.DATA_REFRESH, 0, 0).Format(utils.FormatDate)
- } else {
- startDate = v.EndDate.AddDate(0, 0, -utils.DATA_REFRESH).Format(utils.FormatDate)
- }
- resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.EdbCode, startDate)
- if err != nil {
- return errors.New("RefreshDataFromNationalStatistics Err:" + err.Error())
- }
- if resp.Ret != 200 {
- return errors.New("RefreshDataFromNationalStatistics Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
- }
- }
- return err
- }
|