<?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.XcglAssoJsgzzxMapper">

    <resultMap id="BaseResultMap" type="cn.timer.api.bean.xcgl.XcglAssoJsgzzx" >
                <id column="id" property="id" />
                <result column="salaryitem" property="salaryitem" />
                <result column="yhmbzd" property="yhmbzd" />
                <result column="rule" property="rule" />
                <result column="type" property="type" />
                <result column="addtime" property="addtime" />
                <result column="adduserid" property="adduserid" />
                <result column="jxgzid" property="jxgzid" />
                <result column="remarks" property="remarks" />
                <result column="gsid" property="gsid" />
                <result column="gsgs" property="gsgs" />
                <result column="xzzid" property="xzzid" />
                <result column="rulestate" property="rulestate" />
                <result column="optionid" property="optionid" />
    </resultMap>
    
		    
	<resultMap id="PayTermDtoMap" type="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="xjxgzid" property="xjxgzid"/>
    </resultMap>
    
    
	<resultMap id="CalculationOptionsDtoMap" type="cn.timer.api.dto.xcgl.CalculationOptionsDto" >
                <result column="id" property="id"/>
		   		<result column="salaryitem" property="salaryitem"/>
		   		<result column="rsz" property="rsz"/>
    </resultMap>

    <sql id="Base_Column_List">
                id,
                salaryitem,
                yhmbzd,
                rule,
                type,
                addtime,
                adduserid,
                jxgzid,
                remarks,
                gsid,
                gsgs,
                xzzid,
                rulestate,
                optionid
    </sql>
    
    <sql id="Base_Column_List_Alias">
                id XcglAssoJsgzzx_id,
                salaryitem XcglAssoJsgzzx_salaryitem,
                yhmbzd XcglAssoJsgzzx_yhmbzd,
                rule XcglAssoJsgzzx_rule,
                type XcglAssoJsgzzx_type,
                addtime XcglAssoJsgzzx_addtime,
                adduserid XcglAssoJsgzzx_adduserid,
                jxgzid XcglAssoJsgzzx_jxgzid,
                remarks XcglAssoJsgzzx_remarks,
                gsid XcglAssoJsgzzx_gsid,
                gsgs XcglAssoJsgzzx_gsgs,
                xzzid XcglAssoJsgzzx_xzzid,
                rulestate XcglAssoJsgzzx_rulestate,
                optionid XcglAssoJsgzzx_optionid
    </sql>
    
    <select id="selectSalarySectionList" resultMap="BaseResultMap">
    		select jsgzzx.* from xcgl_asso_jsgzzx jsgzzx
				LEFT JOIN xcgl_asso_option as opt on opt.id = jsgzzx.optionid
				where opt.itemid = 2
				and jsgzzx.xzzid = #{xzzid}
    </select>
    
    
    <select id="selectxcglassojxgzList" resultMap="PayTermDtoMap">
			select gzzx.id as xid,
				gzzx.salaryitem as xsalaryitem,
				gzzx.yhmbzd as xyhmbzd,
				gzzx.rule as xrule,
				gzzx.type as xtype,
				gzzx.jxgzid as xjxgzid,
				gzzx.remarks as xremarks,
				gzzx.gsid as xgsid,
				gzzx.gsgs as xgsgs
			from xcgl_asso_jsgzzx gzzx
		where gzzx.jxgzid = 0
		and gzzx.xzzid = #{xzzid}
	</select>
    
    <select id="selectCalculationOptionsList" resultMap="CalculationOptionsDtoMap">
    		select jsgzzx.id,
				jsgzzx.salaryitem,
				daz.rsz
			from xcgl_asso_jsgzzx jsgzzx
		LEFT JOIN xcgl_asso_xzdazdy as zdy on zdy.zdmc = jsgzzx.salaryitem
		LEFT JOIN xcgl_asso_xzdaz as daz on daz.xzdazdyid = zdy.id
		LEFT JOIN xcgl_asso_xzdadx as xzdadx on xzdadx.id = daz.xzdadxid and xzdadx.txzt = 0
		where jsgzzx.xzzid = #{xzzid}
		and jsgzzx.rulestate = 1
		and xzdadx.userid = #{userid}
    </select>
    
     <delete id="deleteByxzzid" >
        DELETE FROM xcgl_asso_jsgzzx
        WHERE xzzid = #{xzzid}
     </delete>
    
    <insert id="insertxcglassojsgzzxList" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id" >
	    insert into xcgl_asso_jsgzzx (salaryitem,yhmbzd,rule,type,addtime,adduserid,jxgzid,remarks,gsid,gsgs,xzzid,rulestate,optionid)
	    <foreach collection="list" item="item" index="index" open="values " close="" separator=",">
	   	(
	      <if test="item.salaryitem != null" >
	        #{item.salaryitem,jdbcType=VARCHAR},
	      </if>
	      <if test="item.yhmbzd != null" >
	        #{item.yhmbzd,jdbcType=VARCHAR},
	      </if>
	      <if test="item.rule != null" >
	        #{item.rule,jdbcType=VARCHAR},
	      </if>
	      <if test="item.type != null" >
	        #{item.type,jdbcType=INTEGER},
	      </if>
	      <if test="item.addtime != null" >
	        #{item.addtime,jdbcType=BIGINT},
	      </if>
	      <if test="item.adduserid != null" >
	        #{item.adduserid,jdbcType=INTEGER},
	      </if>
	      <if test="item.jxgzid != null" >
	        #{item.jxgzid,jdbcType=INTEGER},
	      </if>
	      <if test="item.remarks != null" >
	        #{item.remarks,jdbcType=VARCHAR},
	      </if>
	      <if test="item.gsid != null" >
	        #{item.gsid,jdbcType=INTEGER},
	      </if>
	      <if test="item.gsgs != null" >
	        #{item.gsgs,jdbcType=VARCHAR},
	      </if>
	      <if test="item.xzzid != null" >
	        #{item.xzzid,jdbcType=INTEGER},
	      </if>
	      <if test="item.rulestate != null" >
	        #{item.rulestate,jdbcType=INTEGER},
	      </if>
	      <if test="item.optionid != null" >
	        #{item.optionid,jdbcType=INTEGER}
	      </if>
	      )
	    </foreach>
  	 </insert>


    <insert id="jsgzzxinsert" useGeneratedKeys="true" keyProperty="id" parameterType="cn.timer.api.bean.xcgl.XcglAssoJsgzzx">
        INSERT INTO xcgl_asso_jsgzzx
        <trim prefix="(" suffix=")" suffixOverrides=",">
                        <if test ='null != salaryitem'>
                        salaryitem,
                        </if>
                        <if test ='null != yhmbzd'>
                        yhmbzd,
                        </if>
                        <if test ='null != rule'>
                        rule,
                        </if>
                        <if test ='null != type'>
                        type,
                        </if>
                        <if test ='null != addtime'>
                        addtime,
                        </if>
                        <if test ='null != adduserid'>
                        adduserid,
                        </if>
                        <if test ='null != jxgzid'>
                        jxgzid,
                        </if>
                        <if test ='null != remarks'>
                        remarks,
                        </if>
                        <if test ='null != gsid'>
                        gsid,
                        </if>
                        <if test ='null != gsgs'>
                        gsgs,
                        </if>
                        <if test ='null != xzzid'>
                        xzzid,
                        </if>
                        <if test ='null != rulestate'>
                        rulestate,
                        </if>
                        <if test ='null != optionid'>
                        optionid
                        </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                        <if test ='null != salaryitem'>
                        #{salaryitem},
                        </if>
                        <if test ='null != yhmbzd'>
                        #{yhmbzd},
                        </if>
                        <if test ='null != rule'>
                        #{rule},
                        </if>
                        <if test ='null != type'>
                        #{type},
                        </if>
                        <if test ='null != addtime'>
                        #{addtime},
                        </if>
                        <if test ='null != adduserid'>
                        #{adduserid},
                        </if>
                        <if test ='null != jxgzid'>
                        #{jxgzid},
                        </if>
                        <if test ='null != remarks'>
                        #{remarks},
                        </if>
                        <if test ='null != gsid'>
                        #{gsid},
                        </if>
                        <if test ='null != gsgs'>
                        #{gsgs},
                        </if>
                        <if test ='null != xzzid'>
                        #{xzzid},
                        </if>
                        <if test ='null != rulestate'>
                        #{rulestate},
                        </if>
                        <if test ='null != optionid'>
                        #{optionid}
                        </if>
        </trim>
    </insert>

    <delete id="delete" >
        DELETE FROM xcgl_asso_jsgzzx
        WHERE id = #{id}
    </delete>

    <update id="jsgzzxupdate" parameterType="cn.timer.api.bean.xcgl.XcglAssoJsgzzx">
        UPDATE xcgl_asso_jsgzzx
        <set>
                    <if test ='null != salaryitem'>salaryitem = #{salaryitem},</if>
                    <if test ='null != yhmbzd'>yhmbzd = #{yhmbzd},</if>
                    <if test ='null != rule'>rule = #{rule},</if>
                    <if test ='null != type'>type = #{type},</if>
                    <if test ='null != addtime'>addtime = #{addtime},</if>
                    <if test ='null != adduserid'>adduserid = #{adduserid},</if>
                    <if test ='null != jxgzid'>jxgzid = #{jxgzid},</if>
                    <if test ='null != remarks'>remarks = #{remarks},</if>
                    <if test ='null != gsid'>gsid = #{gsid},</if>
                    <if test ='null != gsgs'>gsgs = #{gsgs},</if>
                    <if test ='null != xzzid'>xzzid = #{xzzid},</if>
                    <if test ='null != rulestate'>rulestate = #{rulestate},</if>
                    <if test ='null != optionid'>optionid = #{optionid}</if>
        </set>
        WHERE id = #{id}
    </update>


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

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

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


</mapper>