package com.xinelu.manage.controller.sysarea;

import com.xinelu.common.core.controller.BaseController;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.manage.service.sysarea.ISysAreaService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * 区域Controller接口
 *
 * @author zh
 * @date 2024-02-26
 */
@RestController
@RequestMapping("/system/area")
public class SysAreaController extends BaseController {
    @Resource
    private ISysAreaService sysAreaService;

    /**
     * 查询省级区域信息信息
     *
     * @return 省级区域信息集合
     */
    @GetMapping("/getFirstLevelInfo")
    public AjaxResult getFirstLevelInfo() {
        return sysAreaService.getProvinceAreaInfo();
    }

    /**
     * 根据父级id
     *
     * @param parentId 父级id
     * @return 所属下级区域信息集合
     */
    @GetMapping("/getSecondaryLevelInfo")
    public AjaxResult getSecondaryLevelInfo(Long parentId) {
        if (Objects.isNull(parentId)) {
            return AjaxResult.error("上级区域id不能为空");
        }
        return sysAreaService.getSubordinateAreaInfo(parentId);
    }
}