package com.huatek.busi.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.huatek.busi.service.BusiSubTreeService;
import com.huatek.busi.vo.BusiTreeNodeVo;
import com.huatek.torch.frame.tools.ConstantUtil;
import com.huatek.torch.frame.tools.ResultUtil;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @ClassName: BusiSiteTreeController
 * @FullClassPath: com.huatek.busi.controller.BusiSiteTreeController
 * @Description: 站点树控制层
 * @author: Arno
 * @date: Jun 21, 2019 10:30:55 AM
 * @version: 1.0
 */

@RestController
@RequestMapping("/api/BusiSiteSubTree")
public class BusiSiteSubTreeController {

	protected final Logger logger = LoggerFactory.getLogger(BusiSiteSubTreeController.class);

	@Reference(check = false)
	private BusiSubTreeService busiSubTreeService;

	
	 @ApiOperation(value="外挂设备树", notes="")
	    @ApiImplicitParams({
	        @ApiImplicitParam(paramType="query", name = "nodeId", value = "设备节点ID", required = true, dataType = "String"),
	        @ApiImplicitParam(paramType="query", name = "nodeType", value = "节点新名称(eg: 111-变压器  211-GIS  411-避雷器)", required = true, dataType = "String")
	    })
	@GetMapping(value = "/tree")
	public Map<String, Object> tree(@RequestParam(value="nodeId",required=true)String  nodeId,@RequestParam(value="nodeType",required=true)String  nodeType ) {
		List<BusiTreeNodeVo> siteTree = busiSubTreeService.tree(nodeId, nodeType );
		return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", siteTree);
	}

    @ApiOperation(value="修改节点名称", notes="")
    @ApiImplicitParams({
        @ApiImplicitParam(paramType="query", name = "nodeId", value = "设备节点ID", required = true, dataType = "String"),
        @ApiImplicitParam(paramType="query", name = "nodeType", value = "节点新名称(eg: 111-变压器  211-GIS  411-避雷器)", required = true, dataType = "String"),
        @ApiImplicitParam(paramType="query", name = "newName", value = "节点新名称", required = true, dataType = "String")
    })
	@GetMapping(value = "/updateNode")
	public Map<String, Object> updateNode( @RequestParam(value="nodeId",required=true)String  nodeId, @RequestParam(value="nodeType",required=true)String  nodeType, @RequestParam(value="newName",required=true)String newName ) {
    	busiSubTreeService.updateNode(nodeId, nodeType, newName);
		return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", null);
	}

    @ApiOperation(value="删除节点", notes="")
    @ApiImplicitParams({
	    @ApiImplicitParam(paramType="query", name = "nodeId", value = "设备节点ID", required = true, dataType = "String"),
	    @ApiImplicitParam(paramType="query", name = "nodeType", value = "节点新名称(eg: 111-变压器  211-GIS  411-避雷器)", required = true, dataType = "String")
    })
	@GetMapping(value = "/deleteNode")
	public Map<String, Object> deleteNode(@RequestParam(value="nodeId",required=true)String  nodeId, @RequestParam(value="nodeType",required=true)String  nodeType) {
    	busiSubTreeService.deleteNode(nodeId, nodeType);
		return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", null);
	}
    
    @ApiOperation(value="新增节点名称", notes="")
    @ApiImplicitParams({
        @ApiImplicitParam(paramType="query", name = "nodeId", value = "设备节点ID", required = true, dataType = "String"),
        @ApiImplicitParam(paramType="query", name = "nodeType", value = "节点新名称(eg: 111-变压器  211-GIS  411-避雷器)", required = true, dataType = "String"),
        @ApiImplicitParam(paramType="query", name = "count", value = "子节点数量", required = true, dataType = "String")
    })
    @GetMapping(value = "/insertNode")
	public Map<String, Object> insertNode( @RequestParam(value="nodeId",required=true)String  nodeId, @RequestParam(value="nodeType",required=true)String  nodeType, @RequestParam(value="count",required=true)String count ) {
    	busiSubTreeService.insertNode(nodeId, nodeType, count);
		return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", null);
	}
}