package com.jwipc.sys.logic.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jwipc.constant.DelFlag;
import com.jwipc.sys.convert.CountryProvinceCityConvert;
import com.jwipc.sys.dto.AreaDTO;
import com.jwipc.sys.entity.CountryProvinceCity;
import com.jwipc.sys.logic.AreaLogic;
import com.jwipc.sys.service.ICountryProvinceCityService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * <p> </p>
 *
 * @author BOGON
 * @version 1.0
 * @since JDK 1.8
 */
@Service
@RequiredArgsConstructor
public class AreaLogicImpl implements AreaLogic {
    private final ICountryProvinceCityService countryProvinceCityService;
    private final CountryProvinceCityConvert countryProvinceCityConvert;

    @Override
    public List<AreaDTO> getByParent(String parentCode) {
        final List<CountryProvinceCity> list = countryProvinceCityService.list(
                new LambdaQueryWrapper<CountryProvinceCity>().eq(CountryProvinceCity::getPCode, parentCode)
                        .eq(CountryProvinceCity::getDeleteFlag,
                                DelFlag.NORMAL.getStatus()));
        return countryProvinceCityConvert.entities2DTOs(list);
    }
}