<?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.ZsyzWczsMapper">
    
    <resultMap type="ZsyzWczs" id="ZsyzWczsResult">
        <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="outsideTime"    column="outside_time"    />
        <result property="numberOutings"    column="number_outings"    />
        <result property="outgoer"    column="outgoer"    />
        <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="selectZsyzWczsVo">
        select id, dept_id, dept_name, year, month, outside_time, number_outings,outgoer, details, create_by, create_time, update_by, update_time, remark from zsyz_wczs
    </sql>

    <select id="selectZsyzWczsList" parameterType="ZsyzWczs" resultMap="ZsyzWczsResult">
        <include refid="selectZsyzWczsVo"/>
        <where>  
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="deptName != null  and deptName != ''"> and dept_name like concat('%', #{deptName}, '%')</if>
            <if test="year != null  and year != ''"> and year = #{year}</if>
            <if test="month != null  and month != ''"> and month = #{month}</if>
            <if test="outsideTime != null "> and outside_time = #{outsideTime}</if>
            <if test="numberOutings != null "> and number_outings = #{numberOutings}</if>
            <if test="details != null  and details != ''"> and details = #{details}</if>
            <if test="outgoer != null  and outgoer != ''"> and outgoer = #{outgoer}</if>

        </where>
    </select>
    
    <select id="selectZsyzWczsById" parameterType="Long" resultMap="ZsyzWczsResult">
        select w.id, w.dept_id, w.dept_name, w.year, w.month, w.outside_time, w.number_outings,w.outgoer, w.details, w.create_by, w.create_time, w.update_by, w.update_time, w.remark,
               f.id,f.xm_id, f.xmbh, f.source_id, f.fj_name, f.path, f.type
        from zsyz_wczs w
        left join zsyz_fj f on w.id = f.source_id
        where w.id = #{id}
    </select>
        
    <insert id="insertZsyzWczs" parameterType="ZsyzWczs" useGeneratedKeys="true" keyProperty="id">
        insert into zsyz_wczs
        <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="outsideTime != null">outside_time,</if>
            <if test="numberOutings != null">number_outings,</if>
            <if test="outgoer != null">outgoer,</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="outsideTime != null">#{outsideTime},</if>
            <if test="numberOutings != null">#{numberOutings},</if>
            <if test="outgoer != null">#{outgoer},</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="updateZsyzWczs" parameterType="ZsyzWczs">
        update zsyz_wczs
        <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="outsideTime != null">outside_time = #{outsideTime},</if>
            <if test="numberOutings != null">number_outings = #{numberOutings},</if>
            <if test="outgoer != null">outgoer = #{outgoer},</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="deleteZsyzWczsById" parameterType="Long">
        delete from zsyz_wczs where id = #{id}
    </delete>

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