<?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.unis.projectManagement.modular.pmBudget.mapper.PmBudgetMapper">
    <select id="getProjectList" resultType="map">
        SELECT
            bpa.id pmApplicationId,
            bpa.project_name projectName
        FROM
            biz_pm_application bpa
        LEFT JOIN biz_pm_project_info ppi ON bpa.id = ppi.pm_application_id
        WHERE
            bpa.`status` = 3
    </select>
    <select id="getProjectCode" parameterType="string" resultType="map">
        SELECT
            bpa.id pmApplicationId,
            bpa.project_code projectCode,
            ppi.id pmProjectInfoId
        FROM
            biz_pm_application bpa
        LEFT JOIN biz_pm_project_info ppi ON bpa.id = ppi.pm_application_id
        WHERE
            bpa.id = #{id}
    </select>
    <select id="pageList" parameterType="com.baomidou.mybatisplus.core.conditions.Wrapper" resultType="com.unis.projectManagement.modular.pmBudget.entity.PmBudget">
        SELECT
            bpb.*,
            bpa.project_name projectName,
            bpa.project_code projectCode
        FROM
            biz_pm_budget bpb
        LEFT JOIN biz_pm_project_info ppi ON bpb.pm_project_info_id = ppi.id
        LEFT JOIN biz_pm_application bpa ON bpa.id = bpb.pm_application_id
        AND bpa.id = ppi.pm_application_id
        ${ew.customSqlSegment}
    </select>
    <select id="queryDetail" parameterType="string" resultType="com.unis.projectManagement.modular.pmBudget.entity.PmBudget">
        SELECT
            bpb.*,
            bpa.project_name projectName,
            bpa.project_code projectCode
        FROM
            biz_pm_budget bpb
        LEFT JOIN biz_pm_application bpa ON bpb.pm_application_id = bpa.id
        LEFT JOIN biz_pm_project_info ppi ON ppi.pm_application_id = bpa.id
        WHERE bpb.id = #{id}
    </select>
    <select id="selectByDetailId" parameterType="string" resultType="com.unis.projectManagement.modular.pmPerformance.entity.PmBudgetParam">
        SELECT DISTINCT
            bpb.id,
            bpa.project_code projectCode,
            bpa.project_name projectName,
            bpb.leading_department leadingDepartment,
            bpb.applicant,
            bpb.reviewer,
            bpb.construction_period constructionPeriod,
            bpb.funds_scale fundsScale,
            bpb.declaration_time declarationTime,
            bpb.performance_standard performanceStandard,
            bpb.construction_content_summary constructionContentSummary,
            bpb.proposal_design_or_construction_scheme proposalDesignOrConstructionScheme,
            bpb.remark,
            bpb.pm_project_info_id pmProjectInfoId,
            bpb.pm_application_id pmApplicationId,
            bpb.funds_source fundsSource,
            bar.audit_advice auditAdvice
        FROM
            biz_pm_performance bpp
        RIGHT JOIN biz_pm_budget bpb ON bpp.pm_budget_id = bpb.id
        LEFT JOIN biz_audit_request bar ON bar.request_id = bpp.id AND bpb.id = bar.request_id
        LEFT JOIN biz_pm_application bpa ON bpb.pm_application_id = bpa.id
        WHERE bpb.id = #{budgetId}
    </select>
</mapper>