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

    <resultMap type="StationPay" id="StationPayResult">
        <result property="payId"    column="pay_id"    />
        <result property="stationId"    column="station_id"    />
        <result property="stationName"    column="station_name"    />
        <result property="cardEnabledFlag"    column="card_enabled_flag"    />
        <result property="wsPrintFlag"    column="ws_print_flag"    />
        <result property="printSetting"    column="print_setting"    />
        <result property="discountSetting"    column="discount_setting"    />
        <result property="notice"    column="notice"    />
        <result property="integralPrintFlag"    column="integral_print_flag"    />
        <result property="integralFlag"    column="integral_flag"    />
    </resultMap>

    <sql id="selectStationPayVo">
        select integral_flag,pay_id, station_id, station_name, card_enabled_flag,  ws_print_flag, print_setting, discount_setting, notice,integral_print_flag from station_pay
    </sql>

    <select id="selectStationPayList" parameterType="StationPay" resultMap="StationPayResult">
        select p.integral_flag,p.pay_id, p.station_id, s.dept_name as station_name,  p.card_enabled_flag,   p.ws_print_flag,  p.print_setting,  p.discount_setting,  p.notice, p.integral_print_flag
        from station_pay p join sys_dept s on p.station_id = s.dept_id
        <where>
            <if test="stationId != null "> and station_id = #{stationId}</if>
            <if test="cardEnabledFlag != null  and cardEnabledFlag != ''"> and card_enabled_flag = #{cardEnabledFlag}</if>
            <if test="wsPrintFlag != null  and wsPrintFlag != ''"> and ws_print_flag = #{wsPrintFlag}</if>
            <if test="printSetting != null  and printSetting != ''"> and print_setting = #{printSetting}</if>
            <if test="discountSetting != null  and discountSetting != ''"> and discount_setting = #{discountSetting}</if>
            <if test="notice != null  and notice != ''"> and notice = #{notice}</if>
            <if test="integralPrintFlag != null  and integralPrintFlag != ''"> and integral_print_flag = #{integralPrintFlag}</if>
            <if test="integralFlag != null  and integralFlag != ''"> and integral_flag = #{integralFlag}</if>
            <if test="stationIdList != null ">
                and station_id in
                <foreach item="item" index="index" collection="stationIdList"
                         open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </where>
        order by  pay_id desc
    </select>

    <select id="selectStationPayById" parameterType="Long" resultMap="StationPayResult">
        select p.integral_flag,p.pay_id, p.station_id, s.dept_name as station_name,  p.card_enabled_flag,   p.ws_print_flag,  p.print_setting,  p.discount_setting,  p.notice, p.integral_print_flag
        from station_pay p join sys_dept s on p.station_id = s.dept_id
        where pay_id = #{payId}
    </select>

    <insert id="insertStationPay" parameterType="StationPay" useGeneratedKeys="true" keyProperty="payId">
        insert into station_pay
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="stationId != null">station_id,</if>
            <if test="cardEnabledFlag != null">card_enabled_flag,</if>
            <if test="wsPrintFlag != null">ws_print_flag,</if>
            <if test="printSetting != null">print_setting,</if>
            <if test="discountSetting != null">discount_setting,</if>
            <if test="notice != null">notice,</if>
            <if test="integralPrintFlag != null">integral_print_flag,</if>
            <if test="integralFlag != null">integral_flag,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="stationId != null">#{stationId},</if>
            <if test="cardEnabledFlag != null">#{cardEnabledFlag},</if>
            <if test="wsPrintFlag != null">#{wsPrintFlag},</if>
            <if test="printSetting != null">#{printSetting},</if>
            <if test="discountSetting != null">#{discountSetting},</if>
            <if test="notice != null">#{notice},</if>
            <if test="integralPrintFlag != null">#{integralPrintFlag},</if>
            <if test="integralFlag != null">#{integralFlag},</if>
         </trim>
    </insert>

    <update id="updateStationPay" parameterType="StationPay">
        update station_pay
        <trim prefix="SET" suffixOverrides=",">
            <if test="stationId != null">station_id = #{stationId},</if>
            <if test="cardEnabledFlag != null">card_enabled_flag = #{cardEnabledFlag},</if>
            <if test="wsPrintFlag != null">ws_print_flag = #{wsPrintFlag},</if>
            <if test="printSetting != null">print_setting = #{printSetting},</if>
            <if test="discountSetting != null">discount_setting = #{discountSetting},</if>
            <if test="notice != null">notice = #{notice},</if>
            <if test="integralPrintFlag != null">  integral_print_flag = #{integralPrintFlag},</if>
            <if test="integralFlag != null">  integral_flag = #{integralFlag},</if>
        </trim>
        where pay_id = #{payId}
    </update>

    <delete id="deleteStationPayById" parameterType="Long">
        delete from station_pay where pay_id = #{payId}
    </delete>

    <delete id="deleteStationPayByIds" parameterType="String">
        delete from station_pay where pay_id in
        <foreach item="payId" collection="array" open="(" separator="," close=")">
            #{payId}
        </foreach>
    </delete>

</mapper>
