package com.gyee.runeconomy.controller.monitor;/*
@author   谢生杰
@date   2023/4/3-14:38
*/

import com.gyee.common.model.StringUtils;
import com.gyee.common.vo.monitor.CompreVo;
import com.gyee.runeconomy.dto.R;
import com.gyee.runeconomy.dto.ResultMsg;
import com.gyee.runeconomy.init.CacheContext;
import com.gyee.runeconomy.model.auto.ProEconTestingPoint;
import com.gyee.runeconomy.service.monitor.ComprehensiveService;
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;

@Controller
@RequestMapping("/comprehensive")
@Api(value = "综合指标/数据列表", tags = "综合指标/数据列表")
public class ComprehensiveController {
    @Resource
    private ComprehensiveService comprehensiveService;

    /**
     * 综合指标-指标查询
     *
     * @return
     */
    @GetMapping("/targets")
    @ResponseBody
    @ApiOperation(value = "综合指标-获取指标", notes = "综合指标-获取指标")
    public R targets(@RequestParam(value = "type", required = true) String type) {

        List<ProEconTestingPoint> resultList = comprehensiveService.targets(type);
        if (StringUtils.isNotNull(resultList)) {
            return R.data(ResultMsg.ok(resultList));
        } else {
            return R.error(ResultMsg.error());
        }
    }

    /**
     * 数据指标-指标查询
     *
     * @return
     */
    @GetMapping("/wttargets")
    @ResponseBody
    @ApiOperation(value = "数据指标-获取指标", notes = "数据指标-获取指标")
    public R wttargets(@RequestParam(value = "type", required = true) String type,
                       @RequestParam(value = "part", required = true) String part) {

        List<ProEconTestingPoint> resultList = comprehensiveService.wttargets(type, part);
        if (StringUtils.isNotNull(resultList)) {
            return R.data(ResultMsg.ok(resultList));
        } else {
            return R.error(ResultMsg.error());
        }
    }

    /**
     * 综合指标-列表查询
     *
     * @return
     */
    @GetMapping("/listing")
    @ResponseBody
    @ApiOperation(value = "综合指标-列表查询", notes = "综合指标-列表查询")
    public R listing(@RequestParam(value = "type", required = true) String type,
                     @RequestParam(value = "company", required = true) String company,
                     @RequestParam(value = "targets", required = true) String targets) throws Exception {

        List<CompreVo> resultList = comprehensiveService.listing(company, type, targets);
        if (StringUtils.isNotNull(resultList)) {
            return R.data(ResultMsg.ok(resultList));
        } else {
            return R.error(ResultMsg.error());
        }
    }

    /**
     * 数据指标-列表查询
     *
     * @return
     */
    @GetMapping("/wtlisting")
    @ResponseBody
    @ApiOperation(value = "数据指标-列表查询", notes = "数据指标-列表查询")
    public R wtlisting(@RequestParam(value = "type", required = true) String type,
                       @RequestParam(value = "company", required = true) String company,
                       @RequestParam(value = "wpid", required = true) String wpid,
                       @RequestParam(value = "targets", required = true) String targets,
                       @RequestParam(value = "pageSize", required = true) String pageSize,
                       @RequestParam(value = "pageNum", required = true) String pageNum) {
        int count = CacheContext.wpwtmap.get(wpid).size();
        List<CompreVo> resultList = comprehensiveService.wtlisting(company, type, targets, wpid, pageSize, pageNum);
        if (StringUtils.isNotNull(resultList)) {
            return R.data(ResultMsg.ok(resultList, count));
        } else {
            return R.error(ResultMsg.error());
        }
    }
}
