<?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="com.ruoyi.kaohe.mapper.KhVoteMapper">

    <resultMap type="KhVote" id="KhVoteResult">
        <result property="id"    column="id"    />
        <result property="pingceId"    column="pingce_id"    />
        <result property="pingceName"    column="pingce_name"    />
        <result property="bkhdxType"    column="bkhdx_type"    />
        <result property="khitemId"    column="khitem_id"    />
        <result property="khitemName"    column="khitem_name"    />
        <result property="khitemTypeid"    column="khitem_typeId"    />
        <result property="voteItems"    column="vote_items"    />
        <result property="voteTitle"    column="vote_title"    />
        <result property="vDescription"    column="v_description"    />
        <result property="sTime"    column="s_time"    />
        <result property="eTime"    column="e_time"    />
        <result property="maxNum"    column="max_num"    />
        <result property="umax"    column="umax"    />
        <result property="percentage"    column="percentage"    />
        <result property="state"    column="state"    />
        <result property="samePercent"    column="same_percent"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectKhVoteVo">
        select id, pingce_id, pingce_name,bkhdx_type, khitem_id, khitem_name, khitem_typeId, vote_items, vote_title, v_description, s_time, e_time, max_num, umax, percentage, `state`,same_percent, create_by, create_time, update_by, update_time, remark from kh_vote
    </sql>

    <select id="selectKhVoteList" parameterType="KhVote" resultMap="KhVoteResult">
        select v.*,it.type_id from kh_vote v left join kh_items it on   v.khitem_id =it.id
        <!--left join kh_pingce p on v.pingce_id=p.id-->
       <where>
           <if test="pingceId != null "> and pingce_id = #{pingceId}</if>
           <if test="pingceName != null  and pingceName != ''"> and pingce_name like concat('%', #{pingceName}, '%')</if>
         <!--  <if test="pingceName != null  and pingceName != ''"> and p.bkhdx_type = #{bkhdxType}=</if>-->
            <if test="khitemId != null "> and khitem_id = #{khitemId}</if>
            <if test="khitemName != null  and khitemName != ''"> and khitem_name like concat('%', #{khitemName}, '%')</if>
            <if test="khitemTypeid != null "> and khitem_typeId = #{khitemTypeid}</if>
            <if test="voteItems != null  and voteItems != ''"> and vote_items = #{voteItems}</if>
            <if test="voteTitle != null  and voteTitle != ''"> and vote_title = #{voteTitle}</if>
            <if test="vDescription != null  and vDescription != ''"> and v_description = #{vDescription}</if>
            <if test="sTime != null "> and s_time = #{sTime}</if>
            <if test="eTime != null "> and e_time = #{eTime}</if>
            <if test="maxNum != null "> and max_num = #{maxNum}</if>
            <if test="umax != null "> and umax = #{umax}</if>
            <if test="percentage != null "> and percentage = #{percentage}</if>
            <if test="state != null  and state != ''"> and state = #{state}</if>
            <if test="samePercent != null  and samePercent != ''"> and same_percent = #{samePercent}</if>
        </where>
    </select>
    <!--生成评测账号登录时筛选符合条件的vote展示评分     ————废弃————   -->
    <!--<select id="getListByPcIdAndItemIds" parameterType="KhVote" resultMap="KhVoteResult">
        select v.*,it.type_id from kh_vote v left join kh_items it on   v.khitem_id =it.id
        <where>
            <if test="pingceId != null "> and pingce_id = #{pingceId}</if>
            &lt;!&ndash;状态值传1，也就是展示所有状态不等于2（非完成状态）的数据&ndash;&gt;
            <if test="state != null  and state != ''"> and state != #{state}</if>
            <if test="itemIds != null"> and khitem_id in
                <foreach item="itemId" collection="itemIds" open="(" separator="," close=")">
                    #{itemId}
                </foreach>
            </if>
        </where>
    </select>-->
    <!-- 评测账号登录时筛选符合条件的vote展示评分 -->
    <select id="getListByVoteIds" parameterType="KhVote" resultMap="KhVoteResult">
        select v.*,it.type_id from kh_vote v left join kh_items it on   v.khitem_id =it.id
        <where>
            <if test="pingceName != null  and pingceName != ''"> and pingce_name like concat('%', #{pingceName}, '%')</if>
            <if test="voteTitle != null  and voteTitle != ''"> and vote_title like concat('%', #{voteTitle}, '%') </if>
            <!--状态值传1，也就是展示所有状态不等于2（非完成状态）的数据-->
            <if test="state != null  and state != ''"> and state != #{state}</if>
            <if test="voteIds != null"> and v.id in
                <foreach item="voteId" collection="voteIds" open="(" separator="," close=")">
                    #{voteId}
                </foreach>
            </if>
        </where>
    </select>

    <select id="selectUnfinishedVote" parameterType="KhVote" resultMap="KhVoteResult">
        select v.*,it.type_id from kh_vote v left join kh_items it on   v.khitem_id =it.id
        where  v.state !='2'
    </select>

    <select id="selectKhVoteById" parameterType="Long" resultMap="KhVoteResult">
        select v.*,it.type_id,p.bkhdx_type from kh_vote v left join kh_items it on   v.khitem_id =it.id
        left join kh_pingce p on v.pingce_id=p.id
        where v.id = #{id}
    </select>

    <insert id="insertKhVote" parameterType="KhVote" useGeneratedKeys="true" keyProperty="id">
        insert into kh_vote
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="pingceId != null">pingce_id,</if>
            <if test="pingceName != null">pingce_name,</if>
            <if test="khitemId != null">khitem_id,</if>
            <if test="khitemName != null">khitem_name,</if>
            <if test="khitemTypeid != null">khitem_typeId,</if>
            <if test="voteItems != null">vote_items,</if>
            <if test="voteTitle != null and voteTitle != ''">vote_title,</if>
            <if test="vDescription != null">v_description,</if>
            <if test="sTime != null">s_time,</if>
            <if test="eTime != null">e_time,</if>
            <if test="maxNum != null">max_num,</if>
            <if test="umax != null">umax,</if>
            <if test="percentage != null">percentage,</if>
            <if test="state != null">state,</if>
            <if test="samePercent != null">same_percent,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="pingceId != null">#{pingceId},</if>
            <if test="pingceName != null">#{pingceName},</if>
            <if test="khitemId != null">#{khitemId},</if>
            <if test="khitemName != null">#{khitemName},</if>
            <if test="khitemTypeid != null">#{khitemTypeid},</if>
            <if test="voteItems != null">#{voteItems},</if>
            <if test="voteTitle != null and voteTitle != ''">#{voteTitle},</if>
            <if test="vDescription != null">#{vDescription},</if>
            <if test="sTime != null">#{sTime},</if>
            <if test="eTime != null">#{eTime},</if>
            <if test="maxNum != null">#{maxNum},</if>
            <if test="umax != null">#{umax},</if>
            <if test="percentage != null">#{percentage},</if>
            <if test="state != null">#{state},</if>
            <if test="samePercent != null">#{samePercent},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateKhVote" parameterType="KhVote">
        update kh_vote
        <trim prefix="SET" suffixOverrides=",">
            <if test="pingceId != null">pingce_id = #{pingceId},</if>
            <if test="pingceName != null">pingce_name = #{pingceName},</if>
            <if test="khitemId != null">khitem_id = #{khitemId},</if>
            <if test="khitemName != null">khitem_name = #{khitemName},</if>
            <if test="khitemTypeid != null">khitem_typeId = #{khitemTypeid},</if>
            <if test="voteItems != null">vote_items = #{voteItems},</if>
            <if test="voteTitle != null and voteTitle != ''">vote_title = #{voteTitle},</if>
            <if test="vDescription != null">v_description = #{vDescription},</if>
            <if test="sTime != null">s_time = #{sTime},</if>
            <if test="eTime != null">e_time = #{eTime},</if>
            <if test="maxNum != null">max_num = #{maxNum},</if>
            <if test="umax != null">umax = #{umax},</if>
            <if test="percentage != null">percentage = #{percentage},</if>
            <if test="state != null">state = #{state},</if>
            <if test="samePercent != null">same_percent = #{samePercent},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteKhVoteById" parameterType="Long">
        delete from kh_vote where id = #{id}
    </delete>

    <delete id="deleteKhVoteByIds" parameterType="String">
        delete from kh_vote where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>