package com.ym.mec.web.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
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.ym.mec.biz.dal.dto.TreeDto;
import com.ym.mec.biz.service.SysAreaService;
import com.ym.mec.common.controller.BaseController;

@RequestMapping("area")
@Api(tags = "区域服务")
@RestController
public class SysAreaController extends BaseController {

    @Autowired
    private SysAreaService sysAreaService;

    @ApiOperation(value = "根据父节点查询区域树状列表（递归）")
    @GetMapping("/queryTree")
    public Object queryPage(TreeDto treeDto){
        if(treeDto.getParentId() == 0){
            return failed("非法参数");
        }
        return succeed(sysAreaService.queryTreePage(treeDto));
    }

    @ApiOperation(value = "根据父节点查询下一级子节点列表（不递归）")
    @GetMapping("/queryChild")
    public Object queryChild(TreeDto treeDto){
        return succeed(sysAreaService.queryChild(treeDto));
    }
/*
    @ApiOperation(value = "新增区域")
    @PostMapping("/add")
    public Object add(SysArea area){
        return succeed(sysAreaService.insert(area));
    }

    @ApiOperation(value = "根据区域编号删除区域")
    @PostMapping("/del/{id}")
    public Object del(@ApiParam(value = "区域编号", required = true) @PathVariable("id") Integer id){
        return succeed(sysAreaService.delete(id));
    }

    @ApiOperation(value = "修改区域信息")
    @PostMapping("/update")
    public Object update(SysArea area){
        area.setUpdateTime(new Date());
        return succeed(sysAreaService.update(area));
    }*/

    @ApiOperation(value = "根据子级区域获取父级节点")
    @GetMapping("/getParentArea/{id}")
    @ApiParam(value = "区域编号", required = true)
    public Object getParentArea( @PathVariable("id") Integer id){
        return succeed(sysAreaService.getParentArea(id));
    }
}
