优化查询

dev
lisai17@sina.com 2021-09-27 10:50:12 +08:00
parent 6737d9f1c0
commit aba0ed298e
1 changed files with 26 additions and 47 deletions

View File

@ -2497,53 +2497,32 @@ public class OrderStatService {
log.error("参数错误"); log.error("参数错误");
return null; return null;
} }
sql = "SELECT\n" + sql = "select c.*\n" +
" c.*\n" + " from (\n" +
"FROM\n" + " select a.customer_id, u.name customer_name, a.total_price, a.total_weight, a.total_amount total_amount, r.surplus total_surplus\n" +
" (\n" + " from\n" +
" SELECT\n" + " (\n" +
" a.customer_id,\n" + " select ifnull(o.customer_id, - 1) customer_id, count(o.sn) cnt, o.state, o.create_time, p.total_amount total_amount, sum(o.total_price) total_price, sum(o.weight) total_weight\n" +
" u.name customer_name,\n" + " from order_temp o\n" +
" a.total_price,\n" + " left join (\n" +
" a.total_weight, \n" + " select d.customer_id, sum(d.amount) total_amount\n" +
" a.total_amount total_amount,\n" + " from prepay_detail d\n" +
" r.surplus total_surplus\n" + " where d.state = 2\n" +
" FROM\n" + " and d.customer_id = ?\n" +
" (\n" + " and d.verify_time >= ?\n" +
" SELECT\n" + " group by d.customer_id\n" +
" ifnull(o.customer_id, - 1) customer_id,\n" + " ) p on p.customer_id = o.customer_id\n" +
" count(o.sn) cnt,\n" + " where o.state = 5\n" +
" o.state,\n" + " and o.customer_id = ?\n" +
" o.create_time,\n" + " and o.create_time >= ?\n" +
" p.total_amount total_amount,\n" + " group by o.customer_id\n" +
" sum(o.total_price) total_price,\n" + " ) a\n" +
" sum(o.weight) total_weight\n" + " left join customer u on u.id = a.customer_id\n" +
" FROM\n" + " left join prepay_customer r on r.customer_id = a.customer_id\n" +
" order_temp o\n" + " ) c\n" +
" LEFT JOIN (\n" + " where c.`customer_name` is not null \n" +
" SELECT\n" + " and c.customer_id = ?";
" d.customer_id,\n" + rec = Db.findFirst(sql, customer_id, year + "-01-01", customer_id, year + "-01-01", customer_id);
" sum(d.amount) total_amount\n" +
" FROM\n" +
" prepay_detail d\n" +
" WHERE\n" +
" d.state = 2\n" +
" AND d.verify_time LIKE ?\n" +
" GROUP BY\n" +
" d.customer_id\n" +
" ) p ON p.customer_id = o.customer_id\n" +
" WHERE\n" +
" o.state = 5\n" +
" AND o.create_time LIKE ?\n" +
" GROUP BY\n" +
" o.customer_id\n" +
" ) a\n" +
" LEFT JOIN customer u ON u.id = a.customer_id\n" +
" LEFT JOIN prepay_customer r ON r.customer_id = a.customer_id\n" +
" ) c\n" +
"WHERE\n" +
" c.`customer_name` IS NOT NULL and c.customer_id = ?";
rec = Db.findFirst(sql, year + "%", year + "%", customer_id);
} else { // 零散配额 } else { // 零散配额
if (StrKit.isBlank(year) || customer_name == null) { if (StrKit.isBlank(year) || customer_name == null) {
log.error("参数错误"); log.error("参数错误");