<?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.business.mapper.ImputationDataMapper">

    <resultMap id="imputationDataResult" type="ImputationData">
        <result property="year"    column="year"    />
        <result property="jan"    column="jan"    />
        <result property="feb"    column="feb"    />
        <result property="mar"    column="mar"    />
        <result property="apr"    column="apr"    />
        <result property="may"    column="may"    />
        <result property="jun"    column="jun"    />
        <result property="jul"    column="jul"    />
        <result property="aug"    column="aug"    />
        <result property="sep"    column="sep"    />
        <result property="oct"    column="oct"    />
        <result property="nov"    column="nov"    />
        <result property="decb"    column="decb"    />
    </resultMap>

    <sql id="selectImputationDataVo">
        select year, jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, decb from t_u_imputation_data
    </sql>

    <select id="selectImputationData" parameterType="ImputationData" resultMap="imputationDataResult">
        <include refid="selectImputationDataVo"/>
        <where>
            <if test="year != null  and year != ''"> and year = #{year}</if>
        </where>
    </select>

    <select id="selectImputationInterface" parameterType="ImputationData" resultType="ImputationData">
        select year, table_name tableName, interface_name interfaceName, jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, decb from t_u_imputation_interface
        <where>
            <if test="year != null  and year != ''"> and year = #{year}</if>
            <if test="tableName != null  and tableName != ''"> and table_name = #{tableName}</if>
            <if test="interfaceName != null  and interfaceName != ''"> and interface_name = #{interfaceName}</if>
        </where>
    </select>

    <insert id="insertImputationInterface" parameterType="ImputationData">
        insert into t_u_imputation_interface
            <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="year != null">year,</if>
                <if test="tableName != null">table_name,</if>
                <if test="interfaceName != null">interface_name,</if>
                <if test="jan != null">jan,</if>
                <if test="feb != null">feb,</if>
                <if test="mar != null">mar,</if>
                <if test="apr != null">apr,</if>
                <if test="may != null">may,</if>
                <if test="jun != null">jun,</if>
                <if test="jul != null">jul,</if>
                <if test="aug != null">aug,</if>
                <if test="sep != null">sep,</if>
                <if test="oct != null">oct,</if>
                <if test="nov != null">nov,</if>
                <if test="decb != null">decb,</if>
            </trim>
            <trim prefix="values (" suffix=")" suffixOverrides=",">
                <if test="year != null">#{year},</if>
                <if test="tableName != null">#{tableName},</if>
                <if test="interfaceName != null">#{interfaceName},</if>
                <if test="jan != null">#{jan},</if>
                <if test="feb != null">#{feb},</if>
                <if test="mar != null">#{mar},</if>
                <if test="apr != null">#{apr},</if>
                <if test="may != null">#{may},</if>
                <if test="jun != null">#{jun},</if>
                <if test="jul != null">#{jul},</if>
                <if test="aug != null">#{aug},</if>
                <if test="sep != null">#{sep},</if>
                <if test="oct != null">#{oct},</if>
                <if test="nov != null">#{nov},</if>
                <if test="decb != null">#{decb},</if>
            </trim>
    </insert>

    <update id="updateImputationInterfaceByYearMonthTableName" parameterType="ImputationData">
        update t_u_imputation_interface
            <trim prefix="SET" suffixOverrides=",">
                <if test="month == 1">jan = #{count},</if>
                <if test="month == 2">feb = #{count},</if>
                <if test="month == 3">mar = #{count},</if>
                <if test="month == 4">apr = #{count},</if>
                <if test="month == 5">may = #{count},</if>
                <if test="month == 6">jun = #{count},</if>
                <if test="month == 7">jul = #{count},</if>
                <if test="month == 8">aug = #{count},</if>
                <if test="month == 9">sep = #{count},</if>
                <if test="month == 10">oct = #{count},</if>
                <if test="month == 11">nov = #{count},</if>
                <if test="month == 12">decb = #{count},</if>
            </trim>
        where year = #{year} and table_name = #{tableName}
    </update>

    <insert id="insertImputationData" parameterType="ImputationData">
        insert into t_u_imputation_data
            <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="year != null">year,</if>
                <if test="jan != null">jan,</if>
                <if test="feb != null">feb,</if>
                <if test="mar != null">mar,</if>
                <if test="apr != null">apr,</if>
                <if test="may != null">may,</if>
                <if test="jun != null">jun,</if>
                <if test="jul != null">jul,</if>
                <if test="aug != null">aug,</if>
                <if test="sep != null">sep,</if>
                <if test="oct != null">oct,</if>
                <if test="nov != null">nov,</if>
                <if test="decb != null">decb,</if>
            </trim>
            <trim prefix="values (" suffix=")" suffixOverrides=",">
                <if test="year != null">#{year},</if>
                <if test="jan != null">#{jan},</if>
                <if test="feb != null">#{feb},</if>
                <if test="mar != null">#{mar},</if>
                <if test="apr != null">#{apr},</if>
                <if test="may != null">#{may},</if>
                <if test="jun != null">#{jun},</if>
                <if test="jul != null">#{jul},</if>
                <if test="aug != null">#{aug},</if>
                <if test="sep != null">#{sep},</if>
                <if test="oct != null">#{oct},</if>
                <if test="nov != null">#{nov},</if>
                <if test="decb != null">#{decb},</if>
            </trim>
    </insert>

    <update id="updateImputationData" parameterType="ImputationData">
        update t_u_imputation_data
        <trim prefix="SET" suffixOverrides=",">
            <if test="jan != null">jan = #{jan},</if>
            <if test="feb != null">feb = #{feb},</if>
            <if test="mar != null">mar = #{mar},</if>
            <if test="apr != null">apr = #{apr},</if>
            <if test="may != null">may = #{may},</if>
            <if test="jun != null">jun = #{jun},</if>
            <if test="jul != null">jul = #{jul},</if>
            <if test="aug != null">aug = #{aug},</if>
            <if test="sep != null">sep = #{sep},</if>
            <if test="oct != null">oct = #{oct},</if>
            <if test="nov != null">nov = #{nov},</if>
            <if test="decb != null">decb = #{decb},</if>
        </trim>
        where year = #{year}
    </update>

</mapper>
