<?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.system.mapper.WorkerLevelMapper">
    
    <resultMap type="WorkerLevel" id="WorkerLevelResult">
        <result property="id"    column="id"    />
        <result property="title"    column="title"    />
        <result property="level"    column="level"    />
        <result property="ar"    column="ar"    />
        <result property="totalPrice"    column="total_price"    />
        <result property="cr"    column="cr"    />
        <result property="image"    column="image"    />
        <result property="bgImage"    column="bg_image"    />
        <result property="color"    column="color"    />
        <result property="userBgimg"    column="user_bgimg"    />
        <result property="createdAt"    column="created_at"    />
        <result property="updatedAt"    column="updated_at"    />
        <result property="deletedAt"    column="deleted_at"    />
    </resultMap>

    <sql id="selectWorkerLevelVo">
        select id, title, level, ar, total_price, cr, image, bg_image, color, user_bgimg, created_at, updated_at, deleted_at from worker_level
    </sql>

    <select id="selectWorkerLevelList" parameterType="WorkerLevel" resultMap="WorkerLevelResult">
        <include refid="selectWorkerLevelVo"/>
        <where>  
            <if test="title != null  and title != ''"> and title = #{title}</if>
            <if test="level != null "> and level = #{level}</if>
            <if test="ar != null "> and ar = #{ar}</if>
            <if test="totalPrice != null  and totalPrice != ''"> and total_price = #{totalPrice}</if>
            <if test="cr != null "> and cr = #{cr}</if>
            <if test="image != null  and image != ''"> and image = #{image}</if>
            <if test="bgImage != null  and bgImage != ''"> and bg_image = #{bgImage}</if>
            <if test="color != null  and color != ''"> and color = #{color}</if>
            <if test="userBgimg != null  and userBgimg != ''"> and user_bgimg = #{userBgimg}</if>
            <if test="createdAt != null "> and created_at = #{createdAt}</if>
            <if test="updatedAt != null "> and updated_at = #{updatedAt}</if>
            <if test="deletedAt != null "> and deleted_at = #{deletedAt}</if>
        </where>
    </select>
    
    <select id="selectWorkerLevelById" parameterType="Long" resultMap="WorkerLevelResult">
        <include refid="selectWorkerLevelVo"/>
        where id = #{id}
    </select>

    <insert id="insertWorkerLevel" parameterType="WorkerLevel" useGeneratedKeys="true" keyProperty="id">
        insert into worker_level
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="title != null and title != ''">title,</if>
            <if test="level != null">level,</if>
            <if test="ar != null">ar,</if>
            <if test="totalPrice != null and totalPrice != ''">total_price,</if>
            <if test="cr != null">cr,</if>
            <if test="image != null">image,</if>
            <if test="bgImage != null">bg_image,</if>
            <if test="color != null">color,</if>
            <if test="userBgimg != null">user_bgimg,</if>
            <if test="createdAt != null">created_at,</if>
            <if test="updatedAt != null">updated_at,</if>
            <if test="deletedAt != null">deleted_at,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="title != null and title != ''">#{title},</if>
            <if test="level != null">#{level},</if>
            <if test="ar != null">#{ar},</if>
            <if test="totalPrice != null and totalPrice != ''">#{totalPrice},</if>
            <if test="cr != null">#{cr},</if>
            <if test="image != null">#{image},</if>
            <if test="bgImage != null">#{bgImage},</if>
            <if test="color != null">#{color},</if>
            <if test="userBgimg != null">#{userBgimg},</if>
            <if test="createdAt != null">#{createdAt},</if>
            <if test="updatedAt != null">#{updatedAt},</if>
            <if test="deletedAt != null">#{deletedAt},</if>
         </trim>
    </insert>

    <update id="updateWorkerLevel" parameterType="WorkerLevel">
        update worker_level
        <trim prefix="SET" suffixOverrides=",">
            <if test="title != null and title != ''">title = #{title},</if>
            <if test="level != null">level = #{level},</if>
            <if test="ar != null">ar = #{ar},</if>
            <if test="totalPrice != null and totalPrice != ''">total_price = #{totalPrice},</if>
            <if test="cr != null">cr = #{cr},</if>
            <if test="image != null">image = #{image},</if>
            <if test="bgImage != null">bg_image = #{bgImage},</if>
            <if test="color != null">color = #{color},</if>
            <if test="userBgimg != null">user_bgimg = #{userBgimg},</if>
            <if test="createdAt != null">created_at = #{createdAt},</if>
            <if test="updatedAt != null">updated_at = #{updatedAt},</if>
            <if test="deletedAt != null">deleted_at = #{deletedAt},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteWorkerLevelById" parameterType="Long">
        delete from worker_level where id = #{id}
    </delete>

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