package com.ruoyi.web.work.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.web.work.domain.Column;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

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

/**
 * @author lishuwen
 * @date 2022-10-30
 */
public interface ColumnMapper extends BaseMapper<Column> {
    List<Column> selectList(Column column);

    @Select("SELECT id, title, parent_id AS parentId FROM tb_column WHERE type = #{type} AND state = 0 ORDER BY order_num ASC")
    List<Map<String, Object>> treeJson(Column column);

    @Select(" SELECT a.title FROM tb_column c LEFT JOIN tb_column a ON a.parent_id=c.id WHERE c.parent_id IS NULL AND c.title=#{title} ORDER BY a.order_num ASC")
    List<Column> getList(@Param("title") String title);


    @MapKey("id")
    List<Map<String, Object>> selectByTitle(Column column);


    @Select("SELECT * FROM tb_column WHERE type='region' AND level=#{level}  AND title=#{title} LIMIT 1")
    Column selectRegion(Column column);

    @Select("SELECT * FROM tb_region")
    List<Map<String, Object>>region();

    @Select("SELECT id,title,pin,pinyin,level,parent_id AS parentId FROM tb_column WHERE type='region' AND state=0 ORDER BY order_num ASC")
    List<Map<String, Object>> selectCityAll();
}
