package com.huatek.busi.controller;

import java.util.List;
import java.util.Map;

import org.springframework.web.bind.annotation.GetMapping;
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.service.BusiSubPageService;
import com.huatek.busi.service.threshold.ArresterInsulationMonitorThresholdService;
import com.huatek.busi.service.threshold.CapacitanceEquipmentInsulationMonitorThresholdService;
import com.huatek.busi.vo.ArresterInsulationMonitorThresholdVo;
import com.huatek.busi.vo.CapacitanceEquipmentInsulationMonitorThresholdVo;
import com.huatek.busi.vo.warning.BusiArresterVo;
import com.huatek.busi.vo.warning.BusiCapaVo;
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;

/**
 * 容性避雷器告警及预警
 *
 * @author buck_guo
 * @date 2019/08/21
 */
@Api(tags = {Tags.ARRESTER_WARNNING_THRESHOLD})
@Slf4j
@RestController
@RequestMapping("/app/arresterWarnningAndThreshold")
public class ArresterWarnningAndThresholdController {

    @Reference(check = false)
    private BusiSubPageService busiSubPageService;

    @Reference(check = false)
    private ArresterInsulationMonitorThresholdService arresterInsulationMonitorThresholdService;

    @Reference(check = false)
    private CapacitanceEquipmentInsulationMonitorThresholdService capacitanceEquipmentInsulationMonitorThresholdService;

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

    /**
     * 容性避雷器
     * @param sensorCode
     * @return
     */
    @ApiOperation(value = "根据sensorCode获取阈值", response = ArresterInsulationMonitorThresholdVo.class)
    @ApiImplicitParams({@ApiImplicitParam(name = "sensorCode", value = "传感器编码"),
            @ApiImplicitParam(name = "sensorCode", value = "sensorCode")})
    @GetMapping(value = "/findArresterInsulationThresholdBySensorCode", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> findArresterInsulationThresholdBySensorCode(@RequestParam("sensorCode") String sensorCode) {
        List<ArresterInsulationMonitorThresholdVo> vo =
                arresterInsulationMonitorThresholdService.getThresholdVoBysensorCode(sensorCode);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", vo);
    }


    /**
     * 避雷器告警信息
     *
     * @param warningId
     *            告警ID
     * @param sensorCode
     *            传感器编码
     * @return BusiArresterVo
     */
    @ApiOperation(value = "避雷器告警信息", response = BusiArresterVo.class)
    @ApiImplicitParams({@ApiImplicitParam(name = "warningId", value = "告警ID"),
            @ApiImplicitParam(name = "sensorCode", value = "传感器编码")})
    @GetMapping(value = "/getArresterInfo")
    public Map<String, Object> getArresterInfo(@RequestParam("warningId") String warningId,
                                               @RequestParam("sensorCode") String sensorCode) {
        BusiArresterVo arresterInfo = busiSubPageService.getArresterInfo(warningId, sensorCode);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", arresterInfo);
    }

    /**
     * 容性设备告警信息
     *
     * @param warningId
     *            告警ID
     * @param sensorCode
     *            传感器编码
     * @return BusiCapaVo
     */
    @ApiOperation(value = "容性设备告警信息", response = BusiCapaVo.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "warningId", value="告警ID"),
            @ApiImplicitParam(name = "sensorCode", value="传感器编码")
    })
    @GetMapping(value = "/getCapacitanceInfo")
    public Map<String, Object> getCapacitanceInfo(@RequestParam("warningId") String warningId,
                                                  @RequestParam("sensorCode") String sensorCode) {
        BusiCapaVo busiCapaVo = busiSubPageService.getCapacitanceInfo(warningId, sensorCode);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", busiCapaVo);
    }

    @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);
    }
}
