<?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.framework.recovery.mapper.RecStallMapper">

    <resultMap type="RecStall" id="RecStallResult">
        <result property="id"    column="id"    />
        <result property="categoryId"    column="category_id"    />
        <result property="tradeType"    column="trade_type"    />
        <result property="stallName"    column="stall_name"    />
        <result property="stallDesc"    column="stall_desc"    />
        <result property="stallAddress"    column="stall_address"    />
        <result property="stallCont"    column="stall_cont"    />
        <result property="stallContWx"    column="stall_cont_wx"    />
        <result property="stallContAddress"    column="stall_cont_address"    />
        <result property="stallIcon"    column="stall_icon"    />
        <result property="createBy"    column="create_by"    />
        <result property="createDate"    column="create_date"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateDate"    column="update_date"    />
        <result property="cityId"  column="city_id" />
    </resultMap>

    <sql id="selectRecStallVo">
        select id, category_id, trade_type, stall_name, stall_desc, stall_address, stall_cont, stall_cont_wx, stall_cont_address, stall_icon, create_by, create_date, update_by, update_date, city_id from rec_stall
    </sql>

    <select id="selectRecStallList" parameterType="RecStall" resultMap="RecStallResult">
        <include refid="selectRecStallVo"/>
        <where>
            <if test="categoryId != null "> and category_id = #{categoryId}</if>
            <if test="tradeType != null "> and trade_type = #{tradeType}</if>
            <if test="stallName != null  and stallName != ''"> and stall_name like concat('%', #{stallName}, '%')</if>
            <if test="stallDesc != null  and stallDesc != ''"> and stall_desc = #{stallDesc}</if>
            <if test="stallAddress != null  and stallAddress != ''"> and stall_address = #{stallAddress}</if>
            <if test="stallCont != null  and stallCont != ''"> and stall_cont = #{stallCont}</if>
            <if test="stallContWx != null  and stallContWx != ''"> and stall_cont_wx = #{stallContWx}</if>
            <if test="stallContAddress != null  and stallContAddress != ''"> and stall_cont_address = #{stallContAddress}</if>
            <if test="stallIcon != null  and stallIcon != ''"> and stall_icon = #{stallIcon}</if>
            <if test="createDate != null "> and create_date = #{createDate}</if>
            <if test="updateDate != null "> and update_date = #{updateDate}</if>
            <if test="cityId != null "> and city_id = #{cityId}</if>
        </where>
    </select>

    <select id="selectRecStallById" parameterType="Long" resultMap="RecStallResult">
        <include refid="selectRecStallVo"/>
        where id = #{id}
    </select>

    <insert id="insertRecStall" parameterType="RecStall">
        insert into rec_stall
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="categoryId != null">category_id,</if>
            <if test="tradeType != null">trade_type,</if>
            <if test="stallName != null">stall_name,</if>
            <if test="stallDesc != null">stall_desc,</if>
            <if test="stallAddress != null">stall_address,</if>
            <if test="stallCont != null">stall_cont,</if>
            <if test="stallContWx != null">stall_cont_wx,</if>
            <if test="stallContAddress != null">stall_cont_address,</if>
            <if test="stallIcon != null">stall_icon,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createDate != null">create_date,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateDate != null">update_date,</if>
            <if test="cityId != null">city_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="categoryId != null">#{categoryId},</if>
            <if test="tradeType != null">#{tradeType},</if>
            <if test="stallName != null">#{stallName},</if>
            <if test="stallDesc != null">#{stallDesc},</if>
            <if test="stallAddress != null">#{stallAddress},</if>
            <if test="stallCont != null">#{stallCont},</if>
            <if test="stallContWx != null">#{stallContWx},</if>
            <if test="stallContAddress != null">#{stallContAddress},</if>
            <if test="stallIcon != null">#{stallIcon},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createDate != null">#{createDate},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateDate != null">#{updateDate},</if>
            <if test="cityId != null">#{cityId},</if>
         </trim>
    </insert>

    <update id="updateRecStall" parameterType="RecStall">
        update rec_stall
        <trim prefix="SET" suffixOverrides=",">
            <if test="categoryId != null">category_id = #{categoryId},</if>
            <if test="tradeType != null">trade_type = #{tradeType},</if>
            <if test="stallName != null">stall_name = #{stallName},</if>
            <if test="stallDesc != null">stall_desc = #{stallDesc},</if>
            <if test="stallAddress != null">stall_address = #{stallAddress},</if>
            <if test="stallCont != null">stall_cont = #{stallCont},</if>
            <if test="stallContWx != null">stall_cont_wx = #{stallContWx},</if>
            <if test="stallContAddress != null">stall_cont_address = #{stallContAddress},</if>
            <if test="stallIcon != null">stall_icon = #{stallIcon},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createDate != null">create_date = #{createDate},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateDate != null">update_date = #{updateDate},</if>
            <if test="cityId != null">city_id = #{cityId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteRecStallById" parameterType="Long">
        delete from rec_stall where id = #{id}
    </delete>

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

    <select id="selectAllGoods" resultType="com.ruoyi.framework.recovery.domain.vo.GoodsVo">
        SELECT rb.brand as brand, rc.id as id, rc.model as model,rc.specs as specs
        FROM rec_commodity rc left join rec_brand rb on rb.id = rc.brand_id
    </select>
    <select id="selectMinCityId" resultType="java.util.Map">
        SELECT trade_type as tradeType, min(city_id) as cityId from rec_stall where city_id is not null GROUP BY trade_type
    </select>
    <select id="selectRecStallListByCategoryId" resultType="com.ruoyi.framework.recovery.domain.RecStall">
        select rs.id, rs.category_id as categoryId, rs.trade_type as tradeType, rs.stall_name as stallName, rs.stall_desc as stallDesc,
               rs.stall_address as stallAddress, rs.stall_cont as stallCont, rs.stall_cont_wx as stallContWx,
               rs.stall_cont_address as stallContAddress, rs.stall_icon as stallIcon, rs.create_by as createBy, rs.create_date as createDate,
               rs.update_by as updateBy, rs.update_date as updateDate, rs.city_id as cityId, rc.city as city
        from rec_stall rs
        left join rec_city rc on rc.id = rs.city_id
        <where>
            <if test="categoryId != null "> and category_id = #{categoryId}</if>
            <if test="tradeType != null "> and trade_type = #{tradeType}</if>
            <if test="stallName != null  and stallName != ''"> and stall_name like concat('%', #{stallName}, '%')</if>
            <if test="stallDesc != null  and stallDesc != ''"> and stall_desc = #{stallDesc}</if>
            <if test="stallAddress != null  and stallAddress != ''"> and stall_address = #{stallAddress}</if>
            <if test="stallCont != null  and stallCont != ''"> and stall_cont = #{stallCont}</if>
            <if test="stallContWx != null  and stallContWx != ''"> and stall_cont_wx = #{stallContWx}</if>
            <if test="stallContAddress != null  and stallContAddress != ''"> and stall_cont_address = #{stallContAddress}</if>
            <if test="stallIcon != null  and stallIcon != ''"> and stall_icon = #{stallIcon}</if>
            <if test="createDate != null "> and create_date = #{createDate}</if>
            <if test="updateDate != null "> and update_date = #{updateDate}</if>
            <if test="cityId != null "> and city_id = #{cityId}</if>
        </where>
    </select>
</mapper>
