gongzuming
2024-09-20 e425e5d101e1d48e40674a2a801efb8dd060e8a5
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
<?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.flower.FlowerCategoryMapper">
 
    <select id="selectCategoryList" resultType="com.mzl.flower.dto.response.flower.FlowerCategoryTreeDTO">
        SELECT q.*
        , (select count(1) from t_flower_category f where f.parent_id = q.id) childrenCount
        FROM t_flower_category q
        WHERE q.deleted = 0
        <if test="condition.name != null and condition.name != ''">
            AND (q.name LIKE concat('%', #{condition.name},'%')
                or exists (
                    select 1 from t_flower_category sq where sq.parent_id = q.id and sq.name LIKE concat('%', #{condition.name},'%')
                )
            )
        </if>
        <choose>
            <when test="condition.parentId != null">
                AND q.parent_id = #{condition.parentId}
            </when>
            <otherwise>
                AND q.parent_id is null
            </otherwise>
        </choose>
        <if test="condition.shown != null and condition.shown">
            AND (q.shown = 1 or q.shown is null)
        </if>
        <if test="condition.shown != null and !condition.shown">
            AND q.shown = 0
        </if>
        ORDER BY q.sort_by, q.create_time Desc
    </select>
 
    <select id="selectTreeList" resultType="com.mzl.flower.dto.response.flower.FlowerCategoryTreeDTO">
        SELECT q.*
        , (select min(f.price) from t_flower f where f.category = q.id and f.status = 'UP' and f.deleted = 0) priceLow
        , (select max(f.price) from t_flower f where f.category = q.id and f.status = 'UP' and f.deleted = 0) priceHigh
        , (select sum(f.stock) from t_flower f where f.category = q.id and f.status = 'UP' and f.deleted = 0) stock
        , (select count(1) from t_flower f where f.category = q.id and f.status = 'UP' and f.deleted = 0 and (f.shown = 1 or f.shown is null)) flowerCount
        FROM t_flower_category q
        WHERE q.deleted = 0
        <if test="condition.name != null and condition.name != ''">
            AND (q.name LIKE concat('%', #{condition.name},'%')
                or exists (
                    select 1 from t_flower_category sq where sq.parent_id = q.id and sq.name LIKE concat('%', #{condition.name},'%')
                )
            )
        </if>
        <if test="condition.supplierId != null">
            AND exists(
                select 1 from t_flower f, t_flower_category fc
                where f.category = fc.id
                and (fc.id = q.id or fc.parent_id = q.id)
                and f.supplier_id = #{condition.supplierId}
            )
        </if>
        <if test="condition.parentId != null">
            AND q.parent_id = #{condition.parentId}
        </if>
        <if test="condition.shown != null and condition.shown">
            AND (q.shown = 1 or q.shown is null)
        </if>
        <if test="condition.shown != null and !condition.shown">
            AND q.shown = 0
        </if>
        ORDER BY q.sort_by, q.create_time Desc
    </select>
 
    <update id="clearParamByParamId">
        update t_flower_category set param_id = null where param_id = #{paramId}
    </update>
 
    <update id="setParamById">
        update t_flower_category set param_id = #{paramId} where id in
        <foreach collection="categoryIds" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
 
    <select id="selectHomeCategoryDaily" resultType="com.mzl.flower.dto.response.flower.FlowerCategoryDailyDTO">
        SELECT q.id, q.name, d.ave_price, d.ave_price_difference, ave_price_difference_rate, d.day
        FROM t_flower_category q
        join t_flower_category_daily d on q.id = d.category_id
        WHERE q.deleted = 0
        <if test="day != null">
            AND d.day = #{day}
        </if>
        <if test="partnerId != null">
            AND d.partner_id = #{partnerId}
        </if>
        ORDER BY d.day desc, d.ave_price desc
    </select>
</mapper>