package com.dsk.system.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.dsk.system.domain.SysRegion;
import com.dsk.system.mapper.SysRegionMapper;
import com.dsk.system.service.SysRegionService;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

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

/**
 * 行政区编码表(SysRegion)表服务实现类
 *
 * @author makejava
 * @since 2023-06-28 11:23:12
 */
@Service("sysRegionService")
public class SysRegionServiceImpl implements SysRegionService {
    @Resource
    private SysRegionMapper baseMapper;

    private static final Integer ACQUIESCE_PARENT_ID = 100000;

    @Override
    public List<SysRegion> selectByParentId(Integer parentId) {
        return baseMapper.selectList(Wrappers.<SysRegion>lambdaQuery()
                .eq(SysRegion::getParentId, ObjectUtils.isEmpty(parentId) ? ACQUIESCE_PARENT_ID : parentId)
                .orderByAsc(SysRegion::getId));
    }
}
