<?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.zongzhi.mapper.TcCommentatorMapper">
    
    <resultMap type="TcCommentator" id="TcCommentatorResult">
        <result property="id"    column="id"    />
        <result property="areaId"    column="area_id"    />
        <result property="name"    column="name"    />
        <result property="sex"    column="sex"    />
        <result property="age"    column="age"    />
        <result property="nationality"    column="nationality"    />
        <result property="politicsStatus"    column="politics_status"    />
        <result property="unit"    column="unit"    />
        <result property="phoneNum"    column="phone_num"    />
        <result property="vxNum"    column="vx_num"    />
        <result property="type"    column="type"    />
        <result property="createId"    column="create_id"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateId"    column="update_id"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectTcCommentatorVo">
        select id, area_id, name, sex, age, nationality, politics_status, unit, phone_num, vx_num, type, create_id, create_by, create_time, update_id, update_by, update_time, remark from tc_commentator
    </sql>

    <select id="selectTcCommentatorList" parameterType="TcCommentator" resultMap="TcCommentatorResult">
        <include refid="selectTcCommentatorVo"/>
        <where>  
            <if test="areaId != null "> and area_id = #{areaId}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="sex != null  and sex != ''"> and sex = #{sex}</if>
            <if test="age != null "> and age = #{age}</if>
            <if test="nationality != null  and nationality != ''"> and nationality = #{nationality}</if>
            <if test="politicsStatus != null  and politicsStatus != ''"> and politics_status = #{politicsStatus}</if>
            <if test="unit != null  and unit != ''"> and unit = #{unit}</if>
            <if test="phoneNum != null  and phoneNum != ''"> and phone_num = #{phoneNum}</if>
            <if test="vxNum != null  and vxNum != ''"> and vx_num = #{vxNum}</if>
            <if test="type != null "> and type = #{type}</if>
            <if test="createId != null "> and create_id = #{createId}</if>
            <if test="updateId != null "> and update_id = #{updateId}</if>
        </where>
    </select>
    
    <select id="selectTcCommentatorById" parameterType="Long" resultMap="TcCommentatorResult">
        <include refid="selectTcCommentatorVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTcCommentator" parameterType="TcCommentator" useGeneratedKeys="true" keyProperty="id">
        insert into tc_commentator
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="areaId != null">area_id,</if>
            <if test="name != null">name,</if>
            <if test="sex != null">sex,</if>
            <if test="age != null">age,</if>
            <if test="nationality != null">nationality,</if>
            <if test="politicsStatus != null">politics_status,</if>
            <if test="unit != null">unit,</if>
            <if test="phoneNum != null">phone_num,</if>
            <if test="vxNum != null">vx_num,</if>
            <if test="type != null">type,</if>
            <if test="createId != null">create_id,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateId != null">update_id,</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="areaId != null">#{areaId},</if>
            <if test="name != null">#{name},</if>
            <if test="sex != null">#{sex},</if>
            <if test="age != null">#{age},</if>
            <if test="nationality != null">#{nationality},</if>
            <if test="politicsStatus != null">#{politicsStatus},</if>
            <if test="unit != null">#{unit},</if>
            <if test="phoneNum != null">#{phoneNum},</if>
            <if test="vxNum != null">#{vxNum},</if>
            <if test="type != null">#{type},</if>
            <if test="createId != null">#{createId},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateId != null">#{updateId},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateTcCommentator" parameterType="TcCommentator">
        update tc_commentator
        <trim prefix="SET" suffixOverrides=",">
            <if test="areaId != null">area_id = #{areaId},</if>
            <if test="name != null">name = #{name},</if>
            <if test="sex != null">sex = #{sex},</if>
            <if test="age != null">age = #{age},</if>
            <if test="nationality != null">nationality = #{nationality},</if>
            <if test="politicsStatus != null">politics_status = #{politicsStatus},</if>
            <if test="unit != null">unit = #{unit},</if>
            <if test="phoneNum != null">phone_num = #{phoneNum},</if>
            <if test="vxNum != null">vx_num = #{vxNum},</if>
            <if test="type != null">type = #{type},</if>
            <if test="createId != null">create_id = #{createId},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateId != null">update_id = #{updateId},</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="deleteTcCommentatorById" parameterType="Long">
        delete from tc_commentator where id = #{id}
    </delete>

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