<?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.fgw.FgwFjMapper">
    
    <resultMap type="FgwFj" id="FgwFjResult">
        <result property="id"    column="id"    />
        <result property="xmId"    column="xm_id"    />
        <result property="xmbh"    column="xmbh"    />
        <result property="sourceId"    column="source_id"    />
        <result property="fjName"    column="fj_name"    />
        <result property="path"    column="path"    />
        <result property="type"    column="type"    />
        <result property="remark"    column="remark"    />
        <result property="isSh"    column="is_sh"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectFgwFjVo">
        select id, xm_id, xmbh,source_id, fj_name, path, type, remark,is_sh,create_time from fgw_fj
    </sql>

    <select id="selectFgwFjList" parameterType="FgwFj" resultMap="FgwFjResult">
        <include refid="selectFgwFjVo"/>
        <where>  
            <if test="xmId != null "> and xm_id = #{xmId}</if>
            <if test="xmbh != null  and xmbh != ''"> and xmbh = #{xmbh}</if>
            <if test="sourceId != null  "> and source_id = #{sourceId}</if>
            <if test="fjName != null  and fjName != ''"> and fj_name like concat('%', #{fjName}, '%')</if>
            <if test="path != null  and path != ''"> and path = #{path}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="isSh != null  and isSh != ''"> and is_sh = #{isSh}</if>
        </where>
    </select>
    
    <select id="selectFgwFjById" parameterType="Long" resultMap="FgwFjResult">
        <include refid="selectFgwFjVo"/>
        where id = #{id}
    </select>
    <select id="selectFgwFjByXmId" parameterType="Long" resultMap="FgwFjResult">
        <include refid="selectFgwFjVo"/>
        where xm_id = #{id} and type != '18'
    </select>
    <select id="selectFgwFjBySourceId" parameterType="Long" resultMap="FgwFjResult">
        <include refid="selectFgwFjVo"/>
        where source_id = #{id}  and type = '18'
    </select>

    <insert id="insertFgwFj" parameterType="FgwFj" useGeneratedKeys="true" keyProperty="id">
        insert into fgw_fj
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="xmId != null">xm_id,</if>
            <if test="xmbh != null">xmbh,</if>
            <if test="sourceId != null">source_id,</if>
            <if test="fjName != null and fjName != ''">fj_name,</if>
            <if test="path != null">path,</if>
            <if test="type != null">type,</if>
            <if test="remark != null">remark,</if>
            <if test="isSh != null and isSh != ''">is_sh,</if>
            <if test="createTime != null ">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="xmId != null">#{xmId},</if>
            <if test="xmbh != null">#{xmbh},</if>
            <if test="sourceId != null">#{sourceId},</if>
            <if test="fjName != null and fjName != ''">#{fjName},</if>
            <if test="path != null">#{path},</if>
            <if test="type != null">#{type},</if>
            <if test="remark != null">#{remark},</if>
            <if test="isSh != null and isSh != ''">#{isSh},</if>
            <if test="createTime != null">#{createTime},</if>
        </trim>
    </insert>

    <update id="updateFgwFj" parameterType="FgwFj">
        update fgw_fj
        <trim prefix="SET" suffixOverrides=",">
            <if test="xmId != null">xm_id = #{xmId},</if>
            <if test="xmbh != null">xmbh = #{xmbh},</if>
            <if test="fjName != null and fjName != ''">fj_name = #{fjName},</if>
            <if test="path != null">path = #{path},</if>
            <if test="type != null">type = #{type},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="isSh != null and isSh != ''">is_sh = #{isSh},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteFgwFjById" parameterType="Long">
        delete from fgw_fj where id = #{id}
    </delete>

    <delete id="deleteFgwFjByIds" parameterType="String">
        delete from fgw_fj where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <delete id="deleteFgwFjByXmId" parameterType="Long">
                delete from fgw_fj where xm_id = #{id} and is_sh != '2'
        <if test="type != null and type == 18"> and type = #{type}</if>
        <if test="type != null and type != 18"> and type != '18'</if>
    </delete>
</mapper>