package cn.sh.stc.sict.theme.common.controller;

import cn.sh.stc.sict.cloud.common.core.util.R;
import cn.sh.stc.sict.theme.common.service.ThemeTableInfoService;
import cn.sh.stc.sict.theme.common.vo.ThemeTableInfoVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.stream.Collectors;


/**
 * 主题库表分类表
 *
 * @author F_xh。
 * @date 2020-07-24 13:54:35
 */
@RestController
@RequestMapping("/table/info")
@AllArgsConstructor
@Slf4j
@Api(tags = "主题库表分类控制器")
public class ThemeTableInfoController {

    private ThemeTableInfoService themeTableInfoService;


    /**
     * 分页查询
     *
     * @return
     */
    @ApiOperation("查询所有表 tree")
    @GetMapping("/{theme}/tree")
    public R getTableInfoTree(@PathVariable String theme) {
        List<ThemeTableInfoVO> list = themeTableInfoService.listInfo(theme);
        LinkedHashMap<String, List<ThemeTableInfoVO>> tree = list.stream().collect(Collectors.groupingBy(ThemeTableInfoVO::getTypeCode, LinkedHashMap::new, Collectors.toList()));
        return new R<>(tree);
    }
}
