<?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.zbf.system.mapper.TBaseFinancialClassMapper">

    <resultMap type="TBaseFinancialClass" id="TBaseFinancialClassResult">
            <result property="id"    column="id"    />
            <result property="parentId"    column="parent_id"    />
            <result property="materialClassCode"    column="material_class_code"    />
            <result property="materialClassName"    column="material_class_name"    />
            <result property="dataType"    column="data_type"    />
            <result property="createTime"    column="create_time"    />
            <result property="updateTime"    column="update_time"    />
            <result property="createBy"    column="create_by"    />
            <result property="updateBy"    column="update_by"    />
    </resultMap>

    <sql id="selectTBaseFinancialClassVo">
        select id, parent_id, material_class_code, material_class_name,  data_type, create_time, update_time, create_by, update_by from t_base_financial_class
    </sql>

    <select id="selectTBaseFinancialClassList" parameterType="TBaseFinancialClass" resultMap="TBaseFinancialClassResult">
        <include refid="selectTBaseFinancialClassVo"/>
        <where>
                        <if test="parentId != null "> and parent_id = #{parentId}</if>
                        <if test="materialClassCode != null  and materialClassCode != ''"> and material_class_code = #{materialClassCode}</if>
                        <if test="materialClassName != null  and materialClassName != ''"> and material_class_name like concat('%', #{materialClassName}, '%')</if>
                        <if test="dataType != null  and dataType != ''"> and data_type = #{dataType}</if>
        </where>
    </select>

    <select id="selectTBaseFinancialClassById" parameterType="Long" resultMap="TBaseFinancialClassResult">
            <include refid="selectTBaseFinancialClassVo"/>
            where id = #{id}
    </select>

    <insert id="insertTBaseFinancialClass" parameterType="TBaseFinancialClass" useGeneratedKeys="true" keyProperty="id">
        insert into t_base_financial_class
        <trim prefix="(" suffix=")" suffixOverrides=",">
                    <if test="parentId != null">parent_id,</if>
                    <if test="materialClassCode != null">material_class_code,</if>
                    <if test="materialClassName != null">material_class_name,</if>
                    <if test="dataType != null">data_type,</if>
                    <if test="createTime != null">create_time,</if>
                    <if test="updateTime != null">update_time,</if>
                    <if test="createBy != null">create_by,</if>
                    <if test="updateBy != null">update_by,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                    <if test="parentId != null">#{parentId},</if>
                    <if test="materialClassCode != null">#{materialClassCode},</if>
                    <if test="materialClassName != null">#{materialClassName},</if>
                    <if test="dataType != null">#{dataType},</if>
                    <if test="createTime != null">#{createTime},</if>
                    <if test="updateTime != null">#{updateTime},</if>
                    <if test="createBy != null">#{createBy},</if>
                    <if test="updateBy != null">#{updateBy},</if>
        </trim>
    </insert>

    <update id="updateTBaseFinancialClass" parameterType="TBaseFinancialClass">
        update t_base_financial_class
        <trim prefix="SET" suffixOverrides=",">
                    <if test="parentId != null">parent_id = #{parentId},</if>
                    <if test="materialClassCode != null">material_class_code = #{materialClassCode},</if>
                    <if test="materialClassName != null">material_class_name = #{materialClassName},</if>
                    <if test="dataType != null">data_type = #{dataType},</if>
                    <if test="createTime != null">create_time = #{createTime},</if>
                    <if test="updateTime != null">update_time = #{updateTime},</if>
                    <if test="createBy != null">create_by = #{createBy},</if>
                    <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="enableTBaseFinancialClassByIds" parameterType="String">
        update t_base_financial_class set status=0 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
    <update id="disabledTBaseFinancialClassByIds" parameterType="String">
        update t_base_financial_class set status=1 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

    <delete id="deleteTBaseFinancialClassById" parameterType="Long">
        delete from t_base_financial_class  where id = #{id}
    </delete>

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