|
@@ -182,6 +182,45 @@ func GetTradeDataByClassifyAndCompany(exchange, classifyName string, contracts,
|
|
|
if len(contracts) == 0 || len(companies) == 0 {
|
|
|
return
|
|
|
}
|
|
|
+ condBuy := fmt.Sprintf(`classify_name = ? AND classify_type IN (%s)`, utils.GetOrmInReplace(len(contracts)))
|
|
|
+ parsBuy := make([]interface{}, 0)
|
|
|
+ parsBuy = append(parsBuy, classifyName, contracts)
|
|
|
+
|
|
|
+ condSold := fmt.Sprintf(`classify_name = ? AND classify_type IN (%s)`, utils.GetOrmInReplace(len(contracts)))
|
|
|
+ parsSold := make([]interface{}, 0)
|
|
|
+ parsSold = append(parsSold, classifyName, contracts)
|
|
|
+
|
|
|
+ // 是否含有TOP20
|
|
|
+ var hasTop bool
|
|
|
+ var condCompanies []string
|
|
|
+ for _, v := range companies {
|
|
|
+ if v == TradeFuturesCompanyTop20 {
|
|
|
+ hasTop = true
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ condCompanies = append(condCompanies, v)
|
|
|
+ }
|
|
|
+ if !hasTop {
|
|
|
+ if len(condCompanies) == 0 {
|
|
|
+ err = fmt.Errorf("查询条件-期货公司异常")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ condBuy += fmt.Sprintf(` AND buy_short_name IN (%s)`, utils.GetOrmInReplace(len(condCompanies)))
|
|
|
+ parsBuy = append(parsBuy, condCompanies)
|
|
|
+ condSold += fmt.Sprintf(` AND sold_short_name IN (%s)`, utils.GetOrmInReplace(len(condCompanies)))
|
|
|
+ parsSold = append(parsSold, condCompanies)
|
|
|
+ } else {
|
|
|
+ if len(condCompanies) > 0 {
|
|
|
+ condBuy += fmt.Sprintf(` AND (rank = 999 OR buy_short_name IN (%s))`, utils.GetOrmInReplace(len(condCompanies)))
|
|
|
+ condSold += fmt.Sprintf(` AND (rank = 999 OR sold_short_name IN (%s))`, utils.GetOrmInReplace(len(condCompanies)))
|
|
|
+ parsBuy = append(parsBuy, condCompanies)
|
|
|
+ parsSold = append(parsSold, condCompanies)
|
|
|
+ } else {
|
|
|
+ condBuy += ` AND rank = 999`
|
|
|
+ condSold += ` AND rank = 999`
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
tableName := fmt.Sprintf("base_from_trade_%s_index", exchange)
|
|
|
sql := `SELECT
|
|
|
rank,
|
|
@@ -195,7 +234,7 @@ func GetTradeDataByClassifyAndCompany(exchange, classifyName string, contracts,
|
|
|
FROM
|
|
|
%s
|
|
|
WHERE
|
|
|
- classify_name = ? AND classify_type IN (%s) AND buy_short_name IN (%s)
|
|
|
+ %s
|
|
|
UNION ALL
|
|
|
(
|
|
|
SELECT
|
|
@@ -210,11 +249,11 @@ func GetTradeDataByClassifyAndCompany(exchange, classifyName string, contracts,
|
|
|
FROM
|
|
|
%s
|
|
|
WHERE
|
|
|
- classify_name = ? AND classify_type IN (%s) AND sold_short_name IN (%s)
|
|
|
+ %s
|
|
|
)`
|
|
|
- sql = fmt.Sprintf(sql, tableName, utils.GetOrmInReplace(len(contracts)), utils.GetOrmInReplace(len(companies)), tableName, utils.GetOrmInReplace(len(contracts)), utils.GetOrmInReplace(len(companies)))
|
|
|
+ sql = fmt.Sprintf(sql, tableName, condBuy, tableName, condSold)
|
|
|
o := orm.NewOrmUsingDB("data")
|
|
|
- _, err = o.Raw(sql, classifyName, contracts, companies, classifyName, contracts, companies).QueryRows(&items)
|
|
|
+ _, err = o.Raw(sql, parsBuy, parsSold).QueryRows(&items)
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -227,6 +266,45 @@ func GetTradeZhengzhouDataByClassifyAndCompany(exchange string, contracts, compa
|
|
|
if len(contracts) == 0 || len(companies) == 0 {
|
|
|
return
|
|
|
}
|
|
|
+ condBuy := fmt.Sprintf(`classify_name IN (%s)`, utils.GetOrmInReplace(len(contracts)))
|
|
|
+ parsBuy := make([]interface{}, 0)
|
|
|
+ parsBuy = append(parsBuy, contracts)
|
|
|
+
|
|
|
+ condSold := fmt.Sprintf(`classify_name IN (%s)`, utils.GetOrmInReplace(len(contracts)))
|
|
|
+ parsSold := make([]interface{}, 0)
|
|
|
+ parsSold = append(parsSold, contracts)
|
|
|
+
|
|
|
+ // 是否含有TOP20
|
|
|
+ var hasTop bool
|
|
|
+ var condCompanies []string
|
|
|
+ for _, v := range companies {
|
|
|
+ if v == TradeFuturesCompanyTop20 {
|
|
|
+ hasTop = true
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ condCompanies = append(condCompanies, v)
|
|
|
+ }
|
|
|
+ if !hasTop {
|
|
|
+ if len(condCompanies) == 0 {
|
|
|
+ err = fmt.Errorf("查询条件-期货公司异常")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ condBuy += fmt.Sprintf(` AND buy_short_name IN (%s)`, utils.GetOrmInReplace(len(condCompanies)))
|
|
|
+ parsBuy = append(parsBuy, condCompanies)
|
|
|
+ condSold += fmt.Sprintf(` AND sold_short_name IN (%s)`, utils.GetOrmInReplace(len(condCompanies)))
|
|
|
+ parsSold = append(parsSold, condCompanies)
|
|
|
+ } else {
|
|
|
+ if len(condCompanies) > 0 {
|
|
|
+ condBuy += fmt.Sprintf(` AND (rank = 999 OR buy_short_name IN (%s))`, utils.GetOrmInReplace(len(condCompanies)))
|
|
|
+ condSold += fmt.Sprintf(` AND (rank = 999 OR sold_short_name IN (%s))`, utils.GetOrmInReplace(len(condCompanies)))
|
|
|
+ parsBuy = append(parsBuy, condCompanies)
|
|
|
+ parsSold = append(parsSold, condCompanies)
|
|
|
+ } else {
|
|
|
+ condBuy += ` AND rank = 999`
|
|
|
+ condSold += ` AND rank = 999`
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
tableName := fmt.Sprintf("base_from_trade_%s_index", exchange)
|
|
|
sql := `SELECT
|
|
|
rank,
|
|
@@ -239,7 +317,7 @@ func GetTradeZhengzhouDataByClassifyAndCompany(exchange string, contracts, compa
|
|
|
FROM
|
|
|
%s
|
|
|
WHERE
|
|
|
- classify_name IN (%s) AND buy_short_name IN (%s)
|
|
|
+ %s
|
|
|
UNION ALL
|
|
|
(
|
|
|
SELECT
|
|
@@ -253,11 +331,11 @@ func GetTradeZhengzhouDataByClassifyAndCompany(exchange string, contracts, compa
|
|
|
FROM
|
|
|
%s
|
|
|
WHERE
|
|
|
- classify_name IN (%s) AND sold_short_name IN (%s)
|
|
|
+ %s
|
|
|
)`
|
|
|
- sql = fmt.Sprintf(sql, tableName, utils.GetOrmInReplace(len(contracts)), utils.GetOrmInReplace(len(companies)), tableName, utils.GetOrmInReplace(len(contracts)), utils.GetOrmInReplace(len(companies)))
|
|
|
+ sql = fmt.Sprintf(sql, tableName, condBuy, tableName, condSold)
|
|
|
o := orm.NewOrmUsingDB("data")
|
|
|
- _, err = o.Raw(sql, contracts, companies, contracts, companies).QueryRows(&items)
|
|
|
+ _, err = o.Raw(sql, parsBuy, parsSold).QueryRows(&items)
|
|
|
return
|
|
|
}
|
|
|
|