<?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.sunxung.factoring.mapper.signconfirmation.SignConfirmationMapper">

    <resultMap type="com.sunxung.factoring.entity.project.vo.BusinessProcessingTaskVo" id="baseResultMap">
        <result property="id" column="id" />
        <result property="moduleNumber" column="acceptance_number" />
        <result property="businessNumber" column="business_number" />
        <result property="customerName" column="customerName" />
        <result property="businessName" column="business_name" />
        <result property="supplierName" column="supplierName" />
        <result property="comeFrom" column="comeFrom" />
        <result property="expectedSettlementTime" column="expected_settlement_date" />
        <result property="gmtModified" column="gmt_modified" />
        <association property="status" column="acceptance_status" resultMap="dictionaryResult" />
    </resultMap>

    <resultMap id="dictionaryResult" type="Dictionary">
        <result property="id" column="did" />
        <result property="name" column="dname" />
        <result property="code" column="dcode" />
    </resultMap>

    <select id="findMyCompletedList" parameterType="com.sunxung.factoring.entity.project.vo.SearchBusinessProcessingTask" resultMap="baseResultMap">
        SELECT DISTINCT
        t2.id,
        t2.business_name ,
        t2.business_number,
        t3.enterprise_name customerName,
        t2.comeFrom,
        t2.gmt_modified ,
        t4.id did,
        t4.code dcode,
        t4.name dname
        FROM business_processing_log t1
        LEFT JOIN sign_confirmation t2 ON t1.busness_key = t2.id
        LEFT JOIN enterprise_customer_info t3 ON t2.enterprise_customer_info_id = t3.id
        LEFT JOIN t_dictionary t4 ON t2.status_id = t4.id
        <where>
            t1.business_type = 'SignConfirmation'
            AND t1.end_time IS NOT NULL
            <if test="userId != null">
                AND t1.assignee_id = #{userId}
            </if>
            <if test="fastSearch != null and fastSearch !=''">
                AND (t2.business_number LIKE concat('%',#{fastSearch},'%')
                OR t2.enterprise_customer_info_id in (select id from enterprise_customer_info where enterprise_name like concat('%',#{fastSearch},'%') and supplier ="0" ) OR t3.business_number like concat('%',#{fastSearch},'%')
                OR t2.business_name like concat('%',#{fastSearch},'%')  )
            </if>
        </where>
        GROUP BY t1.busness_key,t2.gmt_create
        ORDER BY t2.gmt_modified DESC
    </select>
    <select id="findAllList" parameterType="com.sunxung.factoring.entity.project.vo.SearchBusinessProcessingTask" resultMap="baseResultMap">
        SELECT DISTINCT
        t2.id,
        t2.business_name ,
        t2.business_number,
        t3.enterprise_name customerName,
        t2.comeFrom,
        t2.gmt_modified ,
        t4.id did,
        t4.code dcode,
        t4.name dname
        FROM business_processing_log t1
        LEFT JOIN sign_confirmation t2 ON t1.busness_key = t2.id
        LEFT JOIN enterprise_customer_info t3 ON t2.enterprise_customer_info_id = t3.id
        LEFT JOIN t_dictionary t4 ON t2.status_id = t4.id
        <where>
            t1.business_type = 'SignConfirmation'
            AND t1.end_time IS NOT NULL
            <if test="userIds != null and userIds.size()>0">
                AND t1.assignee_id in
                <foreach collection="userIds" index="index" item="item"  open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="fastSearch != null and fastSearch !=''">
                AND (t2.business_number LIKE concat('%',#{fastSearch},'%')
                OR t2.enterprise_customer_info_id in (select id from enterprise_customer_info where enterprise_name like concat('%',#{fastSearch},'%') and supplier ="0" ) OR t3.business_number like concat('%',#{fastSearch},'%')
                OR t2.business_name like concat('%',#{fastSearch},'%')  )
            </if>
            <if test="statusId != null and statusId !=''">
                and t2.status_id = #{statusId}
            </if>
        </where>
        GROUP BY t1.busness_key,t2.gmt_create
        ORDER BY t2.gmt_modified DESC
    </select>
</mapper>
