123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- package data
- import (
- "hongze/hongze_task/models/data_manage"
- "hongze/hongze_task/utils"
- "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, v.EdbCode)
- if err != nil {
- return
- }
- if item != nil {
- err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
- if err != nil {
- return
- }
- }
- }
- lock.Unlock()
- }
- var lzLock sync.Mutex
- //同步隆重数据
- func SyncLzDataBase() {
- lzLock.Lock()
- var err error
- defer func() {
- if err != nil {
- utils.FileLog.Info("SyncLzDataBase Err:" + err.Error())
- go utils.SendEmailByHongze("同步隆众数据失败", "同步隆众数据失败 Err:"+err.Error(), utils.RefreshEdbInfoEmailSendToUsers, "", "")
- }
- }()
- 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
- }
- for _, v := range items {
- err = data_manage.RefreshEdbDataByLz(v.EdbInfoId, v.EdbCode, v.StartDate.Format(utils.FormatDate), "")
- if err != nil {
- return
- }
- item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
- if err != nil {
- return
- }
- if item != nil {
- err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
- if err != nil {
- return
- }
- }
- }
- lzLock.Unlock()
- }
- var smmLock sync.Mutex
- //同步有色数据
- func SyncSmmDataBase() {
- smmLock.Lock()
- var err error
- defer func() {
- if err != nil {
- utils.FileLog.Info("SyncSmmDataBase Err:" + err.Error())
- go utils.SendEmailByHongze("同步有色数据失败", "同步隆众数据失败 Err:"+err.Error(), utils.RefreshEdbInfoEmailSendToUsers, "", "")
- }
- }()
- 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
- }
- for _, v := range items {
- err = data_manage.RefreshEdbDataByYs(v.EdbInfoId, v.EdbCode, v.StartDate.Format(utils.FormatDate), "")
- if err != nil {
- return
- }
- item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
- if err != nil {
- return
- }
- if item != nil {
- err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
- if err != nil {
- return
- }
- }
- }
- smmLock.Unlock()
- }
- var manualLock sync.Mutex
- //同步手工数据
- func SyncManualDataBase() {
- var err error
- manualLock.Lock()
- defer func() {
- if err != nil {
- utils.FileLog.Info("SyncLzDataBase Err:" + err.Error())
- go utils.SendEmailByHongze("同步手工数据失败", "同步手工数据失败 Err:"+err.Error(), 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 {
- return
- }
- for _, v := range items {
- err = data_manage.RefreshManual(v)
- if err != nil {
- return
- }
- item, err := data_manage.GetEdbInfoMaxAndMinInfo(v.Source, v.EdbCode)
- if err != nil {
- return
- }
- if item != nil {
- err = data_manage.ModifyEdbInfoMaxAndMinInfo(v.EdbInfoId, item)
- if err != nil {
- return
- }
- }
- }
- manualLock.Unlock()
- }
|