<?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.hotent.project.dao.CostAnnualPlanDao">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hotent.project.model.CostAnnualPlan">
        <id column="plan_id" property="planId"/>
        <result column="plan_year" property="planYear"/>
        <result column="area_code" property="areaCode"/>
        <result column="area_level" property="areaLevel"/>
        <result column="catalog_id" property="catalogId"/>
        <result column="project_name" property="projectName"/>
        <result column="audit_time" property="auditTime"/>
        <result column="audit_type" property="auditType"/>
        <result column="org_id" property="orgId"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="create_time" property="createTime"/>
        <result column="create_by" property="createBy"/>
        <result column="update_time" property="updateTime"/>
        <result column="update_by" property="updateBy"/>
        <result column="audited_unit_id" property="auditedUnitId"/>
        <result column="audited_unit_name" property="auditedUnitName"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        plan_id
        , plan_year , area_code,area_level, catalog_id, project_name, audit_time, audit_type, org_id, is_deleted, create_time, create_by, update_time, update_by, audited_unit_id, audited_unit_name
    </sql>

    <select id="selectPage" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from
        cost_annual_plan
        ${ew.customSqlSegment}
    </select>

    <select id="selectList" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from
        cost_annual_plan
        ${ew.customSqlSegment}
    </select>

    <select id="selectById" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from
        cost_annual_plan
        where
        plan_id = ${planId}
    </select>

    <select id="getCostAnnualPlanPage"
            resultMap="BaseResultMap">
        SELECT
        c.*
        FROM
        cost_annual_plan c,
        uc_user u
        WHERE
        c.create_by=u.ID_
        <if test=" planYear != null and  planYear != ''">
            and c.plan_year=#{planYear}
        </if>
        <if test=" areaCode != null and  areaCode != ''">
            and c.area_code=#{areaCode}
        </if>

        <if test=" projectName != null and  projectName != ''">
            and c.project_name LIKE CONCAT('%', #{projectName}, '%')
        </if>

        <if test=" dataScope != null and  dataScope != ''">
            <if test=" dataScope ==1">
                and  (u.CITY_CODE=#{ cityCode} or c.area_code=#{ cityCode})
            </if>
            <if test=" dataScope ==2">
                and (u.COUNTY_CODE=#{ countyCode} or c.area_code=#{ countyCode})
            </if>
        </if>
        ORDER BY c.create_time DESC
    </select>



</mapper>
