<?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.xmgl.mapper.ZqczXmglMapper">
    <!--  返回实体  -->
    <resultMap id="ZqczXmglResult" type="com.qianhe.zqcz.xmgl.domain.ZqczXmglVo">
        <result property="xmid" column="XMID"/>
        <result property="xmmc" column="XMMC"/>
        <result property="xmzy" column="XMZY"/>
        <result property="xmlb" column="XMLB"/>
        <result property="gzcj" column="GZCJ"/>
    </resultMap>
    <!--  通用查询  -->
    <sql id="selectCommon">
        SELECT
            xmgl.XMID,
            xmgl.XMMC,
            xmgl.XMZY,
            xmgl.XMLB,
            xmgl.GZCJ,
            xmgl.XMRS,
            IFNULL( dict.dict_label, '' ) AS GZCJMC
        FROM
        zqcz_xmgl xmgl
        LEFT JOIN sys_dict_data dict ON xmgl.gzcj = dict.dict_value AND dict.dict_type = CASE WHEN xmgl.XMZY = 1 THEN 'zqcz_cyzy_gzcj' WHEN xmgl.XMZY = 2 THEN 'zqcz_jszy_gzcj' ELSE '' END
    </sql>
    <!--  条件查询  -->
    <select id="list" parameterType="com.qianhe.zqcz.xmgl.domain.ZqczXmglQuery" resultMap="ZqczXmglResult">
        <include refid="selectCommon"></include>
        <where>
            <if test="xmmc != null  and xmmc !='' ">AND xmgl.XMMC like concat('%', #{xmmc}, '%')</if>
            <if test="xmzy != null  and xmzy !='' ">AND xmgl.XMZY = #{xmzy}</if>
            <if test="xmlb != null  and xmlb !='' ">AND xmgl.XMLB = #{xmlb}</if>
            <if test="gzcj != null  and gzcj !='' ">AND xmgl.GZCJ = #{gzcj}</if>
            <if test="xmzt != null  and xmzt !='' ">AND xmgl.XMZT = #{xmzt}</if>
        </where>
        ORDER BY xmgl.XMLB, xmgl.GZCJ, xmgl.UPDATE_TIME DESC
    </select>
    <!--  查询详情  -->
    <select id="info" parameterType="long" resultMap="ZqczXmglResult">
        <include refid="selectCommon"></include> WHERE xmgl.XMID = #{xmid}
    </select>
    <!--  新增  -->
    <insert id="add" parameterType="ZqczXmgl">
        INSERT INTO zqcz_xmgl
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="xmmc != null  and xmmc != ''">XMMC,</if>
            <if test="xmzy != null  and xmzy != ''">XMZY,</if>
            <if test="xmlb != null  and xmlb != ''">XMLB,</if>
            <if test="gzcj != null  and gzcj != ''">GZCJ,</if>
            <if test="xmrs != null ">XMRS,</if>
            <if test="xmzt != null  and xmzt != ''">XMZT,</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="xmmc != null and xmmc != ''">#{xmmc},</if>
            <if test="xmzy != null and xmzy != ''">#{xmzy},</if>
            <if test="xmlb != null and xmlb != ''">#{xmlb},</if>
            <if test="gzcj != null and gzcj != ''">#{gzcj},</if>
            <if test="xmrs != null">#{xmrs},</if>
            <if test="xmzt != null and xmzt != ''">#{xmzt},</if>
            <if test="create_by != null">#{create_by},</if>
            <if test="create_time != null">#{create_time},</if>
            <if test="update_by != null">#{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>
    <!--  修改  -->
    <update id="edit" parameterType="ZqczXmgl">
        UPDATE zqcz_xmgl
        <trim prefix="SET" suffixOverrides=",">
            <if test="xmmc != null">XMMC = #{xmmc},</if>
            <if test="xmzy != null">XMZY = #{xmzy},</if>
            <if test="xmlb != null">XMLB = #{xmlb},</if>
            <if test="gzcj != null">GZCJ = #{gzcj},</if>
            <if test="xmrs != null">XMRS = #{xmrs},</if>
            <if test="xmzt != null">XMZT = #{xmzt},</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="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>
            UPDATE_TIME = now()
        </trim>
        WHERE XMID = #{xmid}
    </update>
    <!--  删除  -->
    <delete id="delete" parameterType="long">
        DELETE FROM zqcz_xmgl WHERE XMID IN
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <!-- 项目管理表批量插入 -->
    <insert id="batchAdd" parameterType="java.util.List">
        <choose>
            <when test="dataList != null and dataList.size() > 0 and !dataList.isEmpty()">
                INSERT INTO zqcz_xmgl
                <trim prefix="(" suffix=")" suffixOverrides=",">
                    <if test="dataList[0].xmmc != null and dataList[0].xmmc != ''">XMMC,</if>
                    <if test="dataList[0].xmzy != null and dataList[0].xmzy != ''">XMZY,</if>
                    <if test="dataList[0].xmlb != null and dataList[0].xmlb != ''">XMLB,</if>
                    <if test="dataList[0].gzcj != null and dataList[0].gzcj != ''">GZCJ,</if>
                    <if test="dataList[0].xmrs != null">XMRS,</if>
                    <if test="dataList[0].xmzt != null and dataList[0].xmzt != ''">XMZT,</if>
                    <if test="dataList[0].create_by != null and dataList[0].create_by != ''">CREATE_BY,</if>
                    <if test="dataList[0].create_time != null">CREATE_TIME,</if>
                    <if test="dataList[0].update_by != null and dataList[0].update_by != ''">UPDATE_BY,</if>
                    <if test="dataList[0].remark != null and dataList[0].remark != ''">REMARK,</if>
                    <if test="dataList[0].yl1 != null and dataList[0].yl1 != ''">YL1,</if>
                    <if test="dataList[0].yl2 != null and dataList[0].yl2 != ''">YL2,</if>
                    <if test="dataList[0].yl3 != null and dataList[0].yl3 != ''">YL3,</if>
                    <if test="dataList[0].yl4 != null and dataList[0].yl4 != ''">YL4,</if>
                    <if test="dataList[0].yl5 != null and dataList[0].yl5 != ''">YL5,</if>
                    UPDATE_TIME
                </trim>
                VALUES
                <foreach collection="dataList" item="item" index="index" separator=",">
                    <trim prefix="(" suffix=")" suffixOverrides=",">
                        <if test="item.xmmc != null and item.xmmc != ''">#{item.xmmc},</if>
                        <if test="item.xmzy != null and item.xmzy != ''">#{item.xmzy},</if>
                        <if test="item.xmlb != null and item.xmlb != ''">#{item.xmlb},</if>
                        <if test="item.gzcj != null and item.gzcj != ''">#{item.gzcj},</if>
                        <if test="item.xmrs != null">#{item.xmrs},</if>
                        <if test="item.xmzt != null and item.xmzt != ''">#{item.xmzt},</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 and item.remark != ''">#{item.remark},</if>
                        <if test="item.yl1 != null and item.yl1 != ''">#{item.yl1},</if>
                        <if test="item.yl2 != null and item.yl2 != ''">#{item.yl2},</if>
                        <if test="item.yl3 != null and item.yl3 != ''">#{item.yl3},</if>
                        <if test="item.yl4 != null and item.yl4 != ''">#{item.yl4},</if>
                        <if test="item.yl5 != null and item.yl5 != ''">#{item.yl5},</if>
                        now()
                    </trim>
                </foreach>
            </when>
            <otherwise>
                SELECT 0 FROM DUAL
            </otherwise>
        </choose>
    </insert>
    <!--  逻辑删除  -->
    <update id="logicDelete" parameterType="long">
        UPDATE zqcz_xmgl SET XMZT = '0' WHERE XMID IN
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
</mapper>