<?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.dup.CaseFieldMapper">
    <resultMap id="BaseResultMap" type="cn.com.countrygarden.bi.main.model.dup.CaseField">
        <!--
          WARNING - @mbg.generated
        -->
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="month_date" jdbcType="TIMESTAMP" property="monthDate"/>
        <result column="organ" jdbcType="VARCHAR" property="organ"/>
        <result column="comm" jdbcType="VARCHAR" property="comm"/>
        <result column="case_field" jdbcType="VARCHAR" property="caseField"/>
        <result column="sale_begin_date" jdbcType="TIMESTAMP" property="saleBeginDate"/>
        <result column="sale_end_date" jdbcType="TIMESTAMP" property="saleEndDate"/>
        <result column="comm_manager" jdbcType="VARCHAR" property="commManager"/>
        <result column="case_field_manager" jdbcType="VARCHAR" property="caseFieldManager"/>
        <result column="position" jdbcType="VARCHAR" property="position"/>
        <result column="case_field_authorized" jdbcType="INTEGER" property="caseFieldAuthorized"/>
        <result column="onduty_people_count" jdbcType="INTEGER" property="ondutyPeopleCount"/>
        <result column="show_time" jdbcType="TIMESTAMP" property="showTime"/>
        <result column="show_count" jdbcType="TIMESTAMP" property="showCount"/>
        <result column="people_count" jdbcType="INTEGER" property="peopleCount"/>
        <result column="image" jdbcType="VARCHAR" property="image"/>
        <result column="monthly_develop_count" jdbcType="INTEGER" property="monthlyDevelopCount"/>
        <result column="develop_man_count" jdbcType="INTEGER" property="developManCount"/>
        <result column="monthly_open_count" jdbcType="INTEGER" property="monthlyOpenCount"/>
        <result column="open_help_count" jdbcType="INTEGER" property="openHelpCount"/>
        <result column="comm_manager_rate" jdbcType="VARCHAR" property="commManagerRate"/>
        <result column="sale_manager_rate" jdbcType="VARCHAR" property="saleManagerRate"/>
        <result column="open_coordinate_rate" jdbcType="VARCHAR" property="openCoordinateRate"/>
        <result column="open_coordinate_rate_files" jdbcType="VARCHAR" property="openCoordinateRateFiles"/>
        <result column="advanced_deeds" jdbcType="VARCHAR" property="advancedDeeds"/>
        <result column="deeds_images" jdbcType="VARCHAR" property="deedsImages"/>
        <result column="praise_letter_count" jdbcType="INTEGER" property="praiseLetterCount"/>
        <result column="silk_banner_count" jdbcType="INTEGER" property="silkBannerCount"/>
        <result column="other_paise_count" jdbcType="INTEGER" property="otherPaiseCount"/>
        <result column="official_account_push_count" jdbcType="INTEGER" property="officialAccountPushCount"/>
        <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
        <result column="created_by" jdbcType="VARCHAR" property="createdBy"/>
        <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
        <result column="updated_by" jdbcType="VARCHAR" property="updatedBy"/>
        <result column="is_delete" jdbcType="INTEGER" property="isDelete"/>
        <result column="innovation_service" jdbcType="VARCHAR" property="innovationService"/>
        <result column="innovation_service_images" jdbcType="VARCHAR" property="innovationServiceImages"/>
        <result column="exhibition_area" jdbcType="VARCHAR" property="exhibitionArea"/>
    	
    	<result column="approval_state" jdbcType="INTEGER" property="approvalState"/>
        <result column="approval_opinion" jdbcType="VARCHAR" property="approvalOpinion"/>
        <result column="approver" jdbcType="VARCHAR" property="approver"/>
        <result column="approval_date" jdbcType="TIMESTAMP" property="approvalDate"/>
    </resultMap>

    <!--录入案场信息-->
    <insert id="insertCaseField" parameterType="cn.com.countrygarden.bi.main.model.dup.CaseField">
        <![CDATA[


    INSERT  INTO case_field ( month_date ,  organ ,  comm ,  case_field ,  sale_begin_date ,
         sale_end_date ,  comm_manager ,  case_field_manager ,  position ,  case_field_authorized ,
         onduty_people_count ,  show_time , show_count,  people_count ,  image ,  monthly_develop_count ,
         develop_man_count ,  monthly_open_count ,  open_help_count ,  comm_manager_rate ,
         sale_manager_rate ,  open_coordinate_rate ,  open_coordinate_rate_files ,  advanced_deeds ,
         deeds_images ,  praise_letter_count ,  silk_banner_count ,  other_paise_count ,
         official_account_push_count ,  create_date ,  created_by ,  update_date ,  updated_by,
          innovation_service,innovation_service_images,exhibition_area)
        VALUES (
         #{monthDate },
         #{organ },
         #{comm },
         #{caseField },
         #{saleBeginDate },
         #{saleEndDate },
         #{commManager },
         #{caseFieldManager },
         #{position },
         #{caseFieldAuthorized },
         #{ondutyPeopleCount },
         #{showTime },
         #{showCount },
         #{peopleCount },
         #{image },
         #{monthlyDevelopCount },
         #{developManCount },
         #{monthlyOpenCount },
         #{openHelpCount },
         #{commManagerRate },
         #{saleManagerRate },
         #{openCoordinateRate },
         #{openCoordinateRateFiles },
         #{advancedDeeds },
         #{deedsImages },
         #{praiseLetterCount },
         #{silkBannerCount },
         #{otherPaiseCount },
         #{officialAccountPushCount },
         #{createDate },
         #{createdBy },
         #{updateDate },
         #{updatedBy },
         #{innovationService },
         #{innovationServiceImages },
         #{exhibitionArea }

        )

        ]]>
  </insert>

    <!--根据条件查询案场信息-->
    <select id="queryByKeys" parameterType="Map" resultMap="BaseResultMap">

        select * from case_field
        <where>
            is_delete = 0
            <if test="organ != null and organ!='' and organ!='null'">
                and organ = #{organ}
            </if>
            <if test="organs!=null and organs.size()>0">
                <![CDATA[
                  AND organ IN
                ]]>
                <foreach item="item" index="index" collection="organs" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="comms!=null and comms.size()>0">
                <![CDATA[
                  AND comm IN
                ]]>
                <foreach item="item" index="index" collection="comms" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="comm != null and comm!='' and comm!='null'">
                and comm = #{comm}
            </if>
            <if test="caseField != null and caseField!='' and caseField!='null'">
                and case_field = #{caseField}
            </if>
            <if test="beginDate != null and beginDate != ''">
                <![CDATA[
                    and left(month_date,7) >= left(#{beginDate},7)
                ]]>
            </if>
            <if test="endDate != null and endDate != ''">
                <![CDATA[
                    and left(month_date,7) <= left(#{endDate},7)
                ]]>
            </if>
        </where>
        order by id desc
        <if test="page != null and size != null">
            <![CDATA[
            LIMIT #{page, jdbcType=INTEGER}, #{size, jdbcType=INTEGER}
        ]]>
        </if>

    </select>
    
    <select id="queryByKeysNoPage" parameterType="Map" resultMap="BaseResultMap">

        select * from case_field
        <where>
            is_delete = 0
            <if test="organ != null and organ!='' and organ!='null'">
                AND organ = #{organ}
            </if>
            <if test="comm != null and comm!='' and comm!='null'">
                AND comm = #{comm}
            </if>
                AND DATE_FORMAT(month_date,'%Y-%m') =#{yearMonth} 
        </where>
    </select>

    <select id="queryTotal" parameterType="Map" resultType="java.lang.Integer">

        select count(*) from case_field
        <where>
            is_delete = 0
            <if test="organ != null and organ!='' and organ!='null'">
                and organ = #{organ}
            </if>
            <if test="organs!=null and organs.size()>0">
                <![CDATA[
                  AND organ IN
                ]]>
                <foreach item="item" index="index" collection="organs" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="comms!=null and comms.size()>0">
                <![CDATA[
                  AND comm IN
                ]]>
                <foreach item="item" index="index" collection="comms" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="comm != null and comm!='' and comm!='null'">
                and comm = #{comm}
            </if>
            <if test="caseField != null and caseField!='' and caseField!='null'">
                and case_field = #{caseField}
            </if>
            <if test="beginDate != null and beginDate != ''">
                <![CDATA[
                    and left(month_date,7) >= left(#{beginDate},7)
                ]]>
            </if>
            <if test="endDate != null and endDate !=''">
                <![CDATA[
                    and left(month_date,7) <= left(#{endDate},7)
                ]]>
            </if>
        </where>

    </select>

    <!--软删除-->
    <update id="softDeleteById" parameterType="Map">
        <![CDATA[

          UPDATE case_field AS t SET t.is_delete = 1, t.updated_by = #{userCode, jdbcType=VARCHAR},t.update_date=now()
          WHERE id = #{id, jdbcType=INTEGER}

        ]]>
    </update>

    <!--修改-->
    <update id="modifyCaseFieldById" parameterType="cn.com.countrygarden.bi.main.model.dup.CaseField">
        <![CDATA[


     UPDATE case_field
          set month_date = #{monthDate },
           organ= #{organ },
           comm= #{comm },
           case_field = #{caseField },
           sale_begin_date= #{saleBeginDate },
           sale_end_date= #{saleEndDate },
           comm_manager= #{commManager },
           case_field_manager= #{caseFieldManager },
           position= #{position },
           case_field_authorized= #{caseFieldAuthorized },
           onduty_people_count= #{ondutyPeopleCount },
           show_time= #{showTime },
           show_count= #{showCount },
           people_count= #{peopleCount },
           image= #{image },
           monthly_develop_count= #{monthlyDevelopCount },
           develop_man_count= #{developManCount },
           monthly_open_count= #{monthlyOpenCount },
           open_help_count= #{openHelpCount },
           comm_manager_rate= #{commManagerRate },
           sale_manager_rate= #{saleManagerRate },
           open_coordinate_rate= #{openCoordinateRate },
           open_coordinate_rate_files= #{openCoordinateRateFiles },
           advanced_deeds= #{advancedDeeds },
           deeds_images= #{deedsImages },
           praise_letter_count= #{praiseLetterCount },
           silk_banner_count= #{silkBannerCount },
           other_paise_count= #{otherPaiseCount },
           official_account_push_count= #{officialAccountPushCount },
           update_date= #{updateDate },
           updated_by= #{updatedBy },
          innovation_service= #{innovationService },
          innovation_service_images= #{innovationServiceImages },
          exhibition_area=#{exhibitionArea },
          approval_state=#{approvalState},
          approval_opinion=#{approvalOpinion}
          where id = #{id}



        ]]>
    </update>

    <select id="queryById" parameterType="Map" resultMap="BaseResultMap">
        select * from case_field where id = #{id}
    </select>
    
    
</mapper>