package com.huiju.estateagents.property.controller;

import com.huiju.estateagents.base.BaseController;
import com.huiju.estateagents.base.ResponseBean;
import com.huiju.estateagents.center.taUser.entity.TaUser;
import com.huiju.estateagents.property.common.UserElement;
import com.huiju.estateagents.property.service.BuildingTreeServiceI;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author FXF
 * @date 2019-04-01
 */
@RestController

@RequestMapping("/api")
@Api(value = "楼栋树管理", description = "楼栋树管理 Api")
public class BuildingTreeController extends BaseController {
	
	@Autowired
	private BuildingTreeServiceI buildingTreeService;
	
	@ApiOperation(value = "上传楼栋信息接口", notes = "上传楼栋信息接口")
	@PostMapping(value = "/tree/uploadExcel", consumes = "multipart/*", headers = "content-type=multipart/form-data")
	public ResponseBean uploadExcel(@RequestParam("file") MultipartFile file) {
		ResponseBean responseBean = new ResponseBean();
		responseBean = buildingTreeService.getExcelData(file);
		return responseBean;
	}
	
	@ApiOperation(value = "上传楼栋信息并入库", notes = "上传楼栋信息并入库")
	@PostMapping(value = "/tree/submitExcel", consumes = "multipart/*", headers = "content-type=multipart/form-data")
	public ResponseBean submitExcel(@RequestParam("file") MultipartFile file, HttpServletRequest request) {
		ResponseBean responseBean = new ResponseBean();
		TaUser userElement = getTaUser(request);
		responseBean = buildingTreeService.submitExcelData(file,userElement);
		return responseBean;
	}
	
	@ApiOperation(value = "获取树形数据", notes = "获取树形数据")
	@GetMapping(value = "/admin/buildingInfo/trees")
	@ApiImplicitParams({
			@ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "authorization", value = "Token"),
			@ApiImplicitParam(paramType = "body", dataTypeClass = String.class, name = "id", value = "当前节点id(查期时ID为空)"),
			@ApiImplicitParam(paramType = "body", dataTypeClass = String.class, name = "treeType", value = "phase:(期)，building:(栋),unit:(单元),level:(楼层),roomNo:(房间号)")
	})
	public ResponseBean getTreeList(@RequestParam(value = "id", required = false) Integer id, @RequestParam("treeType") String treeType, HttpServletRequest request){
		ResponseBean responseBean = new ResponseBean();
		TaUser userElement = getTaUser(request);
		responseBean = buildingTreeService.getTreeList(userElement.getOrgId(),id,treeType);
		return responseBean;
	}

	@ApiOperation(value = "添加当前节点", notes = "添加当前节点")
	@ApiImplicitParams({
			@ApiImplicitParam(paramType = "body", dataTypeClass = String.class, name = "parameter", value = "id:当前节点;" +
					"name:节点名称;type：(phase:(期)，building:(栋),unit:(单元),level:(楼层),roomNo:(房间号)), roomNonodeNumber:输入的节点")
	})
	@RequestMapping(value = "/addnode",method = RequestMethod.POST)
	public ResponseBean addNode(@RequestBody String parameter, HttpServletRequest request){
		TaUser userElement = getTaUser(request);
	    ResponseBean	responseBean = buildingTreeService.addNode(parameter, userElement.getOrgId());
		return responseBean;
	}

	@ApiOperation(value = "删除当前节点", notes = "删除当前节点")
	@ApiImplicitParams({
			@ApiImplicitParam(paramType = "body", dataTypeClass = String.class, name = "parameter", value = "id:当前节点;type:(end:(房间)，roomNo:(楼层),level:(单元)，unit:(楼栋),building:(期))")
	})
	@RequestMapping(value = "/deletenode",method = RequestMethod.POST)
	public ResponseBean deletenode(@RequestBody String parameter, HttpServletRequest request){
		TaUser userElement = getTaUser(request);
		ResponseBean	responseBean = buildingTreeService.deleteNode(parameter, userElement.getOrgId());
		return responseBean;
	}
}
