mitao
2025-02-21 31573d6180d15ef65ed0df9c2732495f40b12663
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<?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.panzhihua.service_community.dao.ComBatteryCommodityMapper">
 
    <resultMap type="com.panzhihua.service_community.entity.ComBatteryCommodity" id="ComBatteryCommodityMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="name" column="name" jdbcType="VARCHAR"/>
        <result property="code" column="code" jdbcType="VARCHAR"/>
        <result property="price" column="price" jdbcType="VARCHAR"/>
        <result property="storeId" column="store_id" jdbcType="INTEGER"/>
        <result property="status" column="status" jdbcType="INTEGER"/>
        <result property="classId" column="class_id" jdbcType="INTEGER"/>
        <result property="introduce" column="introduce" jdbcType="VARCHAR"/>
        <result property="postage" column="postage" jdbcType="VARCHAR"/>
        <result property="images" column="images" jdbcType="VARCHAR"/>
        <result property="detail" column="detail" jdbcType="VARCHAR"/>
        <result property="isDel" column="is_del" jdbcType="INTEGER"/>
        <result property="createAt" column="create_at" jdbcType="TIMESTAMP"/>
        <result property="createBy" column="create_by" jdbcType="INTEGER"/>
        <result property="updateAt" column="update_at" jdbcType="TIMESTAMP"/>
        <result property="updateBy" column="update_by" jdbcType="INTEGER"/>
    </resultMap>
 
    <!--查询单个-->
    <select id="queryById" resultType="com.panzhihua.common.model.vos.common.ComBatteryCommodityVo">
        SELECT
            cbc.id,
            cbc.`name`,
            cbc.`code`,
            cbc.price,
            cbc.store_id,
            cbc.`status`,
            cbc.class_id,
            cbc.introduce,
            cbc.postage,
            cbc.images,
            cbc.detail,
            cbc.is_del,
            cbc.create_at,
            cbc.create_by,
            cbc.update_at,
            cbc.update_by,
            cbs.`name` as storeName,
            cbsc.`name` as className,
            (select count(id) from com_battery_commodity_order where commodity_id = cbc.id and `status` in (2,3,4)
            AND create_at BETWEEN DATE_ADD( curdate(), INTERVAL - DAY ( curdate())+ 1 DAY ) AND now()) as monthSale
        FROM
            com_battery_commodity as cbc
            left join com_battery_store as cbs on cbs.id = cbc.store_id
            left join com_battery_store_class as cbsc on cbsc.id = cbc.class_id
        where cbc.id = #{id}
    </select>
 
    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultType="com.panzhihua.common.model.vos.common.ComBatteryCommodityVo">
        SELECT
        cbc.id,
        cbc.`name`,
        cbc.`code`,
        cbc.price,
        cbc.store_id,
        cbc.`status`,
        cbc.class_id,
        cbc.introduce,
        cbc.postage,
        cbc.images,
        cbc.detail,
        cbc.is_del,
        cbc.create_at,
        cbc.create_by,
        cbc.update_at,
        cbc.update_by,
        cbs.`name` as storeName,
        cbsc.`name` as className,
        (select count(id) from com_battery_commodity_order where commodity_id = cbc.id and `status` in (2,3,4)) as monthSale
        FROM
        com_battery_commodity as cbc
        left join com_battery_store as cbs on cbs.id = cbc.store_id
        left join com_battery_store_class as cbsc on cbsc.id = cbc.class_id
        <where>
            and cbc.is_del = 2
            <if test="dto.id != null">
                and cbc.id = #{dto.id}
            </if>
            <if test="dto.name != null and dto.name != ''">
                and cbc.name = #{dto.name}
            </if>
            <if test="dto.code != null and dto.code != ''">
                and cbc.code = #{dto.code}
            </if>
            <if test="dto.storeId != null">
                and cbc.store_id = #{dto.storeId}
            </if>
            <if test="dto.status != null">
                and cbc.status = #{dto.status}
            </if>
            <if test="dto.classId != null">
                and cbc.class_id = #{dto.classId}
            </if>
            <if test="dto.keyWord != null and dto.keyWord != ''">
                and (cbc.`name` like concat('%',#{dto.keyWord},'%') or cbc.`code` like concat('%',#{dto.keyWord},'%'))
            </if>
        </where>
        order by cbc.create_at desc
    </select>
 
    <!--查询所有数据-->
    <select id="queryAllByList" resultType="com.panzhihua.common.model.vos.common.ComBatteryCommodityVo">
        SELECT
        cbc.id,
        cbc.`name`,
        cbc.`code`,
        cbc.price,
        cbc.store_id,
        cbc.`status`,
        cbc.class_id,
        cbc.introduce,
        cbc.postage,
        cbc.images,
        cbc.detail,
        cbc.is_del,
        cbc.create_at,
        cbc.create_by,
        cbc.update_at,
        cbc.update_by,
        cbs.`name` as storeName,
        cbsc.`name` as className,
        (select count(id) from com_battery_commodity_order where commodity_id = cbc.id and `status` in (2,3,4)) as monthSale
        FROM
        com_battery_commodity as cbc
        left join com_battery_store as cbs on cbs.id = cbc.store_id
        left join com_battery_store_class as cbsc on cbsc.id = cbc.class_id
        <where>
            and cbc.is_del = 2
            <if test="dto.id != null">
                and cbc.id = #{dto.id}
            </if>
            <if test="dto.name != null and dto.name != ''">
                and cbc.name = #{dto.name}
            </if>
            <if test="dto.code != null and dto.code != ''">
                and cbc.code = #{dto.code}
            </if>
            <if test="dto.storeId != null">
                and cbc.store_id = #{dto.storeId}
            </if>
            <if test="dto.status != null">
                and cbc.status = #{dto.status}
            </if>
            <if test="dto.classId != null">
                and cbc.class_id = #{dto.classId}
            </if>
            <if test="dto.keyWord != null and dto.keyWord != ''">
                and (cbc.`name` like concat('%',#{dto.keyWord},'%') or cbc.`code` like concat('%',#{dto.keyWord},'%'))
            </if>
        </where>
        order by cbc.create_at desc
    </select>
 
    <select id="queryByAppletsPage" resultType="com.panzhihua.common.model.vos.common.ComBatteryCommodityVo">
        SELECT
        cbc.id,
        cbc.`name`,
        cbc.`code`,
        cbc.price,
        cbc.store_id,
        cbc.`status`,
        cbc.class_id,
        cbc.introduce,
        cbc.postage,
        cbc.images,
        cbc.detail,
        cbc.is_del,
        cbc.create_at,
        cbc.create_by,
        cbc.update_at,
        cbc.update_by,
        cbs.`name` as storeName,
        cbsc.`name` as className,
        (select count(id) from com_battery_commodity_order where commodity_id = cbc.id and `status` in (2,3,4)) as monthSale
        FROM
        com_battery_commodity as cbc
        left join com_battery_store as cbs on cbs.id = cbc.store_id
        left join com_battery_store_class as cbsc on cbsc.id = cbc.class_id
        <where>
            and cbc.is_del = 2 and status = 1
            <if test="dto.id != null">
                and cbc.id = #{dto.id}
            </if>
            <if test="dto.name != null and dto.name != ''">
                and cbc.name like concat('%',#{dto.keyWord},'%')
            </if>
            <if test="dto.storeId != null">
                and cbc.store_id = #{dto.storeId}
            </if>
            <if test="dto.classId != null">
                and cbc.class_id = #{dto.classId}
            </if>
        </where>
        order by cbc.create_at desc
    </select>
 
    <select id="queryAllByClassIdList" resultType="com.panzhihua.common.model.vos.common.ComBatteryCommodityVo">
        SELECT
        cbc.id,
        cbc.`name`,
        cbc.`code`,
        cbc.price,
        cbc.store_id,
        cbc.`status`,
        cbc.class_id,
        cbc.introduce,
        cbc.postage,
        cbc.images,
        cbc.detail,
        cbc.is_del,
        cbc.create_at,
        cbc.create_by,
        cbc.update_at,
        cbc.update_by,
        cbs.`name` as storeName,
        cbsc.`name` as className,
        (select count(id) from com_battery_commodity_order where commodity_id = cbc.id and `status` in (2,3,4)) as monthSale
        FROM
        com_battery_commodity as cbc
        left join com_battery_store as cbs on cbs.id = cbc.store_id
        left join com_battery_store_class as cbsc on cbsc.id = cbc.class_id
        where cbc.class_id = #{classId} and cbc.is_del = 2 and cbc.status = 1
        order by cbc.create_at desc
    </select>
</mapper>