<?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.xinelu.manage.mapper.normdepartmentcompare.NormDepartmentCompareMapper">

    <resultMap type="NormDepartmentCompare" id="NormDepartmentCompareResult">
            <result property="id" column="id"/>
            <result property="departmentId" column="department_id"/>
            <result property="departmentName" column="department_name"/>
            <result property="normCompareName" column="norm_compare_name"/>
            <result property="normCompareCode" column="norm_compare_code"/>
            <result property="normCompareSort" column="norm_compare_sort"/>
            <result property="normCompareRemark" column="norm_compare_remark"/>
            <result property="createBy" column="create_by"/>
            <result property="createTime" column="create_time"/>
            <result property="updateBy" column="update_by"/>
            <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectNormDepartmentCompareVo">
        select id, department_id, department_name, norm_compare_name, norm_compare_code, norm_compare_sort, norm_compare_remark, create_by, create_time, update_by, update_time from norm_department_compare
    </sql>

    <select id="selectNormDepartmentCompareList" parameterType="NormDepartmentCompare" resultMap="NormDepartmentCompareResult">
        <include refid="selectNormDepartmentCompareVo"/>
        <where>
                        <if test="departmentId != null ">
                            and department_id = #{departmentId}
                        </if>
                        <if test="departmentName != null  and departmentName != ''">
                            and department_name like concat('%', #{departmentName}, '%')
                        </if>
                        <if test="normCompareName != null  and normCompareName != ''">
                            and norm_compare_name like concat('%', #{normCompareName}, '%')
                        </if>
                        <if test="normCompareCode != null  and normCompareCode != ''">
                            and norm_compare_code = #{normCompareCode}
                        </if>
                        <if test="normCompareSort != null ">
                            and norm_compare_sort = #{normCompareSort}
                        </if>
                        <if test="normCompareRemark != null  and normCompareRemark != ''">
                            and norm_compare_remark = #{normCompareRemark}
                        </if>
        </where>
    </select>

    <select id="selectNormDepartmentCompareById" parameterType="Long"
            resultMap="NormDepartmentCompareResult">
            <include refid="selectNormDepartmentCompareVo"/>
            where id = #{id}
    </select>

    <insert id="insertNormDepartmentCompare" parameterType="NormDepartmentCompare" useGeneratedKeys="true"
            keyProperty="id">
        insert into norm_department_compare
        <trim prefix="(" suffix=")" suffixOverrides=",">
                    <if test="departmentId != null">department_id,
                    </if>
                    <if test="departmentName != null">department_name,
                    </if>
                    <if test="normCompareName != null">norm_compare_name,
                    </if>
                    <if test="normCompareCode != null">norm_compare_code,
                    </if>
                    <if test="normCompareSort != null">norm_compare_sort,
                    </if>
                    <if test="normCompareRemark != null">norm_compare_remark,
                    </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>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                    <if test="departmentId != null">#{departmentId},
                    </if>
                    <if test="departmentName != null">#{departmentName},
                    </if>
                    <if test="normCompareName != null">#{normCompareName},
                    </if>
                    <if test="normCompareCode != null">#{normCompareCode},
                    </if>
                    <if test="normCompareSort != null">#{normCompareSort},
                    </if>
                    <if test="normCompareRemark != null">#{normCompareRemark},
                    </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>
        </trim>
    </insert>

    <update id="updateNormDepartmentCompare" parameterType="NormDepartmentCompare">
        update norm_department_compare
        <trim prefix="SET" suffixOverrides=",">
                    <if test="departmentId != null">department_id =
                        #{departmentId},
                    </if>
                    <if test="departmentName != null">department_name =
                        #{departmentName},
                    </if>
                    <if test="normCompareName != null">norm_compare_name =
                        #{normCompareName},
                    </if>
                    <if test="normCompareCode != null">norm_compare_code =
                        #{normCompareCode},
                    </if>
                    <if test="normCompareSort != null">norm_compare_sort =
                        #{normCompareSort},
                    </if>
                    <if test="normCompareRemark != null">norm_compare_remark =
                        #{normCompareRemark},
                    </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>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteNormDepartmentCompareById" parameterType="Long">
        delete from norm_department_compare where id = #{id}
    </delete>

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