<?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.SysTenantPackageMapper">

    <resultMap type="SysTenantPackage" id="SysTenantPackageResult">
        <result property="tenantPackageId" column="tenant_package_id"/>
        <result property="name" column="name"/>
        <result property="status" column="status"/>
        <result property="remark" column="remark"/>
        <result property="menuIds" column="menu_ids"/>
        <result property="menuCheckStrictly" column="menu_check_strictly"/>
        <result property="creator" column="creator"/>
        <result property="createTime" column="create_time"/>
        <result property="updater" column="updater"/>
        <result property="updateTime" column="update_time"/>
        <result property="delFlag" column="del_flag"/>
    </resultMap>

    <sql id="selectSysTenantPackageVo">
        select tenant_package_id,
               name,
               status,
               remark,
               menu_ids,
               menu_check_strictly,
               creator,
               create_time,
               updater,
               update_time,
               del_flag
        from sys_tenant_package
    </sql>

    <select id="selectSysTenantPackageList" parameterType="SysTenantPackage" resultMap="SysTenantPackageResult">
        <include refid="selectSysTenantPackageVo"/>
        <where>
            <if test="name != null  and name != ''">and name like concat('%', #{name}, '%')</if>
            <if test="status != null  and status != ''">and status = #{status}</if>
            <if test="menuIds != null  and menuIds != ''">and menu_ids = #{menuIds}</if>
            <if test="creator != null  and creator != ''">and creator = #{creator}</if>
            <if test="updater != null  and updater != ''">and updater = #{updater}</if>
            and del_flag = '0'
        </where>
    </select>

    <select id="selectSysTenantPackageByTenantPackageId" parameterType="Long" resultMap="SysTenantPackageResult">
        <include refid="selectSysTenantPackageVo"/>
        where tenant_package_id = #{tenantPackageId}
    </select>
    <select id="selectSysTenantPackageByName" resultMap="SysTenantPackageResult">
        <include refid="selectSysTenantPackageVo"/>
        where `name` = #{name}
    </select>

    <select id="selectSysTenantPackageListVo" resultMap="SysTenantPackageResult">
        select tenant_package_id,
               name
        from sys_tenant_package where del_flag = '0'
    </select>

    <insert id="insertSysTenantPackage" parameterType="SysTenantPackage" useGeneratedKeys="true"
            keyProperty="tenantPackageId">
        insert into sys_tenant_package
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">name,</if>
            <if test="status != null and status != ''">status,</if>
            <if test="remark != null">remark,</if>
            <if test="menuIds != null">menu_ids,</if>
            <if test="menuCheckStrictly != null">menu_check_strictly,</if>
            <if test="creator != null and creator != ''">creator,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updater != null">updater,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="delFlag != null and delFlag != ''">del_flag,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">#{name},</if>
            <if test="status != null and status != ''">#{status},</if>
            <if test="remark != null">#{remark},</if>
            <if test="menuIds != null">#{menuIds},</if>
            <if test="menuCheckStrictly != null">#{menuCheckStrictly},</if>
            <if test="creator != null and creator != ''">#{creator},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updater != null">#{updater},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="delFlag != null and delFlag != ''">#{delFlag},</if>
        </trim>
    </insert>

    <update id="updateSysTenantPackage" parameterType="SysTenantPackage">
        update sys_tenant_package
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="status != null and status != ''">status = #{status},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="menuIds != null">menu_ids = #{menuIds},</if>
            <if test="menuCheckStrictly != null">menu_check_strictly = #{menuCheckStrictly},</if>
            <if test="creator != null and creator != ''">creator = #{creator},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updater != null">updater = #{updater},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="delFlag != null and delFlag != ''">del_flag = #{delFlag},</if>
        </trim>
        where tenant_package_id = #{tenantPackageId}
    </update>

    <delete id="deleteSysTenantPackageByTenantPackageId" parameterType="Long">
        update
            sys_tenant_package
        set del_flag = '1'
        where tenant_package_id = #{tenantPackageId}
    </delete>

    <delete id="deleteSysTenantPackageByTenantPackageIds" parameterType="String">
        update
        sys_tenant_package
        set del_flag = '1'
        where
        tenant_package_id in
        <foreach item="tenantPackageId" collection="array" open="(" separator="," close=")">
            #{tenantPackageId}
        </foreach>
    </delete>
</mapper>
