package com.vote.system.service.impl;

import com.vctgo.system.api.RemoteBranchKindergartenService;
import com.vctgo.system.api.RemoteSysProvinceService;
import com.vctgo.system.api.domain.dto.SysBranchKindergartenDto;
import com.vote.system.domain.pojo.VoteLocationVo;
import com.vote.system.service.VoteLocationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * @CreateTime: 2024/9/24 下午5:30
 * @Description:
 * @Email: f2965573933@163.com
 * @Author: FanJiaBao
 */
@Service
public class VoteLocationServiceImpl implements VoteLocationService {

    @Autowired
    private RemoteBranchKindergartenService remoteBranchKindergartenService;


    @Override
    public List<VoteLocationVo> getLocationName(String districtId) {
        List<SysBranchKindergartenDto> data = remoteBranchKindergartenService.get(null, null, districtId).getData();
        List<VoteLocationVo> locationVos = new ArrayList<>();

        if (data != null) {
            locationVos = data.stream()
                    .filter(datum -> datum != null && datum.getKindergartenName() != null)
                    .map(datum -> {
                        VoteLocationVo voteLocationVo = new VoteLocationVo();
                        voteLocationVo.setId(datum.getId());
                        voteLocationVo.setLocationName(datum.getKindergartenName());
                        return voteLocationVo;
                    })
                    .collect(Collectors.toList());
        }
        return locationVos;
    }
}