<?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.projectV2.ZsyzQktjMapper">
    
    <resultMap type="ZsyzQktj" id="ZsyzQktjResult">
        <result property="id"    column="id"    />
        <result property="deptId"    column="dept_id"    />
        <result property="deptName"    column="dept_name"    />
        <result property="year"    column="year"    />
        <result property="month"    column="month"    />
        <result property="numberOutings"    column="number_outings"    />
        <result property="numberDocking"    column="number_docking"    />
        <result property="details"    column="details"    />
        <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"    />

        <collection property="zsyzFjList" javaType="java.util.List" resultMap="ZsyzFjResult"/>
    </resultMap>

    <resultMap type="ZsyzFj" id="ZsyzFjResult">
        <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"    />
    </resultMap>

    <sql id="selectZsyzQktjVo">
        select q.id, q.dept_id, q.dept_name, q.year, q.month, q.number_outings, q.number_docking, q.details, q.create_by, q.create_time, q.update_by, q.update_time, q.remark,
               f.id,f.xm_id, f.xmbh, f.source_id, f.fj_name, f.path, f.type
        from zsyz_qktj q
        left join zsyz_fj f on q.id = f.source_id
    </sql>

    <select id="selectZsyzQktjList" parameterType="ZsyzQktj" resultMap="ZsyzQktjResult">
        <include refid="selectZsyzQktjVo"/>
        <where>  
            <if test="deptId != null "> and q.dept_id = #{deptId}</if>
            <if test="deptName != null  and deptName != ''"> and q.dept_name like concat('%', #{deptName}, '%')</if>
            <if test="year != null  and year != ''"> and q.year = #{year}</if>
            <if test="month != null  and month != ''"> and q.month = #{month}</if>
            <if test="numberOutings != null  and numberOutings != ''"> and q.number_outings = #{numberOutings}</if>
            <if test="numberDocking != null  and numberDocking != ''"> and q.number_docking = #{numberDocking}</if>
            <if test="details != null  and details != ''"> and q.details = #{details}</if>
        </where>
    </select>
    
    <select id="selectZsyzQktjById" parameterType="Long" resultMap="ZsyzQktjResult">
        select q.id, q.dept_id, q.dept_name, q.year, q.month, q.number_outings, q.number_docking, q.details, q.create_by, q.create_time, q.update_by, q.update_time, q.remark,
               f.id ,f.xm_id, f.xmbh, f.source_id, f.fj_name, f.path, f.type
        from zsyz_qktj q
        left join zsyz_fj f on q.id = f.source_id
        where q.id = #{id}
    </select>
        
    <insert id="insertZsyzQktj" parameterType="ZsyzQktj" useGeneratedKeys="true" keyProperty="id">
        insert into zsyz_qktj
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deptId != null">dept_id,</if>
            <if test="deptName != null and deptName != ''">dept_name,</if>
            <if test="year != null">year,</if>
            <if test="month != null">month,</if>
            <if test="numberOutings != null">number_outings,</if>
            <if test="numberDocking != null">number_docking,</if>
            <if test="details != null">details,</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="deptId != null">#{deptId},</if>
            <if test="deptName != null and deptName != ''">#{deptName},</if>
            <if test="year != null">#{year},</if>
            <if test="month != null">#{month},</if>
            <if test="numberOutings != null">#{numberOutings},</if>
            <if test="numberDocking != null">#{numberDocking},</if>
            <if test="details != null">#{details},</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="updateZsyzQktj" parameterType="ZsyzQktj">
        update zsyz_qktj
        <trim prefix="SET" suffixOverrides=",">
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="deptName != null and deptName != ''">dept_name = #{deptName},</if>
            <if test="year != null">year = #{year},</if>
            <if test="month != null">month = #{month},</if>
            <if test="numberOutings != null">number_outings = #{numberOutings},</if>
            <if test="numberDocking != null">number_docking = #{numberDocking},</if>
            <if test="details != null">details = #{details},</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 id = #{id}
    </update>

    <delete id="deleteZsyzQktjById" parameterType="Long">
        delete from zsyz_qktj where id = #{id}
    </delete>

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