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

    <resultMap id="BaseResultMap" type="cn.timer.api.bean.xcgl.XcglAssoZxfjkc" >
                <id column="id" property="id" />
                <result column="userid" property="userid" />
                <result column="taxmonth" property="taxmonth" />
                <result column="childrenedu" property="childrenedu" />
                <result column="houseloans" property="houseloans" />
                <result column="houserents" property="houserents" />
                <result column="supportolder" property="supportolder" />
                <result column="continueedu" property="continueedu" />
                <result column="totalmoney" property="totalmoney" />
                <result column="addtime" property="addtime" />
                <result column="qyid" property="qyid" />
    </resultMap>
    
    <resultMap id="AdditionalDeductionMap" type="cn.timer.api.dto.xcgl.AdditionalDeductionDto" >
                <result column="zxfjid" property="zxfjid" />
                <result column="date" property="date" />
                <result column="name" property="name" />
                <result column="phone" property="phone" />
                <result column="empNum" property="empNum" />
                <result column="zljy" property="zljy" />
                <result column="zfdk" property="zfdk" />
                <result column="zfzj" property="zfzj" />
                <result column="sylr" property="sylr" />
                <result column="jxjy" property="jxjy" />
                <result column="lj" property="lj" />
    </resultMap>

    <sql id="Base_Column_List">
                id,
                userid,
                taxmonth,
                childrenedu,
                houseloans,
                houserents,
                supportolder,
                continueedu,
                totalmoney,
                addtime,
                qyid
    </sql>
    
    <sql id="Base_Column_List_Alias">
                id XcglAssoZxfjkc_id,
                userid XcglAssoZxfjkc_userid,
                taxmonth XcglAssoZxfjkc_taxmonth,
                childrenedu XcglAssoZxfjkc_childrenedu,
                houseloans XcglAssoZxfjkc_houseloans,
                houserents XcglAssoZxfjkc_houserents,
                supportolder XcglAssoZxfjkc_supportolder,
                continueedu XcglAssoZxfjkc_continueedu,
                totalmoney XcglAssoZxfjkc_totalmoney,
                addtime XcglAssoZxfjkc_addtime,
                qyid XcglAssoZxfjkc_qyid
    </sql>
	
	<select id="selectAdditionalDeduction" resultMap="AdditionalDeductionMap">
		select emp.`name` as name,
			emp.emp_num as empNum,
			emp.phone,
			zxfj.id as zxfjid,
			zxfj.taxmonth as date,
			zxfj.childrenedu as zljy,
			zxfj.houseloans as zfdk,
			zxfj.houserents as zfzj,
			zxfj.supportolder as sylr,
			zxfj.continueedu as jxjy,
			zxfj.totalmoney as lj
		from yggl_main_emp emp
		LEFT JOIN xcgl_asso_zxfjkc as zxfj on zxfj.userid = emp.emp_num and zxfj.qyid = #{param.orgcode}
		<if test="param.datetime != ''" >
			and zxfj.taxmonth = #{param.datetime}
		</if>
		where emp.org_code = #{param.orgcode}
        <if test="param.status != null and param.status.size() >0" >
            and emp.job_status in
            <foreach collection="param.status" open="(" close=")" separator="," index="i" item="item">
                #{item, jdbcType=INTEGER}
            </foreach>
        </if>
		<if test="param.text != ''" >
			and (emp.`name` like CONCAT('%',#{param.text},'%') or emp.emp_num = #{param.text})
		</if>
	</select>
	
	<select id="selectAdditionalDeductiontwo" resultMap="AdditionalDeductionMap">
		select emp.`name` as name,
			emp.emp_num as empNum,
			emp.phone,
			zxfj.id as zxfjid,
			zxfj.taxmonth as date,
			zxfj.childrenedu as zljy,
			zxfj.houseloans as zfdk,
			zxfj.houserents as zfzj,
			zxfj.supportolder as sylr,
			zxfj.continueedu as jxjy,
			zxfj.totalmoney as lj
		from yggl_main_emp emp
		LEFT JOIN xcgl_asso_zxfjkc as zxfj on zxfj.userid = emp.emp_num 
		<if test="param.datetime != ''" >
			and zxfj.taxmonth = #{param.datetime}
		</if>
		where emp.org_code = #{param.orgcode}
        <if test="param.status != null and param.status.size() >0" >
            and emp.job_status in
            <foreach collection="param.status" open="(" close=")" separator="," index="i" item="item">
                #{item, jdbcType=INTEGER}
            </foreach>
        </if>
		<if test="param.text != ''" >
			and (emp.`name` like CONCAT('%',#{param.text},'%') or emp.emp_num = #{param.text})
		</if>
	</select>

    <insert id="insertXcglAssoZxfjkc" parameterType="cn.timer.api.bean.xcgl.XcglAssoZxfjkc" useGeneratedKeys="true" keyProperty="id">
        INSERT INTO xcgl_asso_zxfjkc
        <trim prefix="(" suffix=")" suffixOverrides=",">
                        <if test ='null != userid'>
                        userid,
                        </if>
                        <if test ='null != taxmonth'>
                        taxmonth,
                        </if>
                        <if test ='null != childrenedu'>
                        childrenedu,
                        </if>
                        <if test ='null != houseloans'>
                        houseloans,
                        </if>
                        <if test ='null != houserents'>
                        houserents,
                        </if>
                        <if test ='null != supportolder'>
                        supportolder,
                        </if>
                        <if test ='null != continueedu'>
                        continueedu,
                        </if>
                        <if test ='null != totalmoney'>
                        totalmoney,
                        </if>
                        <if test ='null != addtime'>
                        addtime,
                        </if>
                        <if test ='null != qyid'>
                        qyid
                        </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                        <if test ='null != userid'>
                        #{userid},
                        </if>
                        <if test ='null != taxmonth'>
                        #{taxmonth},
                        </if>
                        <if test ='null != childrenedu'>
                        #{childrenedu},
                        </if>
                        <if test ='null != houseloans'>
                        #{houseloans},
                        </if>
                        <if test ='null != houserents'>
                        #{houserents},
                        </if>
                        <if test ='null != supportolder'>
                        #{supportolder},
                        </if>
                        <if test ='null != continueedu'>
                        #{continueedu},
                        </if>
                        <if test ='null != totalmoney'>
                        #{totalmoney},
                        </if>
                        <if test ='null != addtime'>
                        #{addtime},
                        </if>
                        <if test ='null != qyid'>
                        #{qyid}
                        </if>
        </trim>
    </insert>

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

    <update id="updateXcglAssoZxfjkc" parameterType="cn.timer.api.bean.xcgl.XcglAssoZxfjkc">
        UPDATE xcgl_asso_zxfjkc
        <set>
                    <if test ='null != userid'>userid = #{userid},</if>
                    <if test ='null != taxmonth'>taxmonth = #{taxmonth},</if>
                    <if test ='null != childrenedu'>childrenedu = #{childrenedu},</if>
                    <if test ='null != houseloans'>houseloans = #{houseloans},</if>
                    <if test ='null != houserents'>houserents = #{houserents},</if>
                    <if test ='null != supportolder'>supportolder = #{supportolder},</if>
                    <if test ='null != continueedu'>continueedu = #{continueedu},</if>
                    <if test ='null != totalmoney'>totalmoney = #{totalmoney},</if>
                    <if test ='null != addtime'>addtime = #{addtime},</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_zxfjkc
        WHERE id = #{id}
    </select>

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

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

</mapper>