<?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.res.CkResourcesRevenueMapper">
    <resultMap id="BaseResultMap" type="cn.com.countrygarden.bi.main.model.ck.res.CkResourcesRevenue">
        <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="time_month" property="timeMonth"/>
        <result column="re_parking" property="reParking"/>
        <result column="re_media" property="reMedia"/>
        <result column="re_field" property="reField"/>
        <result column="re_total" property="reTotal"/>
        <result column="ne_parking" property="neParking"/>
        <result column="ne_media" property="neMedia"/>
        <result column="ne_field" property="neField"/>
        <result column="ne_total" property="neTotal"/>
        <result column="expenditure" property="expenditure"/>
        <result column="status" property="status"/>
        <result column="create_by" property="createBy"/>
        <result column="create_time" property="createTime"/>
        <result column="create_name" property="createName"/>
        <result column="update_by" property="updateBy"/>
        <result column="update_time" property="updateTime"/>
        <result column="data_status" property="dataStatus"/>
        <result column="audit_by" property="auditBy"/>
        <result column="audit_name" property="auditName"/>
        <result column="audit_time" property="auditTime"/>
    </resultMap>

    <select id="selectListData" resultMap="BaseResultMap">
       SELECT `id`,`org_code`, `org_name`,`comm_code`,`comm_name`,`time_month`,`re_parking`,`re_media`,
 `re_field`,`re_total`,`ne_parking`,`ne_media`,`ne_field`,`ne_total`,`expenditure`,`create_time`,`create_name`,
 `data_status`,`audit_name`,audit_time,audit_by
  FROM `ck_resources_revenue`
  WHERE `status`=1

  <if test="cleanerQueyr.orgCode!=null and cleanerQueyr.orgCode!=''">
      and org_code=#{cleanerQueyr.orgCode}
  </if>
 <if test="cleanerQueyr.commCode!=null and cleanerQueyr.commCode!=''">
     AND comm_code=#{cleanerQueyr.commCode}
 </if>
        <if test="time!=null and time.size()!=0">
            AND time_month in
            <foreach collection="time" item="time" index="index" open="(" close=")" separator=",">
                #{time}
            </foreach>
        </if>
        <if test="organCodeString!=null and organCodeString.size()!=0">
            and (org_code in
            <foreach collection="organCodeString" item="organCodeString" index="index" open="(" close=")" separator=",">
                #{organCodeString}
            </foreach>
        </if>
        <if test="commIdString!=null and commIdString.size()!=0">
            or comm_code in
            <foreach collection="commIdString" item="commIdString" index="index" open="(" close=")" separator=",">
                #{commIdString}
            </foreach>
            )
        </if>
        order by create_time desc
    </select>

    <select id="selectListDataToble" resultType="long">
           SELECT COUNT(id) FROM `ck_resources_revenue`
          WHERE `status`=1
        <if test="cleanerQueyr.orgCode!=null and cleanerQueyr.orgCode!=''">
            and org_code=#{cleanerQueyr.orgCode}
        </if>
        <if test="cleanerQueyr.commCode!=null and cleanerQueyr.commCode!=''">
            AND comm_code=#{cleanerQueyr.commCode}
        </if>
        <if test="time!=null and time.size()!=0">
            AND time_month in
            <foreach collection="time" item="time" index="index" open="(" close=")" separator=",">
                #{time}
            </foreach>
        </if>
        <if test="organCodeString!=null and organCodeString.size()!=0">
            and (org_code in
            <foreach collection="organCodeString" item="organCodeString" index="index" open="(" close=")" separator=",">
                #{organCodeString}
            </foreach>
        </if>
        <if test="commIdString!=null and commIdString.size()!=0">
            or comm_code in
            <foreach collection="commIdString" item="commIdString" index="index" open="(" close=")" separator=",">
                #{commIdString}
            </foreach>
            )
        </if>
    </select>

    <select id="selectGetrevenue" resultMap="BaseResultMap">
   SELECT `org_code`, `org_name`,`comm_code`,`comm_name`,`time_month`,`re_parking`,`re_media`,
  `re_field`,`re_total`,`ne_parking`,`ne_media`,`ne_field`,`ne_total`,`expenditure`,`create_time`,`create_name`,
  `audit_name`,audit_time,data_status
   FROM `ck_resources_revenue`
   WHERE `status`=1 AND data_status=1
   <if test="commCode!=null and commCode!=''">
       and comm_code=#{commCode}
   </if>
   <if test="updateDate!=null and updateDate!=''">
       and update_time >= #{updateDate}
   </if>
    </select>

    <select id="selectckResoRevtishi" resultMap="BaseResultMap">
          SELECT `id`,`org_code`, `org_name`,`comm_code`,`comm_name`,`time_month`,`re_parking`,`re_media`,
 `re_field`,`re_total`,`ne_parking`,`ne_media`,`ne_field`,`ne_total`,`expenditure`,`create_time`,`create_name`,
 `data_status`,`audit_name`,audit_time,audit_by
  FROM `ck_resources_revenue`
  WHERE `status`=1 and data_status=#{ckResoRev.dataStatus} and audit_by=#{ckResoRev.auditBy}
  order by create_time asc
    </select>

</mapper>