package com.huatek.busi.controller;

import java.util.Map;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
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.PageInfo;
import com.huatek.busi.constant.ApiConstant.Tags;
import com.huatek.busi.dto.ArresterOfflineExperimentReportDto;
import com.huatek.busi.service.arrester.ArresterOfflineExperimentReportService;
import com.huatek.busi.service.arrester.BusiOfflineArresterBrandService;
import com.huatek.busi.vo.ArresterOfflineExperimentReportVo;
import com.huatek.busi.vo.BusiOfflineArresterBrandVo;
import com.huatek.busi.vo.BusiOfflineArresterRepairVo;
import com.huatek.busi.vo.routinetest.arrester.ArresterOfflineExperimentReportObj;
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.ApiOperation;
import lombok.extern.slf4j.Slf4j;

/**
 * 避雷器离线实现报告
 * 
 * @author buck_guo
 * @date 2019/08/23
 */
@Api(tags = {Tags.ARRESTER_OFFLINE_EXPERIMENT_REPORT})
@Slf4j
@RestController
@RequestMapping("/api/ArresterOfflineExperimentReport")
public class ArresterOfflineExperimentReportController {

    @Reference(check = false)
    private ArresterOfflineExperimentReportService arresterOfflineExperimentReportService;
    @Reference(check = false)
    private BusiOfflineArresterBrandService busiOfflineArresterBrandService;

    @ApiOperation(value = "保存避雷器离线实现报告")
    @PostMapping(value = "/saveArresterOfflineExperimentReport", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> saveArresterOfflineExperimentReport(@RequestHeader("token") String token,
        @RequestBody ArresterOfflineExperimentReportObj arresterOfflineExperimentReportObj) {
        int count = arresterOfflineExperimentReportService.saveArresterOfflineExperimentReport(token,
            arresterOfflineExperimentReportObj);
        log.debug("updateArresterInsulationMonitorThreshold: {}", count);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", "");
    }

    @ApiOperation(value = "查询避雷器离线实现报告分页查询", response = BusiOfflineArresterRepairVo.class)
    @PostMapping(value = "/queryList", produces = {"application/json;charset=utf-8"})
    public Map<String, Object>
        queryList(@RequestBody ArresterOfflineExperimentReportDto arresterOfflineExperimentReportDto) {
        PageInfo<ArresterOfflineExperimentReportVo> pageInfo =
            arresterOfflineExperimentReportService.queryList(arresterOfflineExperimentReportDto);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, pageInfo.getTotal(), "", pageInfo.getList());
    }

    @ApiOperation(value = "根据主键ID避雷器离线实现报告", response = BusiOfflineArresterRepairVo.class)
    @GetMapping(value = "/selectByPrimaryKey/{id}", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> selectByPrimaryKey(@PathVariable(value="id") String id) {
        ArresterOfflineExperimentReportObj arresterOfflineExperimentReportObj =
            arresterOfflineExperimentReportService.selectByPrimaryKey(id);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", arresterOfflineExperimentReportObj);
    }

    @ApiOperation(value = "根据siteId、mainEquipmentId避雷器标配信息", response = BusiOfflineArresterBrandVo.class)
    @PostMapping(value = "/selectArresterBrand", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> selectArresterBrand(@RequestParam(value="siteId")String siteId,@RequestParam(value="mainEquipmentId")String mainEquipmentId) {
        BusiOfflineArresterBrandVo busiOfflineArresterBrandVo =
            busiOfflineArresterBrandService.getBusiOfflineArresterBrandInfo(siteId, mainEquipmentId);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", busiOfflineArresterBrandVo);
    }

    @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){
        ArresterOfflineExperimentReportObj vo = arresterOfflineExperimentReportService.getByTreeId(mainTreeId);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", vo);
    }
}
