优化查询
parent
6737d9f1c0
commit
aba0ed298e
|
|
@ -2497,53 +2497,32 @@ public class OrderStatService {
|
|||
log.error("参数错误");
|
||||
return null;
|
||||
}
|
||||
sql = "SELECT\n" +
|
||||
" c.*\n" +
|
||||
"FROM\n" +
|
||||
sql = "select c.*\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" +
|
||||
" from\n" +
|
||||
" (\n" +
|
||||
" SELECT\n" +
|
||||
" a.customer_id,\n" +
|
||||
" u.name customer_name,\n" +
|
||||
" a.total_price,\n" +
|
||||
" a.total_weight, \n" +
|
||||
" a.total_amount total_amount,\n" +
|
||||
" r.surplus total_surplus\n" +
|
||||
" FROM\n" +
|
||||
" (\n" +
|
||||
" SELECT\n" +
|
||||
" ifnull(o.customer_id, - 1) customer_id,\n" +
|
||||
" count(o.sn) cnt,\n" +
|
||||
" o.state,\n" +
|
||||
" o.create_time,\n" +
|
||||
" p.total_amount total_amount,\n" +
|
||||
" sum(o.total_price) total_price,\n" +
|
||||
" sum(o.weight) total_weight\n" +
|
||||
" FROM\n" +
|
||||
" order_temp o\n" +
|
||||
" LEFT JOIN (\n" +
|
||||
" SELECT\n" +
|
||||
" d.customer_id,\n" +
|
||||
" 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" +
|
||||
" 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" +
|
||||
" from order_temp o\n" +
|
||||
" left join (\n" +
|
||||
" select d.customer_id, sum(d.amount) total_amount\n" +
|
||||
" from prepay_detail d\n" +
|
||||
" where d.state = 2\n" +
|
||||
" and d.customer_id = ?\n" +
|
||||
" and d.verify_time >= ?\n" +
|
||||
" group by d.customer_id\n" +
|
||||
" ) p on p.customer_id = o.customer_id\n" +
|
||||
" where o.state = 5\n" +
|
||||
" and o.customer_id = ?\n" +
|
||||
" and o.create_time >= ?\n" +
|
||||
" group by 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" +
|
||||
" 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);
|
||||
" where c.`customer_name` is not null \n" +
|
||||
" and c.customer_id = ?";
|
||||
rec = Db.findFirst(sql, customer_id, year + "-01-01", customer_id, year + "-01-01", customer_id);
|
||||
} else { // 零散配额
|
||||
if (StrKit.isBlank(year) || customer_name == null) {
|
||||
log.error("参数错误");
|
||||
|
|
|
|||
Loading…
Reference in New Issue