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

    <sql id="selectStatementVo">
        SELECT
            s.id,
            s.num,
            s.state,
            s.audit,
            s.give,
            s.batch_name,
            s.file_name,
            s.service_company,
            s.create_time,
            s.generate_time,
            s.submit_time,
            s.audit_time,
            s.give_time,
            ( SELECT COUNT( d.id ) FROM tb_statement_detail d WHERE d.statement_id = s.id ) AS peoples,
            ( SELECT SUM( d.money ) FROM tb_statement_detail d WHERE d.statement_id = s.id ) AS money,
            p.project_name
        FROM
            tb_statement s
                LEFT JOIN tb_project p ON p.id = s.project_id
    </sql>
    <select id="selectList" resultType="com.ruoyi.web.work.domain.Statement">
        <include refid="selectStatementVo"/>
        <where>  
            <if test="companyId != null "> and s.company_id = #{companyId}</if>
            <if test="batchName != null  and batchName != ''"> and s.batch_name like concat('%', #{batchName}, '%')</if>
            <if test="num != null  and num != ''"> and s.num like concat('%', #{num}, '%')</if>
            <if test="projectId != null "> and s.project_id = #{projectId}</if>
            <if test="state != null "> and s.state = #{state}</if>
            <if test="give != null "> and s.give = #{give}</if>
            <choose>
                <when test="auditors">
                    <if test="audit == null "> and s.audit <![CDATA[ >= ]]> 1</if>
                    <if test="audit != null "> and s.audit=#{audit} and s.audit <![CDATA[ >= ]]> 1</if>
                </when>
                <otherwise>
                    <if test="audit != null "> and s.audit = #{audit}</if>
                </otherwise>
            </choose>
        </where>
    </select>
    <!--结算单审核列表-->
    <select id="selectAuditList" resultType="com.ruoyi.web.work.domain.Statement">
        <include refid="selectStatementVo"/>
        <where>
            <if test="companyId != null "> and s.company_id = #{companyId}</if>
            <if test="batchName != null  and batchName != ''"> and s.batch_name like concat('%', #{batchName}, '%')</if>
            <if test="num != null  and num != ''"> and s.num like concat('%', #{num}, '%')</if>
            <if test="state != null "> and s.state = #{state}</if>
            <if test="projectId != null "> and s.project_id = #{projectId}</if>

        </where>
    </select>

</mapper>