package com.huatek.busi.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.huatek.busi.constant.ApiConstant.Tags;
import com.huatek.busi.dto.InfraredThresholdDto;
import com.huatek.busi.dto.WindingThresholdDto;
import com.huatek.busi.service.threshold.InfraredThresholdService;
import com.huatek.busi.service.threshold.WindingThresholdService;
import com.huatek.busi.vo.InfraredThresholdVo;
import com.huatek.busi.vo.WindingThresholdVo;
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;

/**
 * 绕组测温数据
 * @author buck_guo
 * @date 2019/08/08
 */
@Api(tags = {Tags.WINDING_THRESHOLD})
@RestController
@RequestMapping("/api/WindingThreshold")
public class WindingThresholdController {
    protected final Logger logger = LoggerFactory.getLogger(WindingThresholdController.class);

    @Reference(check = false)
    private WindingThresholdService windingThresholdService;

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

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


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