package com.hai.dao;

import com.hai.model.CmsCategoryModuleModel;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.type.JdbcType;

import java.util.List;
import java.util.Map;

/**
 * mapper扩展类
 */
public interface CmsCategoryModuleMapperExt {
    @Select({
            "<script>",
            "SELECT",
            "ccm.*",
            ", cc.name AS category_name",
            "FROM cms_category_module AS ccm",
            ", cms_category AS cc",
            "WHERE ccm.category_id = cc.id",
            "<if test=\"categoryId != null\">",
            "    AND ccm.category_id = #{categoryId}",
            "</if>",
            "<if test=\"categoryCode != null\">",
            "    AND ccm.code = #{categoryCode}",
            "</if>",
            "<if test=\"moduleName != null\">",
            "    AND ccm.module_name REGEXP #{moduleName}",
            "</if>",
            "<choose>",
            "    <when test=\"status == null\">",
            "        AND ccm.status != 0",
            "    </when>",
            "    <when test=\"status != null\">",
            "        AND ccm.status = #{status}",
            "    </when>",
            "</choose>",
            "ORDER BY ccm.create_time DESC",
            "</script>",
    })
    @Results(id = "ModelResultMap", value = {
            @Result(column="id", property="id", jdbcType= JdbcType.BIGINT, id=true),
            @Result(column="category_id", property="categoryId", jdbcType= JdbcType.BIGINT),
            @Result(column="code", property="code", jdbcType= JdbcType.VARCHAR),
            @Result(column="module_name", property="moduleName", jdbcType= JdbcType.VARCHAR),
            @Result(column="module_desc", property="moduleDesc", jdbcType= JdbcType.VARCHAR),
            @Result(column="module_path", property="modulePath", jdbcType= JdbcType.VARCHAR),
            @Result(column="status", property="status", jdbcType= JdbcType.INTEGER),
            @Result(column="create_time", property="createTime", jdbcType= JdbcType.TIMESTAMP),
            @Result(column="op_id", property="opId", jdbcType= JdbcType.BIGINT),
            @Result(column="ext_1", property="ext1", jdbcType= JdbcType.VARCHAR),
            @Result(column="ext_2", property="ext2", jdbcType= JdbcType.VARCHAR),
            @Result(column="ext_3", property="ext3", jdbcType= JdbcType.VARCHAR),
            @Result(column="category_name", property="categoryName", jdbcType= JdbcType.VARCHAR)
    })
    List<CmsCategoryModuleModel> getListCategoryModule(Map<String, Object> paramsMap) throws Exception;
}
