package com.huatek.busi.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import com.huatek.busi.service.transformer.TransformerOfflineExperimentReportService;
import com.huatek.busi.vo.routinetest.TransformerTestPageVo;
import com.huatek.busi.vo.routinetest.TransformerTestTmpDetailVo;
import com.huatek.busi.vo.routinetest.TransformerTestTmpVo;
import com.huatek.busi.vo.routinetest.TransformerTestVo;
import com.huatek.busi.vo.warning.BusiHomePageWarningVo;
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.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@Api(tags = { "变压器例行试验" })
@Slf4j
@RestController
@RequestMapping("/api/TransformerOffline")
public class TransformerOfflineExperimentReportController {

	@Reference(check = false)
	private TransformerOfflineExperimentReportService transformerOfflineExperimentReportService;

	/** 
	* @Title: transformerList 
	* @Description: 变压器列表 
	* @createDate: Aug 28, 2019 2:52:12 PM 
	* @return   Map<String,Object>    
	*/ 
	@ApiOperation(value = "变压器列表")
	@GetMapping(value = "/transformerList", produces = { "application/json;charset=utf-8" })
	public Map<String, Object> list( ) {
		List<TransformerTestTmpVo> list = transformerOfflineExperimentReportService.getTransformerList();
		log.debug("info: {}", list);
		return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", list);
	}
	
	
	/** 
	* @Title: transformerInfo 
	* @Description: 变压器信息
	* @createDate: Aug 28, 2019 2:52:12 PM 
	* @return   Map<String,Object>    
	*/ 
	@ApiOperation(value = "根据变压器ID获取变压器信息")
	@ApiImplicitParam(name = "transformerId", value = "变压器ID")
	@GetMapping(value = "/transformerInfo", produces = { "application/json;charset=utf-8" })
	public Map<String, Object> transformerInfo( @RequestParam ("transformerId")String transformerId) {
		TransformerTestTmpDetailVo vo = transformerOfflineExperimentReportService.getTransformerInfo(transformerId);
		log.debug("info: {}", vo);
		return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", vo);
	}
	
	
	/**
	 * @Title: info
	 * @Description: 变压器例行试验详情
	 * @createDate: Aug 27, 2019 6:56:13 PM
	 * @param  id  例行试验ID
	 * @return Map<String,Object>
	 */
	@ApiOperation(value = "变压器例行试验详情")
	@ApiImplicitParam(name = "id", value = "例行试验ID")
	@GetMapping(value = "/info", produces = { "application/json;charset=utf-8" })
	public Map<String, Object> info( @RequestParam ("id")String id) {
		TransformerTestVo info = transformerOfflineExperimentReportService.info(id);
		log.debug("info: {}", info);
		return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", info);
	}
	
	
	/**
	 * @Title: add
	 * @Description: 新增变压器例行试验
	 * @createDate: Aug 27, 2019 6:56:13 PM
	 * @param  vo
	 * @return Map<String,Object>
	 */
	@ApiOperation(value = "新增变压器例行试验")
	@PostMapping(value = "/add", produces = { "application/json;charset=utf-8" })
	public Map<String, Object> add(@RequestHeader("token")String token, @RequestBody TransformerTestVo vo) {
		boolean flag = transformerOfflineExperimentReportService.add(token, vo);
		log.debug("addTransformerIcgeThreshold: {}", flag);
		return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, flag ? "新增例行试验成功" :"新增例行试验失败" , "");
	}
	
	/**
	 * @Title: update
	 * @Description: 修改变压器例行试验
	 * @createDate: Aug 27, 2019 6:56:13 PM
	 * @param  vo
	 * @return Map<String,Object>
	 */
	@ApiOperation(value = "修改变压器例行试验")
	@PostMapping(value = "/update", produces = { "application/json;charset=utf-8" })
	public Map<String, Object> update(@RequestHeader("token")String token, @RequestBody TransformerTestVo vo) {
		boolean flag = transformerOfflineExperimentReportService.update(token, vo);
		log.debug("addTransformerIcgeThreshold: {}", flag);
		return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, flag ? "修改例行试验成功" :"修改例行试验失败" , "");
	}
	
    /** 
    * @Title: delete 
    * @Description:删除 变压器例行试验
    * @createDate: Aug 28, 2019 3:29:50 PM
    * @param    ids  主键集合
    * @return   Map<String,Object>    
    */ 
    @ApiOperation(value = "删除变压器例行试验")
    @PostMapping(value = "/delete", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> delete(@RequestHeader("token") String token,
        @RequestBody List<String> ids) {
        int count = transformerOfflineExperimentReportService.delete(token, ids);
        log.debug("deleteBusiOfflineGisRepair: {}", count);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, count >0  ?"删除例行试验成功" :"删除例行试验失败", "");
    }
    
    
    /** 
    * @Title: page 
    * @Description: 变压器例行试验列表分页 
    * @createDate: Aug 28, 2019 5:35:41 PM
    * @param    name
    * @param    page
    * @param    limit
    * @return   Map<String,Object>    
    */ 
    @ApiOperation(value = "变压器例行试验列表分页", response = BusiHomePageWarningVo.class)
    @ApiImplicitParams({
        @ApiImplicitParam(name = "name", value = "变压器名称", required = false),
        @ApiImplicitParam(name = "page", value = "当前页", required = false),
        @ApiImplicitParam(name = "limit", value = "每页大小", required = false)
    })
    @GetMapping(value = "/page")
    public Map<String, Object> page(@RequestParam(value = "name", required = false) String name,
        @RequestParam(value = "page", required = false) Integer page,
        @RequestParam(value = "limit", required = false) Integer limit,
        @DateTimeFormat(pattern="yyyy-MM-dd") @RequestParam(value = "timeStampStart",required = false) LocalDate timeStampStart,
        @DateTimeFormat(pattern="yyyy-MM-dd") @RequestParam(value = "timeStampEnd",required = false) LocalDate timeStampEnd) {
        PageInfo<TransformerTestPageVo> pageInfo = transformerOfflineExperimentReportService.page(name, page,  limit,timeStampStart,timeStampEnd);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, pageInfo.getTotal(), "", pageInfo.getList());
    }

    @ApiOperation(value = "变压器例行试验详情(告警界面链接调用)", response = BusiHomePageWarningVo.class)
    @ApiImplicitParam(name = "mainTreeId", value = "变压器树ID", required = false)
    @GetMapping(value = "/getByTreeId")
    public Map<String, Object> getByTreeId(@RequestParam(value = "mainTreeId", required = false) String mainTreeId){
    	TransformerTestVo vo = transformerOfflineExperimentReportService.getByTreeId(mainTreeId);
    	return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", vo);
    }
}
