package com.base.track.controller;


import com.base.orbit.log.ServerNameEnum;
import com.base.orbit.web.Result;
import com.base.track.model.dto.request.QueryVisualDTO;
import com.base.track.model.dto.response.VisualDTO;
import com.base.track.model.entity.VisualData;
import com.base.track.service.VisualDataService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/visual")
@Api(tags = "可视化图标", description = "可视化图表数据模块接口")
@Slf4j
public class VisualDataController {

    @Resource
    private VisualDataService visualDataService;

    @GetMapping("/selVisualById/{id}")
    @ApiOperation(value = "可视化列表指标值展示")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "进出站id")
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "OK", response = VisualData.class)
    })
    public Object selVisualById(@PathVariable String id) {
        if (StringUtils.isEmpty(id)) {
            log.error("sel visual data is error id is not empty!!", ServerNameEnum.TRACK_SERVER);
            return Result.error("sel visual data is error id is not empty!!");
        }
        return Result.success(visualDataService.selVisualById(id));
    }


    @PostMapping("/countVisualByDTO")
    @ApiOperation(value = "可视化列表指标值计算")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "queryVisualDTO", value = "参数对象")
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "OK", response = VisualDTO.class)
    })
    public Object countVisualByDTO(@RequestBody QueryVisualDTO queryVisualDTO) {
        return Result.success(visualDataService.countVisualByDTO(queryVisualDTO));
    }

    @PostMapping("/countVisualByVo")
    @ApiOperation(value = "传入指定值进行余量计算参数构造")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "queryVisualDTO", value = "参数对象")
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "OK", response = VisualDTO.class)
    })
    public Object countVisualByVo(@RequestBody QueryVisualDTO queryVisualDTO) {
        return Result.success(visualDataService.countVisualByVo(queryVisualDTO));
    }

}
