<?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.ProjectMapper">
    
    <select id="selectList" resultType="com.ruoyi.web.work.domain.Project">
        SELECT
        p.id,
        p.project_name,
        p.num,
        p.create_by,
        p.create_time,
        p.start_date,
        p.finish_date,
        p.balance_date,
        p.state,
        p.service_company,
        ( SELECT COUNT( a.id ) FROM tb_packages a WHERE a.project_id = p.id ) AS peoples
        FROM
        tb_project p
        <where>  
            <if test="companyId != null "> and p.company_id = #{companyId}</if>
            <if test="projectName != null  and projectName != ''"> and p.project_name like concat('%', #{projectName}, '%')</if>
            <if test="num != null  and num != ''"> and p.num like concat('%', #{num}, '%') </if>
            <if test="state != null "> and p.state = #{state}</if>
            <if test="dateBegin != null  and dateBegin != ''"> AND p.create_time BETWEEN #{dateBegin} AND #{dateEnd} + INTERVAL 1 DAY</if>
        </where>
    </select>
    <!--小程序待接包-->
    <select id="selectProjectList" resultType="com.ruoyi.web.work.domain.vo.ProjectListVo">
        SELECT
        p.*,
        c.company_name
        FROM
        tb_project p
        LEFT JOIN tb_company c ON c.id = p.company_id
        WHERE
        p.state = 0
        AND c.state =0
        AND p.company_id IN (<foreach collection="companyIds" item="name" separator=",">#{name}</foreach>)
        AND p.id NOT IN (<foreach collection="projectIds" item="name" separator=",">#{name}</foreach>)
        ORDER BY p.id DESC
    </select>

</mapper>