package com.huatek.busi.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.huatek.busi.common.BusiConstant.SpType;
import com.huatek.busi.common.SiteConstants.ExternalTypeEnum;
import com.huatek.busi.constant.ApiConstant.Tags;
import com.huatek.busi.dto.BusiSensorDto;
import com.huatek.busi.entity.BusiGeneratorAmplType;
import com.huatek.busi.service.BusiSensorService;
import com.huatek.busi.service.threshold.TransformerOilThresholdService;
import com.huatek.busi.vo.BusiSensorVo;
import com.huatek.busi.vo.generator.BusiGeneratorAmplTypeVo;
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 org.springframework.web.bind.annotation.*;

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

/**
 * @ClassName: BusiSensorController
 * @FullClassPath: com.huatek.busi.controller.BusiSensorController
 * @Description: 传感器控制器
 * @author: Arno
 * @date: Jul 18, 2019 3:09:50 PM
 * @version: 1.0
 */
@Api(tags = {Tags.BUSI_SENSOR})
@RestController
@RequestMapping("/api/BusiSensor")
public class BusiSensorController {

    @Reference(check = false)
    private BusiSensorService busiSensorService;

    @Reference(check = false)
    private TransformerOilThresholdService transformerOilThresholdService;

    /**
     * @Title: page @Description: 分页列表 @createDate: Jul 18, 2019 3:10:20 PM @param @return Map<String,Object> @throws
     */
    @ApiOperation(value = "传感器分页列表")
    @PostMapping(value = "/page", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> page(@RequestBody BusiSensorDto bsiSensorDto) {
        return busiSensorService.page(bsiSensorDto);
    }

    /**
     * @Title: findOilSensor @Description: 查询油色谱传感器信息
     */
    @ApiOperation(value = "查询油色谱传感器信息")
    @GetMapping(value = "/findOilSensor", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> findOilSensor(@RequestParam(value = "equipmentId") String equipmentId) {
        List<BusiSensorVo> sensorList = busiSensorService.findOilSensor(equipmentId);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", sensorList);
    }

    @ApiOperation(value = "查询振动传感器信息")
    @GetMapping(value = "/findZdSensor", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> findZdSensor(@RequestParam(value = "equipmentId") String equipmentId) {
        List<BusiSensorVo> sensorList = busiSensorService.findZdSensor(equipmentId);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", sensorList);
    }

    /**
     * @Title: add @Description: 新增传感器 @createDate: Jul 18, 2019 3:10:20 PM @param @return Map<String,Object> @throws
     */
    @ApiOperation(value = "新增传感器 ")
    @PostMapping(value = "/add", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> add(@RequestBody BusiSensorVo busiSensorVo) {
        busiSensorService.add(busiSensorVo);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", "");
    }

    /**
     * @Title: update @Description: 修改传感器 @createDate: Jul 18, 2019 3:10:20 PM @param @return Map<String,Object> @throws
     */
    @ApiOperation(value = "更新传感器 ")
    @PostMapping(value = "/update", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> update(@RequestHeader("token") String token, @RequestBody BusiSensorVo busiSensorVo) {
        busiSensorService.update(token, busiSensorVo);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", "");
    }

    /**
     * @Title: delete @Description: 删除传感器 @createDate: Jul 18, 2019 3:10:20 PM @param @return Map<String,Object> @throws
     */
    @ApiOperation(value = "删除传感器 ")
    @ApiImplicitParams({
        @ApiImplicitParam(paramType = "query", name = "ids", value = "传感器id", required = true, dataType = "String"),
        @ApiImplicitParam(paramType = "query", name = "equipmentType",
            value = "节点新名称(eg:  1-变压器  2-GIS设备  3-测温   4-避雷器  5-其他 6-发电机 7-电缆)", required = true, dataType = "String")})
    @GetMapping(value = "/delete")
    public Map<String, Object> delete(@RequestParam(value = "ids", required = true) String ids,
        @RequestParam(value = "equipmentType", required = true) String equipmentType) {
        busiSensorService.delete(ids, equipmentType);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", "");
    }

    /**
     * 根据外挂设备ID、视频类型(byq_yxgk，blq_hwcw，gis_hwcw)获取sensor
     *
     * @param equipmentId
     *            外挂设备Id
     * @param type
     *            类型
     * @return
     */
    @ApiOperation(value = "根据外挂设备ID、视频类型(byq_yxgk，blq_hwcw，gis_hwcw)获取sensor")
    @PostMapping(value = "/querySensorByequipMentAndType", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> querySensorByequipMentAndType(
        @RequestParam(value = "equipmentId", required = true) String equipmentId,
        @RequestParam(value = "type", required = true) String type) {
        ExternalTypeEnum extType = null;
        if (SpType.BYQ_YXGK.equals(type) || SpType.BYQ_HWCW.equals(type)) {
            extType = ExternalTypeEnum.BYQ;
        } else if (SpType.GIS_HWCW.equals(type)) {
            extType = ExternalTypeEnum.GIS;
        } else if (SpType.BLQ_HWCW.equals(type)) {
            extType = ExternalTypeEnum.BLQ;
        } else if (SpType.OTHER.equals(type)) {
            extType = ExternalTypeEnum.OTHER;
        }
        List<BusiSensorVo> sensorList = busiSensorService.findSensorList(extType, equipmentId);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", sensorList);
    }

    /**
     * 发电机振动类型查询
     */
    @ApiOperation(value = "发电机振动/压力类型查询")
    @GetMapping(value = "/findGeneratorAmplTypeList", produces = {"application/json;charset=utf-8"})
    @ApiImplicitParam(name = "equipmentType", value = "发电机设备类型：011：振动、031：压力")
    public Map<String, Object> findGeneratorAmplTypeList(String equipmentType) {
        List<BusiGeneratorAmplTypeVo> amplTypeList = busiSensorService.findAmplTypeList(equipmentType);
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", amplTypeList);
    }
}
