package com.ym.mec.education.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.ym.mec.education.entity.Subject;
import com.ym.mec.education.mapper.SubjectMapper;
import com.ym.mec.education.service.ISubjectService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 科目(声部) 服务实现类
 * </p>
 *
 * @author lemeng
 * @since 2019-09-25
 */
@Service("ISubjectService")
public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, Subject> implements ISubjectService {

    @Override
    public List<Subject> getSubjectList(String subjectIdArr) {
        if (StringUtils.isNotBlank(subjectIdArr)) {
            List<Subject> subjectList = Lists.newArrayList();
            List<String> subjectIdList = Arrays.asList(subjectIdArr.split(","));
            subjectIdList.forEach(subjectId -> {
                Subject subject = getById(Integer.parseInt(subjectId));
                if (Objects.nonNull(subject)) {
                    subjectList.add(subject);
                }
            });
            return subjectList;
        } else {
            return Collections.emptyList();
        }
    }
}
