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

    <resultMap id="BaseResultMap" type="com.engine.salary.entity.siaccount.dto.SIAccountUtilDTO">
        <result column="num" property="num"/>
        <result column="billmonth" property="billmonth"/>
        <result column="taxcycle" property="taxcycle"/>
    </resultMap>

    <select id="checkIfBusinessaccounting" resultMap="BaseResultMap">
        SELECT
        a.bill_month billmonth,c.tax_cycle taxcycle, c.salary_month salaryMonth, b.social_security_cycle_type socialSecurityCycleType
        FROM
        hrsa_bill_batch a,hrsa_salary_sob b,hrsa_salary_acct_record c
        WHERE
        a.payment_organization = b.tax_agent_id
        AND b.id=c.salary_sob_id
        AND a.id = #{id}
        AND a.delete_type = 0
        AND b.delete_type = 0
        AND c.delete_type = 0
        AND c.status != 1
    </select>
    <select id="checkBeforeDeleteSocialscheme" resultMap="BaseResultMap">
        SELECT
        COUNT(0) num
        FROM
        hrsa_social_archives
        WHERE
        delete_type = 0
        AND social_scheme_id IN
        <foreach collection="ids" open="(" item="id" separator="," close=")">
            #{id}
        </foreach>
    </select>

    <select id="checkBeforeDeleteAccumulationfund" resultMap="BaseResultMap">
        SELECT
        COUNT(0) num
        FROM
        hrsa_fund_archives
        WHERE
        delete_type = 0
        AND fund_scheme_id IN
        <foreach collection="ids" open="(" item="id" separator="," close=")">
            #{id}
        </foreach>
    </select>
    <select id="checkBeforeDeleteOtherscheme" resultMap="BaseResultMap">
        SELECT
        COUNT(0) num
        FROM
        hrsa_other_archives
        WHERE
        delete_type = 0
        AND other_scheme_id IN
        <foreach collection="ids" open="(" item="id" separator="," close=")">
            #{id}
        </foreach>
    </select>

    <select id="checkBeforeDeleteBill" resultMap="BaseResultMap">
        SELECT
        COUNT(0) num
        FROM
        hrsa_bill_detail
        WHERE
        delete_type = 0
        <if test="welfareTypeId == 1">
            AND social_scheme_id IN
            <foreach collection="ids" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="welfareTypeId == 2">
            AND fund_scheme_id IN
            <foreach collection="ids" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="welfareTypeId == 3">
            AND other_scheme_id IN
            <foreach collection="ids" open="(" item="id" separator="," close=")">
                #{id}
            </foreach>
        </if>
    </select>

</mapper>