1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.ruoyi.wrzs.report.mapper;
 
import com.ruoyi.wrzs.report.pojo.vo.CarrierPerformanceVo;
import com.ruoyi.wrzs.report.pojo.vo.DailyWeighbridgeVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
 
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
 
/**
 * 报表中心统计查询
 */
@Mapper
public interface ReportCenterMapper {
 
    /** 每日过磅统计(自动称重记录) */
    @Select("select date_format(first_weight_time, '%Y-%m-%d') as statDate, "
            + "count(*) as tripCount, "
            + "ifnull(sum(net_weight), 0) / 1000 as cargoVolume, "
            + "ifnull(avg(order_deviation), 0) as deviationRate, "
            + "sum(case when cheat_flag = '1' then 1 else 0 end) as cheatCount "
            + "from wrzs_weighbridge_record "
            + "where weigh_status = '2' and first_weight_time between #{start} and #{end} "
            + "group by date_format(first_weight_time, '%Y-%m-%d') order by statDate")
    List<DailyWeighbridgeVo> dailyStat(@Param("start") LocalDateTime start, @Param("end") LocalDateTime end);
 
    /** 每日过磅统计(历史手工过磅记录,兜底) */
    @Select("select date_format(weight_time, '%Y-%m-%d') as statDate, "
            + "count(*) as tripCount, "
            + "ifnull(sum(gross_weight), 0) / 1000 as cargoVolume, "
            + "ifnull(avg(position_offset), 0) as deviationRate, "
            + "0 as cheatCount "
            + "from unattended_operation "
            + "where weight_time between #{start} and #{end} "
            + "group by date_format(weight_time, '%Y-%m-%d') order by statDate")
    List<DailyWeighbridgeVo> dailyStatLegacy(@Param("start") LocalDateTime start, @Param("end") LocalDateTime end);
 
    /** 承运商绩效统计 */
    @Select("select carrier_name as carrierName, "
            + "count(*) as totalTrips, "
            + "sum(case when appointment_time is not null and first_weight_time <= appointment_time then 1 else 0 end) as onTimeTrips, "
            + "sum(case when appointment_time is not null and first_weight_time > appointment_time then 1 else 0 end) as lateTrips, "
            + "sum(case when cheat_flag = '1' then 1 else 0 end) as cheatCount, "
            + "ifnull(avg(order_deviation), 0) as avgDeviation, "
            + "ifnull(sum(net_weight), 0) / 1000 as totalNetWeight "
            + "from wrzs_weighbridge_record "
            + "where weigh_status = '2' and first_weight_time between #{start} and #{end} "
            + "and carrier_name is not null and carrier_name <> '' "
            + "group by carrier_name order by totalTrips desc")
    List<CarrierPerformanceVo> carrierPerformance(@Param("start") LocalDateTime start, @Param("end") LocalDateTime end);
 
    /** 区间总览 */
    @Select("select count(*) as totalTrips, "
            + "ifnull(sum(net_weight), 0) / 1000 as totalNetWeight, "
            + "ifnull(avg(order_deviation), 0) as avgDeviation, "
            + "sum(case when cheat_flag = '1' then 1 else 0 end) as cheatCount, "
            + "sum(case when appointment_time is not null and first_weight_time <= appointment_time then 1 else 0 end) as onTimeTrips, "
            + "sum(case when appointment_time is not null then 1 else 0 end) as appointmentTrips, "
            + "sum(case when erp_sync_status = '1' then 1 else 0 end) as erpSyncedCount "
            + "from wrzs_weighbridge_record "
            + "where weigh_status = '2' and first_weight_time between #{start} and #{end}")
    Map<String, Object> overview(@Param("start") LocalDateTime start, @Param("end") LocalDateTime end);
}