Forráskód Böngészése

rank 关键词处理

xyxie 9 hónapja
szülő
commit
213f92d27b
1 módosított fájl, 10 hozzáadás és 16 törlés
  1. 10 16
      models/data_manage/trade_position_analysis.go

+ 10 - 16
models/data_manage/trade_position_analysis.go

@@ -229,16 +229,14 @@ func GetTradePositionTopByExchangeDataTimeTypeClassify(exchange string, dataTime
 func MultiInsertTradeBaseDataToTop(exchange string, startDate, endDate string) (err error) {
 	o := orm.NewOrm()
 	now := time.Now().Format(utils.FormatDateTime)
-	sql1 := `INSERT INTO trade_position_` + exchange + `_top(classify_name,classify_type,deal_short_name,deal_value,deal_change,data_time,deal_type,source_type,rank,create_time,modify_time)
-	SELECT classify_name,classify_type,buy_short_name,buy_value,buy_change,data_time,1,0,rank,?,? FROM base_from_trade_` + exchange + `_index where buy_short_name !="" and buy_short_name !=" " and data_time between ? and ?`
-	sql1 += " and `rank` <50 "
+	sql1 := "INSERT INTO trade_position_" + exchange + "_top(classify_name,classify_type,deal_short_name,deal_value,deal_change,data_time,deal_type,source_type,`rank`,create_time,modify_time) " +
+		"SELECT classify_name,classify_type,buy_short_name,buy_value,buy_change,data_time,1,0,`rank`,?,? FROM base_from_trade_" + exchange + "_index where `rank` <50 and buy_short_name !='' and buy_short_name !=' ' and data_time between ? and ?"
 	_, err = o.Raw(sql1, now, now, startDate, endDate).Exec()
 	if err != nil {
 		return
 	}
-	sql2 := `INSERT INTO trade_position_` + exchange + `_top(classify_name,classify_type,deal_short_name,deal_value,deal_change,data_time,deal_type,source_type,rank,create_time,modify_time)
-SELECT classify_name,classify_type,sold_short_name,sold_value,sold_change,data_time,2,0,rank,?,? FROM base_from_trade_` + exchange + `_index where sold_short_name !="" and sold_short_name !=" " and data_time between ? and ?`
-	sql2 += " and `rank` <50 "
+	sql2 := "INSERT INTO trade_position_" + exchange + "_top(classify_name,classify_type,deal_short_name,deal_value,deal_change,data_time,deal_type,source_type,`rank`,create_time,modify_time) " +
+		"SELECT classify_name,classify_type,sold_short_name,sold_value,sold_change,data_time,2,0,`rank`,?,? FROM base_from_trade_" + exchange + "_index where ``rank`` <50 and sold_short_name !='' and sold_short_name !=' ' and data_time between ? and ?"
 	_, err = o.Raw(sql2, now, now, startDate, endDate).Exec()
 	return
 }
@@ -246,16 +244,14 @@ SELECT classify_name,classify_type,sold_short_name,sold_value,sold_change,data_t
 func MultiInsertTradeBaseDataToTopByClassify(exchange string, startDate, endDate string, classifyNames, classifyTypes []string) (err error) {
 	o := orm.NewOrm()
 	now := time.Now().Format(utils.FormatDateTime)
-	sql1 := `INSERT INTO trade_position_` + exchange + `_top(classify_name,classify_type,deal_short_name,deal_value,deal_change,data_time,deal_type,source_type,rank,create_time,modify_time)
-	SELECT classify_name,classify_type,buy_short_name,buy_value,buy_change,data_time,1,0,rank,?,? FROM base_from_trade_` + exchange + `_index where buy_short_name !="" and buy_short_name !=" " and data_time between ? and ? and classify_name in (` + utils.GetOrmInReplace(len(classifyNames)) + `)  and classify_type in (` + utils.GetOrmInReplace(len(classifyTypes)) + `)`
-	sql1 += " and `rank` <50 "
+	sql1 := "INSERT INTO trade_position_" + exchange + "_top(classify_name,classify_type,deal_short_name,deal_value,deal_change,data_time,deal_type,source_type,`rank`,create_time,modify_time)" +
+		"SELECT classify_name,classify_type,buy_short_name,buy_value,buy_change,data_time,1,0,`rank`,?,? FROM base_from_trade_" + exchange + "_index where `rank` <50 and buy_short_name !='' and buy_short_name !=' ' and data_time between ? and ? and classify_name in (" + utils.GetOrmInReplace(len(classifyNames)) + ")  and classify_type in (" + utils.GetOrmInReplace(len(classifyTypes)) + ")"
 	_, err = o.Raw(sql1, now, now, startDate, endDate, classifyNames, classifyTypes).Exec()
 	if err != nil {
 		return
 	}
-	sql2 := `INSERT INTO trade_position_` + exchange + `_top(classify_name,classify_type,deal_short_name,deal_value,deal_change,data_time,deal_type,source_type,rank,create_time,modify_time)
-SELECT classify_name,classify_type,sold_short_name,sold_value,sold_change,data_time,2,0,rank,?,? FROM base_from_trade_` + exchange + `_index where sold_short_name !="" and sold_short_name !=" " and data_time between ? and ? and classify_name in (` + utils.GetOrmInReplace(len(classifyNames)) + `)  and classify_type in (` + utils.GetOrmInReplace(len(classifyTypes)) + `)`
-	sql2 += " and `rank` <50 "
+	sql2 := "INSERT INTO trade_position_" + exchange + "_top(classify_name,classify_type,deal_short_name,deal_value,deal_change,data_time,deal_type,source_type,`rank`,create_time,modify_time)" +
+		"SELECT classify_name,classify_type,sold_short_name,sold_value,sold_change,data_time,2,0,`rank`,?,? FROM base_from_trade_" + exchange + "_index where `rank` <50 and sold_short_name !='' and sold_short_name !=' ' and data_time between ? and ? and classify_name in (" + utils.GetOrmInReplace(len(classifyNames)) + ")  and classify_type in (" + utils.GetOrmInReplace(len(classifyTypes)) + ")"
 	_, err = o.Raw(sql2, now, now, startDate, endDate, classifyNames, classifyTypes).Exec()
 	return
 }
@@ -367,8 +363,7 @@ func MultiUpdatePositionTopChangeVal(exchange string, updates []UpdateChangeVal)
 
 func GetTradePositionOriginClassifyCountByExchangeDataTime(exchange string, startDate, endDate string) (count int64, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT COUNT(DISTINCT classify_name, classify_type) FROM base_from_trade_` + exchange + `_index where (buy_short_name !="" or sold_short_name !="" ) and (buy_short_name !=" " or sold_short_name !=" " ) and data_time >= ? and data_time <= ?`
-	sql += " and `rank` <50 "
+	sql := "SELECT COUNT(DISTINCT classify_name, classify_type) FROM base_from_trade_" + exchange + "_index where `rank` <50 and (buy_short_name !='' or sold_short_name !='' ) and (buy_short_name !=' ' or sold_short_name !=' ' ) and data_time >= ? and data_time <= ?"
 	err = o.Raw(sql, startDate, endDate).QueryRow(&count)
 	return
 }
@@ -387,8 +382,7 @@ type TradePositionClassifyInfo struct {
 
 func GetTradePositionOriginClassifyByExchangeDataTime(exchange string, startDate, endDate string) (list []TradePositionClassifyInfo, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT DISTINCT classify_name, classify_type FROM base_from_trade_` + exchange + `_index where (buy_short_name !="" or sold_short_name !="" ) and (buy_short_name !=" " or sold_short_name !=" " ) and data_time >= ? and data_time <= ?`
-	sql += " and `rank` <50 "
+	sql := "SELECT DISTINCT classify_name, classify_type FROM base_from_trade_" + exchange + "_index where `rank` <50 and (buy_short_name !='' or sold_short_name !='' ) and (buy_short_name !=' ' or sold_short_name !=' ' ) and data_time >= ? and data_time <= ?"
 	_, err = o.Raw(sql, startDate, endDate).QueryRows(&list)
 	return
 }