Commit fb226201 by 泽锋 李

优化count 查询

parent ced1d713
......@@ -53,7 +53,7 @@ left join dc_base_warehouse as dbw on dacp.warehouse_code = dbw.warehouse_code w
sql += " and dacp.warehouse_code='" + m.warehousecode + "'";
}
total = _connection.ExecuteScalar<int>("select count(0) from (" + sql + ") tb1");
total = _connection.QuerySingleOrDefault<int>("select count(0) from (" + sql + ") tb1");
var obj = _connection.Query<dc_auto_config_safe_inventoryDto>(sql + " limit " + offset + "," + limit);
......@@ -179,7 +179,7 @@ left join dc_base_warehouse as dbw on dacp.warehouse_code = dbw.warehouse_code w
sql += " and dacp.warehouse_code='" + m.warehousecode + "'";
}
total = _connection.ExecuteScalar<int>("select count(0) from (" + sql + ") tb1");
total = _connection.QuerySingleOrDefault<int>("select count(0) from (" + sql + ") tb1");
var obj = _connection.Query<dc_auto_config_sales_upper_limitDto>(sql + " limit " + offset + "," + limit);
......@@ -306,7 +306,7 @@ where 1 = 1 ";
sql += " and ( dbw.warehouse_code='" + m.warehousecode + "' or ( dacp.type=3 and dacp.variable_code='" + m.warehousecode + "' ) ) ";
}
total = _connection.ExecuteScalar<int>("select count(0) from (" + sql + ") tb1");
total = _connection.QuerySingleOrDefault<int>("select count(0) from (" + sql + ") tb1");
var obj = _connection.Query<dc_auto_config_delivery_dto>(sql + " limit " + offset + "," + limit);
......@@ -422,7 +422,7 @@ left join dc_base_warehouse as dbw on dacp.warehouse_code = dbw.warehouse_code w
sql += " and dacp.warehouse_code='" + m.warehousecode + "'";
}
total = _connection.ExecuteScalar<int>("select count(0) from (" + sql + ") tb1");
total = _connection.QuerySingleOrDefault<int>("select count(0) from (" + sql + ") tb1");
var obj = _connection.Query<dc_auto_config_stock_up_days>(sql + " limit " + offset + "," + limit);
......@@ -861,7 +861,7 @@ left join dc_base_warehouse as dbw on dacp.warehouse_code = dbw.warehouse_code w
sql += " and dacp.warehouse_code='" + m.warehousecode + "'";
}
total = _connection.ExecuteScalar<int>("select count(0) from (" + sql + ") tb1");
total = _connection.QuerySingleOrDefault<int>("select count(0) from (" + sql + ") tb1");
var obj = _connection.Query<dc_base_stock_config_fba>(sql + " limit " + offset + "," + limit);
......@@ -893,7 +893,7 @@ left join dc_base_warehouse as dbw on dacp.warehouse_code = dbw.warehouse_code w
{
sql += " and dacp.platform_sku like '%" + m.platform_sku + "%'";
}
total = _connection.ExecuteScalar<int>("select count(0) from (" + sql + ") tb1");
total = _connection.QuerySingleOrDefault<int>("select count(0) from (" + sql + ") tb1");
var obj = _connection.Query<dc_base_stock_config_fba_lose>(sql + " limit " + offset + "," + limit);
......@@ -1022,7 +1022,7 @@ left join dc_base_warehouse as dbw on dacp.warehouse_code = dbw.warehouse_code w
sql += " and t1.end_date>=" + $"'{m.end_date.Value}'";
}
total = _connection.ExecuteScalar<int>("select count(0) from (" + sql + ") tb1");
total = _connection.QuerySingleOrDefault<int>("select count(0) from (" + sql + ") tb1");
var obj = _connection.Query<dc_auto_sales_config>(sql + " limit " + offset + "," + limit);
......@@ -1151,7 +1151,7 @@ where 1 = 1 ";
sql += " and dacp.warehouse_code='" + m.warehousecode + "'";
}
total = _connection.ExecuteScalar<int>("select count(0) from (" + sql + ") tb1");
total = _connection.QuerySingleOrDefault<int>("select count(0) from (" + sql + ") tb1");
var obj = _connection.Query<dc_auto_stock_up_range_dto>(sql + " limit " + offset + "," + limit);
......@@ -1247,7 +1247,7 @@ where 1 = 1 ";
total = _connection.ExecuteScalar<int>("select count(0) from (" + sql + ") tb1");
total = _connection.QuerySingleOrDefault<int>("select count(0) from (" + sql + ") tb1");
var obj = _connection.Query<dc_auto_jit_tag_group>(sql + " limit " + offset + "," + limit);
......@@ -1389,7 +1389,7 @@ where 1 = 1 ";
sql += " and dacp.warehouse_code='" + m.warehousecode + "'";
}
total = _connection.ExecuteScalar<int>("select count(0) from (" + sql + ") tb1");
total = _connection.QuerySingleOrDefault<int>("select count(0) from (" + sql + ") tb1");
var obj = _connection.Query<dc_config_forecast_sales>(sql + " limit " + offset + "," + limit);
......@@ -1490,7 +1490,7 @@ and start_date<=@end_date and end_date>=@start_date
}
}
total = _connection.ExecuteScalar<int>("select count(0) from (" + sql + ") tb1");
total = _connection.QuerySingleOrDefault<int>("select count(0) from (" + sql + ") tb1");
var obj = _connection.Query<dc_auto_uprush_config_dto>(sql + " limit " + offset + "," + limit);
......@@ -1711,7 +1711,7 @@ and start_date<=@end_date and end_date>=@start_date
}
total = _connection.ExecuteScalar<int>("select count(0) from (" + sql + ") tb1");
total = _connection.QuerySingleOrDefault<int>("select count(0) from (" + sql + ") tb1");
var obj = _connection.Query<dc_report_cash_flow_config_dto>(sql + " limit " + offset + "," + limit);
......@@ -1775,7 +1775,7 @@ and start_date<=@end_date and end_date>=@start_date
}
total = _connection.ExecuteScalar<int>("select count(0) from (" + sql + ") tb1");
total = _connection.QuerySingleOrDefault<int>("select count(0) from (" + sql + ") tb1");
var obj = _connection.Query<dc_report_logistics_company_config_dto>(sql + " limit " + offset + "," + limit);
......@@ -1877,7 +1877,7 @@ where 1 = 1 ";
sql += " and t1.status=" + m.status;
}
total = _connection.ExecuteScalar<int>("select count(0) from (" + sql + ") tb1", parameters);
total = _connection.QuerySingleOrDefault<int>("select count(0) from (" + sql + ") tb1", parameters);
var obj = _connection.Query<dc_auto_return_goods_config_dto>(sql + " limit " + offset + "," + limit, parameters);
......
......@@ -129,7 +129,7 @@ where 1 = 1
if (limit < 10000)
{
total = _connection.ExecuteScalar<int>("select count(0) from (" + sql + ") tb1", parameters, commandTimeout: 0);
total = _connection.QuerySingleOrDefault<int>("select count(0) from (" + sql + ") tb1", parameters, commandTimeout: 0);
}
else
{
......
......@@ -35,7 +35,7 @@ where 1 = 1 ";
}
sql += " order by t1.level asc ";
total = _connection.ExecuteScalar<int>("select count(0) from (" + sql + ") tb1");
total = _connection.QuerySingleOrDefault<int>("select count(0) from (" + sql + ") tb1");
var obj = _connection.Query<dc_auto_jit_tag_dto>(sql + " limit " + offset + "," + limit);
......@@ -80,7 +80,7 @@ where 1 = 1 ";
}
sql += " order by t1.date desc ";
total = _connection.ExecuteScalar<int>("select count(0) from (" + sql + ") tb1", parameters);
total = _connection.QuerySingleOrDefault<int>("select count(0) from (" + sql + ") tb1", parameters);
var obj = _connection.Query<dc_auto_jit_tag_log_dto>(sql + " limit " + offset + "," + limit, parameters);
......
......@@ -156,7 +156,7 @@ where 1 = 1 ";
}
total = _connection.ExecuteScalar<int>("select count(0) from (" + sql + ") tb1", parameters);
total = _connection.QuerySingleOrDefault<int>("select count(0) from (" + sql + ") tb1", parameters);
var obj = _connection.Query<dc_auto_pick_up_goods_order_view_dto>(sql + " limit " + offset + "," + limit, parameters);
......
......@@ -239,7 +239,7 @@ where 1 = 1 ";
sql += " and t1.no_library_sys_push_status=" + m.no_library_sys_push_status;
}
total = _connection.ExecuteScalar<int>("select count(0) from (" + sql + ") tb1", parameters);
total = _connection.QuerySingleOrDefault<int>("select count(0) from (" + sql + ") tb1", parameters);
var obj = _connection.Query<dc_auto_return_goods_sku_dto>(sql + " limit " + offset + "," + limit, parameters);
......
......@@ -271,7 +271,7 @@ from dc_auto_turnover as dat
}
else
{
total = _connection.ExecuteScalar<int>(sqlCount, parameters, commandTimeout: 0);
total = _connection.QuerySingleOrDefault<int>(sqlCount, parameters, commandTimeout: 0);
//Console.WriteLine(sqlCount);
//设置默认排序字段
if (string.IsNullOrWhiteSpace(sort)) sort = "dat.id";
......@@ -359,7 +359,7 @@ from dc_auto_turnover as dat
sql += " dacp.and status=" + m.status.Value;
}
total = _connection.ExecuteScalar<int>("select count(0) from (" + sql + ") tb1");
total = _connection.QuerySingleOrDefault<int>("select count(0) from (" + sql + ") tb1");
var obj = _connection.Query<dc_auto_config_promotion>(sql + " limit " + offset + "," + limit);
......@@ -624,7 +624,7 @@ from dc_auto_turnover as dat
sql += " and dacp.warehouse_code='" + m.warehousecode + "'";
}
total = _connection.ExecuteScalar<int>("select count(0) from (" + sql + ") tb1");
total = _connection.QuerySingleOrDefault<int>("select count(0) from (" + sql + ") tb1");
var obj = _connection.Query<dc_auto_config_correction>(sql + " limit " + offset + "," + limit);
......
......@@ -147,7 +147,7 @@ where 1=1
}
else
{
total = _connection.ExecuteScalar<int>(sqlCount, parameters);
total = _connection.QuerySingleOrDefault<int>(sqlCount, parameters);
//设置默认排序字段
if (string.IsNullOrWhiteSpace(sort)) sort = "t_not_stock.id";
......
......@@ -973,7 +973,7 @@ and platform_type in @platform_types
sql += " order by id desc ";
total = _connection.ExecuteScalar<int>("select count(0) from (" + sql + ") tb1", parameters);
total = _connection.QuerySingleOrDefault<int>("select count(0) from (" + sql + ") tb1", parameters);
var obj = _connection.Query<dc_auto_purchase_advise>(sql + " limit " + offset + "," + limit, parameters);
......@@ -1166,7 +1166,7 @@ and EXISTS (
}
else
{
total = _connection.ExecuteScalar<int>("select count(0) from (" + sql + ") tb1", parameters);
total = _connection.QuerySingleOrDefault<int>("select count(0) from (" + sql + ") tb1", parameters);
//设置默认排序字段
if (string.IsNullOrWhiteSpace(sort)) sort = "t1.quantity_final_advise";
......
......@@ -96,7 +96,7 @@ where t1.quantity_out_stock>0 and ( t3.buyer_name in ('张莹霞','张莹霞1','
}
else
{
total = _connection.ExecuteScalar<int>("select count(0) from (" + sql + ") tb1", parameters);
total = _connection.QuerySingleOrDefault<int>("select count(0) from (" + sql + ") tb1", parameters);
//设置默认排序字段
if (string.IsNullOrWhiteSpace(sort)) sort = "t1.quantity_out_stock";
......@@ -296,7 +296,7 @@ where 1=1
}
else
{
total = _connection.ExecuteScalar<int>(countSql, parameters, commandTimeout: 0);
total = _connection.QuerySingleOrDefault<int>(countSql, parameters, commandTimeout: 0);
//设置默认排序字段
if (!string.IsNullOrEmpty(sort) && !string.IsNullOrEmpty(order))
......@@ -424,7 +424,7 @@ where ( t_db.hq_type!='国内仓' or t2.buyer_name not in ('张莹霞','张莹
}
else
{
total = _connection.ExecuteScalar<int>(countSql, parameters, commandTimeout: 0);
total = _connection.QuerySingleOrDefault<int>(countSql, parameters, commandTimeout: 0);
//设置默认排序字段
if (!string.IsNullOrEmpty(sort) && !string.IsNullOrEmpty(order))
......@@ -994,7 +994,7 @@ end
}
else
{
total = _connection.ExecuteScalar<int>(countSql, parameters, commandTimeout: 0);
total = _connection.QuerySingleOrDefault<int>(countSql, parameters, commandTimeout: 0);
//设置默认排序字段
if (!string.IsNullOrEmpty(sort) && !string.IsNullOrEmpty(order))
......@@ -2846,7 +2846,7 @@ where t2.buyer_name = '赵美聪'
{
sql += " GROUP BY t2.suppliers_id ";
count_sql += " GROUP BY t2.suppliers_id ";
total = _connection.ExecuteScalar<int>(count_sql, parameters);
total = _connection.QuerySingleOrDefault<int>(count_sql, parameters);
//设置默认排序字段
if (string.IsNullOrWhiteSpace(sort)) sort = "yesterday_sales_count";
......
......@@ -592,7 +592,7 @@ namespace AutoTurnOver.DB
}
total = _connection.ExecuteScalar<int>("select count(0) from (" + sql + ") tb1");
total = _connection.QuerySingleOrDefault<int>("select count(0) from (" + sql + ") tb1");
var obj = _connection.Query<dc_report_cash_flow_forecast_task_dto>(sql + " limit " + offset + "," + limit);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment