package com.gyee.runeconomy.controller.monitor;/*
@author   谢生杰
@date   2023/3/28-8:43
*/

import com.gyee.common.model.StringUtils;
import com.gyee.runeconomy.dto.AjaxResult;
import com.gyee.runeconomy.dto.R;
import com.gyee.runeconomy.dto.ResultMsg;
import com.gyee.runeconomy.service.monitor.MatrixService;
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.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/matrix")
@Api(value = "矩阵", tags = "矩阵")
public class MatrixController {
    @Resource
    private MatrixService matrixService;


    /**
     * 基础矩阵
     *
     * @return
     */
    @GetMapping("/basic")
    @ResponseBody
    @ApiOperation(value = "基础矩阵", notes = "基础矩阵")
    public R basic(@RequestParam(value = "type", required = true) String type,
                   @RequestParam(value = "company", required = true) String company) throws Exception {

        Map<String, Object> resultMap = matrixService.basic(company, type);
        if (StringUtils.isNotNull(resultMap)) {
            return R.data(ResultMsg.ok(resultMap));
        } else {
            return R.error(ResultMsg.error());
        }
    }


    /**
     * 明细矩阵
     *
     * @return
     */
    @GetMapping("/detailed")
    @ResponseBody
    @ApiOperation(value = "明细矩阵", notes = "明细矩阵")
    public R detailed(@RequestParam(value = "type", required = true) String type,
                      @RequestParam(value = "company", required = true) String company) throws Exception {

        Map<String, Object> resultMap = matrixService.matrixMX(company, type);
        if (StringUtils.isNotNull(resultMap)) {
            return R.data(ResultMsg.ok(resultMap));
        } else {
            return R.error(ResultMsg.error());
        }
    }


    /**
     * 单场矩阵
     *
     * @return
     */
    @GetMapping("/single")
    @ResponseBody
    @ApiOperation(value = "单场矩阵", notes = "单场矩阵")
    public R single(@RequestParam(value = "wpid", required = true) String wpid) throws Exception {

        Map<String, Object> resultMap = matrixService.single(wpid);
        if (StringUtils.isNotNull(resultMap)) {
            return R.data(ResultMsg.ok(resultMap));
        } else {
            return R.error(ResultMsg.error());
        }
    }

    /**
     * 基础矩阵
     *
     * @return
     */
    @GetMapping("/sbxx")
    @ResponseBody
    @ApiOperation(value = "矩阵设备信息", notes = "矩阵设备信息")
    public AjaxResult basic(@RequestParam(value = "wtid", required = true) String wtid) throws Exception {

        Map<String, String> resultList = new HashMap<>();
        if (com.gyee.runeconomy.util.StringUtils.notEmp(wtid)) {
            resultList = matrixService.equipment(wtid);
        }

        if (null != resultList) {
            return AjaxResult.successData(200, resultList);
        } else {
            return AjaxResult.error(500, "操作失败");
        }

    }

}
