<?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.WcxInnovationMapper">
    <resultMap id="BaseWcxInnovationDtoMap" type="cn.com.countrygarden.bi.main.dto.wcx.WcxInnovationDto">
        <id column="innovation_id" property="innovationId"/>
        <result column="innovation_title" property="innovationTitle"/>
        <result column="innovation_content" property="innovationContent"/>
        <result column="innovation_simple_content" property="innovationSimpleContent"/>
        <result column="innovation_type" property="innovationType"/>
        <result column="baseline" property="baseline"/>
        <result column="classification" property="classification"/>
        <result column="team_content" property="teamContent"/>
        <result column="user_id" property="userId"/>
        <result column="status" property="status"/>
        <result column="create_date" property="createDate"/>
        <result column="employee_name" property="employeeName"/>
        <result column="head_pic_url" property="headPicUrl"/>
        <result column="thumbNumber" property="thumbNumber"/>
        <result column="reviewNumber" property="reviewNumber"/>
        <result column="project_name" property="projectName"/>
        <result column="region_name" property="regionName"/>
        <result column="video_file_url" property="videoUrl"/>
        <result column="audit_status" property="examineStatus"/>
        <result column="handle_date" property="handleDate"/>
        <result column="operator" property="operator"/>
        <result column="opinion" property="opinion"/>
        <result column="file_id" property="fileId"/>
        <result column="is_top" property="isTop"/>
        <result column="is_recomm" property="isRecomm"/>
        <result column="update_time" property="updateTime"/>
        <result column="recomm_time" property="recommTime"/>
        <result column="is_excellent" property="isExcellent"/>
        <result column="reading" property="reading"/>
        <result column="audit_status" property="auditStatus"/>
        <collection property="pics" columnPrefix="pic_" ofType="cn.com.countrygarden.bi.main.model.wcx.WcxFile">
            <id column="file_id" property="fileId"/>
            <result column="file_url" property="fileUrl"/>
        </collection>
    </resultMap>

    <select id="selectPageData" resultMap="BaseWcxInnovationDtoMap">
    SELECT
    i.innovation_id,
    i.innovation_title,
    i.innovation_simple_content,
    i.innovation_type,
    i.baseline,
    i.classification,
    i.team_content,
    i.user_id,
    i.status,
    i.create_date,
    u.employee_name,
    u.head_pic_url,
    pic.file_url pic_file_url,
    pic.file_id pic_file_id,
    video.file_url video_file_url,
    thumb.thumbNumber,
    review.reviewNumber,
    i.project_name,
    i.region_name,
    i.audit_status,
    i.handle_date,
    i.operator,
    i.opinion,
    pic.file_id,
    i.is_top,
    i.is_recomm,
    i.is_excellent,
        (SELECT COUNT(re.reading_id) FROM wcx_innovation_reading re
        WHERE re.innovation_id=i.innovation_id) AS reading
    FROM (
    select ti.* from wcx_innovation ti
    <if test="employeeName != null and employeeName != ''">
        JOIN wcx_user tu ON tu.user_id = ti.user_id
    </if>
    <if test="roleType != null and roleType != ''">
        JOIN (
        SELECT
        wt.innovation_id
        FROM wcx_thumb wt
        JOIN wcx_role wr ON wt.role_id = wr.role_id
        WHERE wr.role_type=#{roleType}
        GROUP BY wt.innovation_id
        )wi ON wi.innovation_id = ti.innovation_id
    </if>
    <if test="roleCode !=null and  roleCode != ''">
        JOIN (
        SELECT
        wt.innovation_id
        FROM
        wcx_thumb wt
        JOIN wcx_role wr ON wt.role_id = wr.role_id
        WHERE wr.role_code =#{roleCode}
        GROUP BY wt.innovation_id
        ) wi ON wi.innovation_id = ti.innovation_id
    </if>
    <if test="orderByThumbNumber != null">
        LEFT JOIN (select innovation_id, sum(thumb_number) thumbNumber from wcx_thumb group by innovation_id) tt
        on tt.innovation_id = ti.innovation_id
    </if>
        <if test="orderByReadingPaixu != null">
            LEFT JOIN (SELECT innovation_id,count(reading_id) as readingNum FROM wcx_innovation_reading GROUP BY innovation_id) rr
            on rr.innovation_id = ti.innovation_id
        </if>
    <include refid="BaseSelectPageList"/>
    <if test="orderByThumbNumber == '-1'">
        ORDER BY tt.thumbNumber DESC
    </if>
        <if test="orderByReadingPaixu == '-1'">
            ORDER BY rr.readingNum DESC
        </if>
    <if test="orderByThumbNumber != null and orderByThumbNumber != '-1'">
        ORDER BY tt.thumbNumber
    </if>
        <if test="orderByReadingPaixu != null and orderByReadingPaixu != '-1'">
            ORDER BY rr.readingNum
        </if>
    <if test="orderByThumbNumber == null and orderByReadingPaixu == null">
        order by ti.create_date desc
    </if>
        <if test="pageSize != '-1'">
            limit #{pageOffset}, #{pageSize}
        </if>
    ) i
    LEFT JOIN  wcx_user u on u.user_id = i.user_id
    LEFT JOIN wcx_file pic on pic.innovation_id = i.innovation_id and pic.file_type = '1'
    LEFT JOIN wcx_file video on video.innovation_id = i.innovation_id and video.file_type = '2'
    LEFT JOIN (select innovation_id, sum(thumb_number) thumbNumber from wcx_thumb group by innovation_id) thumb on
    thumb.innovation_id = i.innovation_id
    LEFT JOIN (select innovation_id, count(review_id) reviewNumber from wcx_review group by innovation_id) review on
    review.innovation_id = i.innovation_id
    LEFT JOIN (SELECT innovation_id,COUNT(reading_id) AS readingNum FROM wcx_innovation_reading GROUP BY innovation_id) rrumb ON rrumb.innovation_id = i.innovation_id

        <if test="orderByThumbNumber == '-1'">
        ORDER BY thumb.thumbNumber DESC
    </if>
    <if test="orderByThumbNumber != '-1' and orderByThumbNumber != null">
       ORDER BY thumb.thumbNumber
    </if>

        <if test="orderByReadingPaixu == '-1'">
            ORDER BY rrumb.readingNum DESC
        </if>
        <if test="orderByReadingPaixu != '-1' and orderByReadingPaixu != null">
            ORDER BY rrumb.readingNum
        </if>

    <if test="orderByThumbNumber == null and orderByReadingPaixu == null">
        ORDER BY i.create_date desc
    </if>
</select>

    <select id="selectPageDataNofen" resultMap="BaseWcxInnovationDtoMap">
    SELECT
    i.innovation_id
    FROM (
    select ti.* from wcx_innovation ti
    <if test="employeeName != null and employeeName != ''">
        JOIN wcx_user tu ON tu.user_id = ti.user_id
    </if>
    <if test="roleType != null and roleType != ''">
        JOIN (
        SELECT
        wt.innovation_id
        FROM wcx_thumb wt
        JOIN wcx_role wr ON wt.role_id = wr.role_id
        WHERE wr.role_type=#{roleType}
        GROUP BY wt.innovation_id
        )wi ON wi.innovation_id = ti.innovation_id
    </if>
    <if test="roleCode !=null and  roleCode != ''">
        JOIN (
        SELECT
        wt.innovation_id
        FROM
        wcx_thumb wt
        JOIN wcx_role wr ON wt.role_id = wr.role_id
        WHERE wr.role_code =#{roleCode}
        GROUP BY wt.innovation_id
        ) wi ON wi.innovation_id = ti.innovation_id
    </if>
    <if test="orderByThumbNumber != null">
        LEFT JOIN (select innovation_id, sum(thumb_number) thumbNumber from wcx_thumb group by innovation_id) tt
        on tt.innovation_id = ti.innovation_id
    </if>
    <where>
        and ti.audit_status=1
        <if test="userId != null">
            ti.user_id = #{userId}
        </if>
        <if test="employeeName != null and employeeName != ''">
            AND tu.employee_name like concat('%', #{employeeName}, '%')
        </if>
        <if test="classification != null and classification != ''">
            and ti.classification = #{classification}
        </if>
        <if test="baseline != null and baseline != ''">
            and ti.baseline = #{baseline}
        </if>
        <if test="innovationTitle != null and innovationTitle != ''">
            and ti.innovation_title like concat('%', #{innovationTitle}, '%')
        </if>
        <if test="thumbUserId != null">
            and ti.innovation_id in (select innovation_id from wcx_thumb where user_id = #{thumbUserId})
        </if>
        <if test="collectionUserId != null">
            and ti.innovation_id in (select innovation_id from wcx_collection where user_id = #{collectionUserId})
        </if>
        <!-- 用于本月项目创新 -->
        <if test="projectName != null and monthStartDate != null and monthEndDate != null">
            AND ti.project_name = #{projectName} AND create_date <![CDATA[>=]]> #{monthStartDate} AND create_date
            <![CDATA[<=]]> #{monthEndDate}
        </if>
        <if test="startDate != null">
            AND ti.create_date <![CDATA[>=]]> #{startDate}
        </if>
        <if test="endDate != null">
            AND date(ti.create_date) <![CDATA[<=]]> #{endDate}
        </if>
        <!-- 区域 -->
        <if test="regionName != null and regionName !=''">
            AND ti.region_name like concat('%',#{regionName}, '%')
        </if>
        <!-- 项目 -->
        <if test="projectName != null and projectName !=''">
            AND ti.project_name like concat(#{projectName}, '%')
        </if>
        <if test="examineStatus != null and examineStatus!=''">
            and ti.audit_status=#{examineStatus}
        </if>
        <if test="isTop!=null">
            and ti.is_top=#{isTop}
        </if>
        <if test="isRecomm!=null">
            and ti.is_recomm=#{isRecomm}
        </if>
        <if test="isExcellent!=null">
            and ti.is_excellent=#{isExcellent}
        </if>
        <if test="isMoren==1">
            AND create_date <![CDATA[>=]]> #{startDateStr} AND create_date
            <![CDATA[<=]]> #{endDateStr}
        </if>
        <if test="regionList != null and regionList.size>0">
            and (
            <foreach collection="regionList" item="item" index="index"  separator="OR">
                ti.region_name LIKE CONCAT('%',#{item},'%')
            </foreach>
            )
        </if>
        <if test="baselineList != null and baselineList.size>0">
            and ti.baseline in
            <foreach collection="baselineList" index="index" open="(" close=")" separator="," item="item">
                #{item}
            </foreach>
        </if>
    </where>
    <if test="orderByThumbNumber == '-1'">
        /*ORDER BY tt.thumbNumber DESC , ti.innovation_id*/
    </if>
    <if test="orderByThumbNumber != null and orderByThumbNumber != '-1'">
        /*ORDER BY tt.thumbNumber , ti.innovation_id*/
    </if>
    <if test="orderByThumbNumber == null">
        order by ti.create_date desc
    </if>
    ) i
    LEFT JOIN  wcx_user u on u.user_id = i.user_id
    LEFT JOIN wcx_file pic on pic.innovation_id = i.innovation_id and pic.file_type = '1'
    LEFT JOIN wcx_file video on video.innovation_id = i.innovation_id and video.file_type = '2'
    LEFT JOIN (select innovation_id, sum(thumb_number) thumbNumber from wcx_thumb group by innovation_id) thumb on
    thumb.innovation_id = i.innovation_id
    LEFT JOIN (select innovation_id, count(review_id) reviewNumber from wcx_review group by innovation_id) review on
    review.innovation_id = i.innovation_id
    <if test="orderByThumbNumber == '-1'">
        /*ORDER BY thumb.thumbNumber DESC , i.innovation_id*/
    </if>
    <if test="orderByThumbNumber != '-1' and orderByThumbNumber != null">
        /* ORDER BY thumb.thumbNumber, i.innovation_id*/
    </if>
    <if test="orderByThumbNumber == null">
        ORDER BY i.create_date desc
    </if>
</select>

    <select id="selectPageDataNofenShenhe" resultMap="BaseWcxInnovationDtoMap">
        SELECT
        i.innovation_id
        FROM (
        select ti.* from wcx_innovation ti
        <if test="employeeName != null and employeeName != ''">
            JOIN wcx_user tu ON tu.user_id = ti.user_id
        </if>
        <if test="roleType != null and roleType != ''">
            JOIN (
            SELECT
            wt.innovation_id
            FROM wcx_thumb wt
            JOIN wcx_role wr ON wt.role_id = wr.role_id
            WHERE wr.role_type=#{roleType}
            GROUP BY wt.innovation_id
            )wi ON wi.innovation_id = ti.innovation_id
        </if>
        <if test="roleCode !=null and  roleCode != ''">
            JOIN (
            SELECT
            wt.innovation_id
            FROM
            wcx_thumb wt
            JOIN wcx_role wr ON wt.role_id = wr.role_id
            WHERE wr.role_code =#{roleCode}
            GROUP BY wt.innovation_id
            ) wi ON wi.innovation_id = ti.innovation_id
        </if>
        <if test="orderByThumbNumber != null">
            LEFT JOIN (select innovation_id, sum(thumb_number) thumbNumber from wcx_thumb group by innovation_id) tt
            on tt.innovation_id = ti.innovation_id
        </if>
        <where>
            and (ti.audit_status=0 or ti.audit_status=2 or ti.audit_status=1)
            <if test="userId != null">
               and ti.user_id = #{userId}
            </if>
            <if test="employeeName != null and employeeName != ''">
                AND tu.employee_name like concat('%', #{employeeName}, '%')
            </if>
            <if test="classification != null and classification != ''">
                and ti.classification = #{classification}
            </if>
            <if test="baseline != null and baseline != ''">
                and ti.baseline = #{baseline}
            </if>
            <if test="innovationTitle != null and innovationTitle != ''">
                and ti.innovation_title like concat('%', #{innovationTitle}, '%')
            </if>
            <if test="thumbUserId != null">
                and ti.innovation_id in (select innovation_id from wcx_thumb where user_id = #{thumbUserId})
            </if>
            <if test="collectionUserId != null">
                and ti.innovation_id in (select innovation_id from wcx_collection where user_id = #{collectionUserId})
            </if>
            <!-- 用于本月项目创新 -->
            <if test="projectName != null and monthStartDate != null and monthEndDate != null">
                AND ti.project_name = #{projectName} AND create_date <![CDATA[>=]]> #{monthStartDate} AND create_date
                <![CDATA[<=]]> #{monthEndDate}
            </if>
            <if test="startDate != null">
                AND ti.create_date <![CDATA[>=]]> #{startDate}
            </if>
            <if test="endDate != null">
                AND date(ti.create_date) <![CDATA[<=]]> #{endDate}
            </if>
            <!-- 区域 -->
            <if test="regionName != null and regionName !=''">
                AND ti.region_name like concat('%',#{regionName}, '%')
            </if>
            <!-- 项目 -->
            <if test="projectName != null and projectName !=''">
                AND ti.project_name like concat(#{projectName}, '%')
            </if>
            <if test="examineStatus != null and examineStatus!=''">
                and ti.audit_status=#{examineStatus}
            </if>
            <if test="isTop!=null">
                and ti.is_top=#{isTop}
            </if>
            <if test="isRecomm!=null">
                and ti.is_recomm=#{isRecomm}
            </if>
            <if test="isExcellent!=null">
                and ti.is_excellent=#{isExcellent}
            </if>
            <if test="isMoren==1">
                AND create_date <![CDATA[>=]]> #{startDateStr} AND create_date
                <![CDATA[<=]]> #{endDateStr}
            </if>
            <if test="regionList != null and regionList.size>0">
                and (
                <foreach collection="regionList" item="item" index="index"  separator="OR">
                    ti.region_name LIKE CONCAT('%',#{item},'%')
                </foreach>
                )
            </if>
            <if test="baselineList != null and baselineList.size>0">
                and ti.baseline in
                <foreach collection="baselineList" index="index" open="(" close=")" separator="," item="item">
                    #{item}
                </foreach>
            </if>
        </where>
        <if test="orderByThumbNumber == '-1'">
            /*ORDER BY tt.thumbNumber DESC , ti.innovation_id*/
        </if>
        <if test="orderByThumbNumber != null and orderByThumbNumber != '-1'">
            /*ORDER BY tt.thumbNumber , ti.innovation_id*/
        </if>
        <if test="orderByThumbNumber == null">
            order by ti.create_date desc
        </if>
        ) i
        LEFT JOIN  wcx_user u on u.user_id = i.user_id
        LEFT JOIN wcx_file pic on pic.innovation_id = i.innovation_id and pic.file_type = '1'
        LEFT JOIN wcx_file video on video.innovation_id = i.innovation_id and video.file_type = '2'
        LEFT JOIN (select innovation_id, sum(thumb_number) thumbNumber from wcx_thumb group by innovation_id) thumb on
        thumb.innovation_id = i.innovation_id
        LEFT JOIN (select innovation_id, count(review_id) reviewNumber from wcx_review group by innovation_id) review on
        review.innovation_id = i.innovation_id
        <if test="orderByThumbNumber == '-1'">
            /*ORDER BY thumb.thumbNumber DESC , i.innovation_id*/
        </if>
        <if test="orderByThumbNumber != '-1' and orderByThumbNumber != null">
            /* ORDER BY thumb.thumbNumber, i.innovation_id*/
        </if>
        <if test="orderByThumbNumber == null">
            ORDER BY i.create_date desc
        </if>
    </select>

    <select id="selectPageDataNot" resultMap="BaseWcxInnovationDtoMap">
        SELECT
        i.innovation_id,
        i.innovation_title,
        i.innovation_simple_content,
        i.innovation_type,
        i.baseline,
        i.classification,
        i.team_content,
        i.user_id,
        i.status,
        i.create_date,
        u.employee_name,
        u.head_pic_url,
        pic.file_url pic_file_url,
        pic.file_id pic_file_id,
        video.file_url video_file_url,
        thumb.thumbNumber,
        review.reviewNumber,
        i.project_name,
        i.region_name,
        i.audit_status,
        i.handle_date,
        i.operator,
        i.opinion,
        pic.file_id,
        i.is_top,
        i.is_recomm,
        i.is_excellent
        FROM (
        select ti.* from wcx_innovation ti
        <if test="employeeName != null and employeeName != ''">
            JOIN wcx_user tu ON tu.user_id = ti.user_id
        </if>
        <if test="roleType != null and roleType != ''">
            JOIN (
            SELECT
            wt.innovation_id
            FROM wcx_thumb wt
            JOIN wcx_role wr ON wt.role_id = wr.role_id
            WHERE wr.role_type=#{roleType}
            GROUP BY wt.innovation_id
            )wi ON wi.innovation_id = ti.innovation_id
        </if>
        <if test="roleCode !=null and  roleCode != ''">
            JOIN (
            SELECT
            wt.innovation_id
            FROM
            wcx_thumb wt
            JOIN wcx_role wr ON wt.role_id = wr.role_id
            WHERE wr.role_code =#{roleCode}
            GROUP BY wt.innovation_id
            ) wi ON wi.innovation_id = ti.innovation_id
        </if>
        <if test="orderByThumbNumber != null">
            LEFT JOIN (select innovation_id, sum(thumb_number) thumbNumber from wcx_thumb group by innovation_id) tt
            on tt.innovation_id = ti.innovation_id
        </if>
        <include refid="BaseSelectPageListNot"/>
        <if test="orderByThumbNumber == '-1'">
            /*ORDER BY tt.thumbNumber DESC , ti.innovation_id*/
        </if>
        <if test="orderByThumbNumber != null and orderByThumbNumber != '-1'">
           /* ORDER BY tt.thumbNumber , ti.innovation_id*/
        </if>
        <if test="orderByThumbNumber == null">
            order by ti.create_date desc
        </if>
        <if test="pageSize != '-1'">
            limit #{pageOffset}, #{pageSize}
        </if>
        ) i
        join wcx_user u on u.user_id = i.user_id
        LEFT JOIN wcx_file pic on pic.innovation_id = i.innovation_id and pic.file_type = '1'
        LEFT JOIN wcx_file video on video.innovation_id = i.innovation_id and video.file_type = '2'
        LEFT JOIN (select innovation_id, sum(thumb_number) thumbNumber from wcx_thumb group by innovation_id) thumb on
        thumb.innovation_id = i.innovation_id
        LEFT JOIN (select innovation_id, count(review_id) reviewNumber from wcx_review group by innovation_id) review on
        review.innovation_id = i.innovation_id
        <if test="orderByThumbNumber == '-1'">
          /*  ORDER BY thumb.thumbNumber DESC , i.innovation_id*/
        </if>
        <if test="orderByThumbNumber != '-1' and orderByThumbNumber != null">
         /*  ORDER BY thumb.thumbNumber, i.innovation_id*/
        </if>
        <if test="orderByThumbNumber == null">
            ORDER BY i.create_date desc
        </if>

    </select>

    <select id="selectPageCount" resultType="long">
        SELECT
        count(ti.innovation_id)
        from wcx_innovation ti
        <if test="(roleType != null and roleType != '')">
            JOIN (
            SELECT
            wt.innovation_id
            FROM wcx_thumb wt
            JOIN wcx_role wr ON wt.role_id = wr.role_id
            WHERE wr.role_type=#{roleType}
            GROUP BY wt.innovation_id
            )wi ON wi.innovation_id = ti.innovation_id
        </if>

        <if test="(roleCode !=null and  roleCode != '')">
            JOIN (
            SELECT wt.innovation_id
            FROM wcx_thumb wt
            JOIN wcx_role wr ON wt.role_id = wr.role_id
            WHERE wr.role_code =#{roleCode}
            GROUP BY wt.innovation_id
            ) wi ON wi.innovation_id = ti.innovation_id
        </if>
        <if test="employeeName != null and employeeName != ''">
            JOIN wcx_user tu ON tu.user_id = ti.user_id
        </if>

        <include refid="BaseSelectPageList"/>
    </select>

    <sql id="BaseSelectPageList">
        <where>
            <if test="userId != null">
                ti.user_id = #{userId}
            </if>
            <if test="employeeName != null and employeeName != ''">
                AND tu.employee_name like concat('%', #{employeeName}, '%')
            </if>
            <if test="classification != null and classification != ''">
                and ti.classification = #{classification}
            </if>
            <if test="baseline != null and baseline != ''">
                and ti.baseline = #{baseline}
            </if>
            <if test="innovationTitle != null and innovationTitle != ''">
                and ti.innovation_title like concat('%', #{innovationTitle}, '%')
            </if>
            <if test="thumbUserId != null">
                and ti.innovation_id in (select innovation_id from wcx_thumb where user_id = #{thumbUserId})
            </if>
            <if test="collectionUserId != null">
                and ti.innovation_id in (select innovation_id from wcx_collection where user_id = #{collectionUserId})
            </if>
            <!-- 用于本月项目创新 -->
            <if test="projectName != null and monthStartDate != null and monthEndDate != null">
                AND ti.project_name = #{projectName} AND create_date <![CDATA[>=]]> #{monthStartDate} AND create_date
                <![CDATA[<=]]> #{monthEndDate}
            </if>
            <if test="startDate != null">
                AND ti.create_date <![CDATA[>=]]> #{startDate}
            </if>
            <if test="endDate != null">
                AND date(ti.create_date) <![CDATA[<=]]> #{endDate}
            </if>
            <!-- 区域 -->
            <if test="regionName != null and regionName !=''">
                AND ti.region_name like concat('%',#{regionName}, '%')
            </if>
            <!-- 项目 -->
            <if test="projectName != null and projectName !=''">
                AND ti.project_name like concat(#{projectName}, '%')
            </if>
            <if test="examineStatus != null and examineStatus!=''">
                and ti.audit_status=#{examineStatus}
            </if>
            <if test="isTop!=null">
               and ti.is_top=#{isTop}
            </if>
            <if test="isRecomm!=null">
                and ti.is_recomm=#{isRecomm}
            </if>
            <if test="isExcellent!=null">
                and ti.is_excellent=#{isExcellent}
            </if>
            <if test="isMoren==1">
                AND create_date <![CDATA[>=]]> #{startDateStr} AND create_date
                <![CDATA[<=]]> #{endDateStr}
            </if>
            <if test="regionList != null and regionList.size>0">
                and (
                <foreach collection="regionList" item="item" index="index"  separator="OR">
                    ti.region_name LIKE CONCAT('%',#{item},'%')
                </foreach>
                )
            </if>
            <if test="baselineList != null and baselineList.size>0">
                and ti.baseline in
                <foreach collection="baselineList" index="index" open="(" close=")" separator="," item="item">
                    #{item}
                </foreach>
            </if>
        </where>
    </sql>

    <sql id="BaseSelectPageListNot">
        <where>
            <if test="userId != null">
                ti.user_id = #{userId}
            </if>
            <if test="employeeName != null and employeeName != ''">
                AND tu.employee_name like concat('%', #{employeeName}, '%')
            </if>
            <if test="classification != null and classification != ''">
                and ti.classification = #{classification}
            </if>
            <if test="baseline != null and baseline != ''">
                and ti.baseline = #{baseline}
            </if>
            <if test="innovationTitle != null and innovationTitle != ''">
                and ti.innovation_title like concat('%', #{innovationTitle}, '%')
            </if>
            <if test="thumbUserId != null">
                and ti.innovation_id in (select innovation_id from wcx_thumb where user_id = #{thumbUserId})
            </if>
            <if test="collectionUserId != null">
                and ti.innovation_id in (select innovation_id from wcx_collection where user_id = #{collectionUserId})
            </if>
            <!-- 用于本月项目创新 -->
            <if test="projectName != null and monthStartDate != null and monthEndDate != null">
                AND ti.project_name = #{projectName} AND create_date <![CDATA[>=]]> #{monthStartDate} AND create_date
                <![CDATA[<=]]> #{monthEndDate}
            </if>
            <if test="startDate != null">
                AND ti.create_date <![CDATA[>=]]> #{startDate}
            </if>
            <if test="endDate != null">
                AND date(ti.create_date) <![CDATA[<=]]> #{endDate}
            </if>
            <!-- 区域 -->
            <if test="regionName != null and regionName !=''">
                AND ti.region_name like concat('%',#{regionName}, '%')
            </if>
            <!-- 项目 -->
            <if test="projectName != null and projectName !=''">
                AND ti.project_name like concat(#{projectName}, '%')
            </if>
            <if test="examineStatus != null and examineStatus!=''">
                and ti.audit_status In ('0','2')
            </if>
            <if test="isTop!=null">
                and ti.is_top=#{isTop}
            </if>
            <if test="isRecomm!=null">
                and ti.is_recomm=#{isRecomm}
            </if>
            <if test="isExcellent!=null">
                and ti.is_excellent=#{isExcellent}
            </if>
            <if test="isMoren==1">
                AND ti.create_date <![CDATA[>=]]> #{startDateStr} AND ti.create_date
                <![CDATA[<=]]> #{endDateStr}
            </if>
            <if test="regionList != null and regionList.size>0">
                and (
                <foreach collection="regionList" item="item" index="index"  separator="OR">
                    ti.region_name LIKE CONCAT('%',#{item},'%')
                </foreach>
                )
            </if>
            <if test="baselineList != null and baselineList.size>0">
                and ti.baseline in
                <foreach collection="baselineList" index="index" open="(" close=")" separator="," item="item">
                    #{item}
                </foreach>
            </if>
        </where>
    </sql>

    <select id="selectOneDto" resultMap="BaseWcxInnovationDtoMap">
        SELECT
            i.innovation_id,
            i.innovation_title,
            i.innovation_simple_content,
            i.innovation_type,
            i.baseline,
            i.classification,
            i.team_content,
            i.user_id,
            i.status,
            i.create_date,
            i.region_name,
            i.project_name,
            i.is_excellent,
            c.content innovation_content,
            pic.file_url pic_file_url,
            pic.file_id pic_file_id,
            video.file_url video_file_url,
            thumb.thumbNumber,
            review.reviewNumber,
            u.head_pic_url,
            u.employee_name,
            i.region_code,
            i.audit_status
        FROM (
          SELECT * FROM wcx_innovation WHERE innovation_id = #{innovationId}
        ) i
        JOIN wcx_user u on u.user_id = i.user_id
        JOIN wcx_content c ON c.content_id = i.innovation_content_id
        LEFT JOIN wcx_file pic on pic.innovation_id = i.innovation_id and pic.file_type = '1'
        LEFT JOIN wcx_file video on video.innovation_id = i.innovation_id and video.file_type = '2'
        LEFT JOIN (select innovation_id, sum(thumb_number) thumbNumber from wcx_thumb group by innovation_id) thumb on thumb.innovation_id = i.innovation_id
        LEFT JOIN (select innovation_id, count(review_id) reviewNumber from wcx_review group by innovation_id) review on review.innovation_id = i.innovation_id
    </select>

    <!-- 查询某时间段下创新数量 -->
    <select id="selectInnCountBetweenDate" resultType="int">
        SELECT count(innovation_id) FROM wcx_innovation
        WHERE create_date <![CDATA[>=]]> #{startDate} and create_date <![CDATA[<=]]> #{endDate}
    </select>
    <!-- 查询某时间段下创新数量, 不在获奖创新内 -->
    <select id="findInnCountBetweenDate" resultType="int">
        SELECT count(innovation_id) FROM wcx_innovation inn
        WHERE inn.create_date <![CDATA[>=]]> #{startDate} and inn.create_date <![CDATA[<=]]> #{endDate}
        AND inn.innovation_id not in
        <include refid="BasePrizeInnIds"/>
    </select>
    <update id="examine">
        Update wcx_innovation
        set audit_status=#{examineStatus},
        handle_date=now(),
        operator=#{operator},
        opinion=#{opinion}
        where innovation_id=#{innovationId}
    </update>
    <!-- 查询通过点赞量排序的创意 -->
    <select id="selectInnOrderByThumbNum" resultMap="BaseWcxInnovationDtoMap">
        SELECT
            inn.*,
            u.employee_name,
            IFNULL(thumbNum, 0) thumbNumber
        FROM (
            SELECT *
            FROM wcx_innovation
            WHERE create_date <![CDATA[>=]]> #{startDate}
            AND create_date <![CDATA[<=]]> #{endDate}
        ) inn
        LEFT JOIN wcx_user u ON u.user_id = inn.user_id
        LEFT JOIN (
            SELECT SUM(thumb_number) thumbNum, innovation_id
            FROM wcx_thumb
            WHERE create_date <![CDATA[>=]]> #{startDate} AND create_date <![CDATA[<=]]> #{endDate}
            GROUP BY innovation_id
        ) thumb ON thumb.innovation_id = inn.innovation_id
        ORDER BY thumbNum DESC
        limit #{pageSize}
    </select>

    <!-- 查询各基础业务线前三名创意的信息 -->
    <select id="selectInnTop3Number" resultMap="BaseWcxInnovationDtoMap">
        SELECT
        inn.*,
        u.employee_name,
        IFNULL(thumbNum, 0) thumbNumber
        FROM
        (SELECT SUM(thumb_number) thumbNum, t.innovation_id
        FROM wcx_thumb t
        JOIN wcx_innovation i ON i.innovation_id = t.innovation_id AND i.baseline = #{baseline}
        WHERE t.create_date <![CDATA[>=]]> #{startDate} AND t.create_date <![CDATA[<=]]> #{endDate}
        GROUP BY t.innovation_id ) allInn
        JOIN wcx_innovation inn ON inn.innovation_id = allInn.innovation_id
        LEFT JOIN wcx_user u ON u.user_id = inn.user_id
        WHERE
        inn.innovation_id not in
        <include refid="BasePrizeInnIds"/>
        <choose>
            <when test="thumbNum != null and thumbNum.size > 0">
                and allInn.thumbNum in
                <foreach collection="thumbNum" index="index" open="(" close=")" separator="," item="item">


                    #{item}
                </foreach>
            </when>
            <otherwise>
                and 1 = 2
            </otherwise>
        </choose>
    </select>

    <!-- 查询各基础业务线前三名的点赞量 -->
    <select id="selectInnTop3NumberThumbNum" resultType="int">
        SELECT DISTINCT SUM(thumb_number) thumbNum
        FROM wcx_thumb t
        JOIN wcx_innovation i ON i.innovation_id = t.innovation_id AND i.baseline = #{baseline}
        WHERE t.create_date <![CDATA[>=]]> #{startDate} AND t.create_date <![CDATA[<=]]> #{endDate}
        AND i.create_date <![CDATA[>=]]> #{startDate} AND t.create_date <![CDATA[<=]]> #{endDate}
        AND i.innovation_id not in
        <include refid="BasePrizeInnIds"/>
        GROUP BY t.innovation_id
        ORDER BY thumbNum DESC
        LIMIT 3
    </select>

    <select id="findBestLeaderLikeInnIds" resultType="string">
        SELECT t.innovation_id
        FROM wcx_thumb t
        JOIN wcx_user u ON u.user_id = t.user_id
        JOIN wcx_role r ON r.role_id = u.role_id AND r.role_type = '2'
        WHERE t.create_date <![CDATA[>=]]> #{startDate} AND t.create_date <![CDATA[<=]]> #{endDate}
        GROUP BY t.innovation_id
    </select>

    <select id="findList" resultMap="BaseWcxInnovationDtoMap">
        SELECT
        i.innovation_id,
        i.innovation_title,
        i.innovation_simple_content,
        i.innovation_type,
        i.baseline,
        i.classification,
        i.team_content,
        i.user_id,
        i.status,
        i.create_date,
        pic.file_url pic_file_url,
        pic.file_id pic_file_id,
        video.file_url video_file_url,
        thumb.thumbNumber,
        review.reviewNumber,
        u.head_pic_url,
        u.employee_name
        FROM (
        SELECT * FROM wcx_innovation WHERE
        <choose>
            <when test="innIds != null and innIds.size > 0">
                innovation_id in
                <foreach collection="innIds" index="index" open="(" close=")" separator="," item="item">
                    #{item}
                </foreach>
            </when>
            <otherwise>
                1 = 2
            </otherwise>
        </choose>
        ) i
        JOIN wcx_user u on u.user_id = i.user_id
        LEFT JOIN wcx_file pic on pic.innovation_id = i.innovation_id and pic.file_type = '1'
        LEFT JOIN wcx_file video on video.innovation_id = i.innovation_id and video.file_type = '2'
        LEFT JOIN (select innovation_id, sum(thumb_number) thumbNumber from wcx_thumb group by innovation_id) thumb on
        thumb.innovation_id = i.innovation_id
        LEFT JOIN (select innovation_id, count(review_id) reviewNumber from wcx_review group by innovation_id) review on
        review.innovation_id = i.innovation_id
    </select>

    <select id="selectInnIdInPrizeItem" resultType="string">
        SELECT pi.inn_id
        FROM wcx_prize p
        JOIN wcx_prize_item pi on p.prize_id = pi.prize_id
        WHERE p.prize_type IN ('1', '2', '6') AND p.status = '1'
        GROUP BY pi.inn_id
    </select>

    <select id="selectInnIdInPrizeItemOfItemStatus" resultType="string">
        SELECT pi.inn_id
        FROM wcx_prize p
        JOIN wcx_prize_item pi on p.prize_id = pi.prize_id AND p.status = '1' and pi.status = #{status}
        WHERE p.prize_type IN ('1', '2', '6')
        GROUP BY pi.inn_id
    </select>

    <select id="findBestNumberInnNumMax" resultType="int">
        SELECT COUNT(i.innovation_id)
        FROM wcx_innovation i
        WHERE i.create_date <![CDATA[>=]]> #{startDate} AND i.create_date <![CDATA[<=]]> #{endDate}
        GROUP BY i.user_id
        ORDER BY COUNT(i.innovation_id) DESC
        LIMIT 1
    </select>

    <delete id="deleteByPrimateKey">
        DELETE FROM wcx_innovation WHERE innovation_id = #{innovationId}
    </delete>

    <select id="haveReview" resultType="string">
        SELECT review_id FROM wcx_review WHERE innovation_id = #{innovationId} limit 1
    </select>

    <select id="findSimplePageData" resultMap="BaseWcxInnovationDtoMap">
        SELECT
        i.innovation_id,
        i.innovation_title,
        i.innovation_simple_content,
        i.innovation_type,
        i.baseline,
        i.classification,
        i.team_content,
        i.user_id,
        i.status,
        i.create_date
        FROM wcx_innovation i
        WHERE
        <if test="innovationTitle != null">
            i.innovation_title like concat('%', #{innovationTitle}, '%')
        </if>
        limit #{pageOffset}, #{pageSize}
    </select>

    <select id="findInnNum" resultType="int">
        SELECT count(innovation_id) FROM wcx_innovation i WHERE i.user_id = #{userId}
        and i.create_date <![CDATA[>=]]> #{startDate} AND i.create_date <![CDATA[<=]]> #{endDate}
    </select>

    <select id="findInnIdsBigLeaderThumb" resultType="string">
        SELECT
        temi.innovation_id
        FROM wcx_innovation temi
        JOIN
        (SELECT b.innovation_id FROM wcx_thumb b
        WHERE b.role_id = (SELECT r.role_id FROM wcx_role r WHERE r.role_code = 'leader')
        AND b.create_date <![CDATA[>=]]> #{startDate} AND b.create_date <![CDATA[<=]]> #{endDate}) temb
        ON temi.innovation_id = temb.innovation_id
        WHERE temi.innovation_id NOT IN
        <include refid="BasePrizeInnIds"/>
    </select>
    <!-- 排除 baseline = 7 -->
    <select id="findInnIdsBigLeaderThumbExclude" resultType="string">
        SELECT
        temi.innovation_id
        FROM wcx_innovation temi
        JOIN
        (SELECT b.innovation_id FROM wcx_thumb b
        WHERE b.role_id = (SELECT r.role_id FROM wcx_role r WHERE r.role_code = 'leader')
        AND b.create_date <![CDATA[>=]]> #{startDate} AND b.create_date <![CDATA[<=]]> #{endDate}) temb
        ON temi.innovation_id = temb.innovation_id
        WHERE temi.baseline !='7' and temi.innovation_id NOT IN
        <include refid="BasePrizeInnIds"/>
    </select>

    <select id="findInn" resultMap="BaseWcxInnovationDtoMap">
        SELECT
        inn.*,
        u.employee_name,
        IFNULL(thumbNum, 0) thumbNumber
        FROM (
        SELECT *
        FROM wcx_innovation
        WHERE innovation_id in
        <foreach collection="innIds" index="index" open="(" close=")" separator="," item="item">
            #{item}
        </foreach>
        ) inn
        JOIN wcx_user u ON u.user_id = inn.user_id
        LEFT JOIN (
        SELECT SUM(thumb_number) thumbNum, innovation_id
        FROM wcx_thumb
        WHERE create_date <![CDATA[>=]]> #{startDate} AND create_date <![CDATA[<=]]> #{endDate}
        GROUP BY innovation_id
        ) thumb ON thumb.innovation_id = inn.innovation_id
        ORDER BY thumbNum DESC
    </select>
    <!-- 排除掉 baseline =7  -->
    <select id="findInnExclude" resultMap="BaseWcxInnovationDtoMap">
        SELECT
        inn.*,
        u.employee_name,
        IFNULL(thumbNum, 0) thumbNumber
        FROM (
        SELECT *
        FROM wcx_innovation
        WHERE baseline !='7' and innovation_id in
        <foreach collection="innIds" index="index" open="(" close=")" separator="," item="item">
            #{item}
        </foreach>
        ) inn
        JOIN wcx_user u ON u.user_id = inn.user_id
        LEFT JOIN (
        SELECT SUM(thumb_number) thumbNum, innovation_id
        FROM wcx_thumb
        WHERE create_date <![CDATA[>=]]> #{startDate} AND create_date <![CDATA[<=]]> #{endDate}
        GROUP BY innovation_id
        ) thumb ON thumb.innovation_id = inn.innovation_id
        ORDER BY thumbNum DESC
    </select>

    <select id="findInnOrderByThumbNumIncludeBigLeaderThumb" resultMap="BaseWcxInnovationDtoMap">
        SELECT
        inn.*,
        u.employee_name,
        IFNULL(innsimple.thumbNum, 0) thumbNumber
        FROM (
        SELECT innovationId, thumbNum
        FROM (
        SELECT temi1.innovation_id innovationId, 1 orderFlag, 0 thumbNum
        FROM wcx_innovation temi1
        WHERE temi1.innovation_id IN
        <foreach collection="bigLeaderThumbInnIds" index="index" open="(" close=")" separator="," item="item">
            #{item}
        </foreach>
        UNION
        SELECT temi2.innovation_id innovationId, 0 orderFlag, temt1.thumbNum thumbNum
        FROM wcx_innovation temi2
        LEFT JOIN (
        SELECT SUM(thumb_number) thumbNum, innovation_id
        FROM wcx_thumb
        WHERE create_date <![CDATA[>=]]> #{startDate}
        AND create_date <![CDATA[<=]]> #{endDate}
        GROUP BY innovation_id
        ) temt1 ON temt1.innovation_id = temi2.innovation_id
        WHERE temi2.create_date <![CDATA[>=]]> #{startDate}
        AND temi2.create_date <![CDATA[<=]]> #{endDate}
        AND temi2.innovation_id NOT IN
        <foreach collection="bigLeaderThumbInnIds" index="index" open="(" close=")" separator="," item="item">
            #{item}
        </foreach>) temInnSimple
        ORDER BY temInnSimple.orderFlag DESC, temInnSimple.thumbNum DESC, temInnSimple.innovationId DESC
        limit #{pageSize}
        ) innsimple
        JOIN wcx_innovation inn ON innsimple.innovationId = inn.innovation_id
        JOIN wcx_user u ON u.user_id = inn.user_id
    </select>

    <!-- 获奖的创新 -->
    <sql id="BasePrizeInnIds">
        (SELECT pi.inn_id
        FROM wcx_prize p
        JOIN wcx_prize_item pi on p.prize_id = pi.prize_id
        WHERE p.prize_type in ('1', '2') AND p.status = '1' AND pi.status = '1')
    </sql>

    <select id="findInnIdsPercent20" resultType="string">
        SELECT innovationId
        FROM (
        SELECT ti1.innovation_id innovationId, 1 orderFlag, 0 thumbNum
        FROM wcx_innovation ti1
        WHERE ti1.innovation_id IN
        <foreach collection="bigLeaderThumbInnIds" index="index" open="(" close=")" separator="," item="item">
            #{item}
        </foreach>
        UNION
        SELECT ti2.innovation_id innovationId, 0 orderFlag, temt1.thumbNum thumbNum
        FROM wcx_innovation ti2
        JOIN (
        SELECT SUM(thumb_number) thumbNum, innovation_id
        FROM wcx_thumb
        WHERE create_date <![CDATA[>=]]> #{startDate}
        AND create_date <![CDATA[<=]]> #{endDate}
        GROUP BY innovation_id
        ) temt1 ON temt1.innovation_id = ti2.innovation_id
        WHERE
        ti2.innovation_id NOT IN
        <foreach collection="bigLeaderThumbInnIds" index="index" open="(" close=")" separator="," item="item">
            #{item}
        </foreach>
        AND ti2.innovation_id not in
        <include refid="BasePrizeInnIds"/>
        ) temInnSimple
        ORDER BY temInnSimple.orderFlag DESC, temInnSimple.thumbNum DESC, temInnSimple.innovationId DESC
        limit #{pageSize}
    </select>
    <!-- 排除掉 baseline !=7 -->
    <select id="findInnIdsPercent20Exclude" resultType="string">
        SELECT innovationId
        FROM (
        SELECT ti1.innovation_id innovationId, 1 orderFlag, 0 thumbNum
        FROM wcx_innovation ti1
        WHERE ti1.baseline !='7' and ti1.innovation_id IN
        <foreach collection="bigLeaderThumbInnIds" index="index" open="(" close=")" separator="," item="item">
            #{item}
        </foreach>
        UNION
        SELECT ti2.innovation_id innovationId, 0 orderFlag, temt1.thumbNum thumbNum
        FROM wcx_innovation ti2
        JOIN (
        SELECT SUM(thumb_number) thumbNum, innovation_id
        FROM wcx_thumb
        WHERE create_date <![CDATA[>=]]> #{startDate}
        AND create_date <![CDATA[<=]]> #{endDate}
        GROUP BY innovation_id
        ) temt1 ON temt1.innovation_id = ti2.innovation_id
        WHERE ti2.baseline !='7' and
        ti2.innovation_id NOT IN
        <foreach collection="bigLeaderThumbInnIds" index="index" open="(" close=")" separator="," item="item">
            #{item}
        </foreach>
        AND ti2.innovation_id not in
        <include refid="BasePrizeInnIds"/>
        ) temInnSimple
        ORDER BY temInnSimple.orderFlag DESC, temInnSimple.thumbNum DESC, temInnSimple.innovationId DESC
        limit #{pageSize}
    </select>

    <select id="findInnIdsByThumbNumber" resultType="string">
        SELECT i.innovation_id
        FROM (SELECT ti.innovation_id FROM wcx_innovation ti
        WHERE ti.create_date <![CDATA[>=]]> #{startDate}
        AND ti.create_date <![CDATA[<=]]> #{endDate}
        AND ti.innovation_id not in
        <include refid="BasePrizeInnIds"/>
        ) i
        LEFT JOIN wcx_thumb t ON i.innovation_id = t.innovation_id
        AND t.create_date <![CDATA[>=]]> #{startDate} AND t.create_date <![CDATA[<=]]> #{endDate}
        GROUP BY i.innovation_id
        HAVING SUM(t.thumb_number) = #{thumbNumber}
    </select>

    <!-- 排除掉 baseline = 7 -->
    <select id="findInnIdsByThumbNumberExclude" resultType="string">
        SELECT i.innovation_id
        FROM (SELECT ti.innovation_id FROM wcx_innovation ti
        WHERE
            ti.baseline !='7'
            AND ti.create_date <![CDATA[>=]]> #{startDate}
            AND ti.create_date <![CDATA[<=]]> #{endDate}
            AND ti.innovation_id not in
        <include refid="BasePrizeInnIds"/>
        ) i
        LEFT JOIN wcx_thumb t ON i.innovation_id = t.innovation_id
        AND t.create_date <![CDATA[>=]]> #{startDate} AND t.create_date <![CDATA[<=]]> #{endDate}
        GROUP BY i.innovation_id
        HAVING SUM(t.thumb_number) = #{thumbNumber}
    </select>


    <select id="updateBaseLineById">
        UPDATE  wcx_innovation
        SET baseline = #{baseline}
        WHERE innovation_id =#{innovationId}
    </select>

    <select id="findById" resultType="integer">
        SELECT count(*) FROM wcx_innovation
        WHERE innovation_id =#{innovationId}
    </select>
    <!--<choose>-->
    <!--<when test="thumbNumber = 0">-->
    <!--SUM(t.thumb_number) = 0 OR SUM(t.thumb_number) is NULL-->
    <!--</when>-->
    <!--<otherwise>-->
    <!--SUM(t.thumb_number) = #{thumbNumber}-->
    <!--</otherwise>-->
    <!--</choose>-->

    <select id="findInnByThumbCountMin" resultMap="BaseWcxInnovationDtoMap">
        SELECT
        inn.*,
        u.employee_name,
        IFNULL(thumb.thumbCount, 0) thumbNumber
        FROM (
        SELECT count(thumb_id) thumbCount, innovation_id
        FROM wcx_thumb t
        WHERE t.create_date <![CDATA[>=]]> #{startDate} and t.create_date <![CDATA[<=]]> #{endDate}
        and t.role_id IN (SELECT tr.role_id FROM wcx_role tr WHERE tr.role_type = '2')
        GROUP BY innovation_id
        HAVING count(thumb_id) >= #{thumbCountMin}
        ) thumb
        JOIN wcx_innovation inn on  thumb.innovation_id = inn.innovation_id
        JOIN wcx_user u on u.user_id = inn.user_id
    </select>
    <!-- 排除掉 baseline 7 -->
    <select id="findInnByThumbCountMinExclude" resultMap="BaseWcxInnovationDtoMap">
        SELECT
        inn.*,
        u.employee_name,
        IFNULL(thumb.thumbCount, 0) thumbNumber
        FROM (
        SELECT count(thumb_id) thumbCount, innovation_id
        FROM wcx_thumb t left join wcx_innovation wi on t.innovation_id=wi.innovation_id
        WHERE wi.innovation_id!='7' and t.create_date <![CDATA[>=]]> #{startDate} and t.create_date <![CDATA[<=]]> #{endDate}
        and t.role_id IN (SELECT tr.role_id FROM wcx_role tr WHERE tr.role_type = '2')
        GROUP BY innovation_id
        HAVING count(thumb_id) >= #{thumbCountMin}
        ) thumb
        JOIN wcx_innovation inn on  thumb.innovation_id = inn.innovation_id
        JOIN wcx_user u on u.user_id = inn.user_id
    </select>

    <select id="findFirstDto" resultMap="BaseWcxInnovationDtoMap">
        SELECT
            i.innovation_id,
            i.innovation_title,
            i.innovation_simple_content,
            i.innovation_content_id,
            i.innovation_type,
            i.baseline,
            i.classification,
            i.team_content,
            i.user_id,
            i.status,
            i.create_date,
            i.project_name,
            i.region_name,
            u.employee_name
        FROM wcx_innovation i
        LEFT JOIN wcx_user u ON u.user_id = i.user_id
        WHERE i.innovation_id = #{innoId}
    </select>

    <insert id="insertOne">
        INSERT INTO wcx_innovation (
            innovation_id,
            innovation_title,
            innovation_content_id,
            innovation_simple_content,
            innovation_type,
            baseline,
            classification,
            team_content,
            project_name,
            region_name,
            user_id,
            status,
            create_date,
            top_end_date
        ) VALUES (
            #{innovationId},
            #{innovationTitle},
            #{innovationContentId},
            #{innovationSimpleContent},
            #{innovationType},
            #{baseline},
            #{classification},
            #{teamContent},
            #{projectName},
            #{regionName},
            #{userId},
            #{status},
            #{createDate},
            #{topEndDate}
        )
    </insert>
    <select id="examineStatus" parameterType="java.lang.String" resultType="int">
        SELECT
         i.audit_status as examineStatus
        FROM wcx_innovation i
        WHERE i.innovation_id = #{innovationId}
    </select>
    <select id="getUserCode" parameterType="java.lang.String" resultType="java.lang.String">
        select
            user_code
        from user_roles
        where role_code=#{roleCode}
    </select>
    <select id="getUserName" resultType="java.lang.String" parameterType="list">
        SELECT  u.UserName,  u.OrganId
        FROM [HM_wygl_new_1853].[dbo].[Tb_Sys_User] AS u
        where u.UserCode in
        <foreach collection="userCodeList" index="index" open="(" close=")" separator="," item="item">
            #{item}
        </foreach>
    </select>
    <update id="updateExamine">
        update wcx_innovation
        set examiner=#{name}
        where innovation_id=#{innovationId}
    </update>

    <update id="updateTop">
        UPDATE wcx_innovation SET is_top = #{wcxIonDto.isTop},update_time=#{wcxIonDto.updateTime}
        WHERE innovation_id = #{wcxIonDto.innovationId};
    </update>

    <update id="updateRecomm">
         UPDATE wcx_innovation SET is_recomm = #{wcxIonDto.isRecomm},recomm_time=#{wcxIonDto.recommTime}
        WHERE innovation_id = #{wcxIonDto.innovationId};
    </update>
    <update id="addExcellent">
         UPDATE wcx_innovation SET is_excellent = #{wcxIonDto.isExcellent}
        WHERE innovation_id = #{wcxIonDto.innovationId};
    </update>

    <select id="selectIdList" resultType="String">
        SELECT DISTINCT
        i.innovation_id
        FROM (
        select ti.* from wcx_innovation ti
        <if test="employeeName != null and employeeName != ''">
            JOIN wcx_user tu ON tu.user_id = ti.user_id
        </if>
        <if test="roleType != null and roleType != ''">
            JOIN (
            SELECT
            wt.innovation_id
            FROM wcx_thumb wt
            JOIN wcx_role wr ON wt.role_id = wr.role_id
            WHERE wr.role_type=#{roleType}
            GROUP BY wt.innovation_id
            )wi ON wi.innovation_id = ti.innovation_id
        </if>
        <if test="roleCode !=null and  roleCode != ''">
            JOIN (
            SELECT
            wt.innovation_id
            FROM
            wcx_thumb wt
            JOIN wcx_role wr ON wt.role_id = wr.role_id
            WHERE wr.role_code =#{roleCode}
            GROUP BY wt.innovation_id
            ) wi ON wi.innovation_id = ti.innovation_id
        </if>
        <if test="orderByThumbNumber != null">
            LEFT JOIN (select innovation_id, sum(thumb_number) thumbNumber from wcx_thumb group by innovation_id) tt
            on tt.innovation_id = ti.innovation_id
        </if>
        <where>
             and ti.audit_status=1
            <if test="userId != null">
              and  ti.user_id = #{userId}
            </if>
            <if test="employeeName != null and employeeName != ''">
                AND tu.employee_name like concat('%', #{employeeName}, '%')
            </if>
            <if test="classification != null and classification != ''">
                and ti.classification = #{classification}
            </if>
            <if test="baseline != null and baseline != ''">
                and ti.baseline = #{baseline}
            </if>
            <if test="innovationTitle != null and innovationTitle != ''">
                and ti.innovation_title like concat('%', #{innovationTitle}, '%')
            </if>
            <if test="thumbUserId != null">
                and ti.innovation_id in (select innovation_id from wcx_thumb where user_id = #{thumbUserId})
            </if>
            <if test="collectionUserId != null">
                and ti.innovation_id in (select innovation_id from wcx_collection where user_id = #{collectionUserId})
            </if>
            <!-- 用于本月项目创新 -->
            <if test="projectName != null and monthStartDate != null and monthEndDate != null">
                AND ti.project_name = #{projectName} AND create_date <![CDATA[>=]]> #{monthStartDate} AND create_date
                <![CDATA[<=]]> #{monthEndDate}
            </if>
            <if test="startDate != null">
                AND ti.create_date <![CDATA[>=]]> #{startDate}
            </if>
            <if test="endDate != null">
                AND date(ti.create_date) <![CDATA[<=]]> #{endDate}
            </if>
            <!-- 区域 -->
            <if test="regionName != null and regionName !=''">
                AND ti.region_name like concat('%',#{regionName}, '%')
            </if>
            <!-- 项目 -->
            <if test="projectName != null and projectName !=''">
                AND ti.project_name like concat(#{projectName}, '%')
            </if>
            <if test="examineStatus != null and examineStatus!=''">
                and ti.audit_status=#{examineStatus}
            </if>
            <if test="isTop!=null">
                and ti.is_top=#{isTop}
            </if>
            <if test="isRecomm!=null">
                and ti.is_recomm=#{isRecomm}
            </if>
            <if test="isExcellent!=null">
                and ti.is_excellent=#{isExcellent}
            </if>
            <if test="isMoren==1">
                AND create_date <![CDATA[>=]]> #{startDateStr} AND create_date
                <![CDATA[<=]]> #{endDateStr}
            </if>
            <if test="regionList != null and regionList.size>0">
                and (
                <foreach collection="regionList" item="item" index="index"  separator="OR">
                    ti.region_name LIKE CONCAT('%',#{item},'%')
                </foreach>
                )
            </if>
            <if test="baselineList != null and baselineList.size>0">
                and ti.baseline in
                <foreach collection="baselineList" index="index" open="(" close=")" separator="," item="item">
                    #{item}
                </foreach>
            </if>
        </where>
        ORDER BY ti.create_date desc
        ) i
        LEFT JOIN  wcx_user u on u.user_id = i.user_id
        LEFT JOIN wcx_file pic on pic.innovation_id = i.innovation_id and pic.file_type = '1'
        LEFT JOIN wcx_file video on video.innovation_id = i.innovation_id and video.file_type = '2'
        LEFT JOIN (select innovation_id, sum(thumb_number) thumbNumber from wcx_thumb group by innovation_id) thumb on
        thumb.innovation_id = i.innovation_id
        LEFT JOIN (select innovation_id, count(review_id) reviewNumber from wcx_review group by innovation_id) review on
        review.innovation_id = i.innovation_id

    </select>

    <select id="selectIdListAudit" resultType="String">
        SELECT DISTINCT
        i.innovation_id
        FROM (
        select ti.* from wcx_innovation ti
        <if test="employeeName != null and employeeName != ''">
            JOIN wcx_user tu ON tu.user_id = ti.user_id
        </if>
        <if test="roleType != null and roleType != ''">
            JOIN (
            SELECT
            wt.innovation_id
            FROM wcx_thumb wt
            JOIN wcx_role wr ON wt.role_id = wr.role_id
            WHERE wr.role_type=#{roleType}
            GROUP BY wt.innovation_id
            )wi ON wi.innovation_id = ti.innovation_id
        </if>
        <if test="roleCode !=null and  roleCode != ''">
            JOIN (
            SELECT
            wt.innovation_id
            FROM
            wcx_thumb wt
            JOIN wcx_role wr ON wt.role_id = wr.role_id
            WHERE wr.role_code =#{roleCode}
            GROUP BY wt.innovation_id
            ) wi ON wi.innovation_id = ti.innovation_id
        </if>
        <if test="orderByThumbNumber != null">
            LEFT JOIN (select innovation_id, sum(thumb_number) thumbNumber from wcx_thumb group by innovation_id) tt
            on tt.innovation_id = ti.innovation_id
        </if>
        <where>
            and (ti.audit_status=0 or ti.audit_status=2)
            <if test="userId != null">
                and  ti.user_id = #{userId}
            </if>
            <if test="employeeName != null and employeeName != ''">
                AND tu.employee_name like concat('%', #{employeeName}, '%')
            </if>
            <if test="classification != null and classification != ''">
                and ti.classification = #{classification}
            </if>
            <if test="baseline != null and baseline != ''">
                and ti.baseline = #{baseline}
            </if>
            <if test="innovationTitle != null and innovationTitle != ''">
                and ti.innovation_title like concat('%', #{innovationTitle}, '%')
            </if>
            <if test="thumbUserId != null">
                and ti.innovation_id in (select innovation_id from wcx_thumb where user_id = #{thumbUserId})
            </if>
            <if test="collectionUserId != null">
                and ti.innovation_id in (select innovation_id from wcx_collection where user_id = #{collectionUserId})
            </if>
            <!-- 用于本月项目创新 -->
            <if test="projectName != null and monthStartDate != null and monthEndDate != null">
                AND ti.project_name = #{projectName} AND create_date <![CDATA[>=]]> #{monthStartDate} AND create_date
                <![CDATA[<=]]> #{monthEndDate}
            </if>
            <if test="startDate != null">
                AND ti.create_date <![CDATA[>=]]> #{startDate}
            </if>
            <if test="endDate != null">
                AND date(ti.create_date) <![CDATA[<=]]> #{endDate}
            </if>
            <!-- 区域 -->
            <if test="regionName != null and regionName !=''">
                AND ti.region_name like concat('%',#{regionName}, '%')
            </if>
            <!-- 项目 -->
            <if test="projectName != null and projectName !=''">
                AND ti.project_name like concat(#{projectName}, '%')
            </if>
            <if test="examineStatus != null and examineStatus!=''">
                and ti.audit_status=#{examineStatus}
            </if>
            <if test="isTop!=null">
                and ti.is_top=#{isTop}
            </if>
            <if test="isRecomm!=null">
                and ti.is_recomm=#{isRecomm}
            </if>
            <if test="isExcellent!=null">
                and ti.is_excellent=#{isExcellent}
            </if>
            <if test="isMoren==1">
                AND create_date <![CDATA[>=]]> #{startDateStr} AND create_date
                <![CDATA[<=]]> #{endDateStr}
            </if>
            <if test="regionList != null and regionList.size>0">
                and (
                <foreach collection="regionList" item="item" index="index"  separator="OR">
                    ti.region_name LIKE CONCAT('%',#{item},'%')
                </foreach>
                )
            </if>
            <if test="baselineList != null and baselineList.size>0">
                and ti.baseline in
                <foreach collection="baselineList" index="index" open="(" close=")" separator="," item="item">
                    #{item}
                </foreach>
            </if>
        </where>
        ORDER BY ti.create_date DESC
        ) i
        LEFT JOIN  wcx_user u on u.user_id = i.user_id
        LEFT JOIN wcx_file pic on pic.innovation_id = i.innovation_id and pic.file_type = '1'
        LEFT JOIN wcx_file video on video.innovation_id = i.innovation_id and video.file_type = '2'
        LEFT JOIN (select innovation_id, sum(thumb_number) thumbNumber from wcx_thumb group by innovation_id) thumb on
        thumb.innovation_id = i.innovation_id
        LEFT JOIN (select innovation_id, count(review_id) reviewNumber from wcx_review group by innovation_id) review on
        review.innovation_id = i.innovation_id
    </select>

    <select id="selectgetOne" resultMap="BaseWcxInnovationDtoMap">
         SELECT
            i.innovation_id,
            i.innovation_title,
            i.innovation_simple_content,
            i.innovation_type,
            i.baseline,
            i.classification,
            i.team_content,
            i.user_id,
            i.status,
            i.create_date,
            i.region_name,
            i.project_name,
            i.is_excellent,
            i.audit_status
        FROM (
          SELECT * FROM wcx_innovation WHERE innovation_id = #{innovationId}
        ) i
    </select>
</mapper>