<?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.engine.salary.mapper.siaccount.InsuranceAccountInspectMapper">
    <resultMap id="BaseResultMap" type="com.engine.salary.entity.siaccount.po.InsuranceAccountInspectPO">
        <result column="id" property="id"/>
        <result column="employee_id" property="employeeId"/>
        <result column="bill_month" property="billMonth"/>
        <result column="payment_status" property="paymentStatus"/>
        <result column="inspect_status" property="inspectStatus"/>
        <result column="supplementary_month" property="supplementaryMonth"/>
        <result column="supplementary_projects" property="supplementaryProjects"/>
        <result column="creator" property="creator"/>
        <result column="delete_type" property="deleteType"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
        <result column="tenant_key" property="tenantKey"/>
    </resultMap>

    <!-- 表字段 -->
    <sql id="baseColumns">
        t.id
        , t.employee_id
        , t.bill_month
        , t.payment_status
        , t.inspect_status
        , t.supplementary_month
        , t.supplementary_projects
        , t.creator
        , t.delete_type
        , t.create_time
        , t.update_time
        , t.tenant_key
    </sql>

    <select id="getByInspectStatusAndBillMonth" resultMap="BaseResultMap">
        SELECT
        <include refid="baseColumns"/>
        FROM
        hrsa_bill_inspect t
        WHERE t.delete_type = 0
        AND t.bill_month = #{billMonth}
        AND t.inspect_status = #{inspectStatus}
    </select>

    <sql id="paramSql">
        <if test="ids != null and ids.size()>0">
        AND  t.id IN
        <foreach collection="ids" open="(" item="id" separator="," close=")">
            #{id}
        </foreach>
        </if>

    </sql>

    <select id="getByInspectStatusAndIds" resultMap="BaseResultMap">
        SELECT
        <include refid="baseColumns"/>
        FROM
        hrsa_bill_inspect t
        WHERE t.delete_type = 0
        AND t.inspect_status = #{inspectStatus}
        <include refid="paramSql"/>
    </select>


    <select id="getList" resultMap="BaseResultMap">
        SELECT
        <include refid="baseColumns"/>
        FROM
        hrsa_bill_inspect t
        WHERE t.delete_type = 0
        AND t.inspect_status = #{inspectStatus}
        AND t.bill_month = #{billMonth}
        <include refid="paramSql"/>
    </select>

    <select id="getByBillMonth" resultMap="BaseResultMap">
        SELECT
        <include refid="baseColumns"/>
        FROM
        hrsa_bill_inspect t
        WHERE t.delete_type = 0
        AND t.bill_month = #{billMonth}
    </select>

    <!-- 批量删除 -->
    <delete id="batchDelInspectDetails">
        UPDATE hrsa_bill_inspect
        SET delete_type = 1
        WHERE delete_type = 0
        AND id IN
        <foreach collection="pos" open="(" item="po" separator="," close=")">
            #{po.id}
        </foreach>
    </delete>

    <!--- 批量保存-->
    <insert id="batchSaveInspectDetails">
        INSERT INTO  hrsa_bill_inspect
        (employee_id,bill_month,payment_status,inspect_status,supplementary_month,
        supplementary_projects,creator,delete_type,create_time,update_time,tenant_key)
        VALUES
        <foreach collection="pos" item="item" separator=",">
            (
            #{item.employeeId},
            #{item.billMonth},
            #{item.paymentStatus},
            #{item.inspectStatus},
            #{item.supplementaryMonth},
            #{item.supplementaryProjects},
            #{item.creator},
            #{item.deleteType},
            #{item.createTime},
            #{item.updateTime},
            #{item.tenantKey}
            )
        </foreach>
    </insert>
    <insert id="batchSaveInspectDetails" databaseId="oracle">
        INSERT INTO hrsa_bill_inspect
        (employee_id,bill_month,payment_status,inspect_status,supplementary_month,
        supplementary_projects,creator,delete_type,create_time,update_time,tenant_key)

        <foreach collection="pos" item="item" separator="union all">
            select
            #{item.employeeId,jdbcType=DOUBLE},
            #{item.billMonth,jdbcType=VARCHAR},
            #{item.paymentStatus,jdbcType=INTEGER},
            #{item.inspectStatus,jdbcType=INTEGER},
            #{item.supplementaryMonth,jdbcType=VARCHAR},
            #{item.supplementaryProjects,jdbcType=VARCHAR},
            #{item.creator,jdbcType=DOUBLE},
            #{item.deleteType,jdbcType=INTEGER},
            #{item.createTime,jdbcType=DATE},
            #{item.updateTime,jdbcType=DATE},
            #{item.tenantKey,jdbcType=VARCHAR}
            from dual
        </foreach>
    </insert>
    <insert id="batchSaveInspectDetails" databaseId="sqlserver">
        <foreach collection="pos" item="item" separator=";">
        INSERT INTO  hrsa_bill_inspect
        (employee_id,bill_month,payment_status,inspect_status,supplementary_month,
        supplementary_projects,creator,delete_type,create_time,update_time,tenant_key)
        VALUES
            (
            #{item.employeeId},
            #{item.billMonth},
            #{item.paymentStatus},
            #{item.inspectStatus},
            #{item.supplementaryMonth},
            #{item.supplementaryProjects},
            #{item.creator},
            #{item.deleteType},
            #{item.createTime},
            #{item.updateTime},
            #{item.tenantKey}
            )
        </foreach>
    </insert>


</mapper>