package com.yccrc.kede.controller.common;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yccrc.common.core.controller.BaseController;
import com.yccrc.common.core.domain.AjaxResult;
import com.yccrc.kede.domain.Region;
import com.yccrc.kede.service.IRegionService;
import com.yccrc.common.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
/**
 * 行政区域Controller
 * 
 * @author chuanglx
 * @date 2022-01-12
 */
@RestController
@RequestMapping("/common/region")
@Api(tags = "行政区域")
public class RegionController extends BaseController
{
    @Autowired
    private IRegionService regionService;

    @ApiOperation(value = "获取指定行政区域及所有子节点")
    @GetMapping(value = "{id}/all")
    public Result<Region> getAll(@PathVariable("id") String id)
    {
        return new Result<Region>().ok(regionService.getRegionIncludeChildren(id));
    }
    
    @ApiOperation(value = "获取指定行政区域")
    @GetMapping(value = "{id}")
    public Result<Region> getInfo(@PathVariable("id") String id)
    {
    	return new Result<Region>().ok(regionService.getById(id));
       // return AjaxResult.success(regionService.getById(id));
    }
    
    @ApiOperation(value = "获取指定行政区域的下级节点")
    @GetMapping(value = "{id}/children")
    public Result<List<Region>> getChildRen(@PathVariable("id") String id)
    {
        return new Result<List<Region>>().ok(regionService.getChildren(id));
    }

    @ApiOperation(value = "获取省份信息")
    @GetMapping(value = "province")
    public Result<List<Region>> getProvince()
    {
        return new Result<List<Region>>().ok(regionService.getProvinces());
    }
}
