<?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.wcx.WcxInnovationOtherMapper">
    <resultMap id="BaseInnoOtherDtoMap" type="cn.com.countrygarden.bi.main.dto.wcx.WcxInnovationOtherDto">
        <id property="innovationOtherId"        column="innovation_other_id"/>
        <result property="innoId"                   column="inno_id"/>
        <result property="innoProjectName"          column="inno_project_name"/>
        <result property="innoRegionName"           column="inno_region_name"/>
        <result property="innoUserId"               column="inno_user_id"/>
        <result property="innoUserName"             column="inno_user_name"/>
        <result property="innoContentId"            column="inno_content_id"/>
        <result property="innoCreateDate"           column="inno_create_date"/>
        <result property="innoStatus"               column="inno_status"/>
        <result property="innoSimpleContent"        column="inno_simple_content"/>
        <result property="reportNumber"             column="report_number"/>
        <result property="reportBy"                 column="report_by"/>
        <result property="reportByName"             column="report_by_name"/>
        <result property="createDate"               column="create_date"/>
        <result property="createBy"                 column="create_by"/>
        <result property="createByName"             column="create_by_name"/>
        <result property="lastUpdateDate"           column="last_update_date"/>
        <result property="lastUpdateBy"             column="last_update_by"/>
        <result property="lastUpdateByName"         column="last_update_by_name"/>
        <result property="status"                   column="status"/>
        <result property="isDelete"                 column="is_delete"/>
        <result property="version"                  column="version"/>
        <result property="reportContent"            column="report_content"/>

        <result property="innoType"                 column="inno_type"/>
        <result property="innoBaseline"             column="inno_baseline"/>
        <result property="innoClassification"       column="inno_classification"/>
        <result property="innoTeamContent"          column="inno_team_content"/>
        <result property="innoTopEndDate"           column="inno_top_end_date"/>
        <result property="innoTitle"                column="inno_title"/>
    </resultMap>

    <resultMap id="BaseInnoOtherMap" type="cn.com.countrygarden.bi.main.model.wcx.WcxInnovationOther">
            <id property="innovationOtherId"        column="innovation_other_id"/>
        <result property="innoId"                   column="inno_id"/>
        <result property="innoProjectName"          column="inno_project_name"/>
        <result property="innoRegionName"           column="inno_region_name"/>
        <result property="innoUserId"               column="inno_user_id"/>
        <result property="innoUserName"             column="inno_user_name"/>
        <result property="innoContentId"            column="inno_content_id"/>
        <result property="innoCreateDate"           column="inno_create_date"/>
        <result property="innoStatus"              column="inno_status"/>
        <result property="innoSimpleContent"      column="inno_simple_content"/>
        <result property="reportNumber"            column="report_number"/>
        <result property="reportBy"                column="report_by"/>
        <result property="reportByName"           column="report_by_name"/>
        <result property="createDate"              column="create_date"/>
        <result property="createBy"                column="create_by"/>
        <result property="createByName"           column="create_by_name"/>
        <result property="lastUpdateDate"         column="last_update_date"/>
        <result property="lastUpdateBy"           column="last_update_by"/>
        <result property="lastUpdateByName"      column="last_update_by_name"/>
        <result property="status"                   column="status"/>
        <result property="isDelete"                column="is_delete"/>
        <result property="version"                  column="version"/>
        <result property="reportContent"            column="report_content"/>

        <result property="innoType"                 column="inno_type"/>
        <result property="innoBaseline"             column="inno_baseline"/>
        <result property="innoClassification"       column="inno_classification"/>
        <result property="innoTeamContent"          column="inno_team_content"/>
        <result property="innoTopEndDate"           column="inno_top_end_date"/>
        <result property="innoTitle"                column="inno_title"/>
    </resultMap>

    <select id="selectPageData" resultMap="BaseInnoOtherDtoMap">
        SELECT
        i.innovation_other_id,
        i.inno_id,
        i.inno_project_name,
        i.inno_region_name,
        i.inno_user_id,
        i.inno_user_name,
        i.inno_content_id,
        i.inno_create_date,
        i.inno_status,
        i.inno_simple_content,
        i.report_number,
        i.report_by,
        i.report_by_name,
        i.create_date,
        i.create_by,
        i.create_by_name,
        i.last_update_date,
        i.last_update_by,
        i.last_update_by_name,
        i.status,
        i.is_delete,
        i.version,
        i.report_content,
        i.inno_type,
        i.inno_baseline,
        i.inno_classification,
        i.inno_team_content,
        i.inno_top_end_date,
        i.inno_title
        FROM wcx_innovation_other i
        WHERE
        <include refid="BaseSelectPageList"/>
        ORDER BY i.status desc, i.create_date desc, i.innovation_other_id
        limit #{pageOffset}, #{pageSize}
    </select>

    <select id="selectPageCount" resultType="long">
        SELECT count(i.innovation_other_id)
        FROM wcx_innovation_other i
        WHERE
        <include refid="BaseSelectPageList"/>
    </select>

    <sql id="BaseSelectPageList">
        i.status = #{status}
        <if test="innoRegionName != null and innoRegionName != ''">
            and i.inno_region_name like concat(#{innoRegionName}, '%')
        </if>
        <if test="innoBaseline != null and innoBaseline != ''">
            and i.inno_baseline = #{innoBaseline}
        </if>
    </sql>


    <select id="findFirst" resultMap="BaseInnoOtherMap">
        SELECT
            innovation_other_id,
            inno_id,
            inno_project_name,
            inno_region_name,
            inno_user_id,
            inno_user_name,
            inno_content_id,
            inno_create_date,
            inno_status,
            inno_simple_content,
            inno_type,
            inno_baseline,
            inno_classification,
            inno_team_content,
            inno_top_end_date,
            inno_title,
            report_number,
            report_by,
            report_by_name,
            create_date,
            create_by,
            create_by_name,
            last_update_date,
            last_update_by,
            last_update_by_name,
            status,
            is_delete,
            version,
            report_content
        FROM
          wcx_innovation_other
        WHERE inno_id = #{innoId} and is_delete = #{isDelete}
    </select>

    <select id="findFirstByPrimaryKey" resultMap="BaseInnoOtherDtoMap">
        SELECT
        innovation_other_id,
        inno_id,
        inno_project_name,
        inno_region_name,
        inno_user_id,
        inno_user_name,
        inno_content_id,
        inno_create_date,
        inno_status,
        inno_simple_content,
        inno_type,
        inno_baseline,
        inno_classification,
        inno_team_content,
        inno_top_end_date,
        inno_title,
        report_number,
        report_by,
        report_by_name,
        create_date,
        create_by,
        create_by_name,
        last_update_date,
        last_update_by,
        last_update_by_name,
        status,
        is_delete,
        version,
        report_content
        FROM
        wcx_innovation_other
        WHERE innovation_other_id = #{innoOtherId}
    </select>

    <insert id="insertFirst">
        INSERT INTO wcx_innovation_other
        (
            innovation_other_id,
            inno_id,
            inno_project_name,
            inno_region_name,
            inno_user_id,
            inno_user_name,
            inno_content_id,
            inno_create_date,
            inno_status,
            inno_simple_content,
            report_number,
            report_by,
            report_by_name,
            create_date,
            create_by,
            create_by_name,
            last_update_date,
            last_update_by,
            last_update_by_name,
            status,
            is_delete,
            version,
            report_content,
            inno_type,
            inno_baseline,
            inno_classification,
            inno_team_content,
            inno_top_end_date,
            inno_title
        )
        VALUES
        (
        #{innovationOtherId},
        #{innoId},
        #{innoProjectName},
        #{innoRegionName},
        #{innoUserId},
        #{innoUserName},
        #{innoContentId},
        #{innoCreateDate},
        #{innoStatus},
        #{innoSimpleContent},
        #{reportNumber},
        #{reportBy},
        #{reportByName},
        #{createDate},
        #{createBy},
        #{createByName},
        #{lastUpdateDate},
        #{lastUpdateBy},
        #{lastUpdateByName},
        #{status},
        #{isDelete},
        #{version},
        #{reportContent},
        #{innoType},
        #{innoBaseline},
        #{innoClassification},
        #{innoTeamContent},
        #{innoTopEndDate},
        #{innoTitle}
        )
    </insert>

    <update id="updateReportNumber" >
        UPDATE wcx_innovation_other
        <set>
            <if test="innoId !=null">
            inno_id = #{innoId},
            </if>
            <if test="innoProjectName !=null">
            inno_project_name = #{innoProjectName},
            </if>
            <if test="innoRegionName !=null">
            inno_region_name = #{innoRegionName},
            </if>
            <if test="innoUserId !=null">
            inno_user_id = #{innoUserId},
            </if>
            <if test="innoUserName !=null">
            inno_user_name = #{innoUserName},
            </if>
            <if test="innoContentId !=null">
            inno_content_id = #{innoContentId},
            </if>
            <if test="innoCreateDate !=null">
            inno_create_date = #{innoCreateDate},
            </if>
            <if test="innoStatus !=null">
            inno_status = #{innoStatus},
            </if>
            <if test="innoSimpleContent !=null">
            inno_simple_content = #{innoSimpleContent},
            </if>
            <if test="reportNumber !=null">
            report_number = #{reportNumber},
            </if>
            <if test="reportBy !=null">
            report_by = #{reportBy},
            </if>
            <if test="reportByName !=null">
            report_by_name = #{reportByName},
            </if>
            <if test="createDate !=null">
            create_date = #{createDate},
            </if>
            <if test="createBy !=null">
            create_by = #{createBy},
            </if>
            <if test="createByName !=null">
            create_by_name = #{createByName},
            </if>
            <if test="lastUpdateDate !=null">
            last_update_date = #{lastUpdateDate},
            </if>
            <if test="lastUpdateBy !=null">
            last_update_by = #{lastUpdateBy},
            </if>
            <if test="lastUpdateByName !=null">
            last_update_by_name = #{lastUpdateByName},
            </if>
            <if test="status !=null">
            status = #{status},
            </if>
            <if test="isDelete !=null">
            is_delete = #{isDelete},
            </if>
            <if test="reportContent !=null">
            report_content = #{reportContent},
            </if>
            <if test="innoType !=null">
            inno_type = #{innoType},
            </if>
            <if test="innoBaseline !=null">
            inno_baseline = #{innoBaseline},
            </if>
            <if test="innoClassification !=null">
            inno_classification = #{innoClassification},
            </if>
            <if test="innoTeamContent !=null">
            inno_team_content = #{innoTeamContent},
            </if>
            <if test="innoTopEndDate !=null">
            inno_top_end_date = #{innoTopEndDate},
            </if>
            <if test="innoTitle !=null">
            inno_title = #{innoTitle},
            </if>
            version               =version + 1
        </set>
        WHERE
        innovation_other_id=#{innoOtherId} and version=#{version}
    </update>

    <update id="updateStatus">
        UPDATE wcx_innovation_other SET is_delete = #{isDelete}, status = #{status}  WHERE innovation_other_id = #{innoOtherId}
    </update>

    <update id="updateAudit">
        UPDATE wcx_innovation_other SET last_update_by = #{lastUpdateBy}, last_update_by_name = #{lastUpdateByName}  WHERE innovation_other_id = #{innoOtherId}
    </update>
</mapper>