<?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.vctgo.system.mapper.SysConfigPermissionMapper">

    <resultMap type="com.vctgo.system.domain.SysConfigPermission" id="SysConfigPermissionResult">
        <result property="id"    column="id"    />
        <result property="serviceName"    column="service_name"    />
        <result property="menuIds"    column="menu_ids"    />
        <result property="isDeleted"    column="is_deleted"    />
        <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"    />
        <result property="createById" column="create_by_id"/>
        <result property="updateById" column="update_by_id"/>
        <result property="tenantId"     column="tenant_id"      />
        <result property="tenantType"     column="tenant_type"      />
    </resultMap>

    <sql id="selectSysConfigPermissionVo">
        select id, service_name, menu_ids, is_deleted, create_by, create_time, update_by, update_time, remark,create_by_id, update_by_id,tenant_id,tenant_type from sys_config_permission
    </sql>

    <sql id="defaultDeleteCondition">
        is_deleted = 0
    </sql>

    <select id="selectSysConfigPermissionList"   resultMap="SysConfigPermissionResult">
        SELECT
            cp.id,
            cp.service_name,
            cp.menu_ids,
            cp.is_deleted,
            cp.create_by,
            cp.create_time,
            cp.update_by,
            cp.update_time,
            cp.remark,
            cp.create_by_id,
            cp.update_by_id,
            cp.tenant_id,
            cp.tenant_type,
            pu.nick_name createNickName
        FROM
        sys_config_permission cp
            LEFT JOIN sys_platform_user pu ON cp.create_by = pu.user_name
        <where>
            <include refid="defaultDeleteCondition"/>
            <if test="query.serviceName != null  and query.serviceName != ''"> and cp.service_name like concat('%', #{query.serviceName}, '%')</if>
            <if test="query.menuIds != null  and query.menuIds != ''"> and cp.menu_ids = #{query.menuIds}</if>
            <if test="query.isDeleted != null  and query.isDeleted != ''"> and cp.is_deleted = #{query.isDeleted}</if>
        </where>
    </select>

    <update id="logicalDeleteSysConfigPermissionByIds" parameterType="String">
        update sys_config_permission set is_deleted = #{query.isDeleted},
        update_by_id = #{query.updateById}, update_by = #{query.updateBy},
        update_time = #{query.updateTime} where id in
        <foreach item="id" collection="ids" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

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