Helius
2022-05-27 4351e71d782741143a98f86f6648acd16689165f
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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
<?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.shopXcx.dao.ShopActivitiesDao">
    <!-- 定义ShopActivities 的复杂关联map -->
    <resultMap type="com.matrix.system.shopXcx.bean.ShopActivities" id="ShopActivitiesMap">
        <id property="id" column="id" />
            <result property="actName" column="act_name" />
            <result property="actCode" column="act_code" />
            <result property="actType" column="act_type" />
            <result property="actBeginTime" column="act_begin_time" />
            <result property="actEndTime" column="act_end_time" />
            <result property="createBy" column="create_by" />
            <result property="actStatus" column="act_status" />
            <result property="shopIds" column="shop_ids" />
            <result property="actRemark" column="act_remark" />
            <result property="actMax" column="act_max" />
        <result property="remainTime" column="remainTime" />
        <result property="isStart" column="isStart" />
        <result property="title" column="title" />
        <result property="actImg" column="act_img" />
        <result property="actContent" column="act_content" />
        <result property="companyId" column="company_id" />
        <association property="groupInfo" javaType="com.matrix.system.shopXcx.bean.ShopActivitiesGroupInfo" column="act_id">
            <id property="id" column="giId"/>
            <result property="goodsId" column="goods_id" />
            <result property="goodsName" column="goods_name" />
            <result property="giType" column="gi_type" />
            <result property="giHeadDiscount" column="gi_head_discount" />
            <result property="giLimitBuy" column="gi_limit_buy" />
            <result property="giVirtualGroup" column="gi_virtual_group" />
        </association>
        <association property="salonRecord" javaType="com.matrix.system.shopXcx.bean.ShopActivitiesSalonRecord" column="act_id">
            <id property="id" column="asr_id" />
            <result property="status" column="status" />
            <result property="remark" column="remark" />
            <result property="shopId" column="shop_id" />
        </association>
        <collection property="attributes" ofType="com.matrix.system.shopXcx.bean.ShopActivitiesSalonDistribute" column="act_id">
            <id property="id" column="sd_id" />
            <result property="attrName" column="attr_name" />
        </collection>
    </resultMap>
    
    
    <!-- 定义ShopActivities 的简单map  ,本map不添加其他的关联属性 -->
    <resultMap type="com.matrix.system.shopXcx.bean.ShopActivities" id="ShopActivitiesSimpleMap">
        <id property="id" column="id" />
            <result property="actName" column="act_name" />
            <result property="actCode" column="act_code" />
            <result property="actType" column="act_type" />
            <result property="actBeginTime" column="act_begin_time" />
            <result property="actEndTime" column="act_end_time" />
            <result property="createBy" column="create_by" />
            <result property="actStatus" column="act_status" />
            <result property="shopIds" column="shop_ids" />
            <result property="actRemark" column="act_remark" />
            <result property="actMax" column="act_max" />
    </resultMap>
    
    <!-- 字段sql -->
    <sql id="columns">
        create_by,
        create_time,
        update_by,
        update_time,
            id,
            act_name,
            act_code,
            act_type,
            act_begin_time,
            act_end_time,
            act_status,
            shop_ids,
            act_remark,
            act_max,
            act_img,
            act_content,
            company_id
    </sql>
    
    <!-- 属性sql -->
    <sql id="propertys">
        #{item.createBy},
        now(),
        #{item.updateBy},
        now(),
            #{item.id},
            #{item.actName},
            #{item.actCode},
            #{item.actType},
            #{item.actBeginTime},
            #{item.actEndTime},
            #{item.actStatus},
            #{item.shopIds},
            #{item.actRemark},
            #{item.actMax},
            #{item.actImg},
            #{item.actContent},
            #{item.companyId}
    </sql>
    
    <!-- where sql -->
    <sql id="where_sql">
         
         <if test="record!=null">
            <if test="(record.id!=null and record.id!='') or  (record.id!='' and record.id==0)  ">
                and id  = #{record.id} 
            </if>
             <if test="(record.companyId!=null and record.companyId!='') or  (record.companyId!='' and record.companyId==0)  ">
                 and company_id  = #{record.companyId}
             </if>
            <if test="(record.actName!=null and record.actName!='') or  (record.actName!='' and record.actName==0)  ">
                and act_name  like  CONCAT(CONCAT('%',#{record.actName}),'%')
            </if>
            <if test="(record.actType!=null and record.actType!='') or  (record.actType!='' and record.actType==0)  ">
                and act_type  = #{record.actType} 
            </if>
            <if test="record.beginTime!=null and record.beginTime!=''  ">
                and DATE_FORMAT(act_begin_time,'%Y-%m-%d %H:%i:%s')  >= DATE_FORMAT(#{record.beginTime} ,'%Y-%m-%d %H:%i:%s')
            </if>
            <if test="record.endTime!=null and record.endTime!='' ">
                and DATE_FORMAT(#{record.endTime} ,'%Y-%m-%d %H:%i:%s') >= DATE_FORMAT(act_end_time,'%Y-%m-%d %H:%i:%s')
            </if>
            <if test="(record.createBy!=null and record.createBy!='') or  (record.createBy!='' and record.createBy==0)  ">
                and create_by  = #{record.createBy} 
            </if>
            <if test="(record.actStatus!=null and record.actStatus!='') or  (record.actStatus!='' and record.actStatus==0)  ">
                and act_status  = #{record.actStatus} 
            </if>
            <if test="(record.shopIds!=null and record.shopIds!='') or  (record.shopIds!='' and record.shopIds==0)  ">
                and find_in_set(#{record.shopIds}, shop_ids)
            </if>
            <if test="(record.actRemark!=null and record.actRemark!='') or  (record.actRemark!='' and record.actRemark==0)  ">
                and act_remark  = #{record.actRemark} 
            </if>
            <if test="(record.actMax!=null and record.actMax!='') or  (record.actMax!='' and record.actMax==0)  ">
                and act_max  = #{record.actMax} 
            </if>
        </if>
         
    </sql>
    
    <!--  插入方法   -->
    <insert id="insert" parameterType="com.matrix.system.shopXcx.bean.ShopActivities"
        useGeneratedKeys="true" keyProperty="item.id">
        INSERT INTO shop_activities (
             <include refid="columns"></include>
        )
    VALUES (
         <include refid="propertys"></include>
    )
    </insert>
    
    
    
    <!--  批量插入   -->
    <insert id="batchInsert" parameterType="java.util.List">
        INSERT INTO shop_activities (
        <include refid="columns"></include>    
        )
    VALUES 
    <foreach collection="list" item="item" index="index" separator=",">(
        <include refid="propertys"></include>    
    )</foreach>
    </insert>
    
    
    
    
    
    <!--  根据Map更新 部分更新   -->
    <update id="updateByMap" parameterType="java.util.HashMap" >
        UPDATE shop_activities
        <set>
            <if test="_parameter.containsKey('actName')">
                    act_name = #{actName},
                </if>        
            <if test="_parameter.containsKey('actType')">
                    act_type = #{actType},
                </if>        
            <if test="_parameter.containsKey('actBeginTime')">
                    act_begin_time = #{actBeginTime},
                </if>        
            <if test="_parameter.containsKey('actEndTime')">
                    act_end_time = #{actEndTime},
                </if>        
            <if test="_parameter.containsKey('createBy')">
                    create_by = #{createBy},
                </if>        
            <if test="_parameter.containsKey('actStatus')">
                    act_status = #{actStatus},
                </if>        
            <if test="_parameter.containsKey('shopIds')">
                    shop_ids = #{shopIds},
                </if>        
            <if test="_parameter.containsKey('actRemark')">
                    act_remark = #{actRemark},
                </if>        
            <if test="_parameter.containsKey('actMax')">
                    act_max = #{actMax},
                </if>        
        </set>
        WHERE id=#{id} 
    </update> 
    
    
    <!--  根据对象更新 部分更新   -->
    <update id="updateByModel" parameterType="Long">
        UPDATE shop_activities
        <set>
            <if test="record.actName != null and record.actName != '' ">
                act_name  = #{record.actName},
            </if>
            <if test="record.actCode != null ">
                act_code  = #{record.actCode},
            </if>
 
            <if test="record.actContent != null ">
                act_content  = #{record.actContent},
            </if>
            <if test="record.actType != null ">
                act_type  = #{record.actType}, 
            </if>
            <if test="record.actBeginTime != null ">
                act_begin_time  = #{record.actBeginTime}, 
            </if>
            <if test="record.actEndTime != null ">
                act_end_time  = #{record.actEndTime}, 
            </if>
            <if test="record.createBy != null and record.createBy != '' ">
                create_by  = #{record.createBy}, 
            </if>
            <if test="record.actStatus != null ">
                act_status  = #{record.actStatus}, 
            </if>
            <if test="record.shopIds != null and record.shopIds != '' ">
                shop_ids  = #{record.shopIds}, 
            </if>
            <if test="record.actRemark != null and record.actRemark != '' ">
                act_remark  = #{record.actRemark}, 
            </if>
            <if test="record.actMax != null ">
                act_max  = #{record.actMax}, 
            </if>
        </set>
        WHERE id=#{record.id} 
    </update>
    
    <!-- 批量删除 -->
    <delete id="deleteByIds" parameterType="java.util.List">
        delete from shop_activities where  id in
        <foreach collection="list" index="index" item="item" open="("
            separator="," close=")">
            #{item}
        </foreach>
    </delete>
        
    <!-- 根据id删除-->
    <delete id="deleteById" parameterType="Long">
        DELETE FROM shop_activities
        where  id=#{id} 
    </delete>
    
    <!-- 根据对象删除-->
    <delete id="deleteByModel" parameterType="com.matrix.system.shopXcx.bean.ShopActivities">
        DELETE FROM shop_activities
        <where>
        <include refid="where_sql" ></include>
        </where>
    </delete>
    
    
    
    <!-- 分页查询 -->
    <select id="selectInPage" resultMap="ShopActivitiesMap">
        select 
        <include refid="columns" ></include>
        from shop_activities
        <where>
          <include refid="where_sql"></include>
         </where>
        <if test="pageVo !=null"><!-- 判断pageVo对象是否为空 -->
            order by create_time desc
            <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 shop_activities
        <where>
           <include refid="where_sql"></include>
        </where>
    </select>
 
    <!-- 根据id查询-->
    <select id="selectById" resultMap="ShopActivitiesMap">
        select *,
               if(now()>act_begin_time, 1, 2) isStart,
            TIMESTAMPDIFF(SECOND, now(), act_end_time) remainTime
        from shop_activities
        where  id=#{id} 
    </select>    
    
    
    <!-- 根据id 锁表查询-->
    <select id="selectForUpdate" resultMap="ShopActivitiesMap">
        select 
        <include refid="columns" ></include>
        from shop_activities
        where  id=#{id} 
        for update
    </select>    
    
    
    
    <!-- 根据对象查询-->
    <select id="selectByModel" resultMap="ShopActivitiesMap">
        select 
        <include refid="columns" ></include>
        from shop_activities
        <where>
          <include refid="where_sql"></include>
         </where>
    </select>
 
    <select id="selectShopActivitiesById" resultMap="ShopActivitiesMap">
        select
            t1.*,
            t2.id giId,
            t2.goods_id,
            t3.title goods_name,
            t2.gi_type,
            t2.gi_head_discount,
            t2.gi_limit_buy,
            t2.gi_virtual_group
        from shop_activities t1
        inner join shop_activities_group_info t2 on t1.id=t2.act_id
        left join shop_product t3 on t2.goods_id=t3.id
        where t1.id=#{id}
    </select>
 
 
    <select id="selectShopActivitiesHasEnd" resultMap="ShopActivitiesMap">
        select
            t1.*,
            t2.id giId,
            t2.goods_id,
            t2.gi_type,
            t2.gi_head_discount,
            t2.gi_virtual_group
        from shop_activities t1
        inner join shop_activities_group_info t2 on t1.id=t2.act_id
        where now() >= t1.act_end_time and act_status=1
    </select>
 
    <update id="batchUpdateActStatus">
        <foreach collection="list" index="index" item="item" separator=";">
            update shop_activities set act_status=#{status}
            where id=#{item.id}
        </foreach>
    </update>
 
    <select id="selectSecKillActivitiesForIng" resultMap="ShopActivitiesMap">
        select
            *,
            if(now()>act_begin_time, 1, 2) isStart,
            TIMESTAMPDIFF(SECOND, now(), act_end_time) remainTime,
            act_begin_time title
        from shop_activities
        where act_type=2 and act_end_time > now() and find_in_set(#{shopId}, shop_ids) and act_status = 1
    </select>
 
    <select id="selectSalonActivityById" resultMap="ShopActivitiesMap">
        select t1.*, t2.id sd_id, t2.attr_name
        from shop_activities t1
        inner join shop_activities_salon_distribute t2 on t1.id=t2.act_id
        where t1.id= #{id}
    </select>
 
    <select id="selectSalonActivityByUser" resultMap="ShopActivitiesMap">
        select t1.*, t2.id asr_id,t2.user_id,t2.shop_id,t2.remark,t2.status
        from shop_activities t1
        inner join shop_activities_salon_record t2 on t1.id=t2.act_id
        where t2.user_id=#{record.userId}
        <if test="record!=null">
            order by t1.create_time desc
            <if test="record.offset >=0  and record.limit >0">
                limit
                #{record.offset},#{record.limit}
            </if>
        </if>
    </select>
 
    <select id="findActivitiesList" resultType="com.matrix.system.activity.vo.ActivitiesListVo">
        SELECT
            *
        FROM
        shop_activities a
        <where>
            a.company_id=#{record.companyId}
            <if test="record.hdzt != null and record.hdzt != ''">
                and a.act_status=#{record.hdzt}
            </if>
            <if test="record.hdmc != null and record.hdmc != ''">
                and a.act_name like concat('%',#{record.hdmc},'%')
            </if>
        </where>
        <if test="record.sort !=null">
            order by
            a.${record.sort} ${record.order}
        </if>
    </select>
 
    <select id="selectOneByCompanyIdAndActTypeAndActStatus" resultType="com.matrix.system.shopXcx.bean.ShopActivities">
        SELECT
        *
        FROM
        shop_activities a
        where
            a.company_id=#{companyId}
            and a.act_type=#{activitiesTypeSign}
            and a.act_status=#{actstatusStatusIng}
    </select>
 
    <select id="selectOneByCompanyIdAndActType" resultType="com.matrix.system.shopXcx.bean.ShopActivities">
        SELECT
            *
        FROM
            shop_activities a
        where
            a.company_id=#{companyId}
          and a.act_type=#{activitiesTypeSign}
          and a.act_status != 5
    </select>
</mapper>