陶杰
2025-01-09 1fe9a1c594c40324b64f2822b2381e741fa231fc
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?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.statisticsAnalysis.FlowerMaterialMapper">
 
 
    <select id="getFlowerMaterialPage"
            resultType="com.mzl.flower.dto.response.statisticAnalysis.FlowerMaterialVO">
<!--         <include refid="flowerMaterialSql"></include>-->
        <include refid="flowerMaterialSqlWidthDict"></include>
    </select>
    <select id="getFlowerMaterialList"
            resultType="com.mzl.flower.dto.response.statisticAnalysis.FlowerMaterialVO">
        <include refid="flowerMaterialSqlWidthDict"></include>
    </select>
    <select id="getFlowerMaterialStatis"
            resultType="com.mzl.flower.dto.response.statisticAnalysis.FlowerMaterialStaticVO">
        select
            count(distinct si.id) as supplier_amount,
            count(f.id) as flower_amount,
            sum(f.stock) as flower_stock_amount
        from t_flower f
        left join t_supplier_info si
        on f.supplier_id=si.id
        left join t_user u
        on si.user_id =u.id
        left join t_station s
        on si.station_id=s.id
        left join t_flower_category fc
        on f.category=fc.id
        <include refid="flowerMaterialSql_where"></include>
    </select>
 
    <sql id="flowerMaterialSql">
        select
            si.id as supplier_id
             ,si.name as supplier_name
             ,u.login_name
             ,si.contact_tel
             ,s.name as station_name
             ,fc.name as category_name
             ,case when fc_parent.id  is not null then fc_parent.name else fc.name end as parent_category_name
             ,f.name as flower_name
             ,f.`level` as flower_level
             ,f.unit as flower_unit
             ,f.price as flower_price
             ,f.stock flower_stock
             ,f.status as flower_status
        from t_flower f
        left join t_supplier_info si
        on f.supplier_id=si.id
        left join t_user u
        on si.user_id =u.id
        left join t_station s
        on si.station_id=s.id
        left join t_flower_category fc
        on f.category=fc.id
        left join t_flower_category fc_parent
        on fc.parent_id=fc_parent.id
--           and u.deleted=0 and s.deleted=0 and fc.deleted=0
        <include refid="flowerMaterialSql_where"></include>
        <if test="dto.orderField !=null and dto.orderField !=''">
            order by ${dto.orderField} ${dto.orderType}
        </if>
    </sql>
 
    <sql id="flowerMaterialSqlWidthDict">
        select
            si.id as supplier_id
             ,si.name as supplier_name
             ,u.login_name
             ,si.contact_tel
             ,s.name as station_name
             ,fc.name as category_name
             ,case when fc_parent.id  is not null then fc_parent.name else fc.name end as parent_category_name
             ,f.name as flower_name
             ,f.`level` as flower_level
             ,f.unit as flower_unit
             ,f.price as flower_price
             ,f.stock flower_stock
             ,f.status as flower_status
             ,code.label as flower_status_str
             , code2.label as flower_level_str
        from t_flower f
        left join t_supplier_info si
        on f.supplier_id=si.id
        left join t_user u
        on si.user_id =u.id
        left join t_station s
        on si.station_id=s.id
        left join t_flower_category fc
        on f.category=fc.id
        left join t_flower_category fc_parent
        on fc.parent_id=fc_parent.id
        LEFT JOIN (SELECT ct.label, ct.value from t_code_value ct where type_code = 'FLOWER_STATUS') code ON f.status = code.value
        LEFT JOIN (SELECT ct.label, ct.value from t_code_value ct where type_code = 'FLOWER_LEVEL') code2 ON f.`level` = code2.value
        <include refid="flowerMaterialSql_where"></include>
        <if test="dto.orderField !=null and dto.orderField !=''">
            order by ${dto.orderField} ${dto.orderType}
        </if>
    </sql>
 
    <sql id="flowerMaterialSql_where">
        where f.deleted=0  and si.deleted =0
        <if test="dto.supplierId != null">
            and f.supplier_id = #{dto.supplierId}
        </if>
        <if test="dto.supplierName !=null and dto.supplierName !=''">
            AND  si.name LIKE concat('%', #{dto.supplierName},'%')
        </if>
        <if test="dto.loginName !=null and dto.loginName !=''">
            AND  u.login_name LIKE concat('%', #{dto.loginName},'%')
        </if>
 
        <if test="dto.contactTel !=null and dto.contactTel !=''">
            AND  si.contact_tel LIKE concat('%', #{dto.contactTel},'%')
        </if>
 
        <if test="dto.stationId !=null and dto.stationId !=''">
            AND  si.station_id = #{dto.stationId}
        </if>
 
        <if test="dto.flowerCategory !=null and dto.flowerCategory !=''">
            AND ( f.category = #{dto.flowerCategory} or f.category in (
                select id from t_flower_category where parent_id = #{dto.flowerCategory}
            ))
 
        </if>
<!--        <if test="dto.flowerStatus != null and dto.flowerStatus != ''">-->
<!--            <if test="dto.flowerStatus == 'OFF'">-->
<!--                AND f.status IN ('OFF', 'FORCE_OFF')-->
<!--            </if>-->
<!--            <if test="dto.flowerStatus != 'OFF'">-->
<!--                AND f.status = #{dto.flowerStatus}-->
<!--            </if>-->
<!--        </if>-->
 
        <if test="dto.flowerStatus != null and dto.flowerStatus != ''">
            AND f.status = #{dto.flowerStatus}
        </if>
        <if test="dto.flowerLevel !=null and dto.flowerLevel !=''">
            AND  f.`level` = #{dto.flowerLevel}
        </if>
 
 
 
 
    </sql>
 
 
 
</mapper>