<?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="cn.com.countrygarden.bi.main.dao.ck.CkCleanerBasicMapper">
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="cn.com.countrygarden.bi.main.model.ck.CkCleanerBasic">
        <id column="id" property="id"/>
        <result column="org_code" property="orgCode"/>
        <result column="org_name" property="orgName"/>
        <result column="comm_name" property="commName"/>
        <result column="comm_code" property="commCode"/>
        <result column="month" property="month"/>
        <result column="year" property="year"/>
        <result column="status" property="status"/>
        <result column="create_by" property="createBy"/>
        <result column="create_time" property="createTime"/>
        <result column="update_by" property="updateBy"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>
    <select id="inheritBasicInfo" resultMap="BaseResultMap">
        SELECT id,org_code , org_name , comm_name,comm_code,month , year , org_name FROM `ck_cleaner_basic`
        <where>
            status=1
            <if test="query.orgCode !=null and query.orgCode !=''">
                and org_code =#{query.orgCode}
            </if>
            <if test="query.year !=null and query.year !=''">
                and year =#{query.year}
            </if>
            <if test="query.month !=null and query.month !=''">
                and month =#{query.month}
            </if>
            <if test="query.id !=null ">
                and id  <![CDATA[<>]]> #{query.id}
            </if>
            <choose>
                <when test=" query.commCode !=null and query.commCode !='' and query.commCode=='empty'">
                    and (ISNULL(comm_code) or comm_code="")
                </when>
                <otherwise>
                    and comm_code=#{query.commCode}
                </otherwise>
            </choose>

        </where>
    </select>

    <select id="statisProjDetadNot" resultType="cn.com.countrygarden.bi.main.dto.ck.CkCleanerTableVo">
         SELECT DISTINCT cb.id AS id,cb.org_name AS orgName,cb.comm_name AS commName,cb.month AS `month`,cb.year AS `year`,cb.create_time FROM ck_cleaner_basic cb
         WHERE (cb.status=0 OR cb.status=2) and cb.month=#{month} and cb.year=#{year}
        <if test="orgCode!=null and orgCode!=''">
            and cb.org_code=#{orgCode}
        </if>
         ORDER BY cb.create_time DESC
    </select>

    <select id="statisPr" resultType="cn.com.countrygarden.bi.main.model.ck.CkCleanerBasic">
         SELECT DISTINCT cb.id AS id,cb.org_code as orgCode,cb.org_name AS orgName,cb.comm_code as commCode,cb.comm_name AS commName,cb.month AS `month`,cb.year AS `year` FROM ck_cleaner_basic cb
         WHERE (cb.status=0 OR cb.status=1) and cb.month=#{ckCleanerBasic.month} and cb.year=#{ckCleanerBasic.year}
         and cb.org_code=#{ckCleanerBasic.orgCode} and cb.comm_code=#{ckCleanerBasic.commCode}
    </select>

    <select id="selectBasic" resultMap="BaseResultMap" useCache="false">

          SELECT id,org_code,org_name,comm_code,comm_name,`month`,`year`,`status` FROM ck_cleaner_basic
          where `status` = 1 AND org_code = #{ckCleanerBasic.orgCode} AND comm_code = #{ckCleanerBasic.commCode} AND `month` = #{ckCleanerBasic.month} AND `year` = #{ckCleanerBasic.year}
        <if test="ckCleanerBasic.id!=null">
        <![CDATA[
            and id <> #{ckCleanerBasic.id}
             ]]>
        </if>

    </select>
</mapper>