package com.huatek.busi.controller;

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.common.BusiConstant.EqType;
import com.huatek.busi.common.SiteConstants;
import com.huatek.busi.common.SiteConstants.SiteTreeEnum;
import com.huatek.busi.constant.ApiConstant.Tags;
import com.huatek.busi.service.BusiSubPageService;
import com.huatek.busi.service.threshold.PhotoThresholdService;
import com.huatek.busi.vo.PhotoThresholdVo;
import com.huatek.busi.vo.warning.BusiPhotoVo;
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;

/**
 * APP读表告警API
 *
 * @author anker_cheng
 * @date 2019/10/11
 */
@Api(tags = {Tags.APP_PHOTO_WARNING_API})
@RestController
@RequestMapping("/app/appHomePage")
public class PhotoThresholdController {
    @Reference(check = false)
    private PhotoThresholdService photoThresholdService;
    @Reference(check = false)
    private BusiSubPageService busiSubPageService;

    @ApiOperation(value = "读表数据告警详情", response = BusiPhotoVo.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "warningId", value = "告警ID"),
            @ApiImplicitParam(name = "sensorCode", value = "传感器编码"),
            @ApiImplicitParam(name = "eqType", value = "告警大类")
    })
    @GetMapping(value = "/getPhotoWarningInfo")
    public Map<String, Object> getRunStateWarningInfo(@RequestParam("warningId") String warningId,
                                                      @RequestParam("sensorCode") String sensorCode, @RequestParam("eqType") String eqType) {
        BusiPhotoVo vo = busiSubPageService.getPhotoWarningInfo(warningId, sensorCode, eqType);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", vo);
    }

    @ApiOperation(value = "读表数据阈值", response = PhotoThresholdVo.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sensorCode", value = "传感器编码"),
            @ApiImplicitParam(name = "workStatus", value = "工作状态"),
            @ApiImplicitParam(name = "eqType", value = "告警大类")
    })
    @GetMapping(value = "/getPhotoThreshold")
    public Map<String, Object> getPhotoThreshold(@RequestParam(value = "sensorCode") String sensorCode,
                                                 @RequestParam(value = "workStatus") String workStatus, @RequestParam("eqType") String eqType) {
        String type = "";
        if (EqType.EQ_TYPE1.equals(eqType)) {
            type = SiteTreeEnum.BYQ.getValue();
        } else if (EqType.EQ_TYPE2.equals(eqType)) {
            type = SiteConstants.SiteTreeEnum.GIS.getValue();
        } else if (EqType.EQ_TYPE3.equals(eqType)) {
            type = SiteConstants.SiteTreeEnum.BLQ.getValue();
        }
        PhotoThresholdVo vo = photoThresholdService.queryPhotoThreshold(sensorCode, workStatus, type);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", vo);
    }
}
