<?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.qianhe.zqcz.jcrw.mapper.ZqczJcrwMapper">
    <!--  返回实体  -->
    <resultMap id="ZqczJcrwResult" type="com.qianhe.zqcz.jcrw.domain.ZqczJcrwVo">
        <id property="jcrwid" column="jcrwid"/>
        <result property="zsrwid" column="zsrwid"/>
        <result property="jcdwid" column="jcdwid"/>
        <result property="jcdwmc" column="jcdwmc"/>
        <result property="jczzlx" column="jczzlx"/>
        <result property="cjlx" column="cjlx"/>
        <result property="jcrwzt" column="jcrwzt"/>
    </resultMap>
    <!--  通用查询  -->
    <sql id="selectCommon">
        SELECT
            jcrw.zsrwid,
            jcrw.jcrwid,
            jcrw.jcdwid,
            jcdw.jcdwmc,
            jcrw.cjlx,
            jcdw.jczzlx,
            jcrw.jcrwzt
        FROM
            zqcz_jcrw jcrw
        LEFT JOIN zqcz_jcdw jcdw ON jcrw.jcdwid = jcdw.jcdwid
    </sql>
    <!--  条件查询  -->
    <select id="list" parameterType="com.qianhe.zqcz.jcrw.domain.ZqczJcrwQuery" resultMap="ZqczJcrwResult">
        <include refid="selectCommon"></include>
        <where>
            <if test="jcdwmc != null and jcdwmc !=''">AND jcdwmc like concat('%', #{jcdwmc}, '%')</if>
            <if test="jcrwzt != null and jcrwzt !=''">AND jcrwzt = #{jcrwzt}</if>
        </where>
        ORDER BY update_time DESC
    </select>
    <!--  查询详情  -->
    <select id="info" parameterType="long" resultMap="ZqczJcrwResult">
        <include refid="selectCommon"></include> WHERE jcrw.jcrwid = #{jcrwid}
    </select>
    <!--  根据直属任务ID查询  -->
    <select id="infoByZsrwId" parameterType="com.qianhe.zqcz.jcrw.domain.ZqczJcrwQuery" resultMap="ZqczJcrwResult">
        <include refid="selectCommon"></include> WHERE jcrw.zsrwid = #{zsrwid}
    </select>
    <!--  新增  -->
    <insert id="add" parameterType="ZqczJcrw">
        INSERT INTO zqcz_jcrw
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="zsrwid != null">ZSRWID,</if>
            <if test="jcdwid != null ">JCDWID,</if>
            <if test="cjlx != null  and cjlx != ''">CJLX,</if>
            <if test="jcrwzt != null  and jcrwzt != ''">JCRWZT,</if>
            <if test="create_by != null  and create_by != ''">CREATE_BY,</if>
            <if test="create_time != null ">CREATE_TIME,</if>
            <if test="update_by != null  and update_by != ''">UPDATE_BY,</if>
            <if test="remark != null  and remark != ''">REMARK,</if>
            <if test="yl1 != null  and yl1 != ''">YL1,</if>
            <if test="yl2 != null  and yl2 != ''">YL2,</if>
            <if test="yl3 != null  and yl3 != ''">YL3,</if>
            <if test="yl4 != null  and yl4 != ''">YL4,</if>
            <if test="yl5 != null  and yl5 != ''">YL5,</if>
            UPDATE_TIME
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="zsrwid != null">#{zsrwid},</if>
            <if test="jcdwid != null">#{jcdwid},</if>
            <if test="cjlx != null and cjlx != ''">#{cjlx},</if>
            <if test="jcrwzt != null and jcrwzt != ''">#{jcrwzt},</if>
            <if test="create_by != null  and create_by != ''">#{create_by},</if>
            <if test="create_time != null">#{create_time},</if>
            <if test="update_by != null  and update_by != ''">#{update_by},</if>
            <if test="remark != null">#{remark},</if>
            <if test="yl1 != null">#{yl1},</if>
            <if test="yl2 != null">#{yl2},</if>
            <if test="yl3 != null">#{yl3},</if>
            <if test="yl4 != null">#{yl4},</if>
            <if test="yl5 != null">#{yl5},</if>
            now()
        </trim>
    </insert>
    <!--  批量插入  -->
    <insert id="batchAdd" parameterType="java.util.List">
        <if test="zqczJcrwList != null and zqczJcrwList.size() > 0">
            INSERT INTO zqcz_jcrw
            <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="zqczJcrwList[0].zsrwid != null">ZSRWID,</if>
                <if test="zqczJcrwList[0].jcdwid != null ">JCDWID,</if>
                <if test="zqczJcrwList[0].cjlx != null  and zqczJcrwList[0].cjlx != ''">CJLX,</if>
                <if test="zqczJcrwList[0].jcrwzt != null  and zqczJcrwList[0].jcrwzt != ''">JCRWZT,</if>
                <if test="zqczJcrwList[0].create_by != null  and zqczJcrwList[0].create_by != ''">CREATE_BY,</if>
                <if test="zqczJcrwList[0].create_time != null ">CREATE_TIME,</if>
                <if test="zqczJcrwList[0].update_by != null  and zqczJcrwList[0].update_by != ''">UPDATE_BY,</if>
                <if test="zqczJcrwList[0].remark != null  and zqczJcrwList[0].remark != ''">REMARK,</if>
                <if test="zqczJcrwList[0].yl1 != null  and zqczJcrwList[0].yl1 != ''">YL1,</if>
                <if test="zqczJcrwList[0].yl2 != null  and zqczJcrwList[0].yl2 != ''">YL2,</if>
                <if test="zqczJcrwList[0].yl3 != null  and zqczJcrwList[0].yl3 != ''">YL3,</if>
                <if test="zqczJcrwList[0].yl4 != null  and zqczJcrwList[0].yl4 != ''">YL4,</if>
                <if test="zqczJcrwList[0].yl5 != null  and zqczJcrwList[0].yl5 != ''">YL5,</if>
                UPDATE_TIME
            </trim>
            VALUES
            <foreach collection="zqczJcrwList" item="item" index="index" separator=",">
                <trim prefix="(" suffix=")" suffixOverrides=",">
                    <if test="item.zsrwid != null">#{item.zsrwid},</if>
                    <if test="item.jcdwid != null">#{item.jcdwid},</if>
                    <if test="item.cjlx != null and item.cjlx != ''">#{item.cjlx},</if>
                    <if test="item.jcrwzt != null and item.jcrwzt != ''">#{item.jcrwzt},</if>
                    <if test="item.create_by != null  and item.create_by != ''">#{item.create_by},</if>
                    <if test="item.create_time != null">#{item.create_time},</if>
                    <if test="item.update_by != null  and item.update_by != ''">#{item.update_by},</if>
                    <if test="item.remark != null">#{item.remark},</if>
                    <if test="item.yl1 != null">#{item.yl1},</if>
                    <if test="item.yl2 != null">#{item.yl2},</if>
                    <if test="item.yl3 != null">#{item.yl3},</if>
                    <if test="item.yl4 != null">#{item.yl4},</if>
                    <if test="item.yl5 != null">#{item.yl5},</if>
                    now()
                </trim>
            </foreach>
        </if>
    </insert>
    <!--  修改  -->
    <update id="edit" parameterType="ZqczJcrw">
        UPDATE zqcz_jcrw
        <trim prefix="SET" suffixOverrides=",">
            <if test="zsrwid != null">ZSRWID = #{zsrwid},</if>
            <if test="jcdwid != null">JCDWID = #{jcdwid},</if>
            <if test="cjlx != null and cjlx != ''">CJLX = #{cjlx},</if>
            <if test="jcrwzt != null  and jcrwzt != ''">JCRWZT = #{jcrwzt},</if>
            <if test="create_by != null">CREATE_BY = #{create_by},</if>
            <if test="create_time != null">CREATE_TIME = #{create_time},</if>
            <if test="update_by != null">UPDATE_BY = #{update_by},</if>
            <if test="update_time != null">UPDATE_TIME = #{update_time},</if>
            <if test="remark != null">REMARK = #{remark},</if>
            <if test="yl1 != null">YL1 = #{yl1},</if>
            <if test="yl2 != null">YL2 = #{yl2},</if>
            <if test="yl3 != null">YL3 = #{yl3},</if>
            <if test="yl4 != null">YL4 = #{yl4},</if>
            <if test="yl5 != null">YL5 = #{yl5},</if>
        </trim>
        WHERE JCRWID = #{jcrwid}
    </update>
    <!--  删除  -->
    <delete id="delete" parameterType="long">
        DELETE FROM zqcz_jcrw WHERE JCRWID IN
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <!--  根据直属任务ID删除  -->
    <delete id="deleteByZsrwid" parameterType="long">
        DELETE FROM zqcz_jcrw WHERE ZSRWID = #{jcdwid}
    </delete>
</mapper>