<?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.hzy.project.business.subject.mapper.SalarySubjectMapper">
    
    <resultMap type="SalarySubject" id="SalarySubjectResult">
        <result property="salarySubjectId"    column="salarySubjectId"    />
        <result property="subjectType"    column="subjectType"    />
        <result property="subjectName"    column="subjectName"    />
        <result property="baseFlag"    column="baseFlag"    />
        <result property="percent"    column="percent"    />
        <result property="formula"    column="formula"    />
        <result property="sort"    column="sort"    />
        <result property="delFlag"    column="delFlag"    />
        <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="selectSalarySubjectVo">
        select salarySubjectId, subjectType, subjectName, baseFlag, percent, formula, sort, delFlag, create_by, create_time, update_by, update_time from m_salary_subject
    </sql>

    <select id="selectSalarySubjectList" parameterType="SalarySubject" resultMap="SalarySubjectResult">
        <include refid="selectSalarySubjectVo"/>
        <where>  
            <if test="subjectType != null  and subjectType != ''"> and subjectType = #{subjectType}</if>
            <if test="subjectName != null  and subjectName != ''"> and subjectName like concat('%', #{subjectName}, '%')</if>
            <if test="baseFlag != null  and baseFlag != ''"> and baseFlag = #{baseFlag}</if>
            <if test="percent != null "> and percent = #{percent}</if>
            <if test="formula != null "> and formula = #{formula}</if>
            <if test="delFlag != null"> and delFlag = #{delFlag}</if>
        </where>
        order by sort
    </select>
    
    <select id="selectSalarySubjectBySalarySubjectId" parameterType="Long" resultMap="SalarySubjectResult">
        <include refid="selectSalarySubjectVo"/>
        where salarySubjectId = #{salarySubjectId}
    </select>

    <insert id="insertSalarySubject" parameterType="SalarySubject" useGeneratedKeys="true" keyProperty="salarySubjectId">
        insert into m_salary_subject
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="subjectType != null">subjectType,</if>
            <if test="subjectName != null">subjectName,</if>
            <if test="baseFlag != null">baseFlag,</if>
            <if test="percent != null">percent,</if>
            <if test="formula != null">formula,</if>
            <if test="sort != null">sort,</if>
            <if test="delFlag != null">delFlag,</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="subjectType != null">#{subjectType},</if>
            <if test="subjectName != null">#{subjectName},</if>
            <if test="baseFlag != null">#{baseFlag},</if>
            <if test="percent != null">#{percent},</if>
            <if test="formula != null">#{formula},</if>
            <if test="sort != null">#{sort},</if>
            <if test="delFlag != null">#{delFlag},</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="updateSalarySubject" parameterType="SalarySubject">
        update m_salary_subject
        <trim prefix="SET" suffixOverrides=",">
            <if test="subjectType != null">subjectType = #{subjectType},</if>
            <if test="subjectName != null">subjectName = #{subjectName},</if>
            <if test="baseFlag != null">baseFlag = #{baseFlag},</if>
            <if test="percent != null">percent = #{percent},</if>
            <if test="formula != null">formula = #{formula},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="delFlag != null">delFlag = #{delFlag},</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 salarySubjectId = #{salarySubjectId}
    </update>

    <delete id="deleteSalarySubjectBySalarySubjectId" parameterType="Long">
        delete from m_salary_subject where salarySubjectId = #{salarySubjectId}
    </delete>

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

</mapper>