<?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.CardInfoMapper">


    <resultMap id="BaseResultMap" type="com.ho.filecenter.entity.CardInfo">
        <id property="id" column="id" jdbcType="INTEGER"/>
        <result property="card" column="card" jdbcType="VARCHAR"/>
        <result property="flowMonitorId" column="flow_monitor_id" jdbcType="INTEGER"/>
        <result property="stationId" column="station_id" jdbcType="INTEGER"/>
        <result property="packageType" column="package_type" jdbcType="INTEGER"/>
        <result property="cardStatus" column="card_status" jdbcType="INTEGER"/>
        <result property="openDate" column="open_date" jdbcType="VARCHAR"/>
        <result property="activationDate" column="activation_date" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        id
        ,card,flow_monitor_id,
        station_id,package_type,card_status,
        open_date,activation_date
    </sql>

    <delete id="deleteByPrimaryKey">
        delete
        from card_info
        where id = #{id,jdbcType=INTEGER}
    </delete>

    <select id="selectByFlowId" resultType="com.ho.filecenter.entity.CardInfo">
        select
        <include refid="Base_Column_List"/>
        from card_info
        where flow_monitor_id = #{id}
    </select>
    <select id="selectByCondition" resultType="com.ho.filecenter.entity.CardInfo">
        SELECT
        <include refid="Base_Column_List"/>
        from `card_info`
        <where>
            <if test="flowMonitorId != null ">
                flow_monitor_id = #{flowMonitorId}
            </if>
            <if test="stationId != null ">
                station_id = #{stationId}
            </if>
            <if test="card != null">
                and card = #{card}
            </if>
            <if test="packageType != null">
                and package_type= # {packageType}
            </if>
        </where>
    </select>

    <select id="selectByCardTotal" resultType="java.lang.Integer">
        select count(*)
        from card_info
        where flow_monitor_id = #{flowMonitorId}
    </select>

    <select id="selectByFlowCardList" resultType="com.ho.filecenter.entity.CardInfo">
        select
        <include refid="Base_Column_List"/>
        from card_info
        where flow_monitor_id = #{flowMonitorId}
        LIMIT #{offset}, #{pageSize}
    </select>

    <select id="selectAll" resultType="com.ho.filecenter.entity.CardInfo">
        select
        <include refid="Base_Column_List"/>
        from card_info
        <if test="card != null">
            card = #{card},
        </if>
        <if test="packageType != null">
            package_type = #{packageType},
        </if>
        <if test="flowMonitorId != null">
            flow_monitor_id = #{flowMonitorId},
        </if>
        <if test="stationId != null">
            station_id = #{stationId},
        </if>
    </select>

    <select id="selectById" resultType="com.ho.filecenter.entity.CardInfo">
        select
        <include refid="Base_Column_List"/>
        from card_info
        where id = #{id}
    </select>
    <select id="selectByCard" resultType="com.ho.filecenter.entity.CardInfo">
        select
        <include refid="Base_Column_List"/>
        from card_info
        where card = #{card}
    </select>

    <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.ho.filecenter.entity.CardInfo"
            useGeneratedKeys="true">
        insert into card_info
        (id, card, flow_monitor_id, station_id,
         package_type, card_status)
        values ( #{id}, #{card}, #{flowMonitorId}, #{stationId}
               , #{packageType}, #{cardStatus})
    </insert>
    <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.ho.filecenter.entity.CardInfo"
            useGeneratedKeys="true">
        insert into card_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="card != null">card,</if>
            <if test="flowMonitorId != null">flow_monitor_id,</if>
            <if test="stationId != null">station_id,</if>
            <if test="packageType != null">package_type,</if>
            <if test="cardStatus != null">card_status,</if>
            <if test="openDate != null">open_date,</if>
            <if test="activationDate != null">activation_date</if>

        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="card != null">#{card},</if>
            <if test="flowMonitorId != null">#{flowMonitorId},</if>
            <if test="stationId != null">#{stationId},</if>
            <if test="packageType != null">#{packageType},</if>
            <if test="cardStatus != null">#{cardStatus},</if>
            <if test="openDate != null">#{openDate},</if>
            <if test="activationDate != null">#{activationDate}</if>
        </trim>
    </insert>

    <update id="updateByPrimaryKeySelective" parameterType="com.ho.filecenter.entity.CardInfo">
        update card_info
        <set>
            <if test="card != null">
                card = #{card},
            </if>
            <if test="flowMonitorId != null">
                flow_monitor_id = #{flowMonitorId},
            </if>
            <if test="stationId != null">
                station_id = #{stationId},
            </if>
            <if test="stationId == null">
                station_id = null,
            </if>
            <if test="packageType != null">
                package_type = #{packageType},
            </if>
            <if test="cardStatus != null">
                card_status = #{cardStatus},
            </if>
            <if test="openDate != null">
                open_date = #{openDate},
            </if>
            <if test="activationDate != null">
                activation_date = #{activationDate}
            </if>

        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.ho.filecenter.entity.CardInfo">
        update card_info
        set flow_monitor_id = #{flowMonitorId},
            card            = #{card},
            station_id      = #{stationId},
            package_type    = #{packageType},
            card_status     = #{cardStatus},
            open_date       = #{openDate},
            activation_date = #{activationDate}
        where id = #{id,jdbcType=INTEGER}
    </update>

</mapper>
