package cn.com.ctop.toutiao.modules.batch.service.impl;

import cn.com.ctop.toutiao.modules.batch.entity.BytedanceAreaInfo;
import cn.com.ctop.toutiao.modules.batch.mapper.BytedanceAreaInfoMapper;
import cn.com.ctop.toutiao.modules.batch.service.IBytedanceAreaInfoService;
import cn.com.ctop.toutiao.modules.batch.vo.BytedanceAreaInfoVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * 省市县信息
 *
 * @author jeecg-boot
 * @version V1.0
 * @date 2019-09-17
 */
@Service
public class BytedanceAreaInfoServiceImpl extends ServiceImpl<BytedanceAreaInfoMapper, BytedanceAreaInfo> implements IBytedanceAreaInfoService {
    @Resource
    private BytedanceAreaInfoMapper bytedanceAreaInfoMapper;
    @Override
    public boolean hasChild(BytedanceAreaInfo areaInfo) {
        QueryWrapper<BytedanceAreaInfo>queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("parent_code",areaInfo.getCode());
        List<BytedanceAreaInfo>areaInfos = this.list(queryWrapper);
        if(null == areaInfos||areaInfos.isEmpty()){
            return false;
        }else{
            return true;
        }
    }

    @Override
    public List<BytedanceAreaInfoVO> getListByParams(BytedanceAreaInfo bytedanceAreaInfo) {
        List<BytedanceAreaInfoVO>areaInfos = bytedanceAreaInfoMapper.getListByParams(bytedanceAreaInfo.getParentCode(),bytedanceAreaInfo.getLevel());
        return areaInfos;
    }
}
