package org.springblade.manager.service.impl;

import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.manager.entity.FormulaBase;
import org.springblade.manager.mapper.FormulaBaseMapper;
import org.springblade.manager.vo.FormulaBaseVo;
import org.springblade.manager.vo.FormulaType;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author yangyj
 * @Date 2022/6/6 14:26
 * @description TODO
 */
@Service
public class FormulaBaseService extends BaseServiceImpl<FormulaBaseMapper, FormulaBase> {
   public Map<String, List<FormulaBaseVo>> getTypeMap(){
        List<FormulaBase> list = this.list();
        if(CollectionUtil.isNotEmpty(list)){
            Map<Integer, List<FormulaBaseVo>> tmp = list.stream().map(e->{FormulaBaseVo fb =new FormulaBaseVo();BeanUtils.copyProperties(e,fb);return fb;}).collect(Collectors.groupingBy(FormulaBaseVo::getType));
            Map<String, List<FormulaBaseVo>> data = new LinkedHashMap<>();
            for(int i=0;i<FormulaType.values().length;i++){
                data.put(FormulaType.getName(i),tmp.get(i));
            }
            return data;
        }
        return null;
    }

}
