guohongjin
2024-05-15 5b7639f0bd9e056738ec15100ed0532e965c6cd5
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
<?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="cn.stylefeng.guns.modular.business.mapper.OrderMentalTestMapper">
 
    <select id="getPage" resultType="cn.stylefeng.guns.modular.business.dto.OrderMentalTestPageDTO">
        SELECT
            o.id id, o.order_no,
            o.create_time test_create_time,
            tt.*, tt.id topicId,
            tu.nick_name, tu.telephone
        FROM
            t_order_mental_test o
            LEFT JOIN t_mental_test_topic tt ON o.goods_id = tt.id
            LEFT JOIN toc_customer tu ON tu.customer_id = o.user_id
        <where>
            <if test="adminView != null and adminView == 1">
                AND o.status_flag = 1 AND ( ( tt.test_type = 0 AND o.test_flag = 1 ) OR tt.test_type = 1 OR o.is_back = 1 )
            </if>
            <if test="title != null and title != ''">
                AND tt.title LIKE CONCAT('%', #{title}, '%')
            </if>
            <if test="testType != null">
                AND tt.test_type = #{testType}
            </if>
            <if test="statusFlag != null">
                AND o.status_flag = #{statusFlag}
            </if>
            <if test="nickName != null and nickName != ''">
                AND tu.nick_name LIKE CONCAT('%', #{nickName}, '%')
            </if>
            <if test="telephone != null and telephone != ''">
                AND tu.telephone LIKE CONCAT('%', #{telephone}, '%')
            </if>
        </where>
        ORDER BY o.create_time DESC
    </select>
 
    <select id="getInfoById" resultType="cn.stylefeng.guns.modular.business.dto.OrderMentalTestDetailDTO">
        SELECT
            o.*,
            t.*, t.id topicId,
            tr.*,
            worker.nick_name consultWorkerName
        FROM
            t_order_mental_test o
            LEFT JOIN t_mental_test_topic t ON o.goods_id = t.id
            LEFT JOIN t_mental_test_record tr ON tr.answer_no = o.order_no
            LEFT JOIN toc_customer worker ON worker.customer_id = tr.consult_worker_id
        <where>
            AND o.id = #{id}
        </where>
        LIMIT 1
    </select>
 
    <select id="getStatOrderList" resultType="java.util.Map">
        SELECT
            DATE_FORMAT( create_time, #{dateFormat} ) `time`,
            SUM( order_amount ) `data`,
            COUNT( 1 ) `number`
        FROM
            t_order_mental_test o
        <where>
            <if test="statusList != null and statusList.size != 0">
                AND o.status_flag IN
                <foreach collection="statusList" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="orderNoList != null and orderNoList.size != 0">
                AND o.order_no IN
                <foreach collection="orderNoList" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="workerId != null">
                AND o.user_id = #{workerId}
            </if>
            <if test="beginTime != null and beginTime != ''">
                AND o.create_time <![CDATA[ >= ]]> #{beginTime}
            </if>
            <if test="endTime != null and endTime != ''">
                AND o.create_time <![CDATA[ <= ]]> #{endTime}
            </if>
        </where>
        GROUP BY `time`
    </select>
 
</mapper>