package com.huatek.busi.controller;

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.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.huatek.busi.constant.ApiConstant.Tags;
import com.huatek.busi.dto.ArresterInsulationMonitorThresholdDto;
import com.huatek.busi.service.threshold.ArresterInsulationMonitorThresholdService;
import com.huatek.busi.vo.ArresterInsulationMonitorThresholdVo;
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;

/**
 * 避雷器-绝缘监测-阈值表：023001 控制层
 *
 * @author anker_cheng
 * @date Aug 12, 2019 7:18:09 PM
 */
@Api(tags = {Tags.ARRESTER_INSULATION_THRESHOLD})
@Slf4j
@RestController
@RequestMapping("/api/ArresterInsulationMonitorThreshold")
public class ArresterInsulationMonitorThresholdController {

    @Reference(check = false)
    private ArresterInsulationMonitorThresholdService arresterInsulationMonitorThresholdService;

    @ApiOperation(value = "获取阈值", response = ArresterInsulationMonitorThresholdVo.class)
    @ApiImplicitParams({
        @ApiImplicitParam(name = "sensorCode", value = "传感器编码"),
        @ApiImplicitParam(name = "runState", value = "设备状态")
    })
    @GetMapping(value = "/getThreshold", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> findArresterInsulationMonitorThreshold(@RequestParam("sensorCode") String sensorCode,
        @RequestParam("runState") String runState) {
        ArresterInsulationMonitorThresholdVo vo =
            arresterInsulationMonitorThresholdService.getThresholdVo(runState, sensorCode);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", vo);
    }

    @ApiOperation(value = "保存阈值")
    @PostMapping(value = "/saveOrUpdate", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> updateArresterInsulationMonitorThreshold(@RequestHeader("token") String token,
        @RequestBody ArresterInsulationMonitorThresholdDto arresterInsulationMonitorThresholdDto) {
        int count =
            arresterInsulationMonitorThresholdService.saveOrUpdate(token, arresterInsulationMonitorThresholdDto);
        log.debug("updateArresterInsulationMonitorThreshold: {}", count);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", "");
    }

}