<?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="cn.bunny.services.mapper.message.MessageTypeMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="cn.bunny.dao.entity.system.MessageType">
        <id column="id" property="id"/>
        <id column="create_time" property="createTime"/>
        <id column="update_time" property="updateTime"/>
        <id column="create_user" property="createUser"/>
        <id column="update_user" property="updateUser"/>
        <id column="is_deleted" property="isDeleted"/>
        <id column="message_name" property="messageName"/>
        <id column="message_type" property="messageType"/>
        <id column="summary" property="summary"/>
        <id column="status" property="status"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, create_time, update_time, create_user, update_user, is_deleted, message_name, message_type, summary, status
    </sql>

    <!-- 分页查询系统消息类型内容 -->
    <select id="selectListByPage" resultType="cn.bunny.dao.vo.system.message.MessageTypeVo">
        select
        message_type.*,
        create_user.username as create_username,
        update_user.username as update_username
        from sys_message_type message_type
        left join sys_user create_user on create_user.id = message_type.create_user
        left join sys_user update_user on update_user.id = message_type.update_user
        <where>
            message_type.is_deleted = 0
            <if test="dto.status != null">
                and status = #{dto.status}
            </if>
            <if test="dto.messageName != null and dto.messageName != ''">
                and message_type.message_name like CONCAT('%',#{dto.messageName},'%')
            </if>
            <if test="dto.messageType != null and dto.messageType != ''">
                and message_type.message_type like CONCAT('%',#{dto.messageType},'%')
            </if>
            <if test="dto.summary != null and dto.summary != ''">
                and message_type.summary like CONCAT('%',#{dto.summary},'%')
            </if>
        </where>
    </select>

    <!-- 物理删除系统消息类型 -->
    <delete id="deleteBatchIdsWithPhysics">
        delete
        from sys_message_type
        where id in
        <foreach collection="ids" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
    </delete>

</mapper>
