<?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.mapper.SjGfjsZdgzMapper">
    
    <resultMap type="SjGfjsZdgz" id="SjGfjsZdgzResult">
        <result property="id"    column="id"    />
        <result property="nd"    column="nd"    />
        <result property="lx"    column="lx"    />
        <result property="khnr"    column="khnr"    />
        <result property="khxd"    column="khxd"    />
        <result property="khnrfs"    column="khnrfs"    />
        <result property="xppx"    column="xppx"    />
        <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"    />
        <result property="yl1"    column="yl1"    />
        <result property="yl2"    column="yl2"    />
        <result property="yl3"    column="yl3"    />
        <result property="yl4"    column="yl4"    />
        <result property="yl5"    column="yl5"    />
    </resultMap>

    <resultMap id="SjGfjsZdgzSjGfjsZdgzCbResult" type="SjGfjsZdgz" extends="SjGfjsZdgzResult">
        <collection property="sjGfjsZdgzCbList" notNullColumn="sub_id" javaType="java.util.List" resultMap="SjGfjsZdgzCbResult" />
    </resultMap>

    <resultMap type="SjGfjsZdgzCb" id="SjGfjsZdgzCbResult">
        <result property="id"    column="id"    />
        <result property="zbId"    column="zb_id"    />
        <result property="nd"    column="nd"    />
        <result property="lx"    column="lx"    />
        <result property="khnr"    column="khnr"    />
        <result property="khxd"    column="khxd"    />
        <result property="pjbz"    column="pjbz"    />
        <result property="px"    column="px"    />
        <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"    />
        <result property="yl1"    column="yl1"    />
        <result property="yl2"    column="yl2"    />
        <result property="yl3"    column="yl3"    />
        <result property="yl4"    column="yl4"    />
        <result property="yl5"    column="yl5"    />
    </resultMap>

    <sql id="selectSjGfjsZdgzVo">
        select id, nd, lx, khnr, khxd, khnrfs, xppx, create_by, create_time, update_by, update_time, remark, yl1, yl2, yl3, yl4, yl5 from sj_gfjs_zdgz
    </sql>

    <select id="selectSjGfjsZdgzList" parameterType="SjGfjsZdgz" resultMap="SjGfjsZdgzResult">
        <include refid="selectSjGfjsZdgzVo"/>
        <where>  
            <if test="nd != null  and nd != ''"> and nd = #{nd}</if>
            <if test="lx != null  and lx != ''"> and lx = #{lx}</if>
            <if test="khnr != null  and khnr != ''"> and khnr = #{khnr}</if>
            <if test="khxd != null  and khxd != ''"> and khxd = #{khxd}</if>
            <if test="khnrfs != null  and khnrfs != ''"> and khnrfs = #{khnrfs}</if>
            <if test="xppx != null "> and xppx = #{xppx}</if>
            <if test="yl1 != null  and yl1 != ''"> and yl1 = #{yl1}</if>
            <if test="yl2 != null  and yl2 != ''"> and yl2 = #{yl2}</if>
            <if test="yl3 != null  and yl3 != ''"> and yl3 = #{yl3}</if>
            <if test="yl4 != null  and yl4 != ''"> and yl4 = #{yl4}</if>
            <if test="yl5 != null  and yl5 != ''"> and yl5 = #{yl5}</if>
        </where>
    </select>
    
    <select id="selectSjGfjsZdgzById" parameterType="Long" resultMap="SjGfjsZdgzResult">
        select a.id, a.nd, a.lx, a.khnr, a.khxd, a.khnrfs, a.xppx, a.create_by, a.create_time, a.update_by, a.update_time, a.remark, a.yl1, a.yl2, a.yl3, a.yl4, a.yl5
        from sj_gfjs_zdgz a
        where a.id = #{id}
    </select>
    <select id="selectSjGfjsZdgzCbById" resultMap="SjGfjsZdgzCbResult">
        select   * from  sj_gfjs_zdgz_cb where zb_id=#{id}
    </select>
    <select id="selectSjGfjsZdgzCxList" resultType="com.qianhe.domain.SjGfjsZdgz">
        select a.id, a.nd,a.lx,a.khnr,a.khxd,a.khnr,a.xppx,b.pjbz,b.px
        from sj_gfjs_zdgz a
                 left join sj_gfjs_zdgz_cb b on a.id = b.zb_id
        where 1=1
        <if test="nd != null  and nd != ''"> and a.nd = #{nd}</if>
        <if test="lx != null  and lx != ''"> and a.lx = #{lx}</if>
        order by  (case when a.khnr='党建引领' then 1 when a.khnr='素质提升' then 2 when a.khnr='管理精益' then 3 else 4 end) ,a.xppx,b.px
    </select>
    <select id="getKhnrList" resultType="java.lang.String">
        select distinct khnr from sj_gfjs_zdgz_cb
        where 1=1
        <if test="lx != null  and lx != ''"> and lx = #{lx}</if>
        <if test="nd != null  and nd != ''"> and nd = #{nd}</if>

    </select>
    <select id="getKhxdList" resultType="java.lang.String">
        select distinct khxd from sj_gfjs_zdgz_cb
        where  1=1
        <if test="khnr != null  and khnr != ''"> and khnr = #{khnr}</if>
        <if test="nd != null  and nd != ''"> and nd = #{nd}</if>
        <if test="lx != null  and lx != ''"> and lx = #{lx}</if>

    </select>
    <select id="getPjbzList" resultType="com.qianhe.domain.SjGfjsZdgzCb">
        select id,pjbz from sj_gfjs_zdgz_cb
        where 1=1
        <if test="khxd != null  and khxd != ''"> and khxd = #{khxd}</if>
        <if test="nd != null  and nd != ''"> and nd = #{nd}</if>
        <if test="lx != null  and lx != ''"> and lx = #{lx}</if>
    </select>
    <select id="selectSjGfjsZdgzCb" resultType="com.qianhe.domain.SjGfjsZdgzCb">
        select * from sj_gfjs_zdgz_cb where  khnr=#{khnr} and khxd=#{khxd} and px=#{px} and nd=#{nd}
        limit 1
    </select>
    <select id="selectSjGfjsZdgzCxBzList" resultType="com.qianhe.domain.SjGfjsZdgzCb">
        select a.khnr,a.khxd,a.xppx
        from sj_gfjs_zdgz a
        left join sj_gfjs_zdgz_cb b on a.id = b.zb_id
        where 1=1
          and a.lx=#{lx} and a.nd =#{nd}
        group by a.khnr,a.khxd,a.xppx
        order by  (case when a.khnr='党建引领' then 1 when a.khnr='素质提升' then 2 when a.khnr='管理精益' then 3 else 4 end) ,a.xppx
    </select>


    <insert id="insertSjGfjsZdgz" parameterType="SjGfjsZdgz" useGeneratedKeys="true" keyProperty="id">
        insert into sj_gfjs_zdgz
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="nd != null">nd,</if>
            <if test="lx != null">lx,</if>
            <if test="khnr != null">khnr,</if>
            <if test="khxd != null">khxd,</if>
            <if test="khnrfs != null">khnrfs,</if>
            <if test="xppx != null">xppx,</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>
            <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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="nd != null">#{nd},</if>
            <if test="lx != null">#{lx},</if>
            <if test="khnr != null">#{khnr},</if>
            <if test="khxd != null">#{khxd},</if>
            <if test="khnrfs != null">#{khnrfs},</if>
            <if test="xppx != null">#{xppx},</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>
            <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>
         </trim>
    </insert>

    <update id="updateSjGfjsZdgz" parameterType="SjGfjsZdgz">
        update sj_gfjs_zdgz
        <trim prefix="SET" suffixOverrides=",">
            <if test="nd != null">nd = #{nd},</if>
            <if test="lx != null">lx = #{lx},</if>
            <if test="khnr != null">khnr = #{khnr},</if>
            <if test="khxd != null">khxd = #{khxd},</if>
            <if test="khnrfs != null">khnrfs = #{khnrfs},</if>
            <if test="xppx != null">xppx = #{xppx},</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>
            <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 id = #{id}
    </update>

    <delete id="deleteSjGfjsZdgzById" parameterType="Long">
        delete from sj_gfjs_zdgz where id = #{id}
    </delete>

    <delete id="deleteSjGfjsZdgzByIds" parameterType="String">
        delete from sj_gfjs_zdgz where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    
    <delete id="deleteSjGfjsZdgzCbByZbIds" parameterType="String">
        delete from sj_gfjs_zdgz_cb where zb_id in 
        <foreach item="zbId" collection="array" open="(" separator="," close=")">
            #{zbId}
        </foreach>
    </delete>

    <delete id="deleteSjGfjsZdgzCbByZbId" parameterType="Long">
        delete from sj_gfjs_zdgz_cb where zb_id = #{zbId}
    </delete>

    <insert id="batchSjGfjsZdgzCb">
        insert into sj_gfjs_zdgz_cb( id, zb_id, nd, lx, khnr, khxd, pjbz, px, create_by, create_time, update_by, update_time, remark, yl1, yl2, yl3, yl4, yl5) values
		<foreach item="item" index="index" collection="list" separator=",">
            ( #{item.id}, #{item.zbId}, #{item.nd}, #{item.lx}, #{item.khnr}, #{item.khxd}, #{item.pjbz}, #{item.px}, #{item.createBy}, #{item.createTime}, #{item.updateBy}, #{item.updateTime}, #{item.remark}, #{item.yl1}, #{item.yl2}, #{item.yl3}, #{item.yl4}, #{item.yl5})
        </foreach>
    </insert>


    <update id="updateSjGfjsZdgz_QZXS" parameterType="SjGfjsZdgz">
        update sj_gfjs_zdgz
        <trim prefix="SET" suffixOverrides=",">
            <if test="khnrfs != null">khnrfs = #{khnrfs},</if>
        </trim>
        where id = #{id}
    </update>
</mapper>