package com.huatek.busi.controller;

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

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.util.StringUtil;
import com.huatek.busi.entity.BusiEquipmentRelationship;
import com.huatek.busi.service.BusiEquipmentRelationshipService;
import com.huatek.busi.service.BusiSiteTreeService;
import com.huatek.busi.vo.TransformerTmpVo;
import com.huatek.torch.frame.tools.ConstantUtil;
import com.huatek.torch.frame.tools.ResultUtil;

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

/**
 * @ClassName: BusiEquipmentRelationshipController
 * @FullClassPath: com.huatek.busi.controller.
 *                 BusiEquipmentRelationshipController
 * @Description: 
 * @author: Arno
 * @date: Aug 21, 2019 4:50:48 PM
 * @version: 1.0
 */

@Api(tags = { "设备与变压器关系设置控制器" })
@RestController
@RequestMapping("/api/BusiEquipmentRelationship")
public class BusiEquipmentRelationshipController {

	@Reference(check = false)
	private BusiEquipmentRelationshipService busiEquipmentRelationshipService;
	
	@Reference(check = false)
	private BusiSiteTreeService busiSiteTreeService;

//	@ApiOperation(value = "获取当前所属变压器", response = TransformerTmpVo.class)
//	@ApiImplicitParam(name = "equipmentId", value = "GIS/测温费/避雷器站点设ID")
//	@GetMapping(value = "/getCurrentTransformerInfo", produces = { "application/json;charset=utf-8" })
//	public Map<String, Object> getCurrentTransformerInfo(@RequestParam("equipmentId") String equipmentId) {
//		TransformerTmpVo info = busiEquipmentRelationshipService.getCurrentTransformerInfo(equipmentId);
//		return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", info);
//	}

	@ApiOperation("绑定关系")
	@PostMapping(value = "/saveRelationship", produces = { "application/json;charset=utf-8" })
	public Map<String, Object> saveRelationship(@RequestBody BusiEquipmentRelationship entity) {
		String equipmentId = entity.getEquipmentId();
		String transformerId = entity.getTransformerId();
		if(StringUtil.isEmpty(transformerId) || StringUtil.isEmpty(equipmentId)){
			return ResultUtil.put(ConstantUtil.REQUEST_FAIL, "变压器ID获取设备ID为空", "");
		}
		busiEquipmentRelationshipService.insertBusiEquipmentRelationship(entity);
		return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", "");
	}

	/**
	 * 取消绑定关系
	 */
	@ApiOperation("取消绑定关系")
	@PostMapping(value = "/cancelRelationship", produces = { "application/json;charset=utf-8" })
	public Map<String, Object> cancleRelationship(@RequestBody BusiEquipmentRelationship entity) {
		String equipmentId = entity.getEquipmentId();
		String transformerId = entity.getTransformerId();
		if(StringUtil.isEmpty(transformerId) || StringUtil.isEmpty(equipmentId)){
			return ResultUtil.put(ConstantUtil.REQUEST_FAIL, "变压器ID获取设备ID为空", "");
		}
		busiEquipmentRelationshipService.cancelBusiEquipmentRelationship(entity);
		return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", "");
	}
    /** 
    * @Title: getTransformerList 
    * @Description: 根据站点id获取变压器数据 
    * @createDate: Aug 21, 2019 4:31:15 PM
    * @param    siteId 站点ID
    * @return   Map<String,Object>    
    */ 
    @ApiOperation(value="根据站点id获取变压器数据", notes="")
    @ApiImplicitParam(paramType="query", name = "siteId", value = "站点ID", required = true, dataType = "String")
	@GetMapping(value = "/getTransformerList")
	public Map<String, Object> getTransformerList(@RequestParam(value="siteId",required=true)String  siteId,@RequestParam(value="equipmentId",required=true)String  equipmentId) {
    	List<TransformerTmpVo> list = busiSiteTreeService.selectByTransformerAndBindRelationBySiteId(siteId,equipmentId);
		return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", list);
	}
}
