Helius
2021-08-25 72a6cb4a44abe356a444788ec92015c25766d9df
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
<?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.xzx.gc.order.mapper.JhyOrderMapper">
 
    <select id="selectJhyOrderList" resultType="com.xzx.gc.order.vo.JhyOrderListVo">
        select
            a.id orderid
            ,a.phone
            ,a.username
            ,CONCAT(a.area, a.address) address
            ,a.longitude
            ,a.latitude
            ,a.weight
            ,a.status
            ,a.remark
            ,date_format(a.receiving_time, '%Y-%m-%d %H:%i') receivingTime
            ,CONCAT(a.reserve_date, ' ', a.reserve_time) reserveTime
            ,GROUP_CONCAT(b.title) items
            ,sum(b.score) recycleScore
            ,IFNULL(SUM(case when d.item_unit = '台' then b.weight
                else 0 end), 0) recycleTai
            ,IFNULL(SUM(case when d.item_unit = 'kg' then b.weight
                else 0 end), 0) recycleKg
            ,c.username jhyName
            ,c.mobile jhyPhone
        from xzx_jhy_order a
        inner join xzx_jhy_order_items b on a.id=b.order_id
        left join xzx_jhy_info c on a.jhy_id=c.user_id
        left join xzx_sys_environmental_info d on b.item_type = d.id
        <where>
            <if test="record.type == 1">
                and a.user_id=#{record.userId}
            </if>
            <if test="record.type == 2">
                <if test="record.status != 1">
                    and a.jhy_id=#{record.userId}
                </if>
            </if>
            <if test="record.status != null and record.status != ''">
                and a.status = #{record.status}
            </if>
        </where>
        group by a.id
        order by a.receiving_time desc, a.id desc
    </select>
 
    <select id="selectOrderStatusCount" resultType="com.xzx.gc.order.vo.JhyStatusCountVo">
        select
           status,
           count(1) cnt
        from xzx_jhy_order
        <where>
            status=1
            <if test="type == 2">
                and user_id=#{userId}
            </if>
        </where>
        group by status
        union  all
        select
           status,
           count(1) cnt
        from xzx_jhy_order
        <where>
            <if test="type == 1">
                and jhy_id=#{userId}
            </if>
            <if test="type == 2" >
                and user_id=#{userId}
            </if>
        </where>
        group by status
    </select>
 
    <select id="selectJhyOrderListByStatus" resultType="com.xzx.gc.entity.JhyOrder">
        select * from xzx_jhy_order
        where user_id=#{userId} and status in
        <foreach collection="list" index="index" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>
 
    <select id="selectJhyOrderNoWaitAndCancel" resultType="com.xzx.gc.entity.JhyOrder">
        select * from xzx_jhy_order
        where status not in (1, 2, 5) and user_id=#{userId}
    </select>
 
    <select id="selectInviteUserOrderList" resultType="com.xzx.gc.order.vo.InviteUserOrderVo">
        select
               c.order_no orderNo,
               from_base64(b.nick_name) username,
               b.mobile_phone phone,
               c.username orderName,
               c.phone orderPhone,
               concat(c.reserve_date, ' ', c.reserve_time) time,
               concat(area, address) address,
               group_concat(d.title) recycleType,
               c.status status,
               sum(d.score) score
        from xzx_user_share_info a
                 inner join xzx_user_info b on a.register_mobile_phone=b.mobile_phone
                 inner join xzx_jhy_order c on b.user_id=c.user_id
                 inner join xzx_jhy_order_items d on c.id=d.order_id
        where register_mobile_phone=#{record.phone}
        group by c.order_no
    </select>
</mapper>