package com.codvision.auth.support.excel;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.codvision.auth.entity.OrgProperty;
import com.codvision.auth.service.IOrgPropertyService;
import com.codvision.base.config.excel.select.ExcelDynamicSelect;

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

/**
 * @author KX
 * @date 2023/6/26 14:42
 */
public class PropertyDynamicSelect implements ExcelDynamicSelect {

    @Override
    public String[] getSource() {
        IOrgPropertyService orgPropertyService = SpringUtil.getBean(IOrgPropertyService.class);
        List<String> sourceList = new ArrayList<>();

        List<OrgProperty> orgProperties = orgPropertyService.list();
        if (CollectionUtil.isNotEmpty(orgProperties)) {
            sourceList = orgProperties.stream().map(OrgProperty::getName).collect(Collectors.toList());
        }
        return ArrayUtil.toArray(sourceList, String.class);
    }
}
