陶杰
2024-10-01 bf2bffc884f00fd2ed2f16667ab6b91328012b8a
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
<?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.mzl.flower.mapper.comment.FlowerCommentMapperCustom">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.mzl.flower.entity.FlowerCommentDO">
        <id column="id" property="id" />
        <result column="deleted" property="deleted" />
        <result column="create_by" property="createBy" />
        <result column="create_time" property="createTime" />
        <result column="update_by" property="updateBy" />
        <result column="update_time" property="updateTime" />
        <result column="order_id" property="orderId" />
        <result column="order_item_id" property="orderItemId" />
 
        <result column="customer_id" property="customerId" />
        <result column="customer_user_id" property="customerUserId" />
        <result column="supplier_id" property="supplierId" />
        <result column="supplier_user_id" property="supplierUserId" />
 
        <result column="flower_id" property="flowerId" />
        <result column="flower_cover" property="flowerCover" />
        <result column="comment_grade" property="commentGrade" />
        <result column="comment" property="comment" />
        <result column="comment_images" property="commentImages" />
        <result column="anonymity_falg" property="anonymityFalg" />
    </resultMap>
    <select id="getPage" resultType="com.mzl.flower.dto.response.comment.FlowerCommentVO">
        <include refid="baseSql" />
    </select>
    <select id="getList" resultType="com.mzl.flower.dto.response.comment.FlowerCommentVO">
        <include refid="baseSql" />
    </select>
    <select id="getSupplierAvgScore" resultType="java.math.BigDecimal">
        SELECT
            COALESCE(ROUND(SUM(c.comment_grade) / NULLIF(COUNT(1), 0), 1), 0) AS average_grade
        FROM t_flower_comment c
        WHERE c.deleted = false
          AND c.supplier_id = #{supplierId}
    </select>
 
    <sql id="baseSql">
        select c.*,
            oi.flower_name,
            oi.flower_unit,
            oi.flower_color,
            oi.flower_level,
            oi.flower_category,
            ci.name as customer_name,
            ci.cover as customer_cover
        from t_flower_comment c
        left join t_order_item oi
        on c.order_item_id=oi.id
        left join t_customer_info ci
        on c.customer_id=ci.id
        where c.deleted=false
        <if test="param.id != null and param.id != ''">
            and c.id = #{param.id}
        </if>
        <if test="param.orderId != null and param.orderId != ''">
            and c.order_id = #{param.orderId}
        </if>
        <if test="param.orderItemId != null and param.orderItemId != ''">
            and c.order_item_id = #{param.orderItemId}
        </if>
        <if test="param.customerId != null ">
            and c.customer_id = #{param.customerId}
        </if>
        <if test="param.supplierId != null">
            and c.supplier_id = #{param.supplierId}
        </if>
        <if test="param.flowerId != null">
            and c.flower_id = #{param.flowerId}
        </if>
 
    </sql>
 
</mapper>