<?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.ShareInfoMapper">
    
    <resultMap type="ShareInfo" id="ShareInfoResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="shareDecs"    column="share_decs"    />
        <result property="musicId"    column="music_id"    />
        <result property="shareAddr"    column="share_addr"    />
        <result property="sharePlat"    column="share_plat"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isDel"    column="is_del"    />
        <result property="review"    column="review"    />
    </resultMap>

    <sql id="selectShareInfoVo">
        select id, user_id, share_decs, music_id, share_addr, share_plat, create_time, update_time, is_del, review from share_info
    </sql>

    <select id="selectShareInfoList" parameterType="ShareInfo" resultMap="ShareInfoResult">
        <include refid="selectShareInfoVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="shareDecs != null  and shareDecs != ''"> and share_decs = #{shareDecs}</if>
            <if test="musicId != null "> and music_id = #{musicId}</if>
            <if test="shareAddr != null  and shareAddr != ''"> and share_addr = #{shareAddr}</if>
            <if test="sharePlat != null  and sharePlat != ''"> and share_plat = #{sharePlat}</if>
            <if test="isDel != null "> and is_del = #{isDel}</if>
            <if test="review != null "> and review = #{review}</if>
        </where>
    </select>
    
    <select id="selectShareInfoById" parameterType="String" resultMap="ShareInfoResult">
        <include refid="selectShareInfoVo"/>
        where id = #{id}
    </select>

    <insert id="insertShareInfo" parameterType="ShareInfo" useGeneratedKeys="true" keyProperty="id">
        insert into share_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="shareDecs != null">share_decs,</if>
            <if test="musicId != null">music_id,</if>
            <if test="shareAddr != null">share_addr,</if>
            <if test="sharePlat != null">share_plat,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="isDel != null">is_del,</if>
            <if test="review != null">review,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="shareDecs != null">#{shareDecs},</if>
            <if test="musicId != null">#{musicId},</if>
            <if test="shareAddr != null">#{shareAddr},</if>
            <if test="sharePlat != null">#{sharePlat},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="review != null">#{review},</if>
         </trim>
    </insert>

    <update id="updateShareInfo" parameterType="ShareInfo">
        update share_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="shareDecs != null">share_decs = #{shareDecs},</if>
            <if test="musicId != null">music_id = #{musicId},</if>
            <if test="shareAddr != null">share_addr = #{shareAddr},</if>
            <if test="sharePlat != null">share_plat = #{sharePlat},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="review != null">review = #{review},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteShareInfoById" parameterType="String">
        delete from share_info where id = #{id}
    </delete>

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

    <select id="selectShareInfoListPage" resultType="com.ruoyi.common.core.domain.entity.ShareInfo">
        SELECT
            su.username as username,
            su.nickname as nickname,
            su.head_img as headImg,
            si.share_decs as shareDecs,
            mi.name as `musicName`,
            mi.img_addr as musicImgAddr,
            mi.music_addr as musicAddr,
            mi.music_id as musicId,
            mi.author as  musicAuthor,
            mi.music_type as musicType
        FROM  share_info si
                  left join shop_user su on si.user_id = su.user_id
                  LEFT JOIN music_info mi on si.music_id = mi.music_id
        WHERE mi.is_del=0
    </select>
</mapper>