<?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.yijia.station.mapper.StationClassStructureMapper">
    
    <resultMap type="StationClassStructure" id="StationClassStructureResult">
        <result property="id"    column="id"    />
        <result property="stationId"    column="station_id"    />
        <result property="stationName"    column="station_name"    />
        <result property="person"    column="person"    />
        <result property="gunNo"    column="gun_no"    />
        <result property="salesVolume"    column="sales_volume"    />
        <result property="salesAmount"    column="sales_amount"    />
        <result property="discount"    column="discount"    />
        <result property="coupon"    column="coupon"    />
        <result property="netReceipts"    column="net_receipts"    />
        <result property="salesNum"    column="sales_num"    />
        <result property="printNum"    column="print_num"    />
        <result property="classStructureNo"    column="class_structure_no"    />
        <result property="classStructureDate"    column="class_structure_date"    />
        <result property="classStructureMan"    column="class_structure_man"    />
    </resultMap>

    <sql id="selectStationClassStructureVo">
        select id, station_id, station_name, person, gun_no, sales_volume, sales_amount, discount, coupon, net_receipts, sales_num, print_num, class_structure_no, class_structure_date, class_structure_man from station_class_structure
    </sql>

    <select id="selectStationClassStructureList" parameterType="StationClassStructure" resultMap="StationClassStructureResult">
        <include refid="selectStationClassStructureVo"/>
        <where>  
            <if test="stationId != null "> and station_id = #{stationId}</if>
            <if test="stationName != null  and stationName != ''"> and station_name like concat('%', #{stationName}, '%')</if>
            <if test="person != null  and person != ''"> and person = #{person}</if>
            <if test="gunNo != null  and gunNo != ''"> and gun_no = #{gunNo}</if>
            <if test="salesVolume != null  and salesVolume != ''"> and sales_volume = #{salesVolume}</if>
            <if test="salesAmount != null  and salesAmount != ''"> and sales_amount = #{salesAmount}</if>
            <if test="discount != null  and discount != ''"> and discount = #{discount}</if>
            <if test="coupon != null  and coupon != ''"> and coupon = #{coupon}</if>
            <if test="netReceipts != null  and netReceipts != ''"> and net_receipts = #{netReceipts}</if>
            <if test="salesNum != null "> and sales_num = #{salesNum}</if>
            <if test="printNum != null "> and print_num = #{printNum}</if>
            <if test="classStructureNo != null  and classStructureNo != ''"> and class_structure_no = #{classStructureNo}</if>
            <if test="classStructureDate != null "> and class_structure_date = #{classStructureDate}</if>
            <if test="classStructureMan != null  and classStructureMan != ''"> and class_structure_man = #{classStructureMan}</if>
        </where>
    </select>
    
    <select id="selectStationClassStructureById" parameterType="Long" resultMap="StationClassStructureResult">
        <include refid="selectStationClassStructureVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertStationClassStructure" parameterType="StationClassStructure" useGeneratedKeys="true" keyProperty="id">
        insert into station_class_structure
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="stationId != null">station_id,</if>
            <if test="stationName != null">station_name,</if>
            <if test="person != null">person,</if>
            <if test="gunNo != null">gun_no,</if>
            <if test="salesVolume != null">sales_volume,</if>
            <if test="salesAmount != null">sales_amount,</if>
            <if test="discount != null">discount,</if>
            <if test="coupon != null">coupon,</if>
            <if test="netReceipts != null">net_receipts,</if>
            <if test="salesNum != null">sales_num,</if>
            <if test="printNum != null">print_num,</if>
            <if test="classStructureNo != null">class_structure_no,</if>
            <if test="classStructureDate != null">class_structure_date,</if>
            <if test="classStructureMan != null">class_structure_man,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="stationId != null">#{stationId},</if>
            <if test="stationName != null">#{stationName},</if>
            <if test="person != null">#{person},</if>
            <if test="gunNo != null">#{gunNo},</if>
            <if test="salesVolume != null">#{salesVolume},</if>
            <if test="salesAmount != null">#{salesAmount},</if>
            <if test="discount != null">#{discount},</if>
            <if test="coupon != null">#{coupon},</if>
            <if test="netReceipts != null">#{netReceipts},</if>
            <if test="salesNum != null">#{salesNum},</if>
            <if test="printNum != null">#{printNum},</if>
            <if test="classStructureNo != null">#{classStructureNo},</if>
            <if test="classStructureDate != null">#{classStructureDate},</if>
            <if test="classStructureMan != null">#{classStructureMan},</if>
         </trim>
    </insert>

    <update id="updateStationClassStructure" parameterType="StationClassStructure">
        update station_class_structure
        <trim prefix="SET" suffixOverrides=",">
            <if test="stationId != null">station_id = #{stationId},</if>
            <if test="stationName != null">station_name = #{stationName},</if>
            <if test="person != null">person = #{person},</if>
            <if test="gunNo != null">gun_no = #{gunNo},</if>
            <if test="salesVolume != null">sales_volume = #{salesVolume},</if>
            <if test="salesAmount != null">sales_amount = #{salesAmount},</if>
            <if test="discount != null">discount = #{discount},</if>
            <if test="coupon != null">coupon = #{coupon},</if>
            <if test="netReceipts != null">net_receipts = #{netReceipts},</if>
            <if test="salesNum != null">sales_num = #{salesNum},</if>
            <if test="printNum != null">print_num = #{printNum},</if>
            <if test="classStructureNo != null">class_structure_no = #{classStructureNo},</if>
            <if test="classStructureDate != null">class_structure_date = #{classStructureDate},</if>
            <if test="classStructureMan != null">class_structure_man = #{classStructureMan},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteStationClassStructureById" parameterType="Long">
        delete from station_class_structure where id = #{id}
    </delete>

    <delete id="deleteStationClassStructureByIds" parameterType="String">
        delete from station_class_structure where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    
</mapper>