package com.hai.dao;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * mapper扩展类
 */
public interface CmsCategoryRoleMapperExt {
    @Insert(value = {
            "<script>",
            "INSERT",
            "INTO cms_category_role(category_id, role_type)",
            "VALUES",
            "<foreach collection=\"roleList\" item=\"item\" index=\"idx\" open=\"(\" separator=\"),(\" close=\")\">",
            "    #{categoryId, jdbcType=BIGINT}, #{item, jdbcType=INTEGER}",
            "</foreach>",
            "</script>"
    })
    int addCategoryRoles(@Param(value = "categoryId") Long categoryId,
                         @Param(value = "roleList") List<Integer> roleList) throws Exception;

    @Delete(value = {
            "<script>",
            "DELETE ccr",
            "FROM cms_category_role AS ccr",
            "WHERE ccr.category_id IN",
            "<foreach collection=\"categoryIds\" item=\"item\" index=\"idx\" open=\"(\" separator=\",\" close=\")\">",
            "    #{item, jdbcType=BIGINT}",
            "</foreach>",
            "AND ccr.role_type NOT IN",
            "<foreach collection=\"roleList\" item=\"item\" index=\"idx\" open=\"(\" separator=\",\" close=\")\">",
            "    #{item, jdbcType=INTEGER}",
            "</foreach>",
            "</script>"
    })
    int delSurplusRolesOfCategories(@Param(value = "categoryIds") List<Long> categoryIds,
                                    @Param(value = "roleList") List<Integer> roleList) throws Exception;
}
