<?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.ServiceTypeMapper">
    
    <resultMap type="ServiceType" id="ServiceTypeResult">
        <result property="id"    column="id"    />
        <result property="image"    column="image"    />
        <result property="nameCn"    column="name_cn"    />
        <result property="illustrateCn"    column="illustrate_cn"    />
        <result property="nameVi"    column="name_vi"    />
        <result property="illustrateVi"    column="illustrate_vi"    />
        <result property="nameEn"    column="name_en"    />
        <result property="illustrateEn"    column="illustrate_en"    />
        <result property="nameTw"    column="name_tw"    />
        <result property="illustrateTw"    column="illustrate_tw"    />
        <result property="width"    column="width"    />
        <result property="height"    column="height"    />
    </resultMap>

    <sql id="selectServiceTypeVo">
        select id, image, name_cn, illustrate_cn, name_vi, illustrate_vi, name_en, illustrate_en, name_tw, illustrate_tw, width, height from service_type
    </sql>

    <select id="selectServiceTypeList" parameterType="ServiceType" resultMap="ServiceTypeResult">
        <include refid="selectServiceTypeVo"/>
        <where>  
            <if test="nameCn != null  and nameCn != ''"> and name_cn = #{nameCn}</if>
            <if test="nameVi != null  and nameVi != ''"> and name_vi = #{nameVi}</if>
            <if test="nameEn != null  and nameEn != ''"> and name_en = #{nameEn}</if>
            <if test="nameTw != null  and nameTw != ''"> and name_tw = #{nameTw}</if>
        </where>
    </select>
    
    <select id="selectServiceTypeById" parameterType="Long" resultMap="ServiceTypeResult">
        <include refid="selectServiceTypeVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertServiceType" parameterType="ServiceType" useGeneratedKeys="true" keyProperty="id">
        insert into service_type
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="image != null">image,</if>
            <if test="nameCn != null">name_cn,</if>
            <if test="illustrateCn != null">illustrate_cn,</if>
            <if test="nameVi != null">name_vi,</if>
            <if test="illustrateVi != null">illustrate_vi,</if>
            <if test="nameEn != null">name_en,</if>
            <if test="illustrateEn != null">illustrate_en,</if>
            <if test="nameTw != null">name_tw,</if>
            <if test="illustrateTw != null">illustrate_tw,</if>
            <if test="width != null">width,</if>
            <if test="height != null">height,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="image != null">#{image},</if>
            <if test="nameCn != null">#{nameCn},</if>
            <if test="illustrateCn != null">#{illustrateCn},</if>
            <if test="nameVi != null">#{nameVi},</if>
            <if test="illustrateVi != null">#{illustrateVi},</if>
            <if test="nameEn != null">#{nameEn},</if>
            <if test="illustrateEn != null">#{illustrateEn},</if>
            <if test="nameTw != null">#{nameTw},</if>
            <if test="illustrateTw != null">#{illustrateTw},</if>
            <if test="width != null">#{width},</if>
            <if test="height != null">#{height},</if>
         </trim>
    </insert>

    <update id="updateServiceType" parameterType="ServiceType">
        update service_type
        <trim prefix="SET" suffixOverrides=",">
            <if test="image != null">image = #{image},</if>
            <if test="nameCn != null">name_cn = #{nameCn},</if>
            <if test="illustrateCn != null">illustrate_cn = #{illustrateCn},</if>
            <if test="nameVi != null">name_vi = #{nameVi},</if>
            <if test="illustrateVi != null">illustrate_vi = #{illustrateVi},</if>
            <if test="nameEn != null">name_en = #{nameEn},</if>
            <if test="illustrateEn != null">illustrate_en = #{illustrateEn},</if>
            <if test="nameTw != null">name_tw = #{nameTw},</if>
            <if test="illustrateTw != null">illustrate_tw = #{illustrateTw},</if>
            <if test="width != null">width = #{width},</if>
            <if test="height != null">height = #{height},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteServiceTypeById" parameterType="Long">
        delete from service_type where id = #{id}
    </delete>

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