<?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.web.modules.trading.mapper.BizMarketStallMapper">

    <resultMap type="com.ruoyi.web.modules.trading.domain.BizMarketStall" id="BizMarketStallResult">
        <id     property="id"          column="id"/>
        <result property="stallCode"   column="stall_code"/>
        <result property="remark"      column="remark"/>
        <result property="delFlag"     column="del_flag"/>
        <result property="createBy"    column="create_by"/>
        <result property="createTime"  column="create_time"/>
        <result property="updateBy"    column="update_by"/>
        <result property="updateTime"  column="update_time"/>
    </resultMap>

    <sql id="selectVo">
        select id, stall_code, remark, del_flag, create_by, create_time, update_by, update_time
        from biz_market_stall
    </sql>

    <select id="selectBizMarketStallById" parameterType="long" resultMap="BizMarketStallResult">
        <include refid="selectVo"/>
        where id = #{id} and del_flag = '0'
    </select>

    <select id="selectBizMarketStallByIdAny" parameterType="long" resultMap="BizMarketStallResult">
        <include refid="selectVo"/>
        where id = #{id}
    </select>

    <select id="selectMaxStallCodeForUpdate" resultType="string">
        select max(stall_code) from biz_market_stall for update
    </select>

    <select id="selectBizMarketStallList" parameterType="com.ruoyi.web.modules.trading.domain.BizMarketStall" resultMap="BizMarketStallResult">
        <include refid="selectVo"/>
        <where>
            del_flag = '0'
            <if test="stallCode != null and stallCode != ''">
                and stall_code like concat('%', #{stallCode}, '%')
            </if>
        </where>
        order by stall_code asc, id asc
    </select>

    <insert id="insertBizMarketStall" parameterType="com.ruoyi.web.modules.trading.domain.BizMarketStall" useGeneratedKeys="true" keyProperty="id">
        insert into biz_market_stall (
            stall_code, remark, del_flag, create_by, create_time
        ) values (
            #{stallCode}, #{remark}, #{delFlag}, #{createBy}, sysdate()
        )
    </insert>

    <update id="updateBizMarketStall" parameterType="com.ruoyi.web.modules.trading.domain.BizMarketStall">
        update biz_market_stall set
            remark = #{remark},
            update_by = #{updateBy},
            update_time = sysdate()
        where id = #{id} and del_flag = '0'
    </update>

    <update id="logicDeleteBizMarketStallByIds">
        update biz_market_stall set del_flag = '2', update_by = #{updateBy}, update_time = sysdate()
        where del_flag = '0' and id in
        <foreach collection="ids" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
</mapper>
