package com.hotwj.platform.common.controller;

import com.hotwj.platform.common.mapper.PublicMapper;
import com.hotwj.platform.common.vo.AddressVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequiredArgsConstructor
@RestController
@RequestMapping("/common/region")
@Tag(name = "区域管理", description = "区域树查询接口")
public class RegionController {

    private final PublicMapper publicMapper;

    /**
     * 查询区域树列表
     */
    @GetMapping("/tree")
    @Operation(summary = "查询区域树列表")
    public R<List<AddressVo>> tree() {
        // 查询数据库，查询所有区域树
        List<AddressVo> addressVoList = publicMapper.selectList();
        // 组装成树
        List<AddressVo> tree = AddressVo.buildTree(addressVoList);

        return R.ok(tree);
    }
}
