package com.ruoyi.web.controller.base;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.base.area.domain.SysCnArea;
import com.ruoyi.base.area.service.ISysCnAreaService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
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 java.util.List;

/**
 * 行政区域Controller
 *
 * @author ruoyi
 * @date 2023-06-25
 */
@Validated
@Api(value = "行政区域控制器", tags = {"行政区域管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/base/cnArea")
public class SysCnAreaController extends BaseController {

    private final ISysCnAreaService iSysCnAreaService;

    /**
     * 获得省市区三级数据
     */
    @ApiOperation("获得省市区三级数据")
    @GetMapping("/tree-lbs")
    public R getTreeLbs() {
        JSONObject treeLbs = iSysCnAreaService.getTreeLbs();
        return R.ok(treeLbs);
    }

    /**
     * 根据父级code查下一级
     *
     * @param parentCode
     * @return
     */
    @ApiOperation("根据父级code查下一级")
    @GetMapping("/lbs-children/{parentCode}")
    public R<List<SysCnArea>> getChildren(@PathVariable("parentCode") String parentCode) {
        List<SysCnArea> list = iSysCnAreaService.getChildren(parentCode);
        return R.ok(list);
    }


    /**
     * 根据行政编号查父级
     *
     * @param code
     * @return
     */
    @ApiOperation("根据行政编号查父级")
    @RequestMapping("/lbs-path/{code}")
    public R<List<SysCnArea>> getPath(@PathVariable("code") String code) {
        List<SysCnArea> list = iSysCnAreaService.getPath(code);
        return R.ok(list);
    }

}
