CustomerActionStatisticsMapper.xml 15.7 KB
<?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="cn.com.glsx.openplatform.mapper.CustomerActionStatisticsMapper">
    <resultMap id="BaseResultMap" type="cn.com.glsx.openplatform.model.CustomerActionStatistics">
        <!--@mbg.generated-->
        <!--@Table t_customer_action_statistics-->
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="customer_id" jdbcType="INTEGER" property="customerId"/>
        <result column="customer_name" jdbcType="VARCHAR" property="customerName"/>
        <result column="device_type" jdbcType="VARCHAR" property="deviceType"/>
        <result column="type" jdbcType="VARCHAR" property="type"/>
        <result column="statistics_time" jdbcType="VARCHAR" property="statisticsTime"/>
        <result column="number" jdbcType="INTEGER" property="number"/>
    </resultMap>

    <sql id="Base_Column_List">
        <!--@mbg.generated-->
        id, customer_id, customer_name, device_type, `type`, statistics_time, number
    </sql>

    <select id="selectMonthList" resultType="java.lang.String">
        select distinct statistics_time
        from t_customer_action_statistics
    </select>

    <select id="selectByMonth" resultMap="BaseResultMap">
        select id, customer_id, customer_name, device_type, type, statistics_time, number
        from t_customer_action_statistics
        <where>
            <if test="month != null and month != ''">
                and statistics_time = #{month,jdbcType=VARCHAR}
            </if>
        </where>
    </select>

    <select id="selectOnlineNumber" resultType="java.lang.Integer">
        select sum(online_number)
        from t_customer_device_statistics_new_doing_copy2
        <where>
            <if test="customerId != null">
                and customer_id = #{customerId,jdbcType=INTEGER}
            </if>
            <if test="statisticsTime != null and statisticsTime != ''">
                and statistics_time = #{statisticsTime,jdbcType=VARCHAR}
            </if>
        </where>
        group by customer_id, statistics_time
    </select>

    <select id="selectByType" resultMap="BaseResultMap">
        select id, customer_id, customer_name, device_type, type, statistics_time, number
        from t_customer_action_statistics
        <where>
            <if test="type != null and type != ''">
                and type = #{type,jdbcType=VARCHAR}
            </if>
        </where>
    </select>

    <select id="selectDeviceList"
            resultType="cn.com.glsx.openplatform.model.PlatformDevice">
        select id, device_sn deviceSn, device_type deviceType
        from t_platform_device
        where customer_id = #{actionStatistics.customerId,jdbcType=INTEGER}
            and device_type = #{actionStatistics.deviceType,jdbcType=VARCHAR}
            and create_time &lt; #{endDate,jdbcType=TIMESTAMP}
        order by rand()
        limit #{count,jdbcType=INTEGER}
    </select>

    <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
        <!--@mbg.generated-->
        select
        <include refid="Base_Column_List"/>
        from t_customer_action_statistics
        where id = #{id,jdbcType=INTEGER}
    </select>

    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
        <!--@mbg.generated-->
        delete
        from t_customer_action_statistics
        where id = #{id,jdbcType=INTEGER}
    </delete>

    <insert id="insert" keyColumn="id" keyProperty="id"
            parameterType="cn.com.glsx.openplatform.model.CustomerActionStatistics"
            useGeneratedKeys="true">
        <!--@mbg.generated-->
        <selectKey order="AFTER" keyProperty="id" resultType="integer">
            select LAST_INSERT_ID()
        </selectKey>
        insert into t_customer_action_statistics (customer_id, customer_name, `type`,
        statistics_time, number)
        values (#{customerId,jdbcType=INTEGER}, #{customerName,jdbcType=VARCHAR},
        #{type,jdbcType=VARCHAR},
        #{statisticsTime,jdbcType=VARCHAR}, #{number,jdbcType=INTEGER})
    </insert>

    <insert id="insertSelective" keyColumn="id" keyProperty="id"
            parameterType="cn.com.glsx.openplatform.model.CustomerActionStatistics"
            useGeneratedKeys="true">
        <!--@mbg.generated-->
        <selectKey order="AFTER" keyProperty="id" resultType="integer">
            select LAST_INSERT_ID()
        </selectKey>
        insert into t_customer_action_statistics
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="customerId != null">
                customer_id,
            </if>
            <if test="customerName != null and customerName != ''">
                customer_name,
            </if>
            <if test="type != null and type != ''">
                `type`,
            </if>
            <if test="statisticsTime != null and statisticsTime != ''">
                statistics_time,
            </if>
            <if test="number != null">
                number,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="customerId != null">
                #{customerId,jdbcType=INTEGER},
            </if>
            <if test="customerName != null and customerName != ''">
                #{customerName,jdbcType=VARCHAR},
            </if>
            <if test="type != null and type != ''">
                #{type,jdbcType=VARCHAR},
            </if>
            <if test="statisticsTime != null and statisticsTime != ''">
                #{statisticsTime,jdbcType=VARCHAR},
            </if>
            <if test="number != null">
                #{number,jdbcType=INTEGER},
            </if>
        </trim>
    </insert>

    <update id="updateByPrimaryKeySelective"
            parameterType="cn.com.glsx.openplatform.model.CustomerActionStatistics">
        <!--@mbg.generated-->
        update t_customer_action_statistics
        <set>
            <if test="customerId != null">
                customer_id = #{customerId,jdbcType=INTEGER},
            </if>
            <if test="customerName != null and customerName != ''">
                customer_name = #{customerName,jdbcType=VARCHAR},
            </if>
            <if test="type != null and type != ''">
                `type` = #{type,jdbcType=VARCHAR},
            </if>
            <if test="statisticsTime != null and statisticsTime != ''">
                statistics_time = #{statisticsTime,jdbcType=VARCHAR},
            </if>
            <if test="number != null">
                number = #{number,jdbcType=INTEGER},
            </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>

    <update id="updateByPrimaryKey"
            parameterType="cn.com.glsx.openplatform.model.CustomerActionStatistics">
        <!--@mbg.generated-->
        update t_customer_action_statistics
        set customer_id = #{customerId,jdbcType=INTEGER},
        customer_name = #{customerName,jdbcType=VARCHAR},
        `type` = #{type,jdbcType=VARCHAR},
        statistics_time = #{statisticsTime,jdbcType=VARCHAR},
        number = #{number,jdbcType=INTEGER}
        where id = #{id,jdbcType=INTEGER}
    </update>

    <update id="updateBatch" parameterType="java.util.List">
        <!--@mbg.generated-->
        update t_customer_action_statistics
        <trim prefix="set" suffixOverrides=",">
            <trim prefix="customer_id = case" suffix="end,">
                <foreach collection="list" index="index" item="item">
                    when id = #{item.id,jdbcType=INTEGER} then #{item.customerId,jdbcType=INTEGER}
                </foreach>
            </trim>
            <trim prefix="customer_name = case" suffix="end,">
                <foreach collection="list" index="index" item="item">
                    when id = #{item.id,jdbcType=INTEGER} then #{item.customerName,jdbcType=VARCHAR}
                </foreach>
            </trim>
            <trim prefix="`type` = case" suffix="end,">
                <foreach collection="list" index="index" item="item">
                    when id = #{item.id,jdbcType=INTEGER} then #{item.type,jdbcType=VARCHAR}
                </foreach>
            </trim>
            <trim prefix="statistics_time = case" suffix="end,">
                <foreach collection="list" index="index" item="item">
                    when id = #{item.id,jdbcType=INTEGER}
                            then #{item.statisticsTime,jdbcType=VARCHAR}
                </foreach>
            </trim>
            <trim prefix="number = case" suffix="end,">
                <foreach collection="list" index="index" item="item">
                    when id = #{item.id,jdbcType=INTEGER} then #{item.number,jdbcType=INTEGER}
                </foreach>
            </trim>
        </trim>
        where id in
        <foreach close=")" collection="list" item="item" open="(" separator=", ">
            #{item.id,jdbcType=INTEGER}
        </foreach>
    </update>

    <update id="updateBatchSelective" parameterType="java.util.List">
        <!--@mbg.generated-->
        update t_customer_action_statistics
        <trim prefix="set" suffixOverrides=",">
            <trim prefix="customer_id = case" suffix="end,">
                <foreach collection="list" index="index" item="item">
                    <if test="item.customerId != null">
                        when id = #{item.id,jdbcType=INTEGER}
                                then #{item.customerId,jdbcType=INTEGER}
                    </if>
                </foreach>
            </trim>
            <trim prefix="customer_name = case" suffix="end,">
                <foreach collection="list" index="index" item="item">
                    <if test="item.customerName != null">
                        when id = #{item.id,jdbcType=INTEGER}
                                then #{item.customerName,jdbcType=VARCHAR}
                    </if>
                </foreach>
            </trim>
            <trim prefix="`type` = case" suffix="end,">
                <foreach collection="list" index="index" item="item">
                    <if test="item.type != null">
                        when id = #{item.id,jdbcType=INTEGER} then #{item.type,jdbcType=VARCHAR}
                    </if>
                </foreach>
            </trim>
            <trim prefix="statistics_time = case" suffix="end,">
                <foreach collection="list" index="index" item="item">
                    <if test="item.statisticsTime != null">
                        when id = #{item.id,jdbcType=INTEGER}
                                then #{item.statisticsTime,jdbcType=VARCHAR}
                    </if>
                </foreach>
            </trim>
            <trim prefix="number = case" suffix="end,">
                <foreach collection="list" index="index" item="item">
                    <if test="item.number != null">
                        when id = #{item.id,jdbcType=INTEGER}
                        then #{item.number,jdbcType=INTEGER}
                    </if>
                </foreach>
            </trim>
        </trim>
        where id in
        <foreach close=")" collection="list" item="item" open="(" separator=", ">
            #{item.id,jdbcType=INTEGER}
        </foreach>
    </update>

    <insert id="batchInsert" keyColumn="id" keyProperty="id" parameterType="map"
            useGeneratedKeys="true">
        <!--@mbg.generated-->
        insert into t_customer_action_statistics
                (customer_id, customer_name, `type`, statistics_time, number)
                values
        <foreach collection="list" item="item" separator=",">
            (#{item.customerId,jdbcType=INTEGER}, #{item.customerName,jdbcType=VARCHAR},
            #{item.type,jdbcType=VARCHAR},
            #{item.statisticsTime,jdbcType=VARCHAR}, #{item.number,jdbcType=INTEGER})
        </foreach>
    </insert>

    <insert id="insertOrUpdate" keyColumn="id" keyProperty="id"
            parameterType="cn.com.glsx.openplatform.model.CustomerActionStatistics"
            useGeneratedKeys="true">
        <!--@mbg.generated-->
        insert into t_customer_action_statistics
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            customer_id,
            customer_name,
            `type`,
            statistics_time,
            number,
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id,jdbcType=INTEGER},
            </if>
            #{customerId,jdbcType=INTEGER},
            #{customerName,jdbcType=VARCHAR},
            #{type,jdbcType=VARCHAR},
            #{statisticsTime,jdbcType=VARCHAR},
            #{number,jdbcType=INTEGER},
        </trim>
        on duplicate key update
        <trim suffixOverrides=",">
            <if test="id != null">
                id = #{id,jdbcType=INTEGER},
            </if>
            customer_id = #{customerId,jdbcType=INTEGER},
            customer_name = #{customerName,jdbcType=VARCHAR},
            `type` = #{type,jdbcType=VARCHAR},
            statistics_time = #{statisticsTime,jdbcType=VARCHAR},
            number = #{number,jdbcType=INTEGER},
        </trim>
    </insert>

    <insert id="insertOrUpdateSelective" keyColumn="id" keyProperty="id"
            parameterType="cn.com.glsx.openplatform.model.CustomerActionStatistics"
            useGeneratedKeys="true">
        <!--@mbg.generated-->
        insert into t_customer_action_statistics
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="customerId != null">
                customer_id,
            </if>
            <if test="customerName != null and customerName != ''">
                customer_name,
            </if>
            <if test="type != null and type != ''">
                `type`,
            </if>
            <if test="statisticsTime != null and statisticsTime != ''">
                statistics_time,
            </if>
            <if test="number != null">
                number,
            </if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id,jdbcType=INTEGER},
            </if>
            <if test="customerId != null">
                #{customerId,jdbcType=INTEGER},
            </if>
            <if test="customerName != null and customerName != ''">
                #{customerName,jdbcType=VARCHAR},
            </if>
            <if test="type != null and type != ''">
                #{type,jdbcType=VARCHAR},
            </if>
            <if test="statisticsTime != null and statisticsTime != ''">
                #{statisticsTime,jdbcType=VARCHAR},
            </if>
            <if test="number != null">
                #{number,jdbcType=INTEGER},
            </if>
        </trim>
        on duplicate key update
        <trim suffixOverrides=",">
            <if test="id != null">
                id = #{id,jdbcType=INTEGER},
            </if>
            <if test="customerId != null">
                customer_id = #{customerId,jdbcType=INTEGER},
            </if>
            <if test="customerName != null and customerName != ''">
                customer_name = #{customerName,jdbcType=VARCHAR},
            </if>
            <if test="type != null and type != ''">
                `type` = #{type,jdbcType=VARCHAR},
            </if>
            <if test="statisticsTime != null and statisticsTime != ''">
                statistics_time = #{statisticsTime,jdbcType=VARCHAR},
            </if>
            <if test="number != null">
                number = #{number,jdbcType=INTEGER},
            </if>
        </trim>
    </insert>
</mapper>