<?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.zongzhi.mapper.TcBjsjMapper">
    
    <resultMap type="TcBjsj" id="TcBjsjResult">
        <result property="id"    column="id"    />
        <result property="areaId"    column="area_id"    />
        <result property="name"    column="name"    />
        <result property="percent"    column="percent"    />
    </resultMap>

    <sql id="selectTcBjsjVo">
        select id, area_id, name, percent from tc_bjsj
    </sql>

    <select id="selectTcBjsjList" parameterType="TcBjsj" resultMap="TcBjsjResult">
        <include refid="selectTcBjsjVo"/>
        <where>  
            <if test="areaId != null "> and area_id = #{areaId}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="percent != null  and percent != ''"> and percent = #{percent}</if>
        </where>
    </select>
    
    <select id="selectTcBjsjById" parameterType="Long" resultMap="TcBjsjResult">
        <include refid="selectTcBjsjVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTcBjsj" parameterType="TcBjsj" useGeneratedKeys="true" keyProperty="id">
        insert into tc_bjsj
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="areaId != null">area_id,</if>
            <if test="name != null">name,</if>
            <if test="percent != null">percent,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="areaId != null">#{areaId},</if>
            <if test="name != null">#{name},</if>
            <if test="percent != null">#{percent},</if>
         </trim>
    </insert>

    <update id="updateTcBjsj" parameterType="TcBjsj">
        update tc_bjsj
        <trim prefix="SET" suffixOverrides=",">
            <if test="areaId != null">area_id = #{areaId},</if>
            <if test="name != null">name = #{name},</if>
            <if test="percent != null">percent = #{percent},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTcBjsjById" parameterType="Long">
        delete from tc_bjsj where id = #{id}
    </delete>

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