<?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.fs.sop.mapper.CompanySopRoleMapper">
    
    <resultMap type="CompanySopRole" id="CompanySopRoleResult">
        <result property="id"    column="id"    />
        <result property="companyId"    column="company_id"    />
        <result property="roleName"    column="role_name"    />
        <result property="roleValue"    column="role_value"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectCompanySopRoleVo">
        select id, company_id, role_name, role_value, create_time, create_by, update_by, update_time, remark from company_sop_role
    </sql>

    <select id="selectCompanySopRoleList" parameterType="CompanySopRole" resultMap="CompanySopRoleResult">
        <include refid="selectCompanySopRoleVo"/>
        <where>  
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="roleName != null  and roleName != ''"> and role_name like concat('%', #{roleName}, '%')</if>
            <if test="roleValue != null  and roleValue != ''"> and role_value = #{roleValue}</if>
        </where>
    </select>
    
    <select id="selectCompanySopRoleById" parameterType="Long" resultMap="CompanySopRoleResult">
        <include refid="selectCompanySopRoleVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertCompanySopRole" parameterType="CompanySopRole" useGeneratedKeys="true" keyProperty="id">
        insert into company_sop_role
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="companyId != null">company_id,</if>
            <if test="roleName != null">role_name,</if>
            <if test="roleValue != null">role_value,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="companyId != null">#{companyId},</if>
            <if test="roleName != null">#{roleName},</if>
            <if test="roleValue != null">#{roleValue},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateCompanySopRole" parameterType="CompanySopRole">
        update company_sop_role
        <trim prefix="SET" suffixOverrides=",">
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="roleName != null">role_name = #{roleName},</if>
            <if test="roleValue != null">role_value = #{roleValue},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCompanySopRoleById" parameterType="Long">
        delete from company_sop_role where id = #{id}
    </delete>

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