huliguo
6 天以前 adac148db7cefc6848933989d407b1827749a5a6
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.errand.mapper.CourierMapper">
 
 
    <select id="getCourierInfo" resultType="com.ruoyi.errand.object.vo.app.CourierInfoVO">
        select
            tc.name as name,
            tc.phone as phone,
            tc2.name as communityName
        from t_courier tc
        left join t_community_courier tcc on tc.id = tcc.courier_id
        left join t_community tc2 on tcc.community_id = tc2.id
        where
            tc.del_flag=0
            and tc.id=#{courierId}
    </select>
    <select id="getDatStatistics" resultType="com.ruoyi.errand.object.vo.app.CourierStatisticsVO">
        SELECT
            COUNT(CASE WHEN DATE(receiving_time) = CURDATE() THEN 1 END) AS `day`,
            COUNT(CASE WHEN YEARWEEK(receiving_time, 1) = YEARWEEK(CURDATE(), 1) THEN 1 END) AS `week`,
            COUNT(CASE WHEN YEAR(receiving_time) = YEAR(CURDATE())
                AND MONTH(receiving_time) = MONTH(CURDATE()) THEN 1 END) AS `month`
        FROM t_order
        WHERE courier_id = #{courierId}
          and del_flag = 0
          AND order_status IN (2, 4, 5) -- 进行中、已完成、已评价状态
          AND receiving_time IS NOT NULL;
    </select>
    <select id="getCourierOrderList" resultType="com.ruoyi.errand.object.vo.app.CourierOrderListVO">
        select
            o.id as id,
            o.address_detail as addressDetail,
            o.recipient_name as recipientName,
            o.recipient_phone as recipientPhone,
            o.order_status as orderStatus,
            o.order_time as receivingTime,
            te.rating as rating
        from
            t_order o
        left join  t_evaluation te on o.id = te.order_id and te.type = 0
        where
        o.del_flag = 0          -- 过滤未删除的订单
        and o.pay_status = 2
        and o.order_status != 3-- 过滤未支付的订单
        <choose>
            <!-- 当状态=1时,按社区ID查询 -->
            <when test="orderStatus == 1">
                AND o.community_id = #{communityId}
            </when>
            <!-- 当状态为全部时,按社区ID或者跑腿员id查询 -->
            <when test="orderStatus == null or orderStatus == 1">
                AND ((o.community_id = #{communityId} and order_status = 1) or o.courier_id = #{courierId})
            </when>
            <!-- 其他状态按快递员ID查询 -->
            <otherwise>
                AND o.courier_id = #{courierId}
            </otherwise>
        </choose>
        <if test="orderStatus !=null and orderStatus !=0">
            AND o.order_status = #{orderStatus}  -- 订单状态筛选条件
        </if>
        ORDER BY
            CASE WHEN o.order_status = 1 THEN 0 ELSE 1 END,  -- 待确认订单置顶
        o.order_time DESC
    </select>
    <select id="getCourierPageList" resultType="com.ruoyi.errand.object.vo.sys.CourierPageListVO">
        select
        tc.id as id,
        tc.name as name,
        tc.phone as phone,
        tcm.name as communityName,
        tc.status as status
        from t_courier tc
        left join t_community_courier tcc on tc.id = tcc.courier_id
        left join t_community tcm on tcc.community_id = tcm.id
        where
            tc.del_flag=0
        <if test="dto.name !=null and ''!=dto.name">
            AND tc.name like concat ('%',#{dto.name},'%')
        </if>
        <if test="dto.phone !=null and ''!=dto.phone">
            AND tc.phone = #{dto.phone}
        </if>
        <if test="dto.status !=null ">
            AND tc.status = #{dto.status}
        </if>
    </select>
    <select id="detail" resultType="com.ruoyi.errand.object.vo.sys.CourierSysDetailVO">
        select
            tc.name as name,
            tc.phone as phone,
            tc.id_card as idCard,
            tcc.community_id as communityId,
            tcm.name as communityName,
            tc.create_time as createTime,
            tc.status as status,
            tc.front_view as frontView,
            tc.back_view as backView
        from t_courier tc
                 left join t_community_courier tcc on tc.id = tcc.courier_id
                 left join t_community tcm on tcc.community_id = tcm.id
        where
            tc.id=#{id}
    </select>
    <select id="getAllCourierList" resultType="com.ruoyi.errand.object.vo.sys.AllCourierListVO">
        select
            id as courierId,
            name as name
        from
            t_courier
        where
            del_flag = 0
          and status = 1
        <if test="couriers!=null and couriers.size>0">
            and
            id not in
            <foreach collection="couriers" item="item" index="index" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
 
 
    </select>
</mapper>