<?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.colums.YjStoreMapper">
    
    <resultMap type="YjStore" id="YjStoreResult">
        <result property="banner"    column="banner"    />
        <result property="storeName"    column="store_name"    />
        <result property="address"    column="address"    />
        <result property="phone"    column="phone"    />
        <result property="founder"    column="founder"    />
        <result property="profile"    column="profile"    />
        <result property="deptId"    column="dept_id"    />
        <result property="deptName"    column="dept_name"    />
    </resultMap>

    <sql id="selectYjStoreVo">
        select
            yj_store.banner,
            yj_store.store_name,
            yj_store.address,
            yj_store.phone,
            yj_store.founder,
            yj_store.profile,
            yj_store.dept_id,
            sys_dept.dept_name
        from yj_store left join sys_dept on yj_store.dept_id = sys_dept.dept_id
    </sql>

    <select id="selectYjStoreList" parameterType="YjStore" resultMap="YjStoreResult">
        <include refid="selectYjStoreVo"/>
        <where>
            <if test="banner != null  and banner != ''"> and yj_store.banner = #{banner}</if>
            <if test="storeName != null  and storeName != ''"> and yj_store.store_name like concat('%', #{storeName}, '%')</if>
            <if test="address != null  and address != ''"> and yj_store.address = #{address}</if>
            <if test="phone != null  and phone != ''"> and yj_store.phone = #{phone}</if>
            <if test="founder != null  and founder != ''"> and yj_store.founder = #{founder}</if>
            <if test="profile != null  and profile != ''"> and yj_store.profile = #{profile}</if>
            <if test="tenantId != null "> and sys_dept.tenant_id = #{tenantId}</if>
        </where>
    </select>

    <select id="selectYjStoreByDeptId" parameterType="Long" resultMap="YjStoreResult">
        <include refid="selectYjStoreVo"/>
        where yj_store.dept_id = #{deptId}
    </select>

    <insert id="insertYjStore" parameterType="YjStore">
        insert into yj_store
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="banner != null">banner,</if>
            <if test="storeName != null and storeName != ''">store_name,</if>
            <if test="address != null">address,</if>
            <if test="phone != null">phone,</if>
            <if test="founder != null">founder,</if>
            <if test="profile != null">profile,</if>
            <if test="deptId != null">dept_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="banner != null">#{banner},</if>
            <if test="storeName != null and storeName != ''">#{storeName},</if>
            <if test="address != null">#{address},</if>
            <if test="phone != null">#{phone},</if>
            <if test="founder != null">#{founder},</if>
            <if test="profile != null">#{profile},</if>
            <if test="deptId != null">#{deptId},</if>
        </trim>
    </insert>

    <update id="updateYjStore" parameterType="YjStore">
        update yj_store
        <trim prefix="SET" suffixOverrides=",">
            <if test="banner != null">yj_store.banner = #{banner},</if>
            <if test="storeName != null and storeName != ''">yj_store.store_name = #{storeName},</if>
            <if test="address != null">yj_store.address = #{address},</if>
            <if test="phone != null">yj_store.phone = #{phone},</if>
            <if test="founder != null">yj_store.founder = #{founder},</if>
            <if test="profile != null">yj_store.profile = #{profile},</if>
        </trim>
        where yj_store.dept_id = #{deptId}
    </update>

    <delete id="deleteYjStoreByDeptId" parameterType="Long">
        delete from yj_store where yj_store.dept_id = #{deptId}
    </delete>

    <delete id="deleteYjStoreByDeptIds" parameterType="String">
        delete from yj_store where yj_store.dept_id in
        <foreach item="deptId" collection="array" open="(" separator="," close=")">
            #{deptId}
        </foreach>
    </delete>
</mapper>