<?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.KhVoteEmpMapper">

    <resultMap type="KhVoteEmp" id="KhVoteEmpResult">
        <result property="id"    column="id"    />
        <result property="khitemTypeid"    column="khitem_typeId"    />
        <result property="voteId"    column="vote_id"    />
        <result property="voteTitle"    column="vote_title"    />
        <result property="bkhdxId"    column="bkhdx_id"    />
        <result property="bkhdxName"    column="bkhdx_name"    />
        <result property="content"    column="content"    />
        <result property="voteNum"    column="vote_num"    />
        <result property="optionA"    column="option_a"    />
        <result property="optionB"    column="option_b"    />
        <result property="optionC"    column="option_c"    />
        <result property="optionD"    column="option_d"    />
        <result property="voteScore"    column="vote_score"    />
        <result property="avgScore"    column="avg_score"    />
        <result property="percentage"    column="percentage"    />
        <result property="endScore"    column="end_score"    />
        <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"    />
        <result property="version"    column="version"    />
    </resultMap>

    <sql id="selectKhVoteEmpVo">
        select id, khitem_typeId, vote_id, vote_title, bkhdx_id, bkhdx_name, content, vote_num,option_a, option_b, option_c, option_d, vote_score, avg_score, percentage, end_score, create_by, create_time, update_by, update_time, remark, version from kh_vote_emp
    </sql>

    <select id="selectKhVoteEmpList" parameterType="KhVoteEmp" resultMap="KhVoteEmpResult">
        <include refid="selectKhVoteEmpVo"/>
        <where>
            <if test="khitemTypeid != null "> and khitem_typeId = #{khitemTypeid}</if>
            <if test="voteId != null "> and vote_id = #{voteId}</if>
            <if test="voteTitle != null  and voteTitle != ''"> and vote_title = #{voteTitle}</if>
            <if test="bkhdxId != null "> and bkhdx_id = #{bkhdxId}</if>
            <if test="bkhdxName != null  and bkhdxName != ''"> and bkhdx_name like concat('%', #{bkhdxName}, '%')</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="voteNum != null "> and vote_num = #{voteNum}</if>
            <if test="optionA != null "> and option_a = #{optionA}</if>
            <if test="optionB != null "> and option_b = #{optionB}</if>
            <if test="optionC != null "> and option_c = #{optionC}</if>
            <if test="optionD != null "> and option_d = #{optionD}</if>
            <if test="voteScore != null "> and vote_score = #{voteScore}</if>
            <if test="avgScore != null "> and avg_score = #{avgScore}</if>
            <if test="percentage != null "> and percentage = #{percentage}</if>
            <if test="endScore != null "> and end_score = #{endScore}</if>
            <!--<if test="version != null "> and version = #{version}</if>-->
        </where>
    </select>
    <!--投票页面查询考核及考核对象信息-->
    <select id="selectVoteEmpsByVoteId" parameterType="KhVoteEmp" resultMap="KhVoteEmpResult">
        select id, khitem_typeId, vote_id, bkhdx_id, bkhdx_name from kh_vote_emp
        <where>
            <if test="voteId != null "> and vote_id = #{voteId}</if>
        </where>
    </select>

    <select id="selectKhVoteEmpById" parameterType="Long" resultMap="KhVoteEmpResult">
        <include refid="selectKhVoteEmpVo"/>
        where id = #{id}
    </select>

    <insert id="insertKhVoteEmp" parameterType="KhVoteEmp" useGeneratedKeys="true" keyProperty="id">
        insert into kh_vote_emp
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="khitemTypeid != null">khitem_typeId,</if>
            <if test="voteId != null">vote_id,</if>
            <if test="voteTitle != null">vote_title,</if>
            <if test="bkhdxId != null">bkhdx_id,</if>
            <if test="bkhdxName != null">bkhdx_name,</if>
            <if test="content != null">content,</if>
            <if test="voteNum != null">vote_num,</if>
            <if test="optionA != null">option_a,</if>
            <if test="optionB != null">option_b,</if>
            <if test="optionC != null">option_c,</if>
            <if test="optionD != null">option_d,</if>
            <if test="voteScore != null">vote_score,</if>
            <if test="avgScore != null">avg_score,</if>
            <if test="percentage != null">percentage,</if>
            <if test="endScore != null">end_score,</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>
            <!--<if test="version != null">version,</if>-->
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="khitemTypeid != null">#{khitemTypeid},</if>
            <if test="voteId != null">#{voteId},</if>
            <if test="voteTitle != null">#{voteTitle},</if>
            <if test="bkhdxId != null">#{bkhdxId},</if>
            <if test="bkhdxName != null">#{bkhdxName},</if>
            <if test="content != null">#{content},</if>
            <if test="voteNum != null">#{voteNum},</if>
            <if test="optionA != null">#{optionA},</if>
            <if test="optionB != null">#{optionB},</if>
            <if test="optionC != null">#{optionC},</if>
            <if test="optionD != null">#{optionD},</if>
            <if test="voteScore != null">#{voteScore},</if>
            <if test="avgScore != null">#{avgScore},</if>
            <if test="percentage != null">#{percentage},</if>
            <if test="endScore != null">#{endScore},</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>
            <!--<if test="version != null">#{version},</if>-->
        </trim>
    </insert>

    <update id="updateKhVoteEmp" parameterType="KhVoteEmp">
        update kh_vote_emp
        <trim prefix="SET" suffixOverrides=",">
            <if test="khitemTypeid != null">khitem_typeId = #{khitemTypeid},</if>
            <if test="voteId != null">vote_id = #{voteId},</if>
            <if test="voteTitle != null">vote_title = #{voteTitle},</if>
            <if test="bkhdxId != null">bkhdx_id = #{bkhdxId},</if>
            <if test="bkhdxName != null">bkhdx_name = #{bkhdxName},</if>
            <if test="content != null">content = #{content},</if>
            <if test="voteNum != null">vote_num = #{voteNum},</if>
            <if test="optionA != null">option_a = #{optionA},</if>
            <if test="optionB != null">option_b = #{optionB},</if>
            <if test="optionC != null">option_c = #{optionC},</if>
            <if test="optionD != null">option_d = #{optionD},</if>
            <if test="voteScore != null">vote_score = #{voteScore},</if>
            <if test="avgScore != null">avg_score = #{avgScore},</if>
            <if test="percentage != null">percentage = #{percentage},</if>
            <if test="endScore != null">end_score = #{endScore},</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>
        <!-- 其他需要更新的字段 /* version = version + 1 AND version = #{version}*/-->
        WHERE id = #{id}
    </update>

    <delete id="deleteKhVoteEmpById" parameterType="Long">
        delete from kh_vote_emp where id = #{id}
    </delete>

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