<?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.oa.mapper.CmcResourceFieldMapper">
    
    <resultMap type="CmcResourceField" id="CmcResourceFieldResult">
        <result property="fieldId"    column="field_id"    />
        <result property="field"    column="field"    />
        <result property="parentId"    column="parent_id"    />
    </resultMap>

    <sql id="selectCmcResourceFieldVo">
        select field_id, field, parent_id from cmc_resource_field
    </sql>

    <select id="selectCmcResourceFieldList" parameterType="CmcResourceField" resultMap="CmcResourceFieldResult">
        <include refid="selectCmcResourceFieldVo"/>
        <where>  
            <if test="field != null  and field != ''"> and field like concat('%', #{field}, '%')</if>
            <if test="parentId != null "> and parent_id = #{parentId}</if>
        </where>
    </select>
    
    <select id="selectCmcResourceFieldByFieldId" parameterType="Integer" resultMap="CmcResourceFieldResult">
        <include refid="selectCmcResourceFieldVo"/>
        where field_id = #{fieldId}
    </select>
        
    <insert id="insertCmcResourceField" parameterType="CmcResourceField" useGeneratedKeys="true" keyProperty="fieldId">
        insert into cmc_resource_field
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="field != null">field,</if>
            <if test="parentId != null">parent_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="field != null">#{field},</if>
            <if test="parentId != null">#{parentId},</if>
         </trim>
    </insert>

    <update id="updateCmcResourceField" parameterType="CmcResourceField">
        update cmc_resource_field
        <trim prefix="SET" suffixOverrides=",">
            <if test="field != null">field = #{field},</if>
            <if test="parentId != null">parent_id = #{parentId},</if>
        </trim>
        where field_id = #{fieldId}
    </update>

    <delete id="deleteCmcResourceFieldByFieldId" parameterType="Integer">
        delete from cmc_resource_field where field_id = #{fieldId}
    </delete>

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