puzhibing
2023-02-15 2811bab657aab4145b65a45a824fb63e93b58e30
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
<?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.stylefeng.guns.modular.system.dao.UserActivityMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.stylefeng.guns.modular.system.model.UserActivity">
        <id column="id" property="id" />
        <result column="name" property="name" />
        <result column="startTime" property="startTime" />
        <result column="endTime" property="endTime" />
        <result column="insertTime" property="insertTime" />
        <result column="status" property="status" />
        <result column="remark" property="remark" />
        <result column="companyType" property="companyType" />
    </resultMap>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, name, startTime, endTime, insertTime, status, remark, companyType
    </sql>
 
 
 
    <select id="queryUserActivityList" resultType="map">
        select
        a.id as id,
        a.insertTime as insertTime,
        a.`name` as `name`,
        a.startTime as startTime,
        a.endTime as endTime,
        a.remark as remark,
        a.`status` as `status`,
        (
        (select count(aa.id) from t_user_red_packet_record aa left join t_user_activity_redenvelope bb on (aa.redPacketActivityId = bb.id) where aa.state = 2 and bb.userActivityId = a.id) +
        (select count(aa.id) from t_user_coupon_record aa left join t_user_activity_registered bb on (aa.couponActivityId = bb.id and aa.activityType = 2) where aa.state = 2 and bb.userActivityId = a.id) +
        (select count(aa.id) from t_user_coupon_record aa left join t_user_activity_invite bb on (aa.couponActivityId = bb.id and aa.activityType = 3) where aa.state = 2 and bb.userActivityId = a.id) +
        (select count(aa.id) from t_user_coupon_record aa left join t_user_activity_balance bb on (aa.couponActivityId = bb.id and aa.activityType = 4) where aa.state = 2 and bb.userActivityId = a.id) +
        (select count(id) from t_order_private_car where state in (7,8,9) and activityId = a.id) +
        (select count(id) from t_order_taxi where state in (7,8,9) and activityId = a.id) +
        (select count(id) from t_order_cross_city where state in (6,8,9) and activityId = a.id)
        ) as number
        from t_user_activity a
        where a.companyId = #{companyId}
        <if test="null != start and null != end">
            and a.insertTime between #{start} and #{end}
        </if>
        <if test="null != name and '' != name">
            and a.`name` like CONCAT('%', #{name}, '%')
        </if>
        <if test="null != status">
            and a.`status` = #{status}
        </if>
        order by a.insertTime desc
        <if test="null != offset and null != limit">
            limit #{offset}, #{limit}
        </if>
    </select>
 
 
    <select id="queryUserActivityListCount" resultType="int">
        select
        count(a.id)
        from t_user_activity a
        where a.companyId = #{companyId}
        <if test="null != start and null != end">
            and a.insertTime between #{start} and #{end}
        </if>
        <if test="null != name and '' != name">
            and a.`name` like CONCAT('%', #{name}, '%')
        </if>
        <if test="null != status">
            and a.`status` = #{status}
        </if>
    </select>
</mapper>