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

    <resultMap type="FutureStocksVo" id="FutureStocksResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="type"    column="type"    />
        <result property="code"    column="code"    />
        <result property="password"    column="password"    />
        <result property="tradingCenterCode"    column="trading_center_code"    />
        <result property="tradingCenterPassword"    column="trading_center_password"    />
        <result property="fundPassword"    column="fund_password"    />
        <result property="commission"    column="commission"    />
        <result property="bond"    column="bond"    />
        <result property="debitCard"    column="debit_card"    />
        <result property="activationDate"    column="activation_date"    />
        <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="bankName"    column="bank_name"    />
        <result property="bankCode"    column="bank_code"    />
    </resultMap>

    <sql id="selectFutureStocksVo">
        select
        a.id,
        a.name,
        a.type,
        a.code,
        a.password,
        a.trading_center_code,
        a.trading_center_password,
        a.fund_password,
        a.commission,
        a.bond,
        a.debit_card,
        a.activation_date,
        a.create_by,
        a.create_time,
        a.update_by,
        a.update_time,
        a.del_flag,
        a.remark ,
        bc."name" as bank_name,
        bc.code as bank_code
        from
        future_stocks a
        left join bank_card_lend bc on
        bc.id = a.debit_card
    </sql>

    <select id="selectFutureStocksList" parameterType="FutureStocksDto" resultMap="FutureStocksResult">
        <include refid="selectFutureStocksVo"/>
        <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>
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by a.create_time desc
    </select>

    <select id="selectFutureStocksById" parameterType="Long" resultMap="FutureStocksResult">
        <include refid="selectFutureStocksVo"/>
        where a.id = #{id}
    </select>

    <insert id="insertFutureStocks" parameterType="FutureStocks">
        insert into future_stocks
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="name != null and name != ''">name,</if>
            <if test="type != null">type,</if>
            <if test="code != null and code != ''">code,</if>
            <if test="password != null and password != ''">password,</if>
            <if test="tradingCenterCode != null and tradingCenterCode != ''">trading_center_code,</if>
            <if test="tradingCenterPassword != null and tradingCenterPassword != ''">trading_center_password,</if>
            <if test="fundPassword != null and fundPassword != ''">fund_password,</if>
            <if test="commission != null">commission,</if>
            <if test="bond != null">bond,</if>
            <if test="debitCard != null and debitCard != ''">debit_card,</if>
            <if test="activationDate != null">activation_date,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="name != null and name != ''">#{name},</if>
            <if test="type != null">#{type},</if>
            <if test="code != null and code != ''">#{code},</if>
            <if test="password != null and password != ''">#{password},</if>
            <if test="tradingCenterCode != null and tradingCenterCode != ''">#{tradingCenterCode},</if>
            <if test="tradingCenterPassword != null and tradingCenterPassword != ''">#{tradingCenterPassword},</if>
            <if test="fundPassword != null and fundPassword != ''">#{fundPassword},</if>
            <if test="commission != null">#{commission},</if>
            <if test="bond != null">#{bond},</if>
            <if test="debitCard != null and debitCard != ''">#{debitCard},</if>
            <if test="activationDate != null">#{activationDate},</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>
         </trim>
    </insert>

    <update id="updateFutureStocks" parameterType="FutureStocks">
        update future_stocks
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="type != null">type = #{type},</if>
            <if test="code != null and code != ''">code = #{code},</if>
            <if test="password != null and password != ''">password = #{password},</if>
            <if test="tradingCenterCode != null and tradingCenterCode != ''">trading_center_code = #{tradingCenterCode},</if>
            <if test="tradingCenterPassword != null and tradingCenterPassword != ''">trading_center_password = #{tradingCenterPassword},</if>
            <if test="fundPassword != null and fundPassword != ''">fund_password = #{fundPassword},</if>
            <if test="commission != null">commission = #{commission},</if>
            <if test="bond != null">bond = #{bond},</if>
            <if test="debitCard != null and debitCard != ''">debit_card = #{debitCard},</if>
            <if test="activationDate != null">activation_date = #{activationDate},</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>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteFutureStocksById" parameterType="Long">
        delete from future_stocks where id = #{id}
    </delete>

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

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