<?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.CkResourceIncomeMapper">
    <resultMap id="BaseResultMap" type="cn.com.countrygarden.bi.main.model.ck.res.CkResourceIncome">
        <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="opening_closing" property="openingClosing"/>
        <result column="current_income" property="currentIncome"/>
        <result column="current_expenditure" property="currentExpenditure"/>
        <result column="current_period" property="currentPeriod"/>
        <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="selectListDataToble" resultType="long">
SELECT COUNT(`id`) FROM `ck_resource_income`
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="selectListData" resultMap="BaseResultMap">
            SELECT `id`,`org_code`,`org_name`,`comm_code`,`comm_name`,`time_month`,`opening_closing`,`current_income`,
  `current_expenditure`,`current_period`,`create_time`,`create_name`,`data_status`,audit_by,
  `audit_name`,`audit_time`
  FROM `ck_resource_income`
  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="selectGetrevenue" resultMap="BaseResultMap">
         SELECT `org_code`,`org_name`,`comm_code`,`comm_name`,`time_month`,`opening_closing`,`current_income`,
   `current_expenditure`,`current_period`,`create_time`,`create_name`,
   `audit_name`,`audit_time`,data_status
   FROM `ck_resource_income`
        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="selectincometishi" resultMap="BaseResultMap">
           SELECT `id`,`org_code`,`org_name`,`comm_code`,`comm_name`,`time_month`,`opening_closing`,`current_income`,
  `current_expenditure`,`current_period`,`create_time`,`create_name`,`data_status`,audit_by,
  `audit_name`,`audit_time`
  FROM `ck_resource_income`
   WHERE `status`=1 and data_status=#{income.dataStatus} and audit_by=#{income.auditBy}
  order by create_time asc
    </select>

    <select id="selectOpeningClosing" resultMap="BaseResultMap">
                   SELECT `id`,`org_code`,`org_name`,`comm_code`,`comm_name`,`time_month`,`opening_closing`,`current_income`,
  `current_expenditure`,`current_period`,`create_time`,`create_name`,`data_status`,audit_by,
  `audit_name`,`audit_time`
  FROM `ck_resource_income`
   WHERE `status`=1 and data_status=1 and time_month LIKE CONCAT("%",#{ro.timeMonth},"%") and org_code=#{ro.orgCode}
   and comm_code=#{ro.commCode}
   ORDER BY create_time ASC
   LIMIT 1
    </select>


    <select id="selectOpeningClosingShenHeOne" resultMap="BaseResultMap">
        SELECT `id`,`org_code`,`org_name`,`comm_code`,`comm_name`,`time_month`,`opening_closing`,`current_income`,
        `current_expenditure`,`current_period`,`create_time`,`create_name`,`data_status`,audit_by,
        `audit_name`,`audit_time`
        FROM `ck_resource_income`
        WHERE `status`=1 and time_month LIKE CONCAT("%",#{ro.timeMonth},"%")
        <if test="ro.auditBy!=null and ro.auditBy!=''">
            and audit_by=#{ro.auditBy}
        </if>
        <if test="ro.orgCode!=null and ro.orgCode!=''">
            and org_code=#{ro.orgCode}
        </if>
        <if test="ro.commCode!=null and ro.commCode!=''">
            and comm_code=#{ro.commCode}
        </if>
        ORDER BY create_time ASC
        LIMIT 1
    </select>
</mapper>