package com.huatek.busi.controller;

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

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
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.dto.InfraredThresholdDto;
import com.huatek.busi.service.threshold.InfraredThresholdService;
import com.huatek.busi.vo.InfraredThresholdVo;
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;

/**
 * 红外热成像数据
 * @author buck_guo
 * @date 2019/08/08
 */
@Api(tags = {Tags.INFRARED_THRESHOLD})
@RestController
@RequestMapping("/api/InfraredThreshold")
public class InfraredThresholdController {
    protected final Logger logger = LoggerFactory.getLogger(InfraredThresholdController.class);

    @Reference(check = false)
    private InfraredThresholdService infraredThresholdService;

     /**
      * 查询红外测温阈值查询
      * @param sensorCode
      * @return
      */
    @ApiOperation(value = "查询红外热成像阈值")
    @PostMapping(value = "/queryInfraredThreshold", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> queryInfraredThreshold(@RequestParam(value = "sensorCode") String sensorCode,
        @RequestParam(value = "workStatus") String workStatus,
        @RequestParam(value = "type") String type) {
        InfraredThresholdVo infraredThresholdVo =
            infraredThresholdService.queryInfraredThreshold(sensorCode, workStatus);
        if (infraredThresholdVo == null) {
            infraredThresholdVo = new InfraredThresholdVo();
            infraredThresholdVo.setRegionPosition(1);
            infraredThresholdVo.setWorkStatus(workStatus);
            infraredThresholdVo.setSensorCode(sensorCode);
            infraredThresholdVo.setType(type);
        }
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "", Arrays.asList(infraredThresholdVo));
    }

    /**
     * 新增修改变压器运行工况阈值
     * @param token
     * @param infraredThresholdDto
     * @return
     */
   @ApiOperation(value = "新增修改红外热阈值")
   @PostMapping(value="/insertOrUpdate", produces = {"application/json;charset=utf-8"})
   public Map<String, Object> insertOrUpdate(@RequestHeader("token")String token,@RequestBody InfraredThresholdDto[] infraredThresholdDto) {
       int count = infraredThresholdService.insertOrUpdate(token,infraredThresholdDto);
       logger.debug("insertOrUpdate: {}", count);
       return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "红外热阈值保存成功", "");
   }


    /**
     * 新增修改变压器运行工况阈值
     * @param token
     * @param sensorCode
     * @param type
     * @return
     */
  @ApiOperation(value = "新增sensor时增加16个红外热阈值")
  @KerLog(projectName = "PROJECTNAME", modelName = "IECBASECONF.MODELNAME", methodName = "IECBASECONF.METHODNAME.ADDIECBASECONF")
  @PostMapping(value="/addSensorInsertInfrared", produces = {"application/json;charset=utf-8"})
  public Map<String, Object> addSensorInsertInfrared(@RequestHeader("token")String token,@RequestParam(value="sensorCode")String sensorCode,@RequestParam(value="type")String type) {
      int count = infraredThresholdService.addSensorInsertInfrared(token,sensorCode,type);
      logger.debug("insertOrUpdate: {}", count);
      return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "红外热阈值保存成功", "");
  }
}