<?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.system.mapper.ZxFjMapper">
    
    <resultMap type="ZxFj" id="ZxFjResult">
        <result property="id"    column="id"    />
        <result property="mainId"    column="main_id"    />
        <result property="sourceId"    column="source_id"    />
        <result property="name"    column="name"    />
        <result property="url"    column="url"    />
        <result property="type"    column="type"    />
        <result property="stytle"    column="stytle"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectZxFjVo">
        select id,main_id, source_id, name, url, type,stytle, remark from zx_fj
    </sql>

    <select id="selectZxFjList" parameterType="ZxFj" resultMap="ZxFjResult">
        <include refid="selectZxFjVo"/>
        <where>
            <if test="mainId != null "> and main_id = #{mainId}</if>
            <if test="sourceId != null "> and source_id = #{sourceId}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="url != null  and url != ''"> and url = #{url}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="stytle != null  and stytle != ''"> and stytle = #{stytle}</if>
        </where>
    </select>
    
    <select id="selectZxFjById" parameterType="Long" resultMap="ZxFjResult">
        <include refid="selectZxFjVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertZxFj" parameterType="ZxFj" useGeneratedKeys="true" keyProperty="id">
        insert into zx_fj
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="mainId != null "> main_id, </if>
            <if test="sourceId != null">source_id,</if>
            <if test="name != null and name != ''">name,</if>
            <if test="url != null">url,</if>
            <if test="type != null">type,</if>
            <if test="stytle != null">stytle,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="mainId != null "> #{mainId},</if>
            <if test="sourceId != null">#{sourceId},</if>
            <if test="name != null and name != ''">#{name},</if>
            <if test="url != null">#{url},</if>
            <if test="type != null">#{type},</if>
            <if test="stytle != null">#{stytle},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>
    <insert id="batchZxFj">
        INSERT INTO `zheng_xie`.`zx_fj`(`main_id`, `source_id`, `name`, `url`, `type`, `stytle`, `remark`) VALUES
        <foreach item="item" index="index" collection="list" separator=",">
            ( #{item.mainId}, #{item.sourceId}, #{item.name},#{item.url},#{item.type},#{item.stytle},#{item.remark})
        </foreach>
    </insert>

    <update id="updateZxFj" parameterType="ZxFj">
        update zx_fj
        <trim prefix="SET" suffixOverrides=",">
            <if test="mainId != null ">main_id = #{mainId},</if>
            <if test="sourceId != null">source_id = #{sourceId},</if>
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="url != null">url = #{url},</if>
            <if test="type != null">type = #{type},</if>
            <if test="stytle != null">stytle = #{stytle},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteZxFjById" parameterType="Long">
        delete from zx_fj where id = #{id}
    </delete>

    <delete id="deleteZxFjByIds" parameterType="String">
        delete from zx_fj where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <delete id="deleteZxFjBySourceId" parameterType="Long">
        delete from zx_fj where source_id = #{sourceId}
    </delete>
</mapper>