CustomerMapper.xml 5.31 KB
Newer Older
张新旗 committed
1 2 3 4
<?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">
5
<mapper namespace="com.soss.system.mapper.CustomerMapper">
张新旗 committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
    
    <resultMap type="Customer" id="CustomerResult">
        <result property="id"    column="id"    />
        <result property="userName"    column="user_name"    />
        <result property="phone"    column="phone"    />
        <result property="createTime"    column="create_time"    />
        <result property="headSculpturePath"    column="head_sculpture_path"    />
        <result property="soucre"    column="soucre"    />
    </resultMap>

    <sql id="selectCustomerVo">
        select id, user_name, phone, create_time, head_sculpture_path, soucre from customer
    </sql>

    <select id="selectCustomerList" parameterType="Customer" resultMap="CustomerResult">
        <include refid="selectCustomerVo"/>
        <where>  
            <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
            <if test="phone != null  and phone != ''"> and phone = #{phone}</if>
            <if test="headSculpturePath != null  and headSculpturePath != ''"> and head_sculpture_path = #{headSculpturePath}</if>
            <if test="soucre != null  and soucre != ''"> and soucre = #{soucre}</if>
        </where>
    </select>
    
30
    <select id="selectCustomerById"  resultMap="CustomerResult">
张新旗 committed
31 32 33 34 35 36 37
        <include refid="selectCustomerVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertCustomer" parameterType="Customer" useGeneratedKeys="true" keyProperty="id">
        insert into customer
        <trim prefix="(" suffix=")" suffixOverrides=",">
38
            <if test="id != null">id,</if>
张新旗 committed
39 40 41 42 43 44 45
            <if test="userName != null">user_name,</if>
            <if test="phone != null">phone,</if>
            <if test="createTime != null">create_time,</if>
            <if test="headSculpturePath != null">head_sculpture_path,</if>
            <if test="soucre != null">soucre,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
46
            <if test="id != null">#{id},</if>
张新旗 committed
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
            <if test="userName != null">#{userName},</if>
            <if test="phone != null">#{phone},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="headSculpturePath != null">#{headSculpturePath},</if>
            <if test="soucre != null">#{soucre},</if>
         </trim>
    </insert>

    <update id="updateCustomer" parameterType="Customer">
        update customer
        <trim prefix="SET" suffixOverrides=",">
            <if test="userName != null">user_name = #{userName},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="headSculpturePath != null">head_sculpture_path = #{headSculpturePath},</if>
            <if test="soucre != null">soucre = #{soucre},</if>
张新旗 committed
62
            <if test="allow != null">allow = #{soucre},</if>
张新旗 committed
63 64 65 66 67 68 69 70 71 72 73 74 75 76
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCustomerById" parameterType="Long">
        delete from customer where id = #{id}
    </delete>

    <delete id="deleteCustomerByIds" parameterType="String">
        delete from customer where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
张新旗 committed
77 78
    <select id="selectCustomerByQuery" resultType="com.soss.system.domain.vo.customer.CustomerResultVo">
        select * from (select
张新旗 committed
79
        c.id ,
张新旗 committed
80 81 82 83 84 85 86 87 88 89
        c.user_name as userName,
        c.phone as phoneNumber,
        (select count(*) from `order` o where o.user_id = c.id) as orderCount,
        (select sum(o.amount) from `order` o where o.user_id = c.id) as amount,
        (select count(*) from `order` o where o.user_id = c.id and o.state in ('8','9','10','11')) as cancelCount,
        (select sum(o.amount) from `order` o where o.user_id = c.id and o.state in ('8','9','10','11')) as cancelAmount,
        (select count(*) from `order` o where o.user_id = c.id and o.state in ('12','14','15')) as refundCount,
        (select sum(o.amount) from `order` o where o.user_id = c.id and o.state in ('12','14','15')) as refundAmount,
        (select o.created_at  from `order` o where o.user_id = c.id order by o.created_at desc limit 1) as lastOrderDate,
        c.create_time as createDate,
张新旗 committed
90
        c.soucre as source
张新旗 committed
91 92 93 94
        from
        customer c ) a
        <where>
            <if test="userInfo != null and userInfo != ''">
张新旗 committed
95
                and ((a.userName like concat('%', #{userInfo}, '%')) or (a.phoneNumber like concat('%', #{userInfo}, '%') ))
张新旗 committed
96 97 98
            </if>
            <if test="buyRecords != null and buyRecords != ''">
                and
张新旗 committed
99
                <if test='buyRecords == "1"'>
张新旗 committed
100 101
                    a.orderCount >0
                </if>
张新旗 committed
102
                <if test='buyRecords == "2"'>
张新旗 committed
103 104
                    a.orderCount =0
                </if>
张新旗 committed
105
                <if test='buyRecords == "3"'>
张新旗 committed
106 107 108 109 110 111 112 113 114 115 116 117 118
                    a.orderCount >1
                </if>
            </if>
            <if test="createAtStart !='' and createAtStart!=null">
                and createDate &gt;=#{createAtStart}

            </if>
            <if test="createAtEnd !='' and createAtEnd!=null">
                and createDate &lt;=#{createAtEnd}

            </if>
        </where>
    </select>
张新旗 committed
119
</mapper>