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

    <resultMap type="KhVoteRecard" id="KhVoteRecardResult">
        <result property="id"    column="id"    />
        <result property="pcId"    column="pingce_id"    />
        <result property="pcName"    column="pingce_name"    />
        <result property="khitemId"    column="khitem_id"    />
        <result property="voteId"    column="vote_id"    />
        <result property="votTitle"    column="vote_title"    />
        <result property="userId"    column="user_id"    />
        <result property="userName"    column="user_name"    />
        <result property="uid"    column="uid"    />
        <result property="tprName"    column="tpr_name"    />
        <result property="voteDetails"    column="vote_details"    />
        <result property="voteTime"    column="vote_time"    />
        <result property="ipAddress"    column="ip_address"    />
        <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="selectKhVoteRecardVo">
        select id, pc_id, khitem_id, vote_id, user_id, user_name, uid, tpr_name, vote_details, vote_time, ip_address, create_by, create_time, update_by, update_time, remark from kh_vote_recard
    </sql>

    <select id="selectKhVoteRecardList" parameterType="KhVoteRecard" resultMap="KhVoteRecardResult">
        select r.id,v.pingce_id,r.vote_id,r.user_name,r.vote_details,r.vote_time,v.pingce_name,v.vote_title
            from kh_vote_recard r join kh_vote v on r.vote_id=v.id
        <where>
            <if test="pcId != null "> and v.pingce_id = #{pcId}</if>
            <if test="pcName != null and pcName != '' "> and v.pingce_name like concat('%', #{pcName}, '%')</if>
            <if test="khitemId != null "> and r.khitem_id = #{khitemId}</if>
            <if test="voteId != null "> and r.vote_id = #{voteId}</if>
            <if test="voteTitle != null and voteTitle != '' "> and v.vote_title like concat('%', #{voteTitle}, '%')</if>
            <if test="userId != null "> and r.user_id = #{userId}</if>
            <if test="userName != null  and userName != ''"> and r.user_name like concat('%', #{userName}, '%')</if>
            <if test="uid != null "> and r.uid = #{uid}</if>
            <if test="tprName != null  and tprName != ''"> and r.tpr_name like concat('%', #{tprName}, '%')</if>
           <!-- <if test="voteDetails != null  and voteDetails != ''"> and r.vote_details = #{voteDetails}</if>-->
            <if test="voteTime != null "> and r.vote_time = #{voteTime}</if>
            <if test="ipAddress != null  and ipAddress != ''"> and r.ip_address = #{ipAddress}</if>
        </where>
    </select>

    <select id="selectKhVoteRecardById" parameterType="Long" resultMap="KhVoteRecardResult">
        <include refid="selectKhVoteRecardVo"/>
        where id = #{id}
    </select>

    <insert id="insertKhVoteRecard" parameterType="KhVoteRecard" useGeneratedKeys="true" keyProperty="id">
        insert into kh_vote_recard
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="pcId != null">pc_id,</if>
            <if test="khitemId != null">khitem_id,</if>
            <if test="voteId != null">vote_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="userName != null">user_name,</if>
            <if test="uid != null">uid,</if>
            <if test="tprName != null">tpr_name,</if>
            <if test="voteDetails != null">vote_details,</if>
            <if test="voteTime != null">vote_time,</if>
            <if test="ipAddress != null">ip_address,</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="pcId != null">#{pcId},</if>
            <if test="khitemId != null">#{khitemId},</if>
            <if test="voteId != null">#{voteId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="userName != null">#{userName},</if>
            <if test="uid != null">#{uid},</if>
            <if test="tprName != null">#{tprName},</if>
            <if test="voteDetails != null">#{voteDetails},</if>
            <if test="voteTime != null">#{voteTime},</if>
            <if test="ipAddress != null">#{ipAddress},</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="updateKhVoteRecard" parameterType="KhVoteRecard">
        update kh_vote_recard
        <trim prefix="SET" suffixOverrides=",">
            <if test="pcId != null">pc_id = #{pcId},</if>
            <if test="khitemId != null">khitem_id = #{khitemId},</if>
            <if test="voteId != null">vote_id = #{voteId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="uid != null">uid = #{uid},</if>
            <if test="tprName != null">tpr_name = #{tprName},</if>
            <if test="voteDetails != null">vote_details = #{voteDetails},</if>
            <if test="voteTime != null">vote_time = #{voteTime},</if>
            <if test="ipAddress != null">ip_address = #{ipAddress},</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="deleteKhVoteRecardById" parameterType="Long">
        delete from kh_vote_recard where id = #{id}
    </delete>

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