package io.gisbi.visualization.server;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.gisbi.api.visualization.VisualizationBackgroundApi;
import io.gisbi.api.visualization.vo.VisualizationBackgroundVO;
import io.gisbi.i18n.Translator;
import io.gisbi.utils.BeanUtils;
import io.gisbi.visualization.dao.auto.entity.VisualizationBackground;
import io.gisbi.visualization.dao.auto.mapper.VisualizationBackgroundMapper;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * @Author bi-coder
 * @date : 2023/6/12 19:31
 */
@RestController
@RequestMapping("/visualizationBackground")
public class VisualizationBackgroundService implements VisualizationBackgroundApi {
    @Resource
    VisualizationBackgroundMapper mapper;

    @Override
    public Map<String, List<VisualizationBackgroundVO>> findAll() {
        List<VisualizationBackground> result = mapper.selectList(new QueryWrapper<>());
        return result.stream().map(vb ->{
            VisualizationBackgroundVO vbVO = new VisualizationBackgroundVO();
            BeanUtils.copyBean(vbVO,vb);
            vbVO.setName(Translator.get("i18n_board")+vbVO.getName());
            return vbVO;
        }).collect(Collectors.groupingBy(VisualizationBackgroundVO::getClassification));
    }
}
