<?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.platform.dao.BrandDao">

    <select id="queryObject" resultType="com.platform.entity.BrandEntity">
		select *  from nideshop_brand
		where id = #{id}
	</select>

    <select id="findByName" resultType="com.platform.entity.BrandEntity">
        select * from nideshop_brand
        where name = #{brandName}
    </select>

    <select id="queryIdByScene" resultType="java.lang.Integer">
        select `id` from nideshop_brand where scene_num = #{sceneNum}
    </select>

    <select id="queryByScene" resultType="com.platform.entity.BrandEntity">
        select * from nideshop_brand where scene_num = #{sceneNum} limit 1
    </select>

    <select id="queryAllLiveSceneNum" resultType="string">
        select scene_num from nideshop_brand
    </select>

    <select id="getBrandListWithPage" resultType="com.platform.entity.BrandEntity">
        select * from nideshop_brand ${ew.customSqlSegment}
    </select>

    <select id="getBrandBindListWithPage" resultType="com.platform.entity.BrandEntity">
        select brand.*,sysUser.username as bind_shower_name,userBrand.user_id as bind_shower_id
         from nideshop_brand brand
         left join sys_user_brand userBrand on ( userBrand.brand_id = brand.id and userBrand.enable = 1)
         left join sys_user sysUser on (userBrand.user_id = sysUser.user_id)
         ${ew.customSqlSegment}
    </select>

    <select id="queryList" resultType="com.platform.entity.BrandEntity">
        select * from nideshop_brand
        WHERE 1=1
        <if test="name != null and name.trim() != ''">
            AND name LIKE concat('%',#{name},'%')
        </if>
        <if test="type != null and type.trim() != ''">
            AND type LIKE concat('%',#{type},'%')
        </if>
        <if test="idList != null and idList.size() > 0">
            AND id in
            <foreach item="id" collection="idList" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="deptIdList != null and deptIdList.size() > 0">
            AND create_user_dept_id in
            <foreach item="id" collection="deptIdList" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="isLiveRoom != null">
            AND is_live_room = #{isLiveRoom}
        </if>
        <choose>
            <when test="sidx != null and sidx.trim() != ''">
                order by ${sidx} ${order}
            </when>
            <otherwise>
                order by sort_order asc,id desc
            </otherwise>
        </choose>
        <if test="offset != null and limit != null">
            limit #{offset}, #{limit}
        </if>
    </select>

    <select id="queryTotal" resultType="int">
        select count(*) from nideshop_brand
        WHERE 1=1
        <if test="name != null and name.trim() != ''">
            AND name LIKE concat('%',#{name},'%')
        </if>
        <if test="idList != null and idList.size() > 0">
            AND id in
            <foreach item="id" collection="idList" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
        <if test="deptIdList != null and deptIdList.size() > 0">
            AND create_user_dept_id in
            <foreach item="id" collection="deptIdList" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
    </select>

    <insert id="save" parameterType="com.platform.entity.BrandEntity" useGeneratedKeys="true" keyProperty="id">
		insert into nideshop_brand(
			`name`,
			`simple_desc`,
			`sort_order`,
			`app_list_pic_url`,
			`type`,
			`scene_num`,
			`share_wx_qr_code`,
			`address`,
			`pic_list`,
			`longitude`,
			`latitude`,
			`introduce_video`,
			`introduce_video_cover`,
			`create_user_dept_id`,
			`create_user_id`,
			`contract_phone`,
			`update_user_id`,
            `live_room_url`,
            `livestream_status`
			)
		values(
			#{name},
			#{simpleDesc},
			#{sortOrder},
			#{appListPicUrl},
			#{type},
			#{sceneNum},
			#{shareWxQrCode},
			#{address},
			#{picList},
			#{longitude},
			#{latitude},
			#{introduceVideo},
			#{introduceVideoCover},
			#{createUserDeptId},
			#{createUserId},
			#{contractPhone},
			#{updateUserId},
			#{liveRoomUrl},
            #{livestreamStatus}
			)
	</insert>

    <update id="update" parameterType="com.platform.entity.BrandEntity">
        update nideshop_brand
        <set>
            <if test="name != null">`name` = #{name},</if>
            <if test="simpleDesc != null">`simple_desc` = #{simpleDesc},</if>
            <if test="sortOrder != null">`sort_order` = #{sortOrder},</if>
            <if test="appListPicUrl != null">`app_list_pic_url` = #{appListPicUrl},</if>
            <if test="type != null">`type` = #{type},</if>
            <if test="sceneNum != null">`scene_num` = #{sceneNum},</if>
            <if test="shareWxQrCode != null">`share_wx_qr_code` = #{shareWxQrCode},</if>
            <if test="address != null">`address` = #{address},</if>
            <if test="picList != null">`pic_list` = #{picList},</if>
            <if test="longitude != null">`longitude` = #{longitude},</if>
            <if test="latitude != null">`latitude` = #{latitude},</if>
            <if test="introduceVideo != null">`introduce_video` = #{introduceVideo},</if>
            <if test="introduceVideoCover != null">`introduce_video_cover` = #{introduceVideoCover},</if>
            <if test="createUserId != null">`create_user_id` = #{createUserId},</if>
            <if test="contractPhone != null">`contract_phone` = #{contractPhone},</if>
            <if test="updateUserId != null">`update_user_id` = #{updateUserId},</if>
            <if test="livestreamStatus != null">`livestream_status` = #{livestreamStatus},</if>
            <if test="liveRoomUrl != null">`live_room_url` = #{liveRoomUrl}</if>
        </set>
        where id = #{id}
    </update>

    <delete id="delete">
		delete from nideshop_brand where id = #{value}
	</delete>

    <delete id="deleteBatch">
        delete from nideshop_brand where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>