<?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.ruoyi.invest.mapper.PosMachineMapper">

    <resultMap type="PosMachineVo" id="PosMachineResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="type"    column="type"    />
        <result property="manufacture"    column="manufacture"    />
        <result property="payCompany"    column="pay_company"    />
        <result property="merchantName"    column="merchant_name"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="remark"    column="remark"    />
        <result property="code"    column="code"    />
        <result property="rate"    column="rate"    />
        <result property="debitCard"    column="debit_card"    />
        <result property="merchantType"    column="merchant_type"    />
        <result property="merchantCode"    column="merchant_code"    />
        <result property="activationDate"    column="activation_date"    />
        <result property="ratePlus"    column="rate_plus"    />
        <result property="bankName"    column="bank_name"    />
        <result property="bankCode"    column="bank_code"    />

    </resultMap>

    <sql id="selectPosMachineVo">
        select
        a.id,
        a.name,
        a.type,
        a.manufacture,
        a.pay_company,
        a.merchant_name,
        a.create_by,
        a.create_time,
        a.update_by,
        a.update_time,
        a.del_flag,
        a.remark,
        a.code,
        a.rate,
        a.rate_plus,
        a.debit_card,
        a.merchant_type,
        a.merchant_code,
        a.activation_date,
        bc."name"  as bank_name,
        bc.code  as bank_code
        from
        pos_machine a
        left join bank_card_lend bc on bc.id =a.debit_card
    </sql>

    <select id="selectPosMachineList" parameterType="PosMachineDto" resultMap="PosMachineResult">
        <include refid="selectPosMachineVo"/>
        <where>
            a.del_flag='0'
            <if test="name != null  and name != ''"> and a.name like '%'|| #{name}||'%'</if>
            <if test="type != null  and type != ''"> and a.type = #{type}</if>
            <if test="merchantName != null  and merchantName != ''"> and a.merchant_name like '%'|| #{merchantName}||'%'</if>
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by a.create_time desc
    </select>

    <select id="selectPosMachineById" parameterType="Long" resultMap="PosMachineResult">
        <include refid="selectPosMachineVo"/>
        where a.id = #{id}
    </select>

    <insert id="insertPosMachine" parameterType="PosMachine">
        insert into pos_machine
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="name != null">name,</if>
            <if test="type != null">type,</if>
            <if test="manufacture != null">manufacture,</if>
            <if test="payCompany != null">pay_company,</if>
            <if test="merchantName != null">merchant_name,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="remark != null">remark,</if>
            <if test="code != null">code,</if>
            <if test="rate != null">rate,</if>
            <if test="ratePlus != null">rate_plus,</if>
            <if test="debitCard != null">debit_card,</if>
            <if test="merchantType != null">merchant_type,</if>
            <if test="merchantCode != null">merchant_code,</if>
            <if test="activationDate != null">activation_date,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="name != null">#{name},</if>
            <if test="type != null">#{type},</if>
            <if test="manufacture != null">#{manufacture},</if>
            <if test="payCompany != null">#{payCompany},</if>
            <if test="merchantName != null">#{merchantName},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="remark != null">#{remark},</if>
            <if test="code != null">#{code},</if>
            <if test="rate != null">#{rate},</if>
            <if test="ratePlus != null">#{ratePlus},</if>
            <if test="debitCard != null">#{debitCard},</if>
            <if test="merchantType != null">#{merchantType},</if>
            <if test="merchantCode != null">#{merchantCode},</if>
            <if test="activationDate != null">#{activationDate},</if>
         </trim>
    </insert>

    <update id="updatePosMachine" parameterType="PosMachine">
        update pos_machine
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="type != null">type = #{type},</if>
            <if test="manufacture != null">manufacture = #{manufacture},</if>
            <if test="payCompany != null">pay_company = #{payCompany},</if>
            <if test="merchantName != null">merchant_name = #{merchantName},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="code != null">code = #{code},</if>
            <if test="rate != null">rate = #{rate},</if>
            <if test="ratePlus != null">rate_plus = #{ratePlus},</if>
            <if test="debitCard != null">debit_card = #{debitCard},</if>
            <if test="merchantType != null">merchant_type = #{merchantType},</if>
            <if test="merchantCode != null">merchant_code = #{merchantCode},</if>
            <if test="activationDate != null">activation_date = #{activationDate},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePosMachineById" parameterType="Long">
        delete from pos_machine where id = #{id}
    </delete>

    <delete id="deletePosMachineByIds" parameterType="String">
        delete from pos_machine where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <update id="removePosMachineById" parameterType="Long">
         update pos_machine set del_flag='1' where id = #{id}
    </update>

    <update id="removePosMachineByIds" parameterType="String">
        update pos_machine set del_flag='1' where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
</mapper>
