大屏代码

master
lzq 2025-08-27 17:43:28 +08:00
parent 25d7b61330
commit 3344a271f4
2 changed files with 59 additions and 71 deletions

View File

@ -23,7 +23,8 @@ import java.util.stream.Collectors;
public class StatisticsService { public class StatisticsService {
private final StatisticsMapper statisticsMapper; private final StatisticsMapper statisticsMapper;
private final String[] weeks = {"周日", "周一", "周二", "周三", "周四", "周五", "周六"}; private final String[] weeks = {"周一", "周二", "周三", "周四", "周五", "周六", "周日"};
private final String[] weeks_ = {"周日", "周一", "周二", "周三", "周四", "周五", "周六"};
private final String[] months = {"1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"}; private final String[] months = {"1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"};
public Map<String, Object> obtainData() throws Exception { public Map<String, Object> obtainData() throws Exception {
@ -167,19 +168,22 @@ public class StatisticsService {
Map<String, List<OrderAmountSummary>> week_temp_1 = GroupUtil.k_a(week_orderAmountSummary.stream().filter(it -> it.getCd() == 1), it -> { Map<String, List<OrderAmountSummary>> week_temp_1 = GroupUtil.k_a(week_orderAmountSummary.stream().filter(it -> it.getCd() == 1), it -> {
Date outTime = it.getOutTime(); Date outTime = it.getOutTime();
Week week = DateUtil.dayOfWeekEnum(outTime); Week week = DateUtil.dayOfWeekEnum(outTime);
return weeks[week.getValue() - 1]; return weeks_[week.getValue() - 1];
}); });
Map<String, List<OrderAmountSummary>> week_temp_2 = GroupUtil.k_a(week_orderAmountSummary.stream().filter(it -> it.getCd() == 2), it -> { Map<String, List<OrderAmountSummary>> week_temp_2 = GroupUtil.k_a(week_orderAmountSummary.stream().filter(it -> it.getCd() == 2), it -> {
Date outTime = it.getOutTime(); Date outTime = it.getOutTime();
Week week = DateUtil.dayOfWeekEnum(outTime); Week week = DateUtil.dayOfWeekEnum(outTime);
return weeks[week.getValue() - 1]; return weeks_[week.getValue() - 1];
}); });
List<Double> weekAmountIn = new ArrayList<>(weeks.length); List<Double> weekAmountIn = new ArrayList<>(weeks.length);
for (String week : weeks) { for (String week : weeks) {
List<OrderAmountSummary> orderAmountSummary = week_temp_1.getOrDefault(week, Collections.emptyList()); List<OrderAmountSummary> orderAmountSummary = week_temp_1.getOrDefault(week, Collections.emptyList());
Double amount = orderAmountSummary.stream().map(OrderAmountSummary::getAmount).reduce(Integer::sum).orElse(0) / 100.0; Double amount = orderAmountSummary.stream().map(OrderAmountSummary::getAmount).reduce(Integer::sum).orElse(0) / 100.0;
weekAmountIn.add(amount); weekAmountIn.add(amount);
} }
List<Double> weekAmountOut = new ArrayList<>(weeks.length); List<Double> weekAmountOut = new ArrayList<>(weeks.length);
for (String week : weeks) { for (String week : weeks) {
List<OrderAmountSummary> orderAmountSummary = week_temp_2.getOrDefault(week, Collections.emptyList()); List<OrderAmountSummary> orderAmountSummary = week_temp_2.getOrDefault(week, Collections.emptyList());
@ -191,7 +195,7 @@ public class StatisticsService {
log.error("订单动态数据获取失败", ex); log.error("订单动态数据获取失败", ex);
return Tuple2.create(Collections.emptyList(), Collections.emptyList()); return Tuple2.create(Collections.emptyList(), Collections.emptyList());
}); });
CompletableFuture<Tuple3<List<Double>, List<Double>,List<String>>> monthAmount = CompletableFuture.supplyAsync(() -> { CompletableFuture<Tuple3<List<Double>, List<Double>, List<String>>> monthAmount = CompletableFuture.supplyAsync(() -> {
long month_start = DateUtil.beginOfMonth(date).getTime() / 1000; long month_start = DateUtil.beginOfMonth(date).getTime() / 1000;
long month_end = DateUtil.endOfMonth(date).getTime() / 1000; long month_end = DateUtil.endOfMonth(date).getTime() / 1000;
List<OrderAmountSummary> month_orderAmountSummary = statisticsMapper.getOrderAmountSummary(month_start, month_end); List<OrderAmountSummary> month_orderAmountSummary = statisticsMapper.getOrderAmountSummary(month_start, month_end);
@ -225,12 +229,12 @@ public class StatisticsService {
Double amount = orderAmountSummary.stream().map(OrderAmountSummary::getAmount).reduce(Integer::sum).orElse(0) / 100.0; Double amount = orderAmountSummary.stream().map(OrderAmountSummary::getAmount).reduce(Integer::sum).orElse(0) / 100.0;
monthAmountOut.add(amount); monthAmountOut.add(amount);
} }
return Tuple3.create(monthAmountIn, monthAmountOut,days); return Tuple3.create(monthAmountIn, monthAmountOut, days);
}).exceptionally(ex -> { }).exceptionally(ex -> {
log.error("订单动态数据获取失败", ex); log.error("订单动态数据获取失败", ex);
return Tuple3.create(Collections.emptyList(), Collections.emptyList(),Collections.emptyList()); return Tuple3.create(Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
}); });
CompletableFuture<Tuple2<List<Double>, List<Double>>> yearAmount = CompletableFuture.supplyAsync(() ->{ CompletableFuture<Tuple2<List<Double>, List<Double>>> yearAmount = CompletableFuture.supplyAsync(() -> {
long year_start = DateUtil.beginOfYear(date).getTime() / 1000; long year_start = DateUtil.beginOfYear(date).getTime() / 1000;
long year_end = DateUtil.endOfYear(date).getTime() / 1000; long year_end = DateUtil.endOfYear(date).getTime() / 1000;
List<OrderAmountSummary> year_orderAmountSummary = statisticsMapper.getOrderAmountSummary(year_start, year_end); List<OrderAmountSummary> year_orderAmountSummary = statisticsMapper.getOrderAmountSummary(year_start, year_end);
@ -271,7 +275,7 @@ public class StatisticsService {
}); });
Tuple2<List<Double>, List<Double>> weekAmount_ = weekAmount.get(); Tuple2<List<Double>, List<Double>> weekAmount_ = weekAmount.get();
Tuple3<List<Double>, List<Double>,List<String>> monthAmount_ = monthAmount.get(); Tuple3<List<Double>, List<Double>, List<String>> monthAmount_ = monthAmount.get();
Tuple2<List<Double>, List<Double>> yearAmount_ = yearAmount.get(); Tuple2<List<Double>, List<Double>> yearAmount_ = yearAmount.get();
return MapUtil.<String, Object>builder() return MapUtil.<String, Object>builder()
.put("carTrends", carTrends.get()) .put("carTrends", carTrends.get())

View File

@ -6,25 +6,27 @@
<select id="getCarTrends" resultType="com.njzscloud.supervisory.statistics.pojo.CarTrends"> <select id="getCarTrends" resultType="com.njzscloud.supervisory.statistics.pojo.CarTrends">
SELECT a.car_number, a.weight, a.order_status, a.station_id, b.name station_name SELECT a.car_number, a.weight, a.order_status, a.station_id, b.name station_name
FROM (SELECT car_number, weight, order_status, station_id FROM (SELECT car_number, weight, order_status, station_id
FROM (SELECT car_number, FROM (SELECT a.car_number,
weight, a.weight,
IF(status = 1, '已完成', IF(status = 4, '已取消', IF(car_status = 0, '已预约', IF(car_status = 1 AND admin_status = 0, '待看料', '待出场')))) order_status, IF(a.status = 1, '已完成', IF(a.status = 4, '已取消', IF(a.car_status = 0, '已预约', IF(a.car_status = 1 AND a.admin_status = 0, '待看料', '待出场')))) order_status,
station_id a.station_id
FROM ba_order FROM ba_order a
WHERE station_id = 1 INNER JOIN ba_goods b ON b.id = a.goods_id AND b.id NOT IN (287, 286, 279, 278, 293, 273, 271, 270, 262, 2)
AND status IN (0, 1, 2, 3) WHERE a.station_id = 1
ORDER BY create_time DESC AND a.status IN (0, 1, 2, 3)
ORDER BY a.create_time DESC
LIMIT 5) t1 LIMIT 5) t1
UNION ALL UNION ALL
SELECT car_number, weight, order_status, station_id SELECT car_number, weight, order_status, station_id
FROM (SELECT car_number, FROM (SELECT a.car_number,
weight, a.weight,
IF(status = 1, '已完成', IF(status = 4, '已取消', IF(car_status = 0, '已预约', IF(car_status = 1 AND admin_status = 0, '待看料', '待出场')))) order_status, IF(a.status = 1, '已完成', IF(a.status = 4, '已取消', IF(a.car_status = 0, '已预约', IF(a.car_status = 1 AND a.admin_status = 0, '待看料', '待出场')))) order_status,
station_id a.station_id
FROM ba_order FROM ba_order a
WHERE station_id = 2 INNER JOIN ba_goods b ON b.id = a.goods_id AND b.id NOT IN (287, 286, 279, 278, 293, 273, 271, 270, 262, 2)
AND status IN (0, 1, 2, 3) WHERE a.station_id = 2
ORDER BY create_time DESC AND a.status IN (0, 1, 2, 3)
ORDER BY a.create_time DESC
LIMIT 5) t2) a LIMIT 5) t2) a
INNER JOIN ba_station b ON b.id = a.station_id INNER JOIN ba_station b ON b.id = a.station_id
</select> </select>
@ -43,7 +45,7 @@
FROM (SELECT garbage_name, weight FROM (SELECT garbage_name, weight
FROM (SELECT b.name garbage_name, SUM(a.weight) weight FROM (SELECT b.name garbage_name, SUM(a.weight) weight
FROM ba_order a FROM ba_order a
INNER JOIN ba_goods b ON b.id = a.goods_id AND b.depot_type = 1 INNER JOIN ba_goods b ON b.id = a.goods_id AND b.depot_type = 1 AND b.id NOT IN (287, 286, 279, 278, 293, 273, 271, 270, 262, 2)
INNER JOIN ba_goods_category c ON c.id = b.category_id INNER JOIN ba_goods_category c ON c.id = b.category_id
WHERE b.name NOT LIKE '%青石%' WHERE b.name NOT LIKE '%青石%'
AND b.name NOT LIKE '%拆除垃圾(派车清运零星客户专用)%' AND b.name NOT LIKE '%拆除垃圾(派车清运零星客户专用)%'
@ -57,7 +59,7 @@
FROM (SELECT garbage_name, weight FROM (SELECT garbage_name, weight
FROM (SELECT b.name garbage_name, SUM(a.weight) weight FROM (SELECT b.name garbage_name, SUM(a.weight) weight
FROM ba_order a FROM ba_order a
INNER JOIN ba_goods b ON b.id = a.goods_id AND b.depot_type = 2 INNER JOIN ba_goods b ON b.id = a.goods_id AND b.depot_type = 2 AND b.id NOT IN (287, 286, 279, 278, 293, 273, 271, 270, 262, 2)
INNER JOIN ba_goods_category c ON c.id = b.category_id INNER JOIN ba_goods_category c ON c.id = b.category_id
WHERE b.name NOT LIKE '%青石%' WHERE b.name NOT LIKE '%青石%'
AND b.name NOT LIKE '%矿石%' AND b.name NOT LIKE '%矿石%'
@ -66,36 +68,13 @@
ORDER BY weight DESC ORDER BY weight DESC
LIMIT 3) t2 LIMIT 3) t2
</select> </select>
<!-- <select id="getGarbageDisposeSummary"
resultType="com.njzscloud.supervisory.statistics.pojo.GarbageDisposeSummary">
SELECT garbage_name, weight, 1 depot_type, '入库' depot_name
FROM (SELECT garbage_name, weight
FROM (SELECT c.name garbage_name, SUM(a.weight) weight
FROM ba_order a
INNER JOIN ba_goods b ON b.id = a.goods_id AND b.depot_type = 1
INNER JOIN ba_goods_category c ON c.id = b.category_id
WHERE c.name NOT LIKE '%青石%'
GROUP BY c.name) t
ORDER BY weight DESC
LIMIT 3) t1
UNION ALL
SELECT garbage_name, weight, 2 depot_type, '出库' depot_name
FROM (SELECT garbage_name, weight
FROM (SELECT c.name garbage_name, SUM(a.weight) weight
FROM ba_order a
INNER JOIN ba_goods b ON b.id = a.goods_id AND b.depot_type = 2
INNER JOIN ba_goods_category c ON c.id = b.category_id
WHERE c.name NOT LIKE '%青石%'
GROUP BY c.name) t
ORDER BY weight DESC
LIMIT 3) t2
</select> -->
<select id="getCurrentMonthGarbageDisposeSummary" <select id="getCurrentMonthGarbageDisposeSummary"
resultType="com.njzscloud.supervisory.statistics.pojo.GarbageDisposeSummary"> resultType="com.njzscloud.supervisory.statistics.pojo.GarbageDisposeSummary">
SELECT goods_name garbage_name, weight SELECT goods_name garbage_name, weight
FROM (SELECT a.goods_name, SUM(a.weight) weight FROM (SELECT a.goods_name, SUM(a.weight) weight
FROM ba_order a FROM ba_order a
INNER JOIN ba_goods b ON b.id = a.goods_id AND b.depot_type = 2 INNER JOIN ba_goods b ON b.id = a.goods_id AND b.depot_type = 2 AND b.id NOT IN (287, 286, 279, 278, 293, 273, 271, 270, 262, 2)
WHERE out_time >= UNIX_TIMESTAMP(DATE_FORMAT(CURDATE(), '%Y-%m-01 00:00:00')) WHERE out_time >= UNIX_TIMESTAMP(DATE_FORMAT(CURDATE(), '%Y-%m-01 00:00:00'))
AND out_time <![CDATA[ < ]]> UNIX_TIMESTAMP(DATE_ADD(DATE_FORMAT(CURDATE(), '%Y-%m-01'), INTERVAL 1 MONTH)) AND out_time <![CDATA[ < ]]> UNIX_TIMESTAMP(DATE_ADD(DATE_FORMAT(CURDATE(), '%Y-%m-01'), INTERVAL 1 MONTH))
GROUP BY a.goods_name) t GROUP BY a.goods_name) t
@ -110,6 +89,7 @@
COUNT(*) AS c COUNT(*) AS c
FROM ba_order a FROM ba_order a
INNER JOIN ba_user b ON b.id = a.vip_user AND b.group_id = 2 INNER JOIN ba_user b ON b.id = a.vip_user AND b.group_id = 2
INNER JOIN ba_goods c ON c.id = a.goods_id AND c.id NOT IN (287, 286, 279, 278, 293, 273, 271, 270, 262, 2)
WHERE a.status IN (0, 1, 2, 3) WHERE a.status IN (0, 1, 2, 3)
GROUP BY b.id, IF(a.status = 1, 1, 0)) t1 GROUP BY b.id, IF(a.status = 1, 1, 0)) t1
INNER JOIN ba_user t2 ON t2.id = t1.id INNER JOIN ba_user t2 ON t2.id = t1.id
@ -123,29 +103,31 @@
COUNT(*) AS c COUNT(*) AS c
FROM ba_order a FROM ba_order a
INNER JOIN ba_user b ON b.id IN (230, 343, 435) INNER JOIN ba_user b ON b.id IN (230, 343, 435)
INNER JOIN ba_goods c ON c.id = a.goods_id AND c.id NOT IN (287, 286, 279, 278, 293, 273, 271, 270, 262, 2)
WHERE a.status IN (0, 1, 2, 3) WHERE a.status IN (0, 1, 2, 3)
GROUP BY b.id, IF(a.status = 1, 1, 0)) t1 GROUP BY b.id, IF(a.status = 1, 1, 0)) t1
INNER JOIN ba_user t2 ON t2.id = t1.id INNER JOIN ba_user t2 ON t2.id = t1.id
ORDER BY c DESC)tt2 ORDER BY c DESC)tt2
</select> </select>
<select id="obtainOrder" resultType="com.njzscloud.supervisory.statistics.pojo.OrderInfo"> <select id="obtainOrder" resultType="com.njzscloud.supervisory.statistics.pojo.OrderInfo">
SELECT car_number, SELECT a.car_number,
goods_name, a.goods_name,
IF(status = 1, '已完成', IF(status = 4, '已取消', IF(car_status = 0, '已预约', IF(car_status = 1 AND admin_status = 0, '待看料', '待出场')))) order_status, IF(a.status = 1, '已完成', IF(a.status = 4, '已取消', IF(a.car_status = 0, '已预约', IF(a.car_status = 1 AND a.admin_status = 0, '待看料', '待出场')))) order_status,
weight, a.weight,
IF(in_time = 0, NULL, FROM_UNIXTIME(in_time)) in_time, IF(a.in_time = 0, NULL, FROM_UNIXTIME(a.in_time)) in_time,
IF(out_time = 0, NULL, FROM_UNIXTIME(out_time)) out_time IF(a.out_time = 0, NULL, FROM_UNIXTIME(a.out_time)) out_time
FROM ba_order FROM ba_order a
WHERE vip_user = #{userId} INNER JOIN ba_goods b ON b.id = a.goods_id AND b.id NOT IN (287, 286, 279, 278, 293, 273, 271, 270, 262, 2)
ORDER BY create_time DESC WHERE a.vip_user = #{userId}
ORDER BY a.create_time DESC
LIMIT 10 LIMIT 10
</select> </select>
<select id="disposeWeight" resultType="java.lang.Double"> <select id="disposeWeight" resultType="java.lang.Double">
SELECT SUM(a.weight) weight SELECT SUM(a.weight) weight
FROM ba_order a FROM ba_order a
INNER JOIN ba_goods b ON b.id = a.goods_id AND b.depot_type = 1 AND b.id NOT IN (287,286,279,278,293,273,271,270,262,2) INNER JOIN ba_goods b ON b.id = a.goods_id AND b.depot_type = 1 AND b.id NOT IN (287,286,279,278,293,273,271,270,262,2)
WHERE out_time >= #{startTime} WHERE a.out_time >= #{startTime}
AND out_time <![CDATA[ <= ]]> #{endTime} AND a.out_time <![CDATA[ <= ]]> #{endTime}
</select> </select>
<select id="getTodayOrderSummary" resultType="com.njzscloud.supervisory.statistics.pojo.TodayOrderSummary"> <select id="getTodayOrderSummary" resultType="com.njzscloud.supervisory.statistics.pojo.TodayOrderSummary">
SELECT MAX(IF(order_status = '已完成', order_count, 0)) completed, SELECT MAX(IF(order_status = '已完成', order_count, 0)) completed,
@ -153,18 +135,20 @@
MAX(IF(order_status = '已预约', order_count, 0)) waiting, MAX(IF(order_status = '已预约', order_count, 0)) waiting,
MAX(IF(order_status = '已完成', order_count, 0)) + MAX(IF(order_status = '已取消', order_count, 0)) + MAX(IF(order_status = '已预约', order_count, 0)) total MAX(IF(order_status = '已完成', order_count, 0)) + MAX(IF(order_status = '已取消', order_count, 0)) + MAX(IF(order_status = '已预约', order_count, 0)) total
FROM (SELECT order_status, COUNT(*) order_count FROM (SELECT order_status, COUNT(*) order_count
FROM (SELECT IF(status = 1, '已完成', IF(status = 4, '已取消', IF(car_status = 0, '已预约', IF(car_status = 1 AND admin_status = 0, '待看料', '待出场'))))order_status FROM (SELECT IF(a.status = 1, '已完成', IF(a.status = 4, '已取消', IF(a.car_status = 0, '已预约', IF(a.car_status = 1 AND a.admin_status = 0, '待看料', '待出场')))) order_status
FROM ba_order FROM ba_order a
WHERE create_time >= UNIX_TIMESTAMP(CURDATE()) INNER JOIN ba_goods b ON b.id = a.goods_id AND b.id NOT IN (287, 286, 279, 278, 293, 273, 271, 270, 262, 2)
AND create_time <![CDATA[ < ]]> UNIX_TIMESTAMP(DATE_ADD(CURDATE(), INTERVAL 24 HOUR ))) t WHERE a.create_time >= UNIX_TIMESTAMP(CURDATE())
AND a.create_time <![CDATA[ < ]]> UNIX_TIMESTAMP(DATE_ADD(CURDATE(), INTERVAL 24 HOUR))) t
GROUP BY order_status) tt GROUP BY order_status) tt
</select> </select>
<select id="getOrderAmountSummary" <select id="getOrderAmountSummary"
resultType="com.njzscloud.supervisory.statistics.pojo.OrderAmountSummary"> resultType="com.njzscloud.supervisory.statistics.pojo.OrderAmountSummary">
SELECT price amount, FROM_UNIXTIME(out_time) out_time, who_pay cd SELECT a.price amount, FROM_UNIXTIME(a.out_time) out_time, a.who_pay cd
FROM ba_order FROM ba_order a
WHERE status = 1 INNER JOIN ba_goods b ON b.id = a.goods_id AND b.id NOT IN (287, 286, 279, 278, 293, 273, 271, 270, 262, 2)
AND out_time >= #{startTime} WHERE a.status = 1
AND out_time <![CDATA[ <= ]]> #{endTime} AND a.out_time >= #{startTime}
AND a.out_time <![CDATA[ <= ]]> #{endTime}
</select> </select>
</mapper> </mapper>