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.RequestMapping;
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.BusiOfflineArresterCheckDto;
import com.huatek.busi.service.arrester.BusiOfflineArresterCheckService;
import com.huatek.busi.vo.BusiOfflineArresterCheckVo;
import com.huatek.torch.frame.tools.ConstantUtil;
import com.huatek.torch.frame.tools.ResultUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

/**
 * 避雷器例行实验控制层
 *
 * @author edward_luo
 * @date Jul 04, 2019 14:00:23 PM
 */
@Api(tags = { Tags.BUSI_OFFLINE_EXPERIMENT_DATA })
@Slf4j
@RestController
@RequestMapping("/api/ArresterCheck")
public class BusiOfflineArresterCheckController {
    @Reference(check = false)
    private BusiOfflineArresterCheckService busiOfflineArresterCheckService;

    /**
     * 通过设备编号查询避雷器最新一条例行实验
     * @param eqmCode
     * @return
     */
    @ApiOperation(value = "通过设备编号查询避雷器最新一条例行实验")
    @GetMapping(value = "/findArresterThreshold/{eqmCode}", produces = {"application/json;charset=utf-8"})
    public Map<String, Object>  findArresterCheck(@PathVariable(value="eqmCode")String eqmCode) {
    	BusiOfflineArresterCheckVo busiOfflineArresterCheckVo = busiOfflineArresterCheckService.findArresterCheckInfo(eqmCode);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", busiOfflineArresterCheckVo);
    }
    
    /**
     * 获取避雷器例行实验列表分页查询
     * @param busiOfflineArresterCheckDto
     * @return
     */
    @ApiOperation(value = "获取避雷器例行实验列表分页查询", response = BusiOfflineArresterCheckVo.class)
    @PostMapping(value = "/queryList", produces = { "application/json;charset=utf-8" })
    public Map<String, Object> queryList(@RequestBody BusiOfflineArresterCheckDto busiOfflineArresterCheckDto) {
    	PageInfo<BusiOfflineArresterCheckVo> busiOfflineGisChecks = busiOfflineArresterCheckService.findBusiOfflineArresterCheckPage(busiOfflineArresterCheckDto);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, busiOfflineGisChecks.getTotal(), "", busiOfflineGisChecks.getList());
    }
    
    /**
     * 新增避雷器例行实验数据
     * @param busiOfflineArresterCheckDto
     * @return
     */
    @ApiOperation(value = "新增避雷器例行实验数据", response = BusiOfflineArresterCheckVo.class)
    @PostMapping(value = "/saevArresterCheck", produces = { "application/json;charset=utf-8" })
    public Map<String, Object> saevArresterCheck(@RequestBody BusiOfflineArresterCheckDto busiOfflineArresterCheckDto) {        
        int count = busiOfflineArresterCheckService.saveBusiOfflineArresterCheck(busiOfflineArresterCheckDto);
        log.debug("updateArresterThreshold: {}", count);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", "");
    }
}