<?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.supplier.mapper.TCanteenSupplierMapper">
    
    <resultMap type="TCanteenSupplier" id="TCanteenSupplierResult">
        <result property="supplierId"    column="supplier_id"    />
        <result property="userId"    column="user_id"    />
        <result property="serviceType"    column="service_type"    />
        <result property="avgRating"    column="avg_rating"    />
        <result property="logoUrl"    column="logo_url"    />
        <result property="description"    column="description"    />
        <result property="status"    column="status"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createrCode"    column="creater_code"    />
        <result property="createdate"    column="createdate"    />
        <result property="updaterCode"    column="updater_code"    />
        <result property="updatedate"    column="updatedate"    />
        <result property="deptId"    column="dept_id"    />
        <result property="remarks"    column="remarks"    />
    </resultMap>

    <sql id="selectTCanteenSupplierVo">
        select supplier_id, user_id, service_type, avg_rating, logo_url, description, status, del_flag, creater_code, createdate, updater_code, updatedate, dept_id, remarks from t_canteen_supplier
    </sql>

    <select id="selectTCanteenSupplierList" parameterType="TCanteenSupplier" resultMap="TCanteenSupplierResult">
        <include refid="selectTCanteenSupplierVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="serviceType != null  and serviceType != ''"> and service_type = #{serviceType}</if>
            <if test="avgRating != null  and avgRating != ''"> and avg_rating = #{avgRating}</if>
            <if test="logoUrl != null  and logoUrl != ''"> and logo_url = #{logoUrl}</if>
            <if test="description != null  and description != ''"> and description = #{description}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="createrCode != null "> and creater_code = #{createrCode}</if>
            <if test="createdate != null "> and createdate = #{createdate}</if>
            <if test="updaterCode != null "> and updater_code = #{updaterCode}</if>
            <if test="updatedate != null "> and updatedate = #{updatedate}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
        </where>
    </select>
    
    <select id="selectTCanteenSupplierBySupplierId" parameterType="Long" resultMap="TCanteenSupplierResult">
        <include refid="selectTCanteenSupplierVo"/>
        where supplier_id = #{supplierId}
    </select>

    <insert id="insertTCanteenSupplier" parameterType="TCanteenSupplier" useGeneratedKeys="true" keyProperty="supplierId">
        insert into t_canteen_supplier
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="serviceType != null and serviceType != ''">service_type,</if>
            <if test="avgRating != null">avg_rating,</if>
            <if test="logoUrl != null">logo_url,</if>
            <if test="description != null">description,</if>
            <if test="status != null">status,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createrCode != null">creater_code,</if>
            <if test="createdate != null">createdate,</if>
            <if test="updaterCode != null">updater_code,</if>
            <if test="updatedate != null">updatedate,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="remarks != null">remarks,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="serviceType != null and serviceType != ''">#{serviceType},</if>
            <if test="avgRating != null">#{avgRating},</if>
            <if test="logoUrl != null">#{logoUrl},</if>
            <if test="description != null">#{description},</if>
            <if test="status != null">#{status},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createrCode != null">#{createrCode},</if>
            <if test="createdate != null">#{createdate},</if>
            <if test="updaterCode != null">#{updaterCode},</if>
            <if test="updatedate != null">#{updatedate},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="remarks != null">#{remarks},</if>
         </trim>
    </insert>

    <update id="updateTCanteenSupplier" parameterType="TCanteenSupplier">
        update t_canteen_supplier
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="serviceType != null and serviceType != ''">service_type = #{serviceType},</if>
            <if test="avgRating != null">avg_rating = #{avgRating},</if>
            <if test="logoUrl != null">logo_url = #{logoUrl},</if>
            <if test="description != null">description = #{description},</if>
            <if test="status != null">status = #{status},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createrCode != null">creater_code = #{createrCode},</if>
            <if test="createdate != null">createdate = #{createdate},</if>
            <if test="updaterCode != null">updater_code = #{updaterCode},</if>
            <if test="updatedate != null">updatedate = #{updatedate},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
        </trim>
        where supplier_id = #{supplierId}
    </update>

    <delete id="deleteTCanteenSupplierBySupplierId" parameterType="Long">
        delete from t_canteen_supplier where supplier_id = #{supplierId}
    </delete>

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