<?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.dsk.cscec.mapper.CbProjectRecordMapper">
    <!--获取项目台账列表-->
    <select id="selectPageProjectRecordList" resultType="com.dsk.cscec.domain.vo.CbProjectRecordSearchVo">
        select a.*
        from (
        select DISTINCT cpr.id,
        cpr.related_id,
        cpr.project_name,
        cpr.cb_stage,
        cpr.project_file_status,
        cpr.ipm_project_no,
        cpr.is_get_project_detail,
        cpr.project_file_name,
        cpr.del_flag,
        cpr.create_by,
        cpr.create_time
        from cb_project_record cpr
        where cpr.del_flag=#{deleteFlagExist}
        <if test="searchBo.projectName != null and searchBo.projectName != ''">
            and cpr.project_name like concat('%',#{searchBo.projectName},'%')
        </if>
        <if test="searchBo.ipmProjectNo != null and searchBo.ipmProjectNo != ''">
            and cpr.ipm_project_no = #{searchBo.ipmProjectNo}
        </if>
        <if test="searchBo.cbStage != null">
            and cpr.cb_stage = #{searchBo.cbStage}
        </if>
        <if test="searchBo.projectFileStatus != null">
            and project_file_status = #{searchBo.projectFileStatus}
        </if>
        and
        cpr.project_file_status != #{projectFileStatusPreparing}
        or
        cpr.cb_stage = #{cbStageNoCostPlan}
        and
        cpr.del_flag=#{deleteFlagExist}
        <if test="searchBo.projectName != null and searchBo.projectName != ''">
            and cpr.project_name like concat('%',#{searchBo.projectName},'%')
        </if>
        <if test="searchBo.ipmProjectNo != null and searchBo.ipmProjectNo != ''">
            and cpr.ipm_project_no = #{searchBo.ipmProjectNo}
        </if>
        <if test="searchBo.cbStage != null">
            and cpr.cb_stage = #{searchBo.cbStage}
        </if>
        <if test="searchBo.projectFileStatus != null">
            and project_file_status = #{searchBo.projectFileStatus}
        </if>
        order by cpr.cb_stage desc) a
        group by a.related_id
        order by a.create_time desc
    </select>

    <!--获取草稿弹窗列表-->
    <select id="selectPageDraftDialogList" resultType="com.dsk.cscec.domain.CbProjectRecord">
        select cpr.id,
               cpr.project_name,
               cpr.cb_stage,
               cpr.update_time
        from cb_project_record cpr
            ${ew.getCustomSqlSegment};
    </select>
</mapper>