package com.koobietech.eas.service.impl;

import com.koobietech.eas.mbg.mapper.EasArcArchivesMapper;
import com.koobietech.eas.mbg.model.EasArcArchives;
import com.koobietech.eas.mbg.model.EasArcArchivesExample;
import com.koobietech.eas.service.EasArcArchivesService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

@Service
public class EasArcArchivesServiceImpl implements EasArcArchivesService {

    @Resource
    EasArcArchivesMapper easArcArchivesMapper;

    @Override
    public List<EasArcArchives> getArchives(EasArcArchives easArcArchives) {
        EasArcArchivesExample easArcArchivesExample = new EasArcArchivesExample();
        EasArcArchivesExample.Criteria criteria = easArcArchivesExample.createCriteria();
        if ( Objects.isNull(easArcArchives) ) {
            return Collections.emptyList();
        }
        if (StringUtils.hasText(easArcArchives.getStudentNumber())) {
            criteria.andStudentNumberEqualTo(easArcArchives.getStudentNumber());
        }
        List<EasArcArchives> easArcArchivesList = easArcArchivesMapper.selectByExample(easArcArchivesExample);

        List<EasArcArchives> collect = easArcArchivesList.stream().map(arcArchives -> {
            arcArchives.setFilePath(null);
            return arcArchives;
        }).collect(Collectors.toList());

        return collect;
    }
}
