|
@@ -10,22 +10,100 @@ import (
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
-// RefreshNationalData 刷新统计局数据
|
|
|
-func RefreshNationalData(cont context.Context) (err error) {
|
|
|
+// RefreshNationalDbs 刷新统计局数据(所有)
|
|
|
+func RefreshNationalDbs(cont context.Context) (err error) {
|
|
|
utils.FileLog.Info("开始刷新统计局数据")
|
|
|
|
|
|
- _ = SyncXDateYQuotaDb()
|
|
|
+ _ = SyncXDateYQuotaDb([]string{})
|
|
|
|
|
|
- _ = SyncXDateYQuotaZRegDb()
|
|
|
+ _ = SyncXDateYQuotaZRegDb([]string{})
|
|
|
|
|
|
- _ = SyncXRegYDateZQuotaDb()
|
|
|
+ _ = SyncXRegYDateZQuotaDb([]string{})
|
|
|
+
|
|
|
+ // 最后更新一下每个指标的开始结束日期
|
|
|
+ if e := models.UpdateNationalStatisticsIndexStartEndDate(); e != nil {
|
|
|
+ alarm_msg.SendAlarmMsg(fmt.Sprintf("统计局-更新指标开始结束日期失败, ErrMsg: %s", e.Error()), 3)
|
|
|
+ }
|
|
|
|
|
|
utils.FileLog.Info("统计局数据刷新成功")
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+// RefreshNationalMonthDbA 刷新月度指标库
|
|
|
+func RefreshNationalMonthDbA(cont context.Context) (err error) {
|
|
|
+ utils.FileLog.Info("统计局-开始同步月度指标库A")
|
|
|
+ SelectSyncFunc([]string{"hgyd", "fsyd"})
|
|
|
+ utils.FileLog.Info("统计局-同步月度指标库A成功")
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// RefreshNationalMonthDbB 刷新月度指标库(主要城市月度、港澳台月度)
|
|
|
+func RefreshNationalMonthDbB(cont context.Context) (err error) {
|
|
|
+ utils.FileLog.Info("统计局-开始同步月度指标库B")
|
|
|
+ SelectSyncFunc([]string{"csyd", "gatyd"})
|
|
|
+ utils.FileLog.Info("统计局-同步月度指标库B成功")
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// RefreshNationalMonthDbC 刷新月度指标库(国际数据)
|
|
|
+func RefreshNationalMonthDbC(cont context.Context) (err error) {
|
|
|
+ utils.FileLog.Info("统计局-开始同步月度指标库C")
|
|
|
+ SelectSyncFunc([]string{"gjyd", "gjydsdj", "gjydsc"})
|
|
|
+ utils.FileLog.Info("统计局-同步月度指标库C成功")
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// RefreshNationalQuarterDb 刷新季度指标库
|
|
|
+func RefreshNationalQuarterDb(cont context.Context) (err error) {
|
|
|
+ utils.FileLog.Info("统计局-开始同步季度指标库")
|
|
|
+ SelectSyncFunc([]string{"hgjd", "fsjd"})
|
|
|
+ utils.FileLog.Info("统计局-同步季度指标库成功")
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// RefreshNationalYearDbA 刷新年度指标库(年度数据、分省年度数据)
|
|
|
+func RefreshNationalYearDbA(cont context.Context) (err error) {
|
|
|
+ utils.FileLog.Info("统计局-开始同步年度指标库A")
|
|
|
+ SelectSyncFunc([]string{"hgnd", "fsnd"})
|
|
|
+ utils.FileLog.Info("统计局-同步年度指标库A成功")
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// RefreshNationalYearDbB 刷新年度指标库(主要城市年度数据、港澳台年度数据、国际年度数据)
|
|
|
+func RefreshNationalYearDbB(cont context.Context) (err error) {
|
|
|
+ utils.FileLog.Info("统计局-开始同步年度指标库B")
|
|
|
+ SelectSyncFunc([]string{"csnd", "gatnd", "gjnd"})
|
|
|
+ utils.FileLog.Info("统计局-同步年度指标库B成功")
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func SelectSyncFunc(dbs []string) {
|
|
|
+ funcA := []string{"hgyd", "hgjd", "hgnd"}
|
|
|
+ funcB := []string{"fsyd", "fsjd", "fsnd", "csyd", "csnd", "gjydsc"}
|
|
|
+ funcC := []string{"gatyd", "gatnd", "gjyd", "gjydsdj", "gjnd"}
|
|
|
+ // 此处要根据不同的指标库选择同步方式
|
|
|
+ for _, q := range dbs {
|
|
|
+ if utils.InArrayByStr(funcA, q) {
|
|
|
+ _ = SyncXDateYQuotaDb([]string{q})
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if utils.InArrayByStr(funcB, q) {
|
|
|
+ _ = SyncXDateYQuotaZRegDb([]string{q})
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if utils.InArrayByStr(funcC, q) {
|
|
|
+ _ = SyncXRegYDateZQuotaDb([]string{q})
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 最后更新一下每个指标的开始结束日期
|
|
|
+ if e := models.UpdateNationalStatisticsIndexStartEndDate(); e != nil {
|
|
|
+ alarm_msg.SendAlarmMsg(fmt.Sprintf("统计局-更新指标开始结束日期失败, ErrMsg: %s", e.Error()), 3)
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
// SyncXDateYQuotaDb 同步两维度X轴-日期, Y轴-指标数据库(月度/季度/年度数据指标)
|
|
|
-func SyncXDateYQuotaDb() (err error) {
|
|
|
+func SyncXDateYQuotaDb(dbs []string) (err error) {
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
|
utils.FileLog.Error("统计局-同步月度/季度/年度数据失败, ErrMsg: %s", err.Error())
|
|
@@ -34,25 +112,31 @@ func SyncXDateYQuotaDb() (err error) {
|
|
|
}
|
|
|
utils.FileLog.Info("统计局-同步月度/季度/年度数据成功")
|
|
|
}()
|
|
|
-
|
|
|
- // 查询无父级的指标分类
|
|
|
- classifyOB := new(models.BaseFromNationalStatisticsClassify)
|
|
|
- classifyCond := ` AND is_parent = 0 AND dbcode IN ('hgyd', 'hgjd', 'hgnd')`
|
|
|
- classifyPars := make([]interface{}, 0)
|
|
|
- classifyOrder := ` base_from_national_statistics_classify_id ASC`
|
|
|
- classifyList, e := classifyOB.GetItemsByCondition(classifyCond, classifyPars, []string{}, classifyOrder)
|
|
|
- if e != nil {
|
|
|
- err = fmt.Errorf("获取指标分类列表失败, Err: %s", e.Error())
|
|
|
- return
|
|
|
+ if len(dbs) == 0 {
|
|
|
+ dbs = []string{"hgyd", "hgjd", "hgnd"}
|
|
|
}
|
|
|
- utils.FileLog.Info("分类长度: %d\n", len(classifyList))
|
|
|
|
|
|
- // 同步指标和数据
|
|
|
- for _, c := range classifyList {
|
|
|
- if e = SyncXDateYQuotaData(c.BaseFromNationalStatisticsClassifyId, c.Dbcode, c.Id); e != nil {
|
|
|
- err = fmt.Errorf("同步指标数据失败, DbCode: %s, ClassifyId: %d, Err: %s", c.Dbcode, c.BaseFromNationalStatisticsClassifyId, e.Error())
|
|
|
+ // 查询无父级的指标分类
|
|
|
+ for _, d := range dbs {
|
|
|
+ classifyOB := new(models.BaseFromNationalStatisticsClassify)
|
|
|
+ classifyCond := ` AND is_parent = 0 AND dbcode = ?`
|
|
|
+ classifyPars := make([]interface{}, 0)
|
|
|
+ classifyPars = append(classifyPars, d)
|
|
|
+ classifyOrder := ` base_from_national_statistics_classify_id ASC`
|
|
|
+ classifyList, e := classifyOB.GetItemsByCondition(classifyCond, classifyPars, []string{}, classifyOrder)
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("获取指标分类列表失败, Err: %s", e.Error())
|
|
|
return
|
|
|
}
|
|
|
+ utils.FileLog.Info("%s分类长度: %d\n", d, len(classifyList))
|
|
|
+
|
|
|
+ // 同步指标和数据
|
|
|
+ for _, c := range classifyList {
|
|
|
+ if e = SyncXDateYQuotaData(c.BaseFromNationalStatisticsClassifyId, c.Dbcode, c.Id); e != nil {
|
|
|
+ err = fmt.Errorf("同步指标数据失败, DbCode: %s, ClassifyId: %d, Err: %s", c.Dbcode, c.BaseFromNationalStatisticsClassifyId, e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
return
|
|
|
}
|
|
@@ -212,7 +296,7 @@ func SyncXDateYQuotaData(classifyId int, dbCode, classifyCode string) (err error
|
|
|
}
|
|
|
|
|
|
// SyncXDateYQuotaZRegDb 同步三维度X轴-日期, Y轴-指标, Z轴-地区的数据库(分省月季年度、主要城市月年度、国际市场月度商品价格)
|
|
|
-func SyncXDateYQuotaZRegDb() (err error) {
|
|
|
+func SyncXDateYQuotaZRegDb(dbs []string) (err error) {
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
|
utils.FileLog.Error("统计局-同步分省月季年度、主要城市月年度、国际市场月度商品价格失败, ErrMsg: %s", err.Error())
|
|
@@ -221,10 +305,12 @@ func SyncXDateYQuotaZRegDb() (err error) {
|
|
|
}
|
|
|
utils.FileLog.Info("统计局-同步分省月季年度、主要城市月年度、国际市场月度商品价格成功")
|
|
|
}()
|
|
|
+ if len(dbs) == 0 {
|
|
|
+ dbs = []string{"fsyd", "fsjd", "fsnd", "csyd", "csnd", "gjydsc"}
|
|
|
+ }
|
|
|
|
|
|
// 需要同步的数据库
|
|
|
- dbCodes := []string{"fsyd", "fsjd", "fsnd", "csyd", "csnd", "gjydsc"}
|
|
|
- for _, d := range dbCodes {
|
|
|
+ for _, d := range dbs {
|
|
|
classifyOB := new(models.BaseFromNationalStatisticsClassify)
|
|
|
// 注意此处只需要同步分类中为指标的即可, 分类为地区的数据在指标中均有包含
|
|
|
classifyCond := ` AND is_parent = 0 AND wdcode = 'zb' AND dbcode = ?`
|
|
@@ -429,7 +515,7 @@ func SyncXDateYQuotaZRegData(classifyId int, dbCode, classifyCode string, regLis
|
|
|
}
|
|
|
|
|
|
// SyncXRegYDateZQuotaDb 同步三维度X轴-地区, Y轴-日期的数据库(港澳台、国际数据指标)
|
|
|
-func SyncXRegYDateZQuotaDb() (err error) {
|
|
|
+func SyncXRegYDateZQuotaDb(dbs []string) (err error) {
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
|
utils.FileLog.Error("统计局-同步港澳台、国际数据指标失败, ErrMsg: %s", err.Error())
|
|
@@ -438,10 +524,12 @@ func SyncXRegYDateZQuotaDb() (err error) {
|
|
|
}
|
|
|
utils.FileLog.Info("统计局-同步港澳台、国际数据指标成功")
|
|
|
}()
|
|
|
+ if len(dbs) == 0 {
|
|
|
+ dbs = []string{"gatyd", "gatnd", "gjyd", "gjydsdj", "gjnd"}
|
|
|
+ }
|
|
|
|
|
|
// 需要同步的数据库
|
|
|
- dbCodes := []string{"gatyd", "gatnd", "gjyd", "gjydsdj", "gjnd"}
|
|
|
- for _, d := range dbCodes {
|
|
|
+ for _, d := range dbs {
|
|
|
classifyOB := new(models.BaseFromNationalStatisticsClassify)
|
|
|
// 注意此处只需要同步分类中为指标的即可, 分类为地区的数据在指标中均有包含
|
|
|
classifyCond := ` AND is_parent = 0 AND wdcode = 'zb' AND dbcode = ?`
|