wzy
2021-04-01 d388e2788b7ef088d7cd40f901b0acdcec460bc3
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
<?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.matrix.system.common.dao.BusParameterSettingsDao">
    <!-- 定义BusParameterSettings 的复杂关联map -->
    <resultMap type="com.matrix.system.common.bean.BusParameterSettings" id="BusParameterSettingsMap">
        <id property="paramId" column="param_id"/>
        <result property="paramCode" column="param_code"/>
        <result property="paramValue" column="param_value"/>
        <result property="paramValue1" column="param_value1"/>
        <result property="paramValue2" column="param_value2"/>
        <result property="paramValue3" column="param_value3"/>
        <result property="companyId" column="company_id"/>
        <result property="shopId" column="shop_id"/>
    </resultMap>
 
 
    <!-- 定义BusParameterSettings 的简单map  ,本map不添加其他的关联属性 -->
    <resultMap type="com.matrix.system.common.bean.BusParameterSettings" id="BusParameterSettingsSimpleMap">
        <id property="paramId" column="param_id"/>
        <result property="paramCode" column="param_code"/>
        <result property="paramValue" column="param_value"/>
        <result property="paramValue1" column="param_value1"/>
        <result property="paramValue2" column="param_value2"/>
        <result property="paramValue3" column="param_value3"/>
        <result property="companyId" column="company_id"/>
        <result property="shopId" column="shop_id"/>
    </resultMap>
 
 
    <!--  插入方法   -->
    <insert id="insert" parameterType="com.matrix.system.common.bean.BusParameterSettings"
            useGeneratedKeys="true" keyProperty="paramId">
        INSERT INTO bus_parameter_settings (
            param_id,
            param_code,
            param_value,
            param_value1,
            param_value2,
            param_value3,
            company_id,
            shop_id
        )
    VALUES (
            #{paramId},
            #{paramCode},
            #{paramValue},
            #{paramValue1},
            #{paramValue2},
            #{paramValue3},
            #{companyId},
            #{shopId}
    )
    </insert>
 
 
    <!--  批量插入   -->
    <insert id="batchInsert" parameterType="java.util.List">
        INSERT INTO bus_parameter_settings (
        param_id,
        param_code,
        param_value,
        param_value1,
        param_value2,
        param_value3,
        company_id,
        shop_id
        )
        VALUES
        <foreach collection="list" item="item" index="index" separator=",">(
            #{item.paramId},
            #{item.paramCode},
            #{item.paramValue},
            #{item.paramValue1},
            #{item.paramValue2},
            #{item.paramValue3},
            #{item.companyId},
            #{item.shopId}
            )
        </foreach>
    </insert>
 
 
    <!--  根据Map更新 部分更新   -->
    <update id="updateByMap" parameterType="java.util.HashMap">
        UPDATE bus_parameter_settings
        <set>
            <if test="_parameter.containsKey('paramCode')">
                param_code = #{paramCode},
            </if>
            <if test="_parameter.containsKey('paramValue')">
                param_value = #{paramValue},
            </if>
            <if test="_parameter.containsKey('paramValue1')">
                param_value1 = #{paramValue1},
            </if>
            <if test="_parameter.containsKey('paramValue2')">
                param_value2 = #{paramValue2},
            </if>
            <if test="_parameter.containsKey('paramValue3')">
                param_value3 = #{paramValue3},
            </if>
            <if test="_parameter.containsKey('companyId')">
                company_id = #{companyId},
            </if>
            <if test="_parameter.containsKey('shopId')">
                shop_id = #{shopId},
            </if>
        </set>
        WHERE param_id=#{paramId}
    </update>
 
 
    <!--  根据对象更新 部分更新   -->
    <update id="updateByModel" parameterType="Long">
        UPDATE bus_parameter_settings
        <set>
            <if test="(paramCode!=null and paramCode!='') or (paramCode!='' and paramCode==0)">
                param_code = #{paramCode},
            </if>
            <if test="(paramValue!=null and paramValue!='') or (paramValue!='' and paramValue==0)">
                param_value = #{paramValue},
            </if>
            <if test="(paramValue1!=null and paramValue1!='') or (paramValue1!='' and paramValue1==0)">
                param_value1 = #{paramValue1},
            </if>
            <if test="(paramValue2!=null and paramValue2!='') or (paramValue2!='' and paramValue2==0)">
                param_value2 = #{paramValue2},
            </if>
            <if test="(paramValue3!=null and paramValue3!='') or (paramValue3!='' and paramValue3==0)">
                param_value3 = #{paramValue3},
            </if>
            <if test="(companyId!=null and companyId!='') ">
                company_id = #{companyId}
            </if>
             <if test="(shopId!=null and shopId!='') ">
                 shop_id = #{shopId}
            </if>
        </set>
        WHERE param_id=#{paramId}
    </update>
 
    <update id="updateParams" parameterType="java.util.List">
        <foreach collection="list" index="index" item="item" separator=";">
            UPDATE bus_parameter_settings
            <set>
                <if test="(item.paramValue!=null ) ">
                    param_value = #{item.paramValue},
                </if>
                <if test="(item.paramValue1!=null) ">
                    param_value1 = #{item.paramValue1},
                </if>
                <if test="(item.paramValue2!=null) ">
                    param_value2 = #{item.paramValue2},
                </if>
                <if test="(item.paramValue3!=null ) ">
                    param_value3 = #{item.paramValue3},
                </if>
                <if test="(item.shopId!=null ) ">
                    shop_id = #{item.shopId},
                </if>
            </set>
            where param_code = #{item.paramCode} and company_id = #{companyId}
        </foreach>
    </update>
 
 
    <!-- 批量删除 -->
    <delete id="deleteByIds" parameterType="java.util.List">
        delete from bus_parameter_settings where param_id in
        <foreach collection="list" index="index" item="item" open="("
                 separator="," close=")">
            #{item}
        </foreach>
    </delete>
 
    <!-- 根据id删除-->
    <delete id="deleteById" parameterType="Long">
        DELETE FROM bus_parameter_settings
        where  param_id=#{paramId} 
    </delete>
 
    <!-- 根据对象删除-->
    <delete id="deleteByModel" parameterType="Long">
        DELETE FROM bus_parameter_settings
        where 1=1
        <if test="record!=null">
            <if test="(record.paramId!=null and record.paramId!='') or (record.paramId!='' and record.paramId==0)">
                and param_id = #{record.paramId}
            </if>
            <if test="(record.paramCode!=null and record.paramCode!='') or (record.paramCode!='' and record.paramCode==0)">
                and param_code = #{record.paramCode}
            </if>
            <if test="(record.paramValue!=null and record.paramValue!='') or (record.paramValue!='' and record.paramValue==0)">
                and param_value = #{record.paramValue}
            </if>
            <if test="(record.paramValue1!=null and record.paramValue1!='') or (record.paramValue1!='' and record.paramValue1==0)">
                and param_value1 = #{record.paramValue1}
            </if>
            <if test="(record.paramValue2!=null and record.paramValue2!='') or (record.paramValue2!='' and record.paramValue2==0)">
                and param_value2 = #{record.paramValue2}
            </if>
            <if test="(record.paramValue3!=null and record.paramValue3!='') or (record.paramValue3!='' and record.paramValue3==0)">
                and param_value3 = #{record.paramValue3}
            </if>
            <if test="(record.companyId!=null and record.companyId!='') ">
                and company_id = #{record.companyId}
            </if>
            <if test="(record.shopId!=null and record.shopId!='') ">
                and shop_id = #{record.shopId}
            </if>
        </if>
    </delete>
 
 
    <!-- 分页查询 -->
    <select id="selectInPage" resultMap="BusParameterSettingsMap">
        select
        param_id,
        param_code,
        param_value,
        param_value1,
        param_value2,
        param_value3,
        company_id,
        shop_id
        from bus_parameter_settings
        where 1=1
        <if test="record!=null">
            <if test="(record.paramId!=null and record.paramId!='') or (record.paramId!='' and record.paramId==0)">
                and param_id = #{record.paramId}
            </if>
            <if test="(record.paramCode!=null and record.paramCode!='') or (record.paramCode!='' and record.paramCode==0)">
                and param_code = #{record.paramCode}
            </if>
            <if test="(record.paramValue!=null and record.paramValue!='') or (record.paramValue!='' and record.paramValue==0)">
                and param_value = #{record.paramValue}
            </if>
            <if test="(record.paramValue1!=null and record.paramValue1!='') or (record.paramValue1!='' and record.paramValue1==0)">
                and param_value1 = #{record.paramValue1}
            </if>
            <if test="(record.paramValue2!=null and record.paramValue2!='') or (record.paramValue2!='' and record.paramValue2==0)">
                and param_value2 = #{record.paramValue2}
            </if>
            <if test="(record.paramValue3!=null and record.paramValue3!='') or (record.paramValue3!='' and record.paramValue3==0)">
                and param_value3 = #{record.paramValue3}
            </if>
            <if test="(record.companyId!=null and record.companyId!='') ">
                and company_id = #{record.companyId}
            </if>
            <if test="(record.shopId!=null and record.shopId!='') ">
                and shop_id = #{record.shopId}
            </if>
        </if>
        <if test="pageVo !=null"><!-- 判断pageVo对象是否为空 -->
            <if test="pageVo.sort !=null  and pageVo.order !=null">
                order by
                ${pageVo.sort} ${pageVo.order}
            </if>
            <if test="pageVo.offset >=0  and pageVo.limit >0">
                limit
                #{pageVo.offset},#{pageVo.limit}
            </if>
        </if>
    </select>
 
    <!-- 查询总条数 -->
    <select id="selectTotalRecord" parameterType="long" resultType="java.lang.Integer">
        select count(*)
        from bus_parameter_settings
        where 1=1
        <if test="record!=null">
            <if test="(record.paramId!=null and record.paramId!='') or (record.paramId!='' and record.paramId==0)">
                and param_id = #{record.paramId}
            </if>
            <if test="(record.paramCode!=null and record.paramCode!='') or (record.paramCode!='' and record.paramCode==0)">
                and param_code = #{record.paramCode}
            </if>
            <if test="(record.paramValue!=null and record.paramValue!='') or (record.paramValue!='' and record.paramValue==0)">
                and param_value = #{record.paramValue}
            </if>
            <if test="(record.paramValue1!=null and record.paramValue1!='') or (record.paramValue1!='' and record.paramValue1==0)">
                and param_value1 = #{record.paramValue1}
            </if>
            <if test="(record.paramValue2!=null and record.paramValue2!='') or (record.paramValue2!='' and record.paramValue2==0)">
                and param_value2 = #{record.paramValue2}
            </if>
            <if test="(record.paramValue3!=null and record.paramValue3!='') or (record.paramValue3!='' and record.paramValue3==0)">
                and param_value3 = #{record.paramValue3}
            </if>
            <if test="(record.companyId!=null and record.companyId!='') ">
                and company_id = #{record.companyId}
            </if>
 
            <if test="(record.shopId!=null and record.shopId!='') ">
                and shop_id = #{record.shopId}
            </if>
        </if>
    </select>
 
    <!-- 根据id查询-->
    <select id="selectById" resultMap="BusParameterSettingsMap">
        select 
            param_id,
            param_code,
            param_value,
            param_value1,
            param_value2,
            param_value3,
            company_id,
            shop_id
        from bus_parameter_settings
        where  param_id=#{paramId} 
    </select>
 
 
    <!-- 根据id 锁表查询-->
    <select id="selectForUpdate" resultMap="BusParameterSettingsMap">
        select 
            param_id,
            param_code,
            param_value,
            param_value1,
            param_value2,
            param_value3,
            company_id,
            shop_id
        from bus_parameter_settings
        where  param_id=#{param_id} 
        for update
    </select>
 
 
    <!-- 根据对象查询-->
    <select id="selectByModel" resultMap="BusParameterSettingsMap">
        select
        param_id,
        param_code,
        param_value,
        param_value1,
        param_value2,
        param_value3,
        company_id,
        shop_id
        from bus_parameter_settings
        where 1=1
        <if test="record!=null">
            <if test="(record.paramId!=null and record.paramId!='') or (record.paramId!='' and record.paramId==0)">
                and param_id = #{record.paramId}
            </if>
            <if test="(record.paramCode!=null and record.paramCode!='') or (record.paramCode!='' and record.paramCode==0)">
                and param_code = #{record.paramCode}
            </if>
            <if test="(record.paramValue!=null and record.paramValue!='') or (record.paramValue!='' and record.paramValue==0)">
                and param_value = #{record.paramValue}
            </if>
            <if test="(record.paramValue1!=null and record.paramValue1!='') or (record.paramValue1!='' and record.paramValue1==0)">
                and param_value1 = #{record.paramValue1}
            </if>
            <if test="(record.paramValue2!=null and record.paramValue2!='') or (record.paramValue2!='' and record.paramValue2==0)">
                and param_value2 = #{record.paramValue2}
            </if>
            <if test="(record.paramValue3!=null and record.paramValue3!='') or (record.paramValue3!='' and record.paramValue3==0)">
                and param_value3 = #{record.paramValue3}
            </if>
            <if test="(record.companyId!=null and record.companyId!='') ">
                and company_id = #{record.companyId}
            </if>
 
            <if test="(record.shopId!=null and record.shopId!='') ">
                and shop_id = #{record.shopId}
            </if>
        </if>
    </select>
 
    <select id="selectByCodes" resultMap="BusParameterSettingsMap">
 
        select * from bus_parameter_settings where company_id=#{companyId} and  shop_id=#{shopId}
        and param_code in
        <foreach collection="list" index="index" item="item" open="("
                 separator="," close=")">
            #{item}
        </foreach>
    </select>
 
    <select id="selectByCodesAndCompanyId" resultMap="BusParameterSettingsMap">
 
        select * from bus_parameter_settings where company_id=#{companyId}
        and param_code in
        <foreach collection="list" index="index" item="item" open="("
                 separator="," close=")">
            #{item}
        </foreach>
    </select>
 
    <select id="selectByCode" resultMap="BusParameterSettingsMap">
         select * from bus_parameter_settings where
         param_code=#{code}
         and company_id=#{companyId} and  shop_id=#{shopId}
    </select>
    <select id="selectCompanyParamByCode" resultMap="BusParameterSettingsMap">
         select * from bus_parameter_settings where
         param_code=#{code}
         and company_id=#{companyId}
    </select>
</mapper>