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.CapacitanceEquipmentInsulationMonitorThresholdDto;
import com.huatek.busi.service.threshold.CapacitanceEquipmentInsulationMonitorThresholdService;
import com.huatek.busi.vo.CapacitanceEquipmentInsulationMonitorThresholdVo;
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;

/**
 * 容性设备-绝缘监测-阈值：022001 控制层
 *
 * @author anker_cheng
 * @date Aug 12, 2019 7:18:09 PM
 */
@Api(tags = {Tags.ARRESTER_CAPACITIVE_THRESHOLD})
@Slf4j
@RestController
@RequestMapping("/api/CapacitanceEquipmentInsulationMonitorThreshold")
public class CapacitanceEquipmentInsulationMonitorThresholdController {

    @Reference(check = false)
    private CapacitanceEquipmentInsulationMonitorThresholdService capacitanceEquipmentInsulationMonitorThresholdService;

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

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