<?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.ho.filecenter.mapper.FlowMonitorMapper">

    <resultMap id="BaseResultMap" type="com.ho.filecenter.entity.FlowMonitor">
            <id property="id" column="id" jdbcType="INTEGER"/>
            <result property="groupId" column="group_id" jdbcType="VARCHAR"/>
            <result property="packageName" column="package_name" jdbcType="VARCHAR"/>
            <result property="packageType" column="package_type" jdbcType="INTEGER"/>
            <result property="singleOrGroup" column="single_or_group" jdbcType="INTEGER"/>
            <result property="totalFlow" column="total_flow" jdbcType="INTEGER"/>
            <result property="deleted" column="deleted" jdbcType="INTEGER"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,group_id,package_name,
        package_type,single_or_group,total_flow,
        deleted
    </sql>
    <delete id="deleteByPrimaryKey">
        delete
        from flow_monitor
        where id = #{id,jdbcType=INTEGER}
    </delete>

    <select id="selectAll" resultType="com.ho.filecenter.entity.FlowMonitor">
        SELECT
        <include refid="Base_Column_List"/>
        FROM flow_monitor
        <where>
            <if test="packageName != null and packageName != ''">
                and package_name LIKE concat('%',#{packageName},'%')
            </if>
            <if test="packageType != null">
                and package_type = #{packageType}
            </if>
            and deleted =1
        </where>
    </select>

    <select id="selectById" resultType="com.ho.filecenter.entity.FlowMonitor">
        select
        <include refid="Base_Column_List"/>
        from flow_monitor
        where id = #{flowMonitorId}
    </select>

    <select id="selectByPid" resultType="com.ho.filecenter.entity.FlowMonitor">
        select
        <include refid="Base_Column_List"/>
        from flow_monitor
        where group_id = #{groupId}
    </select>

    <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.ho.filecenter.entity.FlowMonitor"
            useGeneratedKeys="true">
        insert into flow_monitor
            (id, package_name, package_type, deleted)
        values (#{id}, #{packageName}, #{packageType}, #{deleted})
    </insert>
    <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.ho.filecenter.entity.FlowMonitor"
            useGeneratedKeys="true">
        insert into flow_monitor
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="groupId != null">group_id,</if>
            <if test="packageType != null">package_type,</if>
            <if test="packageName != null">package_name,</if>
            <if test="singleOrGroup != null">single_or_group,</if>
            <if test="totalFlow != null">total_flow,</if>
            <if test="deleted != null">deleted</if>

        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="groupId != null">#{groupId},</if>
            <if test="packageType != null">#{packageType},</if>
            <if test="packageName != null">#{packageName},</if>
            <if test="singleOrGroup != null">#{singleOrGroup},</if>
            <if test="totalFlow != null">#{totalFlow},</if>
            <if test="deleted != null">#{deleted}</if>
        </trim>
    </insert>

    <update id="updateByPrimaryKeySelective" parameterType="com.ho.filecenter.entity.FlowMonitor">
        update flow_monitor
        <set>
            <if test="groupId != null">
                group_id = #{groupId},
            </if>
            <if test="packageName != null">
                package_name = #{packageName},
            </if>
            <if test="packageType != null">
                package_type = #{packageType},
            </if>
            <if test="singleOrGroup != null">
                single_or_group = #{singleOrGroup},
            </if>
            <if test="totalFlow != null">
                total_flow = #{totalFlow},
            </if>
            <if test="deleted != null">
                deleted = #{deleted}
            </if>
        </set>
        where id = #{id}
    </update>

    <update id="updateByPrimaryKey" parameterType="com.ho.filecenter.entity.FlowMonitor">
        update flow_monitor
        set package_name = #{packageName},
            package_type = #{packageType},
            deleted      = #{deleted}
        where id = #{id,jdbcType=INTEGER}
    </update>
</mapper>
