Bladeren bron

煤炭网刷新bug

ziwen 3 jaren geleden
bovenliggende
commit
36c5b1fd26
1 gewijzigde bestanden met toevoegingen van 44 en 4 verwijderingen
  1. 44 4
      models/data_manage/edb_data_coal.go

+ 44 - 4
models/data_manage/edb_data_coal.go

@@ -51,6 +51,31 @@ func GetCoalSurveyDataByTradeCode(condition string, pars []interface{}) (item []
 	return
 }
 
+type BaseFromCoalmineIndex struct {
+	BaseFromCoalmineCompanyIndexId int
+	IndexName                      string `description:"持买单量指标名称"`
+	IndexCode                      string `description:"持买单量指标编码"`
+	DealValue                      string `description:"成交量"`
+	DataTime                       string `description:"数据日期"`
+	Source                         string `description:"来源"`
+	Province                       string `description:"省份"`
+	City                           string `description:"城市"`
+	GroupName                      string `description:"集团名称"`
+	Unit                           string `description:"单位"`
+	Frequency                      string `description:"频率"`
+	CreateTime                     string `description:"插入时间"`
+	ModifyTime                     string `description:"修改时间"`
+}
+
+func GetBaseFromCoalIndexByCode(suffix, indexCode string) (items []*BaseFromCoalmineIndex, err error) {
+	o := orm.NewOrm()
+	o.Using("data")
+	sql := `SELECT * FROM base_from_coalmine_%s WHERE index_code=? `
+	sql = fmt.Sprintf(sql, suffix)
+	_, err = o.Raw(sql, indexCode).QueryRows(&items)
+	return
+}
+
 func GetEdbDataCoalByCode(edbCode string) (items []*EdbInfoSearchData, err error) {
 	o := orm.NewOrm()
 	o.Using("data")
@@ -257,9 +282,21 @@ func RefreshAllEdbDataByCoal(edbInfoId, source int, edbCode, startDate, endDate
 	//计算数据
 	var condition string
 	var pars []interface{}
+	var suffix string
+	if strings.Contains(edbCode, "jsm") {
+		suffix = "jsm_index"
+	} else if strings.Contains(edbCode, "company") {
+		suffix = "company_index"
+	} else if strings.Contains(edbCode, "firm") {
+		suffix = "firm_index"
+	} else if strings.Contains(edbCode, "coastal") {
+		suffix = "coastal_index"
+	} else if strings.Contains(edbCode, "inland") {
+		suffix = "inland_index"
+	}
 
 	if edbCode != "" {
-		condition += " AND b.coal_code=? "
+		condition += " AND b.index_code=? "
 		pars = append(pars, edbCode)
 	}
 
@@ -273,7 +310,10 @@ func RefreshAllEdbDataByCoal(edbInfoId, source int, edbCode, startDate, endDate
 		pars = append(pars, endDate)
 	}
 
-	coalDataList, err := GetCoalSurveyDataByTradeCode(condition, pars)
+	coalBaseDataAll, err := GetBaseFromCoalIndexByCode(suffix, edbCode)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		return
+	}
 
 	//获取指标所有数据
 	dataList := make([]*EdbDataBase, 0)
@@ -291,11 +331,11 @@ func RefreshAllEdbDataByCoal(edbInfoId, source int, edbCode, startDate, endDate
 
 	addSql := ` INSERT INTO edb_data_coal(edb_info_id,edb_code,data_time,value,create_time,modify_time,status,data_timestamp) values `
 	var isAdd bool
-	for _, v := range coalDataList {
+	for _, v := range coalBaseDataAll {
 		item := v
 
 		eDate := item.DataTime
-		sValue := item.InputValue
+		sValue := item.DealValue
 		dataTime, err := time.Parse(utils.FormatDate, eDate)
 		if err != nil {
 			return err