123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- package data
- import (
- "eta/eta_task/models/data_manage"
- "eta/eta_task/utils"
- "strings"
- "sync"
- )
- var lock sync.Mutex
- // 同步钢炼数据
- func SyncGlDataBase() {
- lock.Lock()
- var err error
- defer func() {
- if err != nil {
- utils.FileLog.Info("SyncGlDataBase Err:" + err.Error())
- }
- }()
- 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
- }
- for _, v := range items {
- err = data_manage.RefreshEdbDataByGl(v.EdbInfoId, v.EdbCode, v.StartDate.Format(utils.FormatDate), "")
- if err != nil {
- return
- }
- item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, utils.DATA_SUB_SOURCE_EDB, v.EdbCode)
- if err != nil {
- return
- }
- if item != nil {
- err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
- if err != nil {
- return
- }
- }
- }
- lock.Unlock()
- }
- var manualLock sync.Mutex
- // SyncManualDataBase 同步手工数据
- func SyncManualDataBase() {
- var err error
- errMsgList := make([]string, 0)
- manualLock.Lock()
- defer func() {
- manualLock.Unlock()
- if len(errMsgList) > 0 {
- errMsg := strings.Join(errMsgList, "\n")
- utils.FileLog.Info("SyncManualDataBase Err:" + errMsg)
- go utils.SendEmailByHongze("同步手工数据失败", "同步手工数据失败 Err:"+errMsg, utils.RefreshEdbInfoEmailSendToUsers, "", "")
- }
- }()
- var condition string
- var pars []interface{}
- condition += " AND source=? "
- //condition += " AND edb_code='W000156' "
- pars = append(pars, utils.DATA_SOURCE_MANUAL)
- items, err := data_manage.GetEdbInfoByCondition(condition, pars, 0)
- if err != nil {
- errMsgList = append(errMsgList, "获取指标失败 ;Err:"+err.Error())
- return
- }
- for _, v := range items {
- startDate := v.StartDate.Format(utils.FormatDate)
- resp, err := RefreshEdbData(v.EdbInfoId, v.Source, v.SubSource, v.EdbCode, startDate)
- if err != nil {
- //return errors.New("RefreshEdbData Err:" + err.Error())
- errMsgList = append(errMsgList, "RefreshEdbData Err:"+err.Error())
- continue
- }
- if resp.Ret != 200 {
- //return errors.New("RefreshEdbData Err:" + resp.Msg + ";ErrMsg:" + resp.ErrMsg)
- errMsgList = append(errMsgList, "RefreshEdbData Err:"+resp.Msg+";ErrMsg:"+resp.ErrMsg)
- continue
- }
- }
- }
|