package com.ruoyi.system.service.impl;


import com.ruoyi.system.domain.*;
import com.ruoyi.system.mapper.ActSuppliesConverMapper;
import com.ruoyi.system.service.IActSuppliesConvertService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

@Service
public class ActSuppliesConvertServiceImpl implements IActSuppliesConvertService {

    @Autowired
    private ActSuppliesConverMapper actSuppliesConverMapper;

    @Override
    public List<ActSuppliesTemplate> templiteList(ActSuppliesTemplate sysSupplies) {
        return actSuppliesConverMapper.templiteList(sysSupplies);
    }

    @Override
    public List<ActSuppliesTemplate> templiteListid(Integer id) {
        return actSuppliesConverMapper.templiteListid(id);
    }

    @Override
    public List<ActSuppliesRole> roleList(Integer id) {
        return actSuppliesConverMapper.roleList(id);
    }

    @Override
    public List<ActSuppliesRoleDetail> roleListid(Integer id) {
        return actSuppliesConverMapper.roleListid(id);
    }

    @Override
    public ActSupplies selectSuppliesname(String name) {
        return actSuppliesConverMapper.selectSuppliesname(name);
    }

    @Override
    public List<String> converSupplies(String[] names) {

        List<String> name = Arrays.asList(names);

        List<ActOperation> list = actSuppliesConverMapper.converSupplies(name);

        name = name.stream()
                .map(str -> {
                    if (str == null) {
                        return null; // 保留原始的null值
                    }
                    for (int i = 0; i < list.size(); i++) {
                        if (str.equals(list.get(i).getDetaliesName())) {
                            return list.get(i).getSuppliesName();
                        }
                    }
                    return str;
                })
                .collect(Collectors.toList());

        return name;
    }
}
