package com.hai.dao;

import com.hai.model.CmsContentModel;
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 CmsContentMapperExt {
    @Select(value = {
            "<script>",
            "SELECT",
            "cc.*",
            ", cca.name AS category_name",
            "FROM cms_content AS cc",
            ", cms_category AS cca",
            "WHERE cc.category_id = cca.id",
            "<if test=\"title != null\">",
            "    AND cc.title REGEXP #{title}",
            "</if>",
            "<if test=\"category != null\">",
            "    AND cc.category_id = #{category}",
            "</if>",
            "<if test=\"categoryCode != null\">",
            "    AND cc.category_code = #{categoryCode}",
            "</if>",
            "<if test=\"companyId != null\">",
            "    AND cc.company_id = #{companyId}",
            "</if>",
            "<if test=\"tag != null\">",
            "    AND cc.tag = #{tag}",
            "</if>",
            "<choose>",
            "    <when test=\"status == null\">",
            "        AND cc.status != 0",
            "    </when>",
            "    <when test=\"status != null\">",
            "        AND cc.status = #{status}",
            "    </when>",
            "</choose>",
            "ORDER BY  cc.category_code  and cc.sort_id",
            "</script>"
    })
    @Results({
            @Result(column="id", property="id", jdbcType= JdbcType.BIGINT, id=true),
            @Result(column="title", property="title", jdbcType= JdbcType.VARCHAR),
            @Result(column="category_id", property="categoryId", jdbcType= JdbcType.BIGINT),
            @Result(column="category_code", property="categoryCode", jdbcType= JdbcType.VARCHAR),
            @Result(column="description", property="description", jdbcType= JdbcType.VARCHAR),
            @Result(column="create_time", property="createTime", jdbcType= JdbcType.TIMESTAMP),
            @Result(column="status", property="status", jdbcType= JdbcType.INTEGER),
            @Result(column="has_patch", property="hasPatch", jdbcType= JdbcType.TINYINT),
            @Result(column="visit_count", property="visitCount", jdbcType= JdbcType.INTEGER),
            @Result(column="tag", property="tag", jdbcType= JdbcType.VARCHAR),
            @Result(column="img_source", property="imgSource", jdbcType= JdbcType.TINYINT),
            @Result(column="img_data", property="imgData", jdbcType= JdbcType.VARCHAR),
            @Result(column="jump_type", property="jumpType", jdbcType= JdbcType.INTEGER),
            @Result(column="jump_name", property="jumpName", jdbcType= JdbcType.VARCHAR),
            @Result(column="jump_url", property="jumpUrl", jdbcType= JdbcType.VARCHAR),
            @Result(column="sort_id", property="sortId", jdbcType= JdbcType.INTEGER),
            @Result(column="update_time", property="updateTime", jdbcType= JdbcType.TIMESTAMP),
            @Result(column="recommend", property="recommend", jdbcType= JdbcType.BIT),
            @Result(column="company_id", property="companyId", jdbcType= JdbcType.BIGINT),
            @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="content", property="content", jdbcType= JdbcType.LONGVARCHAR),
            @Result(column="category_name", property="categoryName", jdbcType= JdbcType.VARCHAR),
    })
    List<CmsContentModel> getListContent(Map<String, String> paramsMap) throws Exception;


    @Select(value = {
            "<script>",
            "SELECT",
            "cc.*",
            ", cca.name AS category_name",
            "FROM cms_content AS cc",
            ", cms_category AS cca",
            "WHERE cc.category_id = cca.id",
            "<if test=\"title != null\">",
            "    AND cc.title REGEXP #{title}",
            "</if>",
            "<if test=\"category != null\">",
            "    AND cc.category_id = #{category}",
            "</if>",
            "<if test=\"categoryCode != null\">",
            "    AND cc.category_code = #{categoryCode}",
            "</if>",
            "<if test=\"companyId != null\">",
            "    AND cc.company_id = #{companyId}",
            "</if>",
            "<if test=\"tag != null\">",
            "    AND cc.tag = #{tag}",
            "</if>",
            "<choose>",
            "    <when test=\"status == null\">",
            "        AND cc.status != 0",
            "    </when>",
            "    <when test=\"status != null\">",
            "        AND cc.status = #{status}",
            "    </when>",
            "</choose>",
            "ORDER BY cc.sort_id",
            "</script>"
    })
    @Results({
            @Result(column="id", property="id", jdbcType= JdbcType.BIGINT, id=true),
            @Result(column="title", property="title", jdbcType= JdbcType.VARCHAR),
            @Result(column="category_id", property="categoryId", jdbcType= JdbcType.BIGINT),
            @Result(column="category_code", property="categoryCode", jdbcType= JdbcType.VARCHAR),
            @Result(column="description", property="description", jdbcType= JdbcType.VARCHAR),
            @Result(column="create_time", property="createTime", jdbcType= JdbcType.TIMESTAMP),
            @Result(column="status", property="status", jdbcType= JdbcType.INTEGER),
            @Result(column="has_patch", property="hasPatch", jdbcType= JdbcType.TINYINT),
            @Result(column="visit_count", property="visitCount", jdbcType= JdbcType.INTEGER),
            @Result(column="tag", property="tag", jdbcType= JdbcType.VARCHAR),
            @Result(column="img_source", property="imgSource", jdbcType= JdbcType.TINYINT),
            @Result(column="img_data", property="imgData", jdbcType= JdbcType.VARCHAR),
            @Result(column="jump_type", property="jumpType", jdbcType= JdbcType.INTEGER),
            @Result(column="jump_name", property="jumpName", jdbcType= JdbcType.VARCHAR),
            @Result(column="jump_url", property="jumpUrl", jdbcType= JdbcType.VARCHAR),
            @Result(column="sort_id", property="sortId", jdbcType= JdbcType.INTEGER),
            @Result(column="update_time", property="updateTime", jdbcType= JdbcType.TIMESTAMP),
            @Result(column="recommend", property="recommend", jdbcType= JdbcType.BIT),
            @Result(column="company_id", property="companyId", jdbcType= JdbcType.BIGINT),
            @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="content", property="content", jdbcType= JdbcType.LONGVARCHAR),
            @Result(column="category_name", property="categoryName", jdbcType= JdbcType.VARCHAR),
    })
    List<CmsContentModel> getListContentByCrest(Map<String, String> paramsMap) throws Exception;
}
