<?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.ruoyi.web.work.mapper.PackagesMapper">
    
    <select id="selectList" resultType="com.ruoyi.web.work.domain.Packages">
        SELECT
        p.id,
        p.audit,
        p.state,
        p.msg,
        p.voucher,
        p.create_time,
        p.project_id,
        p.user_id,
        u.NAME,
        u.id_card,
        u.alipay,
        u.phone,
        u.bank_account,
        u.bank_name,
        t.project_name
        FROM
        tb_packages p
        LEFT JOIN tb_user u ON u.id = p.user_id
        LEFT JOIN tb_project t ON t.id=p.project_id
        <where>  
            <if test="userId != null "> and p.user_id = #{userId}</if>
            <if test="name != null  and name != ''"> and u.name like concat('%', #{name}, '%')</if>
            <if test="idCard != null  and idCard != ''"> and u.id_card like concat('%', #{idCard}, '%')</if>
            <if test="phone != null  and phone != ''"> and u.phone like concat('%', #{phone}, '%')</if>
            <if test="projectId != null "> and p.project_id = #{projectId}</if>
            <if test="companyId != null "> and p.company_id = #{companyId}</if>
            <if test="state != null "> and p.state = #{state}</if>
        </where>
    </select>

    <select id="selectPackagesList" resultType="com.ruoyi.web.work.domain.vo.PackagesListVo">
        SELECT
        a.id,
        a.audit,
        a.state,
        a.msg,
        a.voucher,
        a.create_time,
        p.project_name,
        p.balance_date,
        p.start_date,
        p.finish_date,
        c.company_name
        FROM
        tb_packages a
        LEFT JOIN tb_project p ON p.id = a.project_id
        LEFT JOIN tb_company c ON c.id=p.company_id
        WHERE a.user_id =#{userId} AND a.state = #{state}
    </select>

</mapper>