package com.gyee.runeconomy.controller.monitor;/*
@author   谢生杰
@date   2023/4/6-15:20
*/

import com.gyee.common.model.StringUtils;
import com.gyee.runeconomy.dto.R;
import com.gyee.runeconomy.dto.ResultMsg;
import com.gyee.runeconomy.model.auto.ProEconTestingPoint;
import com.gyee.runeconomy.model.vo.ProTreeVo;
import com.gyee.runeconomy.service.monitor.DeviceDetailsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/detail")
@Api(value = "设备详情", tags = "设备详情")
public class DeviceDetailsController {
    @Resource
    private DeviceDetailsService deviceDetailsService;

    /**
     * 左侧树形
     *
     * @return
     */
    @GetMapping("/tree")
    @ResponseBody
    @ApiOperation(value = "左侧树形", notes = "左侧树形")
    public R tree(@RequestParam(value = "wpid", required = true) String wpid) throws Exception {

        List<ProTreeVo> resultList = deviceDetailsService.tree(wpid);
        if (StringUtils.isNotNull(resultList)) {
            return R.data(ResultMsg.ok(resultList));
        } else {
            return R.error(ResultMsg.error());
        }
    }

    /**
     * 监测信息
     *
     * @return
     */
    @GetMapping("/info")
    @ResponseBody
    @ApiOperation(value = "监测信息", notes = "监测信息")
    public R info(@RequestParam(value = "wtid", required = true) String wtid) throws Exception {

        Map<String, Double> resultMap = deviceDetailsService.info(wtid);
        if (StringUtils.isNotNull(resultMap)) {
            return R.data(ResultMsg.ok(resultMap));
        } else {
            return R.error(ResultMsg.error());
        }
    }

    /**
     * 获取统一编码
     *
     * @return
     */
    @GetMapping("/getuniformcode")
    @ResponseBody
    @ApiOperation(value = "获取统一编码", notes = "获取统一编码")
    public R getuniformcode(@RequestParam(value = "part", required = true) String part,
                            @RequestParam(value = "wtid", required = true) String wtid) throws Exception {

        Map<String, List<ProEconTestingPoint>> resultMap = deviceDetailsService.getuniformcode(part, wtid);
        if (StringUtils.isNotNull(resultMap)) {
            return R.data(ResultMsg.ok(resultMap));
        } else {
            return R.error(ResultMsg.error());
        }
    }


}
