package com.huatek.busi.controller;

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

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.transformer.TransformerRunStatusThresholdService;
import com.huatek.busi.vo.TransformerRunStatusThresholdVo;
import com.huatek.busi.vo.warning.BusiRunStateVo;
import com.huatek.torch.frame.log.KerLog;
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;

/**
 * 变压器运行工况
 *
 * @author buck_guo
 * @date 2019/08/07
 */
@Api(tags = {Tags.TRANSFORMERRUNSTATUSTHRESHOLD})
@RestController
@RequestMapping("/app/runStatusThreshold")
public class RunStatusThresholdController {

    protected final Logger logger = LoggerFactory.getLogger(RunStatusThresholdController.class);

    @Reference(check = false)
    private TransformerRunStatusThresholdService transformerRunStatusThresholdService;

    @Reference(check = false)
    private BusiSubPageService busiSubPageService;

    /**
     * 根据站点设备树ID、工作状态获取变压器运行工况阈值
     *
     * @param siteId
     * @param mainTreeId
     *            站点设备树ID
     * @param workStatus
     *            工作状态
     * @return
     */
    @ApiOperation(value = "根据站点设备树ID、工作状态获取变压器运行工况阈值")
    @KerLog(projectName = "PROJECTNAME", modelName = "TRANSFORMERPD.MODELNAME",
            methodName = "TRANSFORMERPD.METHODNAME.QUERYLIST")
    @GetMapping(value = "/findRunStatusThreshold",
            produces = {"application/json;charset=utf-8"})
    public Map<String, Object> findRunStatusThreshold(@RequestParam(value = "siteId") String siteId,
                                                      @RequestParam(value = "mainTreeId") String mainTreeId, @RequestParam(value = "workStatus") String workStatus) {
        TransformerRunStatusThresholdVo transformerPds =
                transformerRunStatusThresholdService.queryRunStatusThreshold(siteId, mainTreeId, workStatus);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", transformerPds);
    }

    /**
     * 根据站点设备树ID获取变压器运行工况阈值
     *
     * @param mainTreeId
     *            站点设备树ID
     * @return
     */
    @ApiOperation(value = "根据站点设备树ID获取变压器运行工况阈值")
    @KerLog(projectName = "PROJECTNAME", modelName = "TRANSFORMERPD.MODELNAME",
            methodName = "TRANSFORMERPD.METHODNAME.QUERYLIST")
    @GetMapping(value = "/findRunStatusThresholdByMainTreeId", produces = {"application/json;charset=utf-8"})
    public Map<String, Object>
    findRunStatusThresholdByMainTreeId(@RequestParam(value = "mainTreeId") String mainTreeId) {
        List<TransformerRunStatusThresholdVo> transformerPds =
                transformerRunStatusThresholdService.queryRunStatusThresholdByMainTreeId(mainTreeId);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", transformerPds);
    }

    /**
     * 运行工况告警信息
     *
     * @param warningId
     * @param mainEquipmentId
     * @return
     */
    @ApiOperation(value = "运行工况告警信息", response = BusiRunStateVo.class)
    @ApiImplicitParams({@ApiImplicitParam(name = "warningId", value = "告警ID"),
            @ApiImplicitParam(name = "mainEquipmentId", value = "主设备编码")})
    @GetMapping(value = "/getRunStateWarningInfo")
    public Map<String, Object> getRunStateWarningInfo(@RequestParam("warningId") String warningId,
                                                      @RequestParam("mainEquipmentId") String mainEquipmentId) {
        BusiRunStateVo busiRunStateVo = busiSubPageService.getRunStateWarningInfo(warningId, mainEquipmentId);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", busiRunStateVo);
    }
}
