<?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.post.mapper.PostPublisherMapper">

    <resultMap type="PostPublisher" id="PostPublisherResult">
        <result property="publisherId" column="publisher_id"/>
        <result property="publisherImage" column="publisher_image"/>
        <result property="publisherName" column="publisher_name"/>
        <result property="nickName" column="nick_name"/>
        <result property="publisherEmail" column="publisher_email"/>
        <result property="publisherPhonenumber" column="publisher_phonenumber"/>
        <result property="status" column="status"/>
        <result property="publisherAddress" column="publisher_address"/>
        <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"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectPostPublisherVo">
        select publisher_id,
               publisher_image,
               publisher_name,
               nick_name,
               publisher_email,
               publisher_phonenumber,
               status,
               publisher_address,
               del_flag
        from post_publisher
        where del_flag = '0'
    </sql>
    <!--查询发行方列表-->
    <select id="selectPostPublisherList" parameterType="PostPublisher" resultMap="PostPublisherResult">
        <include refid="selectPostPublisherVo"/>
        <where>
            <if test="publisherImage != null  and publisherImage != ''">and publisher_image = #{publisherImage}</if>
            <if test="publisherName != null  and publisherName != ''">and publisher_name like concat('%',
                #{publisherName}, '%')
            </if>
            <if test="nickName != null  and nickName != ''">and nick_name like concat('%', #{nickName}, '%')</if>
            <if test="publisherEmail != null  and publisherEmail != ''">and publisher_email = #{publisherEmail}</if>
            <if test="publisherPhonenumber != null  and publisherPhonenumber != ''">and publisher_phonenumber =
                #{publisherPhonenumber}
            </if>
            <if test="status != null  and status != ''">and status = #{status}</if>
            <if test="publisherAddress != null  and publisherAddress != ''">and publisher_address =
                #{publisherAddress}
            </if>
        </where>
    </select>
    <!--查询单个用户-->
    <select id="selectPostPublisherByPublisherId" parameterType="Long" resultMap="PostPublisherResult">
        <include refid="selectPostPublisherVo"/>
        and publisher_id = #{publisherId}
    </select>
    <!--添加发行方信息-->
    <insert id="insertPostPublisher" parameterType="PostPublisher" useGeneratedKeys="true" keyProperty="publisherId">
        insert into post_publisher
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="publisherImage != null">publisher_image,</if>
            <if test="publisherName != null and publisherName != ''">publisher_name,</if>
            <if test="nickName != null and nickName != ''">nick_name,</if>
            <if test="publisherEmail != null">publisher_email,</if>
            <if test="publisherPhonenumber != null">publisher_phonenumber,</if>
            <if test="status != null">status,</if>
            <if test="publisherAddress != null">publisher_address,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="publisherImage != null">#{publisherImage},</if>
            <if test="publisherName != null and publisherName != ''">#{publisherName},</if>
            <if test="nickName != null and nickName != ''">#{nickName},</if>
            <if test="publisherEmail != null">#{publisherEmail},</if>
            <if test="publisherPhonenumber != null">#{publisherPhonenumber},</if>
            <if test="status != null">#{status},</if>
            <if test="publisherAddress != null">#{publisherAddress},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>
    <!--修改发行方信息-->
    <update id="updatePostPublisher" parameterType="PostPublisher">
        update post_publisher
        <trim prefix="SET" suffixOverrides=",">
            <if test="publisherImage != null">publisher_image = #{publisherImage},</if>
            <if test="publisherName != null and publisherName != ''">publisher_name = #{publisherName},</if>
            <if test="nickName != null and nickName != ''">nick_name = #{nickName},</if>
            <if test="publisherEmail != null">publisher_email = #{publisherEmail},</if>
            <if test="publisherPhonenumber != null">publisher_phonenumber = #{publisherPhonenumber},</if>
            <if test="status != null">status = #{status},</if>
            <if test="publisherAddress != null">publisher_address = #{publisherAddress},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where publisher_id = #{publisherId}
    </update>
    <!--发行方ID删除-->
    <delete id="deletePostPublisherByPublisherId" parameterType="Long">
        --         delete
--         from post_publisher
--         where publisher_id = #{publisherId}
        update post_publisher
        set del_flag = '1'
        where user_id = #{userId}
    </delete>
    <!--批量删除-->
    <delete id="deletePostPublisherByPublisherIds" parameterType="String">
        -- delete from post_publisher where publisher_id in
        update post_publisher
        set del_flag = '1'
        where publisher_id in
        <foreach item="publisherId" collection="array" open="(" separator="," close=")">
            #{publisherId}
        </foreach>
    </delete>
    <!--    账号是否重复-->
    <select id="checkPublisherNameUnique" parameterType="String" resultMap="PostPublisherResult">
        select publisher_id, publisher_name
        from post_publisher
        where publisher_name = #{publisherName} limit 1
    </select>
    <!--    头像是否重复-->
    <select id="checkImageUnique" parameterType="String" resultMap="PostPublisherResult">
        select publisher_id, publisher_image
        from post_publisher
        where publisher_image = #{publisherImage} limit 1
    </select>
</mapper>