<?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="cn.timer.api.dao.xcgl.XcglAssoJxgzMapper">

    <resultMap id="BaseResultMap" type="cn.timer.api.bean.xcgl.XcglAssoJxgz" >
                <id column="id" property="id" />
                <result column="xzzid" property="xzzid" />
                <result column="name" property="name" />
                <result column="remarks" property="remarks" />
                <result column="addtime" property="addtime" />
                <result column="adduserid" property="adduserid" />
                <result column="qyid" property="qyid" />
    </resultMap>


	<resultMap id="PayGroupedDataMap" type="cn.timer.api.dto.xcgl.PayGroupedDataDto" >
            <result column="zid" property="zid" />
            <result column="zname" property="zname" />
            <result column="zremarks" property="zremarks" />
            <result column="zxzzid" property="zxzzid" />
            
            <collection property="term" ofType="cn.timer.api.dto.xcgl.PayTermDto">
		   		<result column="xid" property="xid"/>
		   		<result column="xsalaryitem" property="xsalaryitem"/>
		   		<result column="xyhmbzd" property="xyhmbzd"/>
		   		<result column="xrule" property="xrule"/>
		   		<result column="xtype" property="xtype"/>
		   		<result column="xremarks" property="xremarks"/>
		   		<result column="xgsid" property="xgsid"/>
		   		<result column="xgsgs" property="xgsgs"/>
                <result column="xdygk" property="xdygk"/>
                <result column="xdegk" property="xdegk"/>
		   		<result column="xjxgzid" property="xjxgzid"/>
		   		<result column="xoptionid" property="xoptionid"/>
		   		<result column="xiscustom" property="xiscustom"/>
		   		<result column="xrulestate" property="xrulestate"/>
		   		<result column="zxzzid" property="zxzzid"/>
		    </collection>
            
    </resultMap>

    <sql id="Base_Column_List">
                id,
                xzzid,
                name,
                remarks,
                addtime,
                adduserid,
                qyid
    </sql>
    
    <sql id="Base_Column_List_Alias">
                id XcglAssoJxgz_id,
                xzzid XcglAssoJxgz_xzzid,
                name XcglAssoJxgz_name,
                remarks XcglAssoJxgz_remarks,
                addtime XcglAssoJxgz_addtime,
                adduserid XcglAssoJxgz_adduserid,
                qyid XcglAssoJxgz_qyid
    </sql>

	<delete id="deleteByxzzid" >
        DELETE FROM xcgl_asso_jxgz
        WHERE xzzid = #{xzzid}
    </delete>


<insert id="insertxcglassojxgzList" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id" >
	    insert into xcgl_asso_jxgz (xzzid,name,remarks,addtime,adduserid,qyid)
	    <foreach collection="list" item="item" index="index" open="values " close="" separator=",">
	   	(
	      <if test="item.xzzid != null" >
	        #{item.xzzid,jdbcType=INTEGER},
	      </if>
	      <if test="item.name != null" >
	        #{item.name,jdbcType=VARCHAR},
	      </if>
	      <if test="item.remarks != null" >
	        #{item.remarks,jdbcType=VARCHAR},
	      </if>
	      <if test="item.addtime != null" >
	        #{item.addtime,jdbcType=BIGINT},
	      </if>
	      <if test="item.adduserid != null" >
	        #{item.adduserid,jdbcType=INTEGER},
	      </if>
	      <if test="item.qyid != null" >
	        #{item.qyid,jdbcType=INTEGER}
	      </if>
	      )
	    </foreach>
  	 </insert>


    <insert id="jxgzinsert" useGeneratedKeys="true" keyProperty="id" parameterType="cn.timer.api.bean.xcgl.XcglAssoJxgz">
        INSERT INTO xcgl_asso_jxgz
        <trim prefix="(" suffix=")" suffixOverrides=",">
                        <if test ='null != xzzid'>
                        xzzid,
                        </if>
                        <if test ='null != name'>
                        name,
                        </if>
                        <if test ='null != remarks'>
                        remarks,
                        </if>
                        <if test ='null != addtime'>
                        addtime,
                        </if>
                        <if test ='null != adduserid'>
                        adduserid,
                        </if>
                        <if test ='null != qyid'>
                        qyid
                        </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                        <if test ='null != xzzid'>
                        #{xzzid},
                        </if>
                        <if test ='null != name'>
                        #{name},
                        </if>
                        <if test ='null != remarks'>
                        #{remarks},
                        </if>
                        <if test ='null != addtime'>
                        #{addtime},
                        </if>
                        <if test ='null != adduserid'>
                        #{adduserid},
                        </if>
                        <if test ='null != qyid'>
                        #{qyid}
                        </if>
        </trim>
    </insert>

 <!--    <delete id="delete" >
        DELETE FROM xcgl_asso_jxgz
        WHERE id = #{id}
    </delete>

    <update id="update" parameterType="cn.timer.api.bean.xcgl.XcglAssoJxgz">
        UPDATE xcgl_asso_jxgz
        <set>
                    <if test ='null != xzzid'>xzzid = #{xzzid},</if>
                    <if test ='null != name'>name = #{name},</if>
                    <if test ='null != remarks'>remarks = #{remarks},</if>
                    <if test ='null != addtime'>addtime = #{addtime},</if>
                    <if test ='null != adduserid'>adduserid = #{adduserid},</if>
                    <if test ='null != qyid'>qyid = #{qyid}</if>
        </set>
        WHERE id = #{id}
    </update>


    <select id="load" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List" />
        FROM xcgl_asso_jxgz
        WHERE id = #{id}
    </select>

    <select id="pageList" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List" />
        FROM xcgl_asso_jxgz
        LIMIT #{offset}, #{pageSize}
    </select>

    <select id="pageListCount" resultType="java.lang.Integer">
        SELECT count(1)
        FROM xcgl_asso_jxgz
    </select> -->

	<select id="selectPayrollGroupList" resultMap="PayGroupedDataMap">
			select jxgz.id as zid,
				jxgz.`name` as zname,
				jxgz.remarks as zremarks,
				gzzx.id as xid,
				gzzx.salaryitem as xsalaryitem,
				gzzx.yhmbzd as xyhmbzd,
				gzzx.rule as xrule,
				gzzx.type as xtype,
				gzzx.remarks as xremarks,
				gzzx.gsid as xgsid,
				gzzx.gsgs as xgsgs,
				gzzx.dygk as xdygk,
				gzzx.degk as xdegk,
				gzzx.jxgzid as xjxgzid,
				gzzx.optionid as xoptionid,
				jxgz.xzzid as zxzzid,
				gzzx.is_custom as xiscustom,
				gzzx.rulestate as xrulestate,
				gzzx.xzzid as zxzzid
		from xcgl_asso_jxgz jxgz
		LEFT JOIN xcgl_asso_jsgzzx as gzzx on gzzx.jxgzid = jxgz.id
		where jxgz.xzzid = #{xzzid}
	</select>
	
	<select id="selectassojxgzList" resultMap="BaseResultMap">
			select * from xcgl_asso_jxgz jxgz
				where jxgz.id not in (
						select jxgz.id from xcgl_asso_jxgz jxgz
				RIGHT JOIN xcgl_asso_jsgzzx as zzx on zzx.jxgzid = jxgz.id
				where jxgz.xzzid =#{xzzid}
				)
				and jxgz.xzzid =#{xzzid}
	</select>

</mapper>