<?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.yifu.cloud.plus.v1.yifu.salary.mapper.THaveSalaryNosocialMapper">
    <resultMap id="tHaveSalaryNosocialMap" type="com.yifu.cloud.plus.v1.yifu.salary.entity.THaveSalaryNosocial">
        <id property="id" column="ID"/>
        <result property="employeeId" column="employee_id"/>
        <result property="employeeName" column="employee_name"/>
        <result property="employeeIdCard" column="employee_id_card"/>
        <result property="customerId" column="Customer_id"/>
        <result property="settleDomainId" column="settle_domain_id"/>
        <result property="customerName" column="CUSTOMER_NAME"/>
        <result property="settlementOrganName" column="SETTLEMENT_ORGAN_NAME"/>
        <result property="settlementOrganNo" column="SETTLEMENT_ORGAN_NO"/>
		<result property="feedBack" column="FEED_BACK"/>
		<result property="reasonType" column="REASON_TYPE"/>
        <result property="month" column="month"/>
    </resultMap>
	<resultMap id="haveSalaryNoSocialExportMap" type="com.yifu.cloud.plus.v1.yifu.salary.vo.THaveSalaryNoSocialExportVo">
		<result property="customerName" column="CUSTOMER_NAME"/>
		<result property="settlementOrganName" column="SETTLEMENT_ORGAN_NAME"/>
		<result property="employeeName" column="employee_name"/>
		<result property="employeeIdCard" column="employee_id_card"/>
		<result property="month" column="month"/>
		<result property="relaySalary" column="RELAY_SALARY"/>
		<result property="createName" column="CREATE_NAME"/>
		<result property="feedBack" column="FEED_BACK"/>

	</resultMap>
    <sql id="Base_Column_List">
             a.ID,
                  a.employee_id,
                  a.employee_name,
                  a.employee_id_card,
                  a.Customer_id,
                  a.settle_domain_id,
                  a.CUSTOMER_NAME,
                  a.SETTLEMENT_ORGAN_NAME,
                  a.SETTLEMENT_ORGAN_NO,
                  a.month,
                  a.CREATE_MONTH,
                  a.relay_salary,
                  a.FEED_BACK,
				  a.CREATE_NAME,
				 a.REASON_TYPE
         </sql>
    <sql id="tHaveSalaryNosocial_where">
        <if test="tHaveSalaryNosocial != null">
            <if test="tHaveSalaryNosocial.id != null and tHaveSalaryNosocial.id.trim() != ''">
                AND a.ID = #{tHaveSalaryNosocial.id}
            </if>
            <if test="tHaveSalaryNosocial.employeeId != null and tHaveSalaryNosocial.employeeId.trim() != ''">
                AND a.employee_id = #{tHaveSalaryNosocial.employeeId}
            </if>
            <if test="tHaveSalaryNosocial.employeeName != null and tHaveSalaryNosocial.employeeName.trim() != ''">
                AND a.employee_name = #{tHaveSalaryNosocial.employeeName}
            </if>
            <if test="tHaveSalaryNosocial.employeeIdCard != null and tHaveSalaryNosocial.employeeIdCard.trim() != ''">
                AND a.employee_id_card = #{tHaveSalaryNosocial.employeeIdCard}
            </if>
            <if test="tHaveSalaryNosocial.customerId != null and tHaveSalaryNosocial.customerId.trim() != ''">
                AND a.Customer_id = #{tHaveSalaryNosocial.customerId}
            </if>
            <if test="tHaveSalaryNosocial.settleDomainId != null and tHaveSalaryNosocial.settleDomainId.trim() != ''">
                AND a.settle_domain_id = #{tHaveSalaryNosocial.settleDomainId}
            </if>
            <if test="tHaveSalaryNosocial.customerName != null and tHaveSalaryNosocial.customerName.trim() != ''">
                AND a.CUSTOMER_NAME  LIKE CONCAT('%', #{tHaveSalaryNosocial.customerName},'%')
            </if>
            <if test="tHaveSalaryNosocial.settlementOrganName != null and tHaveSalaryNosocial.settlementOrganName.trim() != ''">
                AND a.SETTLEMENT_ORGAN_NAME LIKE CONCAT('%',  #{tHaveSalaryNosocial.settlementOrganName},'%')
            </if>
            <if test="tHaveSalaryNosocial.settlementOrganNo != null and tHaveSalaryNosocial.settlementOrganNo.trim() != ''">
                AND a.SETTLEMENT_ORGAN_NO LIKE CONCAT('%',  #{tHaveSalaryNosocial.settlementOrganNo},'%')
            </if>
            <if test="tHaveSalaryNosocial.month != null">
                AND a.month = #{tHaveSalaryNosocial.month}
            </if>
            <if test="tHaveSalaryNosocial.createMonth != null">
                AND a.CREATE_MONTH = #{tHaveSalaryNosocial.createMonth}
            </if>
			<if test="tHaveSalaryNosocial.createName != null">
				AND a.CREATE_NAME = #{tHaveSalaryNosocial.createName}
			</if>
        </if>
    </sql>

    <!--tHaveSalaryNosocial简单分页查询-->
    <select id="getTHaveSalaryNosocialPage" resultMap="tHaveSalaryNosocialMap">
        SELECT
        a.id,
		a.employee_name,
		a.employee_id_card,
		a.CUSTOMER_NAME,
		a.SETTLEMENT_ORGAN_NAME,
		a.month,
		a.relay_salary,
		a.CREATE_NAME,
               a.feed_back,a.reason_type
        FROM t_have_salary_nosocial a
        <include refid="querPage"/>
    </select>
    <select id="getByIdExport" resultType="com.yifu.cloud.plus.v1.yifu.salary.entity.THaveSalaryNosocial">
        SELECT
        <include refid="Base_Column_List"/>
        ,b.*
        FROM t_have_salary_nosocial a   left join t_feed_back b  on  a.ID=b.RELATE_ID
        where 1=1 and ((b.IGNORE_FLAG=1 and b.TYPE=1) or (b.id is null))
        <if test="array.length > 0">
            and a.id in
            <foreach collection="array" item="id" index="index" open="(" close=")" separator=",">
                #{id}
            </foreach>
        </if>
        <if test="array.length == 0">
            and 1=2
        </if>

    </select>
    <select id="getExport" resultType="com.yifu.cloud.plus.v1.yifu.salary.entity.THaveSalaryNosocial">
        SELECT
        <include refid="Base_Column_List"/>
        ,b.*
        FROM t_have_salary_nosocial a
       <include refid="querPage"/>
    </select>



    <select id="getByIdHandleExport" resultType="com.yifu.cloud.plus.v1.yifu.salary.vo.THaveSalaryNosocialHandleExportVo">
        SELECT
        <include refid="Base_Column_List"/>
        ,b.*
        FROM t_have_salary_nosocial a   left join t_feed_back b  on  a.ID=b.RELATE_ID
        where 1=1 and ((b.IGNORE_FLAG=1 and b.TYPE=1) or (b.id is null))
        <if test="array.length > 0">
            and a.id in
            <foreach collection="array" item="id" index="index" open="(" close=")" separator=",">
                #{id}
            </foreach>
        </if>
        <if test="array.length == 0">
            and a.id in ('')
        </if>

    </select>
    <select id="getHandleExport" resultType="com.yifu.cloud.plus.v1.yifu.salary.vo.THaveSalaryNosocialHandleExportVo">
        SELECT
        <include refid="Base_Column_List"/>
        ,b.*
        FROM t_have_salary_nosocial a
        left join t_feed_back b  on  a.ID=b.RELATE_ID
        <where>
            1=1 and ((b.IGNORE_FLAG=1 and b.TYPE=1) or (b.id is null))
            <if test="tHaveSalaryNosocial.reasonType != null and tHaveSalaryNosocial.reasonType.trim() != ''">
                AND b.REASON_TYPE = #{tHaveSalaryNosocial.reasonType}
            </if>
            <include refid="tHaveSalaryNosocial_where"/>
        </where>
    </select>



    <sql id="querPage">
        left join t_feed_back b  on  a.ID=b.RELATE_ID
        <where>
            1=1 and ((b.IGNORE_FLAG=1 and b.TYPE=1) or (b.id is null))
            <include refid="tHaveSalaryNosocial_where"/>
            <!--数据权限判断-->
            <if test="settleDomainVos != null">
                <if test="settleDomainVos.size() > 0">
                    and a.SETTLE_DOMAIN_ID in
                    <foreach collection="settleDomainVos" item="param" index="index" open="(" close=")" separator=",">
                        #{param.id}
                    </foreach>
                </if>
                <if test="settleDomainVos.size() == 0">
                    and 1=2
                </if>
            </if>
            <if test="settleDomainVos == null">
                and 1=1
            </if>
        </where>
    </sql>


    <select id="getTHaveSalaryNosocialHandelPage" resultMap="tHaveSalaryNosocialMap">
        SELECT
        <include refid="Base_Column_List"/>
        ,b.*
        FROM t_have_salary_nosocial a
        left join t_feed_back b  on  a.ID=b.RELATE_ID
        <where>
            1=1 and ((b.IGNORE_FLAG=1 and b.TYPE=1) or (b.id is null))
            <if test="tHaveSalaryNosocial.reasonType != null ">
                AND b.REASON_TYPE = #{tHaveSalaryNosocial.reasonType}
            </if>
            <include refid="tHaveSalaryNosocial_where"/>
        </where>
    </select>

    <select id="getLastTHaveSalaryNosocial" resultType="com.yifu.cloud.plus.v1.yifu.salary.entity.THaveSalaryNosocial">
        SELECT
        <include refid="Base_Column_List"/>
        ,b.*
        FROM t_have_salary_nosocial a
        left join t_feed_back b  on  a.ID=b.RELATE_ID
        where  a.CREATE_MONTH in(#{lastOneMonth},#{lastTwoMonth},#{lastThreeMonth}) and b.REASON_TYPE is not null

    </select>
	<select id="noPageDiy" resultMap="haveSalaryNoSocialExportMap">
		SELECT
		<include refid="Base_Column_List"/>
		,b.*
		FROM t_have_salary_nosocial a
		left join t_feed_back b  on  a.ID=b.RELATE_ID
		<where>
			1=1 and ((b.IGNORE_FLAG=1 and b.TYPE=1) or (b.id is null))
			<include refid="export_where"/>
		</where>
	</select>
	<select id="noPageCountDiy"  resultType="java.lang.Integer">
		SELECT
		count(1)
		FROM t_have_salary_nosocial a
		left join t_feed_back b  on  a.ID=b.RELATE_ID
		<where>
			1=1 and ((b.IGNORE_FLAG=1 and b.TYPE=1) or (b.id is null))
			<include refid="export_where"/>
		</where>
	</select>
	<sql id="export_where">
		<include refid="tHaveSalaryNosocial_where"/>
		<if test="idsStr != null and idsStr.size > 0">
			AND a.ID in
			<foreach item="items" index="index" collection="idsStr" open="(" separator="," close=")">
				#{items}
			</foreach>
		</if>
		<!--数据权限判断-->
		<if test="settleDomainIds != null">
			<if test="settleDomainIds.size() > 0">
				and a.SETTLE_DOMAIN_ID in
				<foreach collection="settleDomainIds" item="param" index="index" open="(" close=")" separator=",">
					#{param}
				</foreach>
			</if>
			<if test="settleDomainIds.size() == 0">
				and 1=2
			</if>
		</if>
		<if test="settleDomainIds == null">
			and 1=1
		</if>
		<if test='sql != null and sql != ""'>
			and <![CDATA[sql]]>
		</if>
	</sql>
</mapper>