<?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.dcs.hnyz.mapper.ModelComponentMapper">

    <resultMap type="ModelComponent" id="ModelComponentResult">
        <result property="modelId" column="model_id"/>
        <result property="modelName" column="model_name"/>
        <result property="modelType" column="model_type"/>
        <result property="componentName" column="component_name"/>
        <result property="componentType" column="component_type"/>
        <result property="iconClass" column="icon_class"/>
        <result property="zIndex" column="z_index"/>
        <result property="status" column="status"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectModelComponentVo">
        select model_id,
               model_name,
               model_type,
               component_name,
               component_type,
               icon_class,
               z_index,
               status,
               create_by,
               create_time,
               update_by,
               update_time,
               remark
        from model_component
    </sql>

    <select id="selectModelComponentList" parameterType="ModelComponent" resultMap="ModelComponentResult">
        <include refid="selectModelComponentVo"/>
        <where>
            <if test="modelName != null  and modelName != ''">and model_name like concat('%', #{modelName}, '%')</if>
            <if test="modelType != null  and modelType != ''">and model_type = #{modelType}</if>
            <if test="componentName != null  and componentName != ''">and component_name like concat('%',
                #{componentName}, '%')
            </if>
            <if test="status != null  and status != ''">and status = #{status}</if>
        </where>
    </select>

    <select id="selectModelComponentByModelId" parameterType="Long" resultMap="ModelComponentResult">
        <include refid="selectModelComponentVo"/>
        where model_id = #{modelId}
    </select>

    <insert id="insertModelComponent" parameterType="ModelComponent" useGeneratedKeys="true" keyProperty="modelId">
        insert into model_component
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="modelName != null and modelName != ''">model_name,</if>
            <if test="modelType != null and modelType != ''">model_type,</if>
            <if test="componentName != null and componentName != ''">component_name,</if>
            <if test="componentType != null">component_type,</if>
            <if test="iconClass != null">icon_class,</if>
            <if test="status != null">status,</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>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="modelName != null and modelName != ''">#{modelName},</if>
            <if test="modelType != null and modelType != ''">#{modelType},</if>
            <if test="componentName != null and componentName != ''">#{componentName},</if>
            <if test="componentType != null">#{componentType},</if>
            <if test="iconClass != null">#{iconClass},</if>
            <if test="status != null">#{status},</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>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateModelComponent" parameterType="ModelComponent">
        update model_component
        <trim prefix="SET" suffixOverrides=",">
            <if test="modelName != null and modelName != ''">model_name = #{modelName},</if>
            <if test="modelType != null and modelType != ''">model_type = #{modelType},</if>
            <if test="componentName != null and componentName != ''">component_name = #{componentName},</if>
            <if test="componentType != null">component_type = #{componentType},</if>
            <if test="iconClass != null">icon_class = #{iconClass},</if>
            <if test="status != null">status = #{status},</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>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where model_id = #{modelId}
    </update>

    <delete id="deleteModelComponentByModelId" parameterType="Long">
        delete
        from model_component
        where model_id = #{modelId}
    </delete>

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