package com.yunzhupaas.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yunzhupaas.base.entity.ProvinceAtlasEntity;
import com.yunzhupaas.base.mapper.ProvinceAtlasMapper;
import com.yunzhupaas.base.service.ProvinceAtlasService;
import com.yunzhupaas.base.service.SuperServiceImpl;
import com.yunzhupaas.util.StringUtil;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 行政区划
 *
 * @author 云筑产品开发平台组
 * @version V3.1.0
 * @copyright 深圳市乐程软件有限公司（http://www.szlecheng.cn）
 * @date 2023/09/27
 */
@Service
public class ProvinceAtlasServiceImpl extends SuperServiceImpl<ProvinceAtlasMapper, ProvinceAtlasEntity> implements ProvinceAtlasService {

    @Override
    public List<ProvinceAtlasEntity> getList() {
        QueryWrapper<ProvinceAtlasEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(ProvinceAtlasEntity::getEnabledMark, 1);
        return  this.list(queryWrapper);
    }

    @Override
    public List<ProvinceAtlasEntity> getListByPid(String pid) {
        QueryWrapper<ProvinceAtlasEntity> queryWrapper = new QueryWrapper<>();
        if (StringUtil.isNotEmpty(pid)) {
            queryWrapper.lambda().eq(ProvinceAtlasEntity::getParentId, pid);
        }else{
            queryWrapper.lambda().eq(ProvinceAtlasEntity::getParentId, "-1");
        }
        queryWrapper.lambda().eq(ProvinceAtlasEntity::getEnabledMark, 1);
        return  this.list(queryWrapper);
    }

    @Override
    public ProvinceAtlasEntity findOneByCode(String code) {
        QueryWrapper<ProvinceAtlasEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(ProvinceAtlasEntity::getEnCode, code);
        queryWrapper.lambda().eq(ProvinceAtlasEntity::getEnabledMark, 1);
        return  this.getOne(queryWrapper);
    }
}

