package com.app.service.platform;

import com.app.entity.platform.system.Address;
import com.app.mapper.platform.AddressMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

@Service
public class AddressService {

    @Resource
    private AddressMapper mapper;

    /**
     * 功能描述：查询地址名称底下的地址信息
     *
     * @param name 地址名称
     * @return
     */
    public List<Address> findNextLevel(String name) {
        // 根据地址名称查询
        Optional<Address> optional = Optional.ofNullable(mapper.selectOne(new QueryWrapper<Address>().lambda().eq(Address::getName, name)));
        if (optional.isPresent()) {
            Address address = optional.get();
            // 根据父级为code的底下一级信息
            return mapper.selectList(new QueryWrapper<Address>().lambda().eq(Address::getParentId, address.getId()));
        }

        return Collections.EMPTY_LIST;
    }

}
