package com.huatek.busi.controller.cable;

import com.alibaba.dubbo.config.annotation.Reference;
import com.huatek.busi.constant.ApiConstant;
import com.huatek.busi.dto.cable.BusiCableCirculationDto;
import com.huatek.busi.dto.cable.BusiCableCirculationStatisticsDto;
import com.huatek.busi.service.BusiOtherSubTreeService;
import com.huatek.busi.service.IBusiCableSubTreeService;
import com.huatek.busi.service.cable.BusiCableCirculationService;
import com.huatek.busi.service.cable.BusiCableThresholdService;
import com.huatek.busi.service.cable.BusiOtherThresholdService;
import com.huatek.torch.frame.tools.ConstantUtil;
import com.huatek.torch.frame.tools.ResultUtil;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

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

/**
 * 电缆环流控制层
 *
 * @author Bobi_huo
 * @date 2020-09-10 14:01
 */
@Api(tags = {ApiConstant.Tags.BUSI_CABLE_CIRULATION})
@Slf4j
@RestController
@RequestMapping("/api/busiCableCirculation")
public class BusiCableCirculationController {

    @Reference(check = false)
    private BusiCableCirculationService busiCableCirculationService;

    @Reference(check = false)
    private BusiOtherSubTreeService busiOtherSubTreeService;

    @Reference(check = false)
    IBusiCableSubTreeService busiCableSubTreeService;

    @Reference(check = false)
    private BusiCableThresholdService busiCableThresholdService;

    /**
     * 分页
     *
     * @param dto
     * @return
     */
    @PostMapping(value = "/page", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> page(@RequestBody BusiCableCirculationDto dto) {
        return busiCableCirculationService.page(dto);
    }

    /**
     * 新增
     *
     * @param dto
     * @return
     */
    @PostMapping(value = "/add", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> addCable(@RequestBody BusiCableCirculationDto dto) {
        return busiCableCirculationService.addCable(dto);
    }

    /**
     * 根据id返回信息
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/find", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> findCableById(@RequestParam("id") String id) {
        return busiCableCirculationService.findCableById(id);
    }

    /**
     * 修改
     *
     * @param dto
     * @return
     */
    @PostMapping(value = "/update", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> updateCable(@RequestBody BusiCableCirculationDto dto) {
        return busiCableCirculationService.updateCable(dto);
    }

    /**
     * 删除
     *
     * @param ids
     * @return
     */
    @PostMapping(value = "/del", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> deleteCable(@RequestBody List<String> ids) {
        return busiCableCirculationService.deleteCable(ids);
    }

    /**
     * 获取时间最近的实时数据
     *
     * @param equipmentId
     * @return
     */
    @GetMapping(value = "/getRealData", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> getRealData(@RequestParam("equipmentId") String equipmentId) {
        return busiCableCirculationService.getRealData(equipmentId);
    }

    /**
     * 获取时间最近的实时数据
     *
     * @param equipmentId
     * @return
     */
    @GetMapping(value = "/getRealDataForCable", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> getRealDataForCable(@RequestParam("equipmentId") String equipmentId) {
        return busiCableCirculationService.getRealDataForCable(equipmentId);
    }

    /**
     * 获取近15天数据趋势图
     *
     * @param dto
     * @return
     */
    @PostMapping(value = "/getHistoryTrendChart", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> getHistoryTrendChart(@RequestBody BusiCableCirculationStatisticsDto dto) {
        return busiCableCirculationService.getHistoryTrendChart(dto);
    }

    /**
     * 根据设备树id获取subTreegetOtherSubTreeByType
     *
     * @param equipmentType
     * @return
     */
    @GetMapping(value = "/getOtherSubTreeByType", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> getOtherSubTreeByType(@RequestParam("equipmentType") String equipmentType) {
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "查询成功",
                busiOtherSubTreeService.getOtherSubTreeByType(equipmentType));
    }

    @GetMapping(value = "/getCableSubTreeByType", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> getCableSubTreeByType(@RequestParam("equipmentType") String equipmentType) {
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "查询成功",
                busiCableSubTreeService.getCableSubTreeByType(equipmentType));
    }

    /**
     * 根据sensorCode获取基本信息
     *
     * @param sensorCode
     * @return
     */
    @GetMapping(value = "/getCableData", produces = {"application/json;charset=utf-8"})
    public Map<String, Object> getCableData(@RequestParam("sensorCode") String sensorCode,@RequestParam("transformerId") String transformerId) {
        return ResultUtil.put(ConstantUtil.REQUEST_SUCCESS, "查询成功",
//                busiOtherThresholdServicee.getCableData(sensorCode,transformerId));  //其他-电缆环流
                busiCableThresholdService.getCableData(sensorCode,transformerId));
    }
}
