package com.weather.modules.region.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.weather.common.service.impl.CrudServiceImpl;
import com.weather.common.utils.ConvertUtils;
import com.weather.modules.region.dao.SysRegionDao;
import com.weather.modules.region.dto.SysRegionDTO;
import com.weather.modules.region.entity.SysRegionEntity;
import com.weather.modules.region.service.SysRegionService;
import cn.hutool.core.util.StrUtil;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 行政区划表
 *
 * @author Mark 123
 * @since 1.0.0 2026-03-05
 */
@Service
public class SysRegionServiceImpl extends CrudServiceImpl<SysRegionDao, SysRegionEntity, SysRegionDTO> implements SysRegionService {

    @Override
    public QueryWrapper<SysRegionEntity> getWrapper(Map<String, Object> params) {
        String id = (String) params.get("id");

        QueryWrapper<SysRegionEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StrUtil.isNotBlank(id), "id", id);

        return wrapper;
    }


    /**
     * 获取子一级地区信息
     *
     * @param id 地区 id
     * @return 地区信息
     */
    @Override
    public List<SysRegionDTO> getByParentId(Long id) {
        QueryWrapper<SysRegionEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("parent_id", id);
        List<SysRegionEntity> sysRegionEntities = baseDao.selectList(wrapper);
        return ConvertUtils.sourceToTarget(sysRegionEntities, SysRegionDTO.class);
    }
}