package com.admin.major.service.impl;

import com.admin.major.domain.ApplyFile;
import com.admin.major.domain.SpecialApply;
import com.admin.major.domain.dto.SpecialApplyViewDTO;
import com.admin.major.mapper.ApplyFileMapper;
import com.admin.major.mapper.EnhanceSpecialApplyMapper;
import com.admin.major.service.IEnhanceSpecialApplyService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


@Service
public class EnhanceSpecialApplyServiceImpl implements IEnhanceSpecialApplyService {

    @Resource
    private EnhanceSpecialApplyMapper enhanceSpecialApplyMapper;
    @Resource
    private ApplyFileMapper applyFileMapper;


    @Override
    public SpecialApplyViewDTO viewSpecialApply(SpecialApply specialApply) {
        return enhanceSpecialApplyMapper.viewSpecialApply(specialApply)
                .stream()
                .findFirst()
                .orElse(null);
    }

    @Override
    public List<SpecialApplyViewDTO> viewSpecialApplyList(SpecialApply specialApply) {
        List<SpecialApplyViewDTO> specialApplyViewDTOS = enhanceSpecialApplyMapper.viewSpecialApply(specialApply);
        for (int i = 0; i < specialApplyViewDTOS.size(); i++) {
            Integer specialApplyId = specialApplyViewDTOS.get(i).getSpecialApplyId();
            List<ApplyFile> applyFiles = applyFileMapper.selectApplyFileByFileId(specialApplyId.toString());
            ArrayList<String> list = new ArrayList<>();
            for (int j = 0; j < applyFiles.size(); j++) {
                list.add(applyFiles.get(j).getPath());
            }
            specialApplyViewDTOS.get(i).setAttachmentList(list);
        }
        return specialApplyViewDTOS;
    }


}
