package com.huatek.busi.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.huatek.busi.dto.CwzzThresholdDto;
import com.huatek.busi.dto.Sf6EnvThresholdDto;
import com.huatek.busi.service.threshold.CwzzThresholdService;
import com.huatek.busi.service.threshold.Sf6EnvThresholdService;
import com.huatek.busi.vo.CwzzThresholdVo;
import com.huatek.busi.vo.Sf6EnvThresholdVo;
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.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

/**
 *
 * SF6环境监测
 * @author vent
 * @date 2023-04-18
 */
@Api(tags = {" SF6环境监测告警及阈值详情"})
@RestController
@RequestMapping("/api/Sf6EnvThreshold")
public class Sf6EnvThresholdController {
    protected final Logger logger = LoggerFactory.getLogger(Sf6EnvThresholdController.class);

    @Reference(check = false)
    private Sf6EnvThresholdService sf6EnvThresholdService;

     /**
      * √
      * 查询SF6环境监测阈值查询
      * @param sensorCode
      * @return
      */
    @ApiOperation(value = "查询阈值")
    @PostMapping(value = "/querySf6EnvThreshold", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> queryCwzzThreshold(@RequestParam(value = "sensorCode") String sensorCode,
        @RequestParam(value = "workStatus") String workStatus,
        @RequestParam(value = "type") String type) {
        Sf6EnvThresholdVo sf6EnvThresholdVo =
                sf6EnvThresholdService.querySf6EnvThreshold(sensorCode, workStatus);
        if (sf6EnvThresholdVo == null) {
            sf6EnvThresholdVo = new Sf6EnvThresholdVo();
            sf6EnvThresholdVo.setWorkStatus(workStatus);
            sf6EnvThresholdVo.setSensorCode(sensorCode);
            sf6EnvThresholdVo.setType(type);
        }
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", Arrays.asList(sf6EnvThresholdVo));
    }

    /**
     * 新增修改SF6环境监测
     * @param token
     * @param sf6EnvThresholdDto
     * @return
     */
   @ApiOperation(value = "新增修改阈值")
   @PostMapping(value="/insertOrUpdate", produces = {"application/json;charset=utf-8"})
   public Map<String, Object> insertOrUpdate(@RequestHeader("token")String token,@RequestBody Sf6EnvThresholdDto[] sf6EnvThresholdDto) {
       int count = sf6EnvThresholdService.insertOrUpdate(token,sf6EnvThresholdDto);
       logger.debug("insertOrUpdate: {}", count);
       return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "测温阈值保存成功", "");
   }


    /**
     * SF6环境监测
     * @param token
     * @param sensorCode
     * @param type
     * @return
     */
  @ApiOperation(value = "新增sensor时增加SF6环境监测")
  @KerLog(projectName = "PROJECTNAME", modelName = "IECBASECONF.MODELNAME", methodName = "IECBASECONF.METHODNAME.ADDIECBASECONF")
  @PostMapping(value="/addSensorInsertSf6Env", produces = {"application/json;charset=utf-8"})
  public Map<String, Object> addSensorInsertCwzz(@RequestHeader("token")String token,@RequestParam(value="sensorCode")String sensorCode,@RequestParam(value="type")String type) {
      int count = sf6EnvThresholdService.addSensorInsertSf6Env(token,sensorCode,type);
      logger.debug("insertOrUpdate: {}", count);
      return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "测温阈值保存成功", "");
  }
}
