<?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.frequency.platformrules.mapper.PlatformRulesMapper">

    <resultMap type="com.ruoyi.frequency.platformrules.entity.PlatformRules" id="PlatformRulesResult">
        <result property="id"    column="id"    />
        <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="title"    column="title"    />
        <result property="content"    column="content"    />
        <result property="userType"    column="user_type"    />
        <result property="sort"    column="sort"    />
        <result property="platformRulesTypeName"    column="platform_rules_type_name"    />
        <result property="platformRulesTypeId"    column="platform_rules_type_id"    />
        </resultMap>



    <sql id="selectPlatformRulesVo">
        select
            t.id ,
            t.del_flag ,
            t.create_by ,
            t.create_time ,
            t.update_by ,
            t.update_time ,
            t.title ,
            t.content ,
            t.user_type ,
            t.sort,
            tl.name as platform_rules_type_name,
            t.platform_rules_type_id
        from t_platform_rules AS t
                 left join t_platform_rules_type tl on t.platform_rules_type_id = tl.id
    </sql>

    <select id="selectPlatformRulesList" parameterType="com.ruoyi.frequency.platformrules.entity.PlatformRules" resultMap="PlatformRulesResult">
        <include refid="selectPlatformRulesVo"/>
        <where> AND t.del_flag != 2
            <if test="title != null  and title != ''"> and t.title like concat('%',#{title},'%')</if>
            <if test="content != null  and content != ''"> and t.content = #{content}</if>
            <if test="userType != null "> and t.user_type = #{userType}</if>
            <if test="sort != null "> and t.sort = #{sort}</if>
            <if test="delFlag != null and delFlag != ''"> and t.del_flag = #{delFlag}</if>
            <if test="platformRulesTypeId != null "> and t.platform_rules_type_id = #{platformRulesTypeId}</if>
            <if test="beginTime != null ">
                and  t.create_time >= #{beginTime}

            </if>
            <if test="endTime != null ">
                and  t.create_time &lt; #{endTime}
            </if>
        </where>
        order by t.sort
    </select>

    <select id="selectPlatformRulesById" parameterType="Long" resultMap="PlatformRulesResult">
        <include refid="selectPlatformRulesVo"/>
        where t.id = #{id}
    </select>

    <insert id="insertPlatformRules" parameterType="com.ruoyi.frequency.platformrules.entity.PlatformRules">
        insert into t_platform_rules
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</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="title != null">title,</if>
            <if test="content != null">content,</if>
            <if test="userType != null">user_type,</if>
            <if test="sort != null">sort,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</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="title != null">#{title},</if>
            <if test="content != null">#{content},</if>
            <if test="userType != null">#{userType},</if>
            <if test="sort != null">#{sort},</if>
        </trim>
    </insert>

    <update id="updatePlatformRules" parameterType="com.ruoyi.frequency.platformrules.entity.PlatformRules">
        update t_platform_rules
        <trim prefix="SET" suffixOverrides=",">
            <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="title != null">title = #{title},</if>
            <if test="content != null">content = #{content},</if>
            <if test="userType != null">user_type = #{userType},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="platformRulesTypeId != null">platform_rules_type_id = #{platformRulesTypeId},</if>
        </trim>
        where id = #{id}
    </update>
                                                                                                                        </mapper>
